summaryrefslogtreecommitdiff
path: root/src/internal
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/internal
parent99ace9f6a21b254216f60613e91191d902daeeb8 (diff)
downloadperk-c0fbae7a40c662ae77f59f5f919cd6b88e38a85d.tar.bz2
perk-c0fbae7a40c662ae77f59f5f919cd6b88e38a85d.tar.xz
initial commit.
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/perk_impl.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/internal/perk_impl.h b/src/internal/perk_impl.h
new file mode 100644
index 0000000..497ddbe
--- /dev/null
+++ b/src/internal/perk_impl.h
@@ -0,0 +1,64 @@
+#ifndef PERK_IMPL_H
+#define PERK_IMPL_H
+
+#include <stdint.h>
+#include <endian.h>
+
+/* internal structures */
+struct perk_ctx {
+ int argc;
+ char ** argv;
+ char ** envp;
+ const char * fname;
+ int status;
+ int flags;
+ int fd;
+ FILE * fout;
+ FILE * tmp;
+ struct pe_raw_image map;
+};
+
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+
+static inline uint16_t pe_read_short(const unsigned char * raw)
+{
+ return *(uint16_t *)raw;
+}
+
+static inline uint32_t pe_read_long(const unsigned char * raw)
+{
+ return *(uint32_t *)raw;
+}
+
+static inline uint64_t pe_read_quad(const unsigned char * raw)
+{
+ return *(uint64_t *)raw;
+}
+
+#else
+
+static inline uint16_t pe_read_short(unsigned char * raw)
+{
+ uint16_t x = *(uint16_t *)raw;
+ return x<<8 | x>>8;
+}
+
+static inline uint32_t pe_swap_long(uint32_t x)
+{
+ return x<<24 | (x<<8) & 0xff0000 | (x>>8) & 0xff00 | x>>24;
+}
+
+static inline uint32_t pe_read_long(unsigned char * raw)
+{
+ return pe_swap_long(*(uint32_t *)raw);
+}
+
+static inline uint64_t pe_read_quad(unsigned char * raw)
+{
+ uint64_t x = *(uint64_t *)raw;
+ return ((uint64_t)pe_swap_long(x)<<32) | pe_swap_long(x>>32);
+}
+
+#endif
+
+#endif