More brandelf.py updates.
This commit is contained in:
parent
36e9c27e9c
commit
49a97eea4b
@ -43,40 +43,50 @@ class opts:
|
|||||||
# ************************************************************************/
|
# ************************************************************************/
|
||||||
|
|
||||||
def do_file(fn):
|
def do_file(fn):
|
||||||
fp = open(fn, "r+b")
|
done = 1
|
||||||
|
if opts.dry_run:
|
||||||
|
fp = open(fn, "rb")
|
||||||
|
else:
|
||||||
|
fp = open(fn, "r+b")
|
||||||
fp.seek(0, 0)
|
fp.seek(0, 0)
|
||||||
e_ident = fp.read(16)
|
e_ident = fp.read(16)
|
||||||
fp.seek(0, 0)
|
fp.seek(0, 0)
|
||||||
if e_ident[:4] != "\x7f\x45\x4c\x46":
|
|
||||||
raise Exception, "%s is not %s" % (fn, "ELF")
|
def write(s):
|
||||||
if opts.bfdname == "elf32-i386" and opts.elfosabi == "freebsd":
|
if not opts.dry_run:
|
||||||
if e_ident[4:7] != "\x01\x01\x01":
|
fp.write(s)
|
||||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
|
||||||
|
if opts.bfdname[:3] == "elf":
|
||||||
|
if e_ident[:4] != "\x7f\x45\x4c\x46":
|
||||||
|
raise Exception, "%s is not %s" % (fn, "ELF")
|
||||||
fp.seek(7, 0)
|
fp.seek(7, 0)
|
||||||
fp.write("\x09")
|
if opts.bfdname == "elf32-i386" and opts.elfosabi == "freebsd":
|
||||||
elif opts.bfdname == "elf32-i386" and opts.elfosabi == "linux":
|
if e_ident[4:7] != "\x01\x01\x01":
|
||||||
if e_ident[4:7] != "\x01\x01\x01":
|
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
write("\x09")
|
||||||
fp.seek(8, 0)
|
elif opts.bfdname == "elf32-i386" and opts.elfosabi == "linux":
|
||||||
fp.write("Linux\x00\x00\x00")
|
if e_ident[4:7] != "\x01\x01\x01":
|
||||||
elif opts.bfdname == "elf32-i386" and opts.elfosabi == "openbsd":
|
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||||
if e_ident[4:7] != "\x01\x01\x01":
|
write("\x00Linux\x00\x00\x00")
|
||||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
elif opts.bfdname == "elf32-i386" and opts.elfosabi == "openbsd":
|
||||||
fp.seek(7, 0)
|
if e_ident[4:7] != "\x01\x01\x01":
|
||||||
fp.write("\x0c")
|
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||||
elif opts.bfdname == "elf32-powerpc" and opts.elfosabi == "linux":
|
write("\x0c")
|
||||||
if e_ident[4:7] != "\x01\x02\x01":
|
elif opts.bfdname == "elf32-powerpc" and opts.elfosabi == "linux":
|
||||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
if e_ident[4:7] != "\x01\x02\x01":
|
||||||
fp.seek(8, 0)
|
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||||
fp.write("Linux\x00\x00\x00")
|
write("\x00Linux\x00\x00\x00")
|
||||||
elif opts.bfdname == "elf64-x86_64" and opts.elfosabi == "linux":
|
elif opts.bfdname == "elf64-x86_64" and opts.elfosabi == "linux":
|
||||||
if e_ident[4:7] != "\x02\x01\x01":
|
if e_ident[4:7] != "\x02\x01\x01":
|
||||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||||
fp.seek(8, 0)
|
write("\x00Linux\x00\x00\x00")
|
||||||
fp.write("Linux\x00\x00\x00")
|
else:
|
||||||
|
done = 0
|
||||||
else:
|
else:
|
||||||
raise Exception, ("error: invalid args", opts.__dict__)
|
done = 0
|
||||||
fp.close()
|
fp.close()
|
||||||
|
if not done:
|
||||||
|
raise Exception, ("error: invalid args", opts.__dict__)
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user