import os import unittest from poc import elf LIB = os.path.join(os.path.dirname(__file__), "..", "research", "libphp.so") @unittest.skipUnless(os.path.exists(LIB), "research/libphp.so not captured") class ElfTest(unittest.TestCase): def test_symbol_offsets_match_profile(self): syms = elf.symbol_offsets(LIB, ["zval_ptr_dtor", "zif_system"]) self.assertEqual(syms["zval_ptr_dtor"], 0x65EB60) self.assertEqual(syms["zif_system"], 0x465370) def test_missing_symbol_is_none(self): syms = elf.symbol_offsets(LIB, ["definitely_not_a_symbol"]) self.assertIsNone(syms["definitely_not_a_symbol"]) def test_rejects_non_elf(self): with self.assertRaises(ValueError): elf.symbol_offsets(__file__, ["main"])