1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-30 03:48:17 +00:00

Add main_shared Makefile target, create main_shared.c out of main.c library use example

This commit is contained in:
jsteube 2016-10-13 17:27:09 +02:00
parent 8598a79732
commit 10dfea61ad
3 changed files with 134 additions and 73 deletions

View File

@ -91,7 +91,9 @@ VERSION_TAG := $(shell test -d .git && git describe --tags --dirty=
## Compiler flags
##
CFLAGS += -pipe -W -Wall -std=c99 -Iinclude/ -IOpenCL/ -I$(OPENCL_HEADERS_KHRONOS)/
INCLUDE_PATHS := -Iinclude/ -IOpenCL/ -I$(OPENCL_HEADERS_KHRONOS)/
CFLAGS += -pipe -W -Wall -std=c99
ifndef DEBUG
CFLAGS += -O2
@ -105,12 +107,11 @@ endif
##
## Linker flags
##
ifndef DEBUG
LDFLAGS += -s
endif
##
## Native compilation target
##
@ -128,8 +129,8 @@ endif # darwin
ifeq ($(UNAME),Linux)
CFLAGS_NATIVE :=
CFLAGS_NATIVE += $(CFLAGS)
LFLAGS_NATIVE := -lpthread -ldl
CFLAGS_NATIVE += -DWITH_HWMON
LFLAGS_NATIVE := -lpthread -ldl
LFLAGS_NATIVE += $(LDFLAGS)
endif # linux
@ -140,6 +141,14 @@ LFLAGS_NATIVE := -lpthread
LFLAGS_NATIVE += $(LDFLAGS)
endif # freebsd
CFLAGS_NATIVE_SHARED :=
CFLAGS_NATIVE_SHARED += $(CFLAGS)
CFLAGS_NATIVE_SHARED += -DWITH_HWMON -fpic
LFLAGS_NATIVE_SHARED := -L. -lhashcat
LFLAGS_NATIVE_SHARED += -Wl,-rpath=.
LFLAGS_NATIVE_SHARED += -lpthread -ldl
LFLAGS_NATIVE_SHARED += $(LDFLAGS)
##
## Cross compilation target
##
@ -148,7 +157,6 @@ CFLAGS_CROSS_LINUX :=
CFLAGS_CROSS_LINUX += $(CFLAGS)
CFLAGS_CROSS_LINUX += -DWITH_HWMON
#CFLAGS_CROSS_WIN := -D_WIN -DWIN -D__MSVCRT__ -D__USE_MINGW_ANSI_STDIO=1
CFLAGS_CROSS_WIN :=
CFLAGS_CROSS_WIN += $(filter-out -fsanitize=address,$(CFLAGS))
CFLAGS_CROSS_WIN += -DWITH_HWMON
@ -171,6 +179,7 @@ LFLAGS_CROSS_WIN += -lpsapi
OBJS_ALL := affinity autotune benchmark bitmap bitops combinator common convert cpt cpu_aes cpu_crc32 cpu_des cpu_md5 cpu_sha1 cpu_sha256 debugfile dictstat dispatch dynloader event ext_ADL ext_nvapi ext_nvml ext_OpenCL ext_xnvctrl filehandling folder hashcat hashes hlfmt hwmon induct interface locking logfile loopback memory monitor mpsp opencl outfile_check outfile potfile restore rp rp_cpu rp_kernel_on_cpu shared status stdout straight terminal thread timer tuningdb usage user_options weak_hash wordlist
NATIVE_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).NATIVE.o)
NATIVE_SHARED_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).NATIVE.SHARED.o)
LINUX_32_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).LINUX.32.o)
LINUX_64_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).LINUX.64.o)
@ -195,7 +204,7 @@ native: hashcat
binaries: linux32 linux64 win32 win64
clean:
$(RM) -f obj/*.o *.bin *.exe *.restore *.out *.pot *.log hashcat core
$(RM) -f obj/*.o *.bin *.exe *.restore *.out *.pot *.log hashcat hashcat_shared libhashcat.so core
$(RM) -rf *.induct
$(RM) -rf *.outfiles
$(RM) -rf *.dSYM
@ -260,35 +269,48 @@ uninstall:
##
obj/%.NATIVE.o: src/%.c
$(CC) $(CFLAGS_NATIVE) -c -o $@ $<
$(CC) -c $(CFLAGS_NATIVE) $(INCLUDE_PATHS) -o $@ $^
$(BINARY_NATIVE): src/main.c $(NATIVE_OBJS)
$(CC) $(CFLAGS_NATIVE) -o $(BINARY_NATIVE) $^ $(LFLAGS_NATIVE) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\"
$(BINARY_NATIVE): $(NATIVE_OBJS) src/main.c
$(CC) $(CFLAGS_NATIVE) $(INCLUDE_PATHS) -o $@ $^ -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\" $(LFLAGS_NATIVE)
##
## native compiled hashcat (shared)
##
obj/%.NATIVE.SHARED.o: src/%.c
$(CC) -c $(CFLAGS_NATIVE_SHARED) $(INCLUDE_PATHS) -o $@ $^
lib$(BINARY_NATIVE).so: $(NATIVE_SHARED_OBJS)
$(CC) -o $@ $^ -shared
$(BINARY_NATIVE)_shared: lib$(BINARY_NATIVE).so src/main_shared.c
$(CC) $(CFLAGS_NATIVE_SHARED) $(INCLUDE_PATHS) -o $@ $^ -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\" $(LFLAGS_NATIVE_SHARED)
##
## cross compiled hashcat for binary release version
##
obj/%.LINUX.32.o: src/%.c
$(CC_LINUX_32) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_32) -c -o $@ $<
$(CC_LINUX_32) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_32) $(INCLUDE_PATHS) -c -o $@ $<
obj/%.LINUX.64.o: src/%.c
$(CC_LINUX_64) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_64) -c -o $@ $<
$(CC_LINUX_64) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_64) $(INCLUDE_PATHS) -c -o $@ $<
obj/%.WIN.32.o: src/%.c
$(CC_WIN_32) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_32) -c -o $@ $<
$(CC_WIN_32) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_32) $(INCLUDE_PATHS) -c -o $@ $<
obj/%.WIN.64.o: src/%.c
$(CC_WIN_64) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_64) -c -o $@ $<
$(CC_WIN_64) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_64) $(INCLUDE_PATHS) -c -o $@ $<
hashcat32.bin: src/main.c $(LINUX_32_OBJS)
$(CC_LINUX_32) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_32) -o $@ $^ $(LFLAGS_CROSS_LINUX) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\"
$(CC_LINUX_32) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_32) $(INCLUDE_PATHS) -o $@ $^ $(LFLAGS_CROSS_LINUX) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\"
hashcat64.bin: src/main.c $(LINUX_64_OBJS)
$(CC_LINUX_64) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_64) -o $@ $^ $(LFLAGS_CROSS_LINUX) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\"
$(CC_LINUX_64) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_64) $(INCLUDE_PATHS) -o $@ $^ $(LFLAGS_CROSS_LINUX) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\"
hashcat32.exe: src/main.c $(WIN_32_OBJS)
$(CC_WIN_32) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_32) -o $@ $^ $(LFLAGS_CROSS_WIN) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\"
$(CC_WIN_32) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_32) $(INCLUDE_PATHS) -o $@ $^ $(LFLAGS_CROSS_WIN) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\"
hashcat64.exe: src/main.c $(WIN_64_OBJS)
$(CC_WIN_64) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_64) -o $@ $^ $(LFLAGS_CROSS_WIN) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\"
$(CC_WIN_64) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_64) $(INCLUDE_PATHS) -o $@ $^ $(LFLAGS_CROSS_WIN) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\"

View File

@ -11,13 +11,8 @@
#include "types.h"
#include "user_options.h"
#include "usage.h"
#include "hashcat.h"
#define RUN_AS_COMMANDLINE
#if defined (RUN_AS_COMMANDLINE)
#include "memory.h"
#include "hashcat.h"
#include "terminal.h"
#include "thread.h"
#include "status.h"
@ -472,17 +467,6 @@ void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const siz
}
}
#else
void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len)
{
switch (id)
{
}
}
#endif
int main (int argc, char **argv)
{
// hashcat main context
@ -493,11 +477,6 @@ int main (int argc, char **argv)
if (rc_hashcat_init == -1) return -1;
// initialize the session via getops for commandline use or
// alternatively you can set the user_options directly
#if defined (RUN_AS_COMMANDLINE)
// install and shared folder need to be set to recognize "make install" use
char *install_folder = NULL;
@ -549,39 +528,6 @@ int main (int argc, char **argv)
const int rc_hashcat = hashcat (hashcat_ctx, install_folder, shared_folder, argc, argv, COMPTIME);
#else
// this is a bit ugly, but it's the example you're looking for
char *hash = "8743b52063cd84097a65d1633f5c74f5";
char *mask = "?l?l?l?l?l?l?l";
char *hc_argv[] = { hash, mask, NULL };
// initialize the user options with some defaults (you can override them later)
const int rc_options_init = user_options_init (hashcat_ctx);
if (rc_options_init == -1) return -1;
// your own stuff
user_options_t *user_options = hashcat_ctx->user_options;
user_options->hc_argv = hc_argv;
user_options->hc_argc = 2;
user_options->quiet = true;
user_options->potfile_disable = true;
user_options->attack_mode = ATTACK_MODE_BF; // this is -a 3
user_options->hash_mode = 0; // MD5
user_options->workload_profile = 3;
// now run hashcat
const int rc_hashcat = hashcat (hashcat_ctx, NULL, NULL, 0, NULL, 0);
#endif
// finished with hashcat, clean up
hashcat_ctx_destroy (hashcat_ctx);

93
src/main_shared.c Normal file
View File

@ -0,0 +1,93 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "common.h"
#include "types.h"
#include "user_options.h"
#include "usage.h"
#include "memory.h"
#include "hashcat.h"
#include "event.h"
static void main_cracker_hash_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile
fwrite (buf, len, 1, stdout);
fwrite (EOL, sizeof (EOL), 1, stdout);
}
void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len)
{
switch (id)
{
case EVENT_CRACKER_HASH_CRACKED: main_cracker_hash_cracked (hashcat_ctx, buf, len); break;
}
}
int main ()
{
// hashcat main context
hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t)); VERIFY_PTR (hashcat_ctx);
const int rc_hashcat_init = hashcat_ctx_init (hashcat_ctx, event);
if (rc_hashcat_init == -1) return -1;
// install and shared folder need to be set to recognize "make install" use
char *install_folder = NULL;
char *shared_folder = NULL;
#if defined (INSTALL_FOLDER)
install_folder = INSTALL_FOLDER;
#endif
#if defined (SHARED_FOLDER)
shared_folder = SHARED_FOLDER;
#endif
// this is a bit ugly, but it's the example you're looking for
char *hash = "8743b52063cd84097a65d1633f5c74f5";
char *mask = "?l?l?l?l?l?l?l";
char *hc_argv[] = { hash, mask, NULL };
// initialize the user options with some defaults (you can override them later)
const int rc_options_init = user_options_init (hashcat_ctx);
if (rc_options_init == -1) return -1;
// your own stuff
user_options_t *user_options = hashcat_ctx->user_options;
user_options->hc_argv = hc_argv;
user_options->hc_argc = 2;
user_options->quiet = true;
user_options->potfile_disable = true;
user_options->attack_mode = ATTACK_MODE_BF; // this is -a 3
user_options->hash_mode = 0; // MD5
user_options->workload_profile = 3;
// now run hashcat
const int rc_hashcat = hashcat (hashcat_ctx, install_folder, shared_folder, 0, NULL, 0);
hashcat_ctx_destroy (hashcat_ctx);
free (hashcat_ctx);
return rc_hashcat;
}