Advertisement
HenryEx

MH4U Save Encoding QuickBMS

Sep 10th, 2015
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. # Monster Hunter 4 Ultimate
  2. # Script to re-encrypt save file data
  3. #
  4. # Based on information from mhef by Seth VanHeulen
  5. # https://github.com/svanheulen/mhef
  6. #
  7. # Written by HenryEx
  8. #
  9. # script for QuickBMS http://quickbms.aluigi.org
  10.  
  11. ################################################
  12. # Preparations
  13.  
  14. print "Setup..."
  15.  
  16. # set up virtual memory file for save data
  17. math TMP = 0x13E00
  18. log MEMORY_FILE 0 0
  19. putvarchr MEMORY_FILE TMP 0 # improves the speed with pre-allocation
  20. log MEMORY_FILE 0 0 # reset the position and size of the file
  21.  
  22. # Set up default values and keys
  23. get FILENAME filename 0
  24. get FILESIZE asize 0
  25. set SAV_MH4U string "blowfish key iorajegqmrna4itjeangmb agmwgtobjteowhv9mope"
  26. set DLC_MH4U_EU string "AgK2DYheaCjyHGPB"
  27. set DLC_MH4U_JP string "AgK2DYheaCjyHGP8"
  28. set DLC_MH4U_KR string "AgK2DYheaOjyHGP8"
  29. set DLC_MH4U_TW string "Capcom123 "
  30. set KEY_MUL short 0xB0
  31. set KEY_MOD short 0xFF53
  32. set SUM long 0
  33.  
  34. # set up savedata in memory for encryption
  35. put 16 short MEMORY_FILE
  36. put 0 short MEMORY_FILE # space for xor key
  37. put 0 long MEMORY_FILE # space for checksum
  38. append # Append ON
  39. log MEMORY_FILE FILESTART FILESIZE 0 # MEMORY_FILE = decrypted save data
  40. append # Append OFF
  41. math FILESTART = 8
  42.  
  43.  
  44. ################################################
  45. # Encrypt save
  46.  
  47. print "Encrypting save"
  48.  
  49. print "-> Calculating save checksum..."
  50. for i = 0 < FILESIZE
  51. get SBYTE byte 0
  52. math SUM + SBYTE
  53. next i
  54. math SUM u& 0xFFFFFFFF
  55. print "Calculated checksum: %SUM%"
  56.  
  57. putvarchr MEMORY_FILE 4 SUM long
  58. math FILESIZE + 4
  59. math FILESTART - 4
  60.  
  61. print "-> XORing with random key..." # Well, not REALLY random...
  62. # make pseudo-random KEY
  63. xmath KEY "SUM & 0xFFFF"
  64. xmath KEY "((KEY < 7) & 0xFFFF) | (KEY > 9)" # 16bit rotated left 7x
  65. math KEY ^ 0x484D # xor with "MH"
  66.  
  67. putvarchr MEMORY_FILE 2 KEY short
  68.  
  69. # advance key and XOR 16b block of the file with it
  70. xmath XORNUM "FILESIZE / 2"
  71. for i = 0 < XORNUM
  72. xmath POS "(i * 2) + FILESTART" # get current file position
  73. if KEY == 0
  74. math KEY = 1
  75. endif
  76. math KEY * KEY_MUL
  77. math KEY % KEY_MOD
  78.  
  79. getvarchr DATA MEMORY_FILE POS short
  80. math DATA u^ KEY
  81. putvarchr MEMORY_FILE POS DATA short
  82. next i
  83.  
  84. math FILESIZE + 4
  85. math FILESTART - 4
  86.  
  87. print "-> Blowfish Encryption..."
  88. # encrypt via blowfish
  89. Encryption blowfish SAV_MH4U "" 1
  90. log MEMORY_FILE FILESTART FILESIZE MEMORY_FILE
  91. Encryption "" ""
  92.  
  93.  
  94. ################################################
  95. # Save files to disk
  96.  
  97. print "Exporting encrypted save to %FILENAME%"
  98. log FILENAME FILESTART FILESIZE MEMORY_FILE
  99.  
  100. CleanExit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement