diff options
| -rw-r--r-- | .github/actions/install/action.yml | 6 | ||||
| -rwxr-xr-x | .github/actions/install/install.sh | 10 | ||||
| -rw-r--r-- | .github/workflows/tests.yml | 100 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | miasm/arch/aarch64/arch.py | 2 | ||||
| -rw-r--r-- | miasm/arch/arm/arch.py | 16 | ||||
| -rw-r--r-- | miasm/arch/x86/arch.py | 8 | ||||
| -rw-r--r-- | miasm/core/cpu.py | 13 | ||||
| -rw-r--r-- | miasm/os_dep/win_api_x86_32.py | 5 |
9 files changed, 127 insertions, 38 deletions
diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml new file mode 100644 index 00000000..917ce2b5 --- /dev/null +++ b/.github/actions/install/action.yml @@ -0,0 +1,6 @@ + +runs: + using: "composite" + steps: + - run: ${{ github.action_path }}/install.sh + shell: bash diff --git a/.github/actions/install/install.sh b/.github/actions/install/install.sh new file mode 100755 index 00000000..7a84c2a2 --- /dev/null +++ b/.github/actions/install/install.sh @@ -0,0 +1,10 @@ +#! /bin/bash + + +# codespell +pip install codespell +# install +python setup.py build build_ext +python setup.py install +# extended tests +git clone https://github.com/cea-sec/miasm-extended-tests diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..327b2426 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,100 @@ +name: Miasm regression tests + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['2.7', '3.6'] + + steps: + + - name: Git checkout + uses: actions/checkout@v2 + + - name: Use Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Install optional requirements + run: pip install -r optional_requirements.txt + + - name: Install llvm + run: sudo apt-get install llvm + + - name: Install Miasm + uses: ./.github/actions/install + + - name: Base tests + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py && git ls-files -o --exclude-standard + + - name: Regression tests + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o regression -t long,python,llvm,gcc,z3,qemu,cparser + + - name: Run examples + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o example -t long,python,llvm,gcc,z3,qemu,cparser + + - name: Test long tests + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o long + + - name: Test qemu jitter llvm/gcc + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o qemu -t llvm,gcc + + - name: Test qemu jitter python/gcc + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o qemu -t python,gcc + + - name: Test qemu jitter python/llvm + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o qemu -t python,llvm + + - name: Test llvm qemu/long + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o llvm -t qemu,long + + - name: Test gcc qemu/long + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o gcc -t qemu,long + + - name: Test python qemu/long + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o python -t qemu,long + + - name: Z3 tests + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o z3 + + - name: Cparser tests + run: cd test; python --version |& grep -q "Python 3" || flags="-W error"; python $flags test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard + env: + MIASM_TEST_EXTRA_ARG: -o cparser + + - name: Loader tests + run: cd "miasm-extended-tests/$MIASM_EXTENTED_TESTS_LOADER" && ./test_dll.py + env: + MIASM_EXTENTED_TESTS_LOADER: loader + + - name: IR tests + run: cd "miasm-extended-tests/$MIASM_EXTENTED_TESTS_IR" && ./run.sh + env: + MIASM_EXTENTED_TESTS_IR: ir_tests diff --git a/README.md b/README.md index f322a790..07e1d8e6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ [](https://travis-ci.org/cea-sec/miasm) [](https://ci.appveyor.com/project/cea-sec/miasm) -[](https://codeclimate.com/github/cea-sec/miasm) [](https://gitter.im/cea-sec/miasm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - +[](https://github.com/cea-sec/miasm/actions/workflows/tests.yml?branch=master) +[](https://codeclimate.com/github/cea-sec/miasm) +[](https://gitter.im/cea-sec/miasm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) <p align="center"> <img src="https://raw.githubusercontent.com/cea-sec/miasm/master/doc/logo_miasm.png"> diff --git a/miasm/arch/aarch64/arch.py b/miasm/arch/aarch64/arch.py index fc188ff2..f4882845 100644 --- a/miasm/arch/aarch64/arch.py +++ b/miasm/arch/aarch64/arch.py @@ -1797,8 +1797,6 @@ class op0_value(aarch64_uint64): v = self.encodeval(v) if v is False: return False - if v > self.lmask: - return False self.value = v return True diff --git a/miasm/arch/arm/arch.py b/miasm/arch/arm/arch.py index abe6711f..6c5b0ce2 100644 --- a/miasm/arch/arm/arch.py +++ b/miasm/arch/arm/arch.py @@ -1676,10 +1676,6 @@ class armt_barrier_option(reg_noarg, arm_arg): log.debug("cannot encode reg %r", self.expr) return False self.value = self.reg_info.dct_expr_inv[self.expr] - if self.value > self.lmask: - log.debug("cannot encode field value %x %x", - self.value, self.lmask) - return False return True def check_fbits(self, v): @@ -1749,8 +1745,6 @@ class arm_widthm1(arm_imm, m_arg): if not isinstance(self.expr, ExprInt): return False v = int(self.expr) + -1 - if v > self.lmask: - return False self.value = v return True @@ -1996,8 +1990,6 @@ class arm_offpc(arm_offreg): if v & 3: return False v >>= 2 - if v > self.lmask: - return False self.value = v return True @@ -2099,8 +2091,6 @@ class arm_offbw(imm_noarg): log.debug('off must be aligned %r', v) return False v >>= 2 - if v > self.lmask: - return False self.value = v return True @@ -2117,8 +2107,6 @@ class arm_off(imm_noarg): if not isinstance(self.expr, ExprInt): return False v = int(self.expr) - if v > self.lmask: - return False self.value = v return True @@ -2139,8 +2127,6 @@ class arm_offh(imm_noarg): log.debug('off must be aligned %r', v) return False v >>= 1 - if v > self.lmask: - return False self.value = v return True @@ -2284,8 +2270,6 @@ class armt_rlist_pclr(armt_rlist): v = 0 for r in rlist: v |= 1 << r - if v > self.lmask: - return False self.value = v return True diff --git a/miasm/arch/x86/arch.py b/miasm/arch/x86/arch.py index d17577fc..a886e799 100644 --- a/miasm/arch/x86/arch.py +++ b/miasm/arch/x86/arch.py @@ -2548,10 +2548,6 @@ class x86_rm_reg_noarg(object): i -= 8 self.setrexsize(1) self.value = i - if self.value > self.lmask: - log.debug("cannot encode field value %x %x", - self.value, self.lmask) - return False return True @@ -2573,10 +2569,6 @@ class x86_rm_reg_mm(x86_rm_reg_noarg, x86_arg): i -= 8 self.setrexsize(1) self.value = i - if self.value > self.lmask: - log.debug("cannot encode field value %x %x", - self.value, self.lmask) - return False return True class x86_rm_reg_xmm(x86_rm_reg_mm): diff --git a/miasm/core/cpu.py b/miasm/core/cpu.py index 6c73c4c1..d9c1955b 100644 --- a/miasm/core/cpu.py +++ b/miasm/core/cpu.py @@ -737,10 +737,6 @@ class reg_noarg(object): log.debug("cannot encode reg %r", self.expr) return False self.value = self.reg_info.expr.index(self.expr) - if self.value > self.lmask: - log.debug("cannot encode field value %x %x", - self.value, self.lmask) - return False return True def check_fbits(self, v): @@ -1456,7 +1452,10 @@ class cls_mn(with_metaclass(metamn, object)): break if f.value is not None and f.l: - assert f.value <= f.lmask + if f.value > f.lmask: + log.debug('cannot encode %r', f) + can_encode = False + break cur_len += f.l index += 1 if ret is True: @@ -1595,8 +1594,6 @@ class imm_noarg(object): return v def encodeval(self, v): - if v > self.lmask: - return False return v def decode(self, v): @@ -1615,8 +1612,6 @@ class imm_noarg(object): v = self.encodeval(v) if v is False: return False - if v > self.lmask: - return False self.value = v return True diff --git a/miasm/os_dep/win_api_x86_32.py b/miasm/os_dep/win_api_x86_32.py index 568a646d..e9c5fd4a 100644 --- a/miasm/os_dep/win_api_x86_32.py +++ b/miasm/os_dep/win_api_x86_32.py @@ -1735,7 +1735,10 @@ def kernel32_WideCharToMultiByte(jitter): ]) if args.CodePage != CP_ACP and args.CodePage != CP_1252: raise NotImplementedError - src = jitter.vm.get_mem(args.lpWideCharStr, args.cchWideChar * 2) + cchWideChar = args.cchWideChar + if cchWideChar == 0xffffffff: + cchWideChar = len(get_win_str_w(jitter, args.lpWideCharStr)) + 1 + src = jitter.vm.get_mem(args.lpWideCharStr, cchWideChar * 2) dst = src.decode("utf-16le").encode("cp1252", errors="replace") if args.cbMultiByte > 0: # return value is the number of bytes written |