Map sorting and usecode
This commit is contained in:
parent
589bfc31ef
commit
af5b77ea13
7 changed files with 1497 additions and 39 deletions
|
|
@ -9,6 +9,7 @@ from tools.poc_crusader_usecode_parser import (
|
|||
render_partially_structured_blocks,
|
||||
render_structured_pseudocode,
|
||||
try_decode_loop_selector,
|
||||
validate_pseudocode_text,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -222,6 +223,58 @@ class UsecodeStructuringTests(unittest.TestCase):
|
|||
self.assertNotIn("block_0358:", text)
|
||||
self.assertNotIn("goto block_0469;", text)
|
||||
|
||||
def test_generic_loop_renders_in_partial_fallback(self) -> None:
|
||||
blocks = [
|
||||
("entry", ["goto block_01E2;"]),
|
||||
("block_01E2", ["counter = 0;"]),
|
||||
("block_025C", ["if (counter <= rndNum) goto block_0315;"]),
|
||||
("block_0267", ["counter2 = 1;"]),
|
||||
("block_026E", ["if (counter2 <= 7) goto block_02B6;"]),
|
||||
("block_0276", ["spawn FREE.waitNTimerTicks(pid, 10, 0x00000000);", "suspend;", "counter2 = (1 + counter2);", "goto block_026E;"]),
|
||||
("block_02B6", ["counter = (1 + counter);", "goto block_025C;"]),
|
||||
("block_0315", ["goto block_01E2;"]),
|
||||
]
|
||||
|
||||
rendered = render_partially_structured_blocks(blocks)
|
||||
|
||||
text = "\n".join(rendered)
|
||||
self.assertIn("while (true) {", text)
|
||||
self.assertIn("while (counter > rndNum) {", text)
|
||||
self.assertIn("while (counter2 > 7) {", text)
|
||||
self.assertNotIn("block_026E:", text)
|
||||
self.assertNotIn("goto block_025C;", text)
|
||||
|
||||
def test_infinite_loop_region_renders_as_while_true(self) -> None:
|
||||
blocks = [
|
||||
("entry", ["set_info(0x021B, *(arg_06));"]),
|
||||
("block_01E2", ["suspend;", "FREE.slot_20(100);", "if (retval > 50) goto block_0318;"]),
|
||||
("block_0205", ["FREE.slot_20(pid, 120);", "goto block_046D;"]),
|
||||
("block_0318", ["FREE.slot_20(pid, 60);"]),
|
||||
("block_046D", ["goto block_01E2;"]),
|
||||
("block_0470", ["return;"]),
|
||||
]
|
||||
|
||||
rendered = render_partially_structured_blocks(blocks)
|
||||
|
||||
text = "\n".join(rendered)
|
||||
self.assertIn("while (true) {", text)
|
||||
self.assertNotIn("goto block_01E2;", text)
|
||||
self.assertNotIn("block_046D:", text)
|
||||
|
||||
def test_pseudocode_validator_reports_missing_label(self) -> None:
|
||||
errors = validate_pseudocode_text(
|
||||
"function sample()\n{\n entry:\n goto missing;\n}\n"
|
||||
)
|
||||
|
||||
self.assertEqual(errors, ["line 4: goto target missing has no label"])
|
||||
|
||||
def test_pseudocode_validator_accepts_balanced_text(self) -> None:
|
||||
errors = validate_pseudocode_text(
|
||||
"function sample()\n{\n entry:\n while (true) {\n goto entry;\n }\n}\n"
|
||||
)
|
||||
|
||||
self.assertEqual(errors, [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue