bool CDetour::Remove ( BYTE *orig, BYTE *jmp, int iPatchType, int len ) { int iMinLen = 0; DWORD dwBack = 0; if ( !(iMinLen = GetDetourLen(iPatchType)) ) return false; if ( len != 0 && len < iMinLen ) return false; // Try and find the end of the instruction automatically if ( len == 0 ) { len = GetDetourLenAuto( jmp, iMinLen ); if ( len == 0 ) len = GetDetourLen( iPatchType ); if ( len == 0 || iMinLen == 0 ) return false; if ( len < iMinLen ) return false; } // Write the bytes @ the jmp back to the orig MEMORY_BASIC_INFORMATION mbi; VirtualQuery( (void *)orig, &mbi, sizeof(mbi) ); VirtualProtect( mbi.BaseAddress, mbi.RegionSize, PAGE_EXECUTE_READWRITE, &mbi.Protect ); memcpy( orig, jmp, len ); VirtualProtect( mbi.BaseAddress, mbi.RegionSize, mbi.Protect, &mbi.Protect ); FlushInstructionCache( GetCurrentProcess(), (void *)orig, len ); return true; }
void *CDetour::Create ( char *dllName, char *apiName, const BYTE *det, int iPatchType, int len ) { BYTE *jmp = NULL; BYTE *orig = NULL; int iMinLen = 0; if ( !(iMinLen = GetDetourLen(iPatchType)) ) return 0; if ( len != 0 && len < iMinLen ) return 0; // Get the API address m_hModule = GetModuleHandle( dllName ); m_dwAddress = ( DWORD ) GetProcAddress( m_hModule, apiName ); if ( !m_dwAddress || !det ) return 0; orig = (BYTE *)m_dwAddress; // Try and find the end of the instruction automatically if ( len == 0 ) { len = GetDetourLenAuto( orig, iMinLen ); if ( len < iMinLen ) return 0; } if ( !Detour(jmp, orig, det, iPatchType, len) ) return 0; return jmp - len; }
void *CDetour::Create ( BYTE *orig, const BYTE *det, int iPatchType, int len ) { BYTE *jmp = NULL; int iMinLen = 0; if ( !(iMinLen = GetDetourLen(iPatchType)) ) return 0; if ( len != 0 && len < iMinLen ) return 0; // Try and find the end of the instruction automatically if ( len == 0 ) { len = GetDetourLenAuto( orig, iMinLen ); if ( len < iMinLen ) return 0; } if ( !Detour(jmp, orig, det, iPatchType, len) ) return 0; return jmp - len; }
void *CDetour::Create(BYTE *orig, const BYTE *det, int iPatchType, int len) { BYTE *jmp = NULL; int iMinLen = 0; // Get minimum bytes to overwrite if(iPatchType == DETOUR_TYPE_OBS_RAND) iPatchType = (rand() % (DetourRandTypeHigh - DetourRandTypeLow + 1) + DetourRandTypeLow); if(!(iMinLen = GetDetourLen(iPatchType))) return 0; if(len != 0 && len < iMinLen) return 0; // Try and find the end of the instruction automatically if(len == 0) { len = GetDetourLenAuto(orig, iMinLen); if(len < iMinLen) return 0; } if(!Detour(jmp, orig, det, iPatchType, len)) return 0; IsHooked = true; return (jmp-len); }
bool CDetour::Remove ( char *dllName, char *apiName, BYTE *jmp, int iPatchType, int len ) { DWORD dwBack = 0; BYTE *orig = NULL; int iMinLen = 0; // Get the API address m_hModule = GetModuleHandle( dllName ); m_dwAddress = ( DWORD ) GetProcAddress( m_hModule, apiName ); if ( !m_dwAddress || !jmp ) return false; orig = (BYTE *)m_dwAddress; if ( !(iMinLen = GetDetourLen(iPatchType)) ) return false; if ( len != 0 && len < iMinLen ) return false; // Try and find the end of the instruction automatically if ( len == 0 ) { len = GetDetourLenAuto( jmp, iMinLen ); if ( len < iMinLen ) return 0; } // Write the bytes @ the jmp back to the orig VirtualProtect( orig, len, PAGE_READWRITE, &dwBack ); memcpy( orig, jmp, len ); VirtualProtect( orig, len, dwBack, &dwBack ); return true; }