From c3a103b2434091852fe5a3dba9751a47592d73d1 Mon Sep 17 00:00:00 2001 From: Mihail Ivanchev Date: Wed, 1 Apr 2020 01:21:41 +0200 Subject: [PATCH 1/5] Unit tests for Module.get_symbol_at_address. --- tests/__init__.py | 29 ++++++++++++++++++++++ tests/test_module.py | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_module.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..9d3213e3 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,29 @@ +#!/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2020, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. diff --git a/tests/test_module.py b/tests/test_module.py new file mode 100644 index 00000000..c1f0de67 --- /dev/null +++ b/tests/test_module.py @@ -0,0 +1,59 @@ +#!/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2020, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +import mock +import unittest +import winappdbg + +class ModuleTests(unittest.TestCase): + + def assertSymbolAtAddressEqual(self, address, symbol): + self.assertEqual(winappdbg.Module(0).get_symbol_at_address(address), + symbol) + + @mock.patch('winappdbg.Module.iter_symbols') + def test_get_symbol_at_address(self, mock_iter_symbols): + mock_iter_symbols.return_value = [("matchPattern", 0x002A, 0x10), + ("isMatched", 0xFF42, 0x0090), + ("__ii_95", 0x0102, 0), + ("groupSize", 0x000A, 0), + ("__ref_thesaurus", 0x1000, 0x07F0), + ("iter_int32", 0x009E, 0x00A4), + ("__jj_49", 0x0140, 0), + ("numGroups", 0x001F, 0), + ("__comp_state", 0x003C, 0x0004)] + + self.assertSymbolAtAddressEqual(0x000A, ("groupSize", 0x000A, 0)) + self.assertSymbolAtAddressEqual(0x0029, ("numGroups", 0x001F, 0)) + self.assertSymbolAtAddressEqual(0x0141, ("iter_int32", 0x009E, 0x00A4)) + self.assertSymbolAtAddressEqual(0x0142, ("__jj_49", 0x0140, 0)) + self.assertSymbolAtAddressEqual(0x493F, ("__ref_thesaurus", 0x1000, 0)) + self.assertSymbolAtAddressEqual(0xFF7A, ("isMatched", 0xFF42, 0x0090)) + From af34ebe2527422976d04108d1190b802cebe7d8c Mon Sep 17 00:00:00 2001 From: Mihail Ivanchev Date: Wed, 1 Apr 2020 01:27:31 +0200 Subject: [PATCH 2/5] Removing a blank line at EOF. --- tests/test_module.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_module.py b/tests/test_module.py index c1f0de67..1790b2e6 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -56,4 +56,3 @@ def test_get_symbol_at_address(self, mock_iter_symbols): self.assertSymbolAtAddressEqual(0x0142, ("__jj_49", 0x0140, 0)) self.assertSymbolAtAddressEqual(0x493F, ("__ref_thesaurus", 0x1000, 0)) self.assertSymbolAtAddressEqual(0xFF7A, ("isMatched", 0xFF42, 0x0090)) - From f15f8b106be9a2ea1178de460e6ba634f45fe1c9 Mon Sep 17 00:00:00 2001 From: Mihail Ivanchev Date: Wed, 1 Apr 2020 01:38:52 +0200 Subject: [PATCH 3/5] Run unit tests on Travis. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 79c1c8db..57fe18bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ install: script: # Static analysis - flake8 --ignore=E,F403,F405,W503,W504 . + - python -m unittest discover matrix: fast_finish: true From 722b6d999c23d3e9aa1b1cc6e0709906d6adb470 Mon Sep 17 00:00:00 2001 From: Mihail Ivanchev Date: Wed, 1 Apr 2020 01:48:45 +0200 Subject: [PATCH 4/5] Removing test execution from Travis; not quite suited. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 57fe18bc..79c1c8db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,6 @@ install: script: # Static analysis - flake8 --ignore=E,F403,F405,W503,W504 . - - python -m unittest discover matrix: fast_finish: true From 05e67264f60299f1cf06b3b44351ed720957fe0c Mon Sep 17 00:00:00 2001 From: Mihail Ivanchev Date: Wed, 1 Apr 2020 11:01:42 +0200 Subject: [PATCH 5/5] AppVeyor script for unit testing. --- appveyor.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..d22843db --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,16 @@ +environment: + matrix: + - PYTHON: "C:\\Python27" + PYTHON_VERSION: 2.7 + PYTHON_ARCH: 32 + +install: + - set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH% + - python --version + - python -m pip install --upgrade pip + - pip install mock + +build: false + +test_script: + - python -m unittest discover