refactor: remove RzAsm struct from the public APIs (#6089)

* Remove RzAsm struct from the public APIs
* Forbid plugins from changing RzAsm contents
* Implement archinfo for RX
* Rename archinfo for SH
* Fix tests to use the new output
This commit is contained in:
Giovanni 2026-03-26 01:57:42 +08:00 committed by GitHub
parent 5d15b1295e
commit 4712c82435
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
153 changed files with 1235 additions and 887 deletions

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2009-2019 pancake <pancake@nopcode.org>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include "asm_private.h"
#include <rz_asm.h>
RZ_API RzAsmCode *rz_asm_code_new(void) {

View file

@ -403,9 +403,7 @@ RZ_API void rz_analysis_set_cpu(RzAnalysis *analysis, const char *cpu) {
free(analysis->cpu);
analysis->cpu = rz_str_dup(cpu);
int v = rz_analysis_archinfo(analysis, RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN);
if (v > 0) {
analysis->pcalign = v;
}
analysis->pcalign = RZ_MAX(1, v);
rz_analysis_set_reg_profile(analysis);
if (RZ_STR_EQ(cpu, analysis->typedb->target->cpu)) {
return;
@ -550,6 +548,10 @@ RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, RzAnalysisInfoType query)
rz_return_val_if_fail(analysis && query < RZ_ANALYSIS_ARCHINFO_ENUM_SIZE, -1);
if (!analysis->cur || !analysis->cur->archinfo) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
/* fall-thru */
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
/* fall-thru */
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
@ -561,6 +563,10 @@ RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, RzAnalysisInfoType query)
int value = analysis->cur->archinfo(analysis, query);
switch (query) {
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
/* fall-thru */
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
/* fall-thru */
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
// Always consume at least 1 byte
return value > 0 ? value : 1;

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2018-2020 pancake <pancake@nopcode.org>
// SPDX-License-Identifier: LGPL-3.0-only
#include "asm_private.h"
#include <rz_asm.h>
RZ_API RZ_OWN RzAsmOp *rz_asm_op_new(void) {

View file

@ -2,19 +2,16 @@
// SPDX-FileCopyrightText: 2009-2021 nibble <nibble.ds@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include "rz_util/rz_print.h"
#include <rz_vector.h>
#include <rz_util/rz_strbuf.h>
#include <rz_util/rz_regex.h>
#include <rz_util/rz_assert.h>
#include <rz_util/rz_path.h>
#include <rz_list.h>
#include <stdio.h>
#include <rz_asm.h>
#include <rz_core.h>
#include <rz_lib.h>
#include <rz_list.h>
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include <rz_util.h>
#include <rz_vector.h>
#include "asm_private.h"
#define USE_RZ_UTIL 1
#include <spp.h>
@ -280,7 +277,6 @@ RZ_API RzAsm *rz_asm_new(void) {
if (!a) {
return NULL;
}
a->dataalign = 1;
a->bits = RZ_SYS_BITS << 3;
a->bitshift = 0;
a->syntax = RZ_ASM_SYNTAX_INTEL;
@ -384,6 +380,26 @@ RZ_API bool rz_asm_plugin_del(RzAsm *a, RZ_NONNULL RzAsmPlugin *p) {
return ht_sp_delete(a->plugins, p->name);
}
RZ_API const RzAsmPlugin *rz_asm_plugin_current(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, false);
return a->cur;
}
RZ_API RZ_OWN RzIterator *rz_asm_plugin_iterator(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, false);
return ht_sp_as_iter(a->plugins);
}
RZ_API const RzAsmPlugin *rz_asm_plugin_find(RZ_NONNULL RzAsm *a, RZ_NONNULL const char *name) {
rz_return_val_if_fail(a && RZ_STR_ISNOTEMPTY(name), NULL);
bool found = false;
RzAsmPlugin *plugin = ht_sp_find(a->plugins, name, &found);
if (found) {
return plugin;
}
return NULL;
}
RZ_API bool rz_asm_is_valid(RzAsm *a, const char *name) {
if (!name || !*name) {
return false;
@ -424,31 +440,6 @@ RZ_API bool rz_asm_use_assembler(RzAsm *a, const char *name) {
return false;
}
/**
* \brief Appends the plugin configuration \p pcfg to the core plugin_config vector.
*
* \param rz_asm Pointer to RzAsm struct.
* \param pcfg Pointer to the plugins RzConfig struct.
*/
static void set_plugin_configs(RZ_BORROW RzCore *core, const char *plugin_name, RZ_OWN RzConfig *pcfg) {
rz_return_if_fail(pcfg && core);
rz_config_lock(pcfg, 1);
if (!ht_sp_insert(core->plugin_configs, plugin_name, pcfg)) {
RZ_LOG_WARN("Plugin '%s' was already added.\n", plugin_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 remove_plugin_config(RZ_BORROW RzCore *core, const char *plugin_name) {
rz_return_if_fail(core && plugin_name);
ht_sp_delete(core->plugin_configs, plugin_name);
}
static ut32 asm_get_first_default_bits(RzAsmPlugin *h) {
if (!h) {
return RZ_SYS_BITS << 3;
@ -467,6 +458,34 @@ static ut32 asm_get_first_default_bits(RzAsmPlugin *h) {
return RZ_SYS_BITS << 3;
}
/**
* \brief Returns the RzConfig of the arch
*
* \param RzAsm The RzAsm struct to use
*
* \return If the get_config callback is set, then must return a non-NULL value
*/
RZ_API RZ_OWN RzConfig *rz_asm_get_new_config(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, NULL);
if (!a->cur || !a->cur->get_config) {
return NULL;
}
return a->cur->get_config(a->plugin_data);
}
/**
* \brief Returns the opcode path of the arch
*
* \param a The RzAsm struct to use
* \param path The requested sys path
*
* \return On success returns a valid pointer, otherwise NULL.
*/
RZ_API RZ_OWN char *rz_asm_get_sys_opcode_path(RZ_NONNULL RzAsm *a, RZ_NONNULL const char *path) {
rz_return_val_if_fail(a && path, NULL);
return rz_path_system(a->sdb_opcodes_path, path);
}
// TODO: this can be optimized using rz_str_hash()
/**
* \brief Puts an Asm plugin in use and disables the previous one.
@ -486,7 +505,6 @@ RZ_API bool rz_asm_use(RzAsm *a, RZ_NULLABLE const char *name) {
}
RzIterator *iter = ht_sp_as_iter(a->plugins);
RzAsmPlugin **val;
RzCore *core = a->core;
rz_iterator_foreach(iter, val) {
RzAsmPlugin *h = *val;
if (h->arch && h->name && !strcmp(h->name, name)) {
@ -513,13 +531,6 @@ RZ_API bool rz_asm_use(RzAsm *a, RZ_NULLABLE const char *name) {
rz_iterator_free(iter);
return false;
}
if (a->cur && a->cur->get_config && core) {
remove_plugin_config(core, a->cur->name);
}
if (h->get_config && core) {
set_plugin_configs(core, h->name, h->get_config(a->plugin_data));
}
a->cur = h;
rz_iterator_free(iter);
RZ_FREE(a->features);
@ -535,16 +546,134 @@ RZ_API bool rz_asm_use(RzAsm *a, RZ_NULLABLE const char *name) {
}
RZ_DEPRECATE RZ_API void rz_asm_set_cpu(RzAsm *a, const char *cpu) {
if (a) {
free(a->cpu);
a->cpu = rz_str_dup(cpu);
if (!a) {
return;
}
free(a->cpu);
a->cpu = rz_str_dup(cpu);
}
RZ_API const char *rz_asm_get_cpu(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, "");
return a->cpu;
}
RZ_API const char *rz_asm_get_platforms(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, "");
return rz_str_get(a->platforms);
}
RZ_API void rz_asm_set_platforms(RZ_NONNULL RzAsm *a, RZ_NULLABLE const char *platforms) {
rz_return_if_fail(a);
free(a->platforms);
a->platforms = rz_str_dup(platforms);
}
RZ_API void rz_asm_set_features(RZ_NONNULL RzAsm *a, RZ_NULLABLE const char *features) {
rz_return_if_fail(a);
free(a->features);
a->features = rz_str_dup(features);
}
RZ_API const char *rz_asm_get_features(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, "");
return rz_str_get(a->features);
}
RZ_API void rz_asm_set_pseudo(RZ_NONNULL RzAsm *a, bool enable) {
rz_return_if_fail(a);
a->pseudo = enable;
}
RZ_API bool rz_asm_get_pseudo(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, "");
return a->pseudo;
}
RZ_API void rz_asm_set_utf8(RZ_NONNULL RzAsm *a, bool utf8) {
rz_return_if_fail(a);
a->utf8 = utf8;
}
RZ_API bool rz_asm_get_utf8(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, false);
return a->utf8;
}
RZ_API void rz_asm_set_segment_granularity(RZ_NONNULL RzAsm *a, int seggrn) {
rz_return_if_fail(a);
a->seggrn = seggrn;
}
RZ_API int rz_asm_get_segment_granularity(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, false);
return a->seggrn;
}
RZ_API void rz_asm_set_pc_align(RZ_NONNULL RzAsm *a, ut32 pc_align) {
rz_return_if_fail(a);
if (pc_align < 2) {
pc_align = 1;
}
a->pcalign = pc_align;
}
RZ_API ut32 rz_asm_get_pc_align(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, 1);
if (a->pcalign < 2) {
return 1;
}
return a->pcalign;
}
RZ_API void rz_asm_set_syscall(RZ_NONNULL RzAsm *a, RzSyscall *syscall) {
rz_return_if_fail(a);
a->syscall = syscall;
}
RZ_API RzSyscall *rz_asm_get_syscall(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, NULL);
return a->syscall;
}
RZ_API void rz_asm_set_invalid_as_hex_flag(RZ_NONNULL RzAsm *a, bool invhex) {
rz_return_if_fail(a);
a->invhex = invhex;
}
RZ_API bool rz_asm_get_invalid_as_hex_flag(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, false);
return a->invhex;
}
RZ_API void rz_asm_set_show_immediate_hashtag(RZ_NONNULL RzAsm *a, bool show) {
rz_return_if_fail(a);
a->immdisp = show;
}
RZ_API bool rz_asm_get_show_immediate_hashtag(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, false);
return a->immdisp;
}
static bool has_bits(RzAsmPlugin *h, int bits) {
return (h && h->bits && (bits & h->bits));
}
RZ_DEPRECATE RZ_API void rz_asm_set_core(RZ_NONNULL RzAsm *a, RZ_NULLABLE void *core) {
rz_return_if_fail(a);
a->core = core;
}
RZ_DEPRECATE RZ_API RZ_BORROW RzBinBind *rz_asm_get_bin_bind(RzAsm *a) {
rz_return_val_if_fail(a, NULL);
return &a->binb;
}
RZ_DEPRECATE RZ_API int rz_asm_set_bits(RzAsm *a, int bits) {
if (has_bits(a->cur, bits)) {
if (a->bits != bits) {
@ -555,11 +684,46 @@ RZ_DEPRECATE RZ_API int rz_asm_set_bits(RzAsm *a, int bits) {
return false;
}
RZ_DEPRECATE RZ_API int rz_asm_get_bits(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, 0);
return a->bits;
}
RZ_DEPRECATE RZ_API bool rz_asm_is_bits(RzAsm *a, int bits) {
rz_return_val_if_fail(a, false);
return a->bits == bits;
}
RZ_DEPRECATE RZ_API int rz_asm_get_plugin_bits(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, 0);
return a->cur ? a->cur->bits : 0;
}
RZ_DEPRECATE RZ_API const char *rz_asm_get_plugin_cpus(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, NULL);
return a->cur ? rz_str_get(a->cur->cpus) : "";
}
RZ_DEPRECATE RZ_API const char *rz_asm_get_plugin_platforms(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, NULL);
return a->cur ? rz_str_get(a->cur->platforms) : "";
}
RZ_DEPRECATE RZ_API const char *rz_asm_get_plugin_features(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, NULL);
return a->cur ? rz_str_get(a->cur->features) : "";
}
RZ_API ut32 rz_asm_get_endianness(RzAsm *a) {
rz_return_val_if_fail(a && a->cur, RZ_SYS_ENDIAN_NONE);
return a->cur->endian;
}
RZ_API bool rz_asm_is_big_endian_set(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, false);
return a->big_endian;
}
RZ_API bool rz_asm_support_endianness(RzAsm *a, ut32 endian) {
rz_return_val_if_fail(a && a->cur, false);
@ -593,24 +757,29 @@ RZ_API bool rz_asm_set_big_endian(RzAsm *a, bool b) {
return a->big_endian;
}
RZ_API bool rz_asm_set_syntax(RzAsm *a, int syntax) {
// TODO: move into rz_arch ?
switch (syntax) {
case RZ_ASM_SYNTAX_REGNUM:
case RZ_ASM_SYNTAX_INTEL:
case RZ_ASM_SYNTAX_MASM:
case RZ_ASM_SYNTAX_ATT:
case RZ_ASM_SYNTAX_JZ:
a->syntax = syntax;
return true;
default:
return false;
}
RZ_API void rz_asm_set_syntax(RZ_NONNULL RzAsm *a, RzAsmSyntax syntax) {
rz_return_if_fail(a && syntax < RZ_ASM_ENUM_SIZE);
a->syntax = syntax;
}
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc) {
RZ_API RzAsmSyntax rz_asm_get_syntax(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, RZ_ASM_SYNTAX_NONE);
return a->syntax;
}
RZ_API bool rz_asm_is_syntax(RZ_NONNULL RzAsm *a, RzAsmSyntax syntax) {
rz_return_val_if_fail(a, false);
return a->syntax == syntax;
}
RZ_API ut64 rz_asm_get_pc(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, 0);
return a->pc;
}
RZ_API void rz_asm_set_pc(RZ_NONNULL RzAsm *a, ut64 pc) {
rz_return_if_fail(a);
a->pc = pc;
return true;
}
static bool __isInvalid(RzAsmOp *op) {
@ -685,7 +854,7 @@ RZ_API int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return ret;
}
typedef int (*Ase)(RzAsm *a, RzAsmOp *op, const char *buf);
typedef int (*Ase)(const RzAsm *a, RzAsmOp *op, const char *buf);
static bool assemblerMatches(RzAsm *a, RzAsmPlugin *h) {
if (!a || !h->arch || !h->assemble || !has_bits(h, a->bits)) {
@ -1285,6 +1454,11 @@ RZ_API char *rz_asm_describe(RzAsm *a, const char *str) {
return (a && a->pair) ? sdb_get(a->pair, str) : NULL;
}
RZ_API void rz_asm_describe_iterate(RZ_NONNULL RzAsm *a, RZ_NONNULL SdbForeachCallback cb, RZ_NULLABLE void *user) {
rz_return_if_fail(a);
sdb_foreach(a->pair, cb, user);
}
RZ_API RZ_BORROW HtSP /*<RzAsmPlugin *>*/ *rz_asm_get_plugins(RZ_BORROW RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, NULL);
return a->plugins;
@ -1294,6 +1468,16 @@ RZ_API bool rz_asm_set_arch(RzAsm *a, const char *name, int bits) {
return rz_asm_use(a, name) ? rz_asm_set_bits(a, bits) : false;
}
RZ_API const char *rz_asm_get_arch(RZ_NONNULL RzAsm *a) {
rz_return_val_if_fail(a, RZ_SYS_ARCH);
return a->cur ? a->cur->name : RZ_SYS_ARCH;
}
RZ_API bool rz_asm_is_arch(RZ_NONNULL RzAsm *a, RZ_NONNULL const char *name) {
rz_return_val_if_fail(a && RZ_STR_ISNOTEMPTY(name), false);
return a->cur && RZ_STR_EQ(a->cur->name, name);
}
/* to ease the use of the native bindings (not used in rizin) */
RZ_API char *rz_asm_to_string(RzAsm *a, ut64 addr, const ut8 *b, int l) {
rz_return_val_if_fail(a && b && l >= 0, NULL);

46
librz/arch/asm_private.h Normal file
View file

@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: 2009-2020 nibble <nibble.ds@gmail.com>
// SPDX-FileCopyrightText: 2009-2020 pancake <pancake@nopcode.org>
// SPDX-License-Identifier: LGPL-3.0-only
#ifndef RZ_ASM_PRIVATE_H
#define RZ_ASM_PRIVATE_H
#include <rz_types.h>
#include <rz_util.h>
#include <rz_asm.h>
struct rz_asm_t {
void *core; /// should not be used.
ut8 ptr_alignment_I;
void *plugin_data;
ut8 ptr_alignment_II;
// NOTE: Do not change the order of fields above!
// They are used in pointer passing hacks in rz_types.h.
char *cpu;
int bits;
int big_endian;
int syntax;
ut64 pc;
RzAsmPlugin *cur;
RzAsmPlugin *acur;
HtSP /*<RzAsmPlugin *>*/ *plugins;
RzBinBind binb;
RzParse *ifilter;
RzParse *ofilter;
Sdb *pair;
RzSyscall *syscall;
RzPath *sdb_opcodes_path; ///< pointer to RzPath, contains path prefix of the system
char *features;
char *platforms;
int invhex; // invalid instructions displayed in hex
int pcalign;
int bitshift;
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.
HtSS *flags;
int seggrn;
bool pseudo;
};
#endif // RZ_ASM_PRIVATE_H

View file

@ -3,8 +3,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include "binutils_as.h"
#include "asm_private.h"
int binutils_assemble(RzAsm *a, RzAsmOp *op, const char *buf, const char *as, const char *env, const char *header, const char *cmd_opt) {
int binutils_assemble(const RzAsm *a, RzAsmOp *op, const char *buf, const char *as, const char *env, const char *header, const char *cmd_opt) {
char *user_as = rz_sys_getenv(env);
if (user_as) {
as = user_as;

View file

@ -7,6 +7,6 @@
#include <rz_types.h>
#include <rz_asm.h>
int binutils_assemble(RzAsm *a, RzAsmOp *op, const char *buf, const char *as, const char *env, const char *header, const char *cmd_opt);
int binutils_assemble(const RzAsm *a, RzAsmOp *op, const char *buf, const char *as, const char *env, const char *header, const char *cmd_opt);
#endif

View file

@ -6,6 +6,7 @@
#define DEPRECATED_ARCH_HELPER_H
#include <rz_arch.h>
#include "asm_private.h"
#define DEPRECATED_OLD_ARCH_PLUGIN(name) \
RzArchPlugin rz_arch_plugin_##name = { \

View file

@ -1180,8 +1180,8 @@ static parse_mnem_args mnemonic(char const *user_asm, int *nargs) {
* ## Section 7: rizin glue and mnemonic tokenization
--------------------------------------*/
int assemble_8051(RzAsm *a, RzAsmOp *op, char const *user_asm) {
if (!a || !op || !user_asm) {
RZ_IPI int assemble_8051(RzAsmOp *op, ut64 pc, char const *user_asm) {
if (!op || !user_asm) {
return 0;
}
rz_strbuf_set(&op->buf_asm, user_asm);
@ -1216,7 +1216,7 @@ int assemble_8051(RzAsm *a, RzAsmOp *op, char const *user_asm) {
}
ut8 instr[4] = { 0 };
ut8 *binp = instr;
if (!mnem(carg, a->pc, &binp)) {
if (!mnem(carg, pc, &binp)) {
free(arg[0]);
arg[0] = 0;
carg[2] = 0;

View file

@ -6,6 +6,6 @@
#include <rz_asm.h>
int assemble_8051(RzAsm *a, RzAsmOp *op, char const *user_asm);
RZ_IPI int assemble_8051(RzAsmOp *op, ut64 pc, char const *user_asm);
#endif /* ASSEMBLE_8051_H */

View file

@ -69,5 +69,5 @@ enum {
};
int gbDisass(RzAsmOp *op, const ut8 *buf, int len);
int gbAsm(RzAsm *a, RzAsmOp *op, const char *buf);
int gbAsm(const RzAsm *a, RzAsmOp *op, const char *buf);
#endif

View file

@ -203,7 +203,7 @@ static bool gb_parse_ld3(ut8 *buf, char *buf_asm) {
return true;
}
int gbAsm(RzAsm *a, RzAsmOp *op, const char *buf) {
RZ_IPI int gbAsm(const RzAsm *a, RzAsmOp *op, const char *buf) {
int mn_len, j, len = 1;
ut32 mn = 0;
ut64 num;

View file

@ -150,7 +150,7 @@ static void gb_hardware_register_name(char *reg, ut8 offset) {
}
}
int gbDisass(RzAsmOp *op, const ut8 *buf, int len) {
RZ_IPI int gbDisass(RzAsmOp *op, const ut8 *buf, int len) {
int foo = gbOpLength(gb_op[buf[0]].type);
if (len < foo) {
return 0;

View file

@ -9,15 +9,15 @@
// Do not edit. Repository of code generator:
// https://github.com/rizinorg/rz-hexagon
#include "rz_types.h"
#include <rz_util/rz_log.h>
#include <rz_util/rz_buf.h>
#include <rz_types.h>
#include <rz_util.h>
#include <rz_list.h>
#include <rz_util/rz_assert.h>
#include <rz_asm.h>
#include <rz_analysis.h>
#include <rz_util.h>
#include <rz_vector.h>
#include "asm_private.h"
#include <hexagon/hexagon.h>
#include <hexagon/hexagon_insn.h>
#include <hexagon/hexagon_arch.h>
@ -1209,7 +1209,7 @@ static ut64 get_pre_decoding_start(RZ_BORROW RzBuffer *buffer, ut64 addr) {
*/
static void perform_hacks(RZ_NONNULL HexState **state,
RZ_NONNULL RzBuffer **buffer,
RZ_NONNULL RzAsm **rz_asm,
RZ_NONNULL const RzAsm **rz_asm,
RZ_NONNULL RzAnalysis **rz_analysis,
RZ_NONNULL HexReversedOpcode *rz_reverse) {
if (*rz_analysis) {
@ -1257,7 +1257,7 @@ static inline bool do_decoding_loop(ut64 current_addr, ut64 requested_addr, cons
* \param addr The address of the current opcode.
* \param copy_result If set, it copies the result. Otherwise it only buffers it in the internal state.
*/
RZ_API void hexagon_reverse_opcode(HexReversedOpcode *rz_reverse, const ut64 addr, RzAsm *rz_asm, RzAnalysis *rz_analysis) {
RZ_API void hexagon_reverse_opcode(HexReversedOpcode *rz_reverse, const ut64 addr, const RzAsm *rz_asm, RzAnalysis *rz_analysis) {
rz_return_if_fail(rz_reverse);
HexState *state;
RzBuffer *buffer;

View file

@ -75,7 +75,7 @@ RZ_API void hex_insn_container_free(RZ_NULLABLE HexInsnContainer *c);
RZ_API void hex_const_ext_free(RZ_NULLABLE HexConstExt *ce);
RZ_IPI RZ_OWN HexState *hexagon_state_new();
RZ_IPI void hexagon_state_fini(RZ_NULLABLE HexState *state);
RZ_API void hexagon_reverse_opcode(HexReversedOpcode *rz_reverse, const ut64 addr, RzAsm *rz_asm, RzAnalysis *rz_analysis);
RZ_API void hexagon_reverse_opcode(HexReversedOpcode *rz_reverse, const ut64 addr, const RzAsm *rz_asm, RzAnalysis *rz_analysis);
RZ_API ut8 hexagon_get_pkt_index_of_addr(const ut32 addr, const HexPkt *p);
RZ_API HexLoopAttr hex_get_loop_flag(const HexPkt *p);
RZ_API const HexOp *hex_isa_to_reg(const HexInsn *hi, const char isa_id, bool new_reg);

View file

@ -590,10 +590,10 @@ bool pic_highend_disasm_op(PicHighendOp *op, ut64 addr, const ut8 *buff, ut64 le
return true;
}
int pic_highend_disassemble(RzAsm *a, RzAsmOp *asm_op, const ut8 *b, int blen) {
int pic_highend_disassemble(RzAsmOp *asm_op, ut64 addr, const ut8 *b, int blen) {
asm_op->size = 2;
PicHighendOp op = { 0 };
if (!pic_highend_disasm_op(&op, a->pc, b, blen) ||
if (!pic_highend_disasm_op(&op, addr, b, blen) ||
op.code == PIC_HIGHEND_OPCODE_INVALID) {
rz_asm_op_set_asm(asm_op, "invalid");
return -1;

View file

@ -146,7 +146,7 @@ ut8 pic_highend_status(const char *name);
ut8 pic_highend_rcon(const char *name);
ut8 pic_highend_intcon(const char *name);
bool pic_highend_disasm_op(PicHighendOp *op, ut64 addr, const ut8 *buff, ut64 len);
int pic_highend_disassemble(RzAsm *a, RzAsmOp *asm_op, const ut8 *b, int l);
int pic_highend_disassemble(RzAsmOp *asm_op, ut64 addr, const ut8 *b, int l);
int pic_highend_op(RzAnalysis *analysis, RzAnalysisOp *aop, ut64 addr,
const ut8 *buf, int len, RzAnalysisOpMask mask);

View file

@ -33,7 +33,7 @@ void tms320_c64x_free(void *p) {
free(ctx);
}
int tms320_c64x_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len, void *c64x) {
int tms320_c64x_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len, void *c64x) {
TMSContext *ctx = (TMSContext *)c64x;
cs_insn *insn;
@ -82,7 +82,7 @@ fin:
return ret;
}
char *tms320_c64x_mnemonics(RzAsm *a, int id, bool json, void *c64x) {
char *tms320_c64x_mnemonics(const RzAsm *a, int id, bool json, void *c64x) {
TMSContext *ctx = (TMSContext *)c64x;
a->cur->disassemble(a, NULL, NULL, -1);
if (id != -1) {

View file

@ -5,6 +5,7 @@
#define TMS320_C64X_CAPSTONE_H
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_util.h>
#include <rz_analysis.h>
#include <capstone/capstone.h>
@ -13,8 +14,8 @@
void *tms320_c64x_new();
void tms320_c64x_free(void *p);
int tms320_c64x_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len, void *c64x);
char *tms320_c64x_mnemonics(RzAsm *a, int id, bool json, void *c64x);
int tms320_c64x_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len, void *c64x);
char *tms320_c64x_mnemonics(const RzAsm *a, int id, bool json, void *c64x);
int tms320_c64x_op(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask, void *c64x);
#else

View file

@ -1824,7 +1824,7 @@ static int _6502_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8
return op->size;
}
static char *get_reg_profile(RzAnalysis *analysis) {
static char *_6502_get_reg_profile(RzAnalysis *analysis) {
char *p =
"=PC pc\n"
"=SP sp\n"
@ -1849,7 +1849,7 @@ static char *get_reg_profile(RzAnalysis *analysis) {
return rz_str_dup(p);
}
static int esil_6502_init(RzAnalysisEsil *esil) {
static int _6502_esil_init(RzAnalysisEsil *esil) {
if (esil->analysis && esil->analysis->reg) { // initial values
rz_reg_set_value(esil->analysis->reg, rz_reg_get(esil->analysis->reg, "pc", -1), 0x0000);
rz_reg_set_value(esil->analysis->reg, rz_reg_get(esil->analysis->reg, "sp", -1), 0xff);
@ -1861,11 +1861,11 @@ static int esil_6502_init(RzAnalysisEsil *esil) {
return true;
}
static int esil_6502_fini(RzAnalysisEsil *esil) {
static int _6502_esil_fini(RzAnalysisEsil *esil) {
return true;
}
static int address_bits(RzAnalysis *analysis, int bits) {
static int _6502_address_bits(RzAnalysis *analysis, int bits) {
return 16;
}
@ -1880,18 +1880,35 @@ static RzAnalysisILConfig *_6502_il_config(RzAnalysis *analysis) {
return rz_analysis_il_config_new(16, false, 16);
}
static int _6502_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
return 1;
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return 4;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
return -1;
}
}
RzAnalysisPlugin rz_analysis_plugin_6502 = {
.name = "6502",
.desc = "6502/NES analysis plugin",
.license = "LGPL3",
.arch = "6502",
.bits = 8,
.address_bits = address_bits,
.address_bits = _6502_address_bits,
.op = &_6502_op,
.get_reg_profile = &get_reg_profile,
.get_reg_profile = &_6502_get_reg_profile,
.esil = true,
.esil_init = esil_6502_init,
.esil_fini = esil_6502_fini,
.il_config = _6502_il_config
.esil_init = _6502_esil_init,
.esil_fini = _6502_esil_fini,
.il_config = _6502_il_config,
.archinfo = _6502_archinfo,
};

View file

@ -441,8 +441,11 @@ static int archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return 4;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
return 4;
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
return -1;
}

View file

@ -1963,7 +1963,7 @@ static int gb_anop(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8
the mbc can be seen as a register but it isn't. For the Gameboy the mbc is invisble.
*/
static char *get_reg_profile(RzAnalysis *analysis) {
static char *gb_get_reg_profile(RzAnalysis *analysis) {
const char *p =
"=PC mpc\n"
"=SP sp\n"
@ -2005,7 +2005,7 @@ static char *get_reg_profile(RzAnalysis *analysis) {
return rz_str_dup(p);
}
static int esil_gb_init(RzAnalysisEsil *esil) {
static int gb_esil_init(RzAnalysisEsil *esil) {
GBUser *user = RZ_NEW0(GBUser);
rz_analysis_esil_set_op(esil, "daa", gb_custom_daa, 1, 1, RZ_ANALYSIS_ESIL_OP_TYPE_MATH | RZ_ANALYSIS_ESIL_OP_TYPE_CUSTOM);
if (user) {
@ -2028,7 +2028,7 @@ static int esil_gb_init(RzAnalysisEsil *esil) {
return true;
}
static int esil_gb_fini(RzAnalysisEsil *esil) {
static int gb_esil_fini(RzAnalysisEsil *esil) {
RZ_FREE(esil->cb.user);
return true;
}
@ -2037,12 +2037,29 @@ static const char *gb_regs_bound[] = {
"a", "b", "c", "d", "e", "h", "l", "sp", "Z", "N", "H", "C", "ime", NULL
};
static RzAnalysisILConfig *il_config(RzAnalysis *analysis) {
static RzAnalysisILConfig *gb_il_config(RzAnalysis *analysis) {
RzAnalysisILConfig *r = rz_analysis_il_config_new(32, false, 16);
r->reg_bindings = gb_regs_bound;
return r;
}
static int gb_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
return 1;
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return 3;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
return -1;
}
}
RzAnalysisPlugin rz_analysis_plugin_gb = {
.name = "gb",
.desc = "Gameboy CPU code analysis plugin",
@ -2051,8 +2068,9 @@ RzAnalysisPlugin rz_analysis_plugin_gb = {
.esil = true,
.bits = 16,
.op = &gb_anop,
.get_reg_profile = &get_reg_profile,
.esil_init = esil_gb_init,
.esil_fini = esil_gb_fini,
.il_config = il_config
.get_reg_profile = &gb_get_reg_profile,
.esil_init = gb_esil_init,
.esil_fini = gb_esil_fini,
.il_config = gb_il_config,
.archinfo = gb_archinfo,
};

View file

@ -493,6 +493,23 @@ static RzList /*<RzSearchKeyword *>*/ *h8300_preludes(RzAnalysis *analysis) {
return kws;
}
static int h8300_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
return 2;
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return 4;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
return 2;
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
return -1;
}
}
RzAnalysisPlugin rz_analysis_plugin_h8300 = {
.name = "h8300",
.desc = "H8300 code analysis plugin",
@ -504,4 +521,5 @@ RzAnalysisPlugin rz_analysis_plugin_h8300 = {
.get_reg_profile = get_reg_profile,
.il_config = h8300_il_config,
.preludes = h8300_preludes,
.archinfo = h8300_archinfo,
};

View file

@ -24,9 +24,6 @@ RZ_API int hexagon_v6_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, cons
if (len < HEX_INSN_SIZE) {
return -1;
}
if (analysis->pcalign != HEX_PC_ALIGNMENT) {
analysis->pcalign = HEX_PC_ALIGNMENT;
}
// Disassemble as many instructions as possible from the buffer.
HexReversedOpcode rev = { .action = HEXAGON_ANALYSIS, .ana_op = op, .asm_op = NULL, .state = NULL, .pkt_fully_decoded = false, .bytes_buf = buf, .bytes_buf_len = len };
@ -42,7 +39,7 @@ RZ_API int hexagon_v6_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, cons
return op->size;
}
static RzAnalysisILConfig *rz_hexagon_il_config(RzAnalysis *a) {
static RzAnalysisILConfig *hexagon_il_config(RzAnalysis *a) {
rz_return_val_if_fail(a, NULL);
// Hacky getter for the plugin data until RzArch is implemented
RzAsm *rasm = rz_analysis_to_rz_asm(a);
@ -53,7 +50,7 @@ static RzAnalysisILConfig *rz_hexagon_il_config(RzAnalysis *a) {
return rz_analysis_il_config_new(32, a->big_endian, 32);
}
RZ_API char *get_reg_profile(RzAnalysis *analysis) {
RZ_API char *hexagon_get_reg_profile(RzAnalysis *analysis) {
const char *p =
"=PC C9\n"
"=SP R29\n"
@ -743,6 +740,23 @@ RZ_API char *get_reg_profile(RzAnalysis *analysis) {
return rz_str_dup(p);
}
static int hexagon_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
return HEX_INSN_SIZE;
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return HEX_INSN_SIZE * HEX_MAX_INSN_PER_PKT;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
return HEX_PC_ALIGNMENT;
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 4;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
return -1;
}
}
RzAnalysisPlugin rz_analysis_plugin_hexagon = {
.name = "hexagon",
.desc = "Qualcomm Hexagon (QDSP6) V6",
@ -750,7 +764,8 @@ RzAnalysisPlugin rz_analysis_plugin_hexagon = {
.arch = "hexagon",
.bits = 32,
.op = hexagon_v6_op,
.archinfo = hexagon_archinfo,
.esil = false,
.get_reg_profile = get_reg_profile,
.il_config = rz_hexagon_il_config,
.get_reg_profile = hexagon_get_reg_profile,
.il_config = hexagon_il_config,
};

View file

@ -790,6 +790,23 @@ static bool m68k_fini(void *user) {
return true;
}
static int m68k_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
return 2;
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return 4;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
return 2;
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
return -1;
}
}
RzAnalysisPlugin rz_analysis_plugin_m68k_cs = {
.name = "m68k",
.desc = "Capstone M68K analyzer",
@ -801,7 +818,9 @@ RzAnalysisPlugin rz_analysis_plugin_m68k_cs = {
.op = &m68k_analyze_op,
.init = m68k_init,
.fini = m68k_fini,
.archinfo = m68k_archinfo,
};
#else
RzAnalysisPlugin rz_analysis_plugin_m68k_cs = {
.name = "m68k (unsupported)",

View file

@ -237,7 +237,7 @@ static RzStructuredData *ppc_opex(csh handle, cs_insn *insn) {
#define ARG(n) getarg2(a, &gop, n, "")
#define ARG2(n, m) getarg2(a, &gop, n, m)
static char *get_reg_profile(RzAnalysis *analysis) {
static char *ppc_get_reg_profile(RzAnalysis *analysis) {
const char *p = NULL;
if (analysis->bits == 64) {
p =
@ -946,7 +946,7 @@ static char *shrink(char *op) {
return op;
}
static int analyze_op(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask) {
static int ppc_analyze_op(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask) {
PPCContext *ctx = (PPCContext *)a->plugin_data;
int n, ret;
cs_insn *insn;
@ -1751,7 +1751,7 @@ static int analyze_op(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf
return op->size;
}
static int archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
static int ppc_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
bool is_vle = a && a->cpu && !strncmp(a->cpu, "vle", 3);
switch (query) {
@ -1759,6 +1759,10 @@ static int archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
return is_vle ? 2 : 4;
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return 4;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
return is_vle ? 2 : 4;
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
@ -1766,14 +1770,14 @@ static int archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
}
}
static RzList /*<RzSearchKeyword *>*/ *analysis_preludes(RzAnalysis *analysis) {
static RzList /*<RzSearchKeyword *>*/ *ppc_analysis_preludes(RzAnalysis *analysis) {
#define KW(d, ds, m, ms) rz_list_append(l, rz_search_keyword_new((const ut8 *)d, ds, (const ut8 *)m, ms, NULL))
RzList *l = rz_list_newf((RzListFree)rz_search_keyword_free);
KW("\x7c\x08\x02\xa6", 4, NULL, 0);
return l;
}
static RzAnalysisILConfig *il_config(RzAnalysis *analysis) {
static RzAnalysisILConfig *ppc_il_config(RzAnalysis *analysis) {
if (analysis->bits == 64) {
return rz_ppc_cs_64_il_config(analysis->big_endian);
}
@ -1796,13 +1800,13 @@ RzAnalysisPlugin rz_analysis_plugin_ppc_cs = {
.esil = true,
.arch = "ppc",
.bits = 32 | 64,
.archinfo = archinfo,
.preludes = analysis_preludes,
.op = &analyze_op,
.archinfo = ppc_archinfo,
.preludes = ppc_analysis_preludes,
.op = &ppc_analyze_op,
.init = ppc_init,
.fini = ppc_fini,
.get_reg_profile = &get_reg_profile,
.il_config = il_config,
.get_reg_profile = &ppc_get_reg_profile,
.il_config = ppc_il_config,
};
#ifndef RZ_PLUGIN_INCORE

View file

@ -781,7 +781,6 @@ int analyze_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf
ctx->omode = mode;
ctx->obits = analysis->bits;
}
analysis->pcalign = 2;
op->addr = addr;
if (len < 2) {
return -1;

View file

@ -256,6 +256,23 @@ static char *get_reg_profile(RzAnalysis *analysis) {
return rz_str_dup(p);
}
static int rl78_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
return 1;
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return 5;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
return -1;
}
}
RzAnalysisPlugin rz_analysis_plugin_rl78 = {
.name = "rl78",
.desc = "Renesas RL78 analysis plugin",
@ -263,5 +280,6 @@ RzAnalysisPlugin rz_analysis_plugin_rl78 = {
.arch = "rl78",
.bits = 16,
.op = &rl78_op,
.archinfo = rl78_archinfo,
.get_reg_profile = &get_reg_profile
};

View file

@ -376,6 +376,23 @@ static char *analysis_rx_reg_profile(RzAnalysis *analysis) {
return rz_str_dup(p);
}
static int analysis_rx_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
return 1;
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return 8;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
/* fall-thru */
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
return -1;
}
}
RzAnalysisPlugin rz_analysis_plugin_rx = {
.name = "rx",
.arch = "rx",
@ -383,5 +400,6 @@ RzAnalysisPlugin rz_analysis_plugin_rx = {
.license = "LGPL3",
.bits = 32,
.op = &analysis_rx_op,
.archinfo = analysis_rx_archinfo,
.get_reg_profile = &analysis_rx_reg_profile,
};

View file

@ -1174,7 +1174,7 @@ static RZ_OWN char *sh_get_reg_profile(RzAnalysis *analysis) {
return rz_str_dup(p);
}
static int archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
static int sh_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
/* fall-thru */
@ -1196,7 +1196,7 @@ RzAnalysisPlugin rz_analysis_plugin_sh = {
.desc = "SH-4 code analysis plugin",
.license = "LGPL3",
.arch = "sh",
.archinfo = archinfo,
.archinfo = sh_archinfo,
.bits = 32,
.op = &sh_op,
.get_reg_profile = &sh_get_reg_profile,

View file

@ -390,6 +390,23 @@ static bool snes_analysis_fini(void *user) {
return true;
}
static int snes_archinfo(RzAnalysis *a, RzAnalysisInfoType query) {
switch (query) {
case RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE:
return 1;
case RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE:
return 4;
case RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_DATA_ALIGN:
return 1;
case RZ_ANALYSIS_ARCHINFO_CAN_USE_POINTERS:
return true;
default:
return -1;
}
}
RzAnalysisPlugin rz_analysis_plugin_snes = {
.name = "snes",
.desc = "SNES analysis plugin",
@ -399,4 +416,5 @@ RzAnalysisPlugin rz_analysis_plugin_snes = {
.init = snes_analysis_init,
.fini = snes_analysis_fini,
.op = &snes_anop,
.archinfo = snes_archinfo,
};

View file

@ -6,10 +6,11 @@
#include <rz_types.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <6502/6502dis.h>
static int _6520_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int _6520_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
int dlen = disass_6502(a->pc, op, buf, len);
return op->size = RZ_MAX(dlen, 0);
}

View file

@ -2,18 +2,16 @@
// SPDX-FileCopyrightText: 2013-2019 astuder <github@adrianstuder.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <8051/8051_ass.h>
#include <8051/8051_disas.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int _8051_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
int dlen = 0;
char *s = rz_8051_disas(a->pc, buf, len, &dlen);
if (dlen < 0) {
@ -27,14 +25,18 @@ static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return dlen;
}
static int _8051_assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
return assemble_8051(op, a->pc, buf);
}
RzAsmPlugin rz_asm_plugin_8051 = {
.name = "8051",
.arch = "8051",
.bits = 8,
.endian = RZ_SYS_ENDIAN_NONE,
.desc = "Intel 8051 disassembler",
.disassemble = &disassemble,
.assemble = &assemble_8051,
.disassemble = &_8051_disassemble,
.assemble = &_8051_assemble,
.license = "PD",
.cpus =
"8051-generic," // First one is default

View file

@ -2,10 +2,11 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <capstone/capstone.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
if (!buf || !op || !a->plugin_data) {
return -1;
}

View file

@ -1,14 +1,13 @@
// SPDX-FileCopyrightText: 2019 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "amd29k/amd29k.h"
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
if (!a || !op || !buf || len < 4) {
return -1;
}

View file

@ -5,12 +5,13 @@
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "../binutils_as.h"
#define ASSEMBLER32 "RZ_ARM32_AS"
#define ASSEMBLER64 "RZ_ARM64_AS"
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
int bits = a->bits;
char *as = "";
#if __arm__

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <rz_util/ht_uu.h>
@ -31,7 +32,7 @@ typedef struct asm_arm_cs_context_t {
bool arm64ass(const char *str, ut64 addr, ut32 *op);
static bool check_features(RzAsm *a, cs_insn *insn) {
static bool check_features(const RzAsm *a, cs_insn *insn) {
AsmArmCSContext *ctx = (AsmArmCSContext *)a->plugin_data;
int i;
if (!insn || !insn->detail) {
@ -66,7 +67,7 @@ static bool check_features(RzAsm *a, cs_insn *insn) {
return true;
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
AsmArmCSContext *ctx = (AsmArmCSContext *)a->plugin_data;
bool disp_hash = a->immdisp;
@ -177,7 +178,7 @@ beach:
return ret;
}
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
const bool is_thumb = (a->bits == 16);
int opsize;
ut32 opcode;
@ -248,7 +249,7 @@ static bool arm_fini(void *user) {
return true;
}
static char *mnemonics(RzAsm *a, int id, bool json) {
static char *mnemonics(const RzAsm *a, int id, bool json) {
AsmArmCSContext *ctx = (AsmArmCSContext *)a->plugin_data;
int i;
a->cur->disassemble(a, NULL, NULL, -1);
@ -297,7 +298,7 @@ static char **arm_cpu_descriptions() {
return cpu_desc;
}
static bool arm_sw_breakpoint(RzAsm *a, RzAsmOp *op) {
static bool arm_sw_breakpoint(const RzAsm *a, RzAsmOp *op) {
if (a->bits == 64) {
// arm64/aarch64
// { 64, 4, 0, "\x00\x00\x20\xd4" }, // le - arm64 brk0

View file

@ -220,7 +220,7 @@ static char *hack_handle_ldst_asm(ut32 insn) {
return NULL;
}
static int hackyArmAsm(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int hackyArmAsm(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
char *buf_asm = NULL;
// Hacky support for ARMv8.5
if (a->bits == 64 && len >= 4) {

View file

@ -1,19 +1,16 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "avr/assembler.h"
#include "avr/disassembler.h"
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
AVROp aop = { 0 };
op->size = avr_disassembler(buf, len, a->pc, a->big_endian, &aop, &op->buf_asm);
if (!op->size) {
@ -23,7 +20,7 @@ static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return op->size;
}
static int assemble(RzAsm *a, RzAsmOp *ao, const char *str) {
static int assemble(const RzAsm *a, RzAsmOp *ao, const char *str) {
st32 slen = strlen(str);
ut8 buffer[16];

View file

@ -4,12 +4,13 @@
#include <rz_analysis.h>
#include <rz_asm.h>
#include "asm_private.h"
typedef struct {
RzPVector /*<RzAsmTokenPattern *>*/ *token_patterns;
} BfContext;
static RZ_OWN RzPVector /*<RzAsmTokenPattern *>*/ *get_token_patterns(RzAsm *a) {
static RZ_OWN RzPVector /*<RzAsmTokenPattern *>*/ *get_token_patterns(const RzAsm *a) {
BfContext *ctx = (BfContext *)a->plugin_data;
RzPVector *pvec = ctx->token_patterns;
if (pvec) {
@ -51,7 +52,7 @@ static RZ_OWN RzPVector /*<RzAsmTokenPattern *>*/ *get_token_patterns(RzAsm *a)
return pvec;
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
const char *buf_asm = "invalid";
ut32 op_type;
switch (*buf) {
@ -120,7 +121,7 @@ static bool _write_asm(RzAsmOp *op, int value, int n) {
return false;
}
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
int n = 0;
if (buf[0] && buf[1] == ' ') {
buf += 2;
@ -187,7 +188,7 @@ static bool bf_fini(void *user) {
return true;
}
static bool bf_sw_breakpoint(RzAsm *a, RzAsmOp *op) {
static bool bf_sw_breakpoint(const RzAsm *a, RzAsmOp *op) {
// { 0, 1, 0, (const ut8 *)"\xff" },
// { 0, 1, 0, (const ut8 *)"\x00" },
rz_asm_op_set_buf(op, (const ut8 *)"\xff", 1);

View file

@ -7,7 +7,7 @@
CAPSTONE_DEFINE_PLUGIN_FUNCTIONS(cbpf_asm);
static int cbpf_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int cbpf_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CapstoneContext *ctx = (CapstoneContext *)a->plugin_data;
cs_insn *insn;
int n;

View file

@ -2,9 +2,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
static int chip8_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *b, int l) {
static int chip8_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *b, int l) {
ut16 opcode = rz_read_be16(b);
uint8_t x = (opcode >> 8) & 0x0F;
uint8_t y = (opcode >> 4) & 0x0F;

View file

@ -2,9 +2,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include "cil/cil_dis.h"
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CILOp cilop = { { { 0 } } };
if (cil_dis(&cilop, buf, len)) {
return 0;

View file

@ -1,14 +1,13 @@
// SPDX-FileCopyrightText: 2014-2018 fedor.sakharov <fedor.sakharov@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <cr16/cr16_disas.h>
static int cr16_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int cr16_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
struct cr16_cmd cmd = { 0 };
int ret = cr16_decode_command(buf, &cmd, len);
if (ret > -1) {

View file

@ -3,16 +3,14 @@
// SPDX-FileCopyrightText: 2009-2019 h4ng3r
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <dalvik/opcode.h>
static int dalvik_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int dalvik_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
rz_return_val_if_fail(a && op && buf && len > 0, -1);
int vA, vB, vC, vD, vE, vF, vG, vH, payload = 0, i = (int)buf[0];
@ -20,7 +18,6 @@ static int dalvik_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
char str[1024], *strasm = NULL;
ut64 offset = 0;
char *flag_str = NULL;
a->dataalign = 2;
if (buf[0] == 0x00) { /* nop */
if (len < 2) {
@ -526,22 +523,19 @@ static int dalvik_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
}
// TODO
static int dalvik_assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
int i;
char *p = strchr(buf, ' ');
if (p) {
*p = 0;
}
// TODO: use a hashtable here
for (i = 0; i < 256; i++) {
if (!strcmp(dalvik_opcodes[i].name, buf)) {
ut8 buf[4];
rz_write_ble32(buf, i, a->big_endian);
rz_strbuf_setbin(&op->buf, buf, sizeof(buf));
op->size = dalvik_opcodes[i].len;
return op->size;
static int dalvik_assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
ut8 temp[4];
for (ut32 i = 0; i < 256; i++) {
if (strcmp(dalvik_opcodes[i].name, buf)) {
continue;
}
rz_write_ble32(temp, i, a->big_endian);
rz_strbuf_setbin(&op->buf, temp, sizeof(temp));
op->size = dalvik_opcodes[i].len;
return op->size;
}
return 0;
}

View file

@ -1,16 +1,14 @@
// SPDX-FileCopyrightText: 2012-2018 pancake <pancake@nopcode.org>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <dcpu16/dcpu16.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
char buf_asm[96];
if (len < 2) {
return -1; // at least 2 bytes!
@ -20,7 +18,7 @@ static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return op->size;
}
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
int len = dcpu16_assemble((ut8 *)rz_strbuf_get(&op->buf), buf);
op->buf.len = len;
return len;

View file

@ -2,14 +2,13 @@
// SPDX-FileCopyrightText: 2012-2018 fedor sakharov <fedor.sakharov@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <ebc/ebc_disas.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
ebc_command_t cmd = { { 0 }, { 0 } };
int ret = ebc_decode_command(buf, len, &cmd);
if (cmd.operands[0]) {

View file

@ -5,14 +5,15 @@
#include <rz_types.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
static int disassemble(RzAsm *a, RzAsmOp *rz_op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *rz_op, const ut8 *buf, int len) {
int dlen = gbDisass(rz_op, buf, len);
return rz_op->size = RZ_MAX(0, dlen);
}
static int assemble(RzAsm *a, RzAsmOp *rz_op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *rz_op, const char *buf) {
return gbAsm(a, rz_op, buf);
}

View file

@ -2,14 +2,13 @@
// SPDX-FileCopyrightText: 2025 Billow <billow.fun@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <h8300/h8300_disas.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
H8300Instruction cmd = { 0 };
op->size = -1;
int ret = h8300_decode_command(buf, len, &cmd, a->pc, a->cpu);

View file

@ -1,14 +1,13 @@
// SPDX-FileCopyrightText: 2025 billow <billow.fun@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <h8500/h8500.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
H8500Instruction ins = { 0 };
if (!h8500_instruction_parse(buf, len, &ins)) {
return -1;

View file

@ -12,8 +12,8 @@
#include <rz_types.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <rz_util/rz_print.h>
#include <rz_vector.h>
#include <hexagon/hexagon.h>
#include <hexagon/hexagon_insn.h>
@ -170,7 +170,7 @@ RZ_API RZ_OWN RzConfig *hexagon_get_config(void *plugin_data) {
* \param l The size to read from the buffer.
* \return int Size of the reversed opcode.
*/
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int l) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int l) {
rz_return_val_if_fail(a && op, -1);
if (l < HEX_INSN_SIZE) {
return -1;

View file

@ -2,10 +2,11 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <capstone/capstone.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
if (!buf || !op || !a->plugin_data) {
return -1;
}

View file

@ -5,10 +5,11 @@
#include <rz_types.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <i4004/i4004dis.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return i4004dis(op, buf, len);
}

View file

@ -5,9 +5,10 @@
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <i8080/i8080dis.h>
static int do_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int do_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
int dlen = i8080_disasm(buf, rz_strbuf_get(&op->buf_asm), len);
return op->size = RZ_MAX(0, dlen);
}

View file

@ -5,6 +5,7 @@
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_core.h>
#include "java/jvm.h"
@ -28,7 +29,7 @@ static void java_asm_update_context(JavaAsmContext *ctx) {
}
}
static ut64 java_asm_find_method(RzAsm *a) {
static ut64 java_asm_find_method(const RzAsm *a) {
ut64 addr = a->pc;
if (!a->binb.bin) {
return addr;
@ -52,7 +53,7 @@ static ut64 java_asm_find_method(RzAsm *a) {
return addr;
}
static int java_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int java_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
JavaAsmContext *ctx = (JavaAsmContext *)a->plugin_data;
rz_strbuf_set(&op->buf_asm, "invalid");
@ -139,7 +140,7 @@ static bool java_asm_fini(void *user) {
return true;
}
static int java_assemble(RzAsm *a, RzAsmOp *ao, const char *str) {
static int java_assemble(const RzAsm *a, RzAsmOp *ao, const char *str) {
ut8 buffer[128];
st32 written = 0;
st32 slen = strlen(str);

View file

@ -1,12 +1,13 @@
// SPDX-FileCopyrightText: 2014-2015 jn
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include <rz_types.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <lh5801/lh5801.h>
static int disassemble(RzAsm *as, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *as, RzAsmOp *op, const ut8 *buf, int len) {
struct lh5801_insn insn = { 0 };
if (!op) {
return 0;

View file

@ -5,6 +5,7 @@
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "lm32/lm32_isa.h"
#define LM32_UNUSED 0
@ -408,19 +409,17 @@ static int rz_asm_lm32_stringify(RzAsmLm32Instruction *instr, char *str) {
return 0;
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
RzAsmLm32Instruction instr = { 0 };
instr.value = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
instr.addr = a->pc;
if (rz_asm_lm32_decode(&instr)) {
rz_strbuf_set(&op->buf_asm, "invalid");
a->invhex = 1;
return -1;
}
// op->buf_asm is 256 chars long, which is more than sufficient
if (rz_asm_lm32_stringify(&instr, rz_strbuf_get(&op->buf_asm))) {
rz_strbuf_set(&op->buf_asm, "invalid");
a->invhex = 1;
return -1;
}
return 4;

View file

@ -2,9 +2,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
if (!buf || !op || !a->plugin_data) {
return -1;
}

View file

@ -1,9 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: 2021 Heersin <teablearcher@gmail.com>
#include "asm_private.h"
#include <luac/lua_arch.h>
int rz_luac_disasm(RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len) {
int rz_luac_disasm(const RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len) {
LuaOpNameList oplist = NULL;
int r = 0;
@ -28,7 +29,7 @@ int rz_luac_disasm(RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len) {
return r;
}
int rz_luac_asm(RzAsm *a, RzAsmOp *opstruct, const char *str) {
int rz_luac_asm(const RzAsm *a, RzAsmOp *opstruct, const char *str) {
int str_len = strlen(str);
ut32 instruction = 0;
ut8 buffer[4];

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include "cs_helper.h"
@ -41,7 +42,7 @@ static cs_mode m680x_mode(const char *str) {
return CS_MODE_M680X_6800;
}
static int m680x_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int m680x_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CapstoneContext *ctx = (CapstoneContext *)a->plugin_data;
int n, ret;

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <capstone/capstone.h>
@ -12,7 +13,7 @@ CAPSTONE_DEFINE_PLUGIN_FUNCTIONS(m68k_asm);
// Size of the longest instruction in bytes
#define M68K_LONGEST_INSTRUCTION 10
static int m68k_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int m68k_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
if (!buf) {
return -1;
}

View file

@ -3,9 +3,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_types.h>
#include <rz_lib.h>
#include <string.h>
static const char *mal_dis(ut64 c, const ut8 *buf, ut64 len) {
if (len) {
@ -23,7 +23,7 @@ static const char *mal_dis(ut64 c, const ut8 *buf, ut64 len) {
return NULL;
}
static int __disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int __disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
const char *opstr = mal_dis(a->pc, buf, len);
return op->size = opstr ? 1 : 0;
}

View file

@ -2,12 +2,13 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include "mcore/mcore.h"
static mcore_handle handle = { 0 };
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
mcore_t *instr = NULL;
char tmp[256];
if (!op || mcore_init(&handle, buf, len)) {

View file

@ -3,12 +3,12 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_types.h>
#include <string.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include "mcs96/mcs96.h"
#include "rz_analysis.h"
#include "rz_util/rz_pj.h"
typedef struct {
RzPVector /*<RzAsmTokenPattern *>*/ *token_patterns;
@ -311,7 +311,7 @@ static bool mcs96_fini(void *u) {
return true;
}
static int mcs96_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int mcs96_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
if (len > 1 && !memcmp(buf, "\xff\xff", 2)) {
return -1;
}

View file

@ -3,6 +3,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <mips/mips_internal.h>
#include <capstone/capstone.h>
@ -10,7 +11,7 @@
CAPSTONE_DEFINE_PLUGIN_FUNCTIONS(mips_asm);
static int mips_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int mips_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CapstoneContext *ctx = (CapstoneContext *)a->plugin_data;
cs_insn *insn;
@ -78,7 +79,7 @@ fin:
return op->size;
}
static int mips_assemble(RzAsm *a, RzAsmOp *op, const char *str) {
static int mips_assemble(const RzAsm *a, RzAsmOp *op, const char *str) {
return mips_assemble_opcode(str, a->pc, &op->buf, a->big_endian);
}
@ -121,7 +122,7 @@ static char **mips_cpu_descriptions() {
return cpu_desc;
}
static bool mips_sw_breakpoint(RzAsm *a, RzAsmOp *op) {
static bool mips_sw_breakpoint(const RzAsm *a, RzAsmOp *op) {
// mips32/64
// { 32, 4, 0, "\x0d\x00\x00\x00" },
// { 32, 4, 1, "\x00\x00\x00\x0d" },

View file

@ -1,15 +1,14 @@
// SPDX-FileCopyrightText: 2014-2015 fedor.sakharov <fedor.sakharov@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <msp430/msp430_disas.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
struct msp430_cmd cmd;
int ret = msp430_decode_command(buf, len, &cmd);
if (ret < 1) {

View file

@ -1,20 +1,19 @@
// SPDX-FileCopyrightText: 2019 pancake <pancake@nopcode.org>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
int opsz = 0;
rz_strbuf_set(&op->buf_asm, "");
op->size = opsz;
return opsz;
}
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
return 0;
}

View file

@ -2,10 +2,11 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <or1k/or1k_disas.h>
static int insn_to_str(RzAsm *a, char **line, insn_t *descr, insn_extra_t *extra, ut32 insn) {
static int insn_to_str(const RzAsm *a, char **line, insn_t *descr, insn_extra_t *extra, ut32 insn) {
struct operands o = { 0 };
char *name;
insn_type_t type = type_of_opcode(descr, extra);
@ -92,7 +93,7 @@ static int insn_to_str(RzAsm *a, char **line, insn_t *descr, insn_extra_t *extra
return 4;
}
static int or1k_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int or1k_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
ut32 insn, opcode;
ut8 opcode_idx;
char *line = NULL;

View file

@ -3,13 +3,14 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include "pic/pic_baseline.h"
#include "pic/pic_midrange.h"
#include "pic/pic_highend.h"
static int asm_pic_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *b, int l) {
static int asm_pic_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *b, int l) {
if (is_pic_baseline_or_pic_midrange(a->cpu)) {
PicMidrangeOp x = { 0 };
if (!(is_pic_baseline(a->cpu) ? pic_baseline_decode_op : pic_midrange_decode_op)(&x, a->pc, b, l)) {
@ -24,7 +25,7 @@ static int asm_pic_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *b, int l) {
}
return op->size;
} else if (is_pic_highend(a->cpu)) {
return pic_highend_disassemble(a, op, b, l);
return pic_highend_disassemble(op, a->pc, b, l);
}
return -1;
}

View file

@ -2,11 +2,12 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_lib.h>
#include "asm_private.h"
#include "../binutils_as.h"
#define ASSEMBLER "RZ_PPC_AS"
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
#if __powerpc__
char *as = "as";
#else

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include "ppc/libvle/vle.h"
#include "ppc/libps/libps.h"
@ -10,7 +11,7 @@
CAPSTONE_DEFINE_PLUGIN_FUNCTIONS(ppc_asm);
static int decompile_vle(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int decompile_vle(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
vle_t *instr = 0;
vle_handle handle = { 0 };
if (len < 2) {
@ -30,7 +31,7 @@ static int decompile_vle(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return op->size;
}
static int decompile_ps(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int decompile_ps(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
ppcps_t instr = { 0 };
if (len < 4) {
return -1;
@ -47,7 +48,7 @@ static int decompile_ps(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return op->size;
}
static int ppc_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int ppc_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CapstoneContext *ctx = (CapstoneContext *)a->plugin_data;
int n, ret;
ut64 off = a->pc;
@ -127,7 +128,7 @@ static char **ppc_cpu_descriptions() {
return cpu_desc;
}
static bool ppc_sw_breakpoint(RzAsm *a, RzAsmOp *op) {
static bool ppc_sw_breakpoint(const RzAsm *a, RzAsmOp *op) {
// ppc | tw 31, 0, 0 | trap
// { 0x7f, 0xe0, 0x00, 0x08 } | big endian
// { 0x08, 0x00, 0xe0, 0x7f } | little endian

View file

@ -1,15 +1,14 @@
// SPDX-FileCopyrightText: 2014 fedor.sakharov <fedor.sakharov@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <propeller/propeller_disas.h>
static int propeller_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int propeller_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
rz_return_val_if_fail(a && op && buf && len >= 4, -1);
struct propeller_cmd cmd;
int ret = propeller_decode_command(buf, &cmd);

View file

@ -6,10 +6,11 @@
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "pyc/pyc_dis.h"
static int pyc_asm_disassemble(RzAsm *a, RzAsmOp *aop, const ut8 *buf, int len) {
static int pyc_asm_disassemble(const RzAsm *a, RzAsmOp *aop, const ut8 *buf, int len) {
pyc_context_t *ctx = (pyc_context_t *)a->plugin_data;
RzList *shared = NULL;

View file

@ -3,13 +3,14 @@
// SPDX-License-Identifier: BSD-3-Clause
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <capstone/capstone.h>
#include "cs_helper.h"
CAPSTONE_DEFINE_PLUGIN_FUNCTIONS(riscv_asm);
static int riscv_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int riscv_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CapstoneContext *ctx = (CapstoneContext *)a->plugin_data;
int ret = -1;

View file

@ -5,14 +5,15 @@
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "rl78/rl78.h"
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
return 0x69;
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
RL78Instr instr = { 0 };
size_t bytes_read = 0;
if (!rl78_dis(&instr, &bytes_read, buf, len)) {

View file

@ -5,6 +5,7 @@
#include <rz_types.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <stdarg.h>
@ -12,7 +13,7 @@
#include <rsp/rsp_idec.h>
static int rsp_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int rsp_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
rsp_instruction rz_instr;
int i;

View file

@ -5,9 +5,10 @@
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rx/rx.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
RxInst inst = { 0 };
st32 bytes_read;

View file

@ -5,10 +5,11 @@
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "sh/disassembler.h"
#include "sh/assembler.h"
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
SHOp *dis_op = sh_disassembler(rz_read_ble16(buf, a->big_endian));
op->size = 2;
if (!dis_op) {
@ -22,7 +23,7 @@ static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return op->size;
}
static int assemble(RzAsm *a, RzAsmOp *ao, const char *str) {
static int assemble(const RzAsm *a, RzAsmOp *ao, const char *str) {
bool success;
ut16 opcode = sh_assembler(str, a->pc, &success);
if (!success) {
@ -35,7 +36,7 @@ static int assemble(RzAsm *a, RzAsmOp *ao, const char *str) {
return 2;
}
static bool sh_sw_breakpoint(RzAsm *a, RzAsmOp *op) {
static bool sh_sw_breakpoint(const RzAsm *a, RzAsmOp *op) {
// { 32, 2, 1, "\xc3\x20" }, // Big endian
// { 32, 2, 0, "\x20\xc3" }, // Little endian
rz_asm_op_set_buf(op, a->big_endian ? (const ut8 *)"\xc3\x20" : (const ut8 *)"\x20\xc3", 2);

View file

@ -5,11 +5,12 @@
#include <rz_types.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <snes/snes_op_table.h>
#include <snes/snes.h>
static int dis(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int dis(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
struct snes_asm_flags *snesflags = (struct snes_asm_flags *)a->plugin_data;
int dlen = snesDisass(snesflags->M, snesflags->X, a->pc, op, buf, len);
if (dlen < 0) {

View file

@ -2,12 +2,13 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include "cs_helper.h"
CAPSTONE_DEFINE_PLUGIN_FUNCTIONS(sparc_asm);
static int sparc_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int sparc_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CapstoneContext *ctx = (CapstoneContext *)a->plugin_data;
cs_insn *insn;

View file

@ -5,10 +5,11 @@
#include <rz_types.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <spc700/spc700dis.h>
static int disassemble(RzAsm *a, RzAsmOp *rz_op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *rz_op, const ut8 *buf, int len) {
size_t dlen = spc700_disas(&rz_op->buf_asm, a->pc, buf, len);
rz_op->size = dlen;
return (int)dlen;

View file

@ -4,6 +4,7 @@
// instruction set : http://www.tachyonsoft.com/inst390m.htm
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include "cs_helper.h"
@ -11,7 +12,7 @@
CAPSTONE_DEFINE_PLUGIN_FUNCTIONS(sysz);
static int sysz_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int sysz_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CapstoneContext *ctx = (CapstoneContext *)a->plugin_data;
int n, ret;
ut64 off = a->pc;

View file

@ -1,10 +1,10 @@
// SPDX-FileCopyrightText: 2014 Ilya V. Matveychikov <i.matveychikov@milabs.ru>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <tms320/tms320_dasm.h>
#include <tms320/c64x/c64x.h>
@ -13,7 +13,7 @@ typedef struct tms_cs_context_t {
tms320_dasm_t engine;
} TmsContext;
static int tms320_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int tms320_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
TmsContext *ctx = (TmsContext *)a->plugin_data;
if (a->cpu && rz_str_casecmp(a->cpu, "c54x") == 0) {
tms320_f_set_cpu(&ctx->engine, TMS320_F_CPU_C54X);
@ -53,7 +53,7 @@ static bool tms320_fini(void *user) {
return true;
}
static char *tms320_mnemonics(RzAsm *a, int id, bool json) {
static char *tms320_mnemonics(const RzAsm *a, int id, bool json) {
TmsContext *ctx = (TmsContext *)a->plugin_data;
if (!a->cpu || rz_str_casecmp(a->cpu, "c64x")) {
return NULL;

View file

@ -1,18 +1,17 @@
// SPDX-FileCopyrightText: 2023 billow <billow.fun@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <capstone/capstone.h>
#define TRICORE_LONGEST_INSTRUCTION 4
#define TRICORE_SHORTEST_INSTRUCTION 2
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
if (!buf || len < TRICORE_SHORTEST_INSTRUCTION || !a->plugin_data) {
return -1;
}

View file

@ -1,15 +1,14 @@
// SPDX-FileCopyrightText: 2012-2018 pancake <pancake@nopcode.org>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "v810/v810_disas.h"
static int v810_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int v810_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
struct v810_cmd cmd = {
.instr = "",
.operands = ""

View file

@ -1,15 +1,14 @@
// SPDX-FileCopyrightText: 2012-2018 pancake <pancake@nopcode.org>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <v850/v850_disas.h>
static int v850_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int v850_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
V850_Inst inst = { 0 };
inst.addr = a->pc;
if (len < 2) {

View file

@ -4,15 +4,14 @@
// http://webassembly.org/docs/binary-encoding/#module-structure
#include <stdio.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <wasm/wasm.h>
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
WasmOp wop = { { 0 } };
int ret = wasm_dis(&wop, buf, len);
rz_asm_op_set_asm(op, wop.txt);
@ -21,7 +20,7 @@ static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return op->size;
}
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
ut8 *opbuf = (ut8 *)rz_strbuf_get(&op->buf);
op->size = wasm_asm(buf, opbuf, 32); // XXX hardcoded opsize
return op->size;

View file

@ -3,11 +3,12 @@
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
#include "../binutils_as.h"
#define ASSEMBLER "RZ_X86_AS"
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
#if __i386__ || __x86_64__
const char *as = "as";
#else

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include <capstone/capstone.h>
@ -11,7 +12,7 @@ CAPSTONE_DEFINE_PLUGIN_FUNCTIONS(x86_asm);
#include "asm_x86_vm.c"
static bool check_features(RzAsm *a, cs_insn *insn) {
static bool check_features(const RzAsm *a, cs_insn *insn) {
if (RZ_STR_ISEMPTY(a->features)) {
return true;
}
@ -43,7 +44,7 @@ static bool check_features(RzAsm *a, cs_insn *insn) {
return true;
}
static int x86_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int x86_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CapstoneContext *ctx = (CapstoneContext *)a->plugin_data;
int ret, n;
ut64 off = a->pc;
@ -131,7 +132,7 @@ static int x86_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
return op->size;
}
static bool x86_sw_breakpoint(RzAsm *a, RzAsmOp *op) {
static bool x86_sw_breakpoint(const RzAsm *a, RzAsmOp *op) {
// { 0, 1, 0, "\xcc" }, // valid for 16, 32, 64
// { 0, 2, 0, "\xcd\x03" },
rz_asm_op_set_buf(op, (const ut8 *)"\xcc", 1);

View file

@ -3,8 +3,9 @@
#include <rz_lib.h>
#include <rz_asm.h>
#include "asm_private.h"
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
static int assemble(const RzAsm *a, RzAsmOp *op, const char *buf) {
char *ipath, *opath;
if (a->syntax != RZ_ASM_SYNTAX_INTEL) {
RZ_LOG_ERROR("assembler: x86.nasm: the assembler does not support non-intel syntax\n");

File diff suppressed because it is too large Load diff

View file

@ -28,7 +28,7 @@
#define VPCEXT2(y, x) ((y)[2] == (x))
static inline void decompile_vm(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static inline void decompile_vm(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
if (len > 3 && buf[0] == 0x0F && buf[1] == 0x3F && (VPCEXT2(buf, 0x01) || VPCEXT2(buf, 0x05) || VPCEXT2(buf, 0x07) || VPCEXT2(buf, 0x0D) || VPCEXT2(buf, 0x10))) {
if (a->syntax == RZ_ASM_SYNTAX_ATT) {
rz_asm_op_setf_asm(op, "vpcext $0x%x, $0x%x", buf[3], buf[2]);

View file

@ -3,6 +3,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#if USE_SYS_ZYDIS
@ -39,7 +40,7 @@ static bool x86_zydis_asm_fini(void *p) {
return true;
}
static char *x86_zydis_asm_mnemonics(RzAsm *a, int id, bool json) {
static char *x86_zydis_asm_mnemonics(const RzAsm *a, int id, bool json) {
rz_return_val_if_fail(a && a->cur, NULL);
if (!a->plugin_data) {
return NULL;
@ -78,7 +79,7 @@ static char *x86_zydis_asm_mnemonics(RzAsm *a, int id, bool json) {
return rz_strbuf_drain(buf);
}
static int x86_zydis_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int x86_zydis_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
rz_return_val_if_fail(a, 0);
ZydisContext *zydx = (ZydisContext *)a->plugin_data;
ut64 off = a->pc;
@ -141,7 +142,7 @@ static int x86_zydis_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
return op->size;
}
static bool x86_sw_breakpoint(RzAsm *a, RzAsmOp *op) {
static bool x86_sw_breakpoint(const RzAsm *a, RzAsmOp *op) {
// { 0, 1, 0, "\xcc" }, // valid for 16, 32, 64
// { 0, 2, 0, "\xcd\x03" },
rz_asm_op_set_buf(op, (const ut8 *)"\xcc", 1);

View file

@ -1,11 +1,11 @@
// SPDX-FileCopyrightText: 2009-2014 nibble <nibble.ds@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "asm_private.h"
static int arch_xap_disasm(RzStrBuf *asm_buf, const unsigned char *buf, ut64 addr) {
xap_state_t s = { 0 };
@ -19,7 +19,7 @@ static int arch_xap_disasm(RzStrBuf *asm_buf, const unsigned char *buf, ut64 add
return 0;
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
arch_xap_disasm(&op->buf_asm, buf, a->pc);
return (op->size = 2);
}

View file

@ -2,13 +2,14 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_asm.h>
#include "asm_private.h"
#include <rz_lib.h>
#include "cs_helper.h"
CAPSTONE_DEFINE_PLUGIN_FUNCTIONS(xcore_asm);
static int xcore_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int xcore_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CapstoneContext *ctx = (CapstoneContext *)a->plugin_data;
cs_insn *insn;
int n, ret = -1;

View file

@ -3,9 +3,10 @@
#include <rz_types.h>
#include <rz_asm.h>
#include "asm_private.h"
#include <xtensa/xtensa.h>
static int asm_xtensa_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int asm_xtensa_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
XtensaContext *ctx = a->plugin_data;
if (!xtensa_open(ctx, a->cpu, a->big_endian)) {
goto beach;

View file

@ -48,7 +48,7 @@ typedef struct {
}
#define CAPSTONE_PLUGIN_MNEMONICS(name) \
static char *name##_mnemonics(RzAsm *a, int id, bool json) { \
static char *name##_mnemonics(const RzAsm *a, int id, bool json) { \
if (!a->plugin_data) { \
return NULL; \
} \

View file

@ -66,7 +66,7 @@ static int generic_fprintf_func(void *stream, void *data, const char *format, ..
return ret;
}
static int arc_gnu_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int arc_gnu_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
ArcContext *ctx = (ArcContext *)a->plugin_data;
if (len < 2) {
return -1;

View file

@ -71,7 +71,7 @@ int print_insn_cris_without_register_prefix(bfd_vma vma, disassemble_info *info,
int print_insn_crisv32_with_register_prefix(bfd_vma vma, disassemble_info *info, void *data);
int print_insn_crisv32_without_register_prefix(bfd_vma vma, disassemble_info *info, void *data);
static int cris_gnu_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int cris_gnu_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
CrisContext *ctx = (CrisContext *)a->plugin_data;
struct disassemble_info disasm_obj;
int mode = 2;

View file

@ -58,7 +58,7 @@ static int generic_fprintf_func(void *stream, void *data, const char *format, ..
return ret;
}
static int lanai_gnu_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
static int lanai_gnu_disassemble(const RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
LanaiContext *ctx = (LanaiContext *)a->plugin_data;
struct disassemble_info disasm_obj;
if (len < 4) {

Some files were not shown because too many files have changed in this diff Show more