summaryrefslogtreecommitdiff
path: root/other/Kermit/lib
diff options
context:
space:
mode:
authorRoot THC2026-02-24 12:42:47 +0000
committerRoot THC2026-02-24 12:42:47 +0000
commitc9cbeced5b3f2bdd7407e29c0811e65954132540 (patch)
treeaefc355416b561111819de159ccbd86c3004cf88 /other/Kermit/lib
parent073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff)
initial
Diffstat (limited to 'other/Kermit/lib')
-rw-r--r--other/Kermit/lib/DevMemPatt.cpp122
-rw-r--r--other/Kermit/lib/DevMemPatt.obin0 -> 3548 bytes
-rw-r--r--other/Kermit/lib/Makefile16
-rw-r--r--other/Kermit/lib/Patch.cpp502
-rw-r--r--other/Kermit/lib/Patch.obin0 -> 50712 bytes
-rw-r--r--other/Kermit/lib/SymbolFingp.cpp108
-rw-r--r--other/Kermit/lib/SymbolTable.cpp205
-rw-r--r--other/Kermit/lib/SystemMap.cpp67
-rw-r--r--other/Kermit/lib/itos16.cpp36
-rw-r--r--other/Kermit/lib/name2add.c46
-rw-r--r--other/Kermit/lib/name2add.obin0 -> 1128 bytes
-rw-r--r--other/Kermit/lib/rwKernel.cpp107
-rw-r--r--other/Kermit/lib/stoi16.cpp29
13 files changed, 1238 insertions, 0 deletions
diff --git a/other/Kermit/lib/DevMemPatt.cpp b/other/Kermit/lib/DevMemPatt.cpp
new file mode 100644
index 0000000..81fd6e9
--- /dev/null
+++ b/other/Kermit/lib/DevMemPatt.cpp
@@ -0,0 +1,122 @@
1/*
2 * DevMemPatt.cpp:
3 * written by palmers / teso
4 */
5#include <DevMemPatt.hpp>
6
7
8 DevMemPatt::DevMemPatt ()
9 {
10 rw = new rwKernel ();
11 }
12
13
14 DevMemPatt::DevMemPatt (rwKernel *a)
15 {
16 rw = a;
17 }
18
19
20 DevMemPatt::~DevMemPatt ()
21 {
22 }
23
24
25 int DevMemPatt::compare_data_snippet (unsigned char *x, struct sfp *y)
26 {
27 bool i = false;
28 int ret = -1;
29 short a = 0,
30 b = 0;
31
32 while ((b < y->length) && (a < READ_BUFF_SIZE))
33 {
34 if ((x[a] == y->fp[b].val) || (y->fp[b].type == WWCARD))
35 {
36 if (i == false)
37 {
38 i = true;
39 ret = a;
40 }
41 b++;
42 }
43 else if (i == true)
44 {
45 i = false;
46 ret = -1;
47 b = 0;
48 }
49 a++;
50 }
51 return ret;
52 }
53
54
55 unsigned int DevMemPatt::find_patt (unsigned int s, \
56 unsigned int e, unsigned short l, unsigned char *snipp)
57 {
58 bool i = false;
59 int ret = -1;
60 unsigned short a = 0,
61 b = 0;
62 unsigned char *readBuff = NULL;
63
64 readBuff = new unsigned char[READ_BUFF_SIZE];
65
66 while (s < e)
67 {
68 rw->read (readBuff, READ_BUFF_SIZE, s);
69 while ((b < l) && (a < READ_BUFF_SIZE))
70 {
71 if (readBuff[a] == snipp[b])
72 {
73 if (i == false)
74 {
75 i = true;
76 ret = a;
77 }
78 b++;
79 }
80 else if (i == true)
81 {
82 i = false;
83 ret = -1;
84 b = 0;
85 }
86 a++;
87 }
88 if (ret != -1)
89 {
90 if (ret == 0)
91 return s;
92 s = s + ret - READ_BUFF_SIZE;
93 }
94 s += READ_BUFF_SIZE;
95 }
96 return 0;
97 }
98
99
100 unsigned int DevMemPatt::find_patt (struct sfp *a)
101 {
102 int x = -1;
103 unsigned int s = a->start_addr,
104 e = a->stop_addr;
105 unsigned char *readBuff = NULL;
106
107 readBuff = new unsigned char[READ_BUFF_SIZE];
108
109 while (s < e)
110 {
111 rw->read (readBuff, READ_BUFF_SIZE, s);
112 if ((x = compare_data_snippet (readBuff, a)) != -1)
113 {
114 if (x == 0)
115 return s;
116 s = s + x - READ_BUFF_SIZE;
117 }
118 s += READ_BUFF_SIZE;
119 }
120 return 0;
121 }
122
diff --git a/other/Kermit/lib/DevMemPatt.o b/other/Kermit/lib/DevMemPatt.o
new file mode 100644
index 0000000..196bdfd
--- /dev/null
+++ b/other/Kermit/lib/DevMemPatt.o
Binary files differ
diff --git a/other/Kermit/lib/Makefile b/other/Kermit/lib/Makefile
new file mode 100644
index 0000000..6d1a1a8
--- /dev/null
+++ b/other/Kermit/lib/Makefile
@@ -0,0 +1,16 @@
1# written by palmers / teso
2include ../MakeOpt
3
4OBJECTS = name2add.o Patch.o DevMemPatt.o SymbolTable.o SystemMap.o \
5 stoi16.o itos16.o rwKernel.o SymbolFingp.o
6
7
8all: $(OBJECTS) libs
9
10libs:
11 $(AR) $(ARFLAGS) $(AR_OUT) $(OBJECTS)
12 $(CXX) $(CXXFLAGS) -shared -o $(SHARE_OUT) $(OBJECTS)
13
14clean:
15 rm -rf *.o name2add.c $(SHARE_OUT) $(AR_OUT)
16
diff --git a/other/Kermit/lib/Patch.cpp b/other/Kermit/lib/Patch.cpp
new file mode 100644
index 0000000..b72f860
--- /dev/null
+++ b/other/Kermit/lib/Patch.cpp
@@ -0,0 +1,502 @@
1/*
2 * Patch.cpp:
3 * written by palmers / teso
4 */
5#include <Patch.hpp>
6
7SystemMap DummyValMap;
8
9/*
10 * helper class
11 */
12class replaceAddr
13{
14private:
15 unsigned char *data;
16 unsigned short len;
17
18public:
19 replaceAddr (unsigned char *a, unsigned short x)
20 {
21 data = a;
22 len = x;
23 }
24
25 void operator() (Addr2Addr *a)
26 {
27 unsigned short x = 0;
28 unsigned char *b = NULL,
29 *c = NULL;
30
31 b = (unsigned char *) &a->first;
32 c = (unsigned char *) &a->second;
33
34 for (x = 0; x <= (len - 3); x++)
35 {
36 if (b[0] == data[x])
37 {
38 if ((b[1] == data[x + 1]) && \
39 (b[2] == data[x + 2]) && \
40 (b[3] == data[x + 3]))
41 {
42 data[x] = c[0];
43 data[x + 1] = c[1];
44 data[x + 2] = c[2];
45 data[x + 3] = c[3];
46 }
47 }
48 }
49 }
50};
51
52
53/*
54 * member functions
55 */
56 string Patch::state2string ()
57 {
58 string ret;
59
60 switch (state)
61 {
62 case CLEAN:
63 ret = "Clean";
64 break;
65 case LINKED:
66 ret = "Linked";
67 break;
68 case APPLIED:
69 ret = "Applied";
70 break;
71 case AFAILED:
72 ret = "ApplyFailed";
73 break;
74 case LFAILED:
75 ret = "LinkFailed";
76 break;
77 default:
78 ret = "Unknown";
79 break;
80 }
81 return ret;
82 }
83
84
85 void Patch::string2state (string a)
86 {
87 if (a == "Clean")
88 state = CLEAN;
89 else if (a == "Linked")
90 state = LINKED;
91 else if (a == "Applied")
92 state = APPLIED;
93 else if (a == "ApplyFailed")
94 state = AFAILED;
95 else if (a == "LinkFailed")
96 state = LFAILED;
97 else if (a == "Unknown")
98 abort ();
99 }
100
101
102 string Patch::data2string (unsigned char *a)
103 {
104 string ret;
105 int x;
106
107 ret = itos16 ((unsigned int) a[0]);
108 for (x = 1; x < len; x++)
109 {
110 ret += ' ';
111 ret += itos16 ((unsigned int) a[x]);
112 }
113
114 return ret;
115 }
116
117
118 void Patch::string2data (string s, unsigned char *d)
119 {
120 string tmp;
121 unsigned short x,
122 y;
123
124 for (x = 0; x < (len - 1); x++)
125 {
126 y = s.find_first_of (" ");
127 tmp.resize (y);
128 s.copy (tmp.begin (), y);
129 s.erase (0, y + 1);
130 d[x] = (unsigned char) stoi16 (tmp) & 0xff;
131 tmp.erase ();
132 }
133 tmp.resize (s.length ());
134 s.copy (tmp.begin (), s.length ());
135 d[x] = (unsigned char) stoi16 (tmp) & 0xff;
136 }
137
138
139 bool Patch::initObjects (unsigned char *d, unsigned short l, unsigned int add, rwKernel *x)
140 {
141 len = l;
142 address = add;
143 local_rw = x;
144
145 data = new unsigned char[len];
146 back_data = new unsigned char[len];
147 overwr = new unsigned char[len];
148
149 copy (d, d + len, data);
150 copy (d, d + len, back_data);
151 state = CLEAN;
152 return true;
153 }
154
155
156 void Patch::parse (string s)
157 {
158 unsigned char *a = NULL;
159 string tmp;
160 int x = 0;
161
162 x = s.find_first_of (",");
163 tmp.resize (x);
164 s.copy (tmp.begin (), x);
165 s.erase (0, x + 1);
166
167 address = stoi16 (tmp);
168 tmp.erase ();
169
170 x = s.find_first_of (":");
171 tmp.resize (x);
172 s.copy (tmp.begin (), x);
173 s.erase (0, x + 1);
174
175 string2state (tmp);
176 tmp.erase ();
177
178 x = s.find_first_of ("(");
179 s.erase (0, x + 1);
180
181 x = s.find_first_of (")");
182 tmp.resize (x);
183 s.copy (tmp.begin (), x);
184 len = count (tmp.begin (), tmp.end (), ' ') + 1;
185
186 data = new unsigned char[len];
187 back_data = new unsigned char[len];
188 overwr = new unsigned char[len];
189
190 string2data (tmp, data);
191 tmp.erase ();
192
193 if (state == CLEAN)
194 return;
195
196 switch (state)
197 {
198 case LINKED:
199 case LFAILED:
200 a = back_data;
201 break;
202 case APPLIED:
203 case AFAILED:
204 a = overwr;
205 break;
206 }
207
208 x = s.find_first_of ("(");
209 s.erase (0, x + 1);
210
211 x = s.find_first_of (")");
212 tmp.resize (x);
213 s.copy (tmp.begin (), x);
214
215 string2data (tmp, a);
216 }
217
218
219 Patch::Patch ()
220 {
221 }
222
223
224 Patch::Patch (unsigned char *d, unsigned short l, unsigned int add)
225 {
226 initObjects (d, l, add, NULL);
227 }
228
229
230 Patch::Patch (unsigned char *d, unsigned short l, unsigned int add, rwKernel *x)
231 {
232 initObjects (d, l, add, x);
233 }
234
235
236 Patch::Patch (string s)
237 {
238 parse (s);
239 }
240
241
242 Patch::Patch (string s, rwKernel *rw)
243 {
244 parse (s);
245 local_rw = rw;
246 }
247
248
249 Patch::~Patch ()
250 {
251 delete data;
252 delete back_data;
253 delete overwr;
254 }
255
256
257 void Patch::initFromString (string a)
258 {
259 parse (a);
260 }
261
262
263 string Patch::getPatchAsString ()
264 {
265 unsigned char *a = NULL;
266 string b;
267
268 switch (state)
269 {
270 case LINKED:
271 case LFAILED:
272 a = back_data;
273 break;
274 case APPLIED:
275 case AFAILED:
276 a = overwr;
277 break;
278 }
279
280 b = itos16 (address) + ',' + state2string () + ": (" + data2string (data) + ')';
281 if (a != NULL)
282 b += ", (" + data2string (a) + ')';
283 b += '\n';
284 return b;
285 }
286
287
288 bool Patch::isLinked ()
289 {
290 return (state & LINKED);
291 }
292
293
294 bool Patch::wasChanged ()
295 {
296 int x;
297
298 for (x = 0; x < len; x++)
299 if (data[x] != back_data[x])
300 return true;
301 return false;
302 }
303
304
305 bool Patch::isApplied ()
306 {
307 return (state & APPLIED);
308 }
309
310
311 bool Patch::isClean ()
312 {
313 return (state & CLEAN);
314 }
315
316
317 bool Patch::isFailed ()
318 {
319 return (state & AFAILED) || (state & LFAILED);
320 }
321
322
323 int Patch::getState ()
324 {
325 return state;
326 }
327
328
329 void Patch::restore ()
330 {
331 copy (back_data, back_data + len, data);
332 state = CLEAN;
333 }
334
335
336 bool Patch::remove (rwKernel *rw)
337 {
338 if (state != APPLIED)
339 return false;
340
341 rw->write (overwr, len, address);
342 return true;
343 }
344
345
346 bool Patch::remove ()
347 {
348 if (local_rw == NULL)
349 return false;
350 if (state != APPLIED)
351 return false;
352
353 local_rw->write (overwr, len, address);
354 return true;
355 }
356
357
358 unsigned char *Patch::getData ()
359 {
360 return data;
361 }
362
363
364 void Patch::apply (rwKernel *rw)
365 {
366/* pretty simple :) */
367 rw->read (overwr, len, address);
368 rw->write (data, len, address);
369 state = APPLIED;
370 }
371
372
373 void Patch::apply ()
374 {
375 if (local_rw == NULL)
376 {
377 state = AFAILED;
378 return;
379 }
380 local_rw->read (overwr, len, address);
381 local_rw->write (data, len, address);
382 state = APPLIED;
383 }
384
385
386 void Patch::link (Addr2AddrList *a2a)
387 {
388 replaceAddr x (data, len);
389 int y = a2a->size ();
390 Addr2AddrList::iterator z = a2a->begin ();
391 Addr2Addr *t = NULL;
392
393/* XXX: why doesnt for_each work with pointer to list???
394 * its the same problem with for "(x = a2a->begin (); x != a2a->end (); ..."
395 * the x != end (); just f#$§ true!
396 */
397 while (y--)
398 {
399 t = *z;
400 x (t);
401 z++;
402 }
403 state = LINKED;
404 }
405
406
407 void Patch::dump (string file)
408 {
409 unsigned char *a = NULL;
410/*
411 * dump file format:
412 * <Address>,<State>: (<data, hex, byte wise>){, (<other data, hex, byte wise>)}\n
413 * where the data in the curled brackets in depending on the state:
414 * state: data in the curled bbrackets:
415 * clean none
416 * applied overwr
417 * afailed overwr
418 * linked back_date
419 * lfailed back_data
420 */
421 ofstream f;
422
423 switch (state)
424 {
425 case LINKED:
426 case LFAILED:
427 a = back_data;
428 break;
429 case APPLIED:
430 case AFAILED:
431 a = overwr;
432 break;
433 }
434
435 f.open (file.c_str (), ios::ate | ios::app);
436
437 f.setf (ios::hex, ios::basefield);
438 f << address << ',' << state2string () << ':' << ' ';
439 f << '(' << data2string (data) << ')';
440 if (a != NULL)
441 f << ',' << ' ' << '(' << data2string (a) << ')';
442 f << endl;
443 f.setf (ios::dec, ios::basefield);
444 }
445
446
447 istream& operator>> (istream& is, Patch& p)
448 {
449 string tmp;
450
451 getline (is, tmp, '\n');
452 p.initFromString (tmp);
453 return is;
454 }
455
456
457 ostream& operator<< (ostream& os, Patch& p)
458 {
459 os << p.getPatchAsString ();
460 return os;
461 }
462
463
464/*
465 * unrelated functions ....
466 */
467 Addr2AddrList *genReplaceValMap (SymbolTable *st)
468 {
469 zzSymList::iterator x;
470 Addr2Addr *y = NULL;
471 zzSym *z = NULL;
472 Addr2AddrList *a2a = NULL;
473
474 a2a = new Addr2AddrList ();
475
476 /* get all symbol addressess together with dummy values */
477 for (x = st->symList.begin (); x != st->symList.end (); x++)
478 {
479 z = *x;
480 if (DummyValMap[z->Name] != 0)
481 {
482 y = new Addr2Addr ();
483 y->first = DummyValMap[z->Name];
484 y->second = z->Address;
485 a2a->push_back (y);
486 }
487 }
488 return a2a;
489 }
490
491
492 void genDummyValMap ()
493 {
494 int x = 0;
495
496 while (__n2a[x].name != NULL)
497 {
498 DummyValMap.add (string (__n2a[x].name), __n2a[x].add);
499 x++;
500 }
501 }
502
diff --git a/other/Kermit/lib/Patch.o b/other/Kermit/lib/Patch.o
new file mode 100644
index 0000000..630c201
--- /dev/null
+++ b/other/Kermit/lib/Patch.o
Binary files differ
diff --git a/other/Kermit/lib/SymbolFingp.cpp b/other/Kermit/lib/SymbolFingp.cpp
new file mode 100644
index 0000000..4b29bef
--- /dev/null
+++ b/other/Kermit/lib/SymbolFingp.cpp
@@ -0,0 +1,108 @@
1/*
2 * SymbolFingp.cpp:
3 * written by palmers / teso
4 */
5#include <SymbolFingp.hpp>
6#include <stoi16.hpp>
7
8
9bool SymbolFingp::addFinger (struct sfp *a)
10{
11 Fingers.insert (FingerThing::value_type (string (a->name), *a));
12 return true; /* ah, well - think positiv ... */
13}
14
15
16void SymbolFingp::readFingers (ifstream a)
17{
18 int x = 0;
19 struct sfp *tmp_sfp = NULL;
20 string tmp_string;
21
22 if (!a.is_open ())
23 {
24 cerr << "failed to open file" << endl;
25 abort ();
26 }
27#ifdef DEBUG
28 else
29 {
30 cout << "Reading fingerprints ..." << endl;
31 }
32#endif
33
34 a.setf (ios::skipws);
35 while (!a.eof ())
36 {
37 tmp_sfp = new struct sfp;
38
39/* get the name */
40 a >> tmp_string;
41 tmp_sfp->name = new char[tmp_string.length () + 1];
42 copy (tmp_string.begin (), tmp_string.end (), tmp_sfp->name);
43
44/* the addresses */
45 a.setf (ios::hex, ios::basefield);
46 a >> tmp_sfp->start_addr;
47 a >> tmp_sfp->stop_addr;
48
49/* offset from fp to real address */
50 a >> tmp_sfp->offset;
51
52/* length of fp */
53 a >> tmp_sfp->length;
54
55/* the cells */
56 tmp_sfp->fp = new struct cell[tmp_sfp->length];
57
58 for (x = 0; x < tmp_sfp->length; x++)
59 {
60 a >> tmp_string;
61
62 if ((tmp_string.length () == 1) && (tmp_string[0] == '?'))
63 {
64 tmp_sfp->fp[x].type = WWCARD;
65 tmp_sfp->fp[x].val = 0;
66 }
67 else
68 {
69 tmp_sfp->fp[x].type = NOCARD;
70 tmp_sfp->fp[x].val = stoi16 (tmp_string);
71 }
72 }
73 if (addFinger (tmp_sfp) != true)
74 {
75 cerr << "Could not add fingerprint" << endl;
76 abort ();
77 }
78 }
79 a.setf (ios::dec, ios::basefield);
80#ifdef DEBUG
81 cout << "done." << endl;
82#endif
83}
84
85
86SymbolFingp::SymbolFingp ()
87{
88 readFingers (ifstream (DEFAULT_FILE));
89}
90
91
92SymbolFingp::SymbolFingp (string a)
93{
94 readFingers (ifstream (a.c_str ()));
95}
96
97
98SymbolFingp::~SymbolFingp ()
99{
100 Fingers.clear ();
101}
102
103
104struct sfp *SymbolFingp::getFinger (string a)
105{
106 return &Fingers[a];
107}
108
diff --git a/other/Kermit/lib/SymbolTable.cpp b/other/Kermit/lib/SymbolTable.cpp
new file mode 100644
index 0000000..1d412e0
--- /dev/null
+++ b/other/Kermit/lib/SymbolTable.cpp
@@ -0,0 +1,205 @@
1/*
2 * SymbolTable.cpp:
3 * written by palmers / teso
4 */
5#include <SymbolTable.hpp>
6
7
8/*
9 * helper classes
10 */
11class DumpTable
12 {
13private:
14 string file;
15
16public:
17 DumpTable (string a)
18 {
19 file = string (a);
20 }
21
22 ~DumpTable ()
23 {
24 }
25
26 void operator() (zzSym *foo)
27 {
28 ofstream dump (file.c_str ());
29 if (!dump.is_open ())
30 {
31 cerr << "Pfff..." << endl;
32 abort ();
33 }
34 dump << foo->Name << "\tE\t" << foo->Address << endl;
35 dump.close ();
36 }
37 };
38
39
40class FindFind
41 {
42 private:
43 string search;
44
45 public:
46 FindFind (string a)
47 {
48 search = string (a);
49 }
50
51 bool operator() (struct zzSym *foo)
52 {
53 if (search.compare (foo->Name, search.length ()))
54 {
55 return true;
56 }
57 return false;
58 }
59 };
60
61
62/*
63 * member functions
64 */
65 bool SymbolTable::loadFiles (string a, string b)
66 {
67/* check for System.map */
68 mapp = SystemMap (a);
69
70/* load a dumped cache */
71 rest = SystemMap (b);
72 return true;
73 }
74
75
76 bool SymbolTable::createObjects (rwKernel *a)
77 {
78 if (a == NULL)
79 patt = new DevMemPatt ();
80 else
81 patt = new DevMemPatt (a);
82 fing = new SymbolFingp ();
83 return true;
84 }
85
86
87 SymbolTable::SymbolTable ()
88 {
89 loadFiles (DEFAULTSYSTEMMAP, DEFAULTDUMP);
90 createObjects (NULL);
91
92/* XXX, init set of exported symbols */
93 if (false)
94 {
95 exported = SystemMap ();
96 }
97 }
98
99
100 SymbolTable::SymbolTable (string res, string sys)
101 {
102 loadFiles (sys, res);
103 createObjects (NULL);
104
105/* XXX, init set of exported symbols */
106 if (false)
107 {
108 exported = SystemMap ();
109 }
110 }
111
112
113 SymbolTable::SymbolTable (rwKernel *f)
114 {
115 loadFiles (DEFAULTSYSTEMMAP, DEFAULTDUMP);
116 createObjects (f);
117 }
118
119
120 SymbolTable::~SymbolTable ()
121 {
122 delete fing;
123 delete patt;
124 clearCache ();
125 }
126
127
128 void SymbolTable::setSaveFile (string file)
129 {
130 dump_file = string (file);
131 }
132
133
134 unsigned int SymbolTable::getSymbol (string name)
135 {
136 zzSymList::iterator x;
137 zzSym *y = NULL;
138
139 x = find_if (symList.begin (), symList.end (), FindFind (name));
140 if (x == symList.end ())
141 return 0;
142 y = *x;
143 return y->Address;
144 }
145
146
147 bool SymbolTable::findSymbol (string name)
148 {
149 unsigned int x = 0;
150/*
151 * first check if the symbol can be found in restore date
152 * second check if the symbol can be found using SymbolFingp
153 * third is list of exported symbols
154 * fourth System.map (if supplied)
155 */
156 if (rest.contains (name))
157 {
158 addSymbolToCache (name, rest[name]);
159 return true;
160 }
161
162 if ((x = patt->find_patt (fing->getFinger (name))) != 0)
163 {
164 addSymbolToCache (name, x);
165 return true;
166 }
167
168 if (exported.contains (name))
169 {
170 addSymbolToCache (name, exported[name]);
171 return true;
172 }
173
174 if (mapp.contains (name))
175 {
176 addSymbolToCache (name, mapp[name]);
177 return true;
178 }
179
180 return false;
181 }
182
183
184 void SymbolTable::addSymbolToCache (string name, unsigned int add)
185 {
186 zzSym *x = new zzSym;
187
188 x->Name = string (name);
189 x->Address = add;
190 symList.push_back (x);
191 }
192
193
194 void SymbolTable::clearCache ()
195 {
196 symList.clear ();
197 }
198
199
200 bool SymbolTable::saveCache ()
201 {
202 for_each (symList.begin (), symList.end (), DumpTable (dump_file));
203 return true;
204 }
205
diff --git a/other/Kermit/lib/SystemMap.cpp b/other/Kermit/lib/SystemMap.cpp
new file mode 100644
index 0000000..03e2fb4
--- /dev/null
+++ b/other/Kermit/lib/SystemMap.cpp
@@ -0,0 +1,67 @@
1/*
2 * SystemMap.cpp:
3 * written by palmers / teso
4 */
5#include <SystemMap.hpp>
6
7
8 SystemMap::SystemMap (string a)
9 {
10 string tmp;
11 unsigned int num = 0;
12 ifstream f;
13
14 f.open (a.c_str ());
15 if (!f.is_open ())
16 {
17 cerr << "Error opening file \"" << a << "\"!" << endl;
18 abort ();
19 }
20
21 f.setf (ios::skipws);
22 f.setf (ios::hex, ios::basefield);
23
24 while (!f.eof ())
25 {
26 f >> num;
27 f >> tmp;
28 f >> tmp;
29
30 add_map.insert (add_map.end (), bla_val (tmp, num));
31 }
32 f.close ();
33 }
34
35
36 SystemMap::SystemMap ()
37 {
38 }
39
40
41 SystemMap::~SystemMap ()
42 {
43 add_map.clear ();
44 }
45
46
47 bool SystemMap::contains (string a)
48 {
49 if (add_map.find (a) == add_map.end ())
50 return false;
51 return true;
52 }
53
54
55 void SystemMap::add (string a, unsigned int x)
56 {
57 add_map.insert (add_map.end (), bla_val (a, x));
58 }
59
60
61 unsigned int SystemMap::operator[] (string a)
62 {
63 if (add_map.find (a) == add_map.end ())
64 return 0;
65 return add_map[a];
66 }
67
diff --git a/other/Kermit/lib/itos16.cpp b/other/Kermit/lib/itos16.cpp
new file mode 100644
index 0000000..b7a8a20
--- /dev/null
+++ b/other/Kermit/lib/itos16.cpp
@@ -0,0 +1,36 @@
1/*
2 * itos16.cpp:
3 * written by palmers / teso
4 */
5#include <itos16.hpp>
6#include <iostream>
7
8 string itos16 (unsigned int x)
9 {
10 char t[] = "0123456789abcdef";
11 string y;
12 unsigned int a,
13 base = 1,
14 z = 0;
15
16 while (base < x && z++ < 7)
17 base *= 16;
18
19 if (z != 8 && z != 0)
20 base /= 16;
21
22 while (base != 1)
23 {
24 a = 0;
25 while (x >= base)
26 {
27 a++;
28 x -= base;
29 }
30 y += t[a];
31 base /= 16;
32 }
33 y += t[x];
34 return y;
35 }
36
diff --git a/other/Kermit/lib/name2add.c b/other/Kermit/lib/name2add.c
new file mode 100644
index 0000000..a141075
--- /dev/null
+++ b/other/Kermit/lib/name2add.c
@@ -0,0 +1,46 @@
1/*
2 * name2add.c:
3 * this file was automaticly generated by gen_name2add
4 */
5#include <stdio.h>
6#include <name2add.h>
7
8__name2add __n2a[] =
9{
10 {"sys_fork", 0xf8f8f8f8},
11 {"sys_read", 0xf8f8f7f7},
12 {"sys_write", 0xf8f8f6f6},
13 {"sys_exit", 0xf8f8f5f5},
14 {"sys_setuid", 0xf8f8f4f4},
15 {"sys_setgid", 0xf8f8f3f3},
16 {"sys_getuid", 0xf8f8f2f2},
17 {"sys_getgid", 0xf8f8f1f1},
18 {"sys_open", 0xf8f8f0f0},
19 {"sys_close", 0xf8f8efef},
20 {"kmalloc", 0xf8f8eeee},
21 {NULL, 0}
22};
23
24/*
25 * name2add.c:
26 * this file was automaticly generated by gen_name2add
27 */
28#include <stdio.h>
29#include <name2add.h>
30
31__name2add __n2a[] =
32{
33 {"sys_fork", 0xf8f8f8f8},
34 {"sys_read", 0xf8f8f7f7},
35 {"sys_write", 0xf8f8f6f6},
36 {"sys_exit", 0xf8f8f5f5},
37 {"sys_setuid", 0xf8f8f4f4},
38 {"sys_setgid", 0xf8f8f3f3},
39 {"sys_getuid", 0xf8f8f2f2},
40 {"sys_getgid", 0xf8f8f1f1},
41 {"sys_open", 0xf8f8f0f0},
42 {"sys_close", 0xf8f8efef},
43 {"kmalloc", 0xf8f8eeee},
44 {NULL, 0}
45};
46
diff --git a/other/Kermit/lib/name2add.o b/other/Kermit/lib/name2add.o
new file mode 100644
index 0000000..260866e
--- /dev/null
+++ b/other/Kermit/lib/name2add.o
Binary files differ
diff --git a/other/Kermit/lib/rwKernel.cpp b/other/Kermit/lib/rwKernel.cpp
new file mode 100644
index 0000000..4077ff5
--- /dev/null
+++ b/other/Kermit/lib/rwKernel.cpp
@@ -0,0 +1,107 @@
1/*
2 * rwKernel.cpp:
3 * written by palmers / teso
4 */
5#include <rwKernel.hpp>
6#include <unistd.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10#include <sys/mman.h>
11#include <iostream>
12
13
14 bool rwKernel::openFile (int w)
15 {
16 int a = 0;
17 void *tmp = NULL;
18 char *file = NULL;
19
20 if (w == DEVMEM)
21 file = "/dev/mem";
22 else if (w == PROCKCORE)
23 file = "/proc/kcore";
24
25 if ((a = open (file, O_RDWR)) <= 0)
26 {
27 cerr << "open error" << endl;
28 abort ();
29 }
30
31 if ((tmp = mmap (NULL, 0x40000000, PROT_READ | \
32 PROT_WRITE, MAP_SHARED, a, 0xc0000000 - mem_conf)) == (void *) -1)
33 {
34 cerr << "mmap failed" << endl;
35 abort ();
36 }
37 fd = (char *) tmp;
38 return true;
39 }
40
41
42 void rwKernel::setOffset (int x)
43 {
44 switch (x)
45 {
46 case CONF_1GB:
47 mem_conf = 0xC0000000;
48 break;
49 case CONF_2GB:
50 mem_conf = 0x80000000;
51 break;
52 case CONF_3GB:
53 mem_conf = 0x40000000;
54 break;
55 case IGNORE:
56 mem_conf = 0xC0000000;
57 break;
58 default:
59 mem_conf = 0xC0000000;
60 break;
61 }
62 }
63
64
65 void rwKernel::closeFile ()
66 {
67 munmap (fd, 0x40000000);
68 }
69
70
71 rwKernel::rwKernel ()
72 {
73 setOffset (CONF_1GB);
74 openFile (DEVMEM);
75 }
76
77
78 rwKernel::rwKernel (int file, int off)
79 {
80 if (file == PROCKCORE)
81 off = IGNORE;
82 setOffset (off);
83 openFile (file);
84 }
85
86
87 rwKernel::~rwKernel ()
88 {
89 closeFile ();
90 }
91
92
93 void rwKernel::read (unsigned char *dest, unsigned int len, \
94 unsigned int offset)
95 {
96 offset -= mem_conf;
97 copy (fd + offset, fd + offset + len, dest);
98 }
99
100
101 void rwKernel::write (unsigned char *src, unsigned int len, \
102 unsigned int offset)
103 {
104 offset -= mem_conf;
105 copy (src, src + len, fd + offset);
106 }
107
diff --git a/other/Kermit/lib/stoi16.cpp b/other/Kermit/lib/stoi16.cpp
new file mode 100644
index 0000000..83aad59
--- /dev/null
+++ b/other/Kermit/lib/stoi16.cpp
@@ -0,0 +1,29 @@
1/*
2 * stoi16.cpp:
3 * written by palmers / teso
4 */
5#include <stoi16.hpp>
6
7 unsigned int stoi16 (string x)
8 {
9 int num = 0,
10 base = 1,
11 z = x.length () - 1;
12 unsigned int y = 0;
13
14 while (z >= 0)
15 {
16 if (x[z] <= '9' && x[z] >= '0')
17 num = x[z] - '0';
18 if (x[z] <= 'f' && x[z] >= 'a')
19 num = x[z] - 'a' + 10;
20 if (x[z] <= 'F' && x[z] >= 'A')
21 num = x[z] - 'A' + 10;
22
23 y += num * base;
24 base *= 16;
25 z--;
26 }
27 return y;
28 }
29