Skip to content

Commit

Permalink
black format
Browse files Browse the repository at this point in the history
  • Loading branch information
riptl authored and Richard Patel committed Apr 3, 2022
1 parent f99f61e commit 68c10b7
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
10 changes: 4 additions & 6 deletions mkwutil/gen_asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def emit_symbol(self, address):
if address not in self.symbols: # probably slow
return
name = self.symbols[address].name
print(f".global \"{name}\"\n\"{name}\":", file=self.output)
print(f'.global "{name}"\n"{name}":', file=self.output)

def dump_bss(self):
"""Writes a bss segment."""
Expand Down Expand Up @@ -88,11 +88,11 @@ def iter_data_chunks(
cut = 4 - offset
if len(part) > cut:
cut = len(part)
yield part.start, self.data[offset : offset+cut]
yield part.start, self.data[offset : offset + cut]
offset += cut
# Use memoryview to scan over data efficiently.
view = memoryview(self.data)
view = view[offset:part.stop - self.slice.start]
view = view[offset : part.stop - self.slice.start]
while len(view) > 0:
left, view = view[:chunk_size], view[chunk_size:]
yield self.slice.start + offset, bytes(left)
Expand All @@ -101,9 +101,7 @@ def iter_data_chunks(
def dump_text(self):
"""Writes a disassembled text segment."""
for part in self.slice.split(self.symbol_locs):
assert (
part.start % 4 == 0
), f"misaligned text"
assert part.start % 4 == 0, f"misaligned text"
self.emit_symbol(part.start)
for ins in disasm_iter(self.get_data_chunk(part), part.start):
print(ins.disassemble(), file=self.output)
Expand Down
1 change: 1 addition & 0 deletions mkwutil/lib/binary_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
rb"BINARY_BLOB: (.+)\t(0x[0-9a-f]{8})\t(0x[0-9a-f]{8})\n"
)


def __load_binary_blob_slices(elf_file) -> Generator[Slice, None, None]:
elf = ELFFile(elf_file)
blobs: ELFSection = elf.get_section_by_name("binary_blobs")
Expand Down
1 change: 1 addition & 0 deletions mkwutil/lib/verify_binary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hashlib


def check_hash(content, expected):
ctx = hashlib.sha1(content)
digest = ctx.hexdigest()
Expand Down
6 changes: 5 additions & 1 deletion mkwutil/pack_main_dol.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def segment_is_text(seg):

def segment_is_data(seg):
"""Returns whether segment is data."""
return not segment_is_dummy(seg) and not segment_is_text(seg) and not segment_is_bss(seg)
return (
not segment_is_dummy(seg)
and not segment_is_text(seg)
and not segment_is_bss(seg)
)


def segment_is_bss(seg):
Expand Down
4 changes: 2 additions & 2 deletions mkwutil/pack_staticr_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ def pack_staticr_rel(elf_path, rel_path, orig_dir):
instruction_addr = text_start + reloc.r_offset

sym_tab = elf.get_section(relocs.header.sh_link)
r_symbol = reloc.r_info_sym # reloc.r_info >> 8
r_symbol = reloc.r_info_sym # reloc.r_info >> 8
symbol = sym_tab.get_symbol(r_symbol)

st_value = symbol['st_value']
st_value = symbol["st_value"]

if symbol.name in SYMS:
st_value = SYMS[symbol.name] - text_start
Expand Down
7 changes: 7 additions & 0 deletions mkwutil/progress/graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,42 @@ def percent_decomp_stats(slices: SliceTable) -> None:

print("Code&Data Percent: %s" % (100 * n_code / total))


def dol_boxes():
slices = project.load_dol_slices(sections=DOL_SECTIONS)
return map(Box.from_slice, slices)


def rel_boxes():
slices = project.load_rel_slices(sections=REL_SECTIONS)
return map(Box.from_slice, slices)


def section_to_slice(s):
return Slice(name=s.name, start=s.start, stop=s.stop, section=s.type)


def dol_section_boxes():
slices = SliceTable(sections=DOL_SECTIONS)
for s in DOL_SECTIONS:
slices.add(section_to_slice(s))
return map(Box.from_slice, slices)


def rel_section_boxes():
slices = SliceTable(sections=REL_SECTIONS)
for s in REL_SECTIONS:
slices.add(section_to_slice(s))
return map(Box.from_slice, slices)


def dol_lib_boxes():
slices = SliceTable(sections=DOL_SECTIONS)
for _slice in DOL_LIBS:
slices.add(_slice)
return map(Box.from_slice, slices)


def rel_dir_boxes():
slices = SliceTable(sections=REL_DIRS)
for _slice in REL_DIRS:
Expand Down
4 changes: 3 additions & 1 deletion mkwutil/progress/percent_decompiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def build_stats(dir: Path) -> Stats:
)
# REL directories.
for dir in REL_DIRS:
assert dir.section == "text", "For now only text section per directory supported"
assert (
dir.section == "text"
), "For now only text section per directory supported"
dir_split_slices = rel_split_slices.slice(dir.start, dir.stop)
dir_decomp_slices = rel_decomp_slices.slice(dir.start, dir.stop)
dir_split_code, _ = simple_count(dir_split_slices)
Expand Down
2 changes: 1 addition & 1 deletion mkwutil/tools/verify_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def diff_symbols(elf_sym: Symbol, orig_sym: Optional[Symbol]) -> bool:
print("[-] 0x%08x %s" % (elf_sym.addr, elf_sym.name))
return False
if elf_sym.name in ("__save_gpr", "__rest_gpr"):
return True # ignore
return True # ignore
if elf_sym.name != orig_sym.name:
print("[!] 0x%08x %s != %s" % (elf_sym.addr, elf_sym.name, orig_sym.name))
return False
Expand Down

0 comments on commit 68c10b7

Please sign in to comment.