Skip to content
Snippets Groups Projects
Commit 474fb429 authored by pompolic's avatar pompolic
Browse files

Test for adding init parser breakpoint

parent 0ccfbdaa
No related branches found
No related tags found
No related merge requests found
...@@ -180,6 +180,7 @@ class BreakpointManager: ...@@ -180,6 +180,7 @@ class BreakpointManager:
self.parse_whitespace.delete() self.parse_whitespace.delete()
self.parse_xor.delete() self.parse_xor.delete()
#TODO: this probably should be merged into the H_RULE functions array instead
def set_init_parser_breakpoint(self): def set_init_parser_breakpoint(self):
i_p_retq = self.locate_retq("init_parser") i_p_retq = self.locate_retq("init_parser")
self.init_parser_retq = InitParserBreakpoint("*"+hex(i_p_retq)) self.init_parser_retq = InitParserBreakpoint("*"+hex(i_p_retq))
......
...@@ -26,6 +26,7 @@ class BreakpointManagerSettingBreakpoints(unittest.TestCase): ...@@ -26,6 +26,7 @@ class BreakpointManagerSettingBreakpoints(unittest.TestCase):
# "constants" like rld_retq below could be moved to setUpClass (possibly better performance) # "constants" like rld_retq below could be moved to setUpClass (possibly better performance)
self.bpm = BreakpointManager(test_breakpoints) self.bpm = BreakpointManager(test_breakpoints)
self.arch = gdb.selected_frame().architecture() self.arch = gdb.selected_frame().architecture()
# TODO: instead of locate_retq, get bp address from call_list, and disassemble
self.rld_retq = self.bpm.locate_retq(test_breakpoints[0]) self.rld_retq = self.bpm.locate_retq(test_breakpoints[0])
self.lzw_retq = self.bpm.locate_retq(test_breakpoints[1]) self.lzw_retq = self.bpm.locate_retq(test_breakpoints[1])
...@@ -37,12 +38,15 @@ class BreakpointManagerSettingBreakpoints(unittest.TestCase): ...@@ -37,12 +38,15 @@ class BreakpointManagerSettingBreakpoints(unittest.TestCase):
self.hpprbp_mock_object = self.hpprbp_patcher.start() self.hpprbp_mock_object = self.hpprbp_patcher.start()
self.pvbp_patcher = unittest.mock.patch('__main__.ParserVirtualBreakpoint') self.pvbp_patcher = unittest.mock.patch('__main__.ParserVirtualBreakpoint')
self.pvbp_mock_object = self.pvbp_patcher.start() self.pvbp_mock_object = self.pvbp_patcher.start()
self.ipbp_patcher = unittest.mock.patch('__main__.InitParserBreakpoint')
self.ipbp_mock_object = self.ipbp_patcher.start()
def tearDown(self): def tearDown(self):
self.hpprbp_patcher.stop() self.hpprbp_patcher.stop()
self.plprbp_patcher.stop() self.plprbp_patcher.stop()
self.hrbp_patcher.stop() self.hrbp_patcher.stop()
self.pvbp_patcher.stop() self.pvbp_patcher.stop()
self.ipbp_patcher.stop()
# TODO: mock breakpoints, assert on arguments to constructor # TODO: mock breakpoints, assert on arguments to constructor
def test_set_h_rule_breakpoints(self): def test_set_h_rule_breakpoints(self):
...@@ -112,6 +116,15 @@ class BreakpointManagerSettingBreakpoints(unittest.TestCase): ...@@ -112,6 +116,15 @@ class BreakpointManagerSettingBreakpoints(unittest.TestCase):
# with self.subTest(i=i): # with self.subTest(i=i):
# virt_bps[i].delete.assert_called_once() # virt_bps[i].delete.assert_called_once()
def test_set_init_parser_breakpoint(self):
self.bpm.set_init_parser_breakpoint()
#print(self.ipbp_mock_object.call_args.args)
gdb_addr_expr = self.ipbp_mock_object.call_args.args[0]
bp_addr = int(gdb_addr_expr.strip('*'), 16)
#TODO: probably could just get the machine word size
instr = self.arch.disassemble(bp_addr, bp_addr+8, 1)[0]
self.assertTrue(instr['asm'].startswith('ret'))
# TODO # TODO
#def tearDown(self): #def tearDown(self):
#self.bpm.delete #self.bpm.delete
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment