Skip to content

Commit 1a77735

Browse files
committed
ruff format / lint
1 parent c64e2a4 commit 1a77735

File tree

11 files changed

+33
-19
lines changed

11 files changed

+33
-19
lines changed

src/patcherex2/components/assemblers/assembler.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class Assembler:
77
def __init__(self, p):
88
self.p = p
99

10-
def resolve_symbols(self, code, symbols={}):
10+
def resolve_symbols(self, code, symbols=None):
11+
if symbols is None:
12+
symbols = {}
1113
_symbols = {}
1214
_symbols.update(self.p.symbols)
1315
_symbols.update(self.p.binary_analyzer.get_all_symbols())
@@ -23,7 +25,9 @@ def _assemble(self, code, base=0, **kwargs):
2325
def _pre_assemble_hook(self, code, base=0):
2426
return code
2527

26-
def assemble(self, code, base=0, symbols={}, **kwargs):
28+
def assemble(self, code, base=0, symbols=None, **kwargs):
29+
if symbols is None:
30+
symbols = {}
2731
logger.debug(f"Assembling `{code}` at {hex(base)}")
2832
code = self.resolve_symbols(code, symbols=symbols)
2933
code = self._pre_assemble_hook(code, base=base)

src/patcherex2/components/binary_analyzers/angr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def get_unused_funcs(self):
9090
for func in self.p.kb.functions.values():
9191
if func.size == 0:
9292
continue
93-
for dst, xrefs in self.p.kb.xrefs.xrefs_by_dst.items():
93+
for dst, _ in self.p.kb.xrefs.xrefs_by_dst.items():
9494
if dst == func.addr:
9595
break
9696
else:
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
class BinaryAnalyzer(object):
1+
class BinaryAnalyzer:
22
pass

src/patcherex2/components/compilers/clang.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77

88
class Clang(Compiler):
9-
def __init__(self, p, clang_version=15, compiler_flags=[]):
9+
def __init__(self, p, clang_version=15, compiler_flags=None):
1010
super().__init__(p)
11+
if compiler_flags is None:
12+
compiler_flags = []
1113
self._compiler = f"clang-{clang_version}"
1214
self._linker = f"ld.lld-{clang_version}"
1315
self._compiler_flags = compiler_flags

src/patcherex2/components/compilers/clang_arm.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77

88
class ClangArm(Compiler):
9-
def __init__(self, p, clang_version=15, compiler_flags=[]):
9+
def __init__(self, p, clang_version=15, compiler_flags=None):
1010
super().__init__(p)
11+
if compiler_flags is None:
12+
compiler_flags = []
1113
self._compiler = f"clang-{clang_version}"
1214
self._linker = f"ld.lld-{clang_version}"
1315
self._compiler_flags = compiler_flags
@@ -16,11 +18,15 @@ def compile(
1618
self,
1719
code,
1820
base=0,
19-
symbols={},
20-
extra_compiler_flags=[],
21+
symbols=None,
22+
extra_compiler_flags=None,
2123
is_thumb=False,
2224
**kwargs,
2325
):
26+
if symbols is None:
27+
symbols = {}
28+
if extra_compiler_flags is None:
29+
extra_compiler_flags = []
2430
if is_thumb:
2531
extra_compiler_flags += ["-mthumb"]
2632
else:

src/patcherex2/components/compilers/compiler.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class Compiler:
1212
def __init__(self, p):
1313
self.p = p
1414

15-
def compile(self, code, base=0, symbols={}, extra_compiler_flags=[], **kwargs):
15+
def compile(self, code, base=0, symbols=None, extra_compiler_flags=None, **kwargs):
16+
if symbols is None:
17+
symbols = {}
18+
if extra_compiler_flags is None:
19+
extra_compiler_flags = []
1620
with tempfile.TemporaryDirectory() as td:
1721
# source file
1822
with open(os.path.join(td, "code.c"), "w") as f:

src/patcherex2/patcherex.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88

99
class Patcherex:
10-
def __init__(self, binary_path, target_cls=None, target_opts={}):
10+
def __init__(self, binary_path, target_cls=None, target_opts=None):
11+
if target_opts is None:
12+
target_opts = {}
1113
self.binary_path = binary_path
1214
if target_cls is None:
1315
self.target = Target.detect_target(self, binary_path)

src/patcherex2/targets/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
from .elf_arm_linux import ElfArmLinux
33
from .elf_arm_mimxrt1052 import ElfArmMimxrt1052
44
from .elf_leon3_bare import ElfLeon3Bare
5-
from .ihex_ppc_bare import IHex_PPC_Bare
5+
from .ihex_ppc_bare import IHexPPCBare
66
from .target import Target
77

88
__all__ = [
99
"ElfAArch64Linux",
1010
"ElfArmLinux",
1111
"ElfArmMimxrt1052",
1212
"ElfLeon3Bare",
13-
"IHex_PPC_Bare",
13+
"IHexPPCBare",
1414
"Target",
1515
]

src/patcherex2/targets/ihex_ppc_bare.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
logger = logging.getLogger(__name__)
1515

1616

17-
class IHex_PPC_Bare(Target):
17+
class IHexPPCBare(Target):
1818
NOP_BYTES = b"\x01\x00\x00\x00"
1919
NOP_SIZE = 4
2020
JMP_ASM = "b {dst}"

tests/test_aarch64.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ def test_insert_data_patch(self, tlen=5):
103103
ldr x1, ={added_data}
104104
mov x2, %s
105105
svc 0
106-
""" % hex(
107-
tlen
108-
)
106+
""" % hex(tlen)
109107
p2 = InsertInstructionPatch(0x400580, instrs)
110108
self.run_one(
111109
"printf_nopie",

tests/test_arm.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ def test_insert_data_patch(self, tlen=5):
107107
ldr r1, ={added_data}
108108
mov r2, %s
109109
svc 0
110-
""" % hex(
111-
tlen
112-
)
110+
""" % hex(tlen)
113111
p2 = InsertInstructionPatch(0x103EC, instrs)
114112
self.run_one(
115113
"printf_nopie",

0 commit comments

Comments
 (0)