summaryrefslogtreecommitdiffhomepage
path: root/src/reader/pe_read_import_header.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-05-02 10:05:51 -0400
committermidipix <writeonce@midipix.org>2016-11-10 23:35:18 -0500
commitc0fbae7a40c662ae77f59f5f919cd6b88e38a85d (patch)
treead6aaca1b75a1f4b5e9ac533220e382f49489c94 /src/reader/pe_read_import_header.c
parent99ace9f6a21b254216f60613e91191d902daeeb8 (diff)
downloadperk-c0fbae7a40c662ae77f59f5f919cd6b88e38a85d.tar.bz2
perk-c0fbae7a40c662ae77f59f5f919cd6b88e38a85d.tar.xz
initial commit.
Diffstat (limited to 'src/reader/pe_read_import_header.c')
-rw-r--r--src/reader/pe_read_import_header.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/reader/pe_read_import_header.c b/src/reader/pe_read_import_header.c
new file mode 100644
index 0000000..7d71143
--- /dev/null
+++ b/src/reader/pe_read_import_header.c
@@ -0,0 +1,46 @@
+#include <endian.h>
+#include <string.h>
+
+#include <perk/perk.h>
+#include "perk_impl.h"
+
+int pe_read_import_header(const struct pe_import_hdr * p, struct pe_meta_import_hdr * m)
+{
+ #if (BYTE_ORDER == LITTLE_ENDIAN)
+
+ memcpy(m,p,sizeof(*p));
+
+ #else
+
+ m->import_lookup_tbl_rva = pe_read_long(p->import_lookup_tbl_rva);
+ m->time_date_stamp = pe_read_long(p->time_date_stamp);
+ m->forwarder_chain = pe_read_long(p>forwarder_chain);
+ m->name_rva = pe_read_long(p->name_rva);
+ m->import_addr_tbl_rva = pe_read_long(p>import_addr_tbl_rva);
+
+ #endif
+
+ m->name = 0;
+ m->aitems = 0;
+
+ return 0;
+};
+
+int pe_read_import_lookup_item(
+ const struct pe_import_lookup_item * p,
+ struct pe_meta_import_lookup_item * m,
+ uint32_t magic)
+{
+ switch (magic) {
+ case PE_MAGIC_PE32:
+ m->u.import_lookup_entry_64 = pe_read_long(p->u.import_lookup_entry_32);
+ return 0;
+
+ case PE_MAGIC_PE32_PLUS:
+ m->u.import_lookup_entry_64 = pe_read_quad(p->u.import_lookup_entry_64);
+ return 0;
+
+ default:
+ return PERK_BAD_IMAGE_TYPE;
+ }
+};