From 77b7926a502b45a9fcf8b366d465e58dd2bea4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20=C3=80lvarez=20i=20Capilla?= Date: Wed, 9 Feb 2022 12:26:53 +0100 Subject: [PATCH] Add prgl command to decompress current block using lz4 ##print --- libr/core/cmd_print.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index 453764aa1a..0fb55a7b80 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -7,6 +7,12 @@ #include "r_types.h" #include +#ifdef R_MESON_VERSION +#include +#else +#include "../../../shlr/lz4/lz4.c" +#endif + #define R_CORE_MAX_DISASM (1024 * 1024 * 8) #define PF_USAGE_STR "pf[.k[.f[=v]]|[v]]|[n]|[0|cnt][fmt] [a0 a1 ...]" @@ -103,8 +109,9 @@ static const char* help_msg_pr[] = { }; static const char *help_msg_prg[] = { - "Usage: prg[io]", "", "print raw GUNZIPped block", + "Usage: prg[?ilo]", " [len]", "print raw inflated/decompressed block", "prg", "", "print gunzipped data of current block", + "prgl", "", "decompress current block using LZ4 (adjust blocksize)", "prgi", "", "show consumed bytes when inflating", "prgo", "", "show output bytes after inflating", NULL @@ -6422,9 +6429,31 @@ static int cmd_print(void *data, const char *input) { break; case 'g': // "prg" // gunzip switch (input[2]) { + default: case '?': r_core_cmd_help (core, help_msg_prg); break; + case 'l': // "prgl" // lz4 + { + ut8 *dst = calloc (len, 4); + if (dst) { + // TODO. hack into lz4 to make it work without knowing the input + int consumed = 0; + int olen = 0; + ut8 *obuf = r_inflate_lz4 (core->block, len, &consumed, &olen); + if (obuf) { + for (i = 0; i < olen; i += 32) { + int left = R_MIN (olen - i, 32); + r_cons_printf ("wx+"); + r_print_bytes (core->print, obuf + i, left, "%02x"); + } + } else { + eprintf ("Invalid input size %d\n", olen); + } + free (dst); + } + } + break; case 'i': // "prgi" { int outlen = 0; @@ -6444,7 +6473,8 @@ static int cmd_print(void *data, const char *input) { free (out); } break; - default: + case 0: + case ' ': { int outlen = 0; ut8 *out;