forked from balika011/prxtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disasm.h
101 lines (84 loc) · 2.74 KB
/
disasm.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
/***************************************************************
* PRXTool : Utility for PSP executables.
* (c) TyRaNiD 2k6
*
* disasm.h - Implementation of a MIPS disassembler
***************************************************************/
#ifndef __DISASM_H__
#define __DISASM_H__
#include <map>
#include <string>
#include <vector>
#include "prxtypes.h"
enum SymbolType
{
SYMBOL_NOSYM = 0,
SYMBOL_UNK,
SYMBOL_FUNC,
SYMBOL_LOCAL,
SYMBOL_DATA,
};
typedef std::vector<unsigned int> RefMap;
typedef std::vector<std::string> AliasMap;
struct SymbolEntry
{
unsigned int addr;
SymbolType type;
unsigned int size;
std::string name;
RefMap refs;
AliasMap alias;
std::vector<PspLibExport *> exported;
std::vector<PspLibImport *> imported;
};
typedef std::map<unsigned int, SymbolEntry*> SymbolMap;
struct ImmEntry
{
unsigned int addr;
unsigned int target;
/* Does this entry point to a text section ? */
int text;
};
typedef std::map<unsigned int, ImmEntry *> ImmMap;
#include <capstone/capstone.h>
struct DisasmEntry
{
cs_insn *insn;
};
typedef std::map<unsigned int, DisasmEntry *> DisasmMap;
#define DISASM_OPT_MAX 8
#define DISASM_OPT_HEXINTS 'x'
#define DISASM_OPT_MREGS 'r'
#define DISASM_OPT_SYMADDR 's'
#define DISASM_OPT_MACRO 'm'
#define DISASM_OPT_PRINTREAL 'p'
#define DISASM_OPT_PRINTREGS 'g'
#define DISASM_OPT_PRINTSWAP 'w'
#define DISASM_OPT_SIGNEDHEX 'd'
#define INSTR_TYPE_LOCAL 1
#define INSTR_TYPE_FUNC 2
void SetThumbMode(bool mode);
/* Enable hexadecimal integers for immediates */
void disasmSetHexInts(int hexints);
/* Enable mnemonic MIPS registers */
void disasmSetMRegs(int mregs);
/* Enable resolving of PC to a symbol if available */
void disasmSetSymAddr(int symaddr);
/* Enable instruction macros */
void disasmSetMacro(int macro);
void disasmSetPrintReal(int printreal);
void disasmSetOpts(const char *opts, int set);
const char *disasmGetOpts(void);
void disasmPrintOpts(void);
const char *disasmInstruction(unsigned int opcode, unsigned int *PC, unsigned int *realregs, unsigned int *regmask, int nothumb);
const char *disasmInstructionXML(unsigned int opcode, unsigned int PC);
void disasmSetSymbols(SymbolMap *syms);
void disasmAddBranchSymbols(unsigned int opcode, unsigned int *PC, SymbolMap &syms);
SymbolType disasmResolveSymbol(unsigned int PC, char *name, int namelen);
SymbolEntry* disasmFindSymbol(unsigned int PC);
int disasmIsBranch(unsigned int opcode, unsigned int PC, unsigned int *dwTarget);
void disasmSetXmlOutput();
int disasmAddStringRef(unsigned int opcode, unsigned int base, unsigned int size, unsigned int PC, ImmMap &imms, SymbolMap &syms, int data_addr, u32 data_base, u32 data_base_size);
void resetMovwMovt();
void loadDisasm(const uint8_t *code, size_t code_size, uint64_t address);
#endif