Rizin
unix-like reverse engineering framework and cli tools
assembler.h File Reference
#include <rz_types.h>
#include <rz_util.h>

Go to the source code of this file.

Functions

ut32 avr_assembler (const char *input, st32 input_size, ut8 *output, st32 output_size, ut64 pc, bool be)
 

Function Documentation

◆ avr_assembler()

ut32 avr_assembler ( const char *  input,
st32  input_size,
ut8 output,
st32  output_size,
ut64  pc,
bool  be 
)

Definition at line 1084 of file assembler.c.

1084  {
1085  return_error_if_empty_input(input, input_size);
1086 
1087  ut32 written = AVR_INVALID_SIZE;
1088  ut32 ntokens = 0;
1089  char** tokens = tokens_new(input, input_size, &ntokens);
1090  if (!tokens || ntokens < 1) {
1091  RZ_LOG_ERROR("[!] avr_assembler: invalid assembly.\n");
1092  goto avr_assembler_end;
1093  }
1094 
1095 
1096  for (ut32 i = 0; i < RZ_ARRAY_SIZE(instructions); ++i) {
1097  if (!rz_str_casecmp(tokens[0], instructions[i].opcode)) {
1098  ut16 mintoks = instructions[i].mintoks;
1099  ut16 maxtoks = instructions[i].maxtoks;
1100  if (ntokens < mintoks || ntokens > maxtoks) {
1101  RZ_LOG_ERROR("[!] avr_assembler: '%s' requires %u <= ntokens <= %u, but %u tokens was provided.\n", tokens[0], mintoks, maxtoks, ntokens);
1102  goto avr_assembler_end;
1103  }
1104  written = instructions[i].encode(instructions[i].cbits, (cchar**)tokens, ntokens, output, pc, be);
1105  break;
1106  }
1107  }
1108 
1109 avr_assembler_end:
1110  tokens_free(tokens);
1111  return written;
1112 }
lzma_index ** i
Definition: index.h:629
static const AvrInstruction instructions[]
Definition: assembler.c:880
static void tokens_free(char **tokens)
Definition: assembler.c:1073
#define return_error_if_empty_input(a, b)
Definition: assembler.c:16
static char ** tokens_new(cchar *input, st32 input_size, ut32 *ntokens)
Definition: assembler.c:1024
uint16_t ut16
uint32_t ut32
const char cchar
Definition: common.h:9
#define AVR_INVALID_SIZE
Definition: common.h:7
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API int rz_str_casecmp(const char *dst, const char *orig)
Definition: str.c:121
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
Encode encode
Definition: assembler.c:179
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)
diff_output_t output
Definition: zipcmp.c:237

References AVR_INVALID_SIZE, avr_decoder_t::encode, i, input(), instructions, avr_decoder_t::maxtoks, avr_decoder_t::mintoks, output, pc, return_error_if_empty_input, RZ_ARRAY_SIZE, RZ_LOG_ERROR, rz_str_casecmp(), tokens_free(), and tokens_new().

Referenced by assemble().