Advertisement
HEX0x29A

RAW2VA

Apr 3rd, 2015
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.94 KB | None | 0 0
  1. function RAW2VA(pFile: PByte; RAW: DWORD): DWORD;
  2. var
  3.   i   : integer;
  4.   IDH : PImageDosHeader;
  5.   INTH: PImageNtHeaders;
  6.   ISH : PImageSectionHeader;
  7. begin
  8.   Result := $FFFFFFFF;
  9.   if pFile <> nil then
  10.   try
  11.     IDH  := PImageDosHeader(pFile);
  12.     INTH := PImageNtHeaders(DWORD(pFile) + IDH^._lfanew);
  13.     if ((LoWord(IDH^.e_magic) <> $5A4D {MZ})
  14.      or (LoWord(INTH^.Signature) <> $4550 {PE})) then
  15.       Exit;
  16.     ISH := PImageSectionHeader(DWORD(INTH) + SizeOf(TImageNtHeaders));
  17.     for i := 0 to INTH^.FileHeader.NumberOfSections - 1 do
  18.     begin
  19.       if (RAW >= ISH^.PointerToRawData)
  20.       and(RAW <= (ISH^.PointerToRawData+ISH^.SizeOfRawData)) then
  21.       begin
  22.         Result := ISH^.VirtualAddress + RAW - ISH^.PointerToRawData + INTH^.OptionalHeader.ImageBase;
  23.         Break;
  24.       end;
  25.       ISH := PImageSectionHeader(DWORD(ISH) + SizeOf(TImageSectionHeader));
  26.     end;
  27.   except
  28.     Result := $FFFFFFFF;
  29.   end;
  30. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement