new memory checker routine
Posted: Wed Apr 09, 2003 11:30 pm
I have tested this against the raw assembly and it seems to work. I'm too tired tonight to patch the eqlib.cpp. All the addresses listed below (four of them) need to be added to the ini file. Oh, and the detour stuff needs to be added to the loop below.
Code: Select all
//
// detour 4F77B2 to mymemcheck2
//
int *extern_array = 0x5C26D0;
int __cdecl mymemcheck2(unsigned char *buffer, int count, struct mckey key);
#define first 0x4F7820
#define second 0x4F7858
// TITLE orig.asm
// .386P
//
//EXTRN _extern_array:DWORD
//
//_TEXT SEGMENT
//
//getret PROC NEAR
// mov eax,dword ptr [esp]
// ret
//getret ENDP
//
//PUBLIC _memcheck2
int __cdecl mymemcheck2(unsigned char *buffer, int count, struct mckey key)
{
unsigned int x, i, j;
unsigned int ecx, ebx, edx, eax;
if (!extern_array) {
}
//_memcheck2 PROC NEAR
// push ebp
// mov ebp,esp
// mov al,byte ptr [ebp+10h]
// push ebx
// not al
// movzx eax,al
eax = ~key.a[0] & 0xff;
// movzx edx,byte ptr [ebp+11h]
edx = key.a[1] & 0xff;
// mov eax,dword ptr [eax*4+_extern_array]
eax = extern_array[eax];
// push esi
// mov esi,0FFFFFFh
// push edi
// xor eax,esi
eax ^= 0xffffff;
// mov edi,0FFh
// mov ecx,eax
// and ecx,edi
ecx = eax & 0xff;
// xor ecx,edx
ecx ^= edx;
// movzx edx,byte ptr [ebp+12h]
edx = key.a[2] & 0xff;
// mov ecx,dword ptr [ecx*4+_extern_array]
ecx = extern_array[ecx];
// sar eax,8
// and eax,esi
eax = ((int)eax>>8) & 0xffffff;
// xor ecx,eax
ecx ^= eax;
// mov eax,ecx
// and eax,edi
// xor eax,edx
eax = (ecx & 0xff) ^ edx;
// movzx edx,byte ptr [ebp+13h]
edx = key.a[3] & 0xff;
// mov eax,dword ptr [eax*4+_extern_array]
eax = extern_array[eax];
// sar ecx,8
// and ecx,esi
ecx = ((int)ecx>>8) & 0xffffff;
// xor eax,ecx
eax ^= ecx;
// mov ecx,eax
// and ecx,edi
// xor ecx,edx
ecx = (eax & 0xff) ^ edx;
// sar eax,8
eax = ((int)eax>>8) & 0xffffff;
// mov ebx,dword ptr [ecx*4+_extern_array]
// and eax,esi
ebx = extern_array[ecx];
// xor ebx,eax
ebx ^= eax;
ebx ^= first;
// call getret
// mov ecx,dword ptr [ebp+0Ch]
// xor ebx,eax
// mov eax,dword ptr [ebp+8]
// add ecx,eax
// mov dword ptr [ebp+10h],eax
// cmp eax,ecx
if (count == 0) goto done;
// jae done
//myloop:
// mov edx,dword ptr [ebp+10h]
// mov eax,ebx
// and eax,edi
// movzx edx,byte ptr [edx]
// xor eax,edx
// sar ebx,8
// mov eax,dword ptr [eax*4+_extern_array]
//
// and ebx,esi
// xor ebx,eax
// inc dword ptr [ebp+10h]
// cmp dword ptr [ebp+10h],ecx
// jb myloop
for (i=0;i<(unsigned int)count;i++) {
unsigned char tmp = buffer[i];
eax = (int) tmp ^ (ebx & 0xff);
ebx = ((int)ebx >> 8) & 0xffffff;
eax = extern_array[eax];
ebx ^= eax;
}
//done:
done:
// call getret
eax = second;
eax ^= ~ebx;
return eax;
// not ebx
// pop edi
// xor eax,ebx
// pop esi
// pop ebx
// pop ebp
// ret
//_memcheck2 ENDP
//_TEXT ENDS
//END
}