From b29ea61a90b254a5a7016320e60732d641ab2a39 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Thu, 1 Oct 2026 16:08:27 -0500 Subject: [PATCH 1/2] Treat absent .data sections as empty string pools --- tools/decomp-assist/pool_diff.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/decomp-assist/pool_diff.py b/tools/decomp-assist/pool_diff.py index 7b8d55e3..e41bee78 100644 --- a/tools/decomp-assist/pool_diff.py +++ b/tools/decomp-assist/pool_diff.py @@ -7,8 +7,10 @@ BASE = 'build/43U/obj/src/utility/iplESMisc.o' def pool(path): e = ELFFile(open(path, 'rb')) - sec = {s.name: s for s in e.iter_sections()} - d = sec['.data'].data() + section = e.get_section_by_name('.data') + if section is None: + return [] + d = section.data() out = [] off = 0 while off < len(d): @@ -42,6 +44,7 @@ def main(): for j in range(n, max(len(mine), len(base))): src = mine if j < len(mine) else base print(' extra %3d %r' % (j, src[j][1][:70])) + return 1 return 0 -- 2.49.1 From df26ca27d61012d8d86eb8a45359fea3d0516f62 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Thu, 1 Oct 2026 16:08:32 -0500 Subject: [PATCH 2/2] Test absent and unequal string pools --- tools/decomp-assist/test_pool_diff.py | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tools/decomp-assist/test_pool_diff.py diff --git a/tools/decomp-assist/test_pool_diff.py b/tools/decomp-assist/test_pool_diff.py new file mode 100644 index 00000000..b2f12331 --- /dev/null +++ b/tools/decomp-assist/test_pool_diff.py @@ -0,0 +1,53 @@ +import contextlib +import io +import unittest +from unittest.mock import Mock, mock_open, patch + +import pool_diff + + +class PoolDiffTests(unittest.TestCase): + def read_pool(self, data): + elf = Mock() + section = None if data is None else Mock() + if section is not None: + section.data.return_value = data + elf.get_section_by_name.return_value = section + with patch('builtins.open', mock_open(read_data=b'')), patch.object(pool_diff, 'ELFFile', return_value=elf): + result = pool_diff.pool('test.o') + elf.get_section_by_name.assert_called_once_with('.data') + return result + + def compare(self, left, right): + with patch.object(pool_diff.sys, 'argv', ['pool_diff.py', 'left.o', 'right.o']), \ + patch.object(pool_diff, 'pool', side_effect=[left, right]), \ + contextlib.redirect_stdout(io.StringIO()): + return pool_diff.main() + + def test_missing_data_has_no_strings(self): + self.assertEqual(self.read_pool(None), []) + + def test_empty_data_has_no_strings(self): + self.assertEqual(self.read_pool(b''), []) + + def test_existing_string_extraction(self): + self.assertEqual(self.read_pool(b'abc\x00hello\x00world\x00'), [(4, 'hello'), (10, 'world')]) + + def test_two_missing_pools_match(self): + self.assertEqual(self.compare([], []), 0) + + def test_identical_pools_match(self): + self.assertEqual(self.compare([(0, 'hello')], [(0, 'hello')]), 0) + + def test_changed_string_fails(self): + self.assertEqual(self.compare([(0, 'hello')], [(0, 'world')]), 1) + + def test_missing_left_pool_does_not_hide_strings(self): + self.assertEqual(self.compare([], [(0, 'hello')]), 1) + + def test_missing_right_pool_does_not_hide_strings(self): + self.assertEqual(self.compare([(0, 'hello')], []), 1) + + +if __name__ == '__main__': + unittest.main() -- 2.49.1