mirror of
https://github.com/radareorg/radare2.git
synced 2025-03-02 19:26:43 +00:00
Fix #10060 - Add ?e? help and Implement '?ep' to print PIE charts
This commit is contained in:
parent
a23212b464
commit
32605a8d91
@ -4522,7 +4522,8 @@ RAsmPlugin r_asm_plugin_x86_nz = {
|
||||
.arch = "x86",
|
||||
.bits = 16 | 32 | 64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.assemble = &assemble };
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
RLibStruct radare_plugin = {
|
||||
|
@ -793,7 +793,22 @@ static int cmd_help(void *data, const char *input) {
|
||||
free (newmsg);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
case 'p':
|
||||
{
|
||||
char *word, *str = strdup (input + 2);
|
||||
RList *list = r_str_split_list (str, " ");
|
||||
ut64 *nums = calloc (sizeof (ut64), r_list_length (list));
|
||||
int i = 0;
|
||||
r_list_foreach (list, iter, word) {
|
||||
nums[i] = r_num_math (core->num, word);;
|
||||
i++;
|
||||
}
|
||||
int size = r_config_get_i (core->config, "hex.cols");
|
||||
r_print_pie (core->print, nums, r_list_length (list), size);
|
||||
r_list_free (list);
|
||||
}
|
||||
break;
|
||||
case ' ': {
|
||||
const char *msg = r_str_trim_ro (input+1);
|
||||
// TODO: replace all ${flagname} by its value in hexa
|
||||
char *newmsg = filterFlags (core, msg);
|
||||
@ -802,6 +817,15 @@ static int cmd_help(void *data, const char *input) {
|
||||
free (newmsg);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
eprintf ("Usage: ?e[...]\n");
|
||||
eprintf (" e msg echo message\n");
|
||||
eprintf (" ep N... echo pie chart\n");
|
||||
eprintf (" eb N... echo portions bar\n");
|
||||
eprintf (" en msg echo without newline\n");
|
||||
eprintf (" eg x y gotoxy\n");
|
||||
eprintf (" es msg use text-to-speech technology\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 's': { // "?s" sequence from to step
|
||||
|
@ -178,6 +178,8 @@ R_API void r_print_init_rowoffsets(RPrint *p);
|
||||
R_API ut32 r_print_rowoff(RPrint *p, int i);
|
||||
R_API void r_print_set_rowoff(RPrint *p, int i, ut32 offset, bool overwrite);
|
||||
R_API int r_print_row_at_off(RPrint *p, ut32 offset);
|
||||
R_API int r_print_pie(RPrint *p, ut64 *values, int nvalues, int size);
|
||||
|
||||
// WIP
|
||||
R_API int r_print_unpack7bit(const char *src, char *dest);
|
||||
R_API int r_print_pack7bit(const char *src, char *dest);
|
||||
|
@ -9,7 +9,7 @@ OBJS+=prof.o cache.o sys.o buf.o w32-sys.o ubase64.o base85.o base91.o
|
||||
OBJS+=list.o flist.o mixed.o btree.o chmod.o graph.o
|
||||
OBJS+=regex/regcomp.o regex/regerror.o regex/regexec.o uleb128.o
|
||||
OBJS+=sandbox.o calc.o thread.o thread_lock.o thread_msg.o
|
||||
OBJS+=strpool.o bitmap.o p_date.o p_format.o print.o
|
||||
OBJS+=strpool.o bitmap.o p_date.o p_format.o p_pie.o print.o
|
||||
OBJS+=p_seven.o slist.o randomart.o log.o zip.o debruijn.o
|
||||
OBJS+=utf8.o utf16.o utf32.o strbuf.o lib.o name.o spaces.o signal.o syscmd.o
|
||||
OBJS+=diff.o bdiff.o stack.o queue.o tree.o des.o idpool.o
|
||||
|
91
libr/util/p_pie.c
Normal file
91
libr/util/p_pie.c
Normal file
@ -0,0 +1,91 @@
|
||||
/* radare2 - LGPL - Copyright 2018 - pancake */
|
||||
|
||||
#include <r_print.h>
|
||||
#include <math.h>
|
||||
#define PI 3.1415
|
||||
#define O out[x + (y * size)]
|
||||
#define USE_SINCOS 0
|
||||
|
||||
// TODO: add support for colors
|
||||
// TODO: better rounding ascii art
|
||||
|
||||
static void drawSectorLine(char *out, int size, int percent) {
|
||||
int i, x, y;
|
||||
double A = (percent) * PI / 50;
|
||||
double foo = 0.1;
|
||||
for (i = (size-1) / 2; i < (size-3) ; i++) {
|
||||
x = y = (size - 1)/ 2;
|
||||
x += cos (A) * foo + 1;
|
||||
y += sin (A) *foo + 1 ;
|
||||
foo += 1.1;
|
||||
O = ':';
|
||||
}
|
||||
}
|
||||
|
||||
R_API int r_print_pie(RPrint *p, ut64 *values, int nvalues, int size) {
|
||||
ut8 *nv = calloc (nvalues, sizeof (ut8));
|
||||
char *out = calloc (size, size);
|
||||
int i, x, y;
|
||||
if (nv && out) {
|
||||
ut64 total = 0;
|
||||
for (i = 0; i<nvalues; i++) {
|
||||
total += values[i];
|
||||
}
|
||||
total /= 100;
|
||||
if (total < 1) {
|
||||
total = 1;
|
||||
}
|
||||
for (i = 0; i<nvalues; i++) {
|
||||
nv[i] = values[i] / total;
|
||||
}
|
||||
for (x = 0; x < size; x++) {
|
||||
for (y = 0; y < size; y++) {
|
||||
O = ' ';
|
||||
}
|
||||
}
|
||||
#if USE_SINCOS
|
||||
float a = 0.0;
|
||||
int s = size / 2;
|
||||
while (a < 2 * PI) {
|
||||
x = s * cos (a) + (size/2);
|
||||
y = s * sin (a) + (size/2);
|
||||
O = '.';
|
||||
a += 0.1;
|
||||
}
|
||||
#else
|
||||
int radius = (size - 1) / 2;
|
||||
|
||||
// draw portions
|
||||
for (x=0; x<=2*radius; x++) {
|
||||
for (y=0; y<=2*radius; y++) {
|
||||
double distance = sqrt((double)(x-radius)*(x-radius) + (y-radius)*(y-radius));
|
||||
O = (distance>radius-0.5 && distance<radius+0.5)? '.': ' ';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
int amount = 0;
|
||||
for (i = 0; i< nvalues; i++) {
|
||||
drawSectorLine (out, size, nv[i] + amount);
|
||||
amount += nv[i];
|
||||
}
|
||||
|
||||
/// render
|
||||
if (p && p->cb_printf) {
|
||||
for (x = 0; x < size; x++) {
|
||||
for (y = 0; y < size; y++) {
|
||||
p->cb_printf ("%c%c", O, O);
|
||||
}
|
||||
p->cb_printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
free (out);
|
||||
free (nv);
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
main() {
|
||||
ut64 v[] = { 10, 20, 30, 40 };
|
||||
r_print_pie (NULL, &v, 4, 20);
|
||||
}
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user