Skip to main content

luaur_bytecode/methods/
bytecode_graph_parser_is_jump_trampoline.rs

1use crate::records::bytecode_graph_parser::BytecodeGraphParser;
2use crate::type_aliases::instruction::Instruction;
3use luaur_common::enums::luau_opcode::LuauOpcode;
4use luaur_common::functions::get_jump_target::getJumpTarget;
5use luaur_common::macros::luau_insn_op::LUAU_INSN_OP;
6
7impl<'a> BytecodeGraphParser<'a> {
8    pub fn is_jump_trampoline(&self, pc: u32, code: *const Instruction, codesize: u32) -> bool {
9        let op0: LuauOpcode =
10            unsafe { std::mem::transmute((LUAU_INSN_OP(*code.add(pc as usize)) & 0xff) as u8) };
11        if op0 != LuauOpcode::LOP_JUMP {
12            return false;
13        }
14
15        if pc + 1 >= codesize {
16            return false;
17        }
18
19        let op1: LuauOpcode = unsafe {
20            std::mem::transmute((LUAU_INSN_OP(*code.add((pc + 1) as usize)) & 0xff) as u8)
21        };
22        if op1 != LuauOpcode::LOP_JUMPX {
23            return false;
24        }
25
26        let target = unsafe { getJumpTarget(*code.add((pc + 2) as usize), pc + 2) as u32 };
27        target == pc + 1
28    }
29}