-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patharc.py
More file actions
54 lines (43 loc) · 1.53 KB
/
arc.py
File metadata and controls
54 lines (43 loc) · 1.53 KB
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
from cffi import FFI
from PIL import Image
import os
import struct
import io
ffi = FFI()
ffi.cdef("""
uint8_t * cbg_decrypt(uint8_t * crypted, uint32_t * pSize, uint32_t * pWidth, uint32_t * pHeight, uint32_t * pBitDepth);
void cbg_free(uint8_t * decrypted);
uint8_t * dsc_decrypt(uint8_t * crypted, uint32_t crypted_size, uint32_t * decrypted_size);
void dsc_free(uint8_t * decrypted);
""")
__dirname = os.path.dirname(__file__)
arc = ffi.dlopen(os.path.join(__dirname, "arc.dll"))
def cbg_decrypt(crypted):
fsize = ffi.new("uint32_t *")
width = ffi.new("uint32_t *")
height = ffi.new("uint32_t *")
bbp = ffi.new("uint32_t *")
data = arc.cbg_decrypt(crypted, fsize, width, height, bbp)
buf = ffi.buffer(data, fsize[0])
im = None
if bbp[0] == 8 or bbp[0] == 24:
pixels = [(r, g, b) for r, g, b, a in struct.iter_unpack('<BBBB', bytes(buf))]
im = Image.new('RGB', (width[0], height[0]))
im.putdata(pixels)
out = io.BytesIO()
im.save(out, format='PNG')
return out.getvalue()
elif bbp[0] == 32:
im = Image.frombytes('RGBA', (width[0], height[0]), bytes(buf))
out = io.BytesIO()
im.save(out, format='PNG')
return out.getvalue()
def dsc_decrypt(crypted):
fsize = ffi.new('uint32_t *')
data = arc.dsc_decrypt(crypted, len(crypted), fsize)
buf = ffi.buffer(data, fsize[0])
# arc.dsc_free(data)
return bytes(buf)
# def bse_decrypt(crypted):
# data = ffi.new('char[]', crypted);
# arc.bse_decrypt(data)