Ver Mensaje Individual
  #7  
Antiguo 28-06-2016
Avatar de AgustinOrtu
[AgustinOrtu] AgustinOrtu is offline
Miembro Premium
NULL
 
Registrado: ago 2013
Ubicación: Argentina
Posts: 1.858
Reputación: 17
AgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en bruto
Yo tambien soy un ignorante mas, pero solo por curiosidad, que valor de retorno obtienes de la llamada a la funciones:

VirtualAlloc,
VirtualProtect

Porque si alguna falla (evalua a False), entonces no deberia ser seguro continuar con tu codigo. Deberias llamar a GetLastError, ya que estas funciones no elevan excepciones por si solas.

Otra cosa, en la parte final de tu codigo, podrias refactorizarlo porque estas repitiendo codigo. Ademas, no entiendo porque retornas un Integer cuando luego la usas como un Boolean:


Código Delphi [-]
function DetectMemoryBP: Boolean;
var
  pMem, pAllocation: Pointer;
  SysInfo: TSystemInfo;
  oldprotect: dword;
  NullSize_T: SIZE_T;
label
  MemBpBeingDebugged;
begin
  Result := False;
  NullSize_T := 0;
  pMem := nil;
  GetSystemInfo(SysInfo);
  oldprotect := 0;
  pAllocation := VirtualAlloc(nil, sysinfo.dwPageSize, MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);

  if (pAllocation = nil) then
    Exit(False); // o podrias invocar a RaiseLastOsError 

  pMem := Pointer($C3);

  if not VirtualProtect(pAllocation, sysinfo.dwPageSize, PAGE_EXECUTE_READWRITE or PAGE_GUARD, @oldprotect) then
    Exit(False); // o podrias invocar a RaiseLastOsError 

  try
    asm
        mov     EAX, pAllocation
        push    MemBpBeingDebugged
        jmp     EAX // Exception or execution, which shall it be ?
    end;
  finally
    VirtualFree(pAllocation, NullSize_T, MEM_RELEASE);
  end;

  MemBpBeingDebugged:
  Result := True;
end;
Responder Con Cita