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 122 123 124 125 126 127 128 129 130 | local bit = require( 'bit' )
local test = require( 'test' )
- - local fp = io. open ( "test.luac" , "rb" )
- - local ori_data = fp:read( "*all" )
- - fp:close()
local ori_data = {}
- - print ( 'data len ' ..
- - print ( 'ori_data len ' ..
- - 因为题目不支持 io.read 所以要对 check_opcode.lua 进行修改
- - 把读取注释掉,换成 local ori_data = {} , 然后我们手动读入 opc.lua 并进行替换。
local ori_op_name = {
"OP_MOVE" ,
"OP_LOADK" ,
"OP_LOADKX" ,
"OP_LOADBOOL" ,
"OP_LOADNIL" ,
"OP_GETUPVAL" ,
"OP_GETTABUP" ,
"OP_GETTABLE" ,
"OP_SETTABUP" ,
"OP_SETUPVAL" ,
"OP_SETTABLE" ,
"OP_NEWTABLE" ,
"OP_SELF" ,
"OP_ADD" ,
"OP_SUB" ,
"OP_MUL" ,
"OP_MOD" ,
"OP_POW" ,
"OP_DIV" ,
"OP_IDIV" ,
"OP_BAND" ,
"OP_BOR" ,
"OP_BXOR" ,
"OP_SHL" ,
"OP_SHR" ,
"OP_UNM" ,
"OP_BNOT" ,
"OP_NOT" ,
"OP_LEN" ,
"OP_CONCAT" ,
"OP_JMP" ,
"OP_EQ" ,
"OP_LT" ,
"OP_LE" ,
"OP_TEST" ,
"OP_TESTSET" ,
"OP_CALL" ,
"OP_TAILCALL" ,
"OP_RETURN" ,
"OP_FORLOOP" ,
"OP_FORPREP" ,
"OP_TFORCALL" ,
"OP_TFORLOOP" ,
"OP_SETLIST" ,
"OP_CLOSURE" ,
"OP_VARARG" ,
"OP_EXTRAARG"
}
local data = string.dump(test)
local new_op = { [ "OP_MOVE" ] = - 1 ,
[ "OP_LOADK" ] = - 1 ,
[ "OP_LOADKX" ] = - 1 ,
[ "OP_LOADBOOL" ] = - 1 ,
[ "OP_LOADNIL" ] = - 1 ,
[ "OP_GETUPVAL" ] = - 1 ,
[ "OP_GETTABUP" ] = - 1 ,
[ "OP_GETTABLE" ] = - 1 ,
[ "OP_SETTABUP" ] = - 1 ,
[ "OP_SETUPVAL" ] = - 1 ,
[ "OP_SETTABLE" ] = - 1 ,
[ "OP_NEWTABLE" ] = - 1 ,
[ "OP_SELF" ] = - 1 ,
[ "OP_ADD" ] = - 1 ,
[ "OP_SUB" ] = - 1 ,
[ "OP_MUL" ] = - 1 ,
[ "OP_MOD" ] = - 1 ,
[ "OP_POW" ] = - 1 ,
[ "OP_DIV" ] = - 1 ,
[ "OP_IDIV" ] = - 1 ,
[ "OP_BAND" ] = - 1 ,
[ "OP_BOR" ] = - 1 ,
[ "OP_BXOR" ] = - 1 ,
[ "OP_SHL" ] = - 1 ,
[ "OP_SHR" ] = - 1 ,
[ "OP_UNM" ] = - 1 ,
[ "OP_BNOT" ] = - 1 ,
[ "OP_NOT" ] = - 1 ,
[ "OP_LEN" ] = - 1 ,
[ "OP_CONCAT" ] = - 1 ,
[ "OP_JMP" ] = - 1 ,
[ "OP_EQ" ] = - 1 ,
[ "OP_LT" ] = - 1 ,
[ "OP_LE" ] = - 1 ,
[ "OP_TEST" ] = - 1 ,
[ "OP_TESTSET" ] = - 1 ,
[ "OP_CALL" ] = - 1 ,
[ "OP_TAILCALL" ] = - 1 ,
[ "OP_RETURN" ] = - 1 ,
[ "OP_FORLOOP" ] = - 1 ,
[ "OP_FORPREP" ] = - 1 ,
[ "OP_TFORCALL" ] = - 1 ,
[ "OP_TFORLOOP" ] = - 1 ,
[ "OP_SETLIST" ] = - 1 ,
[ "OP_CLOSURE" ] = - 1 ,
[ "OP_VARARG" ] = - 1 ,
[ "OP_EXTRAARG" ] = - 1 }
for i = 6 ,
local by_ori = ori_data[i] - - string.byte(ori_data,i)
- - 改后这里的 ori_data 是数组了
local by_new = string.byte(data,i)
if by_ori ~ = by_new then
local idx = bit:_and( 0x3F ,by_ori)
if idx < 47 then - - 限制一个范围,如果超出了 opcode 的数量就说明这个变化有可能不是 opcode 被换导致的
local op_name = ori_op_name[idx + 1 ]
local op_idx = bit:_and( 0x3F ,by_new)
new_op[op_name] = op_idx
end
end
end
print ( "old \t new \t name" )
for idx, op_name in pairs(ori_op_name) do
local tmp = ''
tmp = new_op[op_name]
print ((idx - 1 ) .. "\t" .. tmp .. "\t" .. op_name )
end
|