Skip to content

Commit ba23314

Browse files
committed
add filehex util
1 parent 20728c6 commit ba23314

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ hexln
3333
hex2blf
3434
blfchk
3535
ecmtabgen
36+
filehex
3637

3738
# Debug files
3839
*.dSYM/

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
HEADERS = bloom.h crack.h hash160.h warpwallet.h
2-
OBJ_MAIN = brainflayer.o hex2blf.o blfchk.o ecmtabgen.o hexln.o
2+
OBJ_MAIN = brainflayer.o hex2blf.o blfchk.o ecmtabgen.o hexln.o filehex.o
33
OBJ_UTIL = hex.o bloom.o mmapf.o hsearchf.o ec_pubkey_fast.o ripemd160_256.o dldummy.o
44
OBJ_ALGO = $(patsubst %.c,%.o,$(wildcard algo/*.c))
55
OBJECTS = $(OBJ_MAIN) $(OBJ_UTIL) $(OBJ_ALGO)
6-
BINARIES = brainflayer hexln hex2blf blfchk ecmtabgen
6+
BINARIES = brainflayer hexln hex2blf blfchk ecmtabgen filehex
77
LIBS = -lssl -lrt -lcrypto -lz -lgmp
88
CFLAGS = -O3 \
99
-flto -funsigned-char -falign-functions=16 -falign-loops=16 -falign-jumps=16 \
@@ -56,6 +56,9 @@ hex2blf: hex2blf.o hex.o bloom.o mmapf.o
5656
ecmtabgen: ecmtabgen.o mmapf.o ec_pubkey_fast.o
5757
$(COMPILE) -static $^ $(LIBS) -o $@
5858

59+
filehex: filehex.o hex.o
60+
$(COMPILE) -static $^ $(LIBS) -o $@
61+
5962
brainflayer: brainflayer.o $(OBJ_UTIL) $(OBJ_ALGO) \
6063
secp256k1/.libs/libsecp256k1.a scrypt-jane/scrypt-jane.o
6164
$(COMPILE) -static $^ $(LIBS) -o $@

filehex.c

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Copyright (c) 2015 Ryan Castellucci, All Rights Reserved */
2+
#include <stdlib.h>
3+
#include <stdio.h>
4+
#include <stdint.h>
5+
#include <string.h>
6+
7+
#include "hex.h"
8+
9+
void filehex(FILE *ifile, const unsigned char *filename) {
10+
unsigned char hexed[65];
11+
unsigned char buf[65536];
12+
size_t offset;
13+
int r, i, buf_pos, i_max;
14+
15+
offset = buf_pos = 0;
16+
while ((r = fread(buf + buf_pos, 1, 256, ifile)) > 0) {
17+
i_max = r + buf_pos - 31;
18+
for (i = 0; i < i_max; ++i, ++offset) {
19+
printf("%s:%s,%zu\n", hex(buf+i, 32, hexed, 65), filename, offset);
20+
}
21+
memcpy(buf, buf+i, buf_pos = 31);
22+
}
23+
}
24+
25+
int main(int argc, char **argv) {
26+
int i;
27+
FILE *ifile;
28+
29+
/*
30+
if (argc > 1) {
31+
fprintf(stderr, "Usage: %s\n", argv[0]);
32+
return 1;
33+
}*/
34+
35+
if (argc == 1) {
36+
filehex(stdin, "STDIN");
37+
} else {
38+
for (i = 1; i < argc; ++i) {
39+
if ((ifile = fopen(argv[i], "r")) != NULL) {
40+
filehex(ifile, argv[i]);
41+
fclose(ifile);
42+
}
43+
}
44+
}
45+
46+
return 0;
47+
}
48+
49+
/* vim: set ts=2 sw=2 et ai si: */

0 commit comments

Comments
 (0)