From 70788d0af07e507be9c3a90db8c1b5342e77bc75 Mon Sep 17 00:00:00 2001 From: Jon Palmisciano Date: Fri, 8 Jul 2022 15:12:17 -0400 Subject: Add unit test for Objective-C plugin --- suite/api_test.py | 42 ++++++++++++++++++++++++++++++++++++++++++ suite/binaries | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/suite/api_test.py b/suite/api_test.py index 8ef6aa04..d9549682 100644 --- a/suite/api_test.py +++ b/suite/api_test.py @@ -3425,3 +3425,45 @@ class LowLevelILTests(TestWithBinaryView): self.do_il_expression_test(LowLevelILFunction.float_compare_greater_equal, [8], LowLevelILFcmpGe, const_args=2) self.do_il_expression_test(LowLevelILFunction.float_compare_ordered, [8], LowLevelILFcmpO, const_args=2) self.do_il_expression_test(LowLevelILFunction.float_compare_unordered, [8], LowLevelILFcmpUo, const_args=2) + + +class TestObjectiveCPlugin(unittest.TestCase): + def setUp(self): + with FileApparatus("Calculator_macOS12_arm64e") as path: + bv = BinaryViewType.get_view_of_file_with_options( + os.path.relpath(path), + options={"workflows.enable": True, "workflows.functionWorkflow": "core.function.objectiveC"} + ) + bv.update_analysis_and_wait() + + self.bv: BinaryView = bv + self.arch: Architecture = self.bv.arch + self.plat: Platform = self.bv.platform + + def test_function_nat(self): + f = self.bv.get_function_at(0x10000667c) + ft = f.function_type + + # Ensure return value and parameter types are being set + assert "CGFloat" == str(ft.return_value) + assert len(ft.parameters) >= 2 + assert "SEL" in str(ft.parameters[1]) + + # Ensure function names are being set + assert "doubleValue" in f.name + + def test_data_vars_created(self): + dv1 = self.bv.get_data_var_at(0x1000331a0) + dv2 = self.bv.get_data_var_at(0x10001f4b0) + + # Ensure data variables are being created + assert "class" in str(dv1.type) + assert "method" in str(dv2.type) + + def test_method_call_resolution(self): + f = self.bv.get_function_at(0x10000667c) + assert f + + # Lazier way of checking that the method call rewriting worked + assert "actualValuePeriodDecimal" in str(f.hlil) + assert "doubleValue" in str(f.hlil) diff --git a/suite/binaries b/suite/binaries index 93c0d264..6660aad8 160000 --- a/suite/binaries +++ b/suite/binaries @@ -1 +1 @@ -Subproject commit 93c0d2647f32bbc42d8f23088f91a44bd305412b +Subproject commit 6660aad8bb0c7810cdb535a2593c947196964384 -- cgit v1.3.1