Skip to content

Commit

Permalink
- Improved the GitHub python binding workflow: (#2072)
Browse files Browse the repository at this point in the history
- Added fullMode input in workflow_dispatch
    - Take decision whether to build either in debug or release mode and if to build for all python versions according to the commit message patterns
    - Set proper artifact names
    - Removed not needed steps
    - Compacted some steps in order to leverage more the matrix feature
    - Bumped cibuildwheel action to 2.22.0
    - Run actual regress tests in place of sample scripts
- Specify optional test install in pyproject.toml with proper requirements
- Derive package version from git tags
- Add GENERATORS env var support in setup.py to specify cmake generator and minor refactoring
- Minor cleanup/refactoring for the regress test suite
- Marked some regress tests with skipIf to skip them in case of old python versions
- Marked some failing regress tests to be checked with skipIf
  • Loading branch information
Antelox authored Dec 29, 2024
1 parent 07e8162 commit 9cfd5cf
Show file tree
Hide file tree
Showing 85 changed files with 539 additions and 834 deletions.
315 changes: 116 additions & 199 deletions .github/workflows/build-wheels-publish.yml

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[build-system]
requires = ["setuptools", "build", "wheel"]
requires = ["setuptools", "build", "wheel", "versioningit"]
build-backend = "setuptools.build_meta"

[project]
name = "unicorn"
version = "2.1.1"
dynamic = ["version"]
requires-python = ">= 2.7, != 3.0.*, != 3.1.*, != 3.2.*, != 3.3.*, != 3.4.*, != 3.5.*, != 3.6.*"
authors = [
{ name = "Nguyen Anh Quynh", email = "quynh@gmail.com" },
Expand Down Expand Up @@ -33,9 +33,11 @@ Changelog = "https://github.com/unicorn-engine/unicorn/blob/master/ChangeLog"

[project.optional-dependencies]
test = [
"pytest",
"pytest-cov",
"capstone==6.0.0a2;python_version>'3.7'",
"capstone==5.0.1;python_version<='3.7'"
]

[tool.setuptools.packages.find]
include = ["unicorn*"]

[tool.versioningit]
17 changes: 9 additions & 8 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,25 @@ def build_libraries():

has_msbuild = shutil.which('msbuild') is not None
conf = 'Debug' if int(os.getenv('DEBUG', 0)) else 'Release'
cmake_args = ['cmake', '-B', BUILD_DIR, "-DCMAKE_BUILD_TYPE=" + conf]
if os.getenv("UNICORN_TRACER"):
cmake_args += ["-DUNICORN_TRACER=on"]
if conf == 'Debug':
cmake_args += ["-DUNICORN_LOGGING=on"]

if has_msbuild and sys.platform == 'win32':
generators = os.getenv('GENERATORS') or 'Visual Studio 16 2019'
plat = 'Win32' if platform.architecture()[0] == '32bit' else 'x64'

subprocess.check_call(['cmake', '-B', BUILD_DIR, '-G', "Visual Studio 16 2019", "-A", plat,
"-DCMAKE_BUILD_TYPE=" + conf], cwd=UC_DIR)
cmake_args += ['-G', generators, "-A", plat]
subprocess.check_call(cmake_args, cwd=UC_DIR)
subprocess.check_call(['msbuild', 'unicorn.sln', '-m', '-p:Platform=' + plat, '-p:Configuration=' + conf],
cwd=BUILD_DIR)

obj_dir = os.path.join(BUILD_DIR, conf)
shutil.copy(os.path.join(obj_dir, LIBRARY_FILE), LIBS_DIR)
shutil.copy(os.path.join(obj_dir, STATIC_LIBRARY_FILE), LIBS_DIR)
else:
cmake_args = ["cmake", '-B', BUILD_DIR, '-S', UC_DIR, "-DCMAKE_BUILD_TYPE=" + conf]
if os.getenv("TRACE"):
cmake_args += ["-DUNICORN_TRACER=on"]
if conf == "Debug":
cmake_args += ["-DUNICORN_LOGGING=on"]
cmake_args += ['-S', UC_DIR]
subprocess.check_call(cmake_args, cwd=UC_DIR)
threads = os.getenv("THREADS", "4")
subprocess.check_call(["cmake", "--build", ".", "-j" + threads], cwd=BUILD_DIR)
Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Sample code for ARM of Unicorn. Nguyen Anh Quynh <aquynh@gmail.com>
# Python sample ported by Loi Anh Tuan <loianhtuan@gmail.com>

from __future__ import print_function
from unicorn import *
from unicorn.arm_const import *

Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_arm64.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Sample code for ARM64 of Unicorn. Nguyen Anh Quynh <aquynh@gmail.com>
# Python sample ported by Loi Anh Tuan <loianhtuan@gmail.com>

from __future__ import print_function
from unicorn import *
from unicorn.arm64_const import *

Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_arm64eb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Python sample ported by Loi Anh Tuan <loianhtuan@gmail.com>
# AARCH64 Python sample ported by zhangwm <rustydaar@gmail.com>

from __future__ import print_function
from unicorn import *
from unicorn.arm64_const import *

Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_armeb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# Sample code for ARM big endian of Unicorn. zhangwm <rustydaar@gmail.com>

from __future__ import print_function
from unicorn import *
from unicorn.arm_const import *

Expand Down
4 changes: 0 additions & 4 deletions bindings/python/tests/test_ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Sample code for Unicorn.
# By Lazymio(@wtdcode), 2021

import pytest
import sys
from unicorn import *
from unicorn.x86_const import *
from datetime import datetime
Expand Down Expand Up @@ -36,7 +34,6 @@ def time_emulation(uc, start, end):


# TODO: Check if worth adapting the ctl_request_cache method for py2 bindings
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
def test_uc_ctl_tb_cache():
# Initialize emulator in X86-32bit mode
uc = Uc(UC_ARCH_X86, UC_MODE_32)
Expand Down Expand Up @@ -84,7 +81,6 @@ def trace_tcg_sub(uc, address, arg1, arg2, size, data):


# TODO: Check if worth adapting the hook_add method for py2 bindings
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
def test_uc_ctl_exits():
uc = Uc(UC_ARCH_X86, UC_MODE_32)
addr = 0x1000
Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_m68k.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Sample code for ARM of Unicorn. Nguyen Anh Quynh <aquynh@gmail.com>
# Python sample ported by Loi Anh Tuan <loianhtuan@gmail.com>

from __future__ import print_function
from unicorn import *
from unicorn.m68k_const import *

Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_mips.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Sample code for MIPS of Unicorn. Nguyen Anh Quynh <aquynh@gmail.com>
# Python sample ported by Loi Anh Tuan <loianhtuan@gmail.com>

from __future__ import print_function
from unicorn import *
from unicorn.mips_const import *

Expand Down
3 changes: 0 additions & 3 deletions bindings/python/tests/test_network_auditing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Unicorn sample for auditing network connection and file handling in shellcode.
# Nguyen Tan Cong <shenlongbk@gmail.com>

from __future__ import print_function
import pytest
import struct
import uuid
from unicorn import *
Expand Down Expand Up @@ -361,7 +359,6 @@ def hook_intr(uc, intno, user_data):
print_sockcall(msg)


@pytest.mark.parametrize("code", [X86_SEND_ETCPASSWD, X86_BIND_TCP, X86_REVERSE_TCP, X86_REVERSE_TCP_2])
# Test X86 32 bit
def test_i386(code):
global fd_chains
Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_ppc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# Sample code for PPC of Unicorn. Nguyen Anh Quynh <aquynh@gmail.com>

from __future__ import print_function
from unicorn import *
from unicorn.ppc_const import *

Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_riscv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# Sample code for RISCV of Unicorn. Nguyen Anh Quynh <aquynh@gmail.com>

from __future__ import print_function
from unicorn import *
from unicorn.riscv_const import *

Expand Down
4 changes: 0 additions & 4 deletions bindings/python/tests/test_shellcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Nguyen Anh Quynh <aquynh@gmail.com>
# KaiJern Lau <kj@theshepherdlab.io>

from __future__ import print_function
import pytest
from unicorn import *
from unicorn.x86_const import *

Expand Down Expand Up @@ -134,8 +132,6 @@ def hook_syscall64(mu, user_data):
mu.emu_stop()


@pytest.mark.parametrize("mode,code",
[(UC_MODE_32, X86_CODE32_SELF), (UC_MODE_32, X86_CODE32), (UC_MODE_64, X86_CODE64)])
# Test X86 32 bit
def test_i386(mode, code):
if mode == UC_MODE_32:
Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_sparc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Sample code for SPARC of Unicorn. Nguyen Anh Quynh <aquynh@gmail.com>
# Python sample ported by Loi Anh Tuan <loianhtuan@gmail.com>

from __future__ import print_function
from unicorn import *
from unicorn.sparc_const import *

Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_tricore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Copyright 2022 Aptiv
"""

from __future__ import print_function
from unicorn import *
from unicorn.tricore_const import *

Expand Down
1 change: 0 additions & 1 deletion bindings/python/tests/test_x86.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# Sample code for X86 of Unicorn. Nguyen Anh Quynh <aquynh@gmail.com>

from __future__ import print_function
import pickle
from unicorn import *
from unicorn.x86_const import *
Expand Down
3 changes: 0 additions & 3 deletions tests/regress/arm64_reg_rw_w0_w30.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/python

import regress

from unicorn import *
from unicorn.arm64_const import *

Expand Down
83 changes: 40 additions & 43 deletions tests/regress/arm_bx_unmapped.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

import regress

from unicorn import *
from unicorn.arm_const import *


MAIN_ADDRESS = 0x8d68
ADDRESS = MAIN_ADDRESS & ~(0x1000 - 1)
STACK_ADDR = ADDRESS + 0x1000
Expand All @@ -15,51 +12,51 @@ def runTest(self):
# code to be emulated
code = {
0x8cd4: (
b'\x04\xb0\x2d\xe5' # 8cd4 push {r11}
b'\x00\xb0\x8d\xe2' # 8cd8 add r11, sp, #0
b'\x0f\x30\xa0\xe1' # 8cdc mov r3, pc
b'\x03\x00\xa0\xe1' # 8ce0 mov r0, r3
b'\x00\xd0\x4b\xe2' # 8ce4 sub sp, r11, #0
b'\x04\xb0\x9d\xe4' # 8ce8 pop {r11}
b'\x1e\xff\x2f\xe1' # 8cec bx lr
b'\x04\xb0\x2d\xe5' # 8cd4 push {r11}
b'\x00\xb0\x8d\xe2' # 8cd8 add r11, sp, #0
b'\x0f\x30\xa0\xe1' # 8cdc mov r3, pc
b'\x03\x00\xa0\xe1' # 8ce0 mov r0, r3
b'\x00\xd0\x4b\xe2' # 8ce4 sub sp, r11, #0
b'\x04\xb0\x9d\xe4' # 8ce8 pop {r11}
b'\x1e\xff\x2f\xe1' # 8cec bx lr
),
0x8cf0: (
b'\x04\xb0\x2d\xe5' # 8cf0 push {r11}
b'\x00\xb0\x8d\xe2' # 8cf4 add r11, sp, #0
b'\x04\x60\x2d\xe5' # 8cf8 push {r6}
b'\x01\x60\x8f\xe2' # 8cfc add r6, pc, $1
b'\x16\xff\x2f\xe1' # 8d00 bx r6
# .thumb
b'\x7b\x46' # 8d04 mov r3, pc
b'\x03\xf1\x08\x03' # 8d06 add r3, $0x8 # elicn: used to be $0x4 but it kept failing
b'\x08\xb4' # 8d0a push {r3}
b'\x00\xbd' # 8d0c pop {pc}
b'\x00\x00' # 8d0e (alignment)
# .arm
b'\x04\x60\x9d\xe4' # 8d10 pop {r6}
b'\x03\x00\xa0\xe1' # 8d14 mov r0, r3
b'\x00\xd0\x4b\xe2' # 8d18 sub sp, r11, #0
b'\x04\xb0\x9d\xe4' # 8d1c pop {r11}
b'\x1e\xff\x2f\xe1' # 8d20 bx lr
b'\x04\xb0\x2d\xe5' # 8cf0 push {r11}
b'\x00\xb0\x8d\xe2' # 8cf4 add r11, sp, #0
b'\x04\x60\x2d\xe5' # 8cf8 push {r6}
b'\x01\x60\x8f\xe2' # 8cfc add r6, pc, $1
b'\x16\xff\x2f\xe1' # 8d00 bx r6
# .thumb
b'\x7b\x46' # 8d04 mov r3, pc
b'\x03\xf1\x08\x03' # 8d06 add r3, $0x8 # elicn: used to be $0x4 but it kept failing
b'\x08\xb4' # 8d0a push {r3}
b'\x00\xbd' # 8d0c pop {pc}
b'\x00\x00' # 8d0e (alignment)
# .arm
b'\x04\x60\x9d\xe4' # 8d10 pop {r6}
b'\x03\x00\xa0\xe1' # 8d14 mov r0, r3
b'\x00\xd0\x4b\xe2' # 8d18 sub sp, r11, #0
b'\x04\xb0\x9d\xe4' # 8d1c pop {r11}
b'\x1e\xff\x2f\xe1' # 8d20 bx lr
),
0x8d24: ( # elicn: used to be 0x8d20 but it caused this block to overlap with the previous one
b'\x04\xb0\x2d\xe5' # 8d24 push {r11}
b'\x00\xb0\x8d\xe2' # 8d28 add r11, sp, #0
b'\x0e\x30\xa0\xe1' # 8d2c mov r3, lr
b'\x03\x00\xa0\xe1' # 8d20 mov r0, r3
b'\x00\xd0\x4b\xe2' # 8d34 sub sp, r11, #0
b'\x04\xb0\x9d\xe4' # 8d38 pop {r11}
b'\x1e\xff\x2f\xe1' # 8d3c bx lr
0x8d24: ( # elicn: used to be 0x8d20 but it caused this block to overlap with the previous one
b'\x04\xb0\x2d\xe5' # 8d24 push {r11}
b'\x00\xb0\x8d\xe2' # 8d28 add r11, sp, #0
b'\x0e\x30\xa0\xe1' # 8d2c mov r3, lr
b'\x03\x00\xa0\xe1' # 8d20 mov r0, r3
b'\x00\xd0\x4b\xe2' # 8d34 sub sp, r11, #0
b'\x04\xb0\x9d\xe4' # 8d38 pop {r11}
b'\x1e\xff\x2f\xe1' # 8d3c bx lr
),
0x8d68: (
b'\xd9\xff\xff\xeb' # 8d68 bl 0x8cd4 <-- MAIN_ADDRESS
b'\x00\x40\xa0\xe1' # 8d6c mov r4, r0
b'\xde\xff\xff\xeb' # 8d70 bl 0x8cf0
b'\x00\x30\xa0\xe1' # 8d74 mov r3, r0
b'\x03\x40\x84\xe0' # 8d78 add r4, r4, r3
b'\xe8\xff\xff\xeb' # 8d7c bl 0x8d24
b'\x00\x30\xa0\xe1' # 8d80 mov r3, r0
b'\x03\x20\x84\xe0' # 8d84 add r2, r4, r3
b'\xd9\xff\xff\xeb' # 8d68 bl 0x8cd4 <-- MAIN_ADDRESS
b'\x00\x40\xa0\xe1' # 8d6c mov r4, r0
b'\xde\xff\xff\xeb' # 8d70 bl 0x8cf0
b'\x00\x30\xa0\xe1' # 8d74 mov r3, r0
b'\x03\x40\x84\xe0' # 8d78 add r4, r4, r3
b'\xe8\xff\xff\xeb' # 8d7c bl 0x8d24
b'\x00\x30\xa0\xe1' # 8d80 mov r3, r0
b'\x03\x20\x84\xe0' # 8d84 add r2, r4, r3
)
}

Expand Down
3 changes: 0 additions & 3 deletions tests/regress/arm_bxeq_hang.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/python

import regress

from unicorn import *
from unicorn.arm_const import *

Expand Down
25 changes: 11 additions & 14 deletions tests/regress/arm_fp_vfp_disabled.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
#!/usr/bin/python

# Added by Peter Mackay, relating to issue 571
# "ARM NEON/VFP support seems to exist but is disabled by default"
# Added by Peter Mackay, relating to issue 571
# ARM NEON/VFP support seems to exist but is disabled by default
# https://github.com/unicorn-engine/unicorn/issues/571

import regress

from unicorn import *
from unicorn.arm_const import *


CODE = (
b'\x11\xEE\x50\x1F' # MRC p15, #0, r1, c1, c0, #2
b'\x41\xF4\x70\x01' # ORR r1, r1, #(0xf << 20)
b'\x01\xEE\x50\x1F' # MCR p15, #0, r1, c1, c0, #2
b'\x4F\xF0\x00\x01' # MOV r1, #0
b'\x07\xEE\x95\x1F' # MCR p15, #0, r1, c7, c5, #4
b'\x4F\xF0\x80\x40' # MOV r0,#0x40000000
b'\xE8\xEE\x10\x0A' # FMXR FPEXC, r0
b'\x2d\xed\x02\x8b' # vpush {d8}
b'\x11\xEE\x50\x1F' # MRC p15, #0, r1, c1, c0, #2
b'\x41\xF4\x70\x01' # ORR r1, r1, #(0xf << 20)
b'\x01\xEE\x50\x1F' # MCR p15, #0, r1, c1, c0, #2
b'\x4F\xF0\x00\x01' # MOV r1, #0
b'\x07\xEE\x95\x1F' # MCR p15, #0, r1, c7, c5, #4
b'\x4F\xF0\x80\x40' # MOV r0,#0x40000000
b'\xE8\xEE\x10\x0A' # FMXR FPEXC, r0
b'\x2d\xed\x02\x8b' # vpush {d8}
)

BASE = 0x1000


class FpVfpDisabled(regress.RegressTest):

def runTest(self):
Expand Down
Loading

0 comments on commit 9cfd5cf

Please sign in to comment.