Add RzConfig for asm plugins (#2488)
* Add function to add config node to config by `RzConfigNode*` * Move `SET<NODE>` macros to `rz_config.h` * Add un/set functions for plugin specific configs. * Add RzConfig and node setter to hexagon plugin. * Use plugins RzConfig to determine sdk syntax setting. * Use plugins RzConfig to determine if numbers should be signed. * Use plugins RzConfig to determine if immediate hash should be printed. * Remove unused parameter `rz_asm`. * Remove unused variable. * Remove unused callback. * Remove unused flags from `RzAsm` * Fix asm tests: Add NULL check; Set correct sign in asm test.
This commit is contained in:
parent
9fe9f09042
commit
628d04f713
13 changed files with 2867 additions and 2668 deletions
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
// LLVM commit: 96e220e6886868d6663d966ecc396befffc355e7
|
||||
// LLVM commit date: 2022-01-05 11:01:52 +0000 (ISO 8601 format)
|
||||
// Date of code generation: 2022-01-24 07:53:55-05:00
|
||||
// Date of code generation: 2022-04-02 06:42:08-04:00
|
||||
//========================================
|
||||
// The following code is generated.
|
||||
// Do not edit. Repository of code generator:
|
||||
|
|
@ -12,6 +12,11 @@
|
|||
#ifndef HEXAGON_H
|
||||
#define HEXAGON_H
|
||||
|
||||
#include <rz_asm.h>
|
||||
#include <rz_config.h>
|
||||
#include <rz_list.h>
|
||||
#include <rz_types.h>
|
||||
|
||||
#define MAX_CONST_EXT 512
|
||||
#define HEXAGON_STATE_PKTS 8
|
||||
|
||||
|
|
@ -126,6 +131,7 @@ typedef struct {
|
|||
HexPkt pkts[HEXAGON_STATE_PKTS]; // buffered instructions
|
||||
RzList *const_ext_l; // Constant extender values.
|
||||
RzAsm rz_asm; // Copy of RzAsm struct. Holds certain flags of interesed for disassembly formatting.
|
||||
RzConfig *cfg;
|
||||
} HexState;
|
||||
typedef enum {
|
||||
HEX_REG_CTR_REGS_SA0 = 0, // c0
|
||||
|
|
@ -550,37 +556,39 @@ char *hex_get_pred_regs(int opcode_reg);
|
|||
char *hex_get_sys_regs(int opcode_reg);
|
||||
char *hex_get_sys_regs64(int opcode_reg);
|
||||
|
||||
RZ_API RZ_BORROW RzConfig *hexagon_get_config();
|
||||
RZ_API void hex_extend_op(HexState *state, RZ_INOUT HexOp *op, const bool set_new_extender, const ut32 addr);
|
||||
int resolve_n_register(const int reg_num, const ut32 addr, const HexPkt *p);
|
||||
int hexagon_disasm_instruction(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, HexPkt *pkt);
|
||||
void hexagon_disasm_0x0(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x1(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x2(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x3(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x4(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x5(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x6(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x7(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x8(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x9(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xa(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xb(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xc(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xd(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xe(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x0(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x1(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x2(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x3(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x4(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x5(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x6(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x7(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x8(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x9(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xa(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xb(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xc(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xd(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xe(const RzAsm *rz_asm, HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
int hexagon_disasm_instruction(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, HexPkt *pkt);
|
||||
void hexagon_disasm_0x0(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x1(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x2(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x3(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x4(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x5(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x6(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x7(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x8(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0x9(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xa(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xb(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xc(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xd(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_0xe(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x0(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x1(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x2(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x3(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x4(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x5(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x6(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x7(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x8(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0x9(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xa(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xb(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xc(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xd(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
void hexagon_disasm_duplex_0xe(HexState *state, const ut32 hi_u32, RZ_INOUT HexInsn *hi, const ut32 addr, HexPkt *pkt);
|
||||
|
||||
#endif
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
// LLVM commit: 96e220e6886868d6663d966ecc396befffc355e7
|
||||
// LLVM commit date: 2022-01-05 11:01:52 +0000 (ISO 8601 format)
|
||||
// Date of code generation: 2022-01-24 07:53:55-05:00
|
||||
// Date of code generation: 2022-04-02 06:41:46-04:00
|
||||
//========================================
|
||||
// The following code is generated.
|
||||
// Do not edit. Repository of code generator:
|
||||
|
|
@ -372,6 +372,8 @@ static void hex_set_pkt_info(const RzAsm *rz_asm, RZ_INOUT HexInsn *hi, const He
|
|||
rz_return_if_fail(hi && p);
|
||||
bool is_first = (k == 0);
|
||||
HexPktInfo *hi_pi = &hi->pkt_info;
|
||||
HexState *state = hexagon_get_state();
|
||||
bool sdk_form = rz_config_get_b(state->cfg, "plugins.hexagon.sdk");
|
||||
|
||||
strncpy(hi_pi->mnem_postfix, "", 16);
|
||||
// Parse instr. position in pkt
|
||||
|
|
@ -379,9 +381,9 @@ static void hex_set_pkt_info(const RzAsm *rz_asm, RZ_INOUT HexInsn *hi, const He
|
|||
hi_pi->first_insn = true;
|
||||
hi_pi->last_insn = true;
|
||||
if (p->is_valid) {
|
||||
strncpy(hi_pi->mnem_prefix, get_pkt_indicator(rz_asm->utf8, rz_asm->hex_sdk, true, SINGLE_IN_PKT), 8);
|
||||
if (rz_asm->hex_sdk) {
|
||||
strncpy(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, rz_asm->hex_sdk, false, SINGLE_IN_PKT), 8);
|
||||
strncpy(hi_pi->mnem_prefix, get_pkt_indicator(rz_asm->utf8, sdk_form, true, SINGLE_IN_PKT), 8);
|
||||
if (sdk_form) {
|
||||
strncpy(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, sdk_form, false, SINGLE_IN_PKT), 8);
|
||||
}
|
||||
} else {
|
||||
strncpy(hi_pi->mnem_prefix, HEX_PKT_UNK, 8);
|
||||
|
|
@ -390,7 +392,7 @@ static void hex_set_pkt_info(const RzAsm *rz_asm, RZ_INOUT HexInsn *hi, const He
|
|||
hi_pi->first_insn = true;
|
||||
hi_pi->last_insn = false;
|
||||
if (p->is_valid) {
|
||||
strncpy(hi_pi->mnem_prefix, get_pkt_indicator(rz_asm->utf8, rz_asm->hex_sdk, true, FIRST_IN_PKT), 8);
|
||||
strncpy(hi_pi->mnem_prefix, get_pkt_indicator(rz_asm->utf8, sdk_form, true, FIRST_IN_PKT), 8);
|
||||
} else {
|
||||
strncpy(hi_pi->mnem_prefix, HEX_PKT_UNK, 8);
|
||||
}
|
||||
|
|
@ -398,22 +400,22 @@ static void hex_set_pkt_info(const RzAsm *rz_asm, RZ_INOUT HexInsn *hi, const He
|
|||
hi_pi->first_insn = false;
|
||||
hi_pi->last_insn = true;
|
||||
if (p->is_valid) {
|
||||
strncpy(hi_pi->mnem_prefix, get_pkt_indicator(rz_asm->utf8, rz_asm->hex_sdk, true, LAST_IN_PKT), 8);
|
||||
if (rz_asm->hex_sdk) {
|
||||
strncpy(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, rz_asm->hex_sdk, false, LAST_IN_PKT), 8);
|
||||
strncpy(hi_pi->mnem_prefix, get_pkt_indicator(rz_asm->utf8, sdk_form, true, LAST_IN_PKT), 8);
|
||||
if (sdk_form) {
|
||||
strncpy(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, sdk_form, false, LAST_IN_PKT), 8);
|
||||
}
|
||||
|
||||
switch (hex_get_loop_flag(p)) {
|
||||
default:
|
||||
break;
|
||||
case HEX_LOOP_01:
|
||||
strncat(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, rz_asm->hex_sdk, false, ELOOP_01_PKT), 23 - strlen(hi_pi->mnem_postfix));
|
||||
strncat(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, sdk_form, false, ELOOP_01_PKT), 23 - strlen(hi_pi->mnem_postfix));
|
||||
break;
|
||||
case HEX_LOOP_0:
|
||||
strncat(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, rz_asm->hex_sdk, false, ELOOP_0_PKT), 23 - strlen(hi_pi->mnem_postfix));
|
||||
strncat(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, sdk_form, false, ELOOP_0_PKT), 23 - strlen(hi_pi->mnem_postfix));
|
||||
break;
|
||||
case HEX_LOOP_1:
|
||||
strncat(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, rz_asm->hex_sdk, false, ELOOP_1_PKT), 23 - strlen(hi_pi->mnem_postfix));
|
||||
strncat(hi_pi->mnem_postfix, get_pkt_indicator(rz_asm->utf8, sdk_form, false, ELOOP_1_PKT), 23 - strlen(hi_pi->mnem_postfix));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -423,7 +425,7 @@ static void hex_set_pkt_info(const RzAsm *rz_asm, RZ_INOUT HexInsn *hi, const He
|
|||
hi_pi->first_insn = false;
|
||||
hi_pi->last_insn = false;
|
||||
if (p->is_valid) {
|
||||
strncpy(hi_pi->mnem_prefix, get_pkt_indicator(rz_asm->utf8, rz_asm->hex_sdk, true, MID_IN_PKT), 8);
|
||||
strncpy(hi_pi->mnem_prefix, get_pkt_indicator(rz_asm->utf8, sdk_form, true, MID_IN_PKT), 8);
|
||||
} else {
|
||||
strncpy(hi_pi->mnem_prefix, HEX_PKT_UNK, 8);
|
||||
}
|
||||
|
|
@ -806,7 +808,7 @@ RZ_API void hexagon_reverse_opcode(const RzAsm *rz_asm, HexReversedOpcode *rz_re
|
|||
HexPkt *p = hex_get_pkt(state, hi->addr);
|
||||
|
||||
// Do disasassembly and analysis
|
||||
hexagon_disasm_instruction(&state->rz_asm, state, data, hi, p);
|
||||
hexagon_disasm_instruction(state, data, hi, p);
|
||||
|
||||
switch (rz_reverse->action) {
|
||||
default:
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2,6 +2,7 @@
|
|||
// SPDX-FileCopyrightText: 2009-2021 nibble <nibble.ds@gmail.com>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <rz_list.h>
|
||||
#include <stdio.h>
|
||||
#include <rz_core.h>
|
||||
#include <rz_types.h>
|
||||
|
|
@ -304,6 +305,46 @@ RZ_API bool rz_asm_use_assembler(RzAsm *a, const char *name) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Copies all config nodes in \p pcfg to the config in \p rz_asm.
|
||||
*
|
||||
* \param rz_asm Pointer to RzAsm struct.
|
||||
* \param pcfg Pointer to the plugins RzConfig struct.
|
||||
*/
|
||||
static void set_plugin_configs(RZ_BORROW RzAsm *rz_asm, RZ_BORROW RzConfig *pcfg) {
|
||||
rz_return_if_fail(pcfg && rz_asm);
|
||||
|
||||
RzConfig *conf = ((RzCore *)(rz_asm->core))->config;
|
||||
RzConfigNode *n;
|
||||
RzListIter *it;
|
||||
rz_list_foreach_iter(pcfg->nodes, it) {
|
||||
n = it->data;
|
||||
if (!rz_config_add_node(conf, rz_config_node_clone(n))) {
|
||||
RZ_LOG_WARN("Failed to add \"%s\" to the global config.\n", n->name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Deletes all copies of \p pcfg nodes in the RzConfig from \p rz_asm.
|
||||
*
|
||||
* \param rz_asm Pointer to RzAsm struct.
|
||||
* \param pcfg Pointer to the plugins RzConfig struct.
|
||||
*/
|
||||
static void unset_plugins_config(RZ_BORROW RzAsm *rz_asm, RZ_BORROW RzConfig *pcfg) {
|
||||
rz_return_if_fail(pcfg && rz_asm && rz_asm->core);
|
||||
|
||||
RzConfig *conf = ((RzCore *)(rz_asm->core))->config;
|
||||
RzConfigNode *n;
|
||||
RzListIter *it;
|
||||
rz_list_foreach_iter(pcfg->nodes, it) {
|
||||
n = it->data;
|
||||
if (!rz_config_rm(conf, n->name)) {
|
||||
RZ_LOG_WARN("Failed to remove \"%s\" from the global config.", n->name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this can be optimized using rz_str_hash()
|
||||
RZ_API bool rz_asm_use(RzAsm *a, const char *name) {
|
||||
RzAsmPlugin *h;
|
||||
|
|
@ -311,6 +352,7 @@ RZ_API bool rz_asm_use(RzAsm *a, const char *name) {
|
|||
if (!a || !name) {
|
||||
return false;
|
||||
}
|
||||
RzCore *core = a->core;
|
||||
if (a->cur && !strcmp(a->cur->arch, name)) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -332,6 +374,16 @@ RZ_API bool rz_asm_use(RzAsm *a, const char *name) {
|
|||
RZ_LOG_ERROR("asm plugin '%s' failed to initialize.\n", h->name);
|
||||
return false;
|
||||
}
|
||||
if (a->cur && a->cur->get_config && core) {
|
||||
rz_config_lock(core->config, false);
|
||||
unset_plugins_config(a, a->cur->get_config());
|
||||
rz_config_lock(core->config, true);
|
||||
}
|
||||
if (h->get_config && core) {
|
||||
rz_config_lock(core->config, false);
|
||||
set_plugin_configs(a, h->get_config());
|
||||
rz_config_lock(core->config, true);
|
||||
}
|
||||
a->cur = h;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -299,6 +299,7 @@ rz_asm = library('rz_asm', rz_asm_sources,
|
|||
c_args: library_cflags,
|
||||
dependencies: [
|
||||
rz_util_dep,
|
||||
rz_config_dep,
|
||||
rz_syscall_dep,
|
||||
rz_flag_dep,
|
||||
rz_parse_dep,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
// LLVM commit: 96e220e6886868d6663d966ecc396befffc355e7
|
||||
// LLVM commit date: 2022-01-05 11:01:52 +0000 (ISO 8601 format)
|
||||
// Date of code generation: 2022-01-24 07:53:55-05:00
|
||||
// Date of code generation: 2022-04-02 05:15:46-04:00
|
||||
//========================================
|
||||
// The following code is generated.
|
||||
// Do not edit. Repository of code generator:
|
||||
|
|
@ -35,14 +35,69 @@ static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int l) {
|
|||
return op->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the plugins RzConfig nodes.
|
||||
*
|
||||
* \param user The user of the RzConfig node. If this callback is called by Core \p user = RzCore.
|
||||
* If it is called by the plugins config setup \p user = HexState.
|
||||
* \param data The node to set. Again, if called by RzCore \p date = Node from RzCore config.
|
||||
* If it is called by the plugins config setup \p data = a plugins config node.
|
||||
* \return bool True if the config was set. False otherwise.
|
||||
*/
|
||||
static bool hex_cfg_set(void *user, void *data) {
|
||||
rz_return_val_if_fail(user && data, false);
|
||||
HexState *state = hexagon_get_state();
|
||||
if (!state) {
|
||||
return false;
|
||||
}
|
||||
RzConfig *pcfg = state->cfg;
|
||||
|
||||
RzConfigNode *cnode = (RzConfigNode *)data; // Config node from core.
|
||||
RzConfigNode *pnode = rz_config_node_get(pcfg, cnode->name); // Config node of plugin.
|
||||
if (pnode == cnode) {
|
||||
return true;
|
||||
}
|
||||
if (cnode) {
|
||||
pnode->i_value = cnode->i_value;
|
||||
pnode->value = cnode->value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool hexagon_init(void **user) {
|
||||
HexState *state = hexagon_get_state();
|
||||
rz_return_val_if_fail(state, false);
|
||||
|
||||
*user = state; // user = RzAsm.plugin_data
|
||||
state->cfg = rz_config_new(state);
|
||||
rz_return_val_if_fail(state->cfg, false);
|
||||
|
||||
RzConfig *cfg = state->cfg; // Rename for SETCB macros.
|
||||
// Add nodes
|
||||
SETCB("plugins.hexagon.imm.hash", "true", &hex_cfg_set, "Display ## before 32bit immediates and # before immidiates with other width.");
|
||||
SETCB("plugins.hexagon.imm.sign", "true", &hex_cfg_set, "True: Print them with sign. False: Print signed immediates in unsigned representation.");
|
||||
SETCB("plugins.hexagon.sdk", "false", &hex_cfg_set, "Print packet syntax in objdump style.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RZ_API RZ_BORROW RzConfig *hexagon_get_config() {
|
||||
HexState *state = hexagon_get_state();
|
||||
rz_return_val_if_fail(state, NULL);
|
||||
return state->cfg;
|
||||
}
|
||||
|
||||
RzAsmPlugin rz_asm_plugin_hexagon = {
|
||||
.name = "hexagon",
|
||||
.arch = "hexagon",
|
||||
.author = "xvilka",
|
||||
.author = "Rot127",
|
||||
.license = "LGPL3",
|
||||
.bits = 32,
|
||||
.desc = "Qualcomm Hexagon (QDSP6) V6",
|
||||
.init = &hexagon_init,
|
||||
.disassemble = &disassemble,
|
||||
.get_config = &hexagon_get_config,
|
||||
};
|
||||
|
||||
#ifndef RZ_PLUGIN_INCORE
|
||||
|
|
|
|||
|
|
@ -352,6 +352,25 @@ beach:
|
|||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Appends the given node to the config \p cfg.
|
||||
*
|
||||
* \param cfg The configuration the node is appended.
|
||||
* \param node The node to append.
|
||||
* \return bool True if the node was successful added. False otherwise.
|
||||
*/
|
||||
RZ_API bool rz_config_add_node(RZ_BORROW RzConfig *cfg, RZ_OWN RzConfigNode *node) {
|
||||
rz_return_val_if_fail(cfg && node, false);
|
||||
if (cfg->lock) {
|
||||
RZ_LOG_WARN("Config locked. Plugin config node not copied.\n");
|
||||
rz_config_node_free(node);
|
||||
return false;
|
||||
}
|
||||
ht_pp_insert(cfg->ht, node->name, node);
|
||||
rz_list_append(cfg->nodes, node);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* rz_config_desc takes a RzConfig and a name,
|
||||
* rz_config_node_desc takes a RzConfigNode
|
||||
* Both set and return node->desc */
|
||||
|
|
@ -371,7 +390,7 @@ RZ_API const char *rz_config_node_desc(RzConfigNode *node, RZ_NULLABLE const cha
|
|||
}
|
||||
|
||||
RZ_API bool rz_config_rm(RzConfig *cfg, RZ_NONNULL const char *name) {
|
||||
rz_return_val_if_fail(RZ_STR_ISNOTEMPTY(name), NULL);
|
||||
rz_return_val_if_fail(RZ_STR_ISNOTEMPTY(name) && cfg, NULL);
|
||||
RzConfigNode *node = rz_config_node_get(cfg, name);
|
||||
if (node) {
|
||||
ht_pp_delete(cfg->ht, node->name);
|
||||
|
|
|
|||
|
|
@ -6,20 +6,10 @@
|
|||
#include <rz_basefind.h>
|
||||
#include <rz_th.h>
|
||||
#include <rz_windows.h>
|
||||
#include <rz_config.h>
|
||||
|
||||
#include "core_private.h"
|
||||
|
||||
#define NODECB(w, x, y) rz_config_set_cb(cfg, w, x, y)
|
||||
#define NODEICB(w, x, y) rz_config_set_i_cb(cfg, w, x, y)
|
||||
#define SETDESC(x, y) rz_config_node_desc(x, y)
|
||||
#define SETOPTIONS(x, ...) set_options(x, __VA_ARGS__)
|
||||
#define SETI(x, y, z) SETDESC(rz_config_set_i(cfg, x, y), z)
|
||||
#define SETB(x, y, z) SETDESC(rz_config_set_b(cfg, x, y), z)
|
||||
#define SETICB(w, x, y, z) SETDESC(NODEICB(w, x, y), z)
|
||||
#define SETPREF(x, y, z) SETDESC(rz_config_set(cfg, x, y), z)
|
||||
#define SETCB(w, x, y, z) SETDESC(NODECB(w, x, y), z)
|
||||
#define SETBPREF(x, y, z) SETDESC(NODECB(x, y, boolify_var_cb), z)
|
||||
|
||||
static bool boolify_var_cb(void *user, void *data) {
|
||||
RzConfigNode *node = (RzConfigNode *)data;
|
||||
if (node->i_value || rz_str_is_false(node->value)) {
|
||||
|
|
@ -852,13 +842,6 @@ static bool cb_asm_immhash(void *user, void *data) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool cb_asm_immsign(void *user, void *data) {
|
||||
RzCore *core = (RzCore *)user;
|
||||
RzConfigNode *node = (RzConfigNode *)data;
|
||||
core->rasm->immsign = node->i_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb_asm_invhex(void *user, void *data) {
|
||||
RzCore *core = (RzCore *)user;
|
||||
RzConfigNode *node = (RzConfigNode *)data;
|
||||
|
|
@ -2496,13 +2479,6 @@ static bool cb_bindbginfo(void *user, void *data) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool cb_hexsdk(void *user, void *data) {
|
||||
RzCore *core = (RzCore *)user;
|
||||
RzConfigNode *node = (RzConfigNode *)data;
|
||||
core->rasm->hex_sdk = (bool)node->i_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb_binprefix(void *user, void *data) {
|
||||
RzCore *core = (RzCore *)user;
|
||||
RzConfigNode *node = (RzConfigNode *)data;
|
||||
|
|
@ -3077,7 +3053,6 @@ RZ_API int rz_core_config_init(RzCore *core) {
|
|||
SETBPREF("asm.slow", "true", "Perform slow analysis operations in disasm");
|
||||
SETBPREF("asm.decode", "false", "Use code analysis as a disassembler");
|
||||
SETICB("asm.imm.hash", 0, &cb_asm_immhash, "Display # for immediates in ARM and Hexagon (0 = on)");
|
||||
SETCB("asm.imm.sign", "true", &cb_asm_immsign, "False: Print signed immediates in unsigned representation. True: Print them with sign.");
|
||||
SETBPREF("asm.imm.str", "true", "Show immediates values as strings");
|
||||
SETBPREF("asm.imm.trim", "false", "Remove all offsets and constants from disassembly");
|
||||
SETBPREF("asm.indent", "false", "Indent disassembly based on reflines depth");
|
||||
|
|
@ -3249,9 +3224,6 @@ RZ_API int rz_core_config_init(RzCore *core) {
|
|||
SETBPREF("bin.classes", "true", "Load classes from rbin on startup");
|
||||
SETCB("bin.verbose", "false", &cb_binverbose, "Show RzBin warnings when loading binaries");
|
||||
|
||||
/* plugins */
|
||||
SETCB("plugins.hexagon.sdk", "false", &cb_hexsdk, "Print packet syntax in objdump style. Hexagon only.");
|
||||
|
||||
/* prj */
|
||||
SETPREF("prj.file", "", "Path of the currently opened project");
|
||||
SETBPREF("prj.compress", "false", "Compress the project file while saving");
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <rz_util.h>
|
||||
#include <rz_parse.h>
|
||||
#include <rz_bind.h>
|
||||
#include <rz_config.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -115,10 +116,8 @@ typedef struct rz_asm_t {
|
|||
int pcalign;
|
||||
int dataalign;
|
||||
int bitshift;
|
||||
bool immdisp; // Display immediates with # symbol (for arm/hexagon architectures). false = show hashs
|
||||
bool immsign; // Print signed immediates as negative values, not their unsigned representation.
|
||||
bool immdisp; // Display immediates with # symbol (for arm architectures). false = show hashs
|
||||
bool utf8; // Flag for plugins: Use utf-8 characters.
|
||||
bool hex_sdk; // Hexagon arch only. Print packet syntax in hexagon-objdump style.
|
||||
HtPP *flags;
|
||||
int seggrn;
|
||||
bool pseudo;
|
||||
|
|
@ -139,6 +138,7 @@ typedef struct rz_asm_plugin_t {
|
|||
int (*disassemble)(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len);
|
||||
int (*assemble)(RzAsm *a, RzAsmOp *op, const char *buf);
|
||||
char *(*mnemonics)(RzAsm *a, int id, bool json);
|
||||
RzConfig *(*get_config)(void);
|
||||
const char *features;
|
||||
const char *platforms;
|
||||
} RzAsmPlugin;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,17 @@ RZ_LIB_VERSION_HEADER(rz_config);
|
|||
#define CN_RO 0x000010
|
||||
#define CN_RW 0x000020
|
||||
|
||||
#define NODECB(w, x, y) rz_config_set_cb(cfg, w, x, y)
|
||||
#define NODEICB(w, x, y) rz_config_set_i_cb(cfg, w, x, y)
|
||||
#define SETDESC(x, y) rz_config_node_desc(x, y)
|
||||
#define SETOPTIONS(x, ...) set_options(x, __VA_ARGS__)
|
||||
#define SETI(x, y, z) SETDESC(rz_config_set_i(cfg, x, y), z)
|
||||
#define SETB(x, y, z) SETDESC(rz_config_set_b(cfg, x, y), z)
|
||||
#define SETICB(w, x, y, z) SETDESC(NODEICB(w, x, y), z)
|
||||
#define SETPREF(x, y, z) SETDESC(rz_config_set(cfg, x, y), z)
|
||||
#define SETCB(w, x, y, z) SETDESC(NODECB(w, x, y), z)
|
||||
#define SETBPREF(x, y, z) SETDESC(NODECB(x, y, boolify_var_cb), z)
|
||||
|
||||
typedef bool (*RzConfigCallback)(void *user, void *data);
|
||||
|
||||
typedef struct rz_config_node_t {
|
||||
|
|
@ -81,6 +92,7 @@ RZ_API RzConfigNode *rz_config_set_b(RzConfig *cfg, RZ_NONNULL const char *name,
|
|||
RZ_API RzConfigNode *rz_config_set_cb(RzConfig *cfg, const char *name, const char *value, bool (*callback)(void *user, void *data));
|
||||
RZ_API RzConfigNode *rz_config_set_i_cb(RzConfig *cfg, const char *name, int ivalue, bool (*callback)(void *user, void *data));
|
||||
RZ_API RzConfigNode *rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value);
|
||||
RZ_API bool rz_config_add_node(RZ_BORROW RzConfig *cfg, RZ_OWN RzConfigNode *node);
|
||||
RZ_API bool rz_config_rm(RzConfig *cfg, RZ_NONNULL const char *name);
|
||||
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name);
|
||||
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name);
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ CMDS=<<EOF
|
|||
wx 00c0007f0bc0006900404d850040000076d09b9a0ac020690040007f07407c700040000087c40aab048063700080007f00c0007f
|
||||
e asm.arch=hexagon
|
||||
e analysis.arch=hexagon
|
||||
e asm.imm.hash=1
|
||||
e plugins.hexagon.imm.hash=false
|
||||
pi 13
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
|
|
@ -309,7 +309,7 @@ FILE=bins/elf/analysis/hexagon-hello-loop
|
|||
CMDS=<<EOF
|
||||
b 0x100000
|
||||
aar
|
||||
e asm.imm.sign=false
|
||||
e plugins.hexagon.imm.sign=false
|
||||
/ai -8
|
||||
/ai 0xffffff40 0xffffffff
|
||||
EOF
|
||||
|
|
@ -402,7 +402,7 @@ EXPECT=<<EOF
|
|||
| 0x00000020 / P2 = bitsclr(R14,#0x7)
|
||||
| 0x00000024 \ dcfetch(R1+#0x0)
|
||||
| 0x00000028 / P2 = and(P2,!P3)
|
||||
| 0x0000002c | if (P2.new) R2 = add(R2,##0xfffffff8)
|
||||
| 0x0000002c | if (P2.new) R2 = add(R2,##-0x8)
|
||||
| ,=< 0x00000030 \ if (P2.new) jump:nt 0x2b4
|
||||
EOF
|
||||
RUN
|
||||
|
|
@ -867,7 +867,7 @@ CMDS=<<EOF
|
|||
e analysis.jmp.cref=true
|
||||
e analysis.trap.after=true
|
||||
e asm.pcalign=4
|
||||
e asm.imm.sign=false
|
||||
e plugins.hexagon.imm.sign=false
|
||||
aaa
|
||||
s sym.sys_deinit_tls
|
||||
pd 11
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ d "? immext(##0x40)" 01400000 0x0
|
|||
d "? immext(##0xffffffc0)" ff7fff0f 0x0
|
||||
|
||||
d "? R0 = ##0x101" 20e00078 0x0
|
||||
d "? R5 = add(clb(R31),#0xffffffff)" 05ff3f8c 0x0
|
||||
d "? R5 = add(clb(R31),#-0x1)" 05ff3f8c 0x0
|
||||
d "? R4 = add(R19,##0x33)" 64c613b0 0x0
|
||||
|
||||
d "? nop" 00c0007f 0x10000000
|
||||
|
|
|
|||
|
|
@ -405,7 +405,7 @@ ad__ 16 dcpu16 PD Mojang's DCPU-16
|
|||
_dA_ 32 64 ebc LGPL3 EFI Bytecode (by Fedor Sakharov)
|
||||
adAe 16 gb LGPL3 GameBoy(TM) (z80-like) (by condret)
|
||||
_dAe 16 h8300 LGPL3 H8/300 disassembly plugin
|
||||
_dA_ 32 hexagon LGPL3 Qualcomm Hexagon (QDSP6) V6 (by xvilka)
|
||||
_dA_ 32 hexagon LGPL3 Qualcomm Hexagon (QDSP6) V6 (by Rot127)
|
||||
_dA_ 4 i4004 LGPL3 Intel 4004 microprocessor
|
||||
_dA_ 8 i8080 BSD Intel 8080 CPU
|
||||
adA_ 32 java LGPL-3 Java bytecode disassembler (by deroad)
|
||||
|
|
|
|||
Loading…
Reference in a new issue