appo

rpgmvp, rpgmvo , rpgmvm , rpgmvw (decoder decrypter unpaker)

Dec 31st, 2016
37,703
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import glob
  4. import json
  5. import sys
  6. import shutil
  7. import os
  8.  
  9. #this might change, not sure, but probably not since 16 is a great number
  10. HEADER_LENGTH = 16
  11.  
  12. def decrypt_image(enc_png, key, path):
  13.     print("Decrypting %s" % enc_png)
  14.     dec_name = os.path.splitext(os.path.basename(enc_png))[0] + ".png"
  15.     dec_data = decrypt_generic(enc_png, key)
  16.     dec_file = open(os.path.join(path, "dump/img", dec_name), 'wb')
  17.     dec_file.write(dec_data)
  18.     dec_file.close()
  19.  
  20. def decrypt_audio(enc_ogg, key, path):
  21.     print("Decrypting %s" % enc_ogg)
  22.     dec_name = os.path.splitext(os.path.basename(enc_ogg))[0] + ".ogg"
  23.     dec_data = decrypt_generic(enc_ogg, key)
  24.     dec_file = open(os.path.join(path, "dump/audio", dec_name), 'wb')
  25.     dec_file.write(dec_data)
  26.     dec_file.close()
  27.  
  28. def decrypt_generic(file_name, key):
  29.     enc_data = bytearray(open(file_name, 'rb').read())
  30.     dec_data = enc_data[16:]
  31.     for i in range(0, HEADER_LENGTH):
  32.         dec_data[i] ^= key[i]
  33.     return dec_data
  34.  
  35. if __name__ == "__main__":
  36.     if len(sys.argv) == 1:
  37.         print("Please supply path to Game.exe(s) to unpack")
  38.         sys.exit(1)
  39.  
  40.     for i in range(1, len(sys.argv)):
  41.         if os.path.basename(sys.argv[i]) != 'Game.exe':
  42.             print("Please supply path to Game.exe(s) to unpack")
  43.             sys.exit(1)
  44.  
  45.     for i in range(1, len(sys.argv)):
  46.         game_path = os.path.dirname(sys.argv[i])
  47.         sysjson_p = open(os.path.join(game_path, "www/data/System.json"), 'r')
  48.         sysjson = json.loads(sysjson_p.read())
  49.         enc_key = sysjson['encryptionKey']
  50.         enc_key = bytearray.fromhex(enc_key)
  51.         sys.stdout.write(enc_key)
  52.         has_images = sysjson['hasEncryptedImages']
  53.         has_audio = sysjson['hasEncryptedAudio']
  54.         sysjson_p.close()
  55.  
  56.         if os.path.exists(os.path.join(game_path, "dump")):
  57.             shutil.rmtree(os.path.join(game_path, "dump"))
  58.  
  59.         os.mkdir(os.path.join(game_path, "dump"))
  60.  
  61.         if has_images:
  62.             os.mkdir(os.path.join(game_path, "dump/img"))
  63.             for enc_png in glob.iglob(os.path.join(game_path, "www/img/**/*.rpgmvp")):
  64.                 decrypt_image(enc_png, enc_key, game_path)
  65.         if has_audio:
  66.             os.mkdir(os.path.join(game_path, "dump/audio"))
  67.             for enc_ogg in glob.iglob(os.path.join(game_path, "www/audio/**/*.rpgmvo")):
  68.                 decrypt_audio(enc_ogg, enc_key, game_path)
RAW Paste Data