MCPcopy Index your code
hub / github.com/encounter/objdiff / scan_instructions_internal

Method scan_instructions_internal

objdiff-core/src/arch/arm64.rs:28–74  ·  view source on GitHub ↗
(
        &self,
        address: u64,
        code: &[u8],
        _section_index: usize,
        _relocations: &[Relocation],
        _diff_config: &DiffObjConfig,
    )

Source from the content-addressed store, hash-verified

26
27impl Arch for ArchArm64 {
28 fn scan_instructions_internal(
29 &self,
30 address: u64,
31 code: &[u8],
32 _section_index: usize,
33 _relocations: &[Relocation],
34 _diff_config: &DiffObjConfig,
35 ) -> Result<Vec<InstructionRef>> {
36 let start_address = address;
37 let mut ops = Vec::<InstructionRef>::with_capacity(code.len() / 4);
38
39 let mut reader = U8Reader::new(code);
40 let decoder = InstDecoder::default();
41 let mut ins = Instruction::default();
42 loop {
43 // This is ridiculous...
44 let offset = <U8Reader<'_> as Reader<
45 <ARMv8 as YaxpeaxArch>::Address,
46 <ARMv8 as YaxpeaxArch>::Word,
47 >>::total_offset(&mut reader);
48 let address = start_address + offset;
49 match decoder.decode_into(&mut ins, &mut reader) {
50 Ok(()) => {}
51 Err(e) => match e {
52 DecodeError::ExhaustedInput => break,
53 DecodeError::InvalidOpcode
54 | DecodeError::InvalidOperand
55 | DecodeError::IncompleteDecoder => {
56 ops.push(InstructionRef {
57 address,
58 size: 4,
59 opcode: OPCODE_INVALID,
60 branch_dest: None,
61 });
62 continue;
63 }
64 },
65 }
66
67 let opcode = opcode_to_u16(ins.opcode);
68 let branch_dest =
69 branch_dest(opcode, address, &code[offset as usize..offset as usize + 4]);
70 ops.push(InstructionRef { address, size: 4, opcode, branch_dest });
71 }
72
73 Ok(ops)
74 }
75
76 fn display_instruction(
77 &self,

Callers

nothing calls this directly

Calls 3

opcode_to_u16Function · 0.85
branch_destFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected