93 if (!hexstr || hexstr[0] !=
'0' || !(hexstr[1] ==
'x' || hexstr[1] ==
'X')) {
98 for (
p = hexstr + 2;
p < hexstr + 6 && *
p;
p += 1) {
100 if (
'0' <= *
p && *
p <=
'9') {
102 }
else if (
'a' <= *
p && *
p <=
'f') {
103 *
out |= *
p -
'a' + 10;
104 }
else if (
'A' <= *
p && *
p <=
'F') {
105 *
out |= *
p -
'A' + 10;
127 char *lastnonws =
dest;
128 bool anynonws =
false;
129 bool in_string =
false;
133 while (
n && *multi && *multi !=
'\n' && *multi !=
'\r') {
135 in_string = !in_string;
148 if (!*multi || *multi ==
'\n' || *multi ==
'\r' || in_string) {
152 while (*multi && (*multi ==
' ' || *multi ==
'\t')) {
156 while (*multi && *multi !=
'\n' && *multi !=
'\r') {
158 in_string = !in_string;
160 if (*multi ==
';' || *multi ==
',') {
163 if (*multi !=
' ' && *multi !=
'\t') {
180 *(lastnonws + 1) =
'\0';
190 size_t arglen = strlen(arguments) + 1;
239 return c ==
'\0' ||
c ==
'\n' ||
c ==
'\r' ||
c ==
';';
293 while (pattern[ti] !=
'\0') {
313 while (tbl[row].pattern) {
361 st16 diff = address - (
pc + 2);
392 *addr_out = addr_big;
400 char *bitpart =
malloc(strlen(addr_str) + 1);
401 char *bytepart =
malloc(strlen(addr_str) + 1);
402 char const *separator =
rz_str_lchr(addr_str,
'.');
414 rz_str_ncpy(bytepart, addr_str, separator - addr_str + 1);
415 bytepart[separator - addr_str + 1] =
'\0';
416 rz_str_ncpy(bitpart, separator + 1, strlen(separator));
420 if (1 < strlen(bitpart) || bitpart[0] <
'0' ||
'7' < bitpart[0]) {
424 bit = bitpart[0] -
'0';
425 if (0x20 <=
byte &&
byte < 0x30) {
426 *addr_out = (
byte - 0x20) * 8 +
bit;
428 }
else if (0x80 <=
byte && !(
byte % 8)) {
429 *addr_out =
byte +
bit;
469 (*out)[0] = firstbyte;
480 (*out)[0] = firstbyte;
490 (*out)[0] = firstbyte;
501 (*out)[0] = firstbyte;
502 (*out)[1] =
imm & 0x00FF;
527 (*out)[0] = ((address & 0x0700) >> 3) | 0x11;
528 (*out)[1] = address & 0x00FF;
559 if (
arg[1][0] ==
'#') {
573 (*out)[0] = ((address & 0x0700) >> 3) | 0x01;
574 (*out)[1] = address & 0x00FF;
580 if (!strcmp(
arg[0],
"c")) {
581 if (
arg[1][0] ==
'/') {
586 if (!strcmp(
arg[0],
"a")) {
590 if (
arg[1][0] ==
'#') {
612 (*out)[2] =
imm & 0x00FF;
623 if (
arg[1][0] ==
'#') {
629 (*out)[1] =
imm & 0x00FF;
650 (*out)[1] =
imm & 0x00FF;
661 (*out)[1] =
imm & 0x00FF;
724 (*out)[1] = (*out)[2];
733 (*out)[1] = dec_address;
765 (*out)[1] = cmp_addr;
781 (*out)[1] = cmp_addr;
801 (*out)[1] = cmp_addr;
825 (*out)[1] = ((address & 0xFF00) >> 8) & 0x00FF;
826 (*out)[2] = address & 0x00FF;
837 (*out)[1] = ((address & 0xFF00) >> 8) & 0x00FF;
838 (*out)[2] = address & 0x00FF;
854 (*out)[1] =
imm >> 8;
863 if (
arg[1][0] !=
'#') {
876 if (
arg[1][0] ==
'#') {
885 if (
arg[1][0] ==
'#') {
907 if (
arg[1][0] ==
'#') {
913 (*out)[1] = dest_addr;
914 (*out)[2] =
imm & 0x00FF;
923 (*out)[1] = src_addr;
924 (*out)[2] = dest_addr;
976 if (
arg[1][0] ==
'/') {
985 if (
arg[1][0] ==
'#') {
994 if (
arg[1][0] !=
'#') {
1007 (*out)[1] = dest_addr;
1008 (*out)[2] =
imm & 0x00FF;
1067 reladdr = address -
pc;
1069 reladdr =
pc - address;
1072 if (reladdr < 0x100) {
1074 }
else if (reladdr < 0x08FF) {
1088 if (
arg[1][0] ==
'#') {
1106 if (
arg[1][0] ==
'#') {
1114 if (
arg[1][0] !=
'#') {
1129 (*out)[1] = dest_addr;
1130 (*out)[2] =
imm & 0x00FF;
1164 #define mnem(n, mn) { #mn " ", &mnem_##mn, n },
1165 #define zeroarg_mnem(mn) { #mn, &mnem_##mn, 0 },
1166 mnem(1, acall)
mnem(2, addc)
mnem(2,
add)
mnem(1, ajmp)
mnem(2, anl)
mnem(3, cjne)
mnem(1, clr)
mnem(1, cpl)
mnem(1, da)
mnem(1, dec)
mnem(1, div)
mnem(2, djnz)
mnem(1, inc)
mnem(2, jbc)
mnem(2, jb)
mnem(1, jc)
mnem(1,
jmp)
mnem(2, jnb)
mnem(1, jnc)
mnem(1, jz)
mnem(1, jnz)
mnem(1, lcall)
mnem(1, ljmp)
1174 mnem(2, movc)
mnem(2, movx)
mnem(2,
mov)
mnem(1,
mul)
mnem(2,
orl)
mnem(1, pop)
mnem(1, push)
mnem(2, xchd)
mnem(2, xch)
mnem(2, xrl)
mnem(1, rlc)
mnem(1, rl)
mnem(1, rrc)
mnem(1, rr)
mnem(1, setb)
mnem(1, sjmp)
mnem(2, subb)
mnem(1,
swap)
zeroarg_mnem(nop)
zeroarg_mnem(reti)
zeroarg_mnem(ret)
1184 if (!
a || !
op || !user_asm) {
1191 char const *arguments = user_asm;
1192 while (!
terminates_asm_line(*arguments) && ((
'a' <= *arguments && *arguments <=
'z') || (
'A' <= *arguments && *arguments <=
'Z'))) {
1198 char *
arg[3] = { 0 };
1200 char const *carg[3] = {
arg[0],
arg[1],
arg[2] };
1203 int wants_arguments;
1205 if (!
mnem || nr_of_arguments != wants_arguments) {
1217 ut8 instr[4] = { 0 };
1219 if (!
mnem(carg,
a->pc, &binp)) {
1240 size_t len = binp - instr;
1242 return binp - instr;
static bool mnem_push(char const *const *arg, ut16 pc, ut8 **out)
static int str_iwhitecasecmp(char const *a, char const *b)
static bool pattern_match(char const *str, char const *pattern)
static bool mnem_reti(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_nop(char const *const *arg, ut16 pc, ut8 **out)
static bool parse_hexadecimal(char const *hexstr, ut16 *out)
static bool to_address(char const *addr_str, ut16 *addr_out)
int assemble_8051(RzAsm *a, RzAsmOp *op, char const *user_asm)
static bool mnem_ljmp(char const *const *arg, ut16 pc, ut8 **out)
static bool singlearg_reladdr(ut8 const firstbyte, char const *arg, ut16 const pc, ut8 **out)
bool(* parse_mnem_args)(char const *const *, ut16, ut8 **)
static bool mnem_ajmp(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_orl(char const *const *arg, ut16 pc, ut8 **out)
static bool is_reg(char const *str)
static bool mnem_rl(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_mul(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_sjmp(char const *const *arg, ut16 pc, ut8 **out)
static bool get_arg(char const *multi, int n, char *dest)
static bool mnem_xrl(char const *const *arg, ut16 pc, ut8 **out)
static bool address_bit(char const *addr_str, ut8 *addr_out)
static bool mnem_acall(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_jnz(char const *const *arg, ut16 pc, ut8 **out)
static bool is_indirect_reg(char const *str)
static int get_arguments(char **arg, char const *arguments)
static bool mnem_anl(char const *const *arg, ut16 pc, ut8 **out)
static bool relative_address(ut16 pc, ut16 address, ut8 *out)
static bool mnem_jb(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_ret(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_xchd(char const *const *arg, ut16 pc, ut8 **out)
static bool resolve_immediate(char const *imm_str, ut16 *imm_out)
static bool single_a_arg_instr(ut8 const firstbyte, char const *arg, ut8 **out)
static bool mnem_subb(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_rlc(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_dec(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_cpl(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_jz(char const *const *arg, ut16 pc, ut8 **out)
static bool address_direct(char const *addr_str, ut8 *addr_out)
static bool mnem_jnc(char const *const *arg, ut16 pc, ut8 **out)
static int register_number(char const *reg)
static bool mnem_div(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_addc(char const *const *arg, ut16 pc, ut8 **out)
static bool singlearg_bit(ut8 const firstbyte, char const *arg, ut8 **out)
static bool mnem_inc(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_add(char const *const *arg, ut16 pc, ut8 **out)
static bool singlearg_immediate(ut8 firstbyte, char const *imm_str, ut8 **out)
static bool mnem_djnz(char const *const *arg, ut16 pc, ut8 **out)
static parse_mnem_args match_prefix_f(int *args, char const *str, ftable const tbl)
static bool singlearg_register(ut8 firstbyte, char const *reg, ut8 **out)
static bool mnem_pop(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_rr(char const *const *arg, ut16 pc, ut8 **out)
static parse_mnem_args mnemonic(char const *user_asm, int *nargs)
static bool mnem_da(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_setb(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_jnb(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_lcall(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_jc(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_movx(char const *const *arg, ut16 pc, ut8 **out)
static bool terminates_asm_line(char c)
static bool mnem_mov_c(char const *const *arg, ut16 pc, ut8 **out)
static bool single_byte_instr(ut8 const instr, ut8 **out)
static bool mnem_movc(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_clr(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_xch(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_rrc(char const *const *arg, ut16 pc, ut8 **out)
static bool singlearg_direct(ut8 const firstbyte, char const *arg, ut8 **out)
static bool mnem_jbc(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_mov(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_jmp(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_cjne(char const *const *arg, ut16 pc, ut8 **out)
static bool mnem_swap(char const *const *arg, ut16 pc, ut8 **out)
static RzILOpEffect * mov(cs_insn *insn, bool is_thumb)
static RzILOpEffect * mul(cs_insn *insn, bool is_thumb)
const lzma_allocator const uint8_t size_t uint8_t * out
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
RZ_API const char * rz_str_lchr(const char *str, char chr)
RZ_API int rz_str_casecmp(const char *dst, const char *orig)
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
RZ_API size_t rz_str_ansi_nlen(const char *str, size_t len)
RZ_API int rz_str_ncasecmp(const char *dst, const char *orig, size_t n)
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len)
char const *const pattern