Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.86 KB | None | 0 0
  1. import struct
  2. import binascii
  3. import sys
  4.  
  5. spoof = 0
  6. i = 0
  7. while i <= (len(sys.argv) - 1):
  8. if sys.argv[i] == "-spoof":
  9. spoof = 1
  10. i += 1
  11. gamename = str(sys.argv[1]) + '.3ds'
  12. with open(gamename, "rb") as f:
  13. f.seek(0x1109) # UniqueId
  14. uid = f.read(4)
  15. uid = binascii.hexlify(uid)[::-1]
  16. c = list(uid)
  17. c[::2], c[1::2] = c[1::2], c[::2]
  18. uid = "".join(c)
  19. f.seek(0x1110) # CompanyCode
  20. read = f.read(2)
  21. ccode = "".join(struct.unpack('<cc', read))
  22. f.seek(0x1150) # ProductCode
  23. read = f.read(10)
  24. pcode = "".join(struct.unpack('<cccccccccc', read))
  25. pcode = pcode.rstrip(' \0')
  26. f.close
  27. with open("exheader.bin", "rb") as f:
  28.  
  29. f.seek(0) # Title
  30. read = f.read(8)
  31. title = "".join(struct.unpack('<cccccccc', read))
  32. title = title.rstrip(' \0')
  33.  
  34. f.seek(0xE) # Remaster version
  35. rver = f.read(2)
  36. rver = (binascii.hexlify(rver))[::-1]
  37. c = list(rver)
  38. c[::2], c[1::2] = c[1::2], c[::2]
  39. rver = "".join(c)
  40.  
  41. f.seek(0x1C) # Stacksize
  42. stack = f.read(4)
  43. stack = (binascii.hexlify(stack))[::-1]
  44. c = list(stack)
  45. c[::2], c[1::2] = c[1::2], c[::2]
  46. stack = "".join(c)
  47.  
  48. f.seek(0x40) # Dependencies
  49. dep = range(48)
  50. for i in range(48):
  51. dep[i] = f.read(8)
  52. dep[i] = binascii.hexlify(dep[i])[::-1]
  53. c = list(dep[i])
  54. c[::2], c[1::2] = c[1::2], c[::2]
  55. dep[i] = "".join(c)
  56. f.seek(0x247) # Uses extended save data access?
  57. r = f.read(1)
  58. uext = binascii.hexlify(r)
  59. if uext == "00":
  60. f.seek(0x230) # ExtSaveDataId
  61. exts = f.read(8)
  62. exts = (binascii.hexlify(exts))[::-1]
  63. c = list(exts)
  64. c[::2], c[1::2] = c[1::2], c[::2]
  65. exts = "".join(c)
  66. f.seek(0x238) # System save id 1
  67. ssid1 = f.read(4)
  68. ssid1 = (binascii.hexlify(ssid1))[::-1]
  69. c = list(ssid1)
  70. c[::2], c[1::2] = c[1::2], c[::2]
  71. ssid1 = "".join(c)
  72. f.seek(0x23C) # System save id 2
  73. ssid2 = f.read(4)
  74. ssid2 = (binascii.hexlify(ssid2))[::-1]
  75. c = list(ssid2)
  76. c[::2], c[1::2] = c[1::2], c[::2]
  77. ssid2 = "".join(c)
  78. f.seek(0x240) # Other save id 1
  79. osid1 = f.read(3)
  80. osid1 = (binascii.hexlify(osid1))[::-1]
  81. c = list(osid1)
  82. c[::2], c[1::2] = c[1::2], c[::2]
  83. osid1 = "".join(c)
  84. osid1 = osid1[1:]
  85. f.seek(0x242) # Other save id 2
  86. osid2 = f.read(3)
  87. osid2 = (binascii.hexlify(osid2))[::-1]
  88. c = list(osid2)
  89. c[::2], c[1::2] = c[1::2], c[::2]
  90. osid2 = "".join(c)
  91. osid2 = osid2[:5]
  92. f.seek(0x245) # Other save id 2
  93. osid3 = f.read(3)
  94. osid3 = (binascii.hexlify(osid3))[::-1]
  95. c = list(osid3)
  96. c[::2], c[1::2] = c[1::2], c[::2]
  97. osid3 = "".join(c)
  98. osid3 = osid3[1:]
  99.  
  100. if uext == "10":
  101. f.seek(0x240) # Other save id 1
  102. esid1 = f.read(3)
  103. esid1 = (binascii.hexlify(esid1))[::-1]
  104. c = list(esid1)
  105. c[::2], c[1::2] = c[1::2], c[::2]
  106. esid1 = "".join(c)
  107. esid1 = esid1[1:]
  108. f.seek(0x242) # Other save id 2
  109. esid2 = f.read(3)
  110. esid2 = (binascii.hexlify(esid2))[::-1]
  111. c = list(esid2)
  112. c[::2], c[1::2] = c[1::2], c[::2]
  113. esid2 = "".join(c)
  114. esid2 = esid2[:5]
  115. f.seek(0x245) # Other save id 2
  116. esid3 = f.read(3)
  117. esid3 = (binascii.hexlify(esid3))[::-1]
  118. c = list(esid3)
  119. c[::2], c[1::2] = c[1::2], c[::2]
  120. esid3 = "".join(c)
  121. esid3 = esid3[1:]
  122.  
  123. f.seek(0x230) # Other save id 1
  124. esid4 = f.read(3)
  125. esid4 = (binascii.hexlify(esid4))[::-1]
  126. c = list(esid4)
  127. c[::2], c[1::2] = c[1::2], c[::2]
  128. esid4 = "".join(c)
  129. esid4 = esid4[1:]
  130. f.seek(0x232) # Other save id 2
  131. esid5 = f.read(3)
  132. esid5 = (binascii.hexlify(esid5))[::-1]
  133. c = list(esid5)
  134. c[::2], c[1::2] = c[1::2], c[::2]
  135. esid5 = "".join(c)
  136. esid5 = esid5[:5]
  137. f.seek(0x235) # Other save id 2
  138. esid6 = f.read(3)
  139. esid6 = (binascii.hexlify(esid6))[::-1]
  140. c = list(esid6)
  141. c[::2], c[1::2] = c[1::2], c[::2]
  142. esid6 = "".join(c)
  143. esid6 = esid6[1:]
  144.  
  145.  
  146. f.seek(0x248) # Access control FileSystemAccess
  147. r = f.read(6)
  148. c = (binascii.hexlify(r))
  149. c = list(c)
  150. c[::2], c[1::2] = c[1::2], c[::2]
  151. fsaccess=["#"] * 21
  152. if c[0] == "1":
  153. fsaccess[0] = "-"
  154. if c[0] == "2":
  155. fsaccess[1] = "-"
  156. if c[0] == "4":
  157. fsaccess[2] = "-"
  158. if c[0] == "8":
  159. fsaccess[3] = "-"
  160. if c[1] == "1":
  161. fsaccess[4] = "-"
  162. if c[1] == "2":
  163. fsaccess[5] = "-"
  164. if c[1] == "4":
  165. fsaccess[6] = "-"
  166. if c[1] == "8":
  167. fsaccess[7] = "-"
  168. if c[2] == "1":
  169. fsaccess[8] = "-"
  170. if c[2] == "2":
  171. fsaccess[9] = "-"
  172. if c[2] == "4":
  173. fsaccess[10] = "-"
  174. if c[2] == "8":
  175. fsaccess[11] = "-"
  176. if c[3] == "1":
  177. fsaccess[12] = "-"
  178. if c[3] == "2":
  179. fsaccess[13] = "-"
  180. if c[3] == "4":
  181. fsaccess[14] = "-"
  182. if c[3] == "8":
  183. fsaccess[15] = "-"
  184. if c[4] == "1":
  185. fsaccess[16] = "-"
  186. if c[4] == "2":
  187. fsaccess[17] = "-"
  188. if c[4] == "4":
  189. fsaccess[18] = "-"
  190. if c[4] == "8":
  191. fsaccess[19] = "-"
  192. if c[5] == "1":
  193. fsaccess[20] = "-"
  194.  
  195. f.seek(0x250) # ServiceAccessControl
  196. svcacc = range(32)
  197. for i in range(32):
  198. r = f.read(8)
  199. r = r.rstrip("\0")
  200. svcacc[i] = r
  201.  
  202. f.seek(0x394) # Access control ARM11
  203. b = f.read(1)
  204. b = binascii.hexlify(b)
  205. b = bin(int(b, 16))[2:]
  206. b = b.zfill(9)[::-1]
  207. b = list(b)
  208. accesslist = range(9)
  209. for i in range (0, 9):
  210. if b[i] == "1":
  211. accesslist[i] = "true "
  212. elif b[i] == "0":
  213. accesslist[i] = "false"
  214. i += 1
  215.  
  216. f.seek(0x39C)
  217. b = f.read(1)
  218. b = str(int(binascii.hexlify(b), 16))
  219. kr = 0
  220. if b != "255":
  221. kmin = b
  222. kr = 1
  223. f.seek(0x39D)
  224. b = f.read(1)
  225. b = str(int(binascii.hexlify(b), 16))
  226. if b != "255":
  227. kmaj = "0" + b
  228.  
  229. #rsfname = str(sys.argv[1]) + ".rsf"
  230.  
  231. with open(gamename[:-4] + ".rsf", "r+b") as f:
  232. f.seek(0x28) # Title
  233. s = str(title)
  234. s = s.rstrip("0")
  235. s = "\"" + title + "\" "
  236. f.write(s)
  237. f.seek(0x52) # CompanyCode
  238. s=str(ccode)
  239. f.write(s)
  240. f.seek(0x73) # ProductCode
  241. s = str(pcode)
  242. s = s.rstrip("0")
  243. s ="\"" + s + "\""
  244. f.write(s)
  245. f.seek(0x16D) # UniqueId
  246. s=str(uid)
  247. f.write(s)
  248. if uext == "00":
  249. f.seek(0x4B5)
  250. f.write("E")
  251. f.seek(0x4C6) # ExtSavaDataId
  252. s=str(exts)
  253. f.write(s)
  254. f.seek(0x4EF) # System save id 1
  255. s=str(ssid1)
  256. f.write(s)
  257. f.seek(0x50E) # System save id 2
  258. s=str(ssid2)
  259. f.write(s)
  260. f.seek(0x534) # Other save id 1
  261. s=str(osid1)
  262. f.write(s)
  263. f.seek(0x555) # Other save id 2
  264. s=str(osid2)
  265. f.write(s)
  266. f.seek(0x576) # Other save id 3
  267. s=str(osid3)
  268. f.write(s)
  269. if uext == "10":
  270. f.seek(0x96C)
  271. f.write("True ")
  272. f.seek(0x10C9)
  273. f.write("A")
  274. f.seek(0x10E4)
  275. s = str(esid1)
  276. if s != "00000":
  277. s = "- 0x" + s
  278. f.write(s)
  279. f.seek(0x10F2)
  280. s = str(esid2)
  281. if s != "00000":
  282. s = "- 0x" + s
  283. f.write(s)
  284. f.seek(0x1100)
  285. s = str(esid3)
  286. if s != "00000":
  287. s = "- 0x" + s
  288. f.write(s)
  289. f.seek(0x110E)
  290. s = (esid4)
  291. if s != "00000":
  292. s = "- 0x" + s
  293. f.write(s)
  294. f.seek(0x111C)
  295. s = (esid5)
  296. if s != "00000":
  297. s = "- 0x" + s
  298. f.write(s)
  299. f.seek(0x112A)
  300. s = (esid6)
  301. if s != "00000":
  302. s = "- 0x" + s
  303. f.write(s)
  304. f.seek(0x595) # File System Access
  305. f.write(fsaccess[0])
  306. f.seek(0x5B5)
  307. f.write(fsaccess[1])
  308. f.seek(0x5D1)
  309. f.write(fsaccess[2])
  310. f.seek(0x5EE)
  311. f.write(fsaccess[3])
  312. f.seek(0x5FA)
  313. f.write(fsaccess[4])
  314. f.seek(0x60E)
  315. f.write(fsaccess[5])
  316. f.seek(0x620)
  317. f.write(fsaccess[6])
  318. f.seek(0x62B)
  319. f.write(fsaccess[7])
  320. f.seek(0x63C)
  321. f.write(fsaccess[8])
  322. f.seek(0x647)
  323. f.write(fsaccess[9])
  324. f.seek(0x657)
  325. f.write(fsaccess[10])
  326. f.seek(0x667)
  327. f.write(fsaccess[11])
  328. f.seek(0x67C)
  329. f.write(fsaccess[12])
  330. f.seek(0x699)
  331. f.write(fsaccess[13])
  332. f.seek(0x6A9)
  333. f.write(fsaccess[14])
  334. f.seek(0x6BF)
  335. f.write(fsaccess[15])
  336. f.seek(0x6D5)
  337. f.write(fsaccess[16])
  338. f.seek(0x6E9)
  339. f.write(fsaccess[17])
  340. f.seek(0x6FC)
  341. f.write(fsaccess[18])
  342. f.seek(0x707)
  343. f.write(fsaccess[19])
  344. f.seek(0x713)
  345. f.write(fsaccess[20])
  346. if kr == 1:
  347. if spoof == 1:
  348. f.seek(0x9C7)
  349. f.write("R")
  350. f.seek(0x9E8)
  351. f.write("02")
  352. f.seek(0x9EF)
  353. f.write("R")
  354. f.seek(0xA10)
  355. f.write("33")
  356. if spoof == 0:
  357. f.seek(0x9C7)
  358. f.write("R")
  359. f.seek(0x9E8)
  360. f.write(kmaj)
  361. f.seek(0x9EF)
  362. f.write("R")
  363. f.seek(0xA10)
  364. f.write(kmin)
  365. f.seek(0x1168) # Service Access Control
  366. for i in range(32):
  367. if svcacc[i] != "":
  368. s="- " + str(svcacc[i]) + " "
  369. s= s.ljust(11,"#")
  370. f.write(s)
  371. f.seek(5,1)
  372. f.seek(0x13A2) # Remaster version
  373. s=str(rver)
  374. f.write(s)
  375. f.seek(0x13B7) # Stacksize
  376. s=str(stack)
  377. f.write(s)
  378. f.seek(0x13D5) # Dependencies
  379. for i in range(48):
  380. if dep[i] != "0000000000000000":
  381. s="a: 0x" + str(dep[i]) + "L"
  382. f.write(s)
  383. f.seek(6,1)
  384. f.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement