partyboy1a

new-code-finder-wip.lua

Oct 12th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. --new code finder
  2.  
  3. executedcode = {}
  4. for i = 1, 0x10000  do --0, 0xFFFF do
  5.     executedcode[i] = {i-1, 0}
  6. end
  7.  
  8. lastexec = nil
  9. mode = "track"
  10. calls = 0
  11.  
  12. function memfunc(addr)
  13.     if mode=="track" then
  14.         executedcode[addr+1][2] = executedcode[addr+1][2] + 1
  15.         --memory.registerexec(addr,nil)
  16.         lastexec = addr
  17.     elseif executedcode[addr+1][2] == 0 then
  18.         gui.register(function() gui.text(0,100,string.format("code at %x got executed",addr)) end )
  19.         emu.pause()
  20.     end
  21. end
  22.  
  23. memory.registerexec(0,0x10000,memfunc)
  24.  
  25. function h4(num)
  26.     s = ""
  27.     if num < 0x10 then s = s .. "0" end
  28.     if num < 0x100 then s = s .. "0" end
  29.     if num < 0x1000 then s = s .. "0" end
  30.     return string.format("%s%x", s, num)
  31. end
  32.  
  33. function iff(cond, a, b)
  34.     --If and only if.
  35.     if cond then
  36.         return a
  37.     else
  38.         return b
  39.     end
  40. end
  41.  
  42. while(true) do
  43.     keys = input.get()
  44.     if keys["F11"] then
  45.         break
  46.     elseif keys["numpad/"] then
  47.         memory.registerexec(0,0x10000,nil)
  48.         table.sort(executedcode, function(a,b) return iff(a[2] < b[2], true, iff(a[2] == b[2], a[1] < b[1], false)) end)
  49.         file = io.open("executioncount.txt","w")
  50.         for _,b in pairs(executedcode) do
  51.             file:write(string.format("%s: %i\n",h4(b[1]), b[2]))
  52.         end
  53.         file:close()
  54.         offset = 0
  55.         while executedcode[offset + 1][2] == 0 do offset = offset + 1 end
  56.         local help = function()
  57.             for i = 1, 25 do for j = 0, 2 do
  58.                 gui.text(j * 80, i * 8, h4(executedcode[i + j*25 + offset][1]) .. ": " .. executedcode[i + j*25 + offset][2])
  59.             end end
  60.         end
  61.         gui.register(help)
  62.         emu.pause()
  63.         gui.register(nil)
  64.         memory.registerexec(0,0x10000,memfunc)
  65.         table.sort(executedcode, function(a,b) return a[1] < b[1] end)
  66.     else
  67.         emu.frameadvance()
  68.     end
  69. end
  70.  
  71. mode = "find"
  72. while(true) do
  73.     emu.frameadvance()
  74. end
  75.  
Advertisement
Add Comment
Please, Sign In to add comment