2 Command line arguments: python E:\Code\Python\ida\ida.py D2Client.dll B:\D2\D2Client.lst process_automap_unit automap_blobs E:\Code\craw_module\source\craw\automap.cpp
3 Time of generation: 2009-07-10 16:34:56
8 #include <ail/string.hpp>
10 #include "utility.hpp"
15 //Initialisation variables
17 char const * module_name
= "D2Client.dll";
18 unsigned image_base
= 0x6FAB0000;
19 unsigned module_base
= 0;
21 unsigned get_y_coordinate
= 0x6FABC214;
22 unsigned sub_6FACF710
= 0x6FACF710;
23 unsigned D2Common_10195
= 0x6FABC3D0;
24 unsigned D2Win_10132
= 0x6FABD354;
25 unsigned D2Lang_10005
= 0x6FABD1D4;
26 unsigned draw_text
= 0x6FABD360;
27 unsigned sub_6FACF780
= 0x6FACF780;
28 unsigned get_unit_state
= 0x6FABC21A;
29 unsigned D2Common_10860
= 0x6FABCA4E;
30 unsigned automap_unit_type_check
= 0x6FAEF3D0;
31 unsigned sub_6FAEDE00
= 0x6FAEDE00;
32 unsigned D2Common_10350
= 0x6FABC3D6;
33 unsigned sub_6FAB2D40
= 0x6FAB2D40;
34 unsigned draw_cross
= 0x6FAED0C0;
35 unsigned sub_6FACF3D0
= 0x6FACF3D0;
36 unsigned set_text_size
= 0x6FABD36C;
37 unsigned get_x_coordinate
= 0x6FABC208;
44 void automap_blobs_interrupt()
52 void __stdcall
process_unit(int x
, int y
, uchar colour
)
54 python::perform_automap_callback(*unit_pointer
, x
, y
, colour
);
57 void __declspec(naked
) intercept_draw_cross()
73 void __stdcall
initialise_automap_blobs()
75 module_base
= reinterpret_cast<unsigned>(GetModuleHandle(module_name
));
77 automap_blobs_interrupt();
79 unsigned * call_addresses
[] =
90 &automap_unit_type_check
,
100 unsigned linking_offset
= module_base
- image_base
;
102 for(std::size_t i
= 0; i
< 17; i
++)
104 unsigned & address
= *call_addresses
[i
];
105 address
+= linking_offset
;
108 bool success
= false;
110 std::string
const marker
= "\x0f\x0b\x0f\x0b\x0f\x0b\x0f\x0b";
112 char * data_pointer
= reinterpret_cast<char *>(&automap_blobs
);
115 std::string
current_string(data_pointer
, marker
.size());
116 if(current_string
== marker
)
125 automap_blobs_interrupt();
127 data_pointer
+= marker
.size();
129 for(unsigned i
= 0; i
< 19; i
++)
131 char * label_pointer
= *reinterpret_cast<char **>(data_pointer
+ 1);
132 unsigned * immediate_pointer
= reinterpret_cast<unsigned *>(label_pointer
- 4);
133 DWORD old_protection
;
134 SIZE_T
const patch_size
= 4;
135 if(!VirtualProtect(immediate_pointer
, patch_size
, PAGE_EXECUTE_READWRITE
, &old_protection
))
136 automap_blobs_interrupt();
137 unsigned & address
= *immediate_pointer
;
138 address
+= linking_offset
;
140 if(!VirtualProtect(immediate_pointer
, patch_size
, old_protection
, &unused
))
141 automap_blobs_interrupt();
146 void __declspec(naked
) automap_blobs()
150 //Initialisation code:
153 jnz is_already_initialised
156 call initialise_automap_blobs
159 is_already_initialised
:
161 //store the unit pointer so we can restore it later if necessary
162 mov unit_pointer
, esi
164 //Actual code starts here:
176 mov byte ptr ds
:[esp
+ 18h
- 10h
], 0
178 test dword ptr ds
:[esi
+ 0C4h
], 10000h
182 mov ecx
, ds
:[esi
+ 10h
]
204 lea ebx
, ds
:[esp
+ 1Ch
- 10h
]
208 call automap_unit_type_check
214 call automap_unit_type_check
216 //fix esi and always have the check pass, keep the colour around though
217 mov esi
, unit_pointer
226 call get_x_coordinate
229 call get_y_coordinate
230 mov ebx
, ds
:[06FBA3B98h
]
236 mov edx
, ds
:[06FBCC2E8h
]
243 mov edx
, ds
:[06FBCC2ECh
]
247 mov eax
, ds
:[06FBCC318h
]
253 cmp edi
, ds
:[06FBCC320h
]
256 cmp ebx
, ds
:[06FBCC31Ch
]
259 cmp ebx
, ds
:[06FBCC324h
]
269 mov eax
, ds
:[06FBA3BA4h
]
275 cmp dword ptr ds
:[esi
+ 4], 10Bh
283 movzx eax
, byte ptr ds
:[esp
+ 20h
- 10h
]
306 mov ecx
, ds
:[esp
+ 20h
- 10h
]
312 call intercept_draw_cross
321 mov edx
, ds
:[esp
+ 20h
- 10h
]
327 call intercept_draw_cross
329 mov eax
, ds
:[06FBA3BA4h
]
338 mov eax
, ds
:[esi
+ 4]
346 mov ds
:[esp
+ 20h
- 10h
], eax
352 lea eax
, ds
:[ebx
- 0Ah
]
363 mov ecx
, ds
:[esp
+ 20h
- 10h
]
366 mov eax
, ds
:[06FBA3BA4h
]
370 mov eax
, ds
:[06FBA3BA0h
]
380 mov ds
:[esp
+ 20h
- 10h
], eax
385 mov eax
, ds
:[esi
+ 4]
388 mov ds
:[esp
+ 20h
- 8], eax
393 mov eax
, ds
:[esi
+ 10h
]
398 lea ecx
, ds
:[esp
+ 28h
- 0Ch
]
400 lea edx
, ds
:[esp
+ 2Ch
- 8]
401 mov ds
:[esp
+ 2Ch
- 0Ch
], eax
403 lea eax
, ds
:[esp
+ 30h
- 10h
]
407 mov eax
, ds
:[esp
+ 20h
- 10h
]
420 cmp dword ptr ds
:[ebp
+ 0], 0
422 mov eax
, ds
:[06FBCC3D0h
]
426 mov ds
:[esp
+ 20h
- 4], eax
430 cmp word ptr ds
:[esp
+ 20h
- 4], ax
447 mov eax
, ds
:[06FBA3BA0h
]
451 mov cl
, byte ptr ds
:[esp
+ 20h
- 10h
]
452 cmp cl
, ds
:[06FBCC303h
]
456 mov edx
, ds
:[esp
+ 20h
- 10h
]
462 call intercept_draw_cross
465 mov eax
, ds
:[06FBA3BA4h
]
469 mov eax
, ds
:[06FBA3BA0h
]
473 cmp esi
, ds
:[06FBCC3D0h
]
476 mov al
, ds
:[06FBCC303h
]
478 cmp byte ptr ds
:[esp
+ 20h
- 10h
], al
501 //Instruction address table hack:
508 push linker_address_0
509 push linker_address_1
510 push linker_address_2
511 push linker_address_3
512 push linker_address_4
513 push linker_address_5
514 push linker_address_6
515 push linker_address_7
516 push linker_address_8
517 push linker_address_9
518 push linker_address_10
519 push linker_address_11
520 push linker_address_12
521 push linker_address_13
522 push linker_address_14
523 push linker_address_15
524 push linker_address_16
525 push linker_address_17
526 push linker_address_18