-
Notifications
You must be signed in to change notification settings - Fork 0
/
prx.h
224 lines (176 loc) · 4.23 KB
/
prx.h
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
/**
* Author: Humberto Naves (hsnaves@gmail.com)
*/
#ifndef __PRX_H
#define __PRX_H
#include "types.h"
#include "nids.h"
#define ELF_HEADER_IDENT 16
#define ELF_PRX_TYPE 0xFFA0
#define ELF_MACHINE_MIPS 8
#define ELF_VERSION_CURRENT 1
#define ELF_FLAGS_MACH_ALLEGREX 0x00A20000
#define ELF_FLAGS_ABI_EABI32 0x00003000
#define ELF_FLAGS_MIPS_ARCH2 0x10000000
/* Structure to hold prx header data */
struct prx
{
uint8 ident[ELF_HEADER_IDENT];
uint16 type;
uint16 machine;
uint32 version;
uint32 entry;
uint32 phoff;
uint32 shoff;
uint32 flags;
uint16 ehsize;
uint16 phentsize;
uint16 phnum;
uint16 shentsize;
uint16 shnum;
uint16 shstrndx;
uint32 size;
const uint8 *data;
struct elf_section *sections;
struct elf_program *programs;
uint32 relocnum;
struct prx_reloc *relocs;
struct prx_reloc *relocsbyaddr;
struct prx_modinfo *modinfo;
};
#define SHT_NULL 0
#define SHT_PROGBITS 1
#define SHT_STRTAB 3
#define SHT_NOBITS 8
#define SHT_LOPROC 0x70000000
#define SHT_HIPROC 0x7fffffff
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xffffffff
#define SHT_PRXRELOC (SHT_LOPROC | 0xA0)
#define SHF_WRITE 1
#define SHF_ALLOC 2
#define SHF_EXECINSTR 4
/* Structure defining a single elf section */
struct elf_section
{
uint32 idxname;
uint32 type;
uint32 flags;
uint32 addr;
uint32 offset;
uint32 size;
uint32 link;
uint32 info;
uint32 addralign;
uint32 entsize;
const uint8 *data;
const char *name;
};
#define PT_NULL 0
#define PT_LOAD 1
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7fffffff
#define PT_PRXRELOC (PT_LOPROC | 0xA0)
#define PT_PRXRELOC2 (PT_LOPROC | 0xA1)
#define PF_X 1
#define PF_W 2
#define PF_R 4
struct elf_program
{
uint32 type;
uint32 offset;
uint32 vaddr;
uint32 paddr;
uint32 filesz;
uint32 memsz;
uint32 flags;
uint32 align;
const uint8 *data;
};
/* MIPS Reloc Entry Types */
#define R_MIPS_NONE 0
#define R_MIPS_16 1
#define R_MIPS_32 2
#define R_MIPS_26 4
#define R_MIPS_HI16 5
#define R_MIPS_LO16 6
#define R_MIPSX_HI16 13
#define R_MIPSX_J26 14
#define R_MIPSX_JAL26 15
struct prx_reloc {
uint32 offset;
uint8 type;
uint8 offsbase;
uint8 addrbase;
uint8 extra;
uint32 addend;
uint32 vaddr;
uint32 target;
};
struct prx_modinfo {
uint16 attributes;
uint16 version;
uint32 gp;
uint32 expvaddr;
uint32 expvaddrbtm;
uint32 impvaddr;
uint32 impvaddrbtm;
uint32 numimports;
uint32 numexports;
struct prx_import *imports;
struct prx_export *exports;
const char *name;
};
struct prx_import {
uint32 namevaddr;
uint32 flags;
uint8 size;
uint8 nvars;
uint16 nfuncs;
uint32 nidsvaddr;
uint32 funcsvaddr;
uint32 varsvaddr;
struct prx_function *funcs;
struct prx_variable *vars;
const char *name;
};
struct prx_export {
uint32 namevaddr;
uint32 flags;
uint8 size;
uint8 nvars;
uint16 nfuncs;
uint32 expvaddr;
struct prx_function *funcs;
struct prx_variable *vars;
const char *name;
};
struct prx_function {
uint32 vaddr;
uint32 nid;
const char *name;
const char *libname;
void *pfunc;
int numargs;
};
struct prx_variable {
uint32 vaddr;
uint32 nid;
const char *name;
const char *libname;
};
uint32 read_uint32_le (const uint8 *bytes);
uint16 read_uint16_le (const uint8 *bytes);
void write_uint32_le (uint8 *bytes, uint32 val);
struct prx *prx_load (const char *path);
void prx_free (struct prx *p);
void prx_print (struct prx *p, int prtrelocs);
void prx_resolve_nids (struct prx *p, struct nidstable *nids);
uint32 prx_translate (struct prx *p, uint32 vaddr);
int prx_inside_prx (struct prx *p, uint32 offset, uint32 size);
int prx_inside_progfile (struct elf_program *program, uint32 vaddr, uint32 size);
int prx_inside_progmem (struct elf_program *program, uint32 vaddr, uint32 size);
int prx_inside_strprogfile (struct elf_program *program, uint32 vaddr);
uint32 prx_findreloc (struct prx *p, uint32 target);
uint32 prx_findrelocbyaddr (struct prx *p, uint32 vaddr);
#endif /* __PRX_H */