sceutils 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sceutils/__init__.py +57 -0
- sceutils/__main__.py +57 -0
- sceutils/axfs.py +308 -0
- sceutils/decrypt_cpupdate.py +136 -0
- sceutils/emmc_extract.py +231 -0
- sceutils/extract_idstorage.py +27 -0
- sceutils/find_imported_by.py +35 -0
- sceutils/keys.py +57 -0
- sceutils/keys_external.py +333 -0
- sceutils/keys_internal.py +121 -0
- sceutils/keys_proto.py +137 -0
- sceutils/module_info.py +138 -0
- sceutils/pup_fiction.py +379 -0
- sceutils/pup_info.py +100 -0
- sceutils/scedecrypt.py +52 -0
- sceutils/scetypes.py +692 -0
- sceutils/sceutils.py +94 -0
- sceutils/self2elf.py +242 -0
- sceutils/selfinfo.py +249 -0
- sceutils/ud0_extract_pup.py +42 -0
- sceutils/unpack_bootimage_new.py +19 -0
- sceutils/util.py +72 -0
- sceutils-0.1.0.dist-info/METADATA +106 -0
- sceutils-0.1.0.dist-info/RECORD +31 -0
- sceutils-0.1.0.dist-info/WHEEL +5 -0
- sceutils-0.1.0.dist-info/entry_points.txt +3 -0
- sceutils-0.1.0.dist-info/licenses/LICENSE +21 -0
- sceutils-0.1.0.dist-info/top_level.txt +2 -0
- unarzl/__init__.py +25 -0
- unarzl/__main__.py +29 -0
- unarzl/arzl.py +497 -0
sceutils/scetypes.py
ADDED
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
import binascii
|
|
2
|
+
import struct
|
|
3
|
+
from collections import defaultdict
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import IO, ClassVar, NamedTuple, Type, TypeVar, Any
|
|
6
|
+
|
|
7
|
+
from .util import c_str
|
|
8
|
+
|
|
9
|
+
SCE_MAGIC = 0x00454353
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SceSegment(NamedTuple):
|
|
13
|
+
offset: int
|
|
14
|
+
idx: int
|
|
15
|
+
size: int
|
|
16
|
+
compressed: bool
|
|
17
|
+
key: bytes
|
|
18
|
+
iv: bytes
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SceType(Enum):
|
|
22
|
+
SELF = 1
|
|
23
|
+
SRVK = 2
|
|
24
|
+
SPKG = 3
|
|
25
|
+
DEV = 0xC0
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SceSigType(Enum):
|
|
29
|
+
ECDSA160 = 1
|
|
30
|
+
RSA2048 = 5
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class SelfType(Enum):
|
|
34
|
+
NONE = 0
|
|
35
|
+
KERNEL = 0x07
|
|
36
|
+
APP = 0x08
|
|
37
|
+
BOOT = 0x09
|
|
38
|
+
SECURE = 0x0B
|
|
39
|
+
USER = 0x0D
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class KeyType(Enum):
|
|
43
|
+
METADATA = 0
|
|
44
|
+
NPDRM = 1
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class SelfPlatform(Enum):
|
|
48
|
+
PS3 = 0
|
|
49
|
+
VITA = 0x40
|
|
50
|
+
VITASDK = 0xC0
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class SkpgType(Enum):
|
|
54
|
+
TYPE_0 = 0x0
|
|
55
|
+
OS0 = 0x1
|
|
56
|
+
TYPE_2 = 0x2
|
|
57
|
+
TYPE_3 = 0x3
|
|
58
|
+
PERMISSIONS_4 = 0x4
|
|
59
|
+
TYPE_5 = 0x5
|
|
60
|
+
TYPE_6 = 0x6
|
|
61
|
+
TYPE_7 = 0x7
|
|
62
|
+
SYSCON_8 = 0x8
|
|
63
|
+
BOOT = 0x9
|
|
64
|
+
VS0 = 0xA
|
|
65
|
+
CPFW = 0xB
|
|
66
|
+
MOTION_C = 0xC
|
|
67
|
+
BBMC_D = 0xD
|
|
68
|
+
TYPE_E = 0xE
|
|
69
|
+
MOTION_F = 0xF
|
|
70
|
+
TOUCH_10 = 0x10
|
|
71
|
+
TOUCH_11 = 0x11
|
|
72
|
+
SYSCON_12 = 0x12
|
|
73
|
+
SYSCON_13 = 0x13
|
|
74
|
+
SYSCON_14 = 0x14
|
|
75
|
+
TYPE_15 = 0x15
|
|
76
|
+
VS0_TAR_PATCH = 0x16
|
|
77
|
+
SA0 = 0x17
|
|
78
|
+
PD0 = 0x18
|
|
79
|
+
SYSCON_19 = 0x19
|
|
80
|
+
TYPE_1A = 0x1A
|
|
81
|
+
PSPEMU_LIST = 0x1B
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class ControlType(Enum):
|
|
85
|
+
CONTROL_FLAGS = 1
|
|
86
|
+
DIGEST_SHA1 = 2
|
|
87
|
+
NPDRM_PS3 = 3
|
|
88
|
+
DIGEST_SHA256 = 4
|
|
89
|
+
NPDRM_VITA = 5
|
|
90
|
+
UNK_SIG1 = 6
|
|
91
|
+
UNK_HASH1 = 7
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class SecureBool(Enum):
|
|
95
|
+
UNUSED = 0
|
|
96
|
+
NO = 1
|
|
97
|
+
YES = 2
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class EncryptionType(Enum):
|
|
101
|
+
NONE = 1
|
|
102
|
+
AES128CTR = 3
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class HashType(Enum):
|
|
106
|
+
NONE = 1
|
|
107
|
+
HMACSHA1 = 2
|
|
108
|
+
HMACSHA256 = 6
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class CompressionType(Enum):
|
|
112
|
+
NONE = 1
|
|
113
|
+
DEFLATE = 2
|
|
114
|
+
|
|
115
|
+
T = TypeVar('T', bound='Struct')
|
|
116
|
+
|
|
117
|
+
class Struct:
|
|
118
|
+
_format: ClassVar[str] = ""
|
|
119
|
+
_size: int = 0
|
|
120
|
+
|
|
121
|
+
@classmethod
|
|
122
|
+
def field_names(cls) -> list[tuple[str,Any]]:
|
|
123
|
+
return [(k,v) for k,v in cls.__annotations__.items() if k[0] != "_"]
|
|
124
|
+
|
|
125
|
+
def __init__(self, **kwargs):
|
|
126
|
+
for field_name, field_type in self.field_names():
|
|
127
|
+
value = kwargs.get(field_name)
|
|
128
|
+
if isinstance(field_type, type) and issubclass(field_type, Enum):
|
|
129
|
+
value = field_type(value)
|
|
130
|
+
setattr(self, field_name, value)
|
|
131
|
+
|
|
132
|
+
def _check(self):
|
|
133
|
+
return
|
|
134
|
+
|
|
135
|
+
@classmethod
|
|
136
|
+
def unpack(cls: Type[T], data: bytes | IO[bytes], endian="<") -> T:
|
|
137
|
+
if hasattr(data, 'read'):
|
|
138
|
+
data = data.read(cls._size) # ty:ignore[call-non-callable]
|
|
139
|
+
|
|
140
|
+
if len(data) < cls._size:
|
|
141
|
+
raise ValueError(f"Not enough data to unpack {cls.__name__}: need {cls._size}, got {len(data)}")
|
|
142
|
+
|
|
143
|
+
def decode_value(value, type):
|
|
144
|
+
if type == str:
|
|
145
|
+
return value.split(b"\x00")[0].decode()
|
|
146
|
+
return value
|
|
147
|
+
|
|
148
|
+
values = struct.unpack(endian + cls._format, data)
|
|
149
|
+
kwargs = {name: decode_value(value, type) for (name, type), value in zip(cls.field_names(), values)}
|
|
150
|
+
instance = cls(**kwargs)
|
|
151
|
+
instance._check()
|
|
152
|
+
return instance
|
|
153
|
+
|
|
154
|
+
def pack(self, endian="<") -> bytes:
|
|
155
|
+
values = []
|
|
156
|
+
for name, _ in self.field_names():
|
|
157
|
+
value = getattr(self, name)
|
|
158
|
+
if isinstance(value, Enum):
|
|
159
|
+
value = value.value
|
|
160
|
+
values.append(value)
|
|
161
|
+
return struct.pack(endian + self._format, *values)
|
|
162
|
+
|
|
163
|
+
def __str__(self) -> str:
|
|
164
|
+
lines = [f"{self.__class__.__name__}:"]
|
|
165
|
+
for name, _ in self.field_names():
|
|
166
|
+
value = getattr(self, name)
|
|
167
|
+
if isinstance(value, int):
|
|
168
|
+
lines.append(f" {name}: 0x{value:X}")
|
|
169
|
+
else:
|
|
170
|
+
lines.append(f" {name}: {value}")
|
|
171
|
+
return "\n".join(lines)
|
|
172
|
+
|
|
173
|
+
class SceHeader(Struct):
|
|
174
|
+
_format = "IIBBHIQQ"
|
|
175
|
+
_size = 0x20
|
|
176
|
+
|
|
177
|
+
magic: int
|
|
178
|
+
version: int
|
|
179
|
+
platform: SelfPlatform
|
|
180
|
+
key_revision: int
|
|
181
|
+
sce_type: SceType
|
|
182
|
+
metadata_offset: int
|
|
183
|
+
header_length: int
|
|
184
|
+
data_length: int
|
|
185
|
+
|
|
186
|
+
def _check(self):
|
|
187
|
+
if self.magic != SCE_MAGIC:
|
|
188
|
+
raise TypeError('Invalid SCE magic')
|
|
189
|
+
if self.version != 3:
|
|
190
|
+
raise TypeError('Unknown SCE version')
|
|
191
|
+
|
|
192
|
+
def __str__(self):
|
|
193
|
+
ret = 'SCE Header:\n'
|
|
194
|
+
ret += f' Version: {self.version}\n'
|
|
195
|
+
ret += f' Platform: {self.platform}\n'
|
|
196
|
+
ret += f' Key Revision: 0x{self.key_revision:X}\n'
|
|
197
|
+
ret += f' SCE Type: {self.sce_type}\n'
|
|
198
|
+
ret += f' Metadata Offset: 0x{self.metadata_offset:X}\n'
|
|
199
|
+
ret += f' Header Length: 0x{self.header_length:X}\n'
|
|
200
|
+
ret += f' Data Length: 0x{self.data_length:X}'
|
|
201
|
+
return ret
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class SelfHeader(Struct):
|
|
205
|
+
_format = "QQQQQQQQQQQ"
|
|
206
|
+
_size = 0x58
|
|
207
|
+
file_length: int
|
|
208
|
+
field_8: int
|
|
209
|
+
self_offset: int
|
|
210
|
+
appinfo_offset: int
|
|
211
|
+
elf_offset: int
|
|
212
|
+
phdr_offset: int
|
|
213
|
+
shdr_offset: int
|
|
214
|
+
segment_info_offset: int
|
|
215
|
+
sceversion_offset: int
|
|
216
|
+
controlinfo_offset: int
|
|
217
|
+
controlinfo_length: int
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class AppInfoHeader(Struct):
|
|
221
|
+
_format = "QIIQQ"
|
|
222
|
+
_size = 0x20
|
|
223
|
+
auth_id: int
|
|
224
|
+
vendor_id: int
|
|
225
|
+
self_type: SelfType
|
|
226
|
+
sys_version: int
|
|
227
|
+
field_18: int
|
|
228
|
+
|
|
229
|
+
def __str__(self):
|
|
230
|
+
ret = ''
|
|
231
|
+
ret += 'App Info Header:\n'
|
|
232
|
+
ret += f' Auth ID: 0x{self.auth_id:X}\n'
|
|
233
|
+
ret += f' Vendor ID: 0x{self.vendor_id:X}\n'
|
|
234
|
+
ret += f' SELF Type: {self.self_type}\n'
|
|
235
|
+
ret += f' Sys Version: 0x{self.sys_version:X}'
|
|
236
|
+
return ret
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
class ElfHeader(Struct):
|
|
240
|
+
_format = "QQHHIIIIIHHHHHH"
|
|
241
|
+
_size = 0x34
|
|
242
|
+
e_ident_1: int
|
|
243
|
+
e_ident_2: int
|
|
244
|
+
e_type: int
|
|
245
|
+
e_machine: int
|
|
246
|
+
e_version: int
|
|
247
|
+
e_entry: int
|
|
248
|
+
e_phoff: int
|
|
249
|
+
e_shoff: int
|
|
250
|
+
e_flags: int
|
|
251
|
+
e_ehsize: int
|
|
252
|
+
e_phentsize: int
|
|
253
|
+
e_phnum: int
|
|
254
|
+
e_shentsize: int
|
|
255
|
+
e_shnum: int
|
|
256
|
+
e_shstrndx: int
|
|
257
|
+
|
|
258
|
+
def _check(self):
|
|
259
|
+
if self.e_ident_1 != 0x10101464C457F:
|
|
260
|
+
raise TypeError('Unknown ELF e_ident')
|
|
261
|
+
if self.e_machine != 0x28 and self.e_machine != 0xF00D:
|
|
262
|
+
raise TypeError('Unknown ELF e_machine')
|
|
263
|
+
if self.e_version != 0x1:
|
|
264
|
+
raise TypeError('Unknown ELF e_version')
|
|
265
|
+
|
|
266
|
+
def __str__(self):
|
|
267
|
+
ret = ''
|
|
268
|
+
ret += 'ELF Header:\n'
|
|
269
|
+
ret += f' e_machine: {"ARM" if self.e_machine == 0x28 else "MeP"}\n'
|
|
270
|
+
ret += f' e_type: 0x{self.e_type:X}\n'
|
|
271
|
+
ret += f' e_entry: 0x{self.e_entry:X}\n'
|
|
272
|
+
ret += f' e_phoff: 0x{self.e_phoff:X}\n'
|
|
273
|
+
ret += f' e_phnum: {self.e_phnum}\n'
|
|
274
|
+
ret += f' e_shoff: 0x{self.e_shoff:X}\n'
|
|
275
|
+
ret += f' e_shnum: {self.e_shnum}'
|
|
276
|
+
return ret
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class ElfPhdr(Struct):
|
|
280
|
+
_format = "IIIIIIII"
|
|
281
|
+
_size = 0x20
|
|
282
|
+
p_type: int
|
|
283
|
+
p_offset: int
|
|
284
|
+
p_vaddr: int
|
|
285
|
+
p_paddr: int
|
|
286
|
+
p_filesz: int
|
|
287
|
+
p_memsz: int
|
|
288
|
+
p_flags: int
|
|
289
|
+
p_align: int
|
|
290
|
+
|
|
291
|
+
def __str__(self):
|
|
292
|
+
ret = ''
|
|
293
|
+
ret += 'ELF Segment:\n'
|
|
294
|
+
ret += f' p_type: 0x{self.p_type:X}\n'
|
|
295
|
+
ret += f' p_offset: 0x{self.p_offset:X}\n'
|
|
296
|
+
ret += f' p_vaddr: 0x{self.p_vaddr:X}\n'
|
|
297
|
+
ret += f' p_paddr: 0x{self.p_paddr:X}\n'
|
|
298
|
+
ret += f' p_filesz: 0x{self.p_filesz:X}\n'
|
|
299
|
+
ret += f' p_memsz: 0x{self.p_memsz:X}\n'
|
|
300
|
+
ret += f' p_flags: 0x{self.p_flags:X}\n'
|
|
301
|
+
ret += f' p_align: 0x{self.p_align:X}'
|
|
302
|
+
return ret
|
|
303
|
+
|
|
304
|
+
class ElfShdr(Struct):
|
|
305
|
+
_format = "IIIIIIIIII"
|
|
306
|
+
_size = 0x28
|
|
307
|
+
sh_name: int
|
|
308
|
+
sh_type: int
|
|
309
|
+
sh_flags: int
|
|
310
|
+
sh_addr: int
|
|
311
|
+
sh_offset: int
|
|
312
|
+
sh_size: int
|
|
313
|
+
sh_link: int
|
|
314
|
+
sh_info: int
|
|
315
|
+
sh_addralign: int
|
|
316
|
+
sh_entsize: int
|
|
317
|
+
|
|
318
|
+
def __str__(self):
|
|
319
|
+
ret = ''
|
|
320
|
+
ret += 'ELF Section:\n'
|
|
321
|
+
ret += f' sh_name: 0x{self.sh_name:X}\n'
|
|
322
|
+
ret += f' sh_type: 0x{self.sh_type:X}\n'
|
|
323
|
+
ret += f' sh_flags: 0x{self.sh_flags:X}\n'
|
|
324
|
+
ret += f' sh_addr: 0x{self.sh_addr:X}\n'
|
|
325
|
+
ret += f' sh_offset: 0x{self.sh_offset:X}\n'
|
|
326
|
+
ret += f' sh_size: 0x{self.sh_size:X}\n'
|
|
327
|
+
ret += f' sh_link: 0x{self.sh_link:X}\n'
|
|
328
|
+
ret += f' sh_info: 0x{self.sh_info:X}\n'
|
|
329
|
+
ret += f' sh_addralign: 0x{self.sh_addralign:X}\n'
|
|
330
|
+
ret += f' sh_entsize: 0x{self.sh_entsize:X}\n'
|
|
331
|
+
return ret
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class SegmentInfo(Struct):
|
|
335
|
+
_format = "QQIIII"
|
|
336
|
+
_size = 0x20
|
|
337
|
+
offset: int
|
|
338
|
+
size: int
|
|
339
|
+
compressed: SecureBool
|
|
340
|
+
field_14: int
|
|
341
|
+
plaintext: SecureBool
|
|
342
|
+
field_1C: int
|
|
343
|
+
|
|
344
|
+
def __str__(self):
|
|
345
|
+
ret = ''
|
|
346
|
+
ret += ' Segment Info:\n'
|
|
347
|
+
ret += f' offset: 0x{self.offset:X}\n'
|
|
348
|
+
ret += f' size: 0x{self.size:X}\n'
|
|
349
|
+
ret += f' compressed: {self.compressed}\n'
|
|
350
|
+
ret += f' plaintext: {self.plaintext}'
|
|
351
|
+
return ret
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
class MetadataInfo(Struct):
|
|
355
|
+
_format = "16sQQ16sQQ"
|
|
356
|
+
_size = 0x40
|
|
357
|
+
key: bytes
|
|
358
|
+
pad0: int
|
|
359
|
+
pad1: int
|
|
360
|
+
iv: bytes
|
|
361
|
+
pad2: int
|
|
362
|
+
pad3: int
|
|
363
|
+
|
|
364
|
+
def _check(self):
|
|
365
|
+
if self.pad0 != 0 or self.pad1 != 0 or self.pad2 != 0 or self.pad3 != 0:
|
|
366
|
+
raise TypeError('Invalid metadata info padding (decryption likely failed)')
|
|
367
|
+
|
|
368
|
+
def __str__(self):
|
|
369
|
+
ret = ''
|
|
370
|
+
ret += 'Metadata Info:\n'
|
|
371
|
+
ret += f' Key: {self.key.hex()}\n'
|
|
372
|
+
ret += f' IV: {self.iv.hex()}'
|
|
373
|
+
return ret
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
class MetadataHeader(Struct):
|
|
377
|
+
_format = "QIIIIII"
|
|
378
|
+
_size = 0x20
|
|
379
|
+
signature_input_length: int
|
|
380
|
+
signature_type: int
|
|
381
|
+
section_count: int
|
|
382
|
+
key_count: int
|
|
383
|
+
opt_header_size: int
|
|
384
|
+
field_18: int
|
|
385
|
+
field_1C: int
|
|
386
|
+
|
|
387
|
+
def __str__(self):
|
|
388
|
+
ret = ''
|
|
389
|
+
ret += ' Metadata Header:\n'
|
|
390
|
+
ret += f' sig_input_len: 0x{self.signature_input_length:X}\n'
|
|
391
|
+
ret += f' sig_type: {SceSigType(self.signature_type)}\n'
|
|
392
|
+
ret += f' section_count 0x{self.section_count:X}\n'
|
|
393
|
+
ret += f' key_count: 0x{self.key_count:X}\n'
|
|
394
|
+
ret += f' opt_header_size: 0x{self.opt_header_size:X}\n'
|
|
395
|
+
ret += f' field_18: {self.field_18}\n'
|
|
396
|
+
ret += f' field_1C: {self.field_1C}'
|
|
397
|
+
return ret
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
class MetadataSection(Struct):
|
|
401
|
+
_format = "QQIiIiIiiI"
|
|
402
|
+
_size = 0x30
|
|
403
|
+
offset: int
|
|
404
|
+
size: int
|
|
405
|
+
type: int
|
|
406
|
+
seg_idx: int
|
|
407
|
+
hashtype: HashType
|
|
408
|
+
hash_idx: int
|
|
409
|
+
encryption: EncryptionType
|
|
410
|
+
key_idx: int
|
|
411
|
+
iv_idx: int
|
|
412
|
+
compression: CompressionType
|
|
413
|
+
|
|
414
|
+
def __str__(self):
|
|
415
|
+
ret = ''
|
|
416
|
+
ret += ' Metadata Section:\n'
|
|
417
|
+
ret += f' offset: 0x{self.offset:X}\n'
|
|
418
|
+
ret += f' size: 0x{self.size:X}\n'
|
|
419
|
+
ret += f' type: 0x{self.type:X}\n'
|
|
420
|
+
ret += f' seg_idx: 0x{self.seg_idx:X}\n'
|
|
421
|
+
ret += f' hashtype: {self.hashtype}\n'
|
|
422
|
+
ret += f' hash_idx: 0x{self.hash_idx:X}\n'
|
|
423
|
+
ret += f' encryption: {self.encryption}\n'
|
|
424
|
+
ret += f' key_idx: 0x{self.key_idx:X}\n'
|
|
425
|
+
ret += f' iv_idx: 0x{self.iv_idx:X}\n'
|
|
426
|
+
ret += f' compression: {self.compression}'
|
|
427
|
+
return ret
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
class SrvkHeader(Struct):
|
|
431
|
+
_format = "IIQIIII"
|
|
432
|
+
_size = 0x20
|
|
433
|
+
field_0: int
|
|
434
|
+
field_4: int
|
|
435
|
+
sys_version: int
|
|
436
|
+
field_10: int
|
|
437
|
+
field_14: int
|
|
438
|
+
field_18: int
|
|
439
|
+
field_1C: int
|
|
440
|
+
|
|
441
|
+
def __str__(self):
|
|
442
|
+
ret = ''
|
|
443
|
+
ret += 'SRVK Header:\n'
|
|
444
|
+
ret += f' field_0: 0x{self.field_0:X}\n'
|
|
445
|
+
ret += f' field_4: 0x{self.field_4:X}\n'
|
|
446
|
+
ret += f' sys_version: 0x{self.sys_version:X}\n'
|
|
447
|
+
ret += f' field_10: 0x{self.field_10:X}\n'
|
|
448
|
+
ret += f' field_14: 0x{self.field_14:X}\n'
|
|
449
|
+
ret += f' field_18: 0x{self.field_18:X}\n'
|
|
450
|
+
ret += f' field_1C: 0x{self.field_1C:X}\n'
|
|
451
|
+
return ret
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
class SpkgHeader(Struct):
|
|
455
|
+
_format = "IIIIQQQQIIIIQQQQQQQQ"
|
|
456
|
+
_size = 0x80
|
|
457
|
+
field_0: int
|
|
458
|
+
pkg_type: SkpgType
|
|
459
|
+
flags: int
|
|
460
|
+
field_C: int
|
|
461
|
+
update_version: int
|
|
462
|
+
final_size: int
|
|
463
|
+
decrypted_size: int
|
|
464
|
+
field_28: int
|
|
465
|
+
field_30: int
|
|
466
|
+
field_34: int
|
|
467
|
+
field_38: int
|
|
468
|
+
field_3C: int
|
|
469
|
+
field_40: int
|
|
470
|
+
field_48: int
|
|
471
|
+
offset: int
|
|
472
|
+
size: int
|
|
473
|
+
part_idx: int
|
|
474
|
+
total_parts: int
|
|
475
|
+
field_70: int
|
|
476
|
+
field_78: int
|
|
477
|
+
|
|
478
|
+
def __str__(self):
|
|
479
|
+
ret = ''
|
|
480
|
+
ret += 'SPKG Header:\n'
|
|
481
|
+
ret += f' field_0: 0x{self.field_0:X}\n'
|
|
482
|
+
ret += f' type: {self.pkg_type}\n'
|
|
483
|
+
ret += f' flags: 0x{self.flags:X}\n'
|
|
484
|
+
ret += f' field_C: 0x{self.field_C:X}\n'
|
|
485
|
+
ret += f' update_version: 0x{self.update_version:X}\n'
|
|
486
|
+
ret += f' final_size: 0x{self.final_size:X}\n'
|
|
487
|
+
ret += f' decrypted_size: 0x{self.decrypted_size:X}\n'
|
|
488
|
+
ret += f' field_28: 0x{self.field_28:X}\n'
|
|
489
|
+
ret += f' field_30: 0x{self.field_30:X}\n'
|
|
490
|
+
ret += f' field_34: 0x{self.field_34:X}\n'
|
|
491
|
+
ret += f' field_38: 0x{self.field_38:X}\n'
|
|
492
|
+
ret += f' field_3C: 0x{self.field_3C:X}\n'
|
|
493
|
+
ret += f' field_40: 0x{self.field_40:X}\n'
|
|
494
|
+
ret += f' field_48: 0x{self.field_48:X}\n'
|
|
495
|
+
ret += f' offset: 0x{self.offset:X}\n'
|
|
496
|
+
ret += f' size: 0x{self.size:X}\n'
|
|
497
|
+
ret += f' part_idx: 0x{self.part_idx:X}\n'
|
|
498
|
+
ret += f' total_parts: 0x{self.total_parts:X}\n'
|
|
499
|
+
ret += f' field_70: 0x{self.field_70:X}\n'
|
|
500
|
+
ret += f' field_78: 0x{self.field_78:X}\n'
|
|
501
|
+
return ret
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
class SceVersionInfo(Struct):
|
|
505
|
+
_format = "IIQ"
|
|
506
|
+
_size = 0x10
|
|
507
|
+
subtype: int
|
|
508
|
+
is_present: int
|
|
509
|
+
size: int
|
|
510
|
+
|
|
511
|
+
def __str__(self):
|
|
512
|
+
ret = 'SCE Version Info Header:\n'
|
|
513
|
+
ret += f' subtype: 0x{self.subtype:X}\n'
|
|
514
|
+
ret += f' isPresent: 0x{self.is_present:X}\n'
|
|
515
|
+
ret += f' size: 0x{self.size:X}\n'
|
|
516
|
+
return ret
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
class SceControlInfo(Struct):
|
|
520
|
+
_format = "IIQ"
|
|
521
|
+
_size = 0x10
|
|
522
|
+
control_type: ControlType
|
|
523
|
+
size: int
|
|
524
|
+
more: int
|
|
525
|
+
|
|
526
|
+
def _initialize(self):
|
|
527
|
+
self.control_type = ControlType(self.control_type)
|
|
528
|
+
|
|
529
|
+
def __str__(self):
|
|
530
|
+
ret = 'SCE Control Info Header:\n'
|
|
531
|
+
ret += f' control_type: {self.control_type}\n'
|
|
532
|
+
ret += f' size: 0x{self.size:X}\n'
|
|
533
|
+
ret += f' more: 0x{self.more:X}\n'
|
|
534
|
+
return ret
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
class SceControlInfoDigest256(Struct):
|
|
538
|
+
_format = "20s32sIII"
|
|
539
|
+
_size = 0x40
|
|
540
|
+
sce_hash: bytes
|
|
541
|
+
file_hash: bytes
|
|
542
|
+
filler1: int
|
|
543
|
+
filler2: int
|
|
544
|
+
sdk_version: int
|
|
545
|
+
|
|
546
|
+
def __str__(self):
|
|
547
|
+
ret = 'SCE Control Info Digest256:\n'
|
|
548
|
+
ret += f' SCE Hash: {self.sce_hash.hex()}\n'
|
|
549
|
+
ret += f' File Hash: {self.file_hash.hex()}\n'
|
|
550
|
+
ret += f' SDK version: 0x{self.sdk_version:X}\n'
|
|
551
|
+
return ret
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
class SceControlInfoDRM(Struct):
|
|
555
|
+
_format = "IHHII48s16s32s32s28s28s28s28s"
|
|
556
|
+
_size = 0x100
|
|
557
|
+
magic: int
|
|
558
|
+
sig_offset: int
|
|
559
|
+
size: int
|
|
560
|
+
npdrm_type: int
|
|
561
|
+
field_C: int
|
|
562
|
+
content_id: bytes
|
|
563
|
+
digest1: bytes
|
|
564
|
+
hash1: bytes
|
|
565
|
+
hash2: bytes
|
|
566
|
+
sig1r: bytes
|
|
567
|
+
sig1s: bytes
|
|
568
|
+
sig2r: bytes
|
|
569
|
+
sig2s: bytes
|
|
570
|
+
|
|
571
|
+
def __str__(self):
|
|
572
|
+
ret = 'SCE DRM Info:\n'
|
|
573
|
+
ret += f' Magic: 0x{self.magic:X}\n'
|
|
574
|
+
ret += f' Sig Offset: 0x{self.sig_offset:X}\n'
|
|
575
|
+
ret += f' Size: 0x{self.size:X}\n'
|
|
576
|
+
ret += f' NPDRM Type: 0x{self.npdrm_type:X}\n'
|
|
577
|
+
ret += f' Content ID: {self.content_id}\n'
|
|
578
|
+
ret += f' Type Digest: {self.digest1.hex()}\n'
|
|
579
|
+
ret += f' ECDSA224 Sig R: {self.sig2r.hex()}\n'
|
|
580
|
+
ret += f' ECDSA224 Sig S: {self.sig2s.hex()}\n'
|
|
581
|
+
return ret
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
class SceRIF(Struct):
|
|
585
|
+
_format = "HHHHQ48s16s16s16sQ20s20s"
|
|
586
|
+
_size = 0xa0
|
|
587
|
+
majver: int
|
|
588
|
+
minver: int
|
|
589
|
+
style: int
|
|
590
|
+
riftype: int
|
|
591
|
+
cid: int
|
|
592
|
+
content_id: bytes
|
|
593
|
+
actidx: bytes
|
|
594
|
+
klicense: bytes
|
|
595
|
+
dates: bytes
|
|
596
|
+
filler: int
|
|
597
|
+
sig1r: bytes
|
|
598
|
+
sig1s: bytes
|
|
599
|
+
|
|
600
|
+
def __str__(self):
|
|
601
|
+
ret = 'SCE RIF Info:\n'
|
|
602
|
+
ret += f' Maj Ver: 0x{self.majver:X}\n'
|
|
603
|
+
ret += f' Min Ver: 0x{self.minver:X}\n'
|
|
604
|
+
ret += f' Style: 0x{self.style:X}\n'
|
|
605
|
+
ret += f' RifType: 0x{self.riftype:X}\n'
|
|
606
|
+
ret += f' CID: 0x{self.cid:X}\n'
|
|
607
|
+
ret += f' Content ID: {self.content_id}\n'
|
|
608
|
+
ret += f' KLicensee: {self.klicense.hex()}\n'
|
|
609
|
+
ret += f' ECDSA160 Sig R: {self.sig1r.hex()}\n'
|
|
610
|
+
ret += f' ECDSA160 Sig S: {self.sig1s.hex()}\n'
|
|
611
|
+
return ret
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
class SceModuleInfo(Struct):
|
|
615
|
+
_format = "hh27sbIIIIIIIIIIIIIII"
|
|
616
|
+
_size = 0x5c
|
|
617
|
+
attributes: int
|
|
618
|
+
version: int
|
|
619
|
+
module_name: str
|
|
620
|
+
type: int
|
|
621
|
+
gp_value: int
|
|
622
|
+
exportsStart: int
|
|
623
|
+
exportsEnd: int
|
|
624
|
+
importsTop: int
|
|
625
|
+
importsEnd: int
|
|
626
|
+
module_nid: int
|
|
627
|
+
tlsStart: int
|
|
628
|
+
tlsFileSize: int
|
|
629
|
+
tlsMemSize: int
|
|
630
|
+
module_start: int
|
|
631
|
+
module_stop: int
|
|
632
|
+
exidx_top: int
|
|
633
|
+
exidx_end: int
|
|
634
|
+
extab_start: int
|
|
635
|
+
extab_end: int
|
|
636
|
+
|
|
637
|
+
def _initialize(self):
|
|
638
|
+
self.module_name = c_str(self.module_name)
|
|
639
|
+
|
|
640
|
+
class SceModuleImports(Struct):
|
|
641
|
+
_format = "hhhhhhIIIIIIIIII"
|
|
642
|
+
_size = 0x34
|
|
643
|
+
size: int
|
|
644
|
+
version: int
|
|
645
|
+
attribute: int
|
|
646
|
+
num_functions: int
|
|
647
|
+
num_vars: int
|
|
648
|
+
num_tls_vars: int
|
|
649
|
+
reserved1: int
|
|
650
|
+
library_nid: int
|
|
651
|
+
library_name: int
|
|
652
|
+
reserved2: int
|
|
653
|
+
func_nid_table: int
|
|
654
|
+
func_entry_table: int
|
|
655
|
+
var_nid_table: int
|
|
656
|
+
var_entry_table: int
|
|
657
|
+
tls_nid_table: int
|
|
658
|
+
tls_entry_table: int
|
|
659
|
+
|
|
660
|
+
class SceModuleImports2(Struct):
|
|
661
|
+
_format = "hhhhIIIIIII"
|
|
662
|
+
_size = 0x24
|
|
663
|
+
size: int
|
|
664
|
+
version: int
|
|
665
|
+
attribute: int
|
|
666
|
+
num_functions: int
|
|
667
|
+
num_vars: int
|
|
668
|
+
library_nid: int
|
|
669
|
+
library_name: int
|
|
670
|
+
func_nid_table: int
|
|
671
|
+
func_entry_table: int
|
|
672
|
+
var_nid_table: int
|
|
673
|
+
var_entry_table: int
|
|
674
|
+
|
|
675
|
+
class SceModuleLibaryExports(Struct):
|
|
676
|
+
_format = "bbhhhhhbbbbIIII"
|
|
677
|
+
_size = 0x20
|
|
678
|
+
size: int
|
|
679
|
+
pad: int
|
|
680
|
+
version: int
|
|
681
|
+
attr: int
|
|
682
|
+
nfunc: int
|
|
683
|
+
nvar: int
|
|
684
|
+
ntlsvar: int
|
|
685
|
+
hashinfo: int
|
|
686
|
+
hashinfotls: int
|
|
687
|
+
pad2: int
|
|
688
|
+
nidaltsets: int
|
|
689
|
+
libname_nid: int
|
|
690
|
+
libname_ptr: int
|
|
691
|
+
nidtable: int
|
|
692
|
+
addrtable: int
|