[PATCH 05/11] [DbgHelp]: extend the image (ELF/PE) scheme to get the RVA out of a section

Eric Pouech eric.pouech at orange.fr
Thu Mar 18 15:31:19 CDT 2010




A+
---

 dlls/dbghelp/elf_module.c    |   12 ++++++++++++
 dlls/dbghelp/image_private.h |   13 +++++++++++++
 dlls/dbghelp/pe_module.c     |   12 ++++++++++++
 3 files changed, 37 insertions(+), 0 deletions(-)


diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index 64b8481..4719aed 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -195,6 +195,18 @@ static void elf_end_find(struct image_file_map* fmap)
 }
 
 /******************************************************************
+ *		elf_get_map_rva
+ *
+ * Get the RVA of an ELF section
+ */
+DWORD_PTR elf_get_map_rva(const struct image_section_map* ism)
+{
+    if (ism->sidx < 0 || ism->sidx >= ism->fmap->u.elf.elfhdr.e_shnum)
+        return 0;
+    return ism->fmap->u.elf.sect[ism->sidx].shdr.sh_addr - ism->fmap->u.elf.elf_start;
+}
+
+/******************************************************************
  *		elf_get_map_size
  *
  * Get the size of an ELF section
diff --git a/dlls/dbghelp/image_private.h b/dlls/dbghelp/image_private.h
index be3ce69..8f0b060 100644
--- a/dlls/dbghelp/image_private.h
+++ b/dlls/dbghelp/image_private.h
@@ -116,12 +116,14 @@ extern BOOL         elf_find_section(struct image_file_map* fmap, const char* na
                                      unsigned sht, struct image_section_map* ism);
 extern const char*  elf_map_section(struct image_section_map* ism);
 extern void         elf_unmap_section(struct image_section_map* ism);
+extern DWORD_PTR    elf_get_map_rva(const struct image_section_map* ism);
 extern unsigned     elf_get_map_size(const struct image_section_map* ism);
 
 extern BOOL         pe_find_section(struct image_file_map* fmap, const char* name,
                                     struct image_section_map* ism);
 extern const char*  pe_map_section(struct image_section_map* psm);
 extern void         pe_unmap_section(struct image_section_map* psm);
+extern DWORD_PTR    pe_get_map_rva(const struct image_section_map* psm);
 extern unsigned     pe_get_map_size(const struct image_section_map* psm);
 
 static inline BOOL image_find_section(struct image_file_map* fmap, const char* name,
@@ -157,6 +159,17 @@ static inline void image_unmap_section(struct image_section_map* ism)
     }
 }
 
+static inline DWORD_PTR image_get_map_rva(struct image_section_map* ism)
+{
+    if (!ism->fmap) return 0;
+    switch (ism->fmap->modtype)
+    {
+    case DMT_ELF: return elf_get_map_rva(ism);
+    case DMT_PE:  return pe_get_map_rva(ism);
+    default: assert(0); return 0;
+    }
+}
+
 static inline unsigned image_get_map_size(struct image_section_map* ism)
 {
     if (!ism->fmap) return 0;
diff --git a/dlls/dbghelp/pe_module.c b/dlls/dbghelp/pe_module.c
index 6a059de..97ea3c8 100644
--- a/dlls/dbghelp/pe_module.c
+++ b/dlls/dbghelp/pe_module.c
@@ -148,6 +148,18 @@ void pe_unmap_section(struct image_section_map* ism)
 }
 
 /******************************************************************
+ *		pe_get_map_rva
+ *
+ * Get the RVA of an PE section
+ */
+DWORD_PTR pe_get_map_rva(const struct image_section_map* ism)
+{
+    if (ism->sidx < 0 || ism->sidx >= ism->fmap->u.pe.ntheader.FileHeader.NumberOfSections)
+        return 0;
+    return ism->fmap->u.pe.sect[ism->sidx].shdr.VirtualAddress;
+}
+
+/******************************************************************
  *		pe_get_map_size
  *
  * Get the size of an PE section






More information about the wine-patches mailing list