| 61 | |
| 62 | |
| 63 | def parse_sections() -> list[Section]: |
| 64 | out = subprocess.check_output([str(READELF), "-SW", str(ELF)], text=True) |
| 65 | sections: list[Section] = [] |
| 66 | for line in out.splitlines(): |
| 67 | m = re.match( |
| 68 | r"\s*\[\s*\d+\]\s+(\S+)\s+\S+\s+([0-9a-f]+)\s+[0-9a-f]+\s+([0-9a-f]+)\s+\S+\s+([A-Za-z]*)", |
| 69 | line, |
| 70 | ) |
| 71 | if not m: |
| 72 | continue |
| 73 | name, addr_hex, size_hex, flags = m.groups() |
| 74 | addr = int(addr_hex, 16) |
| 75 | size = int(size_hex, 16) |
| 76 | sections.append(Section(name=name, addr=addr, size=size, flags=flags)) |
| 77 | return sections |
| 78 | |
| 79 | |
| 80 | def loaded_section_for(addr: int, sections: list[Section]) -> Section | None: |