From 52819fcce7af4dbc90de90aa774c193b60805757 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Sat, 5 Aug 2023 19:15:37 +0000 Subject: [PATCH] Fix a small bug with decompiler optimizer passes preventing MGA matching SWF decompilation. --- bemani/format/afp/swf.py | 4 ++- bemani/format/afp/types/statement.py | 40 +++++++++++++++++----------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/bemani/format/afp/swf.py b/bemani/format/afp/swf.py index f2fcaee..56bc4e9 100644 --- a/bemani/format/afp/swf.py +++ b/bemani/format/afp/swf.py @@ -2232,7 +2232,9 @@ class SWF(VerboseOutput, TrackedCoverage): ap2data[dataoffset : (dataoffset + 12)], ) self.add_coverage(dataoffset, 12) - if flags != 0: + + # TODO: There are some flags bits here that I do not understand. + if flags not in {0x0, 0x4}: raise Exception(f"Unexpected flags {hex(flags)} in AP2_DEFINE_TEXT!") extra_data = 12 + (20 * text_data_count) + (4 * sub_data_total_count) diff --git a/bemani/format/afp/types/statement.py b/bemani/format/afp/types/statement.py index 8b879e7..44e57ee 100644 --- a/bemani/format/afp/types/statement.py +++ b/bemani/format/afp/types/statement.py @@ -748,16 +748,20 @@ def _negative_absorb_and(left: IfExpr, right: IfExpr) -> Optional[IfExpr]: for val in right_ors: if neg_left == val: - return AndIf( - left, - _accum_or([o for o in right_ors if o is not val]), - ).simplify() + other_ors = [o for o in right_ors if o is not val] + if other_ors: + return AndIf( + left, + _accum_or(other_ors), + ).simplify() for val in left_ors: if neg_right == val: - return AndIf( - _accum_or([o for o in left_ors if o is not val]), - right, - ).simplify() + other_ors = [o for o in left_ors if o is not val] + if other_ors: + return AndIf( + _accum_or(other_ors), + right, + ).simplify() return None @@ -811,16 +815,20 @@ def _negative_absorb_or(left: IfExpr, right: IfExpr) -> Optional[IfExpr]: for val in right_ands: if neg_left == val: - return OrIf( - left, - _accum_and([o for o in right_ands if o is not val]), - ).simplify() + other_ands = [o for o in right_ands if o is not val] + if other_ands: + return OrIf( + left, + _accum_and(other_ands), + ).simplify() for val in left_ands: if neg_right == val: - return OrIf( - _accum_and([o for o in left_ands if o is not val]), - right, - ).simplify() + other_ands = [o for o in left_ands if o is not val] + if other_ands: + return OrIf( + _accum_and(other_ands), + right, + ).simplify() return None