能力值:
( LV15,RANK:440 )
|
-
-
9 楼
哈哈,改进成功了。就是一次读一页的内存,然后再匹配。用不到一秒的时间就可以找到两处特征码了。谢谢7楼的帮助。
BYTE CharacterCode[ 9 ] = {0x8B,0x4D,0xFC,0x89,0x41,0x14,0x8B,0x4D,0xfc};//locate the set hook call
BYTE CharacterCode2[8 ] = {0xB9,0x7,0,0,0,0x33,0xC0,0xFC};
BYTE code[ 2 ] = { 0xeb,0x47 };
BYTE code2[ 18 ] = {0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x33,0xc0};
BYTE buffer[ 4096 ];
void Patch( HANDLE hProcess )
{
BYTE mem[ 9 ]={0},*p,*p1,*base,*addr1,*addr2,*q_hook_proc;
DWORD retBytes;
int i,flag;
MEMORY_BASIC_INFORMATION mem_info;
flag = 0;
for( base = NULL;(DWORD)base <=0x1fff000;base+=0x1000 )
{
VirtualQueryEx( hProcess,base,&mem_info,sizeof( mem_info ) );
while( mem_info.State != MEM_COMMIT ||
//mem_info.State != MEM_RESERVE ||
mem_info.Type == MEM_IMAGE ||
mem_info.Type == MEM_MAPPED ||
(mem_info.Protect != PAGE_EXECUTE_READWRITE && mem_info.Protect != PAGE_READWRITE) )
{
base = /*(DWORD)mem_info.BaseAddress*/base+(DWORD)mem_info.RegionSize;
if( base > 0x1ffffff )return;
VirtualQueryEx( hProcess,base,&mem_info,sizeof( mem_info ) );
}
//printf("\n%x %x",base,mem_info.RegionSize );
for( p = base;(DWORD)p < (DWORD)base + mem_info.RegionSize;p+=4096)
{
if( !ReadProcessMemory( hProcess,p,buffer,4096,&retBytes ))
continue;
for( i = 0;i < 4096-8;i++)
{
if( memcmp( &buffer[i],CharacterCode2,8 ) == 0 )
{
q_hook_proc = p + i - 0x12;
printf("\nhookproc:%x\n",q_hook_proc );
}
}
for( i = 0;i < 4096 - 9;i++)
{
if( memcmp( &buffer[i],CharacterCode,9 ) == 0 )
{
printf("%x ",p+i );
if( flag == 0 ){
addr1 = p+i;
flag++;
continue;
}
if( flag == 1 ){
addr2 = p+i;
flag++;
break;
}
}
}
}
if( flag == 2 )break;
base = p-0x1000;
}
//这里为了验证特征码,暂时不修改内存。
/*
WriteProcessMemory( hProcess,(DWORD)addr2 + 13,code,2,NULL );
WriteProcessMemory( hProcess,(DWORD)addr2 - 18,code2,18,NULL );
WriteProcessMemory( hProcess,(DWORD)addr1 + 13,code,2,NULL );
WriteProcessMemory( hProcess,(DWORD)addr1 - 18,code2,18,NULL );
*/
}
至于思路的问题,大家好好看下代码,再结合上边的简略描述,我想理解起来应该不是太困难了。把代码中的patch函数改进之后,效率就更高了……
|