diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..31b844b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/libemu-0.2.0-ab48695.tar.gz diff --git a/libemu-01_no_rpath_python.patch b/libemu-01_no_rpath_python.patch new file mode 100644 index 0000000..1e0ec86 --- /dev/null +++ b/libemu-01_no_rpath_python.patch @@ -0,0 +1,17 @@ +Description: Don't use rpath in the Python bindings. + The Python bindings insist on using an rpath on /usr/lib. Nuke it. +Author: David Martínez Moreno +Forwarded: no +Last-Update: 2012-10-01 + +--- libemu-0.2.0+git20120122.orig/bindings/python/setup.py.in ++++ libemu-0.2.0+git20120122/bindings/python/setup.py.in +@@ -6,7 +6,7 @@ libemu = Extension('libemu', + sources = ['libemu_module.c'], + include_dirs = ['../../include'], + library_dirs = ['../../src/.libs'], +- extra_link_args=['-Wl,-rpath=@LIBDIR@'], ++ #extra_link_args=['-Wl,-rpath=@LIBDIR@'], + libraries = ['emu'], + ) + diff --git a/libemu-02_python_install_dir.patch b/libemu-02_python_install_dir.patch new file mode 100644 index 0000000..9853198 --- /dev/null +++ b/libemu-02_python_install_dir.patch @@ -0,0 +1,17 @@ +Description: Force installation of the Python module in debian/tmp. + Debian-centric patch to force the installation of this module into debian/tmp. +Author: David Martínez Moreno +Forwarded: not-needed +Last-Update: 2012-10-12 + +--- libemu-0.2.0+git20120122.orig/bindings/python/Makefile.am ++++ libemu-0.2.0+git20120122/bindings/python/Makefile.am +@@ -6,7 +6,7 @@ all: + python setup.py build + + install: all +- python setup.py install ++ python setup.py install --prefix=$(DESTDIR)$(prefix) + + clean: + python setup.py clean diff --git a/libemu-03_remove_rpath_and_fix_ldflags.patch b/libemu-03_remove_rpath_and_fix_ldflags.patch new file mode 100644 index 0000000..b4fd918 --- /dev/null +++ b/libemu-03_remove_rpath_and_fix_ldflags.patch @@ -0,0 +1,47 @@ +Description: Remove harmful rpath in LDFLAGS and fix logic for cargo. + Before this patch, libemu was searching for includes and also had an rpath + for libraries in /usr/local/lib. Also the logic for libcargo is wrong, as + makes the content of LDFLAGS empty if cargo is enabled but there are no + headers in the system. This was preventing proper hardening to be activated + in Debian. +Author: David Martínez Moreno +Forwarded: no +Reviewed-By: David Martínez Moreno +Last-Update: 2012-10-14 + +--- a/configure.ac ++++ b/configure.ac +@@ -20,12 +20,13 @@ + dnl Check for some target-specific stuff + case "$host" in + *-*-freebsd*) +- CPPFLAGS="$CPPFLAGS -I/usr/local/include -I/usr/src/contrib/file/" +- LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" ++ #CPPFLAGS="$CPPFLAGS -I/usr/local/include -I/usr/src/contrib/file/" ++ #LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" + ;; + *-*-linux*) +- CPPFLAGS="$CPPFLAGS -D _GNU_SOURCE -I/usr/local/include" +- LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" ++ #CPPFLAGS="$CPPFLAGS -D _GNU_SOURCE -I/usr/local/include" ++ CPPFLAGS="$CPPFLAGS -D _GNU_SOURCE" ++ #LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" + ;; + *-*-darwin*) + CPPFLAGS="$CPPFLAGS -I/opt/local/include" +@@ -170,6 +171,7 @@ + + if test x$enable_cargos = "xyes" ; then + OLD_CPPFLAGS=${CPPFLAGS}; ++ OLD_LDFLAGS=${LDFLAGS} + if test x$cargos_inc != "xno"; then + CPPFLAGS="${CPPFLAGS} -I${cargos_inc}" + fi +@@ -177,7 +179,6 @@ + AC_CHECK_HEADER(cargos-lib.h,[enable_cargos=yes],[enable_cargos=no]) + + if test x$enable_cargos = "xyes" ; then +- OLD_LDFLAGS=${LDFLAGS} + if test x$cargos_lib != "xno"; then + LDFLAGS="${LDFLAGS} -L${cargos_lib}" + fi diff --git a/libemu-04_recognize_gnu.patch b/libemu-04_recognize_gnu.patch new file mode 100644 index 0000000..238daa8 --- /dev/null +++ b/libemu-04_recognize_gnu.patch @@ -0,0 +1,25 @@ +Index: libemu/configure.ac +=================================================================== +--- libemu.orig/configure.ac 2013-07-10 19:47:55.333908583 +0200 ++++ libemu/configure.ac 2013-07-10 19:49:52.310985538 +0200 +@@ -19,15 +19,15 @@ + + dnl Check for some target-specific stuff + case "$host" in +-*-*-freebsd*) +- #CPPFLAGS="$CPPFLAGS -I/usr/local/include -I/usr/src/contrib/file/" +- #LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" +- ;; +-*-*-linux*) ++*-*-linux*|*-*-gnu*) + #CPPFLAGS="$CPPFLAGS -D _GNU_SOURCE -I/usr/local/include" + CPPFLAGS="$CPPFLAGS -D _GNU_SOURCE" + #LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" + ;; ++*-*-freebsd*) ++ #CPPFLAGS="$CPPFLAGS -I/usr/local/include -I/usr/src/contrib/file/" ++ #LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" ++ ;; + *-*-darwin*) + CPPFLAGS="$CPPFLAGS -I/opt/local/include" + LDFLAGS="$LDFLAGS -L/opt/local/lib" diff --git a/libemu-05_unused_local_typedefs.patch b/libemu-05_unused_local_typedefs.patch new file mode 100644 index 0000000..40671ec --- /dev/null +++ b/libemu-05_unused_local_typedefs.patch @@ -0,0 +1,80 @@ +Index: libemu/src/environment/win32/emu_env_w32.c +=================================================================== +--- libemu.orig/src/environment/win32/emu_env_w32.c 2013-07-03 21:39:06.281432486 +0200 ++++ libemu/src/environment/win32/emu_env_w32.c 2013-07-10 21:07:22.279324349 +0200 +@@ -382,7 +382,7 @@ + uint16_t Length; + uint16_t MaximumLength; + uint32_t Buffer; +- } UNICODE_STRING, *PUNICODE_STRING; ++ } UNICODE_STRING; //, *PUNICODE_STRING + + // PEB_LDR_DATA Structure + // http://msdn.microsoft.com/en-us/library/aa813708%28VS.85%29.aspx +@@ -392,10 +392,10 @@ + uint32_t Flink; + uint32_t Blink; + // struct _LIST_ENTRY *Blink; +- } LIST_ENTRY, *PLIST_ENTRY; //, *RESTRICTED_POINTER PRLIST_ENTRY; ++ } LIST_ENTRY; //, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY; + + typedef uint32_t PVOID; +- typedef unsigned char BYTE; ++ // typedef unsigned char BYTE; + typedef uint32_t ULONG; + + typedef struct _LDR_DATA_TABLE_ENTRY +@@ -415,7 +415,7 @@ + PVOID Reserved6; + }; + uint32_t TimeDateStamp; +- } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY; ++ } LDR_DATA_TABLE_ENTRY; //, *PLDR_DATA_TABLE_ENTRY; + + + // http://www.nirsoft.net/kernel_struct/vista/PEB_LDR_DATA.html +@@ -428,17 +428,17 @@ + /* 0x14 */ LIST_ENTRY InMemoryOrderModuleList; + /* 0x1c */ LIST_ENTRY InInitializationOrderModuleList; + /* 0x24 */ uint8_t EntryInProgress; +- } PEB_LDR_DATA, *PPEB_LDR_DATA; ++ } PEB_LDR_DATA; //, *PPEB_LDR_DATA; + +- struct _PEB_LDR_DATA peb_ldr_data; +- peb_ldr_data.InMemoryOrderModuleList.Flink = 0x00251ea0 + 0x1000 + offsetof(struct _LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); +- peb_ldr_data.InInitializationOrderModuleList.Flink = 0x00251ea0 + 0x1000 + offsetof(struct _LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks); ++ PEB_LDR_DATA peb_ldr_data; ++ peb_ldr_data.InMemoryOrderModuleList.Flink = 0x00251ea0 + 0x1000 + offsetof(LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); ++ peb_ldr_data.InInitializationOrderModuleList.Flink = 0x00251ea0 + 0x1000 + offsetof(LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks); + + emu_memory_write_block(mem, 0x00251ea0, &peb_ldr_data, sizeof(peb_ldr_data)); + + uint32_t magic_offset = 0x00251ea0+0x1000; + +- struct _LDR_DATA_TABLE_ENTRY tables[16]; ++ LDR_DATA_TABLE_ENTRY tables[16]; + memset(tables, 0, sizeof(tables)); + + char names[16][64]; +@@ -448,7 +448,7 @@ + for ( i=0; known_dlls[i].dllname != NULL; i++ ) + { + struct emu_env_w32_known_dll *from = known_dlls+i; +- struct _LDR_DATA_TABLE_ENTRY *to = tables+i; ++ LDR_DATA_TABLE_ENTRY *to = tables+i; + + to->DllBase = from->baseaddress; + to->BaseDllName.Length = (strlen(from->dllname) + strlen(".dll")) * 2 + 2; +@@ -456,10 +456,10 @@ + to->BaseDllName.Buffer = magic_offset + sizeof(tables) + i * 64; + + to->InMemoryOrderLinks.Blink = 0xaabbccdd; +- to->InMemoryOrderLinks.Flink = magic_offset + (i+1) * sizeof(struct _LDR_DATA_TABLE_ENTRY) + offsetof(struct _LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); ++ to->InMemoryOrderLinks.Flink = magic_offset + (i+1) * sizeof(struct _LDR_DATA_TABLE_ENTRY) + offsetof(LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); + + to->InInitializationOrderLinks.Blink = 0xa1b2c3d4; +- to->InInitializationOrderLinks.Flink = magic_offset + (i+1) * sizeof(struct _LDR_DATA_TABLE_ENTRY) + offsetof(struct _LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks); ++ to->InInitializationOrderLinks.Flink = magic_offset + (i+1) * sizeof(struct _LDR_DATA_TABLE_ENTRY) + offsetof(LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks); + + int j; + for( j=0;jdllname); j++ ) diff --git a/libemu-06_autoreconf.patch b/libemu-06_autoreconf.patch new file mode 100644 index 0000000..3b0b744 --- /dev/null +++ b/libemu-06_autoreconf.patch @@ -0,0 +1,27 @@ +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/configure.ac libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/configure.ac +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/configure.ac 2018-03-04 23:11:36.750143559 +0100 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/configure.ac 2018-03-04 23:06:29.411571103 +0100 +@@ -5,10 +5,11 @@ + + AC_PREREQ(2.59) + AC_INIT([libemu], [0.2.0], [nepenthesdev@gmail.com]) +-AM_INIT_AUTOMAKE([libemu], [0.2.0]) ++AM_INIT_AUTOMAKE([subdir-objects]) + AC_REVISION([$Id$]) + + AC_PREFIX_DEFAULT(/opt/libemu) ++AC_CONFIG_MACRO_DIRS([m4]) + AC_CONFIG_SRCDIR([include/emu/emu.h]) + AM_CONFIG_HEADER([config.h]) + # AM_MAINTAINER_MODE +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/Makefile.am libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/Makefile.am +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/Makefile.am 2013-04-10 21:32:25.000000000 +0200 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/Makefile.am 2018-03-04 23:05:17.886596611 +0100 +@@ -1,5 +1,7 @@ + # $Id$ + ++ACLOCAL_AMFLAGS= -I m4 ++ + AUTOMAKE_OPTIONS = foreign + + SUBDIRS = src include testsuite doc bindings tools diff --git a/libemu-07_emu_memory_free.patch b/libemu-07_emu_memory_free.patch new file mode 100644 index 0000000..01c0a98 --- /dev/null +++ b/libemu-07_emu_memory_free.patch @@ -0,0 +1,44 @@ +https://github.com/buffer/libemu/commit/9256d8dc460b15a1c05d19b2fd277939602145e1.patch +From 9256d8dc460b15a1c05d19b2fd277939602145e1 Mon Sep 17 00:00:00 2001 +From: Angelo Dell'Aera +Date: Fri, 10 Jun 2016 09:16:46 +0200 +Subject: [PATCH] Fixed bug in emu_memory_free + +--- + src/emu_memory.c | 16 +++++++++++++--- + 1 file changed, 13 insertions(+), 3 deletions(-) + +diff --git a/src/emu_memory.c b/src/emu_memory.c +index c2f2642..45ee83f 100644 +--- a/src/emu_memory.c ++++ b/src/emu_memory.c +@@ -171,16 +171,26 @@ void emu_memory_free(struct emu_memory *m) + int i, j; + + emu_breakpoint_free(m->breakpoint); +- ++ + for( i = 0; i < (1 << (32 - PAGESET_BITS - PAGE_BITS)); i++ ) + { + if( m->pagetable[i] != NULL ) + { + for( j = 0; j < PAGESET_SIZE; j++ ) +- if( m->pagetable[i][j] != NULL ) ++ if( m->pagetable[i][j] != NULL ) { + free(m->pagetable[i][j]); +- ++ m->pagetable[i][j] = NULL; ++ } ++ //free(m->pagetable[i]); ++ } ++ } ++ ++ for( i = 0; i < (1 << (32 - PAGESET_BITS - PAGE_BITS)); i++ ) ++ { ++ if( m->pagetable[i] != NULL ) ++ { + free(m->pagetable[i]); ++ m->pagetable[i] = NULL; + } + } + diff --git a/libemu-08_pkgconfigdir.patch b/libemu-08_pkgconfigdir.patch new file mode 100644 index 0000000..7c3a73d --- /dev/null +++ b/libemu-08_pkgconfigdir.patch @@ -0,0 +1,41 @@ +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.orig/configure.ac libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/configure.ac +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.orig/configure.ac 2018-03-22 21:48:54.248095763 +0100 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/configure.ac 2018-03-22 21:59:57.434006728 +0100 +@@ -23,21 +23,26 @@ + *-*-freebsd*) + #CPPFLAGS="$CPPFLAGS -I/usr/local/include -I/usr/src/contrib/file/" + #LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" ++ PKGCONFIGDIR="/usr/lib/pkgconfig" + ;; + *-*-linux*) + #CPPFLAGS="$CPPFLAGS -D _GNU_SOURCE -I/usr/local/include" + CPPFLAGS="$CPPFLAGS -D _GNU_SOURCE" + #LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" ++ PKGCONFIGDIR="/usr/lib/pkgconfig" + ;; + *-*-darwin*) + CPPFLAGS="$CPPFLAGS -I/opt/local/include" + LDFLAGS="$LDFLAGS -L/opt/local/lib" ++ PKGCONFIGDIR="/usr/local/lib/pkgconfig" + if test "$GCC" = "yes"; then + CFLAGS="$CFLAGS -no-cpp-precomp" + fi + ;; + esac + ++AC_SUBST([PKGCONFIGDIR]) ++ + # Checks for programs. + AC_PROG_CC + AC_PROG_MAKE_SET +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.orig/Makefile.am libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/Makefile.am +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.orig/Makefile.am 2018-03-22 21:48:54.247095778 +0100 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/Makefile.am 2018-03-22 21:50:15.297893338 +0100 +@@ -9,6 +9,6 @@ + + EXTRA_DIST = configure.ac CHANGES libemu.pc.in + +-pkgconfigdir = /usr/lib/pkgconfig/ ++pkgconfigdir = @PKGCONFIGDIR@ + pkgconfig_DATA = libemu.pc + diff --git a/libemu-09_pagesize.patch b/libemu-09_pagesize.patch new file mode 100644 index 0000000..c3c7c68 --- /dev/null +++ b/libemu-09_pagesize.patch @@ -0,0 +1,306 @@ +PAGE_SIZE definition can potentially collide with name from +/usr/include/bits/limits.h +/usr/include/sys/user.h +/usr/include/bits/xopen_lim.h +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/src/emu_memory.c libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/src/emu_memory.c +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/src/emu_memory.c 2018-03-22 22:28:11.673550718 +0100 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/src/emu_memory.c 2018-03-22 22:27:20.249304848 +0100 +@@ -37,16 +37,16 @@ + #include "emu/emu_breakpoint.h" + + +-#define PAGE_BITS 12 /* size of one page, 2^12 = 4096 */ +-#define PAGESET_BITS 10 /* number of pages in one pageset, 2^10 = 1024 */ ++#define EMU_PAGE_BITS 12 /* size of one page, 2^12 = 4096 */ ++#define EMU_PAGESET_BITS 10 /* number of pages in one pageset, 2^10 = 1024 */ + + +-#define PAGE_SIZE (1 << PAGE_BITS) +-#define PAGESET_SIZE (1 << PAGESET_BITS) ++#define EMU_PAGE_SIZE (1 << EMU_PAGE_BITS) ++#define EMU_PAGESET_SIZE (1 << EMU_PAGESET_BITS) + +-#define PAGESET(x) ((x) >> (PAGESET_BITS + PAGE_BITS)) +-#define PAGE(x) (((x) >> PAGE_BITS) & ((1 << PAGESET_BITS) - 1)) +-#define OFFSET(x) (((1 << PAGE_BITS) - 1) & (x)) ++#define EMU_PAGESET(x) ((x) >> (EMU_PAGESET_BITS + EMU_PAGE_BITS)) ++#define EMU_PAGE(x) (((x) >> EMU_PAGE_BITS) & ((1 << EMU_PAGESET_BITS) - 1)) ++#define OFFSET(x) (((1 << EMU_PAGE_BITS) - 1) & (x)) + + #define FS_SEGMENT_DEFAULT_OFFSET 0x7ffdf000 + +@@ -70,7 +70,7 @@ + #if 1 + /*static void emu_memory_debug_pagetable(struct emu_memory *m) + { +- int pagesets = 1 << (32 - PAGESET_BITS - PAGE_BITS); ++ int pagesets = 1 << (32 - EMU_PAGESET_BITS - EMU_PAGE_BITS); + int pagesets_used = 0; + + printf("*** memory debug\n"); +@@ -82,7 +82,7 @@ + if( m->pagetable[i] != NULL ) + { + printf(" pageset %d allocated at 0x%08x\n", i, (int)m->pagetable[i]); +- int pages = 1 << (PAGESET_BITS); ++ int pages = 1 << (EMU_PAGESET_BITS); + int pages_used = 0; + + for( j = 0; j < pages; j++ ) +@@ -107,14 +107,14 @@ + static void emu_memory_debug_addr(uint32_t addr) + { + printf("addr 0x%08x, pageset 0x%08x, page 0x%08x, offset 0x%08x\n", +- addr, PAGESET(addr), PAGE(addr), OFFSET(addr)); ++ addr, EMU_PAGESET(addr), EMU_PAGE(addr), OFFSET(addr)); + }*/ + #endif + + uint32_t emu_memory_get_usage(struct emu_memory *m) + { +- uint32_t usage = (1 << (32 - PAGE_BITS - PAGESET_BITS)) * sizeof(void *); /* pageset table */ +- int pagesets = 1 << (32 - PAGESET_BITS - PAGE_BITS); ++ uint32_t usage = (1 << (32 - EMU_PAGE_BITS - EMU_PAGESET_BITS)) * sizeof(void *); /* pageset table */ ++ int pagesets = 1 << (32 - EMU_PAGESET_BITS - EMU_PAGE_BITS); + + int i, j; + +@@ -122,12 +122,12 @@ + { + if( m->pagetable[i] != NULL ) + { +- usage += PAGESET_SIZE * sizeof(void *); +- int pages = 1 << (PAGESET_BITS); ++ usage += EMU_PAGESET_SIZE * sizeof(void *); ++ int pages = 1 << (EMU_PAGESET_BITS); + + for( j = 0; j < pages; j++ ) + if( m->pagetable[i][j] != NULL ) +- usage += PAGE_SIZE; ++ usage += EMU_PAGE_SIZE; + } + } + +@@ -145,12 +145,12 @@ + + em->emu = e; + +- em->pagetable = malloc((1 << (32 - PAGE_BITS - PAGESET_BITS)) * sizeof(void *)); ++ em->pagetable = malloc((1 << (32 - EMU_PAGE_BITS - EMU_PAGESET_BITS)) * sizeof(void *)); + if( em->pagetable == NULL ) + { + return NULL; + } +- memset(em->pagetable, 0, (1 << (32 - PAGE_BITS - PAGESET_BITS)) * sizeof(void *)); ++ memset(em->pagetable, 0, (1 << (32 - EMU_PAGE_BITS - EMU_PAGESET_BITS)) * sizeof(void *)); + + em->segment_table[s_fs] = FS_SEGMENT_DEFAULT_OFFSET; + +@@ -172,11 +172,11 @@ + + emu_breakpoint_free(m->breakpoint); + +- for( i = 0; i < (1 << (32 - PAGESET_BITS - PAGE_BITS)); i++ ) ++ for( i = 0; i < (1 << (32 - EMU_PAGESET_BITS - EMU_PAGE_BITS)); i++ ) + { + if( m->pagetable[i] != NULL ) + { +- for( j = 0; j < PAGESET_SIZE; j++ ) ++ for( j = 0; j < EMU_PAGESET_SIZE; j++ ) + if( m->pagetable[i][j] != NULL ) { + free(m->pagetable[i][j]); + m->pagetable[i][j] = NULL; +@@ -185,7 +185,7 @@ + } + } + +- for( i = 0; i < (1 << (32 - PAGESET_BITS - PAGE_BITS)); i++ ) ++ for( i = 0; i < (1 << (32 - EMU_PAGESET_BITS - EMU_PAGE_BITS)); i++ ) + { + if( m->pagetable[i] != NULL ) + { +@@ -202,11 +202,11 @@ + { + int i, j; + +- for( i = 0; i < (1 << (32 - PAGESET_BITS - PAGE_BITS)); i++ ) ++ for( i = 0; i < (1 << (32 - EMU_PAGESET_BITS - EMU_PAGE_BITS)); i++ ) + { + if( m->pagetable[i] != NULL ) + { +- for( j = 0; j < PAGESET_SIZE; j++ ) ++ for( j = 0; j < EMU_PAGESET_SIZE; j++ ) + if( m->pagetable[i][j] != NULL ) + free(m->pagetable[i][j]); + +@@ -214,7 +214,7 @@ + } + } + +- memset(m->pagetable, 0, (1 << (32 - PAGE_BITS - PAGESET_BITS)) * sizeof(void *)); ++ memset(m->pagetable, 0, (1 << (32 - EMU_PAGE_BITS - EMU_PAGESET_BITS)) * sizeof(void *)); + + m->segment_table[s_fs] = FS_SEGMENT_DEFAULT_OFFSET; + +@@ -223,9 +223,9 @@ + + static inline int page_is_alloc(struct emu_memory *em, uint32_t addr) + { +- if( em->pagetable[PAGESET(addr)] != NULL ) ++ if( em->pagetable[EMU_PAGESET(addr)] != NULL ) + { +- if( em->pagetable[PAGESET(addr)][PAGE(addr)] != NULL ) ++ if( em->pagetable[EMU_PAGESET(addr)][EMU_PAGE(addr)] != NULL ) + { + return -1; + } +@@ -236,31 +236,31 @@ + + static inline int page_alloc(struct emu_memory *em, uint32_t addr) + { +- if( em->pagetable[PAGESET(addr)] == NULL ) ++ if( em->pagetable[EMU_PAGESET(addr)] == NULL ) + { +- em->pagetable[PAGESET(addr)] = malloc(PAGESET_SIZE * sizeof(void *)); ++ em->pagetable[EMU_PAGESET(addr)] = malloc(EMU_PAGESET_SIZE * sizeof(void *)); + +- if( em->pagetable[PAGESET(addr)] == NULL ) ++ if( em->pagetable[EMU_PAGESET(addr)] == NULL ) + { + emu_errno_set(em->emu, ENOMEM); + emu_strerror_set(em->emu, "out of memory\n", addr); + return -1; + } + +- memset(em->pagetable[PAGESET(addr)], 0, PAGESET_SIZE * sizeof(void *)); ++ memset(em->pagetable[EMU_PAGESET(addr)], 0, EMU_PAGESET_SIZE * sizeof(void *)); + } + +- if( em->pagetable[PAGESET(addr)][PAGE(addr)] == NULL ) ++ if( em->pagetable[EMU_PAGESET(addr)][EMU_PAGE(addr)] == NULL ) + { +- em->pagetable[PAGESET(addr)][PAGE(addr)] = malloc(PAGE_SIZE); ++ em->pagetable[EMU_PAGESET(addr)][EMU_PAGE(addr)] = malloc(EMU_PAGE_SIZE); + +- if( em->pagetable[PAGESET(addr)][PAGE(addr)] == NULL ) ++ if( em->pagetable[EMU_PAGESET(addr)][EMU_PAGE(addr)] == NULL ) + { + emu_errno_set(em->emu, ENOMEM); + emu_strerror_set(em->emu, "out of memory\n", addr); + return -1; + } +- memset(em->pagetable[PAGESET(addr)][PAGE(addr)], 0, PAGE_SIZE); ++ memset(em->pagetable[EMU_PAGESET(addr)][EMU_PAGE(addr)], 0, EMU_PAGE_SIZE); + } + + return 0; +@@ -268,11 +268,11 @@ + + static inline void *translate_addr(struct emu_memory *em, uint32_t addr) + { +- if( em->pagetable[PAGESET(addr)] != NULL ) ++ if( em->pagetable[EMU_PAGESET(addr)] != NULL ) + { +- if( em->pagetable[PAGESET(addr)][PAGE(addr)] != NULL ) ++ if( em->pagetable[EMU_PAGESET(addr)][EMU_PAGE(addr)] != NULL ) + { +- return em->pagetable[PAGESET(addr)][PAGE(addr)] + OFFSET(addr); ++ return em->pagetable[EMU_PAGESET(addr)][EMU_PAGE(addr)] + OFFSET(addr); + } + } + +@@ -342,14 +342,14 @@ + return -1; + } + +- if (OFFSET(addr) + len <= PAGE_SIZE) ++ if (OFFSET(addr) + len <= EMU_PAGE_SIZE) + { + bcopy(address, dest, len); + return 0; + } + else + { +- uint32_t cb = PAGE_SIZE - OFFSET(addr); ++ uint32_t cb = EMU_PAGE_SIZE - OFFSET(addr); + bcopy(address, dest, cb); + return emu_memory_read_block(m, oaddr + cb, dest + cb, len - cb); + } +@@ -461,14 +461,14 @@ + address = translate_addr(m, addr); + } + +- if (OFFSET(addr) + len <= PAGE_SIZE) ++ if (OFFSET(addr) + len <= EMU_PAGE_SIZE) + { + bcopy(src, address, len); + return 0; + } + else + { +- uint32_t cb = PAGE_SIZE - OFFSET(addr); ++ uint32_t cb = EMU_PAGE_SIZE - OFFSET(addr); + bcopy(src, address, cb); + return emu_memory_write_block(m, oaddr + cb, src + cb, len - cb); + } +@@ -491,16 +491,16 @@ + /* make sure a memory block of size *len* is allocated at *addr* */ + /*int32_t emu_memory_alloc_at(struct emu_memory *m, uint32_t addr, size_t len) + { +- len += addr % PAGE_SIZE; +- addr = (addr >> PAGE_BITS) << PAGE_BITS; ++ len += addr % EMU_PAGE_SIZE; ++ addr = (addr >> EMU_PAGE_BITS) << EMU_PAGE_BITS; + + while( len > 0 ) + { +- if( len > PAGE_SIZE ) ++ if( len > EMU_PAGE_SIZE ) + { +- len -= PAGE_SIZE; ++ len -= EMU_PAGE_SIZE; + page_alloc(m, addr); +- addr += PAGE_SIZE; ++ addr += EMU_PAGE_SIZE; + } + else + { +@@ -516,9 +516,9 @@ + { + *addr = 0x00200000; + +- uint32_t pages = len / PAGE_SIZE; ++ uint32_t pages = len / EMU_PAGE_SIZE; + +- if( len % PAGE_SIZE != 0 ) ++ if( len % EMU_PAGE_SIZE != 0 ) + { + pages++; + } +@@ -530,7 +530,7 @@ + { + for( i = 0; i < pages; i++ ) + { +- if( page_is_alloc(m, *addr + i * PAGE_SIZE) != 0 ) ++ if( page_is_alloc(m, *addr + i * EMU_PAGE_SIZE) != 0 ) + { + break; + } +@@ -540,7 +540,7 @@ + { + for( i = 0; i < pages; i++ ) + { +- if( page_alloc(m, *addr + i * PAGE_SIZE) ) ++ if( page_alloc(m, *addr + i * EMU_PAGE_SIZE) ) + { + return -1; + } +@@ -549,7 +549,7 @@ + return 0; + } + +- *addr += len + PAGE_SIZE; ++ *addr += len + EMU_PAGE_SIZE; + } + + return -1; diff --git a/libemu-10_singlebyte.patch b/libemu-10_singlebyte.patch new file mode 100644 index 0000000..abf3169 --- /dev/null +++ b/libemu-10_singlebyte.patch @@ -0,0 +1,44 @@ +From d424e097b2a08fd0b837756192bc257344782009 Mon Sep 17 00:00:00 2001 +From: bwall +Date: Wed, 14 Oct 2015 21:45:56 -0700 +Subject: [PATCH] Resolving issue of single byte buffers causing floating point + exception + +--- + src/emu_hashtable.c | 5 +++++ + src/emu_shellcode.c | 6 ++++++ + 2 files changed, 11 insertions(+) + +diff --git a/src/emu_hashtable.c b/src/emu_hashtable.c +index 19d0cc1..416ec86 100644 +--- a/src/emu_hashtable.c ++++ b/src/emu_hashtable.c +@@ -93,6 +93,11 @@ void emu_hashtable_free(struct emu_hashtable *eh) + + struct emu_hashtable_item *emu_hashtable_search(struct emu_hashtable *eh, void *key) + { ++ if(eh->size == 0) ++ { ++ return NULL; ++ } ++ + uint32_t first_hash = eh->hash(key) % eh->size; + + struct emu_hashtable_bucket *ehb = eh->buckets[first_hash]; +diff --git a/src/emu_shellcode.c b/src/emu_shellcode.c +index 50041b4..21f143b 100644 +--- a/src/emu_shellcode.c ++++ b/src/emu_shellcode.c +@@ -475,6 +475,12 @@ int32_t emu_shellcode_test(struct emu *e, uint8_t *data, uint16_t size) + + uint32_t best_eip=0; + */ ++ // This check avoids a floating point exception further down the line ++ if(size < 2) ++ { ++ return -1; ++ } ++ + uint32_t offset; + struct emu_list_root *el; + el = emu_list_create(); diff --git a/libemu-11_tautology.patch b/libemu-11_tautology.patch new file mode 100644 index 0000000..7375aa1 --- /dev/null +++ b/libemu-11_tautology.patch @@ -0,0 +1,22 @@ +From 910f39fa0d9a18fc07ba2541c3757cc616d0ffeb Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Tue, 13 May 2014 17:54:18 +0200 +Subject: [PATCH] removed tautological condition + +--- + src/environment/win32/env_w32_dll_export_ws2_32_hooks.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/environment/win32/env_w32_dll_export_ws2_32_hooks.c b/src/environment/win32/env_w32_dll_export_ws2_32_hooks.c +index 3f9fe42..9bc7057 100644 +--- a/src/environment/win32/env_w32_dll_export_ws2_32_hooks.c ++++ b/src/environment/win32/env_w32_dll_export_ws2_32_hooks.c +@@ -369,7 +369,7 @@ int recv( + POP_DWORD(c, &flags); + + uint32_t xlen = len; +- if (xlen < 0 || xlen > 4096) ++ if (xlen > 4096) + { + + printf("BUG\n"); diff --git a/libemu-12_nullpointer.patch b/libemu-12_nullpointer.patch new file mode 100644 index 0000000..8f491ca --- /dev/null +++ b/libemu-12_nullpointer.patch @@ -0,0 +1,343 @@ +From 6c1a774e6d342912d646935432b426b4da6d3c93 Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 20:31:07 +0200 +Subject: [PATCH] fixing potential NULL pointer dereferences + +--- + tools/sctest/nanny.c | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/tools/sctest/nanny.c b/tools/sctest/nanny.c +index 7d41264..ee14dd9 100644 +--- a/tools/sctest/nanny.c ++++ b/tools/sctest/nanny.c +@@ -9,6 +9,10 @@ + struct nanny *nanny_new(void) + { + struct nanny *na = malloc(sizeof(struct nanny)); ++ if (NULL == na) ++ { ++ return NULL; ++ } + memset(na, 0, sizeof(struct nanny)); + + na->files = emu_hashtable_new(16, emu_hashtable_ptr_hash, emu_hashtable_ptr_cmp); +@@ -19,6 +23,10 @@ struct nanny *nanny_new(void) + struct nanny_file *nanny_add_file(struct nanny *na, const char *path, uint32_t *emu_file, FILE *real_file) + { + struct nanny_file *file = malloc(sizeof(struct nanny_file)); ++ if (NULL == file) ++ { ++ return NULL; ++ } + memset(file, 0, sizeof(struct nanny_file)); + + *emu_file = rand(); +From c3fb84dc99b01805c7f01d52527339dd58ceabbe Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 20:37:05 +0200 +Subject: [PATCH] fixing potential NULL pointer dereferences + +--- + src/environment/emu_env.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/src/environment/emu_env.c b/src/environment/emu_env.c +index 0183c80..02b9128 100644 +--- a/src/environment/emu_env.c ++++ b/src/environment/emu_env.c +@@ -5,7 +5,8 @@ + * + * + * Copyright (C) 2008 Paul Baecher & Markus Koetter +- * ++ * Copyright (C) 2016 tpltnt ++ * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 +@@ -34,6 +35,10 @@ + struct emu_env *emu_env_new(struct emu *e) + { + struct emu_env *env = malloc(sizeof(struct emu_env)); ++ if (NULL == env) ++ { ++ return NULL; ++ } + memset(env, 0, sizeof(struct emu_env)); + env->env.lin = emu_env_linux_new(e); + env->env.win = emu_env_w32_new(e); +From 5d88320054b642c6388a6af05cf397895b82e2d5 Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 20:44:55 +0200 +Subject: [PATCH] fixing potential NULL pointer dereference + +--- + src/emu_cpu.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/src/emu_cpu.c b/src/emu_cpu.c +index c244bf5..e95eb03 100644 +--- a/src/emu_cpu.c ++++ b/src/emu_cpu.c +@@ -5,6 +5,7 @@ + * + * + * Copyright (C) 2007 Paul Baecher & Markus Koetter ++ * Copyright (C) 2016 tpltnt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License +@@ -209,6 +210,11 @@ void emu_cpu_debug_print(struct emu_cpu *c) + + char *fmsg; + fmsg = (char *)malloc(32*3+1); ++ if (NULL == fmsg) ++ { ++ logDebug(c->emu, "allocating memory failed in emu_cpu_debug_print(struct emu_cpu *c)"); ++ return; ++ } + memset(fmsg, 0, 32*3+1); + int i; + for ( i=0;i<32;i++ ) +From b8c35bf2c3704fb8acc0501abc33be0a4d146c1c Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 21:25:01 +0200 +Subject: [PATCH] fixing potential NULL pointer dereference + +--- + src/emu_stack.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/emu_stack.c b/src/emu_stack.c +index 770ac4e..7370156 100644 +--- a/src/emu_stack.c ++++ b/src/emu_stack.c +@@ -5,6 +5,7 @@ + * + * + * Copyright (C) 2008 Paul Baecher & Markus Koetter ++ * Copyright (C) 2016 tpltnt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License +@@ -35,6 +36,10 @@ + struct emu_stack *emu_stack_new(void) + { + struct emu_stack *es = malloc(sizeof(struct emu_stack)); ++ if (NULL == es) ++ { ++ return NULL; ++ } + memset(es, 0, sizeof(struct emu_stack)); + return es; + } +From d41a3737ab62e9aaaabb791f8959c7cbd9d77a7a Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 21:28:54 +0200 +Subject: [PATCH] fixing potential NULL pointer dereference + +--- + src/emu_memory.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/emu_memory.c b/src/emu_memory.c +index c2f2642..d396ebe 100644 +--- a/src/emu_memory.c ++++ b/src/emu_memory.c +@@ -5,6 +5,7 @@ + * + * + * Copyright (C) 2007 Paul Baecher & Markus Koetter ++ * Copyright (C) 2016 tpltnt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License +@@ -368,6 +369,10 @@ int32_t emu_memory_read_string(struct emu_memory *m, uint32_t addr, struct emu_s + } + + s->data = malloc(i + 1); ++ if (NULL == s->data) ++ { ++ return -1; ++ } + memset(s->data, 0, i + 1); + s->size = i; + +From 23117b2b9cff6346feb944611c05cc723820a3ba Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 21:33:28 +0200 +Subject: [PATCH] fixing potential NULL pointer dereferences + +--- + tools/sctest/dot.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/tools/sctest/dot.c b/tools/sctest/dot.c +index 0d53dfa..dc4d579 100644 +--- a/tools/sctest/dot.c ++++ b/tools/sctest/dot.c +@@ -5,6 +5,7 @@ + * + * + * Copyright (C) 2007 Paul Baecher & Markus Koetter ++ * Copyright (C) 2016 tpltnt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License +@@ -75,6 +76,10 @@ + struct instr_vertex *instr_vertex_new(uint32_t theeip, const char *instr_string) + { + struct instr_vertex *iv = (struct instr_vertex *)malloc(sizeof(struct instr_vertex)); ++ if (NULL == iv) ++ { ++ return NULL; ++ } + memset(iv, 0, sizeof(struct instr_vertex)); + iv->eip = theeip; + iv->instr_string = emu_string_new(); +@@ -91,6 +96,10 @@ void instr_vertex_free(struct instr_vertex *iv) + struct instr_vertex *instr_vertex_copy(struct instr_vertex *from) + { + struct instr_vertex *iv = (struct instr_vertex *)malloc(sizeof(struct instr_vertex)); ++ if (NULL == iv) ++ { ++ return NULL; ++ } + memset(iv, 0, sizeof(struct instr_vertex)); + iv->eip = from->eip; + iv->instr_string = emu_string_new(); +From 0267a6f003b5e08069d8e266826865f42f939025 Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 21:51:23 +0200 +Subject: [PATCH] fixing a potential NULL pointer dereference + +--- + src/emu_memory.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/emu_memory.c b/src/emu_memory.c +index d396ebe..632a608 100644 +--- a/src/emu_memory.c ++++ b/src/emu_memory.c +@@ -368,6 +368,10 @@ int32_t emu_memory_read_string(struct emu_memory *m, uint32_t addr, struct emu_s + i++; + } + ++ if (NULL == s) ++ { ++ return -1; ++ } + s->data = malloc(i + 1); + if (NULL == s->data) + { +From d15e16cee40898dd035537a47b5e97c404387b83 Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 21:56:23 +0200 +Subject: [PATCH] fixing potential NULL pointer dereference + +--- + src/environment/win32/emu_env_w32_dll_export.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/environment/win32/emu_env_w32_dll_export.c b/src/environment/win32/emu_env_w32_dll_export.c +index ee5798c..29347b5 100644 +--- a/src/environment/win32/emu_env_w32_dll_export.c ++++ b/src/environment/win32/emu_env_w32_dll_export.c +@@ -5,6 +5,7 @@ + * + * + * Copyright (C) 2007 Paul Baecher & Markus Koetter ++ * Copyright (C) 2016 tpltnt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License +@@ -52,6 +53,10 @@ + struct emu_env_w32_dll_export *emu_env_w32_dll_export_new(void) + { + struct emu_env_w32_dll_export *exp = (struct emu_env_w32_dll_export *)malloc(sizeof(struct emu_env_w32_dll_export)); ++ if (NULL == exp) ++ { ++ return NULL; ++ } + memset(exp,0,sizeof(struct emu_env_w32_dll_export)); + return exp; + } +From 56ff307ea36b938a11151bb22432b1ab561d71ea Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 21:59:06 +0200 +Subject: [PATCH] fixing potential NULL pointer dereference + +--- + src/environment/win32/emu_env_w32_dll.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/src/environment/win32/emu_env_w32_dll.c b/src/environment/win32/emu_env_w32_dll.c +index 378431d..59dd280 100644 +--- a/src/environment/win32/emu_env_w32_dll.c ++++ b/src/environment/win32/emu_env_w32_dll.c +@@ -5,6 +5,7 @@ + * + * + * Copyright (C) 2007 Paul Baecher & Markus Koetter ++ * Copyright (C) 2016 tpltnt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License +@@ -37,8 +38,12 @@ + struct emu_env_w32_dll *emu_env_w32_dll_new(void) + { + struct emu_env_w32_dll *dll = (struct emu_env_w32_dll *)malloc(sizeof(struct emu_env_w32_dll)); ++ if (NULL == dll) ++ { ++ return NULL; ++ } + memset(dll,0,sizeof(struct emu_env_w32_dll)); +- return dll; ++ return dll; + } + + void emu_env_w32_dll_free(struct emu_env_w32_dll *dll) +From bdb14b443ff1b5294ecbc1ab7ba9b430b7ab2d50 Mon Sep 17 00:00:00 2001 +From: tpltnt +Date: Sat, 13 Aug 2016 22:05:00 +0200 +Subject: [PATCH] fixing potential NULL pointer dereferences + +--- + src/emu_track.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/src/emu_track.c b/src/emu_track.c +index 79a2545..e8749f1 100644 +--- a/src/emu_track.c ++++ b/src/emu_track.c +@@ -5,6 +5,7 @@ + * + * + * Copyright (C) 2007 Paul Baecher & Markus Koetter ++ * Copyright (C) 2016 tpltnt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License +@@ -40,6 +41,10 @@ + struct emu_track_and_source *emu_track_and_source_new(void) + { + struct emu_track_and_source *et = (struct emu_track_and_source *)malloc(sizeof(struct emu_track_and_source)); ++ if (NULL == et) ++ { ++ return NULL; ++ } + memset(et, 0, sizeof(struct emu_track_and_source)); + et->track.reg[esp] = 0xffffffff; + return et; +@@ -185,6 +190,10 @@ void emu_tracking_info_diff(struct emu_tracking_info *a, struct emu_tracking_inf + struct emu_tracking_info *emu_tracking_info_new(void) + { + struct emu_tracking_info *eti = malloc(sizeof(struct emu_tracking_info)); ++ if (NULL == eti) ++ { ++ return NULL; ++ } + memset(eti, 0, sizeof(struct emu_tracking_info)); + eti->reg[esp] = 0xffffffff; + return eti; diff --git a/libemu-13_unbundle_libdasm.patch b/libemu-13_unbundle_libdasm.patch new file mode 100644 index 0000000..1a9d085 --- /dev/null +++ b/libemu-13_unbundle_libdasm.patch @@ -0,0 +1,58 @@ +Unbundle the libdasm library and use the system library instead. +Author: Michal Ambroz +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/src/emu_cpu.c libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/src/emu_cpu.c +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/src/emu_cpu.c 2018-04-01 02:33:17.777374148 +0200 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/src/emu_cpu.c 2018-04-02 01:18:43.558830128 +0200 +@@ -438,7 +438,7 @@ + + #undef PREFIX_LOCK + +-#include "libdasm.h" ++#include + uint32_t dasm_print_instruction(uint32_t eip, uint8_t *data, uint32_t size, char *str) + { + INSTRUCTION inst; +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/src/Makefile.am libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/src/Makefile.am +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/src/Makefile.am 2013-04-10 21:32:25.000000000 +0200 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/src/Makefile.am 2018-04-01 02:38:30.224711454 +0200 +@@ -78,7 +78,7 @@ + libemu_la_SOURCES += functions/xchg.c + libemu_la_SOURCES += functions/xor.c + +-libemu_la_SOURCES += libdasm.c libdasm.h opcode_tables.h ++#libemu_la_SOURCES += libdasm.c libdasm.h opcode_tables.h + + libemu_la_SOURCES += environment/emu_env.c + libemu_la_SOURCES += environment/emu_profile.c +@@ -96,4 +96,4 @@ + libemu_la_SOURCES += environment/linux/env_linux_syscall_hooks.c + + +-libemu_la_LDFLAGS = -no-undefined -version-info @libemu_soname@ -export-symbols-regex "^emu_" ++libemu_la_LDFLAGS = -no-undefined -version-info @libemu_soname@ -export-symbols-regex "^emu_" -ldasm +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/testsuite/instrtree.c libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/testsuite/instrtree.c +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/testsuite/instrtree.c 2013-04-10 21:32:25.000000000 +0200 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/testsuite/instrtree.c 2018-04-01 02:44:22.130650811 +0200 +@@ -28,9 +28,9 @@ + + + #include ++#include + +-#include "../src/libdasm.c" +-#include "../src/libdasm.h" ++#include + /* JMPCall + const char scode[] = "\xfc\xbb\xbf\x05\xeb\xd0\xeb\x0c\x5e\x56\x31\x1e\xad\x01\xc3" + "\x85\xc0\x75\xf7\xc3\xe8\xef\xff\xff\xff\x43\x6f\x00\x97\x53"; +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/testsuite/Makefile.am libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/testsuite/Makefile.am +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9/testsuite/Makefile.am 2013-04-10 21:32:25.000000000 +0200 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/testsuite/Makefile.am 2018-04-01 02:42:41.528096139 +0200 +@@ -18,6 +18,7 @@ + + #instrtree_LDADD = ../src/libemu.la + instrtree_SOURCES = instrtree.c ++instrtree_LDADD = -ldasm + + hashtest_LDADD = ../src/libemu.la + hashtest_SOURCES = hashtest.c diff --git a/libemu-14_obsolete_m4.patch b/libemu-14_obsolete_m4.patch new file mode 100644 index 0000000..3cb6369 --- /dev/null +++ b/libemu-14_obsolete_m4.patch @@ -0,0 +1,72 @@ +diff --git a/configure.ac b/configure.ac +index dfe21f7..aa6fa3c 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -11,7 +11,7 @@ AC_REVISION([$Id$]) + AC_PREFIX_DEFAULT(/opt/libemu) + AC_CONFIG_MACRO_DIRS([m4]) + AC_CONFIG_SRCDIR([include/emu/emu.h]) +-AM_CONFIG_HEADER([config.h]) ++AC_CONFIG_HEADERS([config.h]) + # AM_MAINTAINER_MODE + + AC_CANONICAL_HOST +@@ -46,7 +46,8 @@ AC_SUBST([PKGCONFIGDIR]) + # Checks for programs. + AC_PROG_CC + AC_PROG_MAKE_SET +-AC_PROG_LIBTOOL ++#AC_PROG_LIBTOOL ++LT_INIT + + AC_CHECK_HEADERS([stdint.h stdlib.h string.h strings.h unistd.h]) + +diff --git a/configure.ac b/configure.ac +index aa6fa3c..fdf85e2 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -71,7 +71,16 @@ AC_C_INLINE + AC_TYPE_UID_T + AC_STRUCT_TM + AC_TYPE_SIZE_T +-AC_TYPE_SIGNAL ++AC_CACHE_CHECK([return type of signal handlers],[ac_cv_type_signal],[AC_COMPILE_IFELSE( ++[AC_LANG_PROGRAM([#include ++#include ++], ++ [return *(signal (0, 0)) (0) == 1;])], ++ [ac_cv_type_signal=int], ++ [ac_cv_type_signal=void])]) ++AC_DEFINE_UNQUOTED([RETSIGTYPE],[$ac_cv_type_signal],[Define as the return type of signal handlers ++ (`int' or `void').]) ++ + + + AC_CHECK_SIZEOF(long) +@@ -79,7 +90,16 @@ AC_CHECK_SIZEOF(off_t) + + # Checks for library functions. + AC_FUNC_ERROR_AT_LINE +-AC_TYPE_SIGNAL ++AC_CACHE_CHECK([return type of signal handlers],[ac_cv_type_signal],[AC_COMPILE_IFELSE( ++[AC_LANG_PROGRAM([#include ++#include ++], ++ [return *(signal (0, 0)) (0) == 1;])], ++ [ac_cv_type_signal=int], ++ [ac_cv_type_signal=void])]) ++AC_DEFINE_UNQUOTED([RETSIGTYPE],[$ac_cv_type_signal],[Define as the return type of signal handlers ++ (`int' or `void').]) ++ + AC_CHECK_FUNCS([strndup inet_ntoa memmove memset strdup strerror]) + + # library soname +@@ -98,7 +120,7 @@ dnl ************************************************** + + AC_MSG_CHECKING(for Large File System support) + AC_ARG_ENABLE(lfs, +- AC_HELP_STRING([--enable-lfs],[Turn on Large File System (default)]), ++ AS_HELP_STRING([--enable-lfs],[Turn on Large File System (default)]), + [case "$host" in + *-*-linux*) + case "${enableval}" in diff --git a/libemu-15_python2_build.patch b/libemu-15_python2_build.patch new file mode 100644 index 0000000..b4db621 --- /dev/null +++ b/libemu-15_python2_build.patch @@ -0,0 +1,28 @@ +As the Fedora distribution is aproaching to a date to replace python2 with +python3 there was removed the python link to use python2 by default. As during +build it is needed to specify which python version to use for compilation, +it would be nice to have a variable in a makefile to be able to parametrize +the python runtime used for build. +diff -ru libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.orig/bindings/python/Makefile.am libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/bindings/python/Makefile.am +--- libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.orig/bindings/python/Makefile.am 2018-09-04 14:57:37.065000000 +0000 ++++ libemu-ab48695b7113db692982a1839e3d6eb9e73e90a9.new/bindings/python/Makefile.am 2018-09-04 15:04:16.250000000 +0000 +@@ -1,15 +1,16 @@ + # $Id$ + + AUTOMAKE_OPTIONS = foreign ++PYTHON = python + + all: +- python setup.py build ++ $(PYTHON) setup.py build + + install: all +- python setup.py install --prefix=$(DESTDIR)$(prefix) ++ $(PYTHON) setup.py install --prefix=$(DESTDIR)$(prefix) + + clean: +- python setup.py clean ++ $(PYTHON) setup.py clean + + dist-clean: clean + diff --git a/libemu.spec b/libemu.spec new file mode 100644 index 0000000..b041628 --- /dev/null +++ b/libemu.spec @@ -0,0 +1,382 @@ +Name: libemu +Version: 0.2.0 +Summary: The x86 shell-code detection and emulation +# Group needed for EPEL +%global rel 10 + + +# libemu package licensed with GPLv2+ +# libdasm.c libdasm.h licensed as public domain do whatever - being bundled with libemu since at least 2006 effectively GPLv2+ +# the code is removed during build and unbundled libdasm library is used instead. +License: GPLv2+ +URL: https://github.com/DinoTools/libemu/ +# Other information sources: +# Original nepenthes site - is gone, but available from web archive +# http://libemu.mwcollect.org -> https://web.archive.org/web/20090122230505/http://libemu.mwcollect.org +# https://sourceforge.net/projects/nepenthes/files/libemu%20development/ +# http://downloads.sourceforge.net/project/nepenthes/libemu%20development/libemu/libemu-0.2.0.tar.gz +# Original dionaea site - is gone, but available from web archive +# http://libemu.carnivore.it/ -> https://web.archive.org/web/20150812195102/http://libemu.carnivore.it/ +# Debian libemu package +# https://packages.debian.org/search?searchon=sourcenames&keywords=libemu +# https://packages.debian.org/sid/libemu-dev +# Git repositories/forks +# https://github.com/DinoTools/libemu/ +# https://github.com/tpltnt/libemu +# https://github.com/buffer/libemu +# https://github.com/buffer/pylibemu +# https://github.com/buffer/phoneyc +# https://github.com/dzzie/SCDBG +# Win32 Libemu shim for using Unicorn Engine as a backend +# https://github.com/fireeye/unicorn-libemu-shim +# https://github.com/gento/libemu +# Paul Baecher +# https://baecher.github.io/ +# Markus Koetter +# https://www2.honeynet.org/2009/06/05/iteolih-is-this-worth-your-time/ +# https://www.honeynet.org/node/485 +# Articles +# http://resources.infosecinstitute.com/shellcode-detection-emulation-libemu/ +# https://www.aldeid.com/wiki/Dionaea/Installation + +# Version in Debian - 09bbeb583be41b96b9e8a5876a18ac698a77abfa +# http://http.debian.net/debian/pool/main/libe/libemu/libemu_0.2.0+git20120122.orig.tar.gz +#global gitdate 20120122 +#global commit 09bbeb583be41b96b9e8a5876a18ac698a77abfa + + + +%if 0%{?fedora} || ( 0%{?rhel} && 0%{?rhel} >= 7 ) +# libemu currently doesn't work with python3 +%global with_python3 0 +%endif + +# Exclude the private libemu in python sitearch dir +%global __provides_exclude_from ^(%{python2_sitearch}/.*\\.so$ +%if 0%{?with_python3} >= 0 +%global __provides_exclude_from ^(%{python2_sitearch}|%{python%{python3_pkgversion}_sitearch})/.*\\.so$ +%endif + + +# This stanza is needed for RHEL6 +%if 0%{?rhel} && 0%{?rhel} <= 6 +%{!?__python2: %global __python2 /usr/bin/python2} +%{!?python2_sitelib: %global python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")} +%{!?python2_sitearch: %global python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")} +%endif + + +%global gituser DinoTools +%global gitname libemu +# Current version +%global gitdate 20130410 +%global commit ab48695b7113db692982a1839e3d6eb9e73e90a9 +%global shortcommit %(c=%{commit}; echo ${c:0:7}) + + + +# Build source is tarball release=1 or git commit=0 +%global build_release 0 + +%if 0%{?build_release} > 0 +# Build from the targball release +Release: %{rel}%{?dist}.1 +Source0: https://github.com/%{gituser}/%{gitname}/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz + +%else +# Build from the git commit snapshot +# Not using the 0. on the beginning of release version as these are patches past version 0.2.0 +# Next release should be probably 0.3.0 +Release: %{rel}.%{gitdate}git%{shortcommit}%{?dist}.1 +Source0: https://github.com/%{gituser}/%{gitname}/archive/%{commit}/%{name}-%{version}-%{shortcommit}.tar.gz +%endif #build_release + + +# Patches 1-5 taken from the Debian package - author David Martínez Moreno +# and is licensed under the GPL version 2 or later + +# Remove the hardcoded rpath from python binding +# https://github.com/DinoTools/libemu/issues/3 +# https://github.com/DinoTools/libemu/pull/2 +Patch1: libemu-01_no_rpath_python.patch + +# Allow installing to DESTDIR for the python binding +# https://github.com/DinoTools/libemu/issues/5 +# https://github.com/DinoTools/libemu/pull/4 +Patch2: libemu-02_python_install_dir.patch + + +# Remove hardcoded rpath from configure.ac +# https://github.com/DinoTools/libemu/issues/6 +# https://github.com/DinoTools/libemu/pull/7 +Patch3: libemu-03_remove_rpath_and_fix_ldflags.patch + + +# Comment out unused typedefs +# https://github.com/DinoTools/libemu/issues/8 +# https://github.com/DinoTools/libemu/pull/9 +Patch5: libemu-05_unused_local_typedefs.patch + +# Debian patches not relevant for Fedora - +# - recognizing GNU as OS not needed for Fedora build +# Patch4: libemu-04_recognize_gnu.patch + +# Fix warnings during the autreconf +# https://github.com/DinoTools/libemu/issues/10 +# https://github.com/DinoTools/libemu/pull/11 +Patch6: libemu-06_autoreconf.patch + +# Fix memory leak in emu_memory_free +# https://github.com/buffer/libemu/commit/9256d8dc460b15a1c05d19b2fd277939602145e1.patch +Patch7: libemu-07_emu_memory_free.patch + +# Add configure option for pkgconfigdir +# https://github.com/buffer/libemu/commit/48466d2d0d641c8b2067a366600cd2b6a52ef01b +Patch8: libemu-08_pkgconfigdir.patch + +# fix potential name collision of PAGE_SIZE in emu_memory.c by renaming to EMU_PAGE_SIZE +# https://github.com/DinoTools/libemu/issues/14 +# https://github.com/DinoTools/libemu/pull/15 +Patch9: libemu-09_pagesize.patch + +# fix single byte buffers causing floating point exception +# https://github.com/bwall/libemu/commit/d424e097b2a08fd0b837756192bc257344782009.patch +# https://github.com/buffer/libemu/pull/1 +Patch10: libemu-10_singlebyte.patch + +# removed tautological condition +# https://github.com/tpltnt/libemu/commits/master +# https://github.com/tpltnt/libemu/commit/910f39fa0d9a18fc07ba2541c3757cc616d0ffeb.patch +Patch11: libemu-11_tautology.patch + +# fix potential null pointer dereferences +# https://github.com/DinoTools/libemu/issues/20 +# https://github.com/DinoTools/libemu/pull/19 +# From: +# https://github.com/tpltnt/libemu/commits/master +# https://github.com/tpltnt/libemu/commit/6c1a774e6d342912d646935432b426b4da6d3c93.patch +# https://github.com/tpltnt/libemu/commit/c3fb84dc99b01805c7f01d52527339dd58ceabbe.patch +# https://github.com/tpltnt/libemu/commit/5d88320054b642c6388a6af05cf397895b82e2d5.patch +# https://github.com/tpltnt/libemu/commit/b8c35bf2c3704fb8acc0501abc33be0a4d146c1c.patch +# https://github.com/tpltnt/libemu/commit/d41a3737ab62e9aaaabb791f8959c7cbd9d77a7a.patch +# https://github.com/tpltnt/libemu/commit/23117b2b9cff6346feb944611c05cc723820a3ba.patch +# https://github.com/tpltnt/libemu/commit/0267a6f003b5e08069d8e266826865f42f939025.patch +# https://github.com/tpltnt/libemu/commit/d15e16cee40898dd035537a47b5e97c404387b83.patch +# https://github.com/tpltnt/libemu/commit/56ff307ea36b938a11151bb22432b1ab561d71ea.patch +# https://github.com/tpltnt/libemu/commit/bdb14b443ff1b5294ecbc1ab7ba9b430b7ab2d50.patch +Patch12: libemu-12_nullpointer.patch + +# Unbundle the libdasm library and use the system-installed patch +# https://github.com/DinoTools/libemu/issues/24 +# https://github.com/DinoTools/libemu/pull/25 +Patch13: libemu-13_unbundle_libdasm.patch + +# Review found obsolete macros used +# https://github.com/DinoTools/libemu/issues/26 +# https://github.com/DinoTools/libemu/pull/27 +Patch14: libemu-14_obsolete_m4.patch + +# Parametrize python(2) binary used for building the extension +# https://github.com/DinoTools/libemu/pull/28 +Patch15: libemu-15_python2_build.patch + +BuildRequires: pkgconfig +BuildRequires: automake +BuildRequires: autoconf +BuildRequires: libtool +BuildRequires: git +BuildRequires: gettext-devel +BuildRequires: libdasm-devel +BuildRequires: python2-devel +BuildRequires: python2-setuptools + +%if 0%{?with_python3} +BuildRequires: python%{python3_pkgversion}-devel +BuildRequires: python%{python3_pkgversion}-setuptools +%endif + + + +%description +The libemu is a small library written in C offering basic x86 emulation and +shell-code detection using GetPC heuristics. Intended use is within network +intrusion/prevention detection and honeypots. + + + +%package devel +# ======================= devel package ============================== +Summary: Development files for the libemu x86 emulator +Requires: %{name}%{?_isa} = %{version}-%{release} + +%description devel +The %{name}-devel package contains libraries and header files for +developing applications that use %{name}. + + + +%package -n python2-libemu +# ======================= python2-libemu ============================= +Summary: Python2 binding to the libemu x86 emulator +Requires: %{name}%{?_isa} = %{version}-%{release} +%{?python_provide:%python_provide python2-%{name}} + + +%description -n python2-libemu +Python2 binding to the libemu x86 emulator. + + +%if 0%{?with_python3} +%package -n python3-libemu +# ======================= python3-libemu ============================= +Summary: Python3 binding to the libemu x86 emulator +Requires: %{name}%{?_isa} = %{version}-%{release} +%{?python_provide:%python_provide python%{python3_pkgversion}-%{name}} + + +%description -n python3-libemu +Python3 binding to the libemu x86 emulator. + +%endif #with_python3 + + + +%prep +# ======================= prep ======================================= + + +# Build from tarball release version +%if 0%{?build_release} > 0 +%autosetup -p 1 -n %{gitname}-%{version} -S git + +%else +# Build from git commit +%autosetup -p 1 -n %{gitname}-%{commit} -S git +%endif + +# Unbundle the libdasm library - rest is in patch13 +rm -f src/libdasm.c src/libdasm.h src/opcode_tables.h + +git commit -q -a -m "unbundle libdasm" + +# changes in macros in autoconf versions <= rhel6 +%if ( 0%{?rhel} && 0%{?rhel} <= 6 ) +sed -i 's|AC_CONFIG_MACRO_DIRS|AC_CONFIG_MACRO_DIR|; + ' configure.ac + +git commit -q -a -m "downgrade autoconf for rhel6" +%endif + + +%build +# ======================= build ====================================== + +# Create m4 directory if missing +[ -d m4 ] || mkdir m4 + +autoreconf --verbose --install --force --warnings=all + +%configure --enable-python-bindings + +#Build also for python3 +cp -r bindings/python bindings/python3 + +make %{?_smp_mflags} PYTHON=%{__python2} + +# Just to be sure rebuild with the Fedora hardening options +pushd bindings/python +%py2_build +popd + +%if 0%{?with_python3} +# Ignore the python3 build at this point +pushd bindings/python3 +%py3_build || touch python3_build_failed +popd +%endif #with_python3 + +%install +# ======================= install ==================================== +%make_install pkgconfigdir=%{_libdir}/pkgconfig PYTHON=%{__python2} + +# just to be on the safe side +pushd bindings/python +%py2_install +popd + +%if 0%{?with_python3} +# Ignore the python3 build at this point +pushd bindings/python3 +mkdir -p %{buildroot}/%{python3_sitearch} +%py3_install || touch %{buildroot}/%{python3_sitearch}/python3_install_failed +[ -f python3_build_failed ] && touch %{buildroot}/%{python3_sitearch}/python3_build_failed +popd +%endif + +# No static building allowed for Fedora +find %{buildroot} -name '*.la' -exec rm -f {} ';' +find %{buildroot} -name '*.a' -exec rm -f {} ';' + + +%ldconfig_scriptlets + +%files +# ======================= files ====================================== +%doc AUTHORS CHANGES README +%{_bindir}/sctest +%{_bindir}/scprofiler +%{_libdir}/*.so.* + +%files devel +%{_includedir}/* +%{_libdir}/*.so +%{_libdir}/pkgconfig/%{name}.pc +%{_mandir}/man3/%{name}.3* + + +%files -n python2-libemu +%{python2_sitearch}/* + +%if 0%{?with_python3} +%files -n python3-libemu +%{python3_sitearch}/* +%endif #with_python3 + +%changelog +* Fri Feb 01 2019 Fedora Release Engineering - 0.2.0-10.20130410gitab48695.1 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild + +* Tue Sep 04 2018 Michal Ambroz - 0.2.0-10.20130410gitab48695 +- patch to calling python2 explicitly during build of the python binding +- fixes FTBS due to missing python binary as part of switching to python3 + +* Fri Jul 13 2018 Fedora Release Engineering - 0.2.0-9.20130410gitab48695 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild + +* Tue Apr 03 2018 Michal Ambroz - 0.2.0-8.20130410gitab48695 +- use ldconfig_scriptlets +- fix release version number in the changelog +- fix obsolete m4 macros +- Exclude the private libemu in python sitearch dir +- show all warnings to autoreconf +- use autosetup+git for troubleshooting the patches + +* Mon Apr 02 2018 Michal Ambroz - 0.2.0-0.7.20130410gitab48695 +- unbundle the libdasm library and use system-installed one +- disable the python3 build for now + +* Mon Mar 26 2018 Michal Ambroz - 0.2.0-0.6.20130410gitab48695 +- fix ldconfig requirement to align with the glibc provide + +* Fri Mar 23 2018 Michal Ambroz - 0.2.0-0.5.20130410gitab48695 +- added missing dependency to python3-devel +- use the python{python3_pkgversion}-devel/setuptools to enable EPEL7 build + +* Thu Mar 22 2018 Michal Ambroz - 0.2.0-0.4.20130410gitab48695 +- spec clean-up +- prepare for the python3 support +- include patches from buffer github repository + +* Sun Mar 04 2018 Michal Ambroz - 0.2.0-0.1.20130410gitab48695 +- build for Fedora 27 + diff --git a/sources b/sources new file mode 100644 index 0000000..0f96b46 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (libemu-0.2.0-ab48695.tar.gz) = 4643b461144aff7f28c1c014f06c3cdeef663341bd36bbd20d95cb51ddf6a8a1f4c8b6818f65c2c7b6eedfe0efca0a3b8dc6766b9ff6e0e182f2347ce96abe8f