-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
54 lines (45 loc) · 1.73 KB
/
functions.py
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
from typing import List
import numba
import xipDecoder_strategy
def checksumA(a:int , b:int, c:int) -> bool:
if c == 0:
#if __debug__: print("Unimplemented border case") TODO?
b ^= 1
var1 = (a * b) & 0xFF
return var1 == c
def japDeXor(input_: bytes, offset: int , strategy: xipDecoder_strategy.XipDecoderStrategy ) -> bytes:
assert offset >= 0
xorKey = xipDecoder_strategy.XipDecoderStrategy().japaneseTextXorEncoder()
output = bytes()
for i in range( strategy.fileHeaderLength()):
offset &= 255 #len(xorKey)
byteA = (xorKey[offset] ^ input_[i]).to_bytes(1, "big")
output += bytearray(byteA)
offset += 1
return output
def deXorTxt(input_: bytes) -> bytes:
import struct
with open("./keyFiles/txtCrcMask.bin", "rb") as file:
key = bytes(file.read())
key = struct.unpack_from("<256I", key)
output = bytes()
key_offset = len(input_) % 0x100
i = 0
for i in range(len(input_) // 4):
inputInt4 = struct.unpack_from("<I", input_, i*4)[0]
outputInt4 = ( (inputInt4 - key[(key_offset+i) % len(key)]) % 0x100000000 ).to_bytes(4, "big")
output += outputInt4[::-1]
# if the input is not a multiple of 4, the last bytes (3,2,or 1) are left as is.
i = len(input_) % 4
if i > 0:
output += input_[-i:]
return output
def deXorVisualClip(input_: bytes) -> bytes:
key : bytes = xipDecoder_strategy.VcKey().get()
offset = 0xED
output = bytearray(input_[:])
for i in range(8, len(input_) ):# preserve the first 8 bytes.
offset &= 255 #len(key)
output[i] = key[offset % 256] ^ input_[i]
offset += 1
return output