mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-09 20:04:49 +00:00
* Show progress bar in entropy calculation output of rahash2
- Allow per-block hash calculation instead of only full file
This commit is contained in:
parent
de5f4061ee
commit
a050b58797
@ -1,4 +1,4 @@
|
||||
BIN=rahash2
|
||||
BINDEPS=r_hash r_util
|
||||
BINDEPS=r_hash r_util r_print
|
||||
|
||||
include ../binr.mk
|
||||
|
@ -1,15 +1,47 @@
|
||||
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <r_hash.h>
|
||||
#include <r_util.h>
|
||||
#include <r_print.h>
|
||||
|
||||
static int do_hash_internal(RHash *ctx, ut64 from, int hash, const ut8 *buf, int len, int rad) {
|
||||
const ut8 *c = ctx->digest;
|
||||
int i, dlen;
|
||||
const char *hname = r_hash_name (hash);
|
||||
dlen = r_hash_calculate (ctx, hash, buf, len);
|
||||
if (!dlen)
|
||||
return 0;
|
||||
if (rad) {
|
||||
printf ("e file.%s=", hname);
|
||||
for (i=0; i<dlen; i++)
|
||||
printf ("%02x", c[i]);
|
||||
printf ("\n");
|
||||
} else {
|
||||
if (hash == R_HASH_ENTROPY) {
|
||||
double e = r_hash_entropy (buf, len);
|
||||
printf ("0x%08"PFMT64x"-0x%08"PFMT64x" %10f: ",
|
||||
from, from+len, e);
|
||||
r_print_progressbar (NULL, 17 * e, 60);
|
||||
printf ("\n");
|
||||
} else {
|
||||
printf ("0x%08"PFMT64x"-0x%08"PFMT64x" %s: ",
|
||||
from, from+len, hname);
|
||||
for (i=0; i<dlen; i++)
|
||||
printf ("%02x", c[i]);
|
||||
printf ("\n");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int do_hash(const char *algo, const ut8 *buf, int len, int bsize, int rad) {
|
||||
struct r_hash_t *ctx;
|
||||
const ut8 *c;
|
||||
int i, j, dlen;
|
||||
RHash *ctx;
|
||||
ut64 j;
|
||||
int i;
|
||||
ut64 algobit = r_hash_name_to_bits (algo);
|
||||
|
||||
if (algobit == R_HASH_NONE) {
|
||||
eprintf ("Invalid hashing algorithm specified\n");
|
||||
return 1;
|
||||
@ -20,20 +52,10 @@ static int do_hash(const char *algo, const ut8 *buf, int len, int bsize, int rad
|
||||
/* iterate over all algorithm bits */
|
||||
for (i=1; i<0x800000; i<<=1) {
|
||||
if (algobit & i) {
|
||||
dlen = r_hash_calculate (ctx, algobit&i, buf, len);
|
||||
if (dlen) {
|
||||
c = ctx->digest;
|
||||
if (rad) {
|
||||
printf ("e file.%s=", r_hash_name(i));
|
||||
for (j=0;j<dlen;j++)
|
||||
printf ("%02x", c[j]);
|
||||
printf ("\n");
|
||||
} else {
|
||||
printf ("%s: ", r_hash_name (i));
|
||||
for(j=0;j<dlen;j++)
|
||||
printf ("%02x", c[j]);
|
||||
printf ("\n");
|
||||
}
|
||||
for (j=0; j<len; j+= bsize) {
|
||||
if (j+bsize<len)
|
||||
do_hash_internal (ctx, j, i, buf+j, bsize, rad);
|
||||
else do_hash_internal (ctx, j, i, buf+j, len-j, rad);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,7 +68,7 @@ static int do_help(int line) {
|
||||
if (line) return 0;
|
||||
printf (
|
||||
" -a algo comma separated list of algorithms (default is 'sha1')\n"
|
||||
" -b bsize specify the size of the block\n"
|
||||
" -b bsize specify the size of the block (instead of full file)\n"
|
||||
" -s string hash this string instead of files\n"
|
||||
" -r output radare commands\n"
|
||||
" -V show version information\n"
|
||||
@ -88,5 +110,7 @@ int main(int argc, char **argv) {
|
||||
buf = (const ut8*)r_file_slurp (argv[optind], &buf_len);
|
||||
if (buf == NULL)
|
||||
return do_help (1);
|
||||
if (bsize == 0)
|
||||
bsize = buf_len;
|
||||
return do_hash (algo, buf, buf_len, bsize, rad);
|
||||
}
|
||||
|
@ -713,6 +713,7 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
||||
}
|
||||
} else
|
||||
if (!strcmp (op, "jz") || !strcmp (op, "je")) {
|
||||
if (isnum (arg)) {
|
||||
ut32 dst = getnum (arg) - offset;
|
||||
if (dst>-0x80 && dst<0x7f) {
|
||||
dst-=2;
|
||||
|
@ -299,15 +299,21 @@ R_API void r_print_c(RPrint *p, const ut8 *str, int len) {
|
||||
p->printf (" };\n");
|
||||
}
|
||||
|
||||
// HACK :D
|
||||
static RPrint staticp = {
|
||||
.printf = printf
|
||||
};
|
||||
|
||||
/* TODO: handle screen width */
|
||||
// TODO: use stderr here?
|
||||
R_API void r_print_progressbar(RPrint *p, int pc, int _cols) {
|
||||
int tmp, cols = (_cols==-1)?78:_cols;
|
||||
int i, cols = (_cols==-1)? 78: _cols;
|
||||
if (!p) p = &staticp;
|
||||
(pc<0)?pc=0:(pc>100)?pc=100:0;
|
||||
p->printf ("%4d%% [", pc);
|
||||
cols -= 15;
|
||||
for (tmp=cols*pc/100;tmp;tmp--) p->printf ("#");
|
||||
for (tmp=cols-(cols*pc/100);tmp;tmp--) p->printf ("-");
|
||||
for (i=cols*pc/100;i;i--) p->printf ("#");
|
||||
for (i=cols-(cols*pc/100);i;i--) p->printf ("-");
|
||||
p->printf ("]");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user