Skip to content

Commit 0f7faff

Browse files
committed
chore: format code
Signed-off-by: VIFEX <vifextech@foxmail.com>
1 parent 1ce84b5 commit 0f7faff

5 files changed

Lines changed: 240 additions & 138 deletions

File tree

libsurgeon.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ def show_progress(
163163

164164
# Show current file
165165
if filename:
166-
print(f"{Colors.DIM} -> Completed: {Colors.NC}{Colors.GREEN}{filename}{Colors.NC}")
166+
print(
167+
f"{Colors.DIM} -> Completed: {Colors.NC}{Colors.GREEN}{filename}{Colors.NC}"
168+
)
167169
else:
168170
print(f"{Colors.DIM} -> Processing...{Colors.NC}")
169171

@@ -176,7 +178,9 @@ def show_progress_final(total: int, elapsed: int):
176178
bar = draw_progress_bar(total, total)
177179
print(f"\r\033[K\n\033[K\n", end="")
178180
print("\033[2A", end="")
179-
print(f"{Colors.GREEN}[{bar}]{Colors.NC} {Colors.BOLD}100%{Colors.NC} ({total}/{total}) | Total: {format_time(elapsed)}")
181+
print(
182+
f"{Colors.GREEN}[{bar}]{Colors.NC} {Colors.BOLD}100%{Colors.NC} ({total}/{total}) | Total: {format_time(elapsed)}"
183+
)
180184
print()
181185

182186

@@ -787,11 +791,17 @@ def process_elf_file(
787791
if current_func > 0:
788792
avg_time = elapsed / current_func
789793
eta = int((total_funcs - current_func) * avg_time)
790-
show_progress(current_func, total_funcs, elapsed, last_func_name, eta)
794+
show_progress(
795+
current_func, total_funcs, elapsed, last_func_name, eta
796+
)
791797
except:
792798
pass
793799
elif "ANALYZING" in line and not analysis_done:
794-
print(f"\r{Colors.DIM} Ghidra analyzing...{Colors.NC}", end="", flush=True)
800+
print(
801+
f"\r{Colors.DIM} Ghidra analyzing...{Colors.NC}",
802+
end="",
803+
flush=True,
804+
)
795805

796806
process.wait()
797807

@@ -837,7 +847,11 @@ def process_elf_file(
837847
result.duration = time.time() - start_time
838848

839849
if result.success:
840-
h_count = len(list(Path(include_dir).glob("*.h"))) if os.path.isdir(include_dir) else 0
850+
h_count = (
851+
len(list(Path(include_dir).glob("*.h")))
852+
if os.path.isdir(include_dir)
853+
else 0
854+
)
841855

842856
print()
843857
log_info(f"{Colors.GREEN}ELF Processing Complete{Colors.NC}")
@@ -862,7 +876,9 @@ def process_elf_file(
862876
print(f" - {name} ({lines} lines)")
863877

864878
if result.module_count > 10:
865-
print(f" {Colors.DIM}... and {result.module_count - 10} more modules{Colors.NC}")
879+
print(
880+
f" {Colors.DIM}... and {result.module_count - 10} more modules{Colors.NC}"
881+
)
866882
print()
867883

868884
# Generate README
@@ -896,15 +912,21 @@ def generate_elf_readme(name: str, output_dir: str, strategy: str, result: ElfRe
896912
f.write(f"## Module Grouping Strategy: {strategy}\n\n")
897913

898914
if strategy == "prefix":
899-
f.write("Functions are grouped by their naming prefix. This works best for libraries\n")
915+
f.write(
916+
"Functions are grouped by their naming prefix. This works best for libraries\n"
917+
)
900918
f.write("with consistent naming conventions like:\n")
901919
f.write("- xxBmp* (Bitmap functions) -> elf_name_xxBmp.cpp\n")
902920
f.write("- xxFnt* (Font functions) -> elf_name_xxFnt.cpp\n\n")
903921
elif strategy == "alpha":
904-
f.write("Functions are grouped alphabetically (A-Z). Useful for very large\n")
922+
f.write(
923+
"Functions are grouped alphabetically (A-Z). Useful for very large\n"
924+
)
905925
f.write("ELF files as a first-pass organization.\n\n")
906926
elif strategy == "camelcase":
907-
f.write("Functions are grouped by extracting CamelCase words from their names.\n")
927+
f.write(
928+
"Functions are grouped by extracting CamelCase words from their names.\n"
929+
)
908930
f.write("Good for object-oriented code.\n\n")
909931
elif strategy == "single":
910932
f.write("All functions are placed in a single output file.\n\n")

similarity_analyzer/__init__.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
# Similarity Analyzer Python Package
22

33
from .similarity_analyzer import (
4-
normalize_code,
4+
DEFAULT_PATTERNS,
5+
DEFAULT_VARIANTS,
6+
FileData,
7+
GroupAnalysis,
8+
SimilarityResult,
9+
analyze_group,
510
calc_similarity,
6-
load_file,
711
compare_pair,
8-
group_by_pattern,
9-
analyze_group,
1012
find_similar_pairs,
1113
format_time,
12-
FileData,
13-
SimilarityResult,
14-
GroupAnalysis,
15-
DEFAULT_VARIANTS,
16-
DEFAULT_PATTERNS,
14+
group_by_pattern,
15+
load_file,
16+
normalize_code,
1717
)
1818

1919
__version__ = "1.0.0"
2020
__all__ = [
21-
'normalize_code',
22-
'calc_similarity',
23-
'load_file',
24-
'compare_pair',
25-
'group_by_pattern',
26-
'analyze_group',
27-
'find_similar_pairs',
28-
'format_time',
29-
'FileData',
30-
'SimilarityResult',
31-
'GroupAnalysis',
32-
'DEFAULT_VARIANTS',
33-
'DEFAULT_PATTERNS',
21+
"normalize_code",
22+
"calc_similarity",
23+
"load_file",
24+
"compare_pair",
25+
"group_by_pattern",
26+
"analyze_group",
27+
"find_similar_pairs",
28+
"format_time",
29+
"FileData",
30+
"SimilarityResult",
31+
"GroupAnalysis",
32+
"DEFAULT_VARIANTS",
33+
"DEFAULT_PATTERNS",
3434
]

0 commit comments

Comments
 (0)