-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTGInjector.nim
67 lines (55 loc) · 4.88 KB
/
TGInjector.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os, streams
const mainFile = staticRead "dat.dat"
var
i, marker, padding, romSize : int64
c : char
romFilename : string
romData : FileStream
buf : array[1, int8]
var keyPSPIndex = 0
var keyPublicIndex = 0
let keyPSP = [0x22, 0xDE, 0xB3, 0xE5, 0x19, 0x4A, 0xE8, 0x47, 0x95, 0xFD, 0x45, 0xBA, 0xDD, 0x09, 0x6B, 0xF8]
let keyPublic = [0x7A, 0xE4, 0x14, 0x19, 0xE9, 0x2E, 0x5D, 0xB4, 0x03, 0x33, 0xA9, 0x1D, 0x9B, 0x6F, 0x47, 0x05, 0xCE, 0x0B, 0xEB, 0xE4, 0xA0, 0xE7, 0xA6, 0x9B, 0x8C, 0x0E, 0x97, 0x43, 0xD8, 0x65, 0x5F, 0xCE, 0x8E, 0xD9, 0xC3, 0x37, 0x3C, 0xE4, 0x65, 0x52, 0xCC, 0x1A, 0xAA, 0x44, 0x62, 0xFA, 0x6E, 0xC8, 0x10, 0xAA, 0xA5, 0x42, 0x86, 0x57, 0x7E, 0x93, 0x3D, 0x78, 0x8C, 0xDB, 0x96, 0x1A, 0xDB, 0x9E, 0xD3, 0xDA, 0x8F, 0xC2, 0xAB, 0x0F, 0xC9, 0xE9, 0xA5, 0x98, 0x17, 0x86, 0x3D, 0x62, 0x39, 0x92, 0xA0, 0xCE, 0x32, 0x2D, 0xBF, 0x1C, 0x47, 0x36, 0x5A, 0x30, 0xFA, 0xC3, 0x57, 0x8A, 0xBB, 0xB2, 0x3E, 0x0B, 0x70, 0x88, 0x6A, 0xAB, 0x1D, 0x01, 0xE1, 0xBC, 0x9D, 0xEE, 0x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F, 0x58, 0xB0, 0xCD, 0xA7, 0xD4, 0xCA, 0x83, 0x52, 0xE0, 0x60, 0x84, 0x73, 0xC6, 0x35, 0x99, 0x65, 0x49, 0x4D, 0x64, 0x57, 0x60, 0xB1, 0xF9, 0xDE, 0x85, 0x38, 0x56, 0xEB, 0xEA, 0x0F, 0xAF, 0x44, 0x15, 0x6D, 0x21, 0x5D, 0x82, 0xDB]
echo "TGInjector v1"
if paramCount() == 0:
echo "Provide a rom file as a command-line parameter, or drag'n'drop it on the executable. \nPress enter to exit ..."
c = readChar(stdin)
quit()
else:
romFilename = paramStr(1)
echo "Opening rom: ", romFilename
try:
romData = openFileStream(romFilename, fmRead)
except:
echo "Error opening: ", romFilename, "\nPress enter to exit ..."
c = readChar(stdin)
quit()
var f = open("temporary.DAT", fmReadWrite)
f.write(mainFile)
marker = f.getFilePos()
f.write(romData.readAll)
romSize = f.getFilePos() - marker
marker = f.getFilePos()
echo "Rom size is ", romSize, " bytes"
padding = (len(mainFile) + romSize) mod 32
echo "Padding needed is ", padding, " bytes"
f.setFilePos(0xD94)
discard f.writeBuffer(addr(romSize), sizeof(romSize))
f.setFilePos(0)
var final = open("CONTENT.DAT", fmReadWrite)
i = 0
while i < marker:
keyPSPIndex = keyPSPIndex and 0xF
keyPublicIndex = keyPublicIndex and 0x1FF
discard f.readBytes(buf, 0, 1)
#f.setFilePos(f.getFilePos() - 1)
buf[0] = cast[int8](keyPSP[keyPSPIndex] xor keyPublic[keyPublicIndex] xor buf[0])
discard final.writeBuffer(addr(buf[0]), 1)
keyPSPIndex = keyPSPIndex + 1
keyPublicIndex = keyPublicIndex + 1
i = i + 1
f.close()
removeFile("temporary.DAT")
echo "CONTENT.DAT created, copy it into the /PSP/GAME/NPUF30016 folder, overwriting the existing file \nPress enter to exit ..."
c = readChar(stdin)
quit()