2013-04-02 10:45:16 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2013 - pancake */
|
2010-02-12 12:45:03 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <r_asm.h>
|
|
|
|
|
2010-02-12 17:40:05 +00:00
|
|
|
R_API RAsmCode *r_asm_code_new() {
|
2012-08-22 16:02:23 +00:00
|
|
|
return R_NEW0 (RAsmCode);
|
2010-02-12 17:40:05 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 12:45:03 +00:00
|
|
|
R_API void* r_asm_code_free(struct r_asm_code_t *acode) {
|
2010-02-12 17:40:05 +00:00
|
|
|
if (!acode)
|
|
|
|
return NULL;
|
|
|
|
if (acode->buf)
|
|
|
|
free (acode->buf);
|
|
|
|
if (acode->buf_hex)
|
|
|
|
free (acode->buf_hex);
|
|
|
|
if (acode->buf_asm)
|
|
|
|
free (acode->buf_asm);
|
|
|
|
free (acode);
|
2010-02-12 12:45:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API int r_asm_code_set_equ (RAsmCode *code, const char *key, const char *value) {
|
|
|
|
RAsmEqu *equ;
|
2010-03-13 15:35:18 +00:00
|
|
|
RListIter *iter;
|
2010-02-12 12:45:03 +00:00
|
|
|
if (key == NULL || value == NULL) {
|
|
|
|
eprintf ("Oops, no key or value defined in r_asm_code_set_equ ()\n");
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2010-02-12 12:45:03 +00:00
|
|
|
}
|
|
|
|
if (!code->equs) {
|
|
|
|
code->equs = r_list_new ();
|
|
|
|
code->equs->free = free;
|
2010-03-13 15:35:18 +00:00
|
|
|
} else r_list_foreach (code->equs, iter, equ)
|
|
|
|
if (!strcmp (equ->key, key)) {
|
|
|
|
free (equ->value);
|
|
|
|
equ->value = strdup (value);
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2010-03-13 15:35:18 +00:00
|
|
|
}
|
2010-02-12 12:45:03 +00:00
|
|
|
equ = R_NEW (RAsmEqu);
|
|
|
|
equ->key = strdup (key);
|
|
|
|
equ->value = strdup (value);
|
|
|
|
r_list_append (code->equs, equ);
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2010-02-12 12:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API char *r_asm_code_equ_replace (RAsmCode *code, char *str) {
|
2012-02-14 17:19:16 +00:00
|
|
|
RAsmEqu *equ;
|
2010-02-12 12:45:03 +00:00
|
|
|
RListIter *iter;
|
2012-12-20 10:31:38 +00:00
|
|
|
if (code->equs)
|
2012-02-14 17:19:16 +00:00
|
|
|
r_list_foreach (code->equs, iter, equ) {
|
2015-09-14 00:08:31 +00:00
|
|
|
str = r_str_replace (str, equ->key, equ->value, true);
|
2010-02-12 12:45:03 +00:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|