mirror of
https://github.com/Virtual-World-RE/NeoGF.git
synced 2024-11-15 12:45:34 +01:00
Update gcmtest.py
This commit is contained in:
parent
9a6b751b5a
commit
1c9a484bb4
91
gcmtest.py
91
gcmtest.py
|
@ -5,20 +5,22 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
__version__ = "0.0.1"
|
__version__ = "0.0.2"
|
||||||
__author__ = "rigodron, algoflash, GGLinnk"
|
__author__ = "rigodron, algoflash, GGLinnk"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__status__ = "developpement"
|
__status__ = "developpement"
|
||||||
|
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
# Set roms_path with your ROMs (at the root of the ROM folder)
|
# Set roms_path with your ROMs (at the root of the ROM folder)
|
||||||
# Extract all files from file system using dolphin emu - put it in dolphin_extracts/root/
|
# Extract all files from file system using dolphin emu - put it in gcm_dolphin/root/
|
||||||
# Extract boot.dol and apploader.img using dolphin emu - put it in dolphin_extracts/sys/
|
# Extract boot.dol and apploader.img using dolphin emu - put it in gcm_dolphin/sys/
|
||||||
##################################################
|
##################################################
|
||||||
roms_path = Path("../ROM")
|
roms_path = Path("../ROM")
|
||||||
unpack_path = Path("tests/unpack")
|
dolphin_unpack_path = Path("dolphin_unpack")
|
||||||
repack_iso_path = Path("tests/repack_iso")
|
unpack_path = Path("unpack")
|
||||||
unpack2_path = Path("tests/unpack2")
|
repack_path = Path("repack")
|
||||||
dolphin_path = Path("tests/dolphin_extracts")
|
unpack2_path = Path("unpack2")
|
||||||
# if there is a way to create symlinks on GCM filesystem, it could create strange situations
|
# if there is a way to create symlinks on GCM filesystem, it could create strange situations
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,10 +42,7 @@ def print_paths_differences(folder1_paths:list, folder2_paths:list):
|
||||||
|
|
||||||
# compare two files sha256
|
# compare two files sha256
|
||||||
def compare_sha256(file1_path:Path, file2_path:Path):
|
def compare_sha256(file1_path:Path, file2_path:Path):
|
||||||
with file1_path.open("rb") as f1, file2_path.open("rb") as f2:
|
return hashlib.sha256( file1_path.read_bytes() ).hexdigest() == hashlib.sha256( file2_path.read_bytes() ).hexdigest()
|
||||||
if hashlib.sha256( f1.read() ).hexdigest() != hashlib.sha256( f2.read() ).hexdigest() :
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
# compare two GCM
|
# compare two GCM
|
||||||
|
@ -57,90 +56,90 @@ def verify_GCM_sha256(folder1: Path, folder2: Path):
|
||||||
folder2_paths = [Path(*path.parts[len2:]) for path in (folder2/"root").glob('**/*')]
|
folder2_paths = [Path(*path.parts[len2:]) for path in (folder2/"root").glob('**/*')]
|
||||||
if folder1_paths != folder2_paths:
|
if folder1_paths != folder2_paths:
|
||||||
print_paths_differences(folder1_paths, folder2_paths)
|
print_paths_differences(folder1_paths, folder2_paths)
|
||||||
raise Exception(f"Folders \"{folder1}\" and \"{folder2}\" are differents (not the sames folders or files names).")
|
raise Exception(f"Folders \"{folder1}\" and \"{folder2}\" are different (not the same folders or files names).")
|
||||||
# 2. Compare sys files content
|
# 2. Compare sys files content
|
||||||
if not compare_sha256(folder1/"sys"/"apploader.img", folder2/"sys"/"apploader.img"):
|
if not compare_sha256(folder1/"sys"/"apploader.img", folder2/"sys"/"apploader.img"):
|
||||||
raise Exception(f"\"{folder1}/sys/apploader.bin\" and \"{folder2}/sys/apploader.bin\" are differents.")
|
raise Exception(f"\"{folder1}/sys/apploader.bin\" and \"{folder2}/sys/apploader.bin\" are different.")
|
||||||
if not compare_sha256(folder1/"sys"/"boot.dol", folder2/"sys"/"boot.dol"):
|
if not compare_sha256(folder1/"sys"/"boot.dol", folder2/"sys"/"boot.dol"):
|
||||||
raise Exception(f"\"{folder1}/sys/boot.bin\" and \"{folder2}/sys/boot.bin\" are differents.")
|
raise Exception(f"\"{folder1}/sys/boot.bin\" and \"{folder2}/sys/boot.bin\" are different.")
|
||||||
|
|
||||||
for path1 in (folder1/"root").glob('**/*'):
|
for path1 in (folder1/"root").glob('**/*'):
|
||||||
if path1.is_file():
|
if path1.is_file():
|
||||||
path2 = folder2/Path(*path1.parts[len1:])
|
path2 = folder2/Path(*path1.parts[len1:])
|
||||||
if not compare_sha256(path1, path2):
|
if not compare_sha256(path1, path2):
|
||||||
raise Exception(f"\"{path1}/\" and \"{path2}\" are differents.")
|
raise Exception(f"\"{path1}/\" and \"{path2}\" are different.")
|
||||||
|
|
||||||
|
|
||||||
print("# Cleaning tests folder")
|
print("# Cleaning tests folder")
|
||||||
# Remove tests folders
|
# Remove tests folders
|
||||||
if unpack_path.is_dir():
|
if unpack_path.is_dir():
|
||||||
shutil.rmtree(unpack_path)
|
shutil.rmtree(unpack_path)
|
||||||
if repack_iso_path.is_dir():
|
if repack_path.is_dir():
|
||||||
shutil.rmtree(repack_iso_path)
|
shutil.rmtree(repack_path)
|
||||||
if unpack2_path.is_dir():
|
if unpack2_path.is_dir():
|
||||||
shutil.rmtree(unpack2_path)
|
shutil.rmtree(unpack2_path)
|
||||||
|
|
||||||
print("# Comparing unpacked ROMs with dolphin extracts")
|
print("# Comparing unpacked ROMs with dolphin extracts")
|
||||||
# unpack ROM in unpack
|
# unpack ROM in unpack_path
|
||||||
unpack_path.mkdir(parents=True)
|
unpack_path.mkdir(parents=True)
|
||||||
for iso_path in roms_path.glob("*"):
|
for iso_path in roms_path.glob("*"):
|
||||||
if iso_path.is_file():
|
if iso_path.is_file():
|
||||||
if os.system(f"python gcmtool.py -u \"{iso_path}\" \"{unpack_path}/{iso_path.name}\"") != 0:
|
if os.system(f"python gcmtool.py -u \"{iso_path}\" \"{unpack_path}/{iso_path.name}\"") != 0:
|
||||||
raise Exception("Error")
|
raise Exception("Error while unpacking original gcm.")
|
||||||
|
|
||||||
# compare unpack dolphin_extracts
|
# compare unpack_path dolphin_unpack_path
|
||||||
for folder_path in unpack_path.glob("*"):
|
for folder_path in unpack_path.glob("*"):
|
||||||
verify_GCM_sha256(folder_path, dolphin_path / folder_path.name)
|
verify_GCM_sha256(folder_path, dolphin_unpack_path / folder_path.name)
|
||||||
|
|
||||||
print("# Comparing iso->[1:unpacked]->repacked->[2:unpacked]")
|
print("# Comparing iso->[1:unpacked]->repacked->[2:unpacked]")
|
||||||
# repack unpack repack_iso
|
# repack unpack_path repack_path
|
||||||
repack_iso_path.mkdir()
|
repack_path.mkdir()
|
||||||
for folder_path in unpack_path.glob("*"):
|
for folder_path in unpack_path.glob("*"):
|
||||||
if os.system(f"python gcmtool.py -p \"{folder_path}\" \"{repack_iso_path}/{folder_path.name}\"") != 0:
|
if os.system(f"python gcmtool.py -p \"{folder_path}\" \"{repack_path}/{folder_path.name}\"") != 0:
|
||||||
raise Exception("Error")
|
raise Exception("Error while packing unpacked gcm.")
|
||||||
|
|
||||||
# unpack repack_iso unpack2
|
# unpack repack_path unpack2_path
|
||||||
unpack2_path.mkdir()
|
unpack2_path.mkdir()
|
||||||
for iso_path in repack_iso_path.glob("*"):
|
for iso_path in repack_path.glob("*"):
|
||||||
if os.system(f"python gcmtool.py -u \"{iso_path}\" \"{unpack2_path}/{iso_path.name}\"") != 0:
|
if os.system(f"python gcmtool.py -u \"{iso_path}\" \"{unpack2_path}/{iso_path.name}\"") != 0:
|
||||||
raise Exception("Error")
|
raise Exception("Error while unpacking repacked gcm.")
|
||||||
|
|
||||||
# remove repack_iso
|
# remove repack_path
|
||||||
shutil.rmtree(repack_iso_path)
|
shutil.rmtree(repack_path)
|
||||||
|
|
||||||
# compare unpack unpack2
|
# compare unpack_path unpack2_path
|
||||||
for folder_path in unpack_path.glob("*"):
|
for folder_path in unpack_path.glob("*"):
|
||||||
verify_GCM_sha256(folder_path, unpack2_path / folder_path.name)
|
verify_GCM_sha256(folder_path, unpack2_path / folder_path.name)
|
||||||
|
|
||||||
# remove unpack2
|
# remove unpack2_path
|
||||||
shutil.rmtree(unpack2_path)
|
shutil.rmtree(unpack2_path)
|
||||||
|
|
||||||
print("# Comparing iso->[1:unpacked]->rebuild_fst->repack->[2:unpacked]")
|
print("# Comparing iso->[1:unpacked]->rebuild_fst->repack->[2:unpacked]")
|
||||||
# rebuild unpack fst
|
# rebuild unpack_path FSTs
|
||||||
for folder_path in unpack_path.glob("*"):
|
for folder_path in unpack_path.glob("*"):
|
||||||
if os.system(f"python gcmtool.py -r \"{folder_path}\"") != 0:
|
if os.system(f"python gcmtool.py -r \"{folder_path}\"") != 0:
|
||||||
raise Exception("Error")
|
raise Exception("Error while rebuilding FST.")
|
||||||
|
|
||||||
# repack unpack repack_iso
|
# repack unpack_path repack_path
|
||||||
repack_iso_path.mkdir()
|
repack_path.mkdir()
|
||||||
for folder_path in unpack_path.glob("*"):
|
for folder_path in unpack_path.glob("*"):
|
||||||
if os.system(f"python gcmtool.py -p \"{folder_path}\" \"{repack_iso_path}/{folder_path.name}\"") != 0:
|
if os.system(f"python gcmtool.py -p \"{folder_path}\" \"{repack_path}/{folder_path.name}\"") != 0:
|
||||||
raise Exception("Error")
|
raise Exception("Error while packing gcm with new FST.")
|
||||||
|
|
||||||
# unpack repack_iso unpack2
|
# unpack repack_path unpack2_path
|
||||||
unpack2_path.mkdir()
|
unpack2_path.mkdir()
|
||||||
for iso_path in repack_iso_path.glob("*"):
|
for iso_path in repack_path.glob("*"):
|
||||||
if os.system(f"python gcmtool.py -u \"{iso_path}\" \"{unpack2_path}/{iso_path.name}\"") != 0:
|
if os.system(f"python gcmtool.py -u \"{iso_path}\" \"{unpack2_path}/{iso_path.name}\"") != 0:
|
||||||
raise Exception("Error")
|
raise Exception("Error while unpacking repacked gcm with new FST.")
|
||||||
|
|
||||||
# remove repack_iso
|
# remove repack_path
|
||||||
shutil.rmtree(repack_iso_path)
|
shutil.rmtree(repack_path)
|
||||||
|
|
||||||
# compare unpack unpack2
|
# compare unpack_path unpack2_path
|
||||||
for folder_path in unpack_path.glob("*"):
|
for folder_path in unpack_path.glob("*"):
|
||||||
verify_GCM_sha256(folder_path, unpack2_path / folder_path.name)
|
verify_GCM_sha256(folder_path, unpack2_path / folder_path.name)
|
||||||
|
|
||||||
# remove unpack unpack2
|
# remove unpack_path unpack2_path
|
||||||
|
print(f"# Removing {unpack_path} and {unpack2_path}.")
|
||||||
shutil.rmtree(unpack_path)
|
shutil.rmtree(unpack_path)
|
||||||
shutil.rmtree(unpack2_path)
|
shutil.rmtree(unpack2_path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user