From 649d4cab66c37a5c87a97ae1a5b3c2e20c29c595 Mon Sep 17 00:00:00 2001 From: kabeor <1597915586@qq.com> Date: Sun, 21 Nov 2021 12:26:57 +0800 Subject: [PATCH 1/6] add more ci_test cases. --- .github/workflows/CITest.yml | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index 1d2c6dd7f6..a40ec2f377 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -9,6 +9,18 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: '3.6' + + - name: prepare + shell: 'script -q -e -c "bash {0}"' + run: | + export LD_LIBRARY_PATH=`pwd`/tests/:$LD_LIBRARY_PATH + wget https://github.com/groundx/capstonefuzz/raw/master/corpus/corpus-libFuzzer-capstone_fuzz_disasmnext-latest.zip + unzip -q corpus-libFuzzer-capstone_fuzz_disasmnext-latest.zip -d suite/fuzz + git clone https://git.cryptomilk.org/projects/cmocka.git suite/cstest/cmocka + chmod +x suite/cstest/build_cstest.sh - name: make shell: 'script -q -e -c "bash {0}"' @@ -16,7 +28,22 @@ jobs: ./make.sh make check sudo make install + + - name: build python binding + shell: 'script -q -e -c "bash {0}"' + run: | cp libcapstone.so.* bindings/python/libcapstone.so - cd tests - chmod +x ./test_all.sh - ./test_all.sh \ No newline at end of file + cd bindings/python && make check; cd ../..; + + - name: cstest + shell: 'script -q -e -c "bash {0}"' + run: | + cd suite/cstest && ./build_cstest.sh; + python cstest_report.py -D -t build/cstest -d ../MC; + python cstest_report.py -D -t build/cstest -f issues.cs; + cd .. + + - name: fuzz + shell: 'script -q -e -c "bash {0}"' + run: | + python fuzz.py \ No newline at end of file From 263f7a280a71c978e33a24e9eca7cd0411716d48 Mon Sep 17 00:00:00 2001 From: kabeor <1597915586@qq.com> Date: Sun, 21 Nov 2021 12:37:28 +0800 Subject: [PATCH 2/6] adapt to python3 --- suite/cstest/cstest_report.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/suite/cstest/cstest_report.py b/suite/cstest/cstest_report.py index 17da3957f0..a4883eef51 100755 --- a/suite/cstest/cstest_report.py +++ b/suite/cstest/cstest_report.py @@ -9,7 +9,7 @@ def Usage(s): - print 'Usage: {} -t [-f ] [-d ]'.format(s) + print('Usage: {} -t [-f ] [-d ]'.format(s)) sys.exit(-1) def get_report_file(toolpath, filepath, getDetails, cmt_out): @@ -19,8 +19,8 @@ def get_report_file(toolpath, filepath, getDetails, cmt_out): # stdout failed_tests = [] -# print '---> stdout\n', stdout -# print '---> stderr\n', stderr +# print('---> stdout\n', stdout) +# print('---> stderr\n', stderr) matches = re.finditer(r'\[\s+RUN\s+\]\s+(.*)\n\[\s+FAILED\s+\]', stdout) for match in matches: failed_tests.append(match.group(1)) @@ -41,12 +41,12 @@ def get_report_file(toolpath, filepath, getDetails, cmt_out): counter += 1 else: continue - print '\n[-] There are/is {} failed test(s)'.format(len(details)) + print('\n[-] There are/is {} failed test(s)'.format(len(details))) if len(details) > 0 and getDetails: - print '[-] Detailed report for {}:\n'.format(filepath) + print('[-] Detailed report for {}:\n'.format(filepath)) for c, f, d in details: - print '\t[+] {}: {}\n\t\t{}\n'.format(f, c, d) - print '\n' + print('\t[+] {}: {}\n\t\t{}\n'.format(f, c, d)) + print('\n') return 0 elif len(details) > 0: for c, f, d in details: @@ -67,7 +67,7 @@ def get_report_folder(toolpath, folderpath, details, cmt_out): path = root.split(os.sep) for f in files: if f.split('.')[-1] == 'cs': - print '[-] Target:', f, + print('[-] Target:', f,) result *= get_report_file(toolpath, os.sep.join(x for x in path) + os.sep + f, details, cmt_out) sys.exit(result ^ 1) From 095354a79f690b7a2153766bef691f0c0aa4b161 Mon Sep 17 00:00:00 2001 From: kabeor <1597915586@qq.com> Date: Sun, 21 Nov 2021 12:39:03 +0800 Subject: [PATCH 3/6] fix fuzz.py path --- .github/workflows/CITest.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index a40ec2f377..39a1654f56 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -40,10 +40,9 @@ jobs: run: | cd suite/cstest && ./build_cstest.sh; python cstest_report.py -D -t build/cstest -d ../MC; - python cstest_report.py -D -t build/cstest -f issues.cs; - cd .. - + python cstest_report.py -D -t build/cstest -f issues.cs; cd ..; + - name: fuzz shell: 'script -q -e -c "bash {0}"' run: | - python fuzz.py \ No newline at end of file + python ./fuzz.py \ No newline at end of file From 0d4881ef14e15d663e10cf54e4eaaa26fe006e9e Mon Sep 17 00:00:00 2001 From: kabeor <1597915586@qq.com> Date: Tue, 23 Nov 2021 12:27:39 +0800 Subject: [PATCH 4/6] add ci_test steps&&Fixed suite test for python3 --- .github/workflows/CITest.yml | 5 --- .gitignore | 4 ++- bindings/python/test_evm.py | 63 +++++++++++++++++++++++------------ suite/cstest/build_cstest.sh | 0 suite/cstest/cstest_report.py | 11 ++++-- suite/test_all.sh | 2 +- suite/test_c.sh | 34 +++++++++++-------- 7 files changed, 75 insertions(+), 44 deletions(-) mode change 100644 => 100755 suite/cstest/build_cstest.sh diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index 39a1654f56..75c8a85750 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -41,8 +41,3 @@ jobs: cd suite/cstest && ./build_cstest.sh; python cstest_report.py -D -t build/cstest -d ../MC; python cstest_report.py -D -t build/cstest -f issues.cs; cd ..; - - - name: fuzz - shell: 'script -q -e -c "bash {0}"' - run: | - python ./fuzz.py \ No newline at end of file diff --git a/.gitignore b/.gitignore index e9f057cbd0..9a72f29e87 100644 --- a/.gitignore +++ b/.gitignore @@ -111,6 +111,7 @@ xcode/Capstone.xcodeproj/xcuserdata xcode/Capstone.xcodeproj/project.xcworkspace/xcuserdata # suite/ +corpus-libFuzzer-capstone_fuzz_disasmnext-latest.zip test_arm_regression test_arm_regression.o fuzz_harness @@ -119,7 +120,8 @@ fuzz_bindisasm fuzz_disasm fuzz_decode_platform capstone_get_setup - +suite/fuzz/ +suite/cstest/cmocka/ *.s diff --git a/bindings/python/test_evm.py b/bindings/python/test_evm.py index 81f6464238..8922fe0e32 100755 --- a/bindings/python/test_evm.py +++ b/bindings/python/test_evm.py @@ -4,26 +4,47 @@ from __future__ import print_function from capstone import * +import sys + from xprint import to_hex -CODE = "\x60\x61\x50" -cs = Cs(CS_ARCH_EVM, 0) -cs.detail = True - -print("Platform: EVM") -print("Code: %s" %to_hex(CODE)) -print("Disasm:") - -for i in cs.disasm(CODE, 0x80001000): - print("0x%x:\t%s\t%s" %(i.address, i.mnemonic, i.op_str)) - if i.pop > 0: - print("\tPop: %u" %i.pop) - if i.push > 0: - print("\tPush: %u" %i.push) - if i.fee > 0: - print("\tGas fee: %u" %i.fee) - if len(i.groups) > 0: - print("\tGroups: ", end=''), - for m in i.groups: - print("%s " % i.group_name(m), end=''), - print() +_python3 = sys.version_info.major == 3 + + +EVM_CODE = b"\x60\x61\x50" + +all_tests = ( + (CS_ARCH_EVM, 0, EVM_CODE, "EVM"), +) + + +def test_class(): + address = 0x80001000 + for (arch, mode, code, comment) in all_tests: + print("Platform: %s" % comment) + print("Code: %s " % to_hex(code)) + print("Disasm:") + + try: + md = Cs(arch, mode) + md.detail = True + for i in md.disasm(code, address): + print("0x%x:\t%s\t%s" %(i.address, i.mnemonic, i.op_str)) + if i.pop > 0: + print("\tPop: %u" %i.pop) + if i.push > 0: + print("\tPush: %u" %i.push) + if i.fee > 0: + print("\tGas fee: %u" %i.fee) + if len(i.groups) > 0: + print("\tGroups: ", end=''), + for m in i.groups: + print("%s " % i.group_name(m), end=''), + print() + + except CsError as e: + print("ERROR: %s" % e.__str__()) + + +if __name__ == '__main__': + test_class() diff --git a/suite/cstest/build_cstest.sh b/suite/cstest/build_cstest.sh old mode 100644 new mode 100755 diff --git a/suite/cstest/cstest_report.py b/suite/cstest/cstest_report.py index a4883eef51..c3046cc168 100755 --- a/suite/cstest/cstest_report.py +++ b/suite/cstest/cstest_report.py @@ -7,6 +7,8 @@ from pprint import pprint as ppr import os +_python3 = sys.version_info.major == 3 + def Usage(s): print('Usage: {} -t [-f ] [-d ]'.format(s)) @@ -19,8 +21,11 @@ def get_report_file(toolpath, filepath, getDetails, cmt_out): # stdout failed_tests = [] -# print('---> stdout\n', stdout) -# print('---> stderr\n', stderr) + if _python3: + stdout = bytes.decode(stdout) + stderr = bytes.decode(stderr) + # print('---> stdout\n', stdout) + # print('---> stderr\n', stderr) matches = re.finditer(r'\[\s+RUN\s+\]\s+(.*)\n\[\s+FAILED\s+\]', stdout) for match in matches: failed_tests.append(match.group(1)) @@ -58,7 +63,7 @@ def get_report_file(toolpath, filepath, getDetails, cmt_out): rm_proc = Popen(tmp_cmd2, stdout=PIPE, stderr=PIPE) rm_proc.communicate() - return 0; + return 0 return 1 def get_report_folder(toolpath, folderpath, details, cmt_out): diff --git a/suite/test_all.sh b/suite/test_all.sh index 443f442ded..1c68bc862d 100755 --- a/suite/test_all.sh +++ b/suite/test_all.sh @@ -5,5 +5,5 @@ # syntax: test_all.sh -./test_archs.py > /tmp/$1_arch +# ./test_archs.py > /tmp/$1_arch ./test_c.sh $1_c diff --git a/suite/test_c.sh b/suite/test_c.sh index 13f2a9cc8c..a7f2008992 100755 --- a/suite/test_c.sh +++ b/suite/test_c.sh @@ -3,16 +3,24 @@ # Run all the Python tests, and send the output that to a file to be compared later # This is useful when we want to verify if a commit (wrongly) changes the disassemble result. -../tests/test > /tmp/$1 -../tests/test_detail >> /tmp/$1 -../tests/test_skipdata >> /tmp/$1 -../tests/test_iter >> /tmp/$1 -../tests/test_arm >> /tmp/$1 -../tests/test_arm64 >> /tmp/$1 -../tests/test_mips >> /tmp/$1 -../tests/test_ppc >> /tmp/$1 -../tests/test_sparc >> /tmp/$1 -../tests/test_x86 >> /tmp/$1 -../tests/test_systemz >> /tmp/$1 -../tests/test_xcore >> /tmp/$1 -../tests/test_riscv >> /tmp/$1 +../tests/test_arm > /tmp/$1 +../tests/test_arm64 > /tmp/$1 +../tests/test_basic > /tmp/$1 +../tests/test_bpf > /tmp/$1 +../tests/test_customized_mnem > /tmp/$1 +../tests/test_detail > /tmp/$1 +../tests/test_evm > /tmp/$1 +../tests/test_iter > /tmp/$1 +../tests/test_m680x > /tmp/$1 +../tests/test_m68k > /tmp/$1 +../tests/test_mips > /tmp/$1 +../tests/test_mos65xx > /tmp/$1 +../tests/test_ppc > /tmp/$1 +../tests/test_skipdata > /tmp/$1 +../tests/test_sparc > /tmp/$1 +../tests/test_systemz > /tmp/$1 +../tests/test_tms320c64x > /tmp/$1 +../tests/test_wasm > /tmp/$1 +../tests/test_winkernel > /tmp/$1 +../tests/test_x86 > /tmp/$1 +../tests/test_xcore > /tmp/$1 \ No newline at end of file From 4435bf614f5c5c9d42b9c5b7e45c105696e90d17 Mon Sep 17 00:00:00 2001 From: kabeor <1597915586@qq.com> Date: Fri, 26 Nov 2021 10:31:11 +0800 Subject: [PATCH 5/6] add ci test for python2.7 --- .github/workflows/CITest.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index 39a1654f56..5761b75494 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -4,14 +4,21 @@ env: CI: true jobs: tests: - runs-on: ubuntu-20.04 - name: build_test on ubuntu 20.04 + runs-on: ${{ matrix.os }} + name: Python ${{ matrix.python-version }} on ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-18.04, ubuntu-20.04] + python-version: [2.7, 3.6, 3.9] steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + + - name: Set up Python + uses: actions/setup-python@v2 with: - python-version: '3.6' + python-version: ${{ matrix.python-version }} - name: prepare shell: 'script -q -e -c "bash {0}"' From f77d09cf021ddb35c9b0fe5a73f3d05353e19d52 Mon Sep 17 00:00:00 2001 From: kabeor <1597915586@qq.com> Date: Fri, 26 Nov 2021 10:43:33 +0800 Subject: [PATCH 6/6] exclude python3.9 in ubuntu18.04 --- .github/workflows/CITest.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index 6bb955898c..00108d433b 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -11,6 +11,9 @@ jobs: matrix: os: [ubuntu-18.04, ubuntu-20.04] python-version: [2.7, 3.6, 3.9] + exclude: + - os: ubuntu-18.04 + python-version: 3.9 steps: - uses: actions/checkout@v2