Skip to content

Commit 9cfd5cf

Browse files
authored
- Improved the GitHub python binding workflow: (#2072)
- 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
1 parent 07e8162 commit 9cfd5cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+539
-834
lines changed

.github/workflows/build-wheels-publish.yml

+116-199
Large diffs are not rendered by default.

bindings/python/pyproject.toml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["setuptools", "build", "wheel"]
2+
requires = ["setuptools", "build", "wheel", "versioningit"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "unicorn"
7-
version = "2.1.1"
7+
dynamic = ["version"]
88
requires-python = ">= 2.7, != 3.0.*, != 3.1.*, != 3.2.*, != 3.3.*, != 3.4.*, != 3.5.*, != 3.6.*"
99
authors = [
1010
{ name = "Nguyen Anh Quynh", email = "[email protected]" },
@@ -33,9 +33,11 @@ Changelog = "https://github.com/unicorn-engine/unicorn/blob/master/ChangeLog"
3333

3434
[project.optional-dependencies]
3535
test = [
36-
"pytest",
37-
"pytest-cov",
36+
"capstone==6.0.0a2;python_version>'3.7'",
37+
"capstone==5.0.1;python_version<='3.7'"
3838
]
3939

4040
[tool.setuptools.packages.find]
4141
include = ["unicorn*"]
42+
43+
[tool.versioningit]

bindings/python/setup.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,25 @@ def build_libraries():
102102

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

106111
if has_msbuild and sys.platform == 'win32':
112+
generators = os.getenv('GENERATORS') or 'Visual Studio 16 2019'
107113
plat = 'Win32' if platform.architecture()[0] == '32bit' else 'x64'
108-
109-
subprocess.check_call(['cmake', '-B', BUILD_DIR, '-G', "Visual Studio 16 2019", "-A", plat,
110-
"-DCMAKE_BUILD_TYPE=" + conf], cwd=UC_DIR)
114+
cmake_args += ['-G', generators, "-A", plat]
115+
subprocess.check_call(cmake_args, cwd=UC_DIR)
111116
subprocess.check_call(['msbuild', 'unicorn.sln', '-m', '-p:Platform=' + plat, '-p:Configuration=' + conf],
112117
cwd=BUILD_DIR)
113118

114119
obj_dir = os.path.join(BUILD_DIR, conf)
115120
shutil.copy(os.path.join(obj_dir, LIBRARY_FILE), LIBS_DIR)
116121
shutil.copy(os.path.join(obj_dir, STATIC_LIBRARY_FILE), LIBS_DIR)
117122
else:
118-
cmake_args = ["cmake", '-B', BUILD_DIR, '-S', UC_DIR, "-DCMAKE_BUILD_TYPE=" + conf]
119-
if os.getenv("TRACE"):
120-
cmake_args += ["-DUNICORN_TRACER=on"]
121-
if conf == "Debug":
122-
cmake_args += ["-DUNICORN_LOGGING=on"]
123+
cmake_args += ['-S', UC_DIR]
123124
subprocess.check_call(cmake_args, cwd=UC_DIR)
124125
threads = os.getenv("THREADS", "4")
125126
subprocess.check_call(["cmake", "--build", ".", "-j" + threads], cwd=BUILD_DIR)

bindings/python/tests/test_arm.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Sample code for ARM of Unicorn. Nguyen Anh Quynh <[email protected]>
33
# Python sample ported by Loi Anh Tuan <[email protected]>
44

5-
from __future__ import print_function
65
from unicorn import *
76
from unicorn.arm_const import *
87

bindings/python/tests/test_arm64.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Sample code for ARM64 of Unicorn. Nguyen Anh Quynh <[email protected]>
33
# Python sample ported by Loi Anh Tuan <[email protected]>
44

5-
from __future__ import print_function
65
from unicorn import *
76
from unicorn.arm64_const import *
87

bindings/python/tests/test_arm64eb.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Python sample ported by Loi Anh Tuan <[email protected]>
44
# AARCH64 Python sample ported by zhangwm <[email protected]>
55

6-
from __future__ import print_function
76
from unicorn import *
87
from unicorn.arm64_const import *
98

bindings/python/tests/test_armeb.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22
# Sample code for ARM big endian of Unicorn. zhangwm <[email protected]>
33

4-
from __future__ import print_function
54
from unicorn import *
65
from unicorn.arm_const import *
76

bindings/python/tests/test_ctl.py

-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Sample code for Unicorn.
33
# By Lazymio(@wtdcode), 2021
44

5-
import pytest
6-
import sys
75
from unicorn import *
86
from unicorn.x86_const import *
97
from datetime import datetime
@@ -36,7 +34,6 @@ def time_emulation(uc, start, end):
3634

3735

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

8582

8683
# TODO: Check if worth adapting the hook_add method for py2 bindings
87-
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
8884
def test_uc_ctl_exits():
8985
uc = Uc(UC_ARCH_X86, UC_MODE_32)
9086
addr = 0x1000

bindings/python/tests/test_m68k.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Sample code for ARM of Unicorn. Nguyen Anh Quynh <[email protected]>
33
# Python sample ported by Loi Anh Tuan <[email protected]>
44

5-
from __future__ import print_function
65
from unicorn import *
76
from unicorn.m68k_const import *
87

bindings/python/tests/test_mips.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Sample code for MIPS of Unicorn. Nguyen Anh Quynh <[email protected]>
33
# Python sample ported by Loi Anh Tuan <[email protected]>
44

5-
from __future__ import print_function
65
from unicorn import *
76
from unicorn.mips_const import *
87

bindings/python/tests/test_network_auditing.py

-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Unicorn sample for auditing network connection and file handling in shellcode.
33
# Nguyen Tan Cong <[email protected]>
44

5-
from __future__ import print_function
6-
import pytest
75
import struct
86
import uuid
97
from unicorn import *
@@ -361,7 +359,6 @@ def hook_intr(uc, intno, user_data):
361359
print_sockcall(msg)
362360

363361

364-
@pytest.mark.parametrize("code", [X86_SEND_ETCPASSWD, X86_BIND_TCP, X86_REVERSE_TCP, X86_REVERSE_TCP_2])
365362
# Test X86 32 bit
366363
def test_i386(code):
367364
global fd_chains

bindings/python/tests/test_ppc.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22
# Sample code for PPC of Unicorn. Nguyen Anh Quynh <[email protected]>
33

4-
from __future__ import print_function
54
from unicorn import *
65
from unicorn.ppc_const import *
76

bindings/python/tests/test_riscv.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22
# Sample code for RISCV of Unicorn. Nguyen Anh Quynh <[email protected]>
33

4-
from __future__ import print_function
54
from unicorn import *
65
from unicorn.riscv_const import *
76

bindings/python/tests/test_shellcode.py

-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# Nguyen Anh Quynh <[email protected]>
44
# KaiJern Lau <[email protected]>
55

6-
from __future__ import print_function
7-
import pytest
86
from unicorn import *
97
from unicorn.x86_const import *
108

@@ -134,8 +132,6 @@ def hook_syscall64(mu, user_data):
134132
mu.emu_stop()
135133

136134

137-
@pytest.mark.parametrize("mode,code",
138-
[(UC_MODE_32, X86_CODE32_SELF), (UC_MODE_32, X86_CODE32), (UC_MODE_64, X86_CODE64)])
139135
# Test X86 32 bit
140136
def test_i386(mode, code):
141137
if mode == UC_MODE_32:

bindings/python/tests/test_sparc.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Sample code for SPARC of Unicorn. Nguyen Anh Quynh <[email protected]>
33
# Python sample ported by Loi Anh Tuan <[email protected]>
44

5-
from __future__ import print_function
65
from unicorn import *
76
from unicorn.sparc_const import *
87

bindings/python/tests/test_tricore.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Copyright 2022 Aptiv
66
"""
77

8-
from __future__ import print_function
98
from unicorn import *
109
from unicorn.tricore_const import *
1110

bindings/python/tests/test_x86.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22
# Sample code for X86 of Unicorn. Nguyen Anh Quynh <[email protected]>
33

4-
from __future__ import print_function
54
import pickle
65
from unicorn import *
76
from unicorn.x86_const import *

tests/regress/arm64_reg_rw_w0_w30.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#!/usr/bin/python
2-
31
import regress
4-
52
from unicorn import *
63
from unicorn.arm64_const import *
74

tests/regress/arm_bx_unmapped.py

+40-43
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
21
import regress
3-
42
from unicorn import *
53
from unicorn.arm_const import *
64

7-
85
MAIN_ADDRESS = 0x8d68
96
ADDRESS = MAIN_ADDRESS & ~(0x1000 - 1)
107
STACK_ADDR = ADDRESS + 0x1000
@@ -15,51 +12,51 @@ def runTest(self):
1512
# code to be emulated
1613
code = {
1714
0x8cd4: (
18-
b'\x04\xb0\x2d\xe5' # 8cd4 push {r11}
19-
b'\x00\xb0\x8d\xe2' # 8cd8 add r11, sp, #0
20-
b'\x0f\x30\xa0\xe1' # 8cdc mov r3, pc
21-
b'\x03\x00\xa0\xe1' # 8ce0 mov r0, r3
22-
b'\x00\xd0\x4b\xe2' # 8ce4 sub sp, r11, #0
23-
b'\x04\xb0\x9d\xe4' # 8ce8 pop {r11}
24-
b'\x1e\xff\x2f\xe1' # 8cec bx lr
15+
b'\x04\xb0\x2d\xe5' # 8cd4 push {r11}
16+
b'\x00\xb0\x8d\xe2' # 8cd8 add r11, sp, #0
17+
b'\x0f\x30\xa0\xe1' # 8cdc mov r3, pc
18+
b'\x03\x00\xa0\xe1' # 8ce0 mov r0, r3
19+
b'\x00\xd0\x4b\xe2' # 8ce4 sub sp, r11, #0
20+
b'\x04\xb0\x9d\xe4' # 8ce8 pop {r11}
21+
b'\x1e\xff\x2f\xe1' # 8cec bx lr
2522
),
2623
0x8cf0: (
27-
b'\x04\xb0\x2d\xe5' # 8cf0 push {r11}
28-
b'\x00\xb0\x8d\xe2' # 8cf4 add r11, sp, #0
29-
b'\x04\x60\x2d\xe5' # 8cf8 push {r6}
30-
b'\x01\x60\x8f\xe2' # 8cfc add r6, pc, $1
31-
b'\x16\xff\x2f\xe1' # 8d00 bx r6
32-
# .thumb
33-
b'\x7b\x46' # 8d04 mov r3, pc
34-
b'\x03\xf1\x08\x03' # 8d06 add r3, $0x8 # elicn: used to be $0x4 but it kept failing
35-
b'\x08\xb4' # 8d0a push {r3}
36-
b'\x00\xbd' # 8d0c pop {pc}
37-
b'\x00\x00' # 8d0e (alignment)
38-
# .arm
39-
b'\x04\x60\x9d\xe4' # 8d10 pop {r6}
40-
b'\x03\x00\xa0\xe1' # 8d14 mov r0, r3
41-
b'\x00\xd0\x4b\xe2' # 8d18 sub sp, r11, #0
42-
b'\x04\xb0\x9d\xe4' # 8d1c pop {r11}
43-
b'\x1e\xff\x2f\xe1' # 8d20 bx lr
24+
b'\x04\xb0\x2d\xe5' # 8cf0 push {r11}
25+
b'\x00\xb0\x8d\xe2' # 8cf4 add r11, sp, #0
26+
b'\x04\x60\x2d\xe5' # 8cf8 push {r6}
27+
b'\x01\x60\x8f\xe2' # 8cfc add r6, pc, $1
28+
b'\x16\xff\x2f\xe1' # 8d00 bx r6
29+
# .thumb
30+
b'\x7b\x46' # 8d04 mov r3, pc
31+
b'\x03\xf1\x08\x03' # 8d06 add r3, $0x8 # elicn: used to be $0x4 but it kept failing
32+
b'\x08\xb4' # 8d0a push {r3}
33+
b'\x00\xbd' # 8d0c pop {pc}
34+
b'\x00\x00' # 8d0e (alignment)
35+
# .arm
36+
b'\x04\x60\x9d\xe4' # 8d10 pop {r6}
37+
b'\x03\x00\xa0\xe1' # 8d14 mov r0, r3
38+
b'\x00\xd0\x4b\xe2' # 8d18 sub sp, r11, #0
39+
b'\x04\xb0\x9d\xe4' # 8d1c pop {r11}
40+
b'\x1e\xff\x2f\xe1' # 8d20 bx lr
4441
),
45-
0x8d24: ( # elicn: used to be 0x8d20 but it caused this block to overlap with the previous one
46-
b'\x04\xb0\x2d\xe5' # 8d24 push {r11}
47-
b'\x00\xb0\x8d\xe2' # 8d28 add r11, sp, #0
48-
b'\x0e\x30\xa0\xe1' # 8d2c mov r3, lr
49-
b'\x03\x00\xa0\xe1' # 8d20 mov r0, r3
50-
b'\x00\xd0\x4b\xe2' # 8d34 sub sp, r11, #0
51-
b'\x04\xb0\x9d\xe4' # 8d38 pop {r11}
52-
b'\x1e\xff\x2f\xe1' # 8d3c bx lr
42+
0x8d24: ( # elicn: used to be 0x8d20 but it caused this block to overlap with the previous one
43+
b'\x04\xb0\x2d\xe5' # 8d24 push {r11}
44+
b'\x00\xb0\x8d\xe2' # 8d28 add r11, sp, #0
45+
b'\x0e\x30\xa0\xe1' # 8d2c mov r3, lr
46+
b'\x03\x00\xa0\xe1' # 8d20 mov r0, r3
47+
b'\x00\xd0\x4b\xe2' # 8d34 sub sp, r11, #0
48+
b'\x04\xb0\x9d\xe4' # 8d38 pop {r11}
49+
b'\x1e\xff\x2f\xe1' # 8d3c bx lr
5350
),
5451
0x8d68: (
55-
b'\xd9\xff\xff\xeb' # 8d68 bl 0x8cd4 <-- MAIN_ADDRESS
56-
b'\x00\x40\xa0\xe1' # 8d6c mov r4, r0
57-
b'\xde\xff\xff\xeb' # 8d70 bl 0x8cf0
58-
b'\x00\x30\xa0\xe1' # 8d74 mov r3, r0
59-
b'\x03\x40\x84\xe0' # 8d78 add r4, r4, r3
60-
b'\xe8\xff\xff\xeb' # 8d7c bl 0x8d24
61-
b'\x00\x30\xa0\xe1' # 8d80 mov r3, r0
62-
b'\x03\x20\x84\xe0' # 8d84 add r2, r4, r3
52+
b'\xd9\xff\xff\xeb' # 8d68 bl 0x8cd4 <-- MAIN_ADDRESS
53+
b'\x00\x40\xa0\xe1' # 8d6c mov r4, r0
54+
b'\xde\xff\xff\xeb' # 8d70 bl 0x8cf0
55+
b'\x00\x30\xa0\xe1' # 8d74 mov r3, r0
56+
b'\x03\x40\x84\xe0' # 8d78 add r4, r4, r3
57+
b'\xe8\xff\xff\xeb' # 8d7c bl 0x8d24
58+
b'\x00\x30\xa0\xe1' # 8d80 mov r3, r0
59+
b'\x03\x20\x84\xe0' # 8d84 add r2, r4, r3
6360
)
6461
}
6562

tests/regress/arm_bxeq_hang.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#!/usr/bin/python
2-
31
import regress
4-
52
from unicorn import *
63
from unicorn.arm_const import *
74

tests/regress/arm_fp_vfp_disabled.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
#!/usr/bin/python
2-
3-
# Added by Peter Mackay, relating to issue 571
4-
# "ARM NEON/VFP support seems to exist but is disabled by default"
1+
# Added by Peter Mackay, relating to issue 571
2+
# ARM NEON/VFP support seems to exist but is disabled by default
53
# https://github.com/unicorn-engine/unicorn/issues/571
64

75
import regress
8-
96
from unicorn import *
107
from unicorn.arm_const import *
118

12-
139
CODE = (
14-
b'\x11\xEE\x50\x1F' # MRC p15, #0, r1, c1, c0, #2
15-
b'\x41\xF4\x70\x01' # ORR r1, r1, #(0xf << 20)
16-
b'\x01\xEE\x50\x1F' # MCR p15, #0, r1, c1, c0, #2
17-
b'\x4F\xF0\x00\x01' # MOV r1, #0
18-
b'\x07\xEE\x95\x1F' # MCR p15, #0, r1, c7, c5, #4
19-
b'\x4F\xF0\x80\x40' # MOV r0,#0x40000000
20-
b'\xE8\xEE\x10\x0A' # FMXR FPEXC, r0
21-
b'\x2d\xed\x02\x8b' # vpush {d8}
10+
b'\x11\xEE\x50\x1F' # MRC p15, #0, r1, c1, c0, #2
11+
b'\x41\xF4\x70\x01' # ORR r1, r1, #(0xf << 20)
12+
b'\x01\xEE\x50\x1F' # MCR p15, #0, r1, c1, c0, #2
13+
b'\x4F\xF0\x00\x01' # MOV r1, #0
14+
b'\x07\xEE\x95\x1F' # MCR p15, #0, r1, c7, c5, #4
15+
b'\x4F\xF0\x80\x40' # MOV r0,#0x40000000
16+
b'\xE8\xEE\x10\x0A' # FMXR FPEXC, r0
17+
b'\x2d\xed\x02\x8b' # vpush {d8}
2218
)
2319

2420
BASE = 0x1000
2521

22+
2623
class FpVfpDisabled(regress.RegressTest):
2724

2825
def runTest(self):

0 commit comments

Comments
 (0)