From edce1ecafc2cd0577648e4d65d4886bb8ffb649c Mon Sep 17 00:00:00 2001 From: Alexey Pavlov Date: Mon, 16 Jul 2018 10:03:08 +0300 Subject: [PATCH] unicorn: Build for python 3.7. Completely fix mingw build --- mingw-w64-unicorn/001-mingw.patch | 134 ++++++++++++++++++++++++++++++ mingw-w64-unicorn/PKGBUILD | 33 ++++---- 2 files changed, 150 insertions(+), 17 deletions(-) create mode 100644 mingw-w64-unicorn/001-mingw.patch diff --git a/mingw-w64-unicorn/001-mingw.patch b/mingw-w64-unicorn/001-mingw.patch new file mode 100644 index 0000000000..817c2ae2a3 --- /dev/null +++ b/mingw-w64-unicorn/001-mingw.patch @@ -0,0 +1,134 @@ +--- unicorn-1.0.1/Makefile.orig 2018-07-16 08:59:47.518887600 +0300 ++++ unicorn-1.0.1/Makefile 2018-07-16 09:04:38.977399900 +0300 +@@ -133,8 +133,7 @@ + BIN_EXT = .exe + UNICORN_QEMU_FLAGS += --disable-stack-protector + UNICORN_CFLAGS := $(UNICORN_CFLAGS:-fPIC=) +-$(LIBNAME)_LDFLAGS += -Wl,--output-def,unicorn.def +-DO_WINDOWS_EXPORT = 1 ++DO_WINDOWS_EXPORT = 0 + + # Linux, Darwin + else +@@ -147,7 +146,9 @@ + + ifeq ($(UNICORN_SHARED),yes) + ifneq ($(filter MINGW%,$(UNAME_S)),) +-LIBRARY = $(LIBNAME).$(EXT) ++LIBRARY = lib$(LIBNAME).$(EXT) ++LIBRARY_DLLA = lib$(LIBNAME).$(EXT).$(AR_EXT) ++$(LIBNAME)_LDFLAGS += -Wl,--out-implib=$(LIBRARY_DLLA) + else ifneq ($(filter CYGWIN%,$(UNAME_S)),) + LIBRARY = cyg$(LIBNAME).$(EXT) + LIBRARY_DLLA = lib$(LIBNAME).$(EXT).$(AR_EXT) +@@ -162,7 +163,7 @@ + + ifeq ($(UNICORN_STATIC),yes) + ifneq ($(filter MINGW%,$(UNAME_S)),) +-ARCHIVE = $(LIBNAME).$(AR_EXT) ++ARCHIVE = lib$(LIBNAME).$(AR_EXT) + # Cygwin, Linux, Darwin + else + ARCHIVE = lib$(LIBNAME).$(AR_EXT) +@@ -265,6 +266,10 @@ + ifneq ($(filter CYGWIN%,$(UNAME_S)),) + $(INSTALL_LIB) $(LIBRARY) $(DESTDIR)$(BINDIR) + $(INSTALL_DATA) $(LIBRARY_DLLA) $(DESTDIR)$(LIBDIR) ++else ifneq ($(filter MINGW%,$(UNAME_S)),) ++ mkdir -p $(DESTDIR)$(BINDIR) ++ $(INSTALL_LIB) $(LIBRARY) $(DESTDIR)$(BINDIR) ++ $(INSTALL_DATA) $(LIBRARY_DLLA) $(DESTDIR)$(LIBDIR) + else + $(INSTALL_LIB) $(LIBRARY) $(DESTDIR)$(LIBDIR) + endif +--- unicorn-1.0.1/bindings/python/setup.py.orig 2018-07-16 09:02:48.997206700 +0300 ++++ unicorn-1.0.1/bindings/python/setup.py 2018-07-16 09:03:35.625688600 +0300 +@@ -15,6 +15,7 @@ + from distutils.command.build import build + from distutils.command.sdist import sdist + from setuptools.command.bdist_egg import bdist_egg ++from sysconfig import _POSIX_BUILD + + SYSTEM = sys.platform + +@@ -67,8 +68,8 @@ + LIBRARY_FILE = "libunicorn.dylib" + STATIC_LIBRARY_FILE = 'libunicorn.a' + elif SYSTEM in ('win32', 'cygwin'): +- LIBRARY_FILE = "unicorn.dll" +- STATIC_LIBRARY_FILE = "unicorn.lib" ++ LIBRARY_FILE = "libunicorn.dll" ++ STATIC_LIBRARY_FILE = "libunicorn.a" + else: + LIBRARY_FILE = "libunicorn.so" + STATIC_LIBRARY_FILE = 'libunicorn.a' +@@ -125,10 +126,11 @@ + os.mkdir(LIBS_DIR) + + # copy public headers +- shutil.copytree(os.path.join(BUILD_DIR, 'include', 'unicorn'), os.path.join(HEADERS_DIR, 'unicorn')) ++ if not _POSIX_BUILD: ++ shutil.copytree(os.path.join(BUILD_DIR, 'include', 'unicorn'), os.path.join(HEADERS_DIR, 'unicorn')) + + # copy special library dependencies +- if SYSTEM == 'win32': ++ if SYSTEM == 'win32' and not _POSIX_BUILD: + got_all = True + for dll in ALL_WINDOWS_DLLS: + dllpath = os.path.join(sys.prefix, 'bin', dll) +@@ -174,15 +176,16 @@ + + subprocess.call(cmd, env=new_env) + +- shutil.copy(LIBRARY_FILE, LIBS_DIR) +- try: +- # static library may fail to build on windows if user doesn't have visual studio installed. this is fine. +- shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR) +- except: +- print('Warning: Could not build static library file! This build is not appropriate for a binary distribution') +- # enforce this +- if 'upload' in sys.argv: +- sys.exit(1) ++ if not _POSIX_BUILD: ++ shutil.copy(LIBRARY_FILE, LIBS_DIR) ++ try: ++ # static library may fail to build on windows if user doesn't have visual studio installed. this is fine. ++ shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR) ++ except: ++ print('Warning: Could not build static library file! This build is not appropriate for a binary distribution') ++ # enforce this ++ if 'upload' in sys.argv: ++ sys.exit(1) + os.chdir(cwd) + + +--- unicorn-1.0.1/samples/Makefile.orig 2018-07-16 09:14:10.223004100 +0300 ++++ unicorn-1.0.1/samples/Makefile 2018-07-16 09:15:38.343959400 +0300 +@@ -48,7 +48,7 @@ + + ifeq ($(UNICORN_STATIC),yes) + ifneq ($(filter MINGW%,$(UNAME_S)),) +-ARCHIVE = $(LIBDIR)/unicorn.$(AR_EXT) ++ARCHIVE = $(LIBDIR)/libunicorn.$(AR_EXT) + else ifneq ($(filter CYGWIN%,$(UNAME_S)),) + ARCHIVE = $(LIBDIR)/libunicorn.$(AR_EXT) + else +--- unicorn-1.0.1/bindings/python/unicorn/unicorn.py.orig 2018-07-16 09:18:04.230615900 +0300 ++++ unicorn-1.0.1/bindings/python/unicorn/unicorn.py 2018-07-16 09:23:24.151578600 +0300 +@@ -19,7 +19,7 @@ + range = xrange + + _lib = { 'darwin': 'libunicorn.dylib', +- 'win32': 'unicorn.dll', ++ 'win32': 'libunicorn.dll', + 'cygwin': 'cygunicorn.dll', + 'linux': 'libunicorn.so', + 'linux2': 'libunicorn.so' } +@@ -78,6 +78,7 @@ + # - last-gasp attempt at some hardcoded paths on darwin and linux + + _path_list = [pkg_resources.resource_filename(__name__, 'lib'), ++ sys.prefix + '/bin', + os.path.join(os.path.split(__file__)[0], 'lib'), + '', + distutils.sysconfig.get_python_lib(), diff --git a/mingw-w64-unicorn/PKGBUILD b/mingw-w64-unicorn/PKGBUILD index a8d0a6ca5c..f08e074268 100644 --- a/mingw-w64-unicorn/PKGBUILD +++ b/mingw-w64-unicorn/PKGBUILD @@ -6,8 +6,8 @@ pkgname=("${MINGW_PACKAGE_PREFIX}-unicorn" "${MINGW_PACKAGE_PREFIX}-python2-unicorn" "${MINGW_PACKAGE_PREFIX}-python3-unicorn") pkgver=1.0.1 -pkgrel=2 -pkgdesc='A lightweight multi-platform, multi-architecture CPU emulator framework based on QEMU' +pkgrel=3 +pkgdesc="A lightweight multi-platform, multi-architecture CPU emulator framework based on QEMU (mingw-w64)" url='http://www.unicorn-engine.org/index.html' arch=('any') license=('GPL2') @@ -17,11 +17,15 @@ makedepends=(python2 "${MINGW_PACKAGE_PREFIX}-python3" "${MINGW_PACKAGE_PREFIX}-python2-setuptools" "${MINGW_PACKAGE_PREFIX}-python3-setuptools") -source=("${_realname}-${pkgver}.tar.gz::https://github.com/unicorn-engine/unicorn/archive/${pkgver}.tar.gz") -sha512sums=('edfe1f7bfbc1d20f5b62232057e194a937bc09db686ef2efadb33a54605029a53426432cdb2a29511385aacdb9343b3b3091af50a1909098d7cf6db3429eb966') +source=("${_realname}-${pkgver}.tar.gz::https://github.com/unicorn-engine/unicorn/archive/${pkgver}.tar.gz" + 001-mingw.patch) +sha512sums=('edfe1f7bfbc1d20f5b62232057e194a937bc09db686ef2efadb33a54605029a53426432cdb2a29511385aacdb9343b3b3091af50a1909098d7cf6db3429eb966' + '842b1451888ceaf758d3f00f0eb595a3afa0fa18930666b28073d3f42641c71d18f6c45158e80f1b20f61271b86abc6b8524259ac63359a236abf5ec9c059514') prepare() { cd "${_realname}-${pkgver}" + patch -p1 -i ${srcdir}/001-mingw.patch + sed 's|-O3|-O2|g' -i Makefile qemu/configure sed 's|-g ||g' -i qemu/configure sed 's|UNICORN_DEBUG ?= yes|UNICORN_DEBUG ?= no|g' -i config.mk @@ -51,17 +55,11 @@ package_unicorn() { cd "${_realname}-${pkgver}" make DESTDIR="${pkgdir}" PREFIX="${MINGW_PREFIX}" install - install -dm755 "${pkgdir}/${MINGW_PREFIX}/bin" - mv "${pkgdir}/${MINGW_PREFIX}/lib/unicorn.dll" "${pkgdir}/${MINGW_PREFIX}/bin/libunicorn.dll" - mv "${pkgdir}/${MINGW_PREFIX}/lib/unicorn.a" "${pkgdir}/${MINGW_PREFIX}/lib/libunicorn.a" - install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}/${MINGW_PREFIX}/share/licenses/${pkgname}/COPYING" - install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING_GLIB" "${pkgdir}/${MINGW_PREFIX}/share/licenses/${pkgname}/COPYING_GLIB" + install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING" + install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING_GLIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING_GLIB" } -package_mingw-w64-i686-unicorn() { package_unicorn; } -package_mingw-w64-x86_64-unicorn() { package_unicorn; } - package_python2-unicorn() { depends=("${MINGW_PACKAGE_PREFIX}-python2" "${MINGW_PACKAGE_PREFIX}-unicorn") cd "${_realname}-${pkgver}/bindings/python" @@ -70,12 +68,9 @@ package_python2-unicorn() { python2 setup.py install --root="${pkgdir}" --prefix="${MINGW_PREFIX}" \ -O1 --skip-build - install -Dm 644 sample* shellcode.py -t "${pkgdir}/${MINGW_PREFIX}/share/doc/python2-${_realname}/samples" + install -Dm 644 sample* shellcode.py -t "${pkgdir}${MINGW_PREFIX}/share/doc/python2-${_realname}/samples" } -package_mingw-w64-i686-python2-unicorn() { package_python2-unicorn; } -package_mingw-w64-x86_64-python2-unicorn() { package_python2-unicorn; } - package_python3-unicorn() { depends=("${MINGW_PACKAGE_PREFIX}-python3" "${MINGW_PACKAGE_PREFIX}-unicorn") cd "${_realname}-${pkgver}/bindings/python3" @@ -84,8 +79,12 @@ package_python3-unicorn() { python3 setup.py install --root="${pkgdir}" --prefix="${MINGW_PREFIX}" \ -O1 --skip-build - install -Dm 644 sample* shellcode.py -t "${pkgdir}/${MINGW_PREFIX}/share/doc/python3-${_realname}/samples" + install -Dm 644 sample* shellcode.py -t "${pkgdir}${MINGW_PREFIX}/share/doc/python3-${_realname}/samples" } +package_mingw-w64-i686-unicorn() { package_unicorn; } +package_mingw-w64-x86_64-unicorn() { package_unicorn; } +package_mingw-w64-i686-python2-unicorn() { package_python2-unicorn; } +package_mingw-w64-x86_64-python2-unicorn() { package_python2-unicorn; } package_mingw-w64-i686-python3-unicorn() { package_python3-unicorn; } package_mingw-w64-x86_64-python3-unicorn() { package_python3-unicorn; }