CSV formatting improvements

This commit is contained in:
AlexApps99 2021-07-27 11:09:28 +12:00
parent 42807160cf
commit 3c336794a4
No known key found for this signature in database
GPG Key ID: 7CDEAB71F74AA68D
3 changed files with 112778 additions and 112782 deletions

File diff suppressed because it is too large Load Diff

View File

@ -7,18 +7,12 @@ import os
csv_path = os.path.join(os.path.dirname(__file__), "../data/uking_functions.csv") csv_path = os.path.join(os.path.dirname(__file__), "../data/uking_functions.csv")
MARKERS = ("|", "?", "!")
with open(csv_path, "r") as f: with open(csv_path, "r") as f:
reader = csv.reader(f) reader = csv.reader(f)
# Skip headers
next(reader)
for fn in reader: for fn in reader:
addr = int(fn[0], 16) addr = int(fn[0], 16)
decomp_name = fn[3] name = fn[3]
if not decomp_name or decomp_name == "l": if name and fn[1] != "L":
continue idc.set_name(addr, name)
# Get rid of status markers.
if decomp_name[-1] in MARKERS:
decomp_name = decomp_name[:-1]
idc.set_name(addr, decomp_name)

View File

@ -28,32 +28,31 @@ class FunctionInfo(tp.NamedTuple):
name: str name: str
size: int size: int
decomp_name: str decomp_name: str
library: bool
status: FunctionStatus status: FunctionStatus
raw_row: tp.List[str] raw_row: tp.List[str]
_markers = { _markers = {
"?": FunctionStatus.Equivalent, "O": FunctionStatus.Matching,
"!": FunctionStatus.NonMatching, "m": FunctionStatus.Equivalent,
"|": FunctionStatus.Wip, "M": FunctionStatus.NonMatching,
"W": FunctionStatus.Wip,
"U": FunctionStatus.NotDecompiled,
"L": FunctionStatus.NotDecompiled,
} }
def parse_function_csv_entry(row) -> FunctionInfo: def parse_function_csv_entry(row) -> FunctionInfo:
ea, name, size, decomp_name = row ea, stat, size, name = row
if decomp_name: status = _markers.get(stat, FunctionStatus.NotDecompiled)
status = FunctionStatus.Matching decomp_name = ""
for marker, new_status in _markers.items(): if status != FunctionStatus.NotDecompiled:
if decomp_name[-1] == marker: decomp_name = name
status = new_status
decomp_name = decomp_name[:-1]
break
else:
status = FunctionStatus.NotDecompiled
addr = int(ea, 16) - 0x7100000000 addr = int(ea, 16) - 0x7100000000
return FunctionInfo(addr, name, int(size, 0), decomp_name, status, row) return FunctionInfo(addr, name, int(size), decomp_name, stat == "L", status, row)
def get_functions_csv_path() -> Path: def get_functions_csv_path() -> Path:
@ -65,11 +64,13 @@ def get_functions(path: tp.Optional[Path] = None) -> tp.Iterable[FunctionInfo]:
path = get_functions_csv_path() path = get_functions_csv_path()
with path.open() as f: with path.open() as f:
reader = csv.reader(f) reader = csv.reader(f)
# Skip headers
next(reader)
for row in reader: for row in reader:
try: try:
entry = parse_function_csv_entry(row) entry = parse_function_csv_entry(row)
# excluded library function # excluded library function
if entry.decomp_name == "l": if entry.library:
continue continue
yield entry yield entry
except ValueError as e: except ValueError as e:
@ -82,7 +83,7 @@ def add_decompiled_functions(new_matches: tp.Dict[int, str],
writer = csv.writer(buffer, lineterminator="\n") writer = csv.writer(buffer, lineterminator="\n")
for func in get_functions(): for func in get_functions():
if new_orig_names is not None and func.status == FunctionStatus.NotDecompiled and func.addr in new_orig_names: if new_orig_names is not None and func.status == FunctionStatus.NotDecompiled and func.addr in new_orig_names:
func.raw_row[1] = new_orig_names[func.addr] func.raw_row[3] = new_orig_names[func.addr]
if func.status == FunctionStatus.NotDecompiled and func.addr in new_matches: if func.status == FunctionStatus.NotDecompiled and func.addr in new_matches:
func.raw_row[3] = new_matches[func.addr] func.raw_row[3] = new_matches[func.addr]
writer.writerow(func.raw_row) writer.writerow(func.raw_row)