
Código:
(*
Autor: NvK
Nombre: SizeofAddr
Descripcion: Obtiene el peso de una region de memoria(por ej. de un API)
*)
function
SizeofAddr(hProc: THandle; Addr : Pointer) : uint;
var
mne : array [0..$8] of uchar;
total_bytes : uint;
lpNumberOfBytesRead : Dword;
begin
total_bytes := $0;
if (Addr=nil)or(hProc=0) then
Exit;
while (TRUE) do
begin
ReadProcessMemory(hProc, Addr, @mne, $08, lpNumberOfBytesRead);
ASM
INC DWORD PTR DS: &total_bytes
INC DWORD PTR DS: &Addr
END;
if (mne[0]=$E9) then
begin
if((mne[5]=$90) and (mne[6]=$90) or (mne[6]=$00)) then
begin
ASM
ADD DWORD PTR DS: &total_bytes, $4
END;
break;
end;
end;
if (mne[0]=$EB) then
begin
if((mne[2]=$90) and (mne[3]=$90)or (mne[3]=$00)) then
begin
ASM
INC DWORD PTR DS: &total_bytes
END;
break;
end;
end;
if((mne[0]=$C3) and (mne[1]=$FF) and (mne[2]=$FF)or
(mne[0]=$C3) and (mne[1]=$90) and (mne[2]=$90))
then
break;
if((mne[0]=$C9) and (mne[1]>$C3))then
begin
ASM
INC DWORD PTR DS: &total_bytes
END;
break;
end;
if((mne[0]=$C2) and (mne[1]>$00))then
begin
ASM
ADD DWORD PTR DS: &total_bytes, $2
END;
break;
end;
end;
Result:= total_bytes;
end;
Ejemplo de como usarla:
var
Handle : THandle;
Addr : Pointer;
FuncSize : Integer;
begin
Handle:= OpenProcess(PROCESS_ALL_ACCESS, false, 2668);
Addr:= GetProcAddress(GetModuleHandle('ntdll.dll'), 'NtQuerySystemInformation');
if Addr=nil then
Exit;
WriteLn( Format('NtQuerySystemInformation desde <ntdll.dll> dir. 0x%p'#13#10, [Addr]));
FuncSize:= SizeofAddr(Handle, Addr);
WriteLn('Tam. de direccion: ', FuncSize);
CloseHandle(Handle);
ReadLn;
end.
Como ven OpenProcess lleva 2668(que es el id del proceso a escanear para este ejemplo era el explorer.exe).Saludos.