MCPcopy Create free account
hub / github.com/LeoChen-CoreMind/VMPacker / Decode

Method Decode

pkg/arch/arm64/decoder.go:185–213  ·  view source on GitHub ↗

Decode 解码一条 ARM64 指令

(raw uint32, offset int)

Source from the content-addressed store, hash-verified

183
184// Decode 解码一条 ARM64 指令
185func (d *Decoder) Decode(raw uint32, offset int) vm.Instruction {
186 inst := vm.Instruction{Raw: raw, Op: int(UNKNOWN), Offset: offset, Rd: -1, Rn: -1, Rm: -1}
187
188 // NOP 快速路径
189 if raw == 0xD503201F {
190 inst.Op = int(NOP)
191 return inst
192 }
193
194 op0 := (raw >> 25) & 0xF
195
196 var matched bool
197 switch {
198 case op0>>1 == 0b100:
199 matched = matchAndDecode(raw, dpImmPatterns, &inst)
200 case op0>>1 == 0b101:
201 matched = matchAndDecode(raw, branchPatterns, &inst)
202 case op0&0b0101 == 0b0100:
203 matched = matchAndDecode(raw, ldstPatterns, &inst)
204 case op0&0b0111 == 0b0101, op0 == 0b1101:
205 matched = matchAndDecode(raw, dpRegPatterns, &inst)
206 }
207
208 if !matched {
209 inst.Op = int(UNSUPPORTED)
210 }
211
212 return inst
213}
214
215// InstName 返回指令名称
216func (d *Decoder) InstName(op int) string {

Callers 15

TestDecode_STP_64bitFunction · 0.95
TestDecode_LDP_64bitFunction · 0.95
TestDecode_ADD_IMMFunction · 0.95
TestDecode_SUB_REGFunction · 0.95
TestDecode_SUBS_REG_CMPFunction · 0.95
TestDecode_SUBS_IMM_CMPFunction · 0.95
TestDecode_MOVZFunction · 0.95
TestDecode_ORR_REG_MOVFunction · 0.95
TestDecode_LDR_REGFunction · 0.95

Calls 1

matchAndDecodeFunction · 0.85

Tested by 15

TestDecode_STP_64bitFunction · 0.76
TestDecode_LDP_64bitFunction · 0.76
TestDecode_ADD_IMMFunction · 0.76
TestDecode_SUB_REGFunction · 0.76
TestDecode_SUBS_REG_CMPFunction · 0.76
TestDecode_SUBS_IMM_CMPFunction · 0.76
TestDecode_MOVZFunction · 0.76
TestDecode_ORR_REG_MOVFunction · 0.76
TestDecode_LDR_REGFunction · 0.76