Improve pcc output and add a test ##print

This commit is contained in:
Sergi Àlvarez i Capilla 2022-01-11 02:59:30 +01:00
parent dc21a2e081
commit 3fb7de3e2d
2 changed files with 51 additions and 16 deletions

View File

@ -120,25 +120,47 @@ R_API void r_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang
/* implemented in core because of disasm :( */
break;
case 'c': // "pcc"
p->cb_printf ("const char cstr[%d] = \"", len);
{
int col = 0;
const int max_cols = 60;
for (i = 0; !r_print_is_interrupted () && i < len; i++) {
if (col == 0 || col > max_cols) {
p->cb_printf ("\"\\\n \"");
col = 0;
}
if (IS_PRINTABLE (buf[i])) {
p->cb_printf ("%c", buf[i]);
col ++;
} else {
p->cb_printf ("\\x%02x", buf[i]);
col += 4;
int col = 0;
const int max_cols = 60;
p->cb_printf ("const char cstr[%d] = \"", len);
for (i = 0; !r_print_is_interrupted () && i < len; i++) {
if (col == 0 || col > max_cols) {
p->cb_printf ("\"\\\n \"");
col = 0;
}
ut8 ch = buf[i];
switch (ch) {
case '\\':
p->cb_printf ("\\\\");
break;
case '\t':
p->cb_printf ("\\t");
break;
case '\r':
p->cb_printf ("\\r");
break;
case '\n':
p->cb_printf ("\\n");
break;
default:
if (IS_PRINTABLE (buf[i])) {
if (buf[i] == '"') {
p->cb_printf ("\\\"");
} else {
p->cb_printf ("%c", buf[i]);
}
} else {
p->cb_printf ("\\x%02x", buf[i]);
col += 3;
}
break;
}
col += 1;
}
p->cb_printf ("\";\n");
}
}
p->cb_printf ("\";\n");
break;
case 'a': // "pca"
p->cb_printf ("shellcode:");

View File

@ -1,3 +1,16 @@
NAME=pcc
FILE=README.md
CMDS=pcc
EXPECT=<<EOF
const char cstr[256] = ""\
"Radare2 Regression Test Suite\n=============================\n\n"\
"A set of regression tests for Radare2 (http://radare.org).\n\nO"\
"riginally based on work by and now in collaboration with panc"\
"ake.\n\nDirectory Hierarchy\n-------------------\n\n * db/: "\
" The tests";
EOF
RUN
NAME=endian tests: pv4
FILE=-
CMDS=<<EOF