93 pj_ks(pj,
"stackop", stackop);
95 pj_kn(pj,
"stackptr",
op->stackptr);
101 if (
op->jump != -1LL) {
104 if (
op->fail != -1LL) {
109 if (
op->val != -1LL) {
112 printf(
"stackop: %s\n", stackop);
140 for (ret = 0; ret <
len;) {
150 pj_ks(pj,
"type",
"Invalid");
172 printf(
"Usage: rz-asm [-ACdDehLBvw] [-a arch] [-b bits] [-o addr] [-s syntax]\n"
173 " [-f file] [-F fil:ter] [-i skip] [-l len] 'code'|hex|-\n");
176 printf(
" -a [arch] Set architecture to assemble/disassemble (see -L)\n"
177 " -A Show Analysis information from given hexpairs\n"
178 " -b [bits] Set cpu register size (8, 16, 32, 64) (RZ_ASM_BITS)\n"
179 " -B Binary input/output (-l is mandatory for binary input)\n"
180 " -c [cpu] Select specific CPU (depends on arch)\n"
181 " -C Output in C format\n"
182 " -d, -D Disassemble from hexpair bytes (-D show hexpairs)\n"
183 " -e Use big endian instead of little endian\n"
184 " -I Display lifted RzIL code (same input as in -d, IL is also validated)\n"
185 " -E Display ESIL expression (same input as in -d)\n"
186 " -f [file] Read data from file\n"
187 " -F [in:out] Specify input and/or output filters (att2intel, x86.pseudo, ...)\n"
188 " -h, -hh Show this help, -hh for long\n"
189 " -i [len] ignore/skip N bytes of the input buffer\n"
190 " -j output in json format\n"
191 " -k [kernel] Select operating system (linux, windows, darwin, ..)\n"
192 " -l [len] Input/Output length\n"
193 " -L List Asm plugins: (a=asm, d=disasm, A=analyze, e=ESIL)\n"
194 " -o,-@ [addr] Set start address for code (default 0)\n"
195 " -O [file] Output file name (rz-asm -Bf a.asm -O a)\n"
196 " -p Run SPP over input for assembly\n"
198 " -r output in rizin commands\n"
199 " -s [syntax] Select syntax (intel, att)\n"
200 " -v Show version information\n"
201 " -x Use hex dwords instead of hex pairs when assembling.\n"
202 " -w What's this instruction for? describe opcode\n"
203 " If '-l' value is greater than output length, output is padded with nops\n"
204 " If the last argument is '-' reads from stdin\n");
206 " RZ_ASM_NOPLUGINS do not load shared plugins (speedup loading)\n"
207 " RZ_ASM_ARCH same as rz-asm -a\n"
208 " RZ_ASM_BITS same as rz-asm -b\n"
209 " RZ_DEBUG if defined, show error messages and crash signal\n"
213 printf(
"Supported Assembler directives:\n");
228 if (
op->size < 1 || !
op->il_op) {
229 eprintf(
"Invalid instruction of lifting not implemented.\n");
234 eprintf(
"Failed to initialize IL VM for this architecture.\n");
240 eprintf(
"Failed to derive context from IL VM.\n");
256 eprintf(
"IL Validation failed%c\n", report ?
':' :
'.');
284 if ((
int)clen < 1 || !(data =
malloc(clen))) {
292 if (!
len || clen <=
len) {
335 while ((
len - ret) > 0) {
337 if (dr == -1 ||
op.size < 1) {
343 as->
a->
pc,
op.size, op_hex,
368 if (data && data != (
ut8 *)
buf) {
378 for (
i = 1; *
str;
str += 2,
i += 2) {
392 printf(
"f label.%s @ %s\n", (
const char *)
k, (
const char *)
v);
407 eprintf(
"Failed to write buffer\n");
416 for (j = 0; j < 8 &&
b--; j++) {
424 for (
i = 0;
i < acode->
len;
i +=
sizeof(
ut32)) {
461 int bin,
bool use_spp,
bool rad,
bool hexwords,
const char *
arch) {
473 printf(
"f label.main @ $$ + 1\n");
501 free(oldhomeplugindir);
513 const char *kernel =
NULL;
518 bool use_spp =
false;
519 bool hexwords =
false;
521 int fd = -1,
bin = 0, ret = 0,
bits = 32,
c, whatsop = 0;
525 bool analinfo =
false;
616 core->
rasm = tmp_asm;
642 if (*opt.
arg ==
'?') {
643 printf(
"att\nintel\nmasm\njz\nregnum\n");
681 eprintf(
"rz-asm: Unknown asm plugin '%s'\n",
arch);
686 }
else if (env_arch) {
688 eprintf(
"rz-asm: Unknown asm plugin '%s'\n", env_arch);
693 eprintf(
"rz-asm: Cannot find asm.x86 plugin\n");
705 if (isbig && !canbebig) {
706 eprintf(
"Warning: This architecture can't swap to big endian.\n");
742 if (!strcmp(
file,
"-")) {
745 if (!
buf || sz < 1) {
758 }
else if (analinfo) {
786 }
else if (analinfo) {
800 }
else if (opt.
argv[opt.
ind]) {
801 if (!strcmp(opt.
argv[opt.
ind],
"-")) {
813 if ((!
bin || !
dis) && feof(stdin)) {
830 }
else if (analinfo) {
846 len = strlen(usrstr);
855 if (!strncmp(usrstr,
"0x", 2)) {
856 memmove(usrstr, usrstr + 2, strlen(usrstr + 2) + 1);
866 }
else if (analinfo) {
870 bin, use_spp, rad, hexwords,
arch);
RZ_API void * rz_asm_code_free(RzAsmCode *acode)
RZ_API char * rz_asm_code_get_hex(RzAsmCode *acode)
RZ_API void rz_analysis_set_cpu(RzAnalysis *analysis, const char *cpu)
RZ_API int rz_analysis_add(RzAnalysis *analysis, RzAnalysisPlugin *p)
RZ_API RzAnalysis * rz_analysis_free(RzAnalysis *a)
RZ_API bool rz_analysis_set_bits(RzAnalysis *analysis, int bits)
RZ_API RzAnalysis * rz_analysis_new(void)
RZ_API int rz_analysis_set_big_endian(RzAnalysis *analysis, int bigend)
RZ_API bool rz_analysis_use(RzAnalysis *analysis, const char *name)
RZ_API RZ_OWN RzAnalysisILVM * rz_analysis_il_vm_new(RzAnalysis *a, RZ_NULLABLE RzReg *init_state_reg)
RZ_API void rz_analysis_il_vm_free(RZ_NULLABLE RzAnalysisILVM *vm)
RZ_API char * rz_asm_op_get_hex(RzAsmOp *op)
RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str)
RZ_API char * rz_asm_op_get_asm(RzAsmOp *op)
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
RZ_API RzAsmCode * rz_asm_mdisassemble(RzAsm *a, const ut8 *buf, int len)
RZ_API bool rz_asm_add(RzAsm *a, RzAsmPlugin *p)
RZ_API void rz_asm_list_directives(void)
RZ_API void rz_asm_free(RzAsm *a)
RZ_API int rz_asm_syntax_from_string(const char *name)
RZ_API bool rz_asm_set_big_endian(RzAsm *a, bool b)
RZ_API RzAsm * rz_asm_new(void)
RZ_DEPRECATE RZ_API int rz_asm_set_bits(RzAsm *a, int bits)
RZ_API char * rz_asm_describe(RzAsm *a, const char *str)
RZ_API RzAsmCode * rz_asm_rasm_assemble(RzAsm *a, const char *buf, bool use_spp)
RZ_API bool rz_asm_set_syntax(RzAsm *a, int syntax)
RZ_DEPRECATE RZ_API void rz_asm_set_cpu(RzAsm *a, const char *cpu)
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc)
RZ_API bool rz_asm_use(RzAsm *a, const char *name)
Puts an Asm plugin in use and disables the previous one.
RZ_API int rz_asm_sub_names_input(RzAsm *a, const char *f)
RZ_API int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
RZ_API int rz_asm_sub_names_output(RzAsm *a, const char *f)
static int dis(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
int bits(struct state *s, int need)
RZ_API RzCmdStatus rz_core_asm_plugins_print(RzCore *core, const char *arch, RzCmdStateOutput *state)
RZ_API bool rz_cmd_state_output_init(RZ_NONNULL RzCmdStateOutput *state, RzOutputMode mode)
Initialize a RzCmdStateOutput structure and its inner fields based on the provided mode.
RZ_API void rz_cmd_state_output_fini(RZ_NONNULL RzCmdStateOutput *state)
Clear the inner fields of RzCmdStateOutput structure, but do not free it.
RZ_API void rz_cmd_state_output_print(RZ_NONNULL RzCmdStateOutput *state)
Print the output accumulated in state to RzCons, if necessary.
RZ_API void rz_cons_flush(void)
const lzma_filter * filters
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static fork const void static count static fd const char const char static newpath const char static path const char path
static static fork const void static count close
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
void skip(file *in, unsigned n)
RZ_API void Ht_() free(HtName_(Ht) *ht)
RZ_API void rz_il_op_effect_stringify(RZ_NONNULL RzILOpEffect *op, RZ_NONNULL RzStrBuf *sb)
RZ_API void rz_il_validate_global_context_free(RzILValidateGlobalContext *ctx)
RZ_API RzILValidateGlobalContext * rz_il_validate_global_context_new_from_vm(RZ_NONNULL RzILVM *vm)
RZ_API bool rz_il_validate_effect(RZ_NULLABLE RzILOpEffect *op, RZ_NONNULL RzILValidateGlobalContext *ctx, RZ_NULLABLE RZ_OUT HtPP **local_var_sorts_out, RZ_NULLABLE RZ_OUT RzILTypeEffect *type_out, RZ_NULLABLE RZ_OUT RzILValidateReport *report_out)
RZ_API void rz_core_free(RzCore *c)
RZ_API RzCore * rz_core_new(void)
static int __lib_analysis_cb(RzLibPlugin *pl, void *user, void *data)
static char * stackop2str(int type)
static bool print_label(void *user, const void *k, const void *v)
static void __load_plugins(RzAsmState *as)
RZ_API int rz_main_rz_asm(int argc, const char *argv[])
static bool print_and_check_il(RzAsmState *as, RzAnalysisOp *op)
static RzAsmState * __as_new(void)
static void print_buf(RzAsmState *as, char *str)
static int __lib_asm_cb(RzLibPlugin *pl, void *user, void *data)
static int print_assembly_output(RzAsmState *as, const char *buf, ut64 offset, ut64 len, int bits, int bin, bool use_spp, bool rad, bool hexwords, const char *arch)
static int show_analinfo(RzAsmState *as, const char *arg, ut64 offset)
static void __as_free(RzAsmState *as)
static int rasm_disasm(RzAsmState *as, ut64 addr, const char *buf, int len, int bits, int bin, DisasmMode mode)
static int rasm_show_help(int v)
static void __as_set_archbits(RzAsmState *as)
static void showanalysis(RzAsmState *as, RzAnalysisOp *op, ut64 offset, ut8 *buf, int len, PJ *pj)
static int rasm_asm(RzAsmState *as, const char *buf, ut64 offset, ut64 len, int bits, int bin, bool use_spp, bool hexwords)
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char argv
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
RZ_API bool rz_analysis_op_fini(RzAnalysisOp *op)
RZ_API const char * rz_analysis_optype_to_string(int type)
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
@ RZ_ANALYSIS_OP_MASK_BASIC
@ RZ_ANALYSIS_OP_MASK_ESIL
static ut32 rz_read_ble32(const void *src, bool big_endian)
RZ_API char * rz_stdin_slurp(int *sz)
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
RZ_API void rz_getopt_init(RzGetopt *go, int argc, const char **argv, const char *ostr)
RZ_API int rz_getopt_next(RzGetopt *opt)
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
RZ_API char * rz_hex_bin2strdup(const ut8 *in, int len)
RZ_API void rz_lib_free(RzLib *lib)
RZ_API RzLib * rz_lib_new(const char *symname, const char *symnamefunc)
RZ_API bool rz_lib_opendir(RzLib *lib, const char *path, bool force)
Open all the libraries in the given directory, if it wasn't already opened.
RZ_API bool rz_lib_add_handler(RzLib *lib, int type, const char *desc, RzLibCallback ct, RzLibCallback dt, void *user)
RZ_API int rz_main_version_print(const char *program)
RZ_API RzNum * rz_num_new(RzNumCallback cb, RzNumCallback2 cb2, void *ptr)
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
RZ_API void rz_num_free(RzNum *num)
RZ_API RZ_OWN char * rz_path_home_prefix(RZ_NULLABLE const char *path)
Return path prefixed by the home prefix.
RZ_API RZ_OWN char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
RZ_API PJ * pj_end(PJ *j)
RZ_API const char * pj_string(PJ *pj)
RZ_API void pj_free(PJ *j)
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
#define RZ_STR_ISEMPTY(x)
RZ_API int rz_str_replace_char(char *s, int a, int b)
#define RZ_STRBUF_SAFEGET(sb)
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
RZ_API void rz_strbuf_init(RzStrBuf *sb)
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
@ RZ_OUTPUT_MODE_STANDARD
#define RZ_HOME_OLD_PLUGINS
High-level RzIL vm to emulate disassembled code.
RZ_NONNULL RzILVM * vm
low-level vm to execute IL code
Represent the output state of a command handler.
RZ_API RzSyscall * rz_syscall_new(void)
Creates a new RzSyscall type.
RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const char *cpu, const char *os)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
int read(izstream &zs, T *x, Items items)