forked from pspdev/prxtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NidMgr.h
100 lines (89 loc) · 2.84 KB
/
NidMgr.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
/***************************************************************
* PRXTool : Utility for PSP executables.
* (c) TyRaNiD 2k5
*
* NidMgr.h - Definition of a class to manipulate a list
* of NID Libraries.
***************************************************************/
#ifndef __NIDMGR_H__
#define __NIDMGR_H__
#include "types.h"
#include <tinyxml/tinyxml.h>
#include <vector>
#define LIB_NAME_MAX 64
#define LIB_SYMBOL_NAME_MAX 128
#define FUNCTION_NAME_MAX 128
#define FUNCTION_ARGS_MAX 128
#define FUNCTION_RET_MAX 64
struct LibraryEntry;
/** Structure to hold a single library nid */
struct LibraryNid
{
/** The NID value for this symbol */
u32 nid;
/** The name of the symbol */
char name[LIB_SYMBOL_NAME_MAX];
/** The parent library */
struct LibraryEntry *pParentLib;
};
/** Structure to hold a single function entry */
struct FunctionType
{
char name[FUNCTION_NAME_MAX];
char args[FUNCTION_ARGS_MAX];
char ret[FUNCTION_RET_MAX];
};
/** Structure to hold a single library entry */
struct LibraryEntry
{
/** Pointer to the next library in the chain */
struct LibraryEntry* pNext;
/** The PRX name (i.e. module name) of the file containing this lib */
char prx_name[LIB_NAME_MAX];
/** The name of the library */
char lib_name[LIB_NAME_MAX];
/** The filename of the module containing this lib (for dependancies) */
char prx[MAXPATH];
/** The flags as defined in the export */
int flags;
/** The number of entries in the NID list */
int entry_count;
/** The number of variable NIDs in the list */
int vcount;
/** The number of function NIDs in the list */
int fcount;
/** A pointer to a list of NIDs */
LibraryNid *pNids;
};
/** Class to load and manage a list of libraries */
class CNidMgr
{
typedef std::vector<FunctionType *> FunctionVect;
/** Head pointer to the list of libraries */
LibraryEntry *m_pLibHead;
/** Mapping of function names to prototypes */
FunctionVect m_funcMap;
/** A buffer to store a pre-generated symbol name so it can be passed to the caller */
char m_szCurrName[LIB_SYMBOL_NAME_MAX];
/** Indicator that we have loaded a master NID file */
LibraryEntry *m_pMasterNids;
/** Generate a name */
const char *GenName(const char *lib, u32 nid);
/** Search the loaded libs for a symbol */
const char *SearchLibs(const char *lib, u32 nid);
void FreeMemory();
const char* ReadNid(TiXmlElement *pElement, u32 &nid);
int CountNids(TiXmlElement *pElement, const char *name);
void ProcessLibrary(TiXmlElement *pLibrary, const char *prx_name, const char *prx);
void ProcessPrxfile(TiXmlElement *pPrxfile);
public:
CNidMgr();
~CNidMgr();
const char *FindLibName(const char *lib, u32 nid);
const char *FindDependancy(const char *lib);
bool AddXmlFile(const char *szFilename);
LibraryEntry *GetLibraries(void);
bool AddFunctionFile(const char *szFilename);
FunctionType *FindFunctionType(const char *name);
};
#endif