Last active
September 3, 2023 04:00
-
-
Save Dobby233Liu/3e962fdf4a7be6aab8420120af7dfb72 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
from lib import enc_key, map_out, decrypt | |
in_file = len(sys.argv) > 1 and sys.argv[1] | |
while not in_file or not os.path.exists(in_file): | |
in_file = input("in: ") | |
in_file = os.path.relpath(in_file) | |
out_file, des_magic = map_out(in_file) | |
out_file = os.path.join(os.path.dirname(in_file), out_file) | |
print(f"out: {out_file}{os.path.exists(out_file) and ' (exists)' or ''}") | |
input() | |
decrypt(in_file, out_file, enc_key, des_magic) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os | |
from lib import enc_key, map_out, decrypt | |
os.makedirs("out", exist_ok=True) | |
for in_file in glob.glob("../*.rpgmvo"): | |
out_file, des_magic = map_out(in_file) | |
out_file = os.path.join("out/", out_file) | |
print(in_file, "->", out_file) | |
decrypt(in_file, out_file, enc_key, des_magic) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
ext_map = { | |
".rpgmvp": ".png", | |
".rpgmvo": ".ogg" | |
} | |
ext_magic = { | |
".png": [b"\x89PNG"], | |
".ogg": [b"OggS", b"ID3\x03", b"RIFF"] | |
} | |
with open("encryptionKey","rb") as enc_key_f: | |
enc_key = bytearray(enc_key_f.read(16)) | |
def map_out(in_file): | |
in_file = os.path.basename(in_file) | |
out_ext = ext_map.get(os.path.splitext(in_file)[1].lower(), ".dec") | |
return os.path.splitext(in_file)[0] + out_ext, ext_magic.get(out_ext, None) | |
def decrypt(in_file, out_file, enc_key, des_magic): | |
with open(in_file, "rb") as in_file_f, open(out_file, "wb") as out_file_f: | |
if in_file_f.read(6) != b"RPGMV\x00": | |
raise Exception("not RPG Maker MV-encrypted") | |
in_file_f.read(10) | |
hit_magic = -1 | |
for encb, keyb, counter in zip(in_file_f.read(16), enc_key, range(16)): | |
decb = encb ^ keyb | |
out_file_f.write(bytes([decb])) | |
if counter < 4 and des_magic and hit_magic >= -1: | |
if hit_magic < 0: | |
for magic, i in zip(des_magic, range(len(des_magic))): | |
if magic[counter] == decb: | |
hit_magic = i | |
elif des_magic[hit_magic][counter] != decb: | |
hit_magic = -2 | |
out_file_f.write(in_file_f.read()) | |
if hit_magic < 0: | |
print("WARNING: file doesn't line up with any known magic") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment