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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
use crate::eabi::i5;
use core::ffi::c_void;
pub const SYSTEM_REGISTRY: [u8; 7] = *b"/system";
pub const REG_KEYNAME_SIZE: u32 = 27;
/// Typedef for a registry handle.
#[repr(transparent)]
pub struct RegistryHandle(u32);
/// Struct used to open a registry.
#[repr(C)]
#[derive(Copy, Clone)]
pub struct RegistryKey {
pub key_type: KeyType,
/// Seemingly never used, set to `SYSTEM_REGISTRY`.
pub name: [u8; 256usize],
/// Length of the name.
pub name_len: u32,
/// Unknown, set to 1.
pub unk2: u32,
/// Unknown, set to 1.
pub unk3: u32,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum KeyType {
/// Key is a directory
Directory = 1,
/// Key is an integer (4 bytes)
Integer = 2,
/// Key is a string
String = 3,
/// Key is a binary string
Bytes = 4,
}
psp_extern! {
#![name = "sceReg"]
#![flags = 0x4001]
#![version = (0x00, 0x00)]
#[psp(0x92E41280)]
/// Open the registry
///
/// # Parameters
///
/// - `reg`: A filled in `Key` structure
/// - `mode`: Open mode (set to 1)
/// - `handle`: Pointer to a `Handle` to receive the registry handle
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegOpenRegistry(
reg: *mut RegistryKey,
mode: i32,
handle: *mut RegistryHandle,
) -> i32;
#[psp(0x39461B4D)]
/// Flush the registry to disk
///
/// # Parameters
///
/// - `handle`: The open registry handle
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegFlushRegistry(handle: RegistryHandle) -> i32;
#[psp(0xFA8A5739)]
/// Close the registry
///
/// # Parameters
///
/// - `handle`: The open registry handle
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegCloseRegistry(handle: RegistryHandle) -> i32;
#[psp(0x1D8A762E)]
/// Open a registry directory
///
/// # Parameters
///
/// - `handle`: The open registry handle
/// - `name`: The path to the dir to open (e.g. `/CONFIG/SYSTEM`)
/// - `mode`: Open mode (can be 1 or 2, probably read or read/write)
/// - `dir_handle`: Pointer to a `Handle` to receive the registry dir handle
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegOpenCategory(
handle: RegistryHandle,
name: *const u8,
mode: i32,
dir_handle: *mut RegistryHandle,
) -> i32;
#[psp(0x4CA16893)]
/// Remove a registry dir
///
/// # Parameters
///
/// - `handle`: The open registry dir handle
/// - `name`: The name of the key
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegRemoveCategory(
handle: RegistryHandle,
name: *const u8,
) -> i32;
#[psp(0x0CAE832B)]
/// Close the registry directory
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegCloseCategory(dir_handle: RegistryHandle) -> i32;
#[psp(0x0D69BF40)]
/// Flush the registry directory to disk
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegFlushCategory(dir_handle: RegistryHandle) -> i32;
#[psp(0xD4475AA8, i5)]
/// Get a key's information
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
/// - `name`: Name of the key
/// - `key_handle`: Pointer to a `Handle` to get registry key handle (used in `sceRegGetKeyValue`)
/// - `type_`: Type of the key
/// - `size`: The size of the key's value in bytes
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegGetKeyInfo(
dir_handle: RegistryHandle,
name: *const u8,
key_handle: *mut RegistryHandle,
type_: *mut KeyType,
size: *mut usize,
) -> i32;
#[psp(0xC5768D02)]
/// Get a key's information by name
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
/// - `name`: Name of the key
/// - `type_`: Type of the key
/// - `size`: The size of the key's value in bytes
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegGetKeyInfoByName(
dir_handle: RegistryHandle,
name: *const u8,
type_: *mut KeyType,
size: *mut usize,
) -> i32;
#[psp(0x28A8E98A)]
/// Get a key's value
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
/// - `key_handle`: The open registry key handler (from `sceRegGetKeyInfo`)
/// - `buf`: Buffer to hold the value
/// - `size`: The size of the buffer
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegGetKeyValue(
dir_handle: RegistryHandle,
key_handle: RegistryHandle,
buf: *mut c_void,
size: usize,
) -> i32;
#[psp(0x30BE0259)]
/// Get a key's value by name
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
/// - `name`: The key name
/// - `buf`: Buffer to hold the value
/// - `size`: The size of the buffer
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegGetKeyValueByName(
dir_handle: RegistryHandle,
name: *const u8,
buf: *mut c_void,
size: usize,
) -> i32;
#[psp(0x17768E14)]
/// Set a key's value
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
/// - `name`: The key name
/// - `buf`: Buffer to hold the value
/// - `size`: The size of the buffer
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegSetKeyValue(
dir_handle: RegistryHandle,
name: *const u8,
buf: *const c_void,
size: usize,
) -> i32;
#[psp(0x2C0DB9DD)]
/// Get number of subkeys in the current dir
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
/// - `num`: Pointer to an integer to receive the number
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegGetKeysNum(
dir_handle: RegistryHandle,
num: *mut i32,
) -> i32;
#[psp(0x2D211135)]
/// Get the key names in the current directory
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
/// - `buf`: Buffer to hold the NUL terminated strings, should be of size `num * KEYNAME_SIZE`
/// - `num`: Number of elements in buf
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegGetKeys(
dir_handle: RegistryHandle,
buf: *mut u8,
num: i32,
) -> i32;
#[psp(0x57641A81)]
/// Create a key
///
/// # Parameters
///
/// - `dir_handle`: The open registry dir handle
/// - `name`: Name of the key to create
/// - `type_`: Type of key (note cannot be a directory type)
/// - `size`: Size of the allocated value space
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegCreateKey(
dir_handle: RegistryHandle,
name: *const u8,
type_: i32,
size: usize,
) -> i32;
#[psp(0xDEDA92BF)]
/// Remove a registry (HONESTLY, DO NOT USE)
///
/// # Parameters
///
/// - `key`: Filled out registry parameter
///
/// # Return Value
///
/// 0 on success, < 0 on error
pub fn sceRegRemoveRegistry(key: *mut RegistryKey) -> i32;
}