im = re_usestack.match(insn)
if im is not None:
- if insn[:5] == 'pushl' or insn[:6] == 'pushfl':
+ if insn.startswith('pushl') or insn.startswith('pushfl'):
stackusage += 4
continue
- elif insn[:5] == 'pushw' or insn[:6] == 'pushfw':
+ elif insn.startswith('pushw') or insn.startswith('pushfw'):
stackusage += 2
continue
stackusage += int(im.group('num'), 16)
insnaddr = m.group('insnaddr')
calladdr = m.group('calladdr')
if calladdr is None:
- if insn[:6] == 'lcallw':
+ if insn.startswith('lcallw'):
noteCall(cur, subfuncs, insnaddr, -1, stackusage + 4)
noteYield(cur, stackusage + 4)
- elif insn[:3] == 'int':
+ elif insn.startswith('int'):
noteCall(cur, subfuncs, insnaddr, -1, stackusage + 6)
noteYield(cur, stackusage + 6)
- elif insn[:3] == 'sti':
+ elif insn.startswith('sti'):
noteYield(cur, stackusage)
else:
# misc instruction
if '+' in ref:
# Inter-function jump.
pass
- elif insn[:1] == 'j':
+ elif insn.startswith('j'):
# Tail call
noteCall(cur, subfuncs, insnaddr, calladdr, 0)
- elif insn[:5] == 'calll':
+ elif insn.startswith('calll'):
noteCall(cur, subfuncs, insnaddr, calladdr, stackusage + 4)
else:
print "unknown call", ref
# Return the subset of sections with a given name prefix
def getSectionsPrefix(sections, prefix):
- lp = len(prefix)
out = []
for size, align, name in sections:
- if name[:lp] == prefix:
+ if name.startswith(prefix):
out.append((size, align, name))
return out
fixedsections = []
for sectioninfo in sections:
size, align, name = sectioninfo
- if name[:11] == '.fixedaddr.':
+ if name.startswith('.fixedaddr.'):
addr = int(name[11:], 16)
fixedsections.append((addr, sectioninfo))
if align != 1:
# Find and keep the section associated with a symbol (if available).
def keepsymbol(symbol, infos, pos, callerpos=None):
addr, section = infos[pos][1].get(symbol, (None, None))
- if section is None or '*' in section or section[:9] == '.discard.':
+ if section is None or '*' in section or section.startswith('.discard.'):
return -1
if callerpos is not None and symbol not in infos[callerpos][4]:
# This symbol reference is a cross section reference (an xref).
(info32flat[0], info32flat[1], info32flat[2], [], {}))
# Start by keeping sections that are globally visible.
for size, align, section in info16[0]:
- if section[:11] == '.fixedaddr.' or '.export.' in section:
+ if section.startswith('.fixedaddr.') or '.export.' in section:
keepsection(section, infos)
keepsymbol('post32', infos, 0, 2)
# Return sections found.
if line == 'SYMBOL TABLE:':
state = 'symbol'
continue
- if line[:24] == 'RELOCATION RECORDS FOR [':
+ if line.startswith('RELOCATION RECORDS FOR ['):
state = 'reloc'
relocsection = line[24:-2]
continue