summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-11-13 23:46:38 -0500
committermidipix <writeonce@midipix.org>2016-11-13 23:56:16 -0500
commit62b9db8b87aef70ba5d76542ebcf90ae872ea940 (patch)
treecb103c0f470835aa6ee5ebb7e0aaadc689a4f1ef
parent8de972a241a38696697a0a0aedd2a3c44c059335 (diff)
downloadperk-62b9db8b87aef70ba5d76542ebcf90ae872ea940.tar.bz2
perk-62b9db8b87aef70ba5d76542ebcf90ae872ea940.tar.xz
logic: added pe_get_roffset_from_rva(), pe_get_rva_from_roffset().
-rw-r--r--include/perk/perk.h4
-rw-r--r--src/logic/pe_get_image_meta.c43
2 files changed, 47 insertions, 0 deletions
diff --git a/include/perk/perk.h b/include/perk/perk.h
index 988e0f6..3918d24 100644
--- a/include/perk/perk.h
+++ b/include/perk/perk.h
@@ -216,6 +216,10 @@ perk_api void pe_free_image_meta (struct pe_image_meta *);
perk_api int pe_get_named_section_index(const struct pe_image_meta *, const char * name);
perk_api int pe_get_block_section_index(const struct pe_image_meta *, const struct pe_block *);
+
+perk_api int pe_get_roffset_from_rva (const struct pe_image_meta *, uint32_t rva, uint32_t * roffset);
+perk_api int pe_get_rva_from_roffset (const struct pe_image_meta *, uint32_t roffset, uint32_t * rva);
+
perk_api int pe_get_expsym_by_name (const struct pe_image_meta *, const char * name, struct pe_expsym * optional);
perk_api int pe_get_expsym_by_index (const struct pe_image_meta *, unsigned index, struct pe_expsym * optional);
diff --git a/src/logic/pe_get_image_meta.c b/src/logic/pe_get_image_meta.c
index ee2b632..5f31a9a 100644
--- a/src/logic/pe_get_image_meta.c
+++ b/src/logic/pe_get_image_meta.c
@@ -59,6 +59,49 @@ int pe_get_block_section_index(const struct pe_image_meta * m, const struct pe_b
return -1;
}
+int pe_get_roffset_from_rva(const struct pe_image_meta * m, uint32_t rva, uint32_t * roffset)
+{
+ int i;
+ uint32_t low,high;
+
+ for (i=0; i<m->coff.num_of_sections; i++) {
+ low = m->sectbl[i].virtual_addr;
+ high = low + m->sectbl[i].virtual_size;
+
+ if ((rva >= low) && (rva < high)) {
+ *roffset = (rva - low) + m->sectbl[i].ptr_to_raw_data;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int pe_get_rva_from_roffset(const struct pe_image_meta * m, uint32_t roffset, uint32_t * rva)
+{
+ int i;
+ uint32_t low,high,ref;
+
+ for (i=0, ref=-1; i<m->coff.num_of_sections; i++) {
+ low = m->sectbl[i].ptr_to_raw_data;
+ high = low + m->sectbl[i].virtual_size;
+
+ if ((roffset >= low) && (roffset < high)) {
+ *rva = (roffset - low) + m->sectbl[i].virtual_addr;
+ return 0;
+ } else if (ref > low) {
+ ref = low;
+ }
+ }
+
+ if (roffset < ref) {
+ *rva = roffset;
+ return 0;
+ }
+
+ return -1;
+}
+
int pe_get_expsym_by_name(
const struct pe_image_meta * m,
const char * name,