Skip to content

Commit

Permalink
add filehex util
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancdotorg committed Feb 11, 2016
1 parent 20728c6 commit ba23314
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ hexln
hex2blf
blfchk
ecmtabgen
filehex

# Debug files
*.dSYM/
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
HEADERS = bloom.h crack.h hash160.h warpwallet.h
OBJ_MAIN = brainflayer.o hex2blf.o blfchk.o ecmtabgen.o hexln.o
OBJ_MAIN = brainflayer.o hex2blf.o blfchk.o ecmtabgen.o hexln.o filehex.o
OBJ_UTIL = hex.o bloom.o mmapf.o hsearchf.o ec_pubkey_fast.o ripemd160_256.o dldummy.o
OBJ_ALGO = $(patsubst %.c,%.o,$(wildcard algo/*.c))
OBJECTS = $(OBJ_MAIN) $(OBJ_UTIL) $(OBJ_ALGO)
BINARIES = brainflayer hexln hex2blf blfchk ecmtabgen
BINARIES = brainflayer hexln hex2blf blfchk ecmtabgen filehex
LIBS = -lssl -lrt -lcrypto -lz -lgmp
CFLAGS = -O3 \
-flto -funsigned-char -falign-functions=16 -falign-loops=16 -falign-jumps=16 \
Expand Down Expand Up @@ -56,6 +56,9 @@ hex2blf: hex2blf.o hex.o bloom.o mmapf.o
ecmtabgen: ecmtabgen.o mmapf.o ec_pubkey_fast.o
$(COMPILE) -static $^ $(LIBS) -o $@

filehex: filehex.o hex.o
$(COMPILE) -static $^ $(LIBS) -o $@

brainflayer: brainflayer.o $(OBJ_UTIL) $(OBJ_ALGO) \
secp256k1/.libs/libsecp256k1.a scrypt-jane/scrypt-jane.o
$(COMPILE) -static $^ $(LIBS) -o $@
Expand Down
49 changes: 49 additions & 0 deletions filehex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Copyright (c) 2015 Ryan Castellucci, All Rights Reserved */
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include "hex.h"

void filehex(FILE *ifile, const unsigned char *filename) {
unsigned char hexed[65];
unsigned char buf[65536];
size_t offset;
int r, i, buf_pos, i_max;

offset = buf_pos = 0;
while ((r = fread(buf + buf_pos, 1, 256, ifile)) > 0) {
i_max = r + buf_pos - 31;
for (i = 0; i < i_max; ++i, ++offset) {
printf("%s:%s,%zu\n", hex(buf+i, 32, hexed, 65), filename, offset);
}
memcpy(buf, buf+i, buf_pos = 31);
}
}

int main(int argc, char **argv) {
int i;
FILE *ifile;

/*
if (argc > 1) {
fprintf(stderr, "Usage: %s\n", argv[0]);
return 1;
}*/

if (argc == 1) {
filehex(stdin, "STDIN");
} else {
for (i = 1; i < argc; ++i) {
if ((ifile = fopen(argv[i], "r")) != NULL) {
filehex(ifile, argv[i]);
fclose(ifile);
}
}
}

return 0;
}

/* vim: set ts=2 sw=2 et ai si: */

0 comments on commit ba23314

Please sign in to comment.