06-04-2010, 08:08 PM
لا أدري إن كنت طرحتها أم لا. العكس Rva2Offset:
بالتوفيق.
PHP كود :
//Convert Rva2Offset & Offset2Rva
IMAGE_SECTION_HEADER = packed record
Name : packed array [0..IMAGE_SIZEOF_SHORT_NAME-1] of Char;
PhysicalAddress : DWORD;
VirtualAddress : DWORD;
SizeOfRawData : DWORD;
PointerToRawData : DWORD;
PointerToRelocations : DWORD;
PointerToLinenumbers : DWORD;
NumberOfRelocations : WORD;
NumberOfLinenumbers : WORD;
Characteristics : DWORD;
end;
PIMAGE_DOS_HEADER = ^IMAGE_DOS_HEADER;
PIMAGE_NT_HEADERS = ^IMAGE_NT_HEADERS;
PIMAGE_SECTION_HEADER = ^IMAGE_SECTION_HEADER;
function rva2offset( pAddrOfFile: Pointer; dwRva : dword ):dword;
var i : byte;
sectionh : PIMAGE_SECTION_HEADER;
dosh : PIMAGE_DOS_HEADER;
peh : PIMAGE_NT_HEADERS;
begin
if dwRva = 0 then begin
result:=dwRva;
exit;
end;
dosh := PIMAGE_DOS_HEADER(pAddrOfFile);
peh := PIMAGE_NT_HEADERS(Longword(dosh) + Longword(dosh._lfanew));
Sectionh := PIMAGE_SECTION_HEADER(peh);
inc(pimage_nt_headers(Sectionh));
dwRva := dwRva - peh.OptionalHeader.ImageBase;
for i:=1 to peh.FileHeader.NumberOfSections do begin
if (dwRva >= Sectionh.VirtualAddress) and
(dwRva < (Sectionh.VirtualAddress + Sectionh.PhysicalAddress)) then break;
inc(sectionh);
end;
result:=dwRva - sectionh.VirtualAddress + sectionh.PointerToRawData;
end;
function offset2rva (pAddrOfFile: Pointer; dwRva : dword ):dword;
var i : byte;
sectionh : PIMAGE_SECTION_HEADER;
dosh : PIMAGE_DOS_HEADER;
peh : PIMAGE_NT_HEADERS;
temp: dword;
begin
if dwRva = 0 then begin
result:=dwRva;
exit;
end;
dosh := PIMAGE_DOS_HEADER(pAddrOfFile);
peh := PIMAGE_NT_HEADERS(Longword(dosh) + Longword(dosh.e_lfanew));
Sectionh := PIMAGE_SECTION_HEADER(peh);
inc(pimage_nt_headers(Sectionh));
inc (sectionh, peh.FileHeader.NumberOfSections);
for i:=peh.FileHeader.NumberOfSections downto 1 do begin
temp := dwRva + sectionh.VirtualAddress - sectionh.PointerToRawData;
if (temp >= Sectionh.VirtualAddress) and
(temp < (Sectionh.VirtualAddress + Sectionh.PhysicalAddress)) then break;
dec(sectionh);
end;
dwRva := temp + peh.OptionalHeader.ImageBase;
Result := dwRva;
end
اللهم احقن دماء المسلمين، لا تنسوهم بالدعاء...

