Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 26188ce

Browse files
black
1 parent e1c5b44 commit 26188ce

25 files changed

+122
-406
lines changed

idb/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def memview(buf):
1515
# bytes(memoryview('foo')) == "<memoryview ...>"
1616
return buf
1717

18-
1918
else:
2019

2120
def memview(buf):

idb/analysis.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ def __init__(self, db, nodeid, fields):
258258
# note that order of fields is important:
259259
# fields with matching minvers override previously defined fields of the same name
260260
self._fields_by_name = {
261-
f.name: f
262-
for f in self.fields
263-
if (not f.minver) or (f.minver and idb_version >= f.minver)
261+
f.name: f for f in self.fields if (not f.minver) or (f.minver and idb_version >= f.minver)
264262
}
265263

266264
def _is_address(self, index):
@@ -457,9 +455,7 @@ def u32_(self):
457455
if val == 0xFF:
458456
val = self.u32(big=True)
459457
elif val & 0xC0 == 0xC0:
460-
val = (
461-
((val & 0x1F) << 24) | (self.u8() << 16) | (self.u8() << 8) | self.u8()
462-
)
458+
val = ((val & 0x1F) << 24) | (self.u8() << 16) | (self.u8() << 8) | self.u8()
463459
elif val & 0x80:
464460
val = ((val & 0x3F) << 8) | self.u8()
465461
return val
@@ -1174,9 +1170,7 @@ def pairs(l):
11741170

11751171
Chunk = namedtuple("Chunk", ["effective_address", "length"])
11761172
FunctionParameter = namedtuple("FunctionParameter", ["type", "name"])
1177-
FunctionSignature = namedtuple(
1178-
"FunctionSignature", ["calling_convention", "rtype", "unk", "parameters"]
1179-
)
1173+
FunctionSignature = namedtuple("FunctionSignature", ["calling_convention", "rtype", "unk", "parameters"])
11801174
StackChangePoint = namedtuple("StackChangePoint", ["effective_address", "change"])
11811175

11821176

@@ -1226,9 +1220,7 @@ def get_signature(self):
12261220
typedata.deserialize(self.idb.til, ts, names, [])
12271221
inf = Root(self.idb).idainfo
12281222

1229-
return idb.typeinf.TInfo(
1230-
typ, typedata, til=self.idb.til, name=self.get_name(), inf=inf
1231-
)
1223+
return idb.typeinf.TInfo(typ, typedata, til=self.idb.til, name=self.get_name(), inf=inf)
12321224
except KeyError:
12331225
return None
12341226

@@ -1283,7 +1275,7 @@ def get_stack_change_points(self):
12831275
unpacker = unpack_dqs
12841276
else:
12851277
raise RuntimeError("unexpected wordsize")
1286-
for (delta, change) in pairs(unpacker(v)):
1278+
for delta, change in pairs(unpacker(v)):
12871279
offset += delta
12881280
if change & 1:
12891281
change = change >> 1
@@ -1575,9 +1567,7 @@ def enumerate_imports(db):
15751567
],
15761568
)
15771569

1578-
EntryPoint = namedtuple(
1579-
"EntryPoint", ["name", "address", "ordinal", "forwarded_symbol"]
1580-
)
1570+
EntryPoint = namedtuple("EntryPoint", ["name", "address", "ordinal", "forwarded_symbol"])
15811571

15821572

15831573
def enumerate_entrypoints(db):
@@ -1597,14 +1587,10 @@ def enumerate_entrypoints(db):
15971587
for index, addr in ents.functions.items():
15981588
if index == db.uint(-1):
15991589
break
1600-
yield EntryPoint(
1601-
names.get(index), addr, ordinals.get(index), forwarded_symbols.get(index)
1602-
)
1590+
yield EntryPoint(names.get(index), addr, ordinals.get(index), forwarded_symbols.get(index))
16031591

16041592
for index, addr in ents.main_entry.items():
1605-
yield EntryPoint(
1606-
names.get(index), addr, ordinals.get(index), forwarded_symbols.get(index)
1607-
)
1593+
yield EntryPoint(names.get(index), addr, ordinals.get(index), forwarded_symbols.get(index))
16081594

16091595

16101596
ScriptSnippets = Analysis(

idb/fileformat.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
lots of inspiration from: https://github.com/nlitsme/pyidbutil
33
"""
4+
45
import re
56
import abc
67
import zlib
@@ -762,9 +763,7 @@ def prev(self):
762763
next_page = self.index.get_page(next_page_number)
763764
while not next_page.is_leaf():
764765
self.path.append(next_page)
765-
next_page = self.index.get_page(
766-
next_page.get_entry(next_page.entry_count - 1).page
767-
)
766+
next_page = self.index.get_page(next_page.get_entry(next_page.entry_count - 1).page)
768767

769768
self.path.append(next_page)
770769
self.entry = next_page.get_entry(next_page.entry_count - 1)
@@ -962,9 +961,7 @@ def pcb__segments(self):
962961
for i in range(self.segment_count):
963962
segment = self._segments[i]
964963
segment_byte_count = segment.end - segment.start
965-
segment_length = (
966-
4 * segment_byte_count
967-
) # each flag entry is a uint32 on all platforms
964+
segment_length = 4 * segment_byte_count # each flag entry is a uint32 on all platforms
968965
self.segments.append(ID1.SegmentDescriptor(segment, offset))
969966
offset += segment_length
970967
offset = 0x14 + (self.segment_count * (2 * self.wordsize))

idb/idapython.py

Lines changed: 19 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,7 @@ class idc:
644644
SEGPERM_READ = 4 # Read
645645
SEGPERM_MAXVAL = 7 # (SEGPERM_EXEC + SEGPERM_WRITE + SEGPERM_READ)
646646

647-
SFL_COMORG = (
648-
0x01 # IDP dependent field (IBM PC: if set, ORG directive is not commented out)
649-
)
647+
SFL_COMORG = 0x01 # IDP dependent field (IBM PC: if set, ORG directive is not commented out)
650648
SFL_OBOK = 0x02 # orgbase is present? (IDP dependent field)
651649
SFL_HIDDEN = 0x04 # is the segment hidden?
652650
SFL_DEBUG = 0x08 # is the segment created for the debugger?
@@ -844,9 +842,7 @@ def GetSegmentAttr(self, ea, attr):
844842
elif attr == self.SEGATTR_COLOR:
845843
return self._get_segment(ea).color
846844
else:
847-
raise NotImplementedError(
848-
"segment attribute %d not yet implemented" % (attr)
849-
)
845+
raise NotImplementedError("segment attribute %d not yet implemented" % (attr))
850846

851847
def MinEA(self):
852848
segs = idb.analysis.Segments(self.idb).segments.values()
@@ -885,9 +881,7 @@ def ItemSize(self, ea):
885881
def NextHead(self, ea):
886882
ea += 1
887883
flags = self.GetFlags(ea)
888-
while (
889-
flags is not None and flags != 0 and not self.api.ida_bytes.is_head(flags)
890-
):
884+
while flags is not None and flags != 0 and not self.api.ida_bytes.is_head(flags):
891885
ea += 1
892886
# TODO: handle Index/KeyError here when we overrun a segment
893887
flags = self.GetFlags(ea)
@@ -1030,20 +1024,13 @@ def _disassemble(self, ea):
10301024
)
10311025
elif procname == "sparcb":
10321026
if bitness == 32:
1033-
dis = self._load_dis(
1034-
capstone.CS_ARCH_SPARC, capstone.CS_MODE_BIG_ENDIAN
1035-
)
1027+
dis = self._load_dis(capstone.CS_ARCH_SPARC, capstone.CS_MODE_BIG_ENDIAN)
10361028
elif procname == "sparcl":
10371029
if bitness == 32:
1038-
dis = self._load_dis(
1039-
capstone.CS_ARCH_SPARC, capstone.CS_MODE_LITTLE_ENDIAN
1040-
)
1030+
dis = self._load_dis(capstone.CS_ARCH_SPARC, capstone.CS_MODE_LITTLE_ENDIAN)
10411031

10421032
if dis is None:
1043-
raise NotImplementedError(
1044-
"unknown arch %s bit:%s inst_len:%d"
1045-
% (procname, bitness, len(inst_buf))
1046-
)
1033+
raise NotImplementedError("unknown arch %s bit:%s inst_len:%d" % (procname, bitness, len(inst_buf)))
10471034
dis.detail = True
10481035

10491036
try:
@@ -1294,22 +1281,12 @@ def isCustFmt1(flags):
12941281
@staticmethod
12951282
def isNum0(flags):
12961283
t = flags & FLAGS.MS_0TYPE
1297-
return (
1298-
t == FLAGS.FF_0NUMB
1299-
or t == FLAGS.FF_0NUMO
1300-
or t == FLAGS.FF_0NUMD
1301-
or t == FLAGS.FF_0NUMH
1302-
)
1284+
return t == FLAGS.FF_0NUMB or t == FLAGS.FF_0NUMO or t == FLAGS.FF_0NUMD or t == FLAGS.FF_0NUMH
13031285

13041286
@staticmethod
13051287
def isNum1(flags):
13061288
t = flags & FLAGS.MS_1TYPE
1307-
return (
1308-
t == FLAGS.FF_1NUMB
1309-
or t == FLAGS.FF_1NUMO
1310-
or t == FLAGS.FF_1NUMD
1311-
or t == FLAGS.FF_1NUMH
1312-
)
1289+
return t == FLAGS.FF_1NUMB or t == FLAGS.FF_1NUMO or t == FLAGS.FF_1NUMD or t == FLAGS.FF_1NUMH
13131290

13141291
@staticmethod
13151292
def get_optype_flags0(flags):
@@ -1529,11 +1506,7 @@ def next_inited(self, ea, maxea):
15291506
def get_item_end(self, ea):
15301507
ea += 1
15311508
flags = self.api.idc.GetFlags(ea)
1532-
while (
1533-
flags is not None
1534-
and not self.api.ida_bytes.is_head(flags)
1535-
and self.api.idc.SegEnd(ea)
1536-
):
1509+
while flags is not None and not self.api.ida_bytes.is_head(flags) and self.api.idc.SegEnd(ea):
15371510
ea += 1
15381511
flags = self.api.idc.GetFlags(ea)
15391512
return ea
@@ -1919,11 +1892,7 @@ def _find_bb_end(self, ea):
19191892
Returns:
19201893
int: the address of the final instruction in the basic block. it may be the same as the start.
19211894
"""
1922-
if not is_empty(
1923-
idb.analysis.get_crefs_from(
1924-
self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F]
1925-
)
1926-
):
1895+
if not is_empty(idb.analysis.get_crefs_from(self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F])):
19271896
return ea
19281897

19291898
if not self.api.idc.GetFlags(ea):
@@ -1946,11 +1915,7 @@ def _find_bb_end(self, ea):
19461915
if not self.api.ida_bytes.is_flow(flags):
19471916
return last_ea
19481917

1949-
if not is_empty(
1950-
idb.analysis.get_crefs_from(
1951-
self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F]
1952-
)
1953-
):
1918+
if not is_empty(idb.analysis.get_crefs_from(self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F])):
19541919
return ea
19551920

19561921
def _find_bb_start(self, ea):
@@ -1972,11 +1937,7 @@ def _find_bb_start(self, ea):
19721937
last_ea = ea
19731938
ea = self.api.idc.PrevHead(ea)
19741939

1975-
if not is_empty(
1976-
idb.analysis.get_crefs_from(
1977-
self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F]
1978-
)
1979-
):
1940+
if not is_empty(idb.analysis.get_crefs_from(self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F])):
19801941
return last_ea
19811942

19821943
if not self.api.ida_bytes.is_flow(flags):
@@ -1993,9 +1954,7 @@ def _get_flow_preds(self, ea):
19931954

19941955
# get all the flow xrefs to this instruction.
19951956
# a flow xref is like a fallthrough or jump, not like a call.
1996-
for xref in idb.analysis.get_crefs_to(
1997-
self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F]
1998-
):
1957+
for xref in idb.analysis.get_crefs_to(self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F]):
19991958
yield xref
20001959

20011960
def _get_flow_succs(self, ea):
@@ -2010,9 +1969,7 @@ def _get_flow_succs(self, ea):
20101969

20111970
# get all the flow xrefs from this instruction.
20121971
# a flow xref is like a fallthrough or jump, not like a call.
2013-
for xref in idb.analysis.get_crefs_from(
2014-
self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F]
2015-
):
1972+
for xref in idb.analysis.get_crefs_from(self.idb, ea, types=[idaapi.fl_JN, idaapi.fl_JF, idaapi.fl_F]):
20161973
yield xref
20171974

20181975
def FlowChart(self, func):
@@ -2083,9 +2040,7 @@ def __init__(self, db, api, ea):
20832040
for xref in api.idaapi._get_flow_preds(block.startEA):
20842041
if xref.frm not in bbs_by_end:
20852042
pred_start = api.idaapi._find_bb_start(xref.frm)
2086-
pred = BasicBlock(
2087-
self, pred_start, xref.frm, api.idc.NextHead(xref.frm)
2088-
)
2043+
pred = BasicBlock(self, pred_start, xref.frm, api.idc.NextHead(xref.frm))
20892044
bbs_by_start[pred.startEA] = pred
20902045
bbs_by_end[pred.lastInstEA] = pred
20912046
else:
@@ -2100,9 +2055,7 @@ def __init__(self, db, api, ea):
21002055
for xref in api.idaapi._get_flow_succs(block.lastInstEA):
21012056
if xref.to not in bbs_by_start:
21022057
succ_end = api.idaapi._find_bb_end(xref.to)
2103-
succ = BasicBlock(
2104-
self, xref.to, succ_end, api.idc.NextHead(succ_end)
2105-
)
2058+
succ = BasicBlock(self, xref.to, succ_end, api.idc.NextHead(succ_end))
21062059
bbs_by_start[succ.startEA] = succ
21072060
bbs_by_end[succ.lastInstEA] = succ
21082061
else:
@@ -2541,9 +2494,7 @@ def DataRefsFrom(self, ea):
25412494

25422495
# calls are not data references.
25432496
# global variables are data references.
2544-
for xref in idb.analysis.get_drefs_from(
2545-
self.idb, ea, types=self.ALL_DREF_TYPES
2546-
):
2497+
for xref in idb.analysis.get_drefs_from(self.idb, ea, types=self.ALL_DREF_TYPES):
25472498
yield xref.to
25482499

25492500
def DataRefsTo(self, ea):
@@ -2806,9 +2757,7 @@ def get_first_struc_idx(self):
28062757
return 0 if len(self._struct_ids) > 0 else self.api.idc.BADADDR
28072758

28082759
def get_last_struc_idx(self):
2809-
return (
2810-
self._struct_ids[-1] if len(self._struct_ids) > 0 else self.api.idc.BADADDR
2811-
)
2760+
return self._struct_ids[-1] if len(self._struct_ids) > 0 else self.api.idc.BADADDR
28122761

28132762
def get_struc(self, id):
28142763
"""Get pointer to struct type info."""
@@ -2859,9 +2808,7 @@ def get_ordinal_from_idb_type(self, name, _type):
28592808
if not _type or len(_type) == 0:
28602809
return -1
28612810
typ = self.get_named_type(name)
2862-
if self.get_base_flags(typ.type.base_type) == self.get_base_flags(
2863-
ord(_type[0])
2864-
):
2811+
if self.get_base_flags(typ.type.base_type) == self.get_base_flags(ord(_type[0])):
28652812
return typ.ordinal
28662813
else:
28672814
return -1

idb/netnode.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,9 @@ def make_key(nodeid, tag=None, index=None, wordsize=4):
9292
if index is None:
9393
return b"." + struct.pack(">" + wordformat + "c", nodeid, tag)
9494
elif index < 0:
95-
return b"." + struct.pack(
96-
">" + wordformat + "c" + wordformat.lower(), nodeid, tag, index
97-
)
95+
return b"." + struct.pack(">" + wordformat + "c" + wordformat.lower(), nodeid, tag, index)
9896
else:
99-
return b"." + struct.pack(
100-
">" + wordformat + "c" + wordformat, nodeid, tag, index
101-
)
97+
return b"." + struct.pack(">" + wordformat + "c" + wordformat, nodeid, tag, index)
10298
else:
10399
raise ValueError("unexpected type of nodeid: " + str(type(nodeid)))
104100

idb/shim.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def load_module(self, fullname):
4141
def install(self):
4242
sys.meta_path.insert(0, self)
4343

44-
4544
elif sys.version_info[0] == 3:
4645
import sys
4746
import types

0 commit comments

Comments
 (0)