Permalink
Browse files

add hexln tool

  • Loading branch information...
ryancdotorg committed Oct 24, 2015
1 parent 2ab38f5 commit 209f1f05da40570f88d3664da81eb49c93c784c6
Showing with 39 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +5 −2 Makefile
  3. +33 −0 hexln.c
View
@@ -29,6 +29,7 @@
*.hex
brainflayer
+hexln
hex2blf
blfchk
ecmtabgen
View
@@ -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)
@@ -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 $@
View
33 hexln.c
@@ -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.