首页
社区
课程
招聘
[旧帖] 关于Lua源代码编译的问题 0.00雪花
发表于: 2015-3-4 15:20 3229

[旧帖] 关于Lua源代码编译的问题 0.00雪花

2015-3-4 15:20
3229
弱弱问下。关于lopcodes.h 这个文件中的 GET_OPCODE ,SET_OPCODE 如何实现对opcode 指

令进行加密?  

#define GET_OPCODE(i)        (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))

#define SET_OPCODE(i,o)        ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
   ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))

这两个分别是什么意思?  有人能讲解下么``

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 360
活跃值: (257)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
Lua instruction is a 32 bits double word, and there are:

a fixed 6 bits op-code.
8 bits A operation
9 bits B operation
9 bits C operation

26 bits Ax operation
18 bits Bx operation
18 bits sBx operation

There are the following compositions:

C B A OP (9 9 8 6)
Ax     OP (26 6)
Bx  A Op (18 8 6)
sBX A Op (18 8 6)

For example, a = b + 1, instruction is 0x0040400D

(cast(OpCode, ((0x0040400D)>>POS_OP) & MASK1(SIZE_OP,0)))

-> (0x0040400D >> 0) & ((~((~(Instruction)0)<<(6)))<<(0))
-> 0x0040400D & 0x3F
-> 0x0D

So, GET_OPCODE(instruction) is 0x0D = OP_ADD

The SET_OPCODE is REVERSE work macro. If you can't understand that macro, please reference your C language textbooks.
2015-3-4 19:37
0
雪    币: 13
活跃值: (49)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
3
貌似还是不是很懂。。请指教``
2015-3-5 10:50
0
游客
登录 | 注册 方可回帖
返回
//