64 lines
1.8 KiB
Lua
64 lines
1.8 KiB
Lua
local readbc = require('readbc')
|
|
local opcodes = require('opcodes')
|
|
|
|
local function inspect_proto(proto)
|
|
print('\n-- proto --')
|
|
print('Params: ' .. proto.numparams)
|
|
print('Frame Size: ' .. proto.framesize)
|
|
print('#instructions: ' .. proto.numbc)
|
|
print('#upvalues: ' .. proto.numuv)
|
|
print('#collectable constants: ' .. proto.numkgc)
|
|
print('#numeric constants: ' .. proto.numkn)
|
|
|
|
if proto.debugInfo ~= nil then
|
|
print('-- bytecode: lines ' .. proto.debugInfo.firstLine .. ' ' .. proto.debugInfo.numLine)
|
|
else
|
|
print('-- bytecode --')
|
|
end
|
|
for i = 1, #proto.bcins do
|
|
local decoded = opcodes.decode(proto.bcins[i])
|
|
if opcodes.defs[decoded.id] ~= nil then
|
|
local def = opcodes.defs[decoded.id]
|
|
-- check for ABC or AD format
|
|
if def.b ~= opcodes.Mode.none then
|
|
print(string.format('%s\t A: %s\tB: %s\t C: %s', def.name, decoded.a, decoded.b, decoded.c))
|
|
else
|
|
print(string.format('%s\t A: %s\tD: %s', def.name, decoded.a, decoded.d))
|
|
end
|
|
else
|
|
print('UNKNOWN OPCODE')
|
|
end
|
|
end
|
|
end
|
|
|
|
local function inspect(fp)
|
|
local header = readbc.read_header(fp)
|
|
|
|
print('-- header --')
|
|
print('Name: ' .. header.name)
|
|
print(string.format('Bytecode Version: %s', header.version))
|
|
print('Stripped: ' .. (header.stripped and 'yes' or 'no'))
|
|
|
|
local proto = readbc.read_proto(fp)
|
|
while proto ~= nil do
|
|
inspect_proto(proto)
|
|
proto = readbc.read_proto(fp)
|
|
end
|
|
end
|
|
|
|
local arg = {...}
|
|
if arg[1] == nil then
|
|
print('Please pass a LuaJIT bytecode file as command line argument')
|
|
return 1
|
|
end
|
|
|
|
local fp = io.open(arg[1])
|
|
if fp == nil then
|
|
print('Could not open path ' .. arg[1])
|
|
return 1
|
|
end
|
|
|
|
inspect(fp)
|
|
|
|
fp:close()
|