Skip to content

Commit

Permalink
add hexln tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancdotorg committed Oct 24, 2015
1 parent 2ab38f5 commit 209f1f0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*.hex

brainflayer
hexln
hex2blf
blfchk
ecmtabgen
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
OBJ_MAIN = brainflayer.o hex2blf.o blfchk.o ecmtabgen.o hexln.o
OBJ_UTIL = hex.o bloom.o mmapf.o hsearchf.o ec_pubkey_fast.o ripemd160_256.o dldummy.o
OBJ_FMT = warpwallet.o brainwalletio.o brainv2.o
OBJECTS = $(OBJ_MAIN) $(OBJ_UTIL) $(OBJ_FMT)
BINARIES = brainflayer hex2blf blfchk ecmtabgen
BINARIES = brainflayer hexln hex2blf blfchk ecmtabgen
LIBS = -lssl -lrt -lcrypto -lz -lgmp
CFLAGS = -O3 -flto -pedantic -std=gnu99 -Wall -Wextra -funsigned-char -Wno-pointer-sign -Wno-sign-compare
COMPILE = gcc $(CFLAGS)
Expand Down Expand Up @@ -39,6 +39,9 @@ ec_pubkey_fast.o: ec_pubkey_fast.c secp256k1/include/secp256k1.h
%.o: %.c
$(COMPILE) -c $< -o $@

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

blfchk: blfchk.o hex.o bloom.o mmapf.o hsearchf.o
$(COMPILE) -static $^ $(LIBS) -o $@

Expand Down
33 changes: 33 additions & 0 deletions hexln.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright (c) 2015 Ryan Castellucci, All Rights Reserved */
#include <stdlib.h>
#include <stdio.h>

#include "hex.h"

int main(int argc, char **argv) {
char *line = NULL;
size_t line_sz = 0, buf_sz = 2;
ssize_t line_read;
unsigned char *buf = malloc(buf_sz);

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

while ((line_read = getline(&line, &line_sz, stdin)) > 0) {
while (line_sz * 2 > buf_sz) {
buf_sz *= 2;
buf = realloc(buf, buf_sz);
}
if (buf == NULL) {
fprintf(stderr, "memory error\n");
return 1;
}
printf("%s\n", hex(line, line_read - 1, buf, buf_sz));
}

return 0;
}

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

0 comments on commit 209f1f0

Please sign in to comment.