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