Skip to content

Commit

Permalink
Merge pull request #2 from GZH2K19:main
Browse files Browse the repository at this point in the history
Regular
  • Loading branch information
GZH2K19 authored Oct 3, 2024
2 parents d51c8ff + 9ee564a commit bc4fcdf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
82 changes: 46 additions & 36 deletions Decrypter3000.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,57 @@ def decrypt(data:bytes, tEncKey:list[int]):
return


def process_game(game_path:str):
game = Path(game_path)
print("Processing:", game)

json_system = game/"data"/"System.json"
if not json_system.exists():
print("Error: System.json not found.\n")
return
with open(json_system, "r", encoding="utf-8-sig") as f:
data = json.load(f)
encKey = data.get("encryptionKey")
if not encKey:
print("Error: Encryption key not found.\n")
return
print("Encryption key:", encKey)
tEncKey = transEncKey(encKey)

folderList = []
if data.get("hasEncryptedImages"):
folderList.append("img")
if data.get("hasEncryptedAudio"):
folderList.append("audio")
if not folderList:
print("Error: Encrypted files not found.\n")
return

for folder in folderList:
print("Decrypting", folder, "files...")
ori = game/folder
new = game/(folder+"_decrypted")
for r in ori.rglob("*.*_"):
with open(r, "rb") as f:
byt = decrypt(f.read(), tEncKey)
if not byt:
print("Failed to decrypt:", r.relative_to(game))
continue
file = str(new/r.relative_to(ori))[:-1]
os.makedirs(os.path.dirname(file), exist_ok=True)
with open(file, "wb") as f:
f.write(byt)
print("Done.\n")


if __name__ == "__main__":
if not argv[1:]:
print("No arguments provided. Please drag the game folder onto this script.")
else:
try:
for game in argv[1:]:
game = Path(game)
print("Processing", game)
json_system = game/"data"/"System.json"
if not json_system.exists():
print("Error: System.json not found.\n")
continue
with open(json_system, "r", encoding="utf-8-sig") as f:
data = json.load(f)
encKey = data.get("encryptionKey")
if not encKey:
print("Error: Encryption key not found.\n")
continue
print("Encryption key:", encKey)
tEncKey = transEncKey(encKey)
folderList = [i for i in ["img", "audio"] if (game/i).exists()]
if not folderList:
print("Error: Encrypted files not found.\n")
continue

for folder in folderList:
print("Decrypting", folder, "files...")
ori = game/folder
new = game/(folder+"_decrypted")
for r in ori.rglob("*.*_"):
with open(r, "rb") as f:
byt = decrypt(f.read(), tEncKey)
if not byt:
print("Failed to decrypt:", r.relative_to(game))
continue
file = str(new/r.relative_to(ori))[:-1]
os.makedirs(os.path.dirname(file), exist_ok=True)
with open(file, "wb") as f:
f.write(byt)
print("Done.\n")
for game_path in argv[1:]:
process_game(game_path)
except:
from traceback import format_exc
print(format_exc())
input("Press ENTER to exit...")
os.system("pause")
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Instruction
Just drag the game folder onto this script. The decrypted resource folder will be created in the same directory as the source folder.
Just drag the game folder onto this script (on Windows). The decrypted resource folder will be created in the same directory as the source folder.

## Disclaimer
All code is for research and educational purposes only. Do not use for illegal activities. The author is also not responsible for any consequences arising from the use of this code.

0 comments on commit bc4fcdf

Please sign in to comment.