Skip to content

Commit

Permalink
Add CSV/TSV output format, fix an output bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DesWurstes committed Mar 4, 2018
1 parent 88d313c commit b15d28b
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 47 deletions.
57 changes: 49 additions & 8 deletions oclvanitygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void
usage(const char *name)
{
fprintf(stderr,
"\x1B[44moclVanitygen Cash %s\x1B[0m(" OPENSSL_VERSION_TEXT ")\n"
"\x1B[44moclVanitygen Cash %s\x1B[0m (" OPENSSL_VERSION_TEXT ")\n"
"Usage: %s [-vcqk1NTS] [-d <device>] [-f <filename>|-] [<pattern>...]\n"
"Generates a bitcoin receiving address matching <pattern>, and outputs the\n"
"address and associated private key. The private key may be stored in a safe\n"
Expand Down Expand Up @@ -72,7 +72,8 @@ usage(const char *name)
"-V Enable kernel/OpenCL/hardware verification (SLOW)\n"
"-f <file> File containing list of patterns, one per line\n"
" (Use \"-\" as the file name for stdin)\n"
"-o <file> Write pattern matches to <file>\n"
"-o <file> Write pattern matches to <file> in TSV format (readable)\n"
"-O <file> Write pattern matches to <file> in CSV format (importable e.g. Excel)\n"
"-s <file> Seed random number generator from <file>\n",
version, name);
}
Expand Down Expand Up @@ -105,6 +106,7 @@ main(int argc, char **argv)
vg_ocl_context_t *vocp = NULL;
EC_POINT *pubkey_base = NULL;
const char *result_file = NULL;
const char *result_file_csv = NULL;
char *devstrs[MAX_DEVS];
int ndevstrs = 0;
int opened = 0;
Expand All @@ -116,7 +118,7 @@ main(int argc, char **argv)
int i;

while ((opt = getopt(argc, argv,
"vcqk1Tp:P:d:w:t:g:b:VSh?f:o:s:D:")) != -1) {
"vcqk1Tp:P:d:w:t:g:b:VSh?f:o:O:s:D:")) != -1) {
switch (opt) {
case 'v':
verbose = 2;
Expand Down Expand Up @@ -253,11 +255,19 @@ main(int argc, char **argv)
case 'o':
if (result_file) {
fprintf(stderr,
"Multiple output files specified\n");
"Multiple TSV output files specified\n");
return 1;
}
result_file = optarg;
break;
case 'O':
if (result_file_csv) {
fprintf(stderr,
"Multiple CSV output files specified\n");
return 1;
}
result_file_csv = optarg;
break;
case 's':
if (seedfile != NULL) {
fprintf(stderr,
Expand All @@ -272,10 +282,6 @@ main(int argc, char **argv)
}
}

if (verbose == 2) {
printf("Built on %s.\n", __DATE__);
}

#if OPENSSL_VERSION_NUMBER < 0x10000000L
/* Complain about older versions of OpenSSL */
if (verbose > 0) {
Expand Down Expand Up @@ -323,8 +329,43 @@ main(int argc, char **argv)
vcp = vg_prefix_context_new(addrtype, privtype, testnet);
}

if (result_file) {
FILE *fp = fopen(result_file, "a");
if (!fp) {
fprintf(stderr,
"ERROR: could not open TSV result file: %s\n",
strerror(errno));
return 1;
} else {
fprintf(fp, "Pattern\tAddress\t");
if (pubkey_base == NULL)
fprintf(fp, "Private Key\n");
else
fprintf(fp, "Private Key Part\n");
fclose(fp);
}
}

if (result_file_csv) {
FILE *fp = fopen(result_file_csv, "a");
if (!fp) {
fprintf(stderr,
"ERROR: could not open CSV result file: %s\n",
strerror(errno));
return 1;
} else {
fprintf(fp, "Pattern\tAddress\t");
if (pubkey_base == NULL)
fprintf(fp, "Private Key\n");
else
fprintf(fp, "Private Key Part\n");
fclose(fp);
}
}

vcp->vc_verbose = verbose;
vcp->vc_result_file = result_file;
vcp->vc_result_file_csv = result_file_csv;
vcp->vc_remove_on_match = remove_on_match;
vcp->vc_only_one = only_one;
vcp->vc_pubkeytype = addrtype;
Expand Down
69 changes: 40 additions & 29 deletions pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,11 @@ vg_output_timing_console(vg_context_t *vcp, double count,

if (time > 1000000) {
p = snprintf(&linebuf[p], rem,
"\x1B[34m[%d%% in %e%s]\x1B[0m",
"\x1B[34m[%d%% in %e%s]",
(int) (100 * targ), time, unit);
} else {
p = snprintf(&linebuf[p], rem,
"\x1B[34m[%d%% in %.1f%s]\x1B[0m",
"\x1B[34m[%d%% in %.1f%s]",
(int) (100 * targ), time, unit);
}
assert(p > 0);
Expand All @@ -509,17 +509,18 @@ vg_output_timing_console(vg_context_t *vcp, double count,

if (vcp->vc_found) {
if (vcp->vc_remove_on_match)
p = snprintf(&linebuf[p], rem, "\x1B[34m[Found %lld/%ld]\x1B[0m",
p = snprintf(&linebuf[p], rem, "[Found %lld/%ld]",
vcp->vc_found, vcp->vc_npatterns_start);
else
p = snprintf(&linebuf[p], rem, "\x1B[34m[Found %lld]\x1B[0m",
p = snprintf(&linebuf[p], rem, "[Found %lld]",
vcp->vc_found);
assert(p > 0);
rem -= p;
if (rem < 0)
rem = 0;
}

p = snprintf(&linebuf[p], rem,
"\x1B[0m ");
if (rem) {
memset(&linebuf[sizeof(linebuf)-rem], 0x20, rem);
linebuf[sizeof(linebuf)-1] = '\0';
Expand Down Expand Up @@ -576,27 +577,24 @@ vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey, const char *pattern, in
else
vg_encode_privkey(pkey, vcp->vc_privtype, privkey_buf);

if (!vcp->vc_result_file || (vcp->vc_verbose > 0)) {
if (vcp->vc_verbose > 0 || !vcp->vc_result_file || !vcp->vc_result_file_csv) {
printf("\r%79s\rPattern: \x1b[33m%s\x1b[0m\n", "", pattern);
}

if (vcp->vc_verbose > 0) {
if (vcp->vc_verbose > 1) {
pend = key_buf;
len = i2o_ECPublicKey(pkey, &pend);
printf("Pubkey (hex): ");
dumphex(key_buf, len);
printf("Privkey (hex): ");
dumpbn(EC_KEY_get0_private_key(pkey));
pend = key_buf;
len = i2d_ECPrivateKey(pkey, &pend);
printf("Privkey (ASN1): ");
dumphex(key_buf, len);
}

if (vcp->vc_verbose > 1) {
pend = key_buf;
len = i2o_ECPublicKey(pkey, &pend);
printf("Pubkey (hex): ");
dumphex(key_buf, len);
printf("Privkey (hex): ");
dumpbn(EC_KEY_get0_private_key(pkey));
pend = key_buf;
len = i2d_ECPrivateKey(pkey, &pend);
printf("Privkey (ASN1): ");
dumphex(key_buf, len);
}

if (!vcp->vc_result_file || (vcp->vc_verbose > 0)) {
if (vcp->vc_verbose > 0 || !vcp->vc_result_file || !vcp->vc_result_file_csv) {
if (isscript) {
printf("P2SHAddress: \x1b[32m%s\x1b[0m\n", addr2_buf);
} else {
Expand All @@ -609,18 +607,31 @@ vg_output_match_console(vg_context_t *vcp, EC_KEY *pkey, const char *pattern, in
FILE *fp = fopen(vcp->vc_result_file, "a");
if (!fp) {
fprintf(stderr,
"ERROR: could not open result file: %s\n",
"ERROR: could not open TSV result file: %s\n",
strerror(errno));
} else {
fprintf(fp, "%s\t", pattern);
if (isscript)
fprintf(fp, "%s\t", addr2_buf);
else
fprintf(fp, "%s\n", addr_buf);
fprintf(fp, "%s\n", privkey_buf);
fclose(fp);
}
}
if (vcp->vc_result_file_csv) {
FILE *fp = fopen(vcp->vc_result_file_csv, "a");
if (!fp) {
fprintf(stderr,
"ERROR: could not open CSV result file: %s\n",
strerror(errno));
} else {
fprintf(fp,
"Pattern: %s\n"
, pattern);
fprintf(fp, "%s,", pattern);
if (isscript)
fprintf(fp, "P2SHAddress: %s\n", addr2_buf);
fprintf(fp, "%s,", addr2_buf);
else
fprintf(fp,
"Address: %s\n", addr_buf,);
fprintf(fp, "%s: %s\n", keytype, privkey_buf);
fprintf(fp, "%s\n", addr_buf);
fprintf(fp, "%s\n", privkey_buf);
fclose(fp);
}
}
Expand Down
1 change: 1 addition & 0 deletions pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct _vg_context_s {
int vc_pattern_generation;
double vc_chance;
const char *vc_result_file;
const char *vc_result_file_csv;
int vc_remove_on_match;
int vc_only_one;
int vc_verbose;
Expand Down
71 changes: 61 additions & 10 deletions vanitygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ vg_thread_loop(void *arg)
npoints = 0;
rekey_at = 0;
i = nbatch;
goto outloop;
break;
case 2:
goto out;
Expand Down Expand Up @@ -297,7 +298,7 @@ vg_thread_loop(void *arg)
}
}
}

outloop:
c += i << 1;
if (c >= output_interval) {
output_interval = vg_output_timing(vcp, c, &tvstart);
Expand Down Expand Up @@ -369,7 +370,7 @@ void
usage(const char *name)
{
fprintf(stderr,
"\x1B[44mVanitygen Cash %s\x1B[0m(" OPENSSL_VERSION_TEXT ")\n"
"\x1B[44mVanitygen Cash %s\x1B[0m (" OPENSSL_VERSION_TEXT ")\n"
"Usage: %s [-vcqnrk1T] [-t <threads>] [-f <filename>|-] [<pattern>...]\n"
"Generates a bitcoin receiving address matching <pattern>, and outputs the\n"
"address and associated private key. The private key may be stored in a safe\n"
Expand All @@ -387,12 +388,13 @@ usage(const char *name)
"-k Keep pattern and continue search after finding a match\n"
"-1 Stop after first match\n"
"-T Generate Bitcoin Cash testnet address\n"
"-F <format> Generate address with the given format (pubkey or script)\n"
"-F <format> Generate address with the given format (pubkey or script) (EXPERTS ONLY!)\n"
"-P <pubkey> Specify base public key for piecewise key generation\n"
"-t <threads> Set number of worker threads (Default: number of CPUs)\n"
"-f <file> File containing list of patterns, one per line\n"
" (Use \"-\" as the file name for stdin)\n"
"-o <file> Write pattern matches to <file>\n"
"-o <file> Write pattern matches to <file> in TSV format (readable)\n"
"-O <file> Write pattern matches to <file> in CSV format (importable e.g. Excel)\n"
"-s <file> Seed random number generator from <file>\n",
version, name);
}
Expand All @@ -409,13 +411,14 @@ main(int argc, char **argv)
int pubkeytype;
enum vg_format format = VCF_PUBKEY;
int regex = 0;
int verbose = 1;
unsigned int verbose = 1;
int simulate = 0;
int remove_on_match = 1;
int only_one = 0;
int opt;
char *seedfile = NULL;
const char *result_file = NULL;
const char *result_file_csv = NULL;
char **patterns;
int npatterns = 0;
int nthreads = 0;
Expand All @@ -428,7 +431,7 @@ main(int argc, char **argv)

unsigned int i;

while ((opt = getopt(argc, argv, "cvqnrk1P:TF:t:h?f:o:s:")) != -1) {
while ((opt = getopt(argc, argv, "cvqnrk1P:TF:t:h?f:o:O:s:")) != -1) {
switch (opt) {
case 'c':
fprintf(stderr, "%s\n",
Expand Down Expand Up @@ -528,11 +531,19 @@ main(int argc, char **argv)
case 'o':
if (result_file) {
fprintf(stderr,
"Multiple output files specified\n");
"Multiple TSV output files specified\n");
return 1;
}
result_file = optarg;
break;
case 'O':
if (result_file_csv) {
fprintf(stderr,
"Multiple CSV output files specified\n");
return 1;
}
result_file_csv = optarg;
break;
case 's':
if (seedfile != NULL) {
fprintf(stderr,
Expand All @@ -546,9 +557,6 @@ main(int argc, char **argv)
return 1;
}
}
if (verbose == 2) {
printf("Built on %s.\n", __DATE__);
}

#if OPENSSL_VERSION_NUMBER < 0x10000000L
/* Complain about older versions of OpenSSL */
Expand Down Expand Up @@ -606,8 +614,51 @@ main(int argc, char **argv)
vcp = vg_prefix_context_new(addrtype, privtype, testnet);
}

if (result_file) {
FILE *fp = fopen(result_file, "a");
if (!fp) {
fprintf(stderr,
"ERROR: could not open TSV result file: %s\n",
strerror(errno));
return 1;
} else {
fprintf(fp, "Pattern\t");
if (format == VCF_PUBKEY)
fprintf(fp, "Address\t");
else
fprintf(fp, "P2SH Address\t");
if (pubkey_base == NULL)
fprintf(fp, "Private Key\n");
else
fprintf(fp, "Private Key Part\n");
fclose(fp);
}
}

if (result_file_csv) {
FILE *fp = fopen(result_file_csv, "a");
if (!fp) {
fprintf(stderr,
"ERROR: could not open CSV result file: %s\n",
strerror(errno));
return 1;
} else {
fprintf(fp, "Pattern,");
if (format == VCF_PUBKEY)
fprintf(fp, "Address,");
else
fprintf(fp, "P2SH Address,");
if (pubkey_base == NULL)
fprintf(fp, "Private Key\n");
else
fprintf(fp, "Private Key Part\n");
fclose(fp);
}
}

vcp->vc_verbose = verbose;
vcp->vc_result_file = result_file;
vcp->vc_result_file_csv = result_file_csv;
vcp->vc_remove_on_match = remove_on_match;
vcp->vc_only_one = only_one;
vcp->vc_format = format;
Expand Down

0 comments on commit b15d28b

Please sign in to comment.