imagehlp: add ImageRvaToSection() and ImageRvaToVa()
Marcus R. Brown
mrbrown at 0xd6.org
Fri Nov 21 06:04:55 CST 2003
My first Wine patch. Cheers.
* dlls/imagehlp/access.c:
Marcus R. Brown <mrbrown at 0xd6.org>
Implement ImageRvaToSection() and ImageRvaToVa().
Index: dlls/imagehlp/access.c
===================================================================
RCS file: /home/wine/wine/dlls/imagehlp/access.c,v
retrieving revision 1.18
diff -u -b -B -w -p -r1.18 access.c
--- dlls/imagehlp/access.c 5 Sep 2003 23:08:37 -0000 1.18
+++ dlls/imagehlp/access.c 21 Nov 2003 11:58:37 -0000
@@ -151,8 +151,22 @@ PIMAGE_NT_HEADERS WINAPI ImageNtHeader(P
PIMAGE_SECTION_HEADER WINAPI ImageRvaToSection(
PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva)
{
- FIXME("(%p, %p, %ld): stub\n", NtHeaders, Base, Rva);
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ PIMAGE_SECTION_HEADER pCurSection;
+ INT i;
+ WORD numSections;
+
+ TRACE("(%p, %p, %lx)\n", NtHeaders, Base, Rva);
+
+ pCurSection = IMAGE_FIRST_SECTION(NtHeaders);
+ numSections = NtHeaders->FileHeader.NumberOfSections;
+
+ for (i = 0; i < numSections; i++, pCurSection++) {
+ /* Is the RVA within this section? */
+ if (Rva >= pCurSection->VirtualAddress &&
+ Rva < (pCurSection->VirtualAddress + pCurSection->SizeOfRawData))
+ return pCurSection;
+ }
+
return NULL;
}
@@ -163,11 +177,23 @@ PVOID WINAPI ImageRvaToVa(
PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva,
PIMAGE_SECTION_HEADER *LastRvaSection)
{
- FIXME("(%p, %p, %ld, %p): stub\n",
- NtHeaders, Base, Rva, LastRvaSection
- );
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ PIMAGE_SECTION_HEADER pSection = NULL;
+
+ TRACE("(%p, %p, %lx, %p)\n", NtHeaders, Base, Rva, LastRvaSection);
+
+ if (!LastRvaSection || !(pSection = *LastRvaSection) ||
+ (Rva < pSection->VirtualAddress ||
+ Rva >= (pSection->VirtualAddress + pSection->SizeOfRawData)))
+ pSection = ImageRvaToSection(NtHeaders, Base, Rva);
+
+ if (!pSection)
return NULL;
+
+ if (LastRvaSection)
+ *LastRvaSection = pSection;
+
+ return (PVOID)((LPBYTE)Base +
+ (pSection->PointerToRawData - pSection->VirtualAddress + Rva));
}
/***********************************************************************
More information about the wine-patches
mailing list