Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions libr/asm/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define FILTER_DWORD 0

#define isx86separator(x) ( \
(x) == ' ' || (x) == '\t' || (x) == '\n' || (x) == '\r' || (x) == ' ' || \
(x) == ' ' || (x) == '\t' || (x) == '\n' || (x) == '\r' || \
(x) == ',' || (x) == ';' || (x) == '[' || (x) == ']' || \
(x) == '(' || (x) == ')' || (x) == '{' || (x) == '}' || (x) == '\x1b')

Expand Down Expand Up @@ -211,7 +211,7 @@ static char *filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint
}
char *colon = strstr (ptr, ":");
bool size_suffix = false;
if (colon && !(x86 && bits == 16)) {
if (colon && ! (x86 && bits == 16)) {
char *s = colon + 1;
if (s && isdigit ((ut8)*s)) {
char *e = s;
Expand Down Expand Up @@ -411,7 +411,7 @@ static char *filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint
}
memmove (ptr_left, ptr_esc, copied_len);
char *dptr_left = strcpy (ptr_left + copied_len,
(ansi_found && ptr_right - ptr_end + 1 >= 4) ? Color_RESET : "");
(ansi_found && ptr_right - ptr_end + 1 >= 4)? Color_RESET: "");
int dlen = strlen (dptr_left);
dptr_left += dlen;
char *dptr_end = ptr_right + 1;
Expand All @@ -436,7 +436,7 @@ static char *filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint
ut64 tail = r_num_tail_base (NULL, addr, off);
if (tail != UT64_MAX) {
char str[128];
snprintf (str, sizeof (str), "..%"PFMT64x, tail);
snprintf (str, sizeof (str), "..%" PFMT64x, tail);
insert (ptr, str);
}
}
Expand Down Expand Up @@ -639,12 +639,42 @@ static char *filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint
return NULL;
}

static char *apply_camel_syntax(const char *str) {
const char *p = r_str_trim_head_ro (str);
const char *mnem_start = p;
// find first non-space.. maybe just strchr can be enough
while (*p && *p != ' ' && *p != '\t' && *p != '\x1b') {
p++;
}
size_t mnem_len = p - mnem_start;
if (mnem_len == 0) {
return NULL;
}
char *mnem = r_str_ndup (mnem_start, mnem_len);
char *camel_mnem = r_str_snake_to_camel (mnem);
free (mnem);
if (!camel_mnem) {
return NULL;
}
size_t prefix_len = mnem_start - str;
char *result = r_str_newf ("%.*s%s%s", (int)prefix_len, str, camel_mnem, p);
free (camel_mnem);
return result;
}

R_API char *r_asm_parse_filter(RAsm *a, ut64 addr, RFlag *f, RAnalHint *hint, const char *data) {
RAsmPluginSession *aps = a->cur;
char *str = filter (aps, addr, f, hint, data);
if (!str) {
str = strdup (data);
}
if (a->config && a->config->syntax == R_ARCH_SYNTAX_CAMEL) {
char *camel = apply_camel_syntax (str);
if (camel) {
free (str);
str = camel;
}
}
// Handle immediate base conversion
if (hint && hint->immbase && a->config) {
// Use r_asm_parse_immbase for standard bases (8, 10, 16)
Expand Down
2 changes: 1 addition & 1 deletion libr/core/cconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -4104,7 +4104,7 @@ R_API int r_core_config_init(RCore *core) {
SETB ("asm.trace.color", "true", "indent disassembly with trace.count information");
SETB ("asm.trace.space", "false", "indent disassembly with trace.count information");
SETB ("asm.ucase", "false", "use uppercase syntax at disassembly");
SETB ("asm.capitalize", "false", "use camelcase at disassembly");
SETB ("asm.capitalize", "false", "use capitalied instructions in the disassembly"); // maybe this should be asm.syntax=capital
SETB ("asm.var", "true", "show local function variables in disassembly");
SETB ("asm.var.access", "false", "show accesses of local variables");
SETB ("asm.sub.var", "true", "substitute variables in disassembly");
Expand Down
Loading