def test_replace_function_patch(self): code = ''' int add(int a, int b){ for(;; b--, a+=2) if(b <= 0) return a; } ''' self.run_test("replace_function_patch", [ReplaceFunctionPatch(0x120000c4c, 0x70, code)], expected_output=b"70707070")
def test_replace_function_patch_with_function_reference(self): code = ''' extern int add(int, int); extern int subtract(int, int); int multiply(int a, int b){ for(int c = 0;; b = subtract(b, 1), c = subtract(c, a)) if(b <= 0) return c; } ''' self.run_test("replace_function_patch", [ReplaceFunctionPatch(0x40082c, 0x7C, code, symbols={"add" : 0x40076c, "subtract" : 0x4007cc})], expected_output=b"-21-21")
def test_replace_function_patch_with_function_reference_and_rodata(self): code = ''' extern int printf(const char *format, ...); int multiply(int a, int b){ printf("%sWorld %s %s %s %d\\n", "Hello ", "Hello ", "Hello ", "Hello ", a * b);printf("%sWorld\\n", "Hello "); return a * b; } ''' self.run_test( "replace_function_patch", [ ReplaceFunctionPatch( 0x120000d2c, 0xBC, code, symbols={"printf": 0x120001150}) ], expected_output= b"Hello World Hello Hello Hello 21\nHello World\n2121")