fkie-cad / dewolf

A research decompiler implemented as a Binary Ninja plugin.
GNU Lesser General Public License v2.1
162 stars 9 forks source link

[Parser Testing] Change mock types to allow for easier testing of parser #300

Closed mm4rks closed 10 months ago

mm4rks commented 11 months ago

Proposal

In the lifter we use type() to determine the correct handler for the given instruction. However, this prevents us to use mock classes (e.g., unittest.mock.Mock) to test parser functionality: instructions can't be lifted.

Changing handler selection in the lifter, to select by expression.__class__ would allow lifting of mocked instructions.

Since we add instruction patching (jmp / edges) to the parser, proper testing would be nice :)

Approach

     def lift(self, expression: T, **kwargs) -> V:
         """Lift the given expression based on the registered handlers."""
-        handler = self.HANDLERS.get(type(expression), self.lift_unknown)
+        handler = self.HANDLERS.get(expression.__class__, self.lift_unknown)
         return handler(expression)

use unittest.mock.Mock and simplify tests for the parser.

mm4rks commented 11 months ago

/cib

github-actions[bot] commented 11 months ago

Branch issue-300-_Parser_Testing_Change_mock_types_to_allow_for_easier_testing_of_parser created!