mirror of
https://github.com/brain-hackers/lab
synced 2026-03-12 06:04:18 +09:00
Add x1 experiments
This commit is contained in:
27
x1/extract.py
Executable file
27
x1/extract.py
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
from elftools.elf.elffile import ELFFile # pip install pyelftools
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 3:
|
||||
print(f'Usage: {sys.argv[0]} in.elf out.bin')
|
||||
sys.exit(1)
|
||||
|
||||
with open(sys.argv[1], 'rb') as f:
|
||||
extract(ELFFile(f))
|
||||
|
||||
|
||||
def extract(elf):
|
||||
text = elf.get_section_by_name('.text')
|
||||
if text is None:
|
||||
print('Input ELF has no .text section', file=sys.stderr)
|
||||
|
||||
with open(sys.argv[2], 'wb') as f:
|
||||
f.write(text.data())
|
||||
|
||||
print(f'Successfully extracted the .text section to "{sys.argv[2]}"')
|
||||
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user