Skip to content

Instantly share code, notes, and snippets.

@GitMirar
Created January 29, 2016 04:12
Show Gist options
  • Save GitMirar/aa35d275cf9fb4015a8a to your computer and use it in GitHub Desktop.
Save GitMirar/aa35d275cf9fb4015a8a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import os, sys
PDF_STAOBJ_STASTR = '\x0A\x25\x50\x44\x46\x2D\x31\x2E\x34\x0A\x6F\x62\x6A\x3C\x3C\x3E\x3E\x73\x74\x72\x65\x61\x6D\x0A'
PDF_ENDSTR_ENDOBJ = '\x65\x6e\x64\x73\x74\x72\x65\x61\x6d\x0a\x65\x6e\x64\x6f\x62\x6a\x0a'
def main():
patched_pdf = sys.argv[1].replace(".exe", ".pdf")
if (len(sys.argv) != 3):
print("usage: " + sys.argv[0] + " [BINARY] [PDF]")
sys.exit(-1)
path_binary = sys.argv[1]
path_pdf = sys.argv[2]
try:
with open(path_binary, 'r') as f:
binary = f.read()
with open(path_pdf, 'r') as f:
pdf = f.read()
with open(patched_pdf, "w+") as f:
f.write(binary)
f.write(PDF_ENDSTR_ENDOBJ)
f.write(pdf)
f.seek(2) # after MZ
f.write(PDF_STAOBJ_STASTR)
except IOError as e:
print(e)
sys.exit(-1)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment