Skip to content

Instantly share code, notes, and snippets.

@ph1ee
Last active June 18, 2020 14:47
Show Gist options
  • Save ph1ee/b9737ce2de944f087c1ec88af62441c9 to your computer and use it in GitHub Desktop.
Save ph1ee/b9737ce2de944f087c1ec88af62441c9 to your computer and use it in GitHub Desktop.
filecut is a tool to extract a chunk of bytes within a binary file
#!/usr/bin/env python3
import sys
import os
def main(infile, extent):
try:
begin, end = extent.split("-")
size = end - begin
except ValueError:
# Just like GDB expression
begin, size = extent.split("@")
begin = int(begin, base=0)
size = int(size, base=0)
with open(infile, "rb") as f:
f.seek(begin)
sys.stdout.buffer.write(f.read(size))
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment