1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Updated brandelf.py.

This commit is contained in:
Markus F.X.J. Oberhumer 2006-11-16 22:23:01 +01:00
parent 6e5153cd07
commit 36e9c27e9c

View File

@ -47,15 +47,31 @@ def do_file(fn):
fp.seek(0, 0)
e_ident = fp.read(16)
fp.seek(0, 0)
if e_ident[:7] != "\x7f\x45\x4c\x46\x01\x01\x01":
raise Exception, "%s is not ELF" % fn
if e_ident[:4] != "\x7f\x45\x4c\x46":
raise Exception, "%s is not %s" % (fn, "ELF")
if opts.bfdname == "elf32-i386" and opts.elfosabi == "freebsd":
if e_ident[4:7] != "\x01\x01\x01":
raise Exception, "%s is not %s" % (fn, opts.bfdname)
fp.seek(7, 0)
fp.write("\x09")
elif opts.bfdname == "elf32-i386" and opts.elfosabi == "linux":
if e_ident[4:7] != "\x01\x01\x01":
raise Exception, "%s is not %s" % (fn, opts.bfdname)
fp.seek(8, 0)
fp.write("Linux\x00\x00\x00")
elif opts.bfdname == "elf32-i386" and opts.elfosabi == "openbsd":
if e_ident[4:7] != "\x01\x01\x01":
raise Exception, "%s is not %s" % (fn, opts.bfdname)
fp.seek(7, 0)
fp.write("\x0c")
elif opts.bfdname == "elf32-i386" and opts.elfosabi == "linux":
elif opts.bfdname == "elf32-powerpc" and opts.elfosabi == "linux":
if e_ident[4:7] != "\x01\x02\x01":
raise Exception, "%s is not %s" % (fn, opts.bfdname)
fp.seek(8, 0)
fp.write("Linux\x00\x00\x00")
elif opts.bfdname == "elf64-x86_64" and opts.elfosabi == "linux":
if e_ident[4:7] != "\x02\x01\x01":
raise Exception, "%s is not %s" % (fn, opts.bfdname)
fp.seek(8, 0)
fp.write("Linux\x00\x00\x00")
else: