summaryrefslogtreecommitdiffhomepage
path: root/src/internal
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-05-08 23:22:07 -0400
committermidipix <writeonce@midipix.org>2015-05-08 23:22:07 -0400
commitfeffc7263bb2fd33ae467de2dd51f1ddbbb1b895 (patch)
tree983daec02a2d1833796ad8bd04d43d9b3ec42765 /src/internal
parent23329916dde5e0ffa056f74a81aeda1bfb7e54cc (diff)
downloadpemagine-feffc7263bb2fd33ae467de2dd51f1ddbbb1b895.tar.bz2
pemagine-feffc7263bb2fd33ae467de2dd51f1ddbbb1b895.tar.xz
initial commit.
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/pe_impl.c51
-rw-r--r--src/internal/pe_impl.h17
-rw-r--r--src/internal/pe_lib_entry_point.c6
3 files changed, 74 insertions, 0 deletions
diff --git a/src/internal/pe_impl.c b/src/internal/pe_impl.c
new file mode 100644
index 0000000..46069e8
--- /dev/null
+++ b/src/internal/pe_impl.c
@@ -0,0 +1,51 @@
+/*****************************************************************************/
+/* pemagination: a (virtual) tour into portable bits and executable bytes */
+/* Copyright (C) 2013,2014,2015 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.PEMAGINE. */
+/*****************************************************************************/
+
+#include <psxtypes/psxtypes.h>
+#include <pemagine/pemagine.h>
+#include "pe_impl.h"
+
+size_t pe_impl_strlen_ansi(const char * str)
+{
+ char * ch;
+ char * upper_bound;
+
+ /* sanity check */
+ upper_bound = (char *)str + PE_STR_MAX_SYMBOL_LEN_ALLOWED;
+
+ for (ch = (char *)str; (ch < upper_bound) && (*ch); ch++);
+
+ if (ch < upper_bound)
+ return (size_t)((intptr_t)ch - (intptr_t)str);
+ else
+ return -1;
+}
+
+
+size_t pe_impl_strlen_utf16(const wchar16_t * str)
+{
+ wchar16_t * wch;
+ wchar16_t * upper_bound;
+
+ /* sanity check */
+ upper_bound = (wchar16_t *)str + PE_STR_MAX_SYMBOL_LEN_ALLOWED;
+
+ for (wch = (wchar16_t *)str; (wch < upper_bound) && (*wch); wch++);
+
+ if (wch < upper_bound)
+ return (size_t)((intptr_t)wch - (intptr_t)str);
+ else
+ return -1;
+}
+
+
+wchar16_t pe_impl_utf16_char_to_lower(const wchar16_t c)
+{
+ if ((c >= 'A') && (c <= 'Z'))
+ return c + 'a' - 'A';
+ else
+ return c;
+}
diff --git a/src/internal/pe_impl.h b/src/internal/pe_impl.h
new file mode 100644
index 0000000..09e81c9
--- /dev/null
+++ b/src/internal/pe_impl.h
@@ -0,0 +1,17 @@
+#include <psxtypes/psxtypes.h>
+#include <pemagine/pemagine.h>
+
+#define PE_STR_MAX_SYMBOL_LEN_ALLOWED (uint32_t)0x10000
+
+#define IN_LOAD_ORDER_MODULE_LIST_OFFSET (intptr_t)0x00
+#define IN_MEMORY_ORDER_MODULE_LIST_OFFSET (intptr_t)0x01 * sizeof(struct pe_list_entry)
+#define IN_INITIALIZATION_ORDER_MODULE_LIST_OFFSET (intptr_t)0x02 * sizeof(struct pe_list_entry)
+
+struct pe_block {
+ uint32_t rva;
+ uint32_t size;
+};
+
+size_t pe_impl_strlen_ansi(const char * str);
+size_t pe_impl_strlen_utf16(const wchar16_t * str);
+wchar16_t pe_impl_utf16_char_to_lower(const wchar16_t c);
diff --git a/src/internal/pe_lib_entry_point.c b/src/internal/pe_lib_entry_point.c
new file mode 100644
index 0000000..efdaa26
--- /dev/null
+++ b/src/internal/pe_lib_entry_point.c
@@ -0,0 +1,6 @@
+#include <psxtypes/psxtypes.h>
+
+int __stdcall pe_lib_entry_point(void * hinstance, uint32_t reason, void * reserved)
+{
+ return 1;
+}