mirror of
https://github.com/fail0verflow/mini.git
synced 2024-11-24 04:09:18 +01:00
port makebin.py to python3
This commit is contained in:
parent
befb64ce1c
commit
fc1234b22d
18
makebin.py
18
makebin.py
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, struct
|
||||
|
||||
@ -11,7 +11,7 @@ data = open(loaderfile,"rb").read()
|
||||
hdrlen, loaderlen, elflen, arg = struct.unpack(">IIII",data[:16])
|
||||
|
||||
if hdrlen < 0x10:
|
||||
print "ERROR: header length is 0x%x, expected at least 0x10"%hdrlen
|
||||
print("ERROR: header length is 0x%x, expected at least 0x10"%hdrlen)
|
||||
sys.exit(1)
|
||||
|
||||
loaderoff = hdrlen
|
||||
@ -24,25 +24,25 @@ loader = data[loaderoff:elfoff]
|
||||
elf = open(elffile,"rb").read()
|
||||
|
||||
if elflen > 0:
|
||||
print "WARNING: loader already contains ELF, will replace"
|
||||
print("WARNING: loader already contains ELF, will replace")
|
||||
|
||||
elflen = len(elf)
|
||||
|
||||
if loaderlen < len(loader):
|
||||
print "ERROR: loader is larger than its reported length"
|
||||
print("ERROR: loader is larger than its reported length")
|
||||
sys.exit(1)
|
||||
|
||||
if loaderlen > len(loader):
|
||||
print "Padding loader with 0x%x zeroes"%(loaderlen-len(loader))
|
||||
loader += "\x00"*(loaderlen-len(loader))
|
||||
print("Padding loader with 0x%x zeroes"%(loaderlen-len(loader)))
|
||||
loader += b"\0"*(loaderlen-len(loader))
|
||||
|
||||
newdata = struct.pack(">IIII", hdrlen, loaderlen, elflen, 0) + hdr[16:]
|
||||
newdata += loader
|
||||
newdata += elf
|
||||
|
||||
print "Header: 0x%x bytes"%(hdrlen)
|
||||
print "Loader: 0x%x bytes"%(loaderlen)
|
||||
print "ELF: 0x%x bytes"%(elflen)
|
||||
print("Header: 0x%x bytes"%(hdrlen))
|
||||
print("Loader: 0x%x bytes"%(loaderlen))
|
||||
print("ELF: 0x%x bytes"%(elflen))
|
||||
|
||||
f = open(outfile,"wb")
|
||||
f.write(newdata)
|
||||
|
Loading…
Reference in New Issue
Block a user