Skip to content

Commit

Permalink
[PPC] Expose instruction formats (capstone-engine#2276)
Browse files Browse the repository at this point in the history
* Expose PPC formats in PPC details

* Add PPC format note in v6 release guide.

* Update python bindings
  • Loading branch information
Rot127 authored Feb 23, 2024
1 parent 122348b commit b4fde98
Show file tree
Hide file tree
Showing 7 changed files with 2,375 additions and 2,349 deletions.
13 changes: 13 additions & 0 deletions Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ void map_groups(MCInst *MI, const insn_map *imap)
#endif // CAPSTONE_DIET
}

/// Returns the pointer to the supllementary information in
/// the instruction mapping table @imap or NULL in case of failure.
const void *map_get_suppl_info(MCInst *MI, const insn_map *imap)
{
#ifndef CAPSTONE_DIET
if (!MI->flat_insn->detail)
return NULL;

unsigned Opcode = MCInst_getOpcode(MI);
return &imap[Opcode].suppl_info;
#endif // CAPSTONE_DIET
}

// Search for the CS instruction id for the given @MC_Opcode in @imap.
// return -1 if none is found.
unsigned int find_cs_id(unsigned MC_Opcode, const insn_map *imap,
Expand Down
2 changes: 2 additions & 0 deletions Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ void map_groups(MCInst *MI, const insn_map *imap);

void map_cs_id(MCInst *MI, const insn_map *imap, unsigned int imap_size);

const void *map_get_suppl_info(MCInst *MI, const insn_map *imap);

#define DECL_get_detail_op(arch, ARCH) \
cs_##arch##_op *ARCH##_get_detail_op(MCInst *MI, int offset);

Expand Down
4 changes: 4 additions & 0 deletions arch/PowerPC/PPCMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ void PPC_set_instr_map_data(MCInst *MI, const uint8_t *Bytes, size_t BytesLen)
map_groups(MI, ppc_insns);
PPC_add_branch_predicates(MI, Bytes, BytesLen);
PPC_check_updates_cr0(MI);
const ppc_suppl_info *suppl_info = map_get_suppl_info(MI, ppc_insns);
if (suppl_info) {
PPC_get_detail(MI)->format = suppl_info->form;
}
}

/// Inialize PPCs detail.
Expand Down
1 change: 1 addition & 0 deletions bindings/python/capstone/ppc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class CsPpc(ctypes.Structure):
_fields_ = (
('bc', PpcBC),
('update_cr0', ctypes.c_bool),
('format', ctypes.c_uint32),
('op_count', ctypes.c_uint8),
('operands', PpcOp * 8),
)
Expand Down
Loading

0 comments on commit b4fde98

Please sign in to comment.