-
Notifications
You must be signed in to change notification settings - Fork 6
/
list.cpp
130 lines (108 loc) · 2.9 KB
/
list.cpp
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
#include "list.h"
#include "CmdExt.h"
#include "CmdList.h"
#include <iomanip>
DEFINE_CMD(link)
{
size_t head = EXT_F_IntArg(args, 1, 0);
dig_link(head);
}
DEFINE_CMD(flink)
{
size_t head = EXT_F_IntArg(args, 1, 0);
size_t entry = EXT_F_IntArg(args, 2, 0);
dig_link(head, entry);
}
void dig_link(size_t head)
{
try
{
size_t addr = head;
if (EXT_F_ValidAddr(addr))
{
size_t head = addr;
for (size_t i = 0; i < 0x400; i++)
{
addr = dig_link(addr, head, head, i * 0x400, 0x400);
if (addr == 0)
return;
}
EXT_F_OUT("\t[[ Too long list, unable to dump all ]]\n");
}
else
{
EXT_F_OUT(" --> 0x%I64x\n", addr);
}
}
FC;
}
void dig_link(size_t head, size_t entry)
{
try
{
size_t addr = head;
if (EXT_F_ValidAddr(addr))
{
for (size_t i = 0; i < 0x100; i++)
{
addr = dig_link(addr, head, entry, i * 0x1000, 0x1000);
if (addr == 0)
return;
}
EXT_F_OUT("\t[[ Too long list, unable to dump all ]]\n");
}
else
{
EXT_F_OUT(" --> 0x%I64x\n", addr);
}
}
FC;
}
size_t dig_link(size_t addr, size_t head, size_t entry, size_t index, size_t count)
{
try
{
stringstream ss;
for (size_t i = 0; i < count; i++)
{
if (!EXT_F_ValidAddr(addr))
{
ss << "\t[[ broken link at "
<< HEX_ADDR(addr)
<< " ]]\n";
EXT_F_OUT(ss.str().c_str());
return 0;
}
size_t flink = EXT_F_READ<size_t>(addr);
size_t blink = EXT_F_READ<size_t>(addr + 8);
ss << hex << showbase << setfill(' ') << setw(10) << i + index
<< " [ "
<< HEX_ADDR(flink)
<< " , "
<< HEX_ADDR(blink)
<< " ] \n";
if (flink == entry/* || blink == head*/)
{
ss << "\t[ found entry "
<< HEX_ADDR(addr)
<< " ]\n";
EXT_F_OUT(ss.str().c_str());
return 0;
}
if (flink == head/* || blink == head*/)
{
ss << "\t[ finished "
<< HEX_ADDR(addr)
<< " ]\n";
EXT_F_OUT(ss.str().c_str());
return 0;
}
addr = flink;
}
ss << "\t[[ ... next " << count << " entries ... ]]\n";
EXT_F_OUT(ss.str().c_str());
return addr;
}
FC;
return addr;
}