-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsesym.lua
51 lines (40 loc) · 1.03 KB
/
parsesym.lua
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
local args = {...}
local symbols = {}
--DB3E
for line in io.lines(table.remove(args, 1)) do
local bank, address, name = line:match("(%x%x):(%x%x%x%x) (.+)")
if bank then
bank, address = tonumber(bank, 16), tonumber(address, 16)
if not symbols[address] then
symbols[address] = {[bank] = name}
else
symbols[address][bank] = name
end
end
end
local function findSymbol(address)
local lastBank = {}
local foundSymbolsByBank = {}
for addr, bankNames in pairs(symbols) do
for bank, name in ipairs(bankNames) do
if lastBank[bank] and lastBank[bank] < address and addr > address then
foundSymbolsByBank[#foundSymbolsByBank+1] = {
name,
address-addr
}
lastBank[bank] = math.huge
end
lastBank[bank] = addr
end
end
return foundSymbolsByBank
end
local function formatFoundSymbols(found)
local formatList = {}
for i=1, #found do
formatList[i] = found[i][1].."+"..found[i][2]
end
return table.concat(formatList, "\n")
end
local found = findSymbol(0xDB3E)
print(formatFoundSymbols(found))