2 Command line arguments: python E:\Code\Python\ida\ida.py D2Client.dll B:\D2\D2Client.lst sub_6FAF0350 automap_loop E:\Code\craw_module\source\craw\automap_loop.cpp
3 Time of generation: 2009-07-10 16:34:47
12 //Initialisation variables
14 char const * module_name
= "D2Client.dll";
15 unsigned image_base
= 0x6FAB0000;
16 unsigned module_base
= 0;
18 unsigned custom_exit
= 0x6FAB326D;
19 unsigned Fog_10265
= 0x6FABBF8C;
20 unsigned D2Common_10366
= 0x6FABC1BA;
21 unsigned Fog_10024
= 0x6FABBF80;
22 unsigned D2Common_10915
= 0x6FABC6A0;
23 unsigned sub_6FAEE860
= 0x6FAEE860;
24 unsigned process_automap_unit
= 0x6FAEF920;
28 void automap_loop_interrupt()
38 void __stdcall
initialise_automap_loop()
40 module_base
= reinterpret_cast<unsigned>(GetModuleHandle(module_name
));
42 automap_loop_interrupt();
44 unsigned * call_addresses
[] =
55 unsigned linking_offset
= module_base
- image_base
;
57 for(std::size_t i
= 0; i
< 7; i
++)
59 unsigned & address
= *call_addresses
[i
];
60 address
+= linking_offset
;
65 std::string
const marker
= "\x0f\x0b\x0f\x0b\x0f\x0b\x0f\x0b";
67 char * data_pointer
= reinterpret_cast<char *>(&automap_loop
);
70 std::string
current_string(data_pointer
, marker
.size());
71 if(current_string
== marker
)
80 automap_loop_interrupt();
82 data_pointer
+= marker
.size();
84 for(unsigned i
= 0; i
< 7; i
++)
86 char * label_pointer
= *reinterpret_cast<char **>(data_pointer
+ 1);
87 unsigned * immediate_pointer
= reinterpret_cast<unsigned *>(label_pointer
- 4);
89 SIZE_T
const patch_size
= 4;
90 if(!VirtualProtect(immediate_pointer
, patch_size
, PAGE_EXECUTE_READWRITE
, &old_protection
))
91 automap_loop_interrupt();
92 unsigned & address
= *immediate_pointer
;
93 address
+= linking_offset
;
95 if(!VirtualProtect(immediate_pointer
, patch_size
, old_protection
, &unused
))
96 automap_loop_interrupt();
100 //Deviation from the ASM output: overwriting the function address so it calls our own code instead:
102 process_automap_unit
= reinterpret_cast<unsigned>(&automap_blobs
);
104 void __declspec(naked
) automap_loop()
108 //Initialisation code:
111 jnz is_already_initialised
114 call initialise_automap_loop
117 is_already_initialised
:
119 //Actual code starts here:
122 mov eax
, ds
:[06FBCC3D0h
]
126 mov ebp
, ds
:[06FBCC080h
]
130 lea ecx
, ds
:[esp
+ 18h
- 8]
132 lea edx
, ds
:[esp
+ 1Ch
- 4]
136 mov ds
:[esp
+ 24h
- 4], edi
137 mov ds
:[esp
+ 24h
- 8], edi
141 mov eax
, ds
:[esp
+ 18h
- 8]
145 lea esp
, ds
:[esp
+ 0]
147 mov eax
, ds
:[esp
+ 18h
- 4]
148 mov ecx
, ds
:[eax
+ edi
* 4]
149 mov esi
, ds
:[ecx
+ 40h
]
155 call process_automap_unit
156 mov esi
, ds
:[esi
+ 0E8h
]
164 mov esi
, ds
:[06FBCC080h
]
172 mov cx
, ds
:[ebp
+ 22h
]
174 cmp ds
:[eax
+ 22h
], cx
178 mov eax
, ds
:[eax
+ 80h
]
186 mov eax
, ds
:[06FBA3BA0h
]
190 mov edi
, ds
:[ebp
+ 80h
]
194 mov ecx
, ds
:[edi
+ 10h
]
197 mov eax
, ds
:[edx
* 4 + 06FBCA960h
]
201 lea esp
, ds
:[esp
+ 0]
203 cmp ds
:[eax
+ 0Ch
], ecx
205 mov eax
, ds
:[eax
+ 0E4h
]
213 mov cx
, ds
:[edi
+ 22h
]
217 cmp ds
:[eax
+ 22h
], cx
221 mov eax
, ds
:[eax
+ 80h
]
230 cmp dword ptr ds
:[eax
], 0
247 mov esi
, ds
:[06FBCC080h
]
250 mov edi
, ds
:[edi
+ 80h
]
261 //Instruction address table hack:
268 push linker_address_0
269 push linker_address_1
270 push linker_address_2
271 push linker_address_3
272 push linker_address_4
273 push linker_address_5
274 push linker_address_6