forked from HYLcool/ourspike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.h
145 lines (117 loc) · 2.26 KB
/
loader.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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
typedef long long int lli;
typedef short int si;
#define VIRMEM_OFFSET 0x10000
#define MAX_SIZE 0x80000
class ElfHead{
public:
ElfHead(){};
~ElfHead(){};
lli getPhos(){return phoffset;};
lli getShos(){return shoffset;};
lli getPhsiz(){return ph_siz;};
lli getShsiz(){return sh_siz;};
lli getEntryAddr() {return entryaddr;}
private:
char Magic[16];
lli other_info;
lli entryaddr;
lli phoffset;
lli shoffset;
int flags;
si eh_siz;
si ph_siz;
si ph_cnt;
si sh_siz;
si sh_cnt;
si str_index;
};
class ProgramHead{
public:
ProgramHead(){};
~ProgramHead(){};
lli getOs(){return offset;};
lli getFs(){return FileSiz;};
lli getMs(){return MemSiz;};
private:
lli type;
lli offset;
lli Virtaddr;
lli Physaddr;
lli FileSiz;
lli MemSiz;
lli Flag_Align;
};
class SegmentHead{
public:
SegmentHead(){};
~SegmentHead(){};
lli getAddr(){return Address;};
lli getSize(){return size;};
private:
int index;
int type;
lli flag;
lli Address;
lli fioffset;
lli size;
lli Link_info;
lli align;
lli entsize;
};
//A data instruction to simulate main memory.
class Memory{
public:
Memory(){Mem = new char[MAX_SIZE + VIRMEM_OFFSET];};
~Memory(){ delete Mem; };
void initial(int beginAd, int size){};
void readMem(int situation, char* p, int size)
{
for(int i = 0; i < size; i++)
{
*(p + i) = Mem[situation + i];
}
};
void writeMem(int situation, char* p, int size)
{
for(int i = 0; i < size; i++)
{
Mem[situation + i] = *(p + i);
}
}
void MyPrint()
{
for(int i = 0; i < MAX_SIZE; i++)
{
if (i % 4 == 0)
cout << endl;
if (Mem[i] >= 32 && Mem[i] <= 126)
cout << Mem[i] << " ";
else
cout << (int)(unsigned char)Mem[i] << " ";
}
}
void setsize(int s){Memsiz = s;};
char * getMemAdd() {return Mem;}
private:
char *Mem;
int Memsiz;
};
class Loadelf{
public:
Loadelf(Memory * mem){
Mem = mem;
};
~Loadelf(){};
void Load_file(string);
private:
ifstream file;
char *tmp;
ElfHead *ElfH;
ProgramHead *ProH;
SegmentHead *SegH;
Memory *Mem;
};