Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply ruff suggestions #1479

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/expression/graph_dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def intra_block_flow_symb(lifter, _, flow_graph, irblock, in_nodes, out_nodes):
node_n_r = current_nodes[n_r]
else:
node_n_r = get_node_name(irblock.loc_key, i, n_r)
if not n_r in in_nodes:
if n_r not in in_nodes:
in_nodes[n_r] = node_n_r
flow_graph.add_uniq_edge(node_n_r, node_n_w)

Expand All @@ -68,7 +68,7 @@ def intra_block_flow_symb(lifter, _, flow_graph, irblock, in_nodes, out_nodes):
node_n_r = current_nodes[n_r]
else:
node_n_r = get_node_name(irblock.loc_key, 0, n_r)
if not n_r in in_nodes:
if n_r not in in_nodes:
in_nodes[n_r] = node_n_r

flow_graph.add_node(node_n_r)
Expand Down
2 changes: 1 addition & 1 deletion example/ida/graph_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def OnRefresh(self):
for dst in all_dst:
if not dst.is_loc():
continue
if not dst.loc_key in self.ircfg.blocks:
if dst.loc_key not in self.ircfg.blocks:
continue
node1 = addr_id[loc_key]
node2 = addr_id[dst.loc_key]
Expand Down
2 changes: 1 addition & 1 deletion example/ida/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def guess_machine(addr=None):

is_bigendian = info.is_be()
infos = (is_armt, size, is_bigendian)
if not infos in info2machine:
if infos not in info2machine:
raise NotImplementedError('not fully functional')
machine = Machine(info2machine[infos])

Expand Down
12 changes: 6 additions & 6 deletions miasm/analysis/data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def intra_block_flow_raw(lifter, ircfg, flow_graph, irb, in_nodes, out_nodes):

for n in all_mems:
node_n_w = get_node_name(irb.loc_key, i, n)
if not n in nodes_r:
if n not in nodes_r:
continue
o_r = n.ptr.get_r(mem_read=False, cst_read=True)
for n_r in o_r:
Expand Down Expand Up @@ -71,13 +71,13 @@ def inter_block_flow_link(lifter, ircfg, flow_graph, irb_in_nodes, irb_out_nodes
current_nodes = dict(current_nodes)

# link current nodes to block in_nodes
if not lbl in ircfg.blocks:
if lbl not in ircfg.blocks:
print("cannot find block!!", lbl)
return set()
irb = ircfg.blocks[lbl]
to_del = set()
for n_r, node_n_r in viewitems(irb_in_nodes[irb.loc_key]):
if not n_r in current_nodes:
if n_r not in current_nodes:
continue
flow_graph.add_uniq_edge(current_nodes[n_r], node_n_r)
to_del.add(n_r)
Expand All @@ -86,7 +86,7 @@ def inter_block_flow_link(lifter, ircfg, flow_graph, irb_in_nodes, irb_out_nodes
if link_exec_to_data:
for n_x_r in exec_nodes:
for n_r, node_n_r in viewitems(irb_in_nodes[irb.loc_key]):
if not n_x_r in current_nodes:
if n_x_r not in current_nodes:
continue
if isinstance(n_r, ExprInt):
continue
Expand Down Expand Up @@ -115,7 +115,7 @@ def create_implicit_flow(lifter, flow_graph, irb_in_nodes, irb_out_nodes):
lbl = todo.pop()
irb = lifter.blocks[lbl]
for lbl_son in lifter.graph.successors(irb.loc_key):
if not lbl_son in lifter.blocks:
if lbl_son not in lifter.blocks:
print("cannot find block!!", lbl)
continue
irb_son = lifter.blocks[lbl_son]
Expand All @@ -127,7 +127,7 @@ def create_implicit_flow(lifter, flow_graph, irb_in_nodes, irb_out_nodes):

node_n_w = irb.loc_key, len(irb), n_r
irb_out_nodes[irb.loc_key][n_r] = node_n_w
if not n_r in irb_in_nodes[irb.loc_key]:
if n_r not in irb_in_nodes[irb.loc_key]:
irb_in_nodes[irb.loc_key][n_r] = irb.loc_key, 0, n_r
node_n_r = irb_in_nodes[irb.loc_key][n_r]
for lbl_p in lifter.graph.predecessors(irb.loc_key):
Expand Down
2 changes: 1 addition & 1 deletion miasm/analysis/expression_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def expr_range(expr):
return - expr_range(expr.args[0])
elif expr.op == "%":
assert len(expr.args) == 2
op, mod = [expr_range(arg) for arg in expr.args]
op, mod = (expr_range(arg) for arg in expr.args)
if mod.intervals.length == 1:
# Modulo intervals is not supported
return op % mod.intervals.hull()[0]
Expand Down
42 changes: 21 additions & 21 deletions miasm/arch/aarch64/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,9 @@ def decode(self, v):
def encode(self):
if not test_set_sf(self.parent, self.expr.size):
return False
if not self.expr.size in self.gpregs_info:
if self.expr.size not in self.gpregs_info:
return False
if not self.expr in self.gpregs_info[self.expr.size].expr:
if self.expr not in self.gpregs_info[self.expr.size].expr:
return False
self.value = self.gpregs_info[self.expr.size].expr.index(self.expr)
return True
Expand All @@ -629,9 +629,9 @@ def decode(self, v):
def encode(self):
if not test_set_sf(self.parent, self.expr.size):
return False
if not self.expr.size in self.gpregs_info:
if self.expr.size not in self.gpregs_info:
return False
if not self.expr in self.gpregs_info[self.expr.size].expr:
if self.expr not in self.gpregs_info[self.expr.size].expr:
return False
if self.expr not in self.gpregs_info[self.expr.size].expr:
return False
Expand All @@ -651,9 +651,9 @@ def decode(self, v):
return True

def encode(self):
if not self.expr.size in self.simd_size:
if self.expr.size not in self.simd_size:
return False
if not self.expr in simds_info[self.expr.size].expr:
if self.expr not in simds_info[self.expr.size].expr:
return False
self.value = simds_info[self.expr.size].expr.index(self.expr)
self.parent.size.value = self.simd_size.index(self.expr.size)
Expand Down Expand Up @@ -700,7 +700,7 @@ def decode(self, v):
return True

def encode(self):
if not self.expr in gpregs_info[self.expr.size].expr:
if self.expr not in gpregs_info[self.expr.size].expr:
return False
self.value = gpregs_info[self.expr.size].expr.index(self.expr)
self.parent.sf.value = 1 if self.expr.size == 32 else 0
Expand Down Expand Up @@ -746,11 +746,11 @@ def encode(self):
self.value = 0x1F
return True
return False
if not self.expr.size in self.gpregs_info:
if self.expr.size not in self.gpregs_info:
return False
if not test_set_sf(self.parent, self.expr.size):
return False
if not self.expr in self.gpregs_info[self.expr.size].expr:
if self.expr not in self.gpregs_info[self.expr.size].expr:
return False
self.value = self.gpregs_info[self.expr.size].expr.index(self.expr)
return True
Expand Down Expand Up @@ -977,7 +977,7 @@ def encode(self):
return False
reg, amount = self.expr.args

if not reg in gpregsz_info[self.expr.size].expr:
if reg not in gpregsz_info[self.expr.size].expr:
return False
self.value = gpregsz_info[self.expr.size].expr.index(reg)
option = extend_lst.index(self.expr.op)
Expand Down Expand Up @@ -1029,7 +1029,7 @@ def encode(self):
return True
if not (isinstance(self.expr, m2_expr.ExprOp) and self.expr.op == 'segm'):
return False
if not arg0 in self.parent.rn.reg_info.expr:
if arg0 not in self.parent.rn.reg_info.expr:
return False
self.parent.rn.value = self.parent.rn.reg_info.expr.index(arg0)
is_reg = False
Expand Down Expand Up @@ -1096,7 +1096,7 @@ def get_size(self):
def test_set_sf(parent, size):
if not hasattr(parent, 'sf'):
return False
if parent.sf.value == None:
if parent.sf.value is None:
parent.sf.value = 1 if size == 64 else 0
return True
psize = 64 if parent.sf.value else 32
Expand All @@ -1112,9 +1112,9 @@ def encode(self):
if not test_set_sf(self.parent, size):
return False
if isinstance(self.expr, m2_expr.ExprId):
if not size in gpregs_info:
if size not in gpregs_info:
return False
if not self.expr in self.reg_info[size].expr:
if self.expr not in self.reg_info[size].expr:
return False
self.parent.shift.value = 0
self.parent.imm.value = 0
Expand All @@ -1123,10 +1123,10 @@ def encode(self):

if not isinstance(self.expr, m2_expr.ExprOp):
return False
if not self.expr.op in shift_expr:
if self.expr.op not in shift_expr:
return False
args = self.expr.args
if not args[0] in self.reg_info[size].expr:
if args[0] not in self.reg_info[size].expr:
return False
if not isinstance(args[1], m2_expr.ExprInt):
return False
Expand Down Expand Up @@ -1491,7 +1491,7 @@ def encode(self):
return False
if set_imm_to_size(self.parent.args[0].expr.size, self.expr.args[1]) is None:
return False
arg, amount = [int(arg) for arg in self.expr.args]
arg, amount = (int(arg) for arg in self.expr.args)
if arg > 0xFFFF:
return False
if amount % 16 or amount // 16 > 4:
Expand Down Expand Up @@ -1607,7 +1607,7 @@ def encode(self):
expr = self.expr
if not isinstance(expr, m2_expr.ExprOp):
return False
if not expr.op in ['postinc', 'preinc_wb', 'preinc']:
if expr.op not in ['postinc', 'preinc_wb', 'preinc']:
return False
if hasattr(self.parent, "postpre"):
if expr.op == 'postinc':
Expand All @@ -1617,7 +1617,7 @@ def encode(self):
if len(expr.args) != 2:
return False
reg, off = expr.args
if not reg in gpregs64_info.expr:
if reg not in gpregs64_info.expr:
return False
if not isinstance(off, m2_expr.ExprInt):
return False
Expand Down Expand Up @@ -1672,7 +1672,7 @@ def encode(self):
else:
return False

if not reg in gpregs64_info.expr:
if reg not in gpregs64_info.expr:
return False
self.value = gpregs64_info.expr.index(reg)
return True
Expand All @@ -1687,7 +1687,7 @@ def decode_w_size(self, off):

def encode_w_size(self, off):
size = self.parent.args[0].expr.size
if not size in self.size2scale:
if size not in self.size2scale:
return False
scale = self.size2scale[size]
off = int(mod_size2int[size](off) >> scale)
Expand Down
2 changes: 1 addition & 1 deletion miasm/arch/aarch64/sem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ def smull(arg1, arg2, arg3):


def get_mnemo_expr(ir, instr, *args):
if not instr.name.lower() in mnemo_func:
if instr.name.lower() not in mnemo_func:
raise NotImplementedError('unknown mnemo %s' % instr)
instr, extra_ir = mnemo_func[instr.name.lower()](ir, instr, *args)
return instr, extra_ir
Expand Down
10 changes: 5 additions & 5 deletions miasm/arch/arm/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ def encode(self):
len(ptr.args) == 2 and
ptr.op == 'preinc'):
reg, imm = ptr.args
if not reg in gpregs.expr:
if reg not in gpregs.expr:
return False
self.value = gpregs.expr.index(reg)
if not isinstance(imm, ExprInt):
Expand Down Expand Up @@ -1772,7 +1772,7 @@ def decode(self, v):
return True

def encode(self):
if not self.expr in self.reg_info.dct_expr_inv:
if self.expr not in self.reg_info.dct_expr_inv:
log.debug("cannot encode reg %r", self.expr)
return False
self.value = self.reg_info.dct_expr_inv[self.expr]
Expand Down Expand Up @@ -1871,7 +1871,7 @@ def encode(self):
if not isinstance(value, ExprInt):
return False
value = int(value)
if not value in [8, 16, 24]:
if value not in [8, 16, 24]:
return False
self.parent.rot2.value = value // 8
return True
Expand Down Expand Up @@ -2399,7 +2399,7 @@ class armt_reg_wb(arm_reg_wb):
def decode(self, v):
v = v & self.lmask
e = self.reg_info.expr[v]
if not e in self.parent.trlist.expr.args:
if e not in self.parent.trlist.expr.args:
e = ExprOp('wback', e)
self.expr = e
return True
Expand Down Expand Up @@ -3003,7 +3003,7 @@ def encode(self):
return True

aif_str = ["X", "F", "I", "IF", "A", "AF", "AI", "AIF"]
aif_expr = [ExprId(x, 32) if x != None else None for x in aif_str]
aif_expr = [ExprId(x, 32) if x is not None else None for x in aif_str]

aif_reg = reg_info(aif_str, aif_expr)

Expand Down
4 changes: 2 additions & 2 deletions miasm/arch/arm/disasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def cb_arm_fix_call(mdis, cur_block, offsets_to_dis):
return

values = viewvalues(mdis.arch.pc)
if not l1.args[0] in values:
if l1.args[0] not in values:
return
if not l2.args[1] in values:
if l2.args[1] not in values:
return
loc_key_cst = mdis.loc_db.get_or_create_offset_location(l1.offset + 4)
cur_block.add_cst(loc_key_cst, AsmConstraint.c_next)
Expand Down
4 changes: 2 additions & 2 deletions miasm/arch/arm/sem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ def is_pc_written(ir, instr_ir):
def add_condition_expr(ir, instr, cond, instr_ir, extra_ir):
if cond == COND_AL:
return instr_ir, extra_ir
if not cond in tab_cond:
if cond not in tab_cond:
raise ValueError('unknown condition %r' % cond)
cond = tab_cond[cond]

Expand Down Expand Up @@ -2050,7 +2050,7 @@ def split_expr_dst(ir, instr_ir):


def get_mnemo_expr(ir, instr, *args):
if not instr.name.lower() in mnemo_func_cond:
if instr.name.lower() not in mnemo_func_cond:
raise ValueError('unknown mnemo %s' % instr)
cond, mf = mnemo_func_cond[instr.name.lower()]
instr_ir, extra_ir = mf(ir, instr, *args)
Expand Down
2 changes: 1 addition & 1 deletion miasm/arch/mips32/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def decode(self, v):
return True
def encode(self):
e = self.expr
if not e in regs.regs_cpr0_expr:
if e not in regs.regs_cpr0_expr:
return False
index = regs.regs_cpr0_expr.index(e)
self.value = index & 7
Expand Down
2 changes: 1 addition & 1 deletion miasm/arch/ppc/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def ppc_bo_bi_to_mnemo(bo, bi, prefer_taken=True, default_taken=True):
bi2cond = { 0b00: 'LT', 0b01: 'GT', 0b10: 'EQ', 0b11: 'SO' }
bi2ncond = { 0b00: 'GE', 0b01: 'LE', 0b10: 'NE', 0b11: 'NS' }
n = bo & 0b11110
if not n in bo2mnemo:
if n not in bo2mnemo:
raise NotImplementedError("Unknown BO field")
mnem = 'B' + bo2mnemo[n]
if mnem[-1] == 'T':
Expand Down
2 changes: 1 addition & 1 deletion miasm/arch/ppc/sem.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def mn_compute_flags(rvalue, overflow_expr=None):
ExprInt(0, 1)) & ~rvalue.msb())))
ret.append(ExprAssign(CR0_EQ, ExprCond(rvalue, ExprInt(0, 1),
ExprInt(1, 1))))
if overflow_expr != None:
if overflow_expr is not None:
ret.append(ExprAssign(CR0_SO, XER_SO | overflow_expr))
else:
ret.append(ExprAssign(CR0_SO, XER_SO))
Expand Down
6 changes: 3 additions & 3 deletions miasm/arch/sh4/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def encode(self):
if not res:
return False
r = res[jra]
if not r in gpregs.expr:
if r not in gpregs.expr:
return False
v = gpregs.expr.index(r)
self.value = v
Expand Down Expand Up @@ -262,7 +262,7 @@ def encode(self):
return False
d = int(res[jrb])
p.disp.value = d // (s // 8)
if not res[jra] in gpregs.expr:
if res[jra] not in gpregs.expr:
return False
v = gpregs.expr.index(res[jra])
else:
Expand Down Expand Up @@ -580,7 +580,7 @@ def encode(self):
if not res:
return False
r = res[jra]
if not r in gpregs.expr:
if r not in gpregs.expr:
return False
self.value = gpregs.expr.index(r)
return True
Expand Down
Loading
Loading