Last active
June 18, 2020 14:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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