-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgoto.lua
More file actions
121 lines (121 loc) · 1.85 KB
/
goto.lua
File metadata and controls
121 lines (121 loc) · 1.85 KB
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
list=gg.getRangesList("^/da*.s")
xl={Cd=0,Cb=0,Xa=0}
for k,v in pairs(list) do
k=v.state
if xl[k] and v.type:sub(2,2)=="w" then
xl[k..v.internalName:match("lib([^/]+).so[^o]*$")]=v.start
end
end
tree={}
x32=gg.getTargetInfo().x64
if x32 then
x32=32
else
x32=4
end
function x64(value)
if x32==4 then
value=value&0xffffffff
end
return value
end
function treeCache(adr,list)
local next
local last=tree[adr]
if not last then
last={}
tree[adr]=last
end
for k,v in ipairs(list) do
if adr==0 then
return
end
next=last[v]
if next and next.adr then
adr=next.adr
else
next={}
last[v]=next
adr=gg.getValues({{address=x64(adr)+v,flags=x32}})[1]
next.adr=adr
end
adr=adr.value
last=next
end
return next
end
--[[
使用树优化你的代码,多个同路径避免重复获取。
node=treeCache(0,{0,1,2})
print(node.adr)
重建树(清空自己和所有子目标)
node.adr=nil
node=treeCache(0,{0,1,2})
]]--
heep={}
function getheep(adr,list)
local next,last
for k,v in ipairs(list) do
if adr==0 then
return
end
adr=x64(adr)+v
if next then
last=next.tree
if not last then
last={}
next.tree=last
end
end
next=heep[adr]
if not next then
next=gg.getValues({{address=adr,flags=x32}})[1]
if last then
last[adr]=next
end
heep[adr]=next
end
adr=next.value
end
return next
end
function cleartree(tree)
for k,v in pairs(tree) do
heep[k]=nil
tree=v.tree
if tree then
cleartree(tree)
end
end
end
function clearheep(adr)
local next=heep[adr]
if next then
heep[adr]=nil
cleartree(next.tree)
end
end
--[[
通过堆获取,避免重复获取
node=getheep(0,{0,1,2})
清理堆,这可能很耗时
node=clearheep(0)
]]--
function getAdr(adr,list)
local next
for k,v in ipairs(list) do
if adr==0 then
return
end
next=gg.getValues({{address=x64(adr)+v,flags=x32}})
adr=next.value
end
return next
end
--[[
直接获取
adr=getAdr(0,{0,1,2})
]]--
for k,v in pairs(t) do
print(string.format("%x",getheep(v,xl[v.i]).address))
end