-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathself.h
More file actions
107 lines (86 loc) · 2.45 KB
/
self.h
File metadata and controls
107 lines (86 loc) · 2.45 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Copyright (C) 2025 John Törnblom
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>. */
#pragma once
#include <elf.h>
#include <stdint.h>
/**
* Magic integer (little endian) that all PS4 or PS5 SELF files starts with.
**/
#define SELF_PS4_MAGIC 0x1D3D154F
#define SELF_PS5_MAGIC 0xEEF51454
/**
* Data structure for PS4 and PS5 SELF file headers.
**/
typedef struct self_head {
uint32_t magic;
uint8_t version;
uint8_t mode;
uint8_t endian;
uint8_t attrs;
uint32_t key_type;
uint16_t header_size;
uint16_t meta_size;
uint64_t file_size;
uint16_t num_entries;
uint16_t flags;
} self_head_t;
/**
* Data structure present in PS4 and PS5 SELF files that encodes additional
* information about segments in the embedded ELF file.
**/
typedef struct self_entry {
struct __attribute__((packed)) {
uint8_t is_ordered: 1;
uint8_t is_encrypted: 1;
uint8_t is_signed: 1;
uint8_t is_compressed: 1;
uint8_t unknown0 : 4;
uint8_t window_bits : 3;
uint8_t has_blocks : 1;
uint8_t block_bits : 4;
uint8_t has_digest : 1;
uint8_t has_extents : 1;
uint8_t unknown1 : 2;
uint16_t segment_index : 16;
uint32_t unknown2 : 28;
} props;
uint64_t offset;
uint64_t enc_size;
uint64_t dec_size;
} self_entry_t;
/**
* Data structure that captures extended information associated with an ELF file.
**/
typedef struct self_exinfo {
uint64_t authid;
uint64_t type;
uint64_t app_version;
uint64_t fw_version;
uint8_t digest[0x20];
} self_exinfo_t;
/**
*
**/
void* self_map_segment(int fd, const Elf64_Phdr *phdr, size_t ind);
/**
* Extract the ELF embedded within the given SELF.
**/
int self_extract_elf(int self_fd, int elf_fd);
/**
* Check if the given path is a SELF file.
**/
int self_is_valid(const char* path);
/**
* Compute the size of the ELF file embedded within the given SELF file.
**/
size_t self_get_elfsize(const char* path);