summaryrefslogtreecommitdiffstats
path: root/src/cv2pdb.h
blob: e132e9522d74557fbc6524cd5d24b236039ea229 (plain)
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
// Convert DMD CodeView debug information to PDB files

// Copyright (c) 2009 by Rainer Schuetze, All Rights Reserved

//

// License for redistribution is given by the Artistic License 2.0

// see file LICENSE for further details


#ifndef __CV2PDB_H__

#define __CV2PDB_H__


#include "LastError.h"

#include "mspdb.h"


#include <windows.h>


extern "C" {
#include "mscvpdb.h"

}

class PEImage;

class CV2PDB : public LastError
{
public:
	CV2PDB(PEImage& image);
	~CV2PDB();

	bool cleanup(bool commit);
	bool openPDB(const char* pdbname);

	bool setError(const char* msg);
	bool createModules();

	bool initLibraries();
	const BYTE* getLibrary(int i);
	bool initSegMap();

	int addFields(codeview_reftype* dfieldlist, const codeview_reftype* fieldlist, int maxdlen);

	int addAggregate(codeview_type* dtype, bool clss, int n_element, int fieldlist, int property, 
	                 int derived, int vshape, int structlen, const char*name);
	int addClass(codeview_type* dtype, int n_element, int fieldlist, int property, 
	                                   int derived, int vshape, int structlen, const char*name);
	int addStruct(codeview_type* dtype, int n_element, int fieldlist, int property, 
	                                    int derived, int vshape, int structlen, const char*name);

	int addPointerType(codeview_type* dtype, int type, int attr = 0x800A);
	int addPointerType(unsigned char* dtype, int type, int attr = 0x800A);

	int addFieldMember(codeview_fieldtype* dfieldtype, int attr, int offset, int type, const char* name);
	int addFieldStaticMember(codeview_fieldtype* dfieldtype, int attr, int type, const char* name);
	int addFieldNestedType(codeview_fieldtype* dfieldtype, int type, const char* name);

	void checkUserTypeAlloc(int size = 1000, int add = 10000);

	const codeview_type* getTypeData(int type);
	const codeview_type* getUserTypeData(int type);
	const codeview_type* findCompleteClassType(const codeview_type* cvtype);

	int findMemberFunctionType(codeview_symbol* lastGProcSym, int thisPtrType);

	int sizeofClassType(const codeview_type* cvtype);
	int sizeofBasicType(int type);
	int sizeofType(int type);

	// to be used when writing new type only to avoid double translation

	int translateType(int type);

	bool nameOfBasicType(int type, char* name, int maxlen);
	bool nameOfType(int type, char* name, int maxlen);
	bool nameOfDynamicArray(int indexType, int elemType, char* name, int maxlen);
	bool nameOfAssocArray(int indexType, int elemType, char* name, int maxlen);
	bool nameOfDelegate(int thisType, int funcType, char* name, int maxlen);
	bool nameOfOEMType(codeview_oem_type* oem, char* name, int maxlen);
	bool nameOfModifierType(int type, int mod, char* name, int maxlen);

	int numeric_leaf(int* value, const void* leaf);
	int copy_leaf(unsigned char* dp, int& dpos, const unsigned char* p, int& pos);

	const char* appendDynamicArray(int indexType, int elemType);
	const char* appendAssocArray(int keyType, int elemType);
	const char* appendDelegate(int thisType, int funcType);
	int appendObjectType (int object_derived_type);
	int appendPointerType(int pointedType, int attr);

	bool initGlobalTypes();
	bool initGlobalSymbols();

	bool addTypes();
	bool addSrcLines();
	bool addPublics();

	bool addUdtSymbol(int type, const char* name);

	// returns new destSize

	int copySymbols(BYTE* srcSymbols, int srcSize, BYTE* destSymbols, int destSize);

	bool writeSymbols(mspdb::Mod* mod, DWORD* data, int databytes, int prefix, bool addGlobals);
	bool addSymbols(mspdb::Mod* mod, BYTE* symbols, int cb, bool addGlobals);
	bool addSymbols(int iMod, BYTE* symbols, int cb, bool addGlobals);
	bool addSymbols();

	bool writeImage(const char* opath);

	mspdb::Mod* globalMod();

// private:

	BYTE* libraries;

	PEImage& img;

	mspdb::PDB* pdb;
	mspdb::DBI *dbi;
	mspdb::TPI *tpi;

	mspdb::Mod** modules;
	mspdb::Mod* globmod;
	int countEntries;

	OMFSignatureRSDS* rsds;

	OMFSegMap* segMap;
	OMFSegMapDesc* segMapDesc;
	OMFGlobalTypes* globalTypeHeader;

	unsigned char* globalTypes;
	int cbGlobalTypes;
	int allocGlobalTypes;

	unsigned char* userTypes;
	int* pointerTypes;
	int cbUserTypes;
	int allocUserTypes;

	unsigned char* globalSymbols;
	int cbGlobalSymbols;

	unsigned char* staticSymbols;
	int cbStaticSymbols;

	unsigned char* udtSymbols;
	int cbUdtSymbols;
	int allocUdtSymbols;

	int nextUserType;
	int objectType;

	bool useGlobalMod;
	bool thisIsNotRef;
	bool v3;
	const char* lastError;

	double Dversion;
};


#endif //__CV2PDB_H__