all: misc cleanups
This commit is contained in:
@@ -256,7 +256,7 @@ def compress_stub(method, idata):
|
||||
# encode upx stub header
|
||||
odata = encode_compressed_stub_header(method, idata, odata) + odata
|
||||
else:
|
||||
raise Exception, ("invalid method", method, opts.methods)
|
||||
raise Exception("invalid method", method, opts.methods)
|
||||
if 1 and len(odata) >= len(idata):
|
||||
# not compressible
|
||||
return 0, idata
|
||||
|
||||
@@ -58,29 +58,29 @@ def do_file(fn):
|
||||
|
||||
def brand_arm(s):
|
||||
if e_ident[4:7] != s:
|
||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||
write("\x61") # ELFOSABI_ARM
|
||||
def brand_freebsd(s):
|
||||
if e_ident[4:7] != s:
|
||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||
write("\x09")
|
||||
def brand_linux(s):
|
||||
if e_ident[4:7] != s:
|
||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||
##write("\x00Linux\x00\x00\x00")
|
||||
write("\x00" * 9)
|
||||
def brand_netbsd(s):
|
||||
if e_ident[4:7] != s:
|
||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||
write("\x02")
|
||||
def brand_openbsd(s):
|
||||
if e_ident[4:7] != s:
|
||||
raise Exception, "%s is not %s" % (fn, opts.bfdname)
|
||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||
write("\x0c")
|
||||
|
||||
if opts.bfdname[:3] == "elf":
|
||||
if e_ident[:4] != "\x7f\x45\x4c\x46":
|
||||
raise Exception, "%s is not %s" % (fn, "ELF")
|
||||
raise Exception("%s is not %s" % (fn, "ELF"))
|
||||
fp.seek(7, 0)
|
||||
if opts.bfdname == "elf32-bigarm" and opts.elfosabi == "arm":
|
||||
brand_arm("\x01\x02\x01")
|
||||
@@ -106,7 +106,7 @@ def do_file(fn):
|
||||
done = 0
|
||||
fp.close()
|
||||
if not done:
|
||||
raise Exception, ("error: invalid args", opts.__dict__)
|
||||
raise Exception("error: invalid args", opts.__dict__)
|
||||
|
||||
|
||||
def main(argv):
|
||||
@@ -127,7 +127,7 @@ def main(argv):
|
||||
else: assert 0, ("getopt problem:", opt, optarg, xopts, args)
|
||||
# process arguments
|
||||
if not args:
|
||||
raise Exception, "error: no arguments given"
|
||||
raise Exception("error: no arguments given")
|
||||
for arg in args:
|
||||
do_file(arg)
|
||||
return 0
|
||||
|
||||
@@ -63,7 +63,7 @@ def not_found(state, l, inc, fatal=None):
|
||||
if fatal is None:
|
||||
fatal = opts.fatal
|
||||
if fatal:
|
||||
raise Exception, "%s:%d: include file %s not found" % (state[0], state[2], inc)
|
||||
raise Exception("%s:%d: include file %s not found" % (state[0], state[2], inc))
|
||||
return l
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ def parse_comment(state, l, comment):
|
||||
if f == "ignore=0": cf["fatal"] = 1
|
||||
elif f == "ignore=1": cf["fatal"] = 0
|
||||
else:
|
||||
raise Exception, "%s:%d: bad flags %s %s" % (state[0], state[2], f, str(flags))
|
||||
raise Exception("%s:%d: bad flags %s %s" % (state[0], state[2], f, str(flags)))
|
||||
return cf
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ def handle_inc_c(state, l, ofp):
|
||||
elif q1 == '"' and q2 == '"':
|
||||
dirs = [state[1]] + opts.includes
|
||||
else:
|
||||
raise Exception, "syntax error: include line " + l
|
||||
raise Exception("syntax error: include line " + l)
|
||||
for dir in dirs:
|
||||
fn = os.path.join(dir, inc)
|
||||
if os.path.isfile(fn):
|
||||
@@ -114,7 +114,7 @@ def handle_inc_nasm(state, l, ofp):
|
||||
elif q1 == '"' and q2 == '"':
|
||||
pass
|
||||
else:
|
||||
raise Exception, "syntax error: include line " + l
|
||||
raise Exception("syntax error: include line " + l)
|
||||
# info: nasm simply does concat the includes
|
||||
for prefix in opts.includes + [""]:
|
||||
fn = prefix + inc
|
||||
|
||||
@@ -73,6 +73,8 @@ def check_dump(dump_fn):
|
||||
psections = d.find("Sections:\n")
|
||||
psymbols = d.find("SYMBOL TABLE:\n")
|
||||
prelocs = d.find("RELOCATION RECORDS FOR ");
|
||||
if prelocs == -1: # no relocations
|
||||
prelocs = len(d)
|
||||
assert 0 <= psections < psymbols < prelocs
|
||||
# preprocessSections
|
||||
sections = []
|
||||
@@ -139,7 +141,7 @@ def do_file(fn):
|
||||
fp.seek(0, 0)
|
||||
idata = fp.read()
|
||||
if idata[:4] != "\x7f\x45\x4c\x46":
|
||||
raise Exception, "%s is not %s" % (fn, "ELF")
|
||||
raise Exception("%s is not %s" % (fn, "ELF"))
|
||||
if idata[4:7] == "\x01\x01\x01":
|
||||
# ELF32 LE
|
||||
eh, idata = idata[:52], idata[52:]
|
||||
@@ -162,7 +164,7 @@ def do_file(fn):
|
||||
e_shnum, e_shstrndx = struct.unpack(">HH", eh[60:64])
|
||||
assert e_shstrndx + 3 == e_shnum
|
||||
else:
|
||||
raise Exception, "%s is not %s" % (fn, "ELF")
|
||||
raise Exception("%s is not %s" % (fn, "ELF"))
|
||||
|
||||
odata = None
|
||||
pos = idata.find("\0.symtab\0.strtab\0.shstrtab\0")
|
||||
@@ -207,7 +209,7 @@ def main(argv):
|
||||
elif opt in ["--with-dump"]: opts.with_dump = optarg
|
||||
else: assert 0, ("getopt problem:", opt, optarg, xopts, args)
|
||||
if not args:
|
||||
raise Exception, "error: no arguments given"
|
||||
raise Exception("error: no arguments given")
|
||||
if opts.with_dump or opts.bindump:
|
||||
assert len(args) == 1, "need exactly one file"
|
||||
# process arguments
|
||||
|
||||
Reference in New Issue
Block a user