Du Delphi à C++

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 17 mars 2005 à 12:16
cs_islanmao Messages postés 7 Date d'inscription mercredi 30 avril 2003 Statut Membre Dernière intervention 7 avril 2005 - 17 mars 2005 à 13:46
Question n'est pas de moi, je remets cause l'originale a sauté.


Bonjour tout le monde,


j'ai le code d'une procédure en delphi que j'ai trouvé sur le net, et je voudrais le changer en C++ , pourriez vous m'aider?

procedure PatchINT3;
var
NOP : Byte;
NTDLL: THandle;
BytesWritten: DWORD;
Address: Pointer;
begin
if Win32Platform <> VER_PLATFORM_WIN32_NT then Exit;
NTDLL := GetModuleHandle('NTDLL.DLL');
if NTDLL = 0 then Exit;
Address := GetProcAddress(NTDLL, 'DbgBreakPoint');
if Address = nil then Exit;
try
if Char(Address^) <> #$CC then Exit;

NOP := $90;
if WriteProcessMemory(GetCurrentProcess, Address, @NOP, 1, BytesWritten) and
(BytesWritten = 1) then
FlushInstructionCache(GetCurrentProcess, Address, 1);
except
//Do not panic if you see an EAccessViolation here, it is perfectly harmless!
on EAccessViolation do ;
else raise;
end;
end;

Merci :))

ciao...
BruNews, MVP VC++

3 réponses

ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
17 mars 2005 à 12:27
Je me disais aussi, le temps de préparer la réponse, la question avait disparrue

Voici une version C++ de ce que j'ai compris.

void PatchINT3()
{
OSVERSIONINFO osvi = {0};
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
if(osvi.dwPlatformId != VER_PLATFORM_WIN32_NT)
return;


HINSTANCE hInstance = GetModuleHandle("NTDLL.DLL");
if(hInstance == NULL)
return;


void* p = (void*)GetProcAddress(hInstance, "DbgBreakPoint");
if( p == NULL)
return;


__try
{
if( *((BYTE*)p) != 0xCC)
return;


BYTE nop = 0x90;
DWORD BytesWritten;
if(WriteProcessMemory(GetCurrentProcess(), p, @nop, 1, &BytesWritten) &&
BytesWritten == 1)
{
FlushInstructionCache(GetCurrentProcess(), p, 1);
}
}
__except((GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) ?
ECEPTION_EXECUTE_HANDLER :
EXCEPTION_CONTINUE_SEARCH )
{
}
}
0
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
17 mars 2005 à 12:28
petite erreur (le @ me semblais birzarre à taper aussi...)

WriteProcessMemory(GetCurrentProcess(), p, &nop, 1, &BytesWritten
0
cs_islanmao Messages postés 7 Date d'inscription mercredi 30 avril 2003 Statut Membre Dernière intervention 7 avril 2005
17 mars 2005 à 13:46
Merci bcp ;-) c hyper sympa
En fait j'ai des erreurs à la compilation, le heap est corrompu, c'est pour corriger ce beug ...
0
Rejoignez-nous