aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser/lua-scripts/df-demo.lua
blob: 7db2f8521d670f5a921aaaa8bdf3ea6a8c5b36b1 (plain) (blame)
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
xobj = require("lua-scripts.xobj")
asmrw = require("lua-scripts.asmrw")
colors = require("ansicolors")

df_exe = "/home/bloodstalker/df/df_44_09_linux/df_linux/libs/Dwarf_Fortress"

function main()
  local text_section = xobj.getTextSection(df_exe)
end

function pretty_dump()
  count = 0
  local text_section = xobj.getTextSection(df_exe)
  io.write(colors("%{blue}".."    ".."\t".."00 ".."01 ".."02 ".."03 ".."04 ".."05 ".."06 ".."07 ".."08 ".."09 ".."0A ".."0B ".."0C ".."0D ".."0E ".."0F"))
  for k,v in pairs(text_section) do
    if count % 16 == 0 then
      print()
      io.write(colors("%{blue}".."0x"..string.format("%03x",count)), "\t")
    end
    io.write(colors("%{green}"..string.format("%02x", v)), " ")
    count = count + 1
  end
  count = 0
  print()
end

function jmp_table_test()
  io.write(colors("%{cyan}".."lua:getting text section...\n"))
  local text_section = xobj.getTextSection(df_exe)
  local rodata = xobj.getRODataSection(df_exe)
  for k,v in pairs(rodata) do
    if v > 32 and v < 127 then 
      io.write(string.format("%c",v)) 
    else
      io.write(" ")
    end
  end
  io.write("\0\n")
  io.write(colors("%{green}".."lua:got text section.\n"))
  local head = jmp_s_t()
  -- messes up the stack. I could fix it but not sure why i would want to keep this in
  --local head2 = jmp_s_t:new()
  io.write(colors("%{cyan}".."lua:calling getjmptable\n"))
  --head = getjmptable(#text_section, text_section)

  --if false then
    --while head:inext() ~= nil do
      --head:dump("entry")
      --io.write("type:", head:type(), "\tlocation:", "0x"..string.format("%x", head:location()))
      --print()
      --head = head:inext()
    --end
    --end
end

--main()
--pretty_dump()
jmp_table_test()