2021-02-11 00:26:17 +01:00
|
|
|
#!/usr/bin/python3
|
2021-02-11 17:45:16 +01:00
|
|
|
import re
|
2021-02-11 00:26:17 +01:00
|
|
|
import typing as T
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
MAX_X = 50
|
|
|
|
SQUARE_SIZE = 10
|
2021-02-11 17:45:16 +01:00
|
|
|
TEXT_SIZE = 15
|
2021-02-11 00:26:17 +01:00
|
|
|
SQUARE_MARGIN = 2
|
|
|
|
DOCS_DIR = Path(__file__).parent
|
|
|
|
PROGRESS_TXT_FILE = DOCS_DIR / "progress.txt"
|
|
|
|
PROGRESS_SVG_FILE = DOCS_DIR / "progress.svg"
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Function:
|
|
|
|
name: str
|
|
|
|
offset: int
|
|
|
|
size: int
|
|
|
|
flags: str
|
|
|
|
|
|
|
|
@property
|
|
|
|
def decompiled(self):
|
|
|
|
return "+" in self.flags
|
|
|
|
|
|
|
|
|
|
|
|
def collect_functions() -> T.Iterable[Function]:
|
|
|
|
for line in PROGRESS_TXT_FILE.open():
|
|
|
|
if line.startswith("#"):
|
|
|
|
continue
|
|
|
|
func_name, offset, size, flags = re.split(r"\s+", line.strip())
|
|
|
|
yield Function(
|
|
|
|
name=func_name,
|
|
|
|
offset=int(offset, 16),
|
|
|
|
size=int(size, 16),
|
|
|
|
flags=flags,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
functions = list(collect_functions())
|
|
|
|
|
|
|
|
svg_width = (
|
|
|
|
min(MAX_X, len(functions)) * (SQUARE_SIZE + SQUARE_MARGIN)
|
|
|
|
+ SQUARE_MARGIN
|
|
|
|
)
|
2021-02-11 17:45:16 +01:00
|
|
|
svg_height = (
|
|
|
|
((len(functions) + MAX_X - 1) // MAX_X) * (SQUARE_SIZE + SQUARE_MARGIN)
|
|
|
|
+ SQUARE_MARGIN * 2
|
|
|
|
+ TEXT_SIZE * 2
|
|
|
|
)
|
2021-02-11 00:26:17 +01:00
|
|
|
|
|
|
|
with PROGRESS_SVG_FILE.open("w") as handle:
|
|
|
|
print(
|
|
|
|
f'<svg version="1.1" '
|
|
|
|
f'width="{svg_width}" '
|
|
|
|
f'height="{svg_height}" '
|
|
|
|
f'xmlns="http://www.w3.org/2000/svg">',
|
|
|
|
file=handle,
|
|
|
|
)
|
|
|
|
|
|
|
|
for i, function in enumerate(functions):
|
|
|
|
x = (i % MAX_X) * (SQUARE_SIZE + SQUARE_MARGIN)
|
|
|
|
y = (i // MAX_X) * (SQUARE_SIZE + SQUARE_MARGIN)
|
|
|
|
color = "green" if function.decompiled else "pink"
|
|
|
|
print(
|
|
|
|
f"<rect "
|
|
|
|
f'width="{SQUARE_SIZE}" '
|
|
|
|
f'height="{SQUARE_SIZE}" '
|
|
|
|
f'x="{x}" '
|
|
|
|
f'y="{y}" '
|
|
|
|
f'fill="{color}"/>',
|
|
|
|
file=handle,
|
|
|
|
)
|
|
|
|
|
2021-02-11 17:45:16 +01:00
|
|
|
y += SQUARE_SIZE
|
|
|
|
y += TEXT_SIZE
|
|
|
|
ready_functions = sum(function.decompiled for function in functions)
|
|
|
|
total_functions = len(functions)
|
|
|
|
ready_size = sum(
|
|
|
|
function.size for function in functions if function.decompiled
|
|
|
|
)
|
|
|
|
total_size = sum(function.size for function in functions)
|
|
|
|
print(
|
|
|
|
f'<text x="0" y="{y}" '
|
|
|
|
f'style="font-family: sans-serif; font-size: {TEXT_SIZE}px">'
|
|
|
|
f'Functions decompiled (count): '
|
|
|
|
f'{ready_functions/total_functions:.02%}'
|
|
|
|
f'</text>',
|
|
|
|
file=handle,
|
|
|
|
)
|
|
|
|
y += TEXT_SIZE + SQUARE_MARGIN
|
|
|
|
print(
|
|
|
|
f'<text x="0" y="{y}" '
|
|
|
|
f'style="font-family: sans-serif; font-size: {TEXT_SIZE}px">'
|
|
|
|
f'Functions decompiled (bytesize): {ready_size/total_size:.02%}'
|
|
|
|
f'</text>',
|
|
|
|
file=handle,
|
|
|
|
)
|
|
|
|
|
2021-02-11 00:26:17 +01:00
|
|
|
print("</svg>", file=handle)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|