Initial commit
This commit is contained in:
@@ -0,0 +1,254 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <CL/cl.h>
|
||||
|
||||
#define CL_PLATFORMS_MAX 128
|
||||
#define CL_DEVICES_MAX 128
|
||||
|
||||
//char options[] = "–x spir -spir-std=1.2 -I.";
|
||||
char options[] = "-I. -x clc++ -cl-std=CL1.2";
|
||||
|
||||
static void checkErr (char *func, cl_int err)
|
||||
{
|
||||
if (err != CL_SUCCESS)
|
||||
{
|
||||
fprintf (stderr, "%s(): ", func);
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case CL_BUILD_PROGRAM_FAILURE :
|
||||
fprintf (stderr, "CL_BUILD_PROGRAM_FAILURE");
|
||||
break;
|
||||
|
||||
case CL_COMPILER_NOT_AVAILABLE :
|
||||
fprintf (stderr, "CL_COMPILER_NOT_AVAILABLE");
|
||||
break;
|
||||
|
||||
case CL_DEVICE_NOT_AVAILABLE :
|
||||
fprintf (stderr, "CL_DEVICE_NOT_AVAILABLE");
|
||||
break;
|
||||
|
||||
case CL_DEVICE_NOT_FOUND :
|
||||
fprintf (stderr, "CL_DEVICE_NOT_FOUND");
|
||||
break;
|
||||
|
||||
case CL_INVALID_BINARY :
|
||||
fprintf (stderr, "CL_INVALID_BINARY");
|
||||
break;
|
||||
|
||||
case CL_INVALID_BUILD_OPTIONS :
|
||||
fprintf (stderr, "CL_INVALID_BUILD_OPTIONS");
|
||||
break;
|
||||
|
||||
case CL_INVALID_CONTEXT :
|
||||
fprintf (stderr, "CL_INVALID_CONTEXT");
|
||||
break;
|
||||
|
||||
case CL_INVALID_DEVICE :
|
||||
fprintf (stderr, "CL_INVALID_DEVICE");
|
||||
break;
|
||||
|
||||
case CL_INVALID_DEVICE_TYPE :
|
||||
fprintf (stderr, "CL_INVALID_DEVICE_TYPE");
|
||||
break;
|
||||
|
||||
case CL_INVALID_OPERATION :
|
||||
fprintf (stderr, "CL_INVALID_OPERATION");
|
||||
break;
|
||||
|
||||
case CL_INVALID_PLATFORM :
|
||||
fprintf (stderr, "CL_INVALID_PLATFORM");
|
||||
break;
|
||||
|
||||
case CL_INVALID_PROGRAM :
|
||||
fprintf (stderr, "CL_INVALID_PROGRAM");
|
||||
break;
|
||||
|
||||
case CL_INVALID_VALUE :
|
||||
fprintf (stderr, "CL_INVALID_VALUE");
|
||||
break;
|
||||
|
||||
case CL_OUT_OF_HOST_MEMORY :
|
||||
fprintf (stderr, "CL_OUT_OF_HOST_MEMORY");
|
||||
break;
|
||||
|
||||
default :
|
||||
fprintf (stderr, "Unknown error code: %d", err);
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
|
||||
exit (err);
|
||||
}
|
||||
}
|
||||
|
||||
static char *load_kernel (const char *kernel_file)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
|
||||
if ((fp = fopen (kernel_file, "rb")) != NULL)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat (kernel_file, &st) == -1)
|
||||
{
|
||||
fprintf (stderr, "! stat() failed (%d) : %s\n", errno, strerror (errno));
|
||||
}
|
||||
|
||||
char *buf = (char *) malloc (st.st_size + 1);
|
||||
|
||||
memset (buf, 0, st.st_size + 1);
|
||||
|
||||
size_t num_read = fread (buf, sizeof (char), st.st_size, fp);
|
||||
|
||||
if (num_read != (size_t) st.st_size)
|
||||
{
|
||||
fprintf (stderr, "! fread() [%s] failed (%d) : %s", kernel_file, errno, strerror (errno));
|
||||
fclose (fp);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
|
||||
return buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "! fopen() [%s] failed (%d) : %s", kernel_file, errno, strerror (errno));
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int writeProgramBins (char *dst, unsigned char *binary, size_t binary_size)
|
||||
{
|
||||
FILE *fp = fopen (dst, "wb");
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
fprintf(stderr, "! fopen() [%s] failed (%d) : %s\n", dst, errno, strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fwrite (binary, sizeof (unsigned char), binary_size, fp) != binary_size)
|
||||
{
|
||||
fprintf(stderr, "! fwrite() [%s] failed (%d) : %s\n", dst, errno, strerror (errno));
|
||||
fclose (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc != 4)
|
||||
{
|
||||
fprintf (stderr, "> Usage: %s ccopts src dst\n", argv[0]);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
char *ccopts = argv[1];
|
||||
char *src = argv[2];
|
||||
char *dst = argv[3];
|
||||
|
||||
char *programSrc = load_kernel (src);
|
||||
|
||||
if (programSrc == NULL)
|
||||
{
|
||||
fprintf (stderr, "Unable to open %s. Exiting.\n", src);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
cl_device_id devices[1];
|
||||
cl_uint nDevices;
|
||||
|
||||
cl_platform_id platform;
|
||||
cl_uint platforms;
|
||||
|
||||
cl_int err;
|
||||
|
||||
err = clGetPlatformIDs(1, &platform, &platforms);
|
||||
|
||||
checkErr ((char *) "clGetPlatformIDs", err);
|
||||
|
||||
err = clGetDeviceIDs (platform, CL_DEVICE_TYPE_GPU, 1, devices, &nDevices);
|
||||
|
||||
checkErr ((char *) "clGetDeviceIDs", err);
|
||||
|
||||
cl_context context = clCreateContext (NULL, 1, devices, NULL, NULL, &err);
|
||||
|
||||
checkErr ((char *) "clCreateContext", err);
|
||||
|
||||
cl_program program = clCreateProgramWithSource (context, 1, (const char **) &programSrc, NULL, &err);
|
||||
|
||||
checkErr ((char *) "clCreateProgramWithSource", err);
|
||||
|
||||
size_t opt_len = strlen (ccopts) + 1 + strlen (options) + 1;
|
||||
|
||||
char *options2 = (char *) malloc (opt_len + 1);
|
||||
|
||||
memset (options2, 0, opt_len + 1);
|
||||
|
||||
snprintf (options2, opt_len, "%s %s", options, ccopts);
|
||||
|
||||
err = clCompileProgram (program, 1, devices, options2, 0, NULL, NULL, NULL, NULL);
|
||||
|
||||
//checkErr ((char *) "clCompileProgram", err);
|
||||
|
||||
size_t ret_val_size = 0;
|
||||
|
||||
err = clGetProgramBuildInfo (program, devices[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
|
||||
|
||||
checkErr ((char *) "clGetProgramBuildInfo", err);
|
||||
|
||||
if (ret_val_size > 1)
|
||||
{
|
||||
char *build_log = (char *) malloc (ret_val_size + 1);
|
||||
|
||||
memset (build_log, 0, ret_val_size + 1);
|
||||
|
||||
err = clGetProgramBuildInfo (program, devices[0], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
|
||||
|
||||
checkErr ((char *) "clGetProgramBuildInfo", err);
|
||||
|
||||
puts (build_log);
|
||||
}
|
||||
|
||||
size_t binary_size;
|
||||
|
||||
err = clGetProgramInfo (program, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL);
|
||||
|
||||
checkErr ((char *) "clGetProgramInfo", err);
|
||||
|
||||
unsigned char *binary = (unsigned char *) malloc (binary_size);
|
||||
|
||||
memset(binary, 0, binary_size);
|
||||
|
||||
err = clGetProgramInfo (program, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL);
|
||||
|
||||
checkErr ((char *) "clGetProgramInfo", err);
|
||||
|
||||
err = writeProgramBins (dst, binary, binary_size);
|
||||
|
||||
checkErr ((char *) "writeProgramBins", err);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+124
@@ -0,0 +1,124 @@
|
||||
#!/bin/bash
|
||||
# Author: Gabriele Gristina <matrix@hashcat.net>
|
||||
# Revision: 1.0
|
||||
|
||||
## global vars
|
||||
DEPS="make gcc-4.9 g++-4.9 gcc-4.9-multilib g++-4.9-multilib libc6-dev-i386 mingw-w64 build-essential unzip"
|
||||
DOWNLOAD_DEPS="ADL_SDK8.zip R352-developer.zip cuda_7.5.18_linux.run NVIDIA-Linux-x86_64-352.21.run gdk_linux_amd64_352_55_release.run AMDAPPSDK-3.0-linux64.tar.bz2"
|
||||
|
||||
## root check
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
echo "! Must be root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## cleanup 'hashcat-deps' directories
|
||||
rm -rf /opt/hashcat-deps/{adl-sdk,cuda-7.5,NVIDIA-Linux-x86_64-352.21,nvidia-gdk,amd-app-sdk} && \
|
||||
mkdir -p /opt/hashcat-deps/{tmp,adl-sdk,cuda-7.5,NVIDIA-Linux-x86_64-352.21,nvidia-gdk,amd-app-sdk} && \
|
||||
cd /opt/hashcat-deps/tmp
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "! Cannot create hashcat-deps directories."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## check dependencies
|
||||
i=0
|
||||
for d in ${DOWNLOAD_DEPS}; do
|
||||
if [ ! -f "${d}" ]; then
|
||||
echo "! ${d} not found."
|
||||
((i++))
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${i} -gt 0 ]; then
|
||||
echo "! Please download manually into the directory /opt/hashcat-deps/tmp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## installing needed packages
|
||||
for pkg in ${DEPS}; do
|
||||
apt-get -y install ${pkg}
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "! failed to install ${pkg}"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
## extract ADL SDK
|
||||
unzip ADL_SDK8.zip -d /opt/hashcat-deps/adl-sdk-8
|
||||
ret=$?
|
||||
|
||||
if [[ ${ret} -ne 0 ]] && [[ ${ret} -ne 1 ]]; then
|
||||
echo "! failed to extract ADL SDK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf /opt/hashcat-deps/adl-sdk && ln -s /opt/hashcat-deps/adl-sdk-8 /opt/hashcat-deps/adl-sdk
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "! failed to setup ADL SDK link"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## extract NVAPI
|
||||
unzip R352-developer.zip -d /opt/hashcat-deps/
|
||||
ret=$?
|
||||
|
||||
if [[ ${ret} -ne 0 ]] && [[ ${ret} -ne 1 ]]; then
|
||||
echo "! failed to extract NVAPI"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## install CUDA SDK
|
||||
chmod +x cuda_7.5.18_linux.run && \
|
||||
./cuda_7.5.18_linux.run -toolkit -silent -override --toolkitpath=/opt/hashcat-deps/cuda-7.5
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "! failed to install CUDA SDK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## install NVIDIA Driver
|
||||
chmod +x NVIDIA-Linux-x86_64-352.21.run && \
|
||||
./NVIDIA-Linux-x86_64-352.21.run -x && \
|
||||
mv NVIDIA-Linux-x86_64-352.21 /opt/hashcat-deps/ && \
|
||||
cd /opt/hashcat-deps/NVIDIA-Linux-x86_64-352.21 && \
|
||||
ln -s libnvidia-ml.so.352.21 libnvidia-ml.so && \
|
||||
ln -s libcuda.so.352.21 libcuda.so && \
|
||||
cd 32 && \
|
||||
ln -s libnvidia-ml.so.352.21 libnvidia-ml.so && \
|
||||
ln -s libcuda.so.352.21 libcuda.so && \
|
||||
cd /opt/hashcat-deps/tmp
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "! failed to install NVIDIA Driver"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## install NVIDIA GPU Deployment Kit
|
||||
chmod +x gdk_linux_amd64_352_55_release.run && \
|
||||
./gdk_linux_amd64_352_55_release.run --silent --installdir=/opt/hashcat-deps/nvidia-gdk
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "! failed to install NVIDIA GPU Deployment Kit"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## extract AMD APP SDK
|
||||
tar xjf AMDAPPSDK-3.0-linux64.tar.bz2 && \
|
||||
./AMD-APP-SDK-v3.0.130.135-GA-linux64.sh --noexec --target /opt/hashcat-deps/amd-app-sdk-v3.0.130.135
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "! failed to extract AMD APP SDK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf /opt/hashcat-deps/amd-app-sdk && ln -s /opt/hashcat-deps/amd-app-sdk-v3.0.130.135 /opt/hashcat-deps/amd-app-sdk
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "! failed to setup ADL SDK link"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "> oclHashcat dependencies have been resolved."
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
##
|
||||
## Author......: Jens Steube <jens.steube@gmail.com>
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
export IN=$HOME/oclHashcat
|
||||
export OUT=$HOME/xy/oclHashcat-2.00
|
||||
|
||||
rm -rf $OUT
|
||||
rm -rf $OUT.7z
|
||||
|
||||
mkdir -p $OUT $OUT/kernels $OUT/kernels/4098
|
||||
|
||||
cp $IN/oclHashcat??.exe $OUT/
|
||||
cp $IN/oclHashcat??.bin $OUT/
|
||||
cp $IN/hashcat.hcstat $OUT/
|
||||
|
||||
cp -r $IN/docs $OUT/
|
||||
cp -r $IN/charsets $OUT/
|
||||
cp -r $IN/masks $OUT/
|
||||
cp -r $IN/rules $OUT/
|
||||
cp -r $IN/extra $OUT/
|
||||
cp $IN/example.dict $OUT/
|
||||
cp $IN/example[0123456789]*.hash $OUT/
|
||||
cp $IN/oclExample[0123456789]*.sh $OUT/
|
||||
cp $IN/oclExample[0123456789]*.cmd $OUT/
|
||||
|
||||
cp -r $IN/kernels/4098/*.llvmir $OUT/kernels/4098/
|
||||
|
||||
dos2unix $OUT/rules/*.rule
|
||||
dos2unix $OUT/rules/hybrid/*.rule
|
||||
dos2unix $OUT/docs/*
|
||||
dos2unix $OUT/example*
|
||||
dos2unix $OUT/*Example*.sh
|
||||
dos2unix $OUT/*Example*.cmd
|
||||
|
||||
unix2dos $OUT/masks/*.hcmask
|
||||
unix2dos $OUT/rules/*.rule
|
||||
unix2dos $OUT/rules/hybrid/*.rule
|
||||
unix2dos $OUT/docs/*
|
||||
unix2dos $OUT/example*
|
||||
unix2dos $OUT/*Example*.cmd
|
||||
|
||||
chmod 700 $OUT
|
||||
chmod 700 $OUT/kernels
|
||||
chmod 700 $OUT/kernels/4098
|
||||
chmod 600 $OUT/kernels/4098/*
|
||||
chmod 700 $OUT/rules
|
||||
chmod 600 $OUT/rules/*
|
||||
chmod 700 $OUT/docs
|
||||
chmod 600 $OUT/docs/*
|
||||
chmod 700 $OUT/charsets
|
||||
chmod 700 $OUT/charsets/*
|
||||
chmod 700 $OUT/masks
|
||||
chmod 600 $OUT/masks/*
|
||||
chmod 600 $OUT/example*
|
||||
chmod 600 $OUT/*Example*.cmd
|
||||
chmod 700 $OUT/*Example*.sh
|
||||
chmod 700 $OUT/extra
|
||||
chmod 700 $OUT/extra/tab_completion/*.sh
|
||||
chmod 700 $OUT/extra/tab_completion/install
|
||||
chmod 600 $OUT/extra/rules_optimize/*.exe
|
||||
chmod 700 $OUT/extra/rules_optimize/*.bin
|
||||
chmod 600 $OUT/*.exe
|
||||
chmod 700 $OUT/*.bin
|
||||
chmod 600 $OUT/hashcat.hcstat
|
||||
|
||||
time 7z a -t7z -m0=lzma2:d31 -mx=9 -mmt=8 -ms=on $OUT.7z $OUT
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
##
|
||||
## Author......: Jens Steube <jens.steube@gmail.com>
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
export IN=$HOME/oclHashcat
|
||||
export OUT=$HOME/xy/cudaHashcat-2.00
|
||||
|
||||
rm -rf $OUT
|
||||
rm -rf $OUT.7z
|
||||
|
||||
mkdir -p $OUT $OUT/kernels $OUT/kernels/4318
|
||||
|
||||
cp $IN/cudaHashcat??.exe $OUT/
|
||||
cp $IN/cudaHashcat??.bin $OUT/
|
||||
cp $IN/hashcat.hcstat $OUT/
|
||||
|
||||
cp -r $IN/docs $OUT/
|
||||
cp -r $IN/charsets $OUT/
|
||||
cp -r $IN/masks $OUT/
|
||||
cp -r $IN/rules $OUT/
|
||||
cp -r $IN/extra $OUT/
|
||||
cp $IN/example.dict $OUT/
|
||||
cp $IN/example[0123456789]*.hash $OUT/
|
||||
cp $IN/cudaExample[0123456789]*.sh $OUT/
|
||||
cp $IN/cudaExample[0123456789]*.cmd $OUT/
|
||||
|
||||
cp -r $IN/kernels/4318/*.cubin $OUT/kernels/4318/
|
||||
|
||||
dos2unix $OUT/rules/*.rule
|
||||
dos2unix $OUT/rules/hybrid/*.rule
|
||||
dos2unix $OUT/docs/*
|
||||
dos2unix $OUT/example*
|
||||
dos2unix $OUT/*Example*.sh
|
||||
dos2unix $OUT/*Example*.cmd
|
||||
|
||||
unix2dos $OUT/masks/*.hcmask
|
||||
unix2dos $OUT/rules/*.rule
|
||||
unix2dos $OUT/rules/hybrid/*.rule
|
||||
unix2dos $OUT/docs/*
|
||||
unix2dos $OUT/example*
|
||||
unix2dos $OUT/*Example*.cmd
|
||||
|
||||
chmod 700 $OUT
|
||||
chmod 700 $OUT/kernels
|
||||
chmod 700 $OUT/kernels/4318
|
||||
chmod 600 $OUT/kernels/4318/*
|
||||
chmod 700 $OUT/rules
|
||||
chmod 600 $OUT/rules/*
|
||||
chmod 700 $OUT/docs
|
||||
chmod 600 $OUT/docs/*
|
||||
chmod 700 $OUT/charsets
|
||||
chmod 700 $OUT/charsets/*
|
||||
chmod 700 $OUT/masks
|
||||
chmod 600 $OUT/masks/*
|
||||
chmod 600 $OUT/example*
|
||||
chmod 600 $OUT/*Example*.cmd
|
||||
chmod 700 $OUT/*Example*.sh
|
||||
chmod 700 $OUT/extra
|
||||
chmod 700 $OUT/extra/tab_completion/*.sh
|
||||
chmod 700 $OUT/extra/tab_completion/install
|
||||
chmod 600 $OUT/extra/rules_optimize/*.exe
|
||||
chmod 700 $OUT/extra/rules_optimize/*.bin
|
||||
chmod 600 $OUT/*.exe
|
||||
chmod 700 $OUT/*.bin
|
||||
chmod 600 $OUT/hashcat.hcstat
|
||||
|
||||
time 7z a -t7z -m0=lzma2:d28 -mx=9 -mmt=8 -ms=on $OUT.7z $OUT
|
||||
@@ -0,0 +1,22 @@
|
||||
##
|
||||
## Author......: Jens Steube <jens.steube@gmail.com>
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
GCC ?= /usr/bin/x86_64-linux-gnu-gcc
|
||||
MINGW ?= i686-w64-mingw32-gcc
|
||||
ROOT := ../..
|
||||
CFLAGS := -O2 -s -std=c99 -pipe -W -Wall -I$(ROOT)/include/ -I../rules_test/
|
||||
SRC := ./rules_optimize.c
|
||||
TARGET := $(ROOT)/extra/rules_optimize/rules_optimize
|
||||
|
||||
all: ${TARGET}.bin ${TARGET}.exe
|
||||
|
||||
${TARGET}.bin: $(SRC)
|
||||
${GCC} ${CFLAGS} ../rules_test/cpu_rules.c $< -o ${TARGET}.bin
|
||||
|
||||
${TARGET}.exe: $(SRC)
|
||||
${MINGW} ${CFLAGS} ../rules_test/cpu_rules.c $< -o ${TARGET}.exe
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)*.bin $(TARGET)*.exe
|
||||
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MIN_FUNCTIONS 1
|
||||
#define MAX_FUNCTIONS 5
|
||||
|
||||
int max_len = 0;
|
||||
|
||||
#include "cpu_rules.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char rule_buf[BLOCK_SIZE];
|
||||
int rule_len;
|
||||
|
||||
} rule_t;
|
||||
|
||||
static int cmp (const void *p1, const void *p2)
|
||||
{
|
||||
rule_t *r1 = (rule_t *) p1;
|
||||
rule_t *r2 = (rule_t *) p2;
|
||||
|
||||
return r1->rule_len - r2->rule_len;
|
||||
}
|
||||
|
||||
int process_block (int o[BLOCK_SIZE], char *block_ptr[BLOCK_SIZE], int block_cnt, char *word_buf, char final_buf[BLOCK_SIZE], int final_len, char rule_buf[BLOCK_SIZE])
|
||||
{
|
||||
int last_o = o[0];
|
||||
|
||||
for (int i = 1; i < block_cnt; i++)
|
||||
{
|
||||
if (o[i] < last_o) return (0);
|
||||
}
|
||||
|
||||
memset (rule_buf, 0, BLOCK_SIZE);
|
||||
|
||||
strcat (rule_buf, block_ptr[o[0]]);
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 1; i < block_cnt; i++)
|
||||
{
|
||||
strcat (rule_buf, " ");
|
||||
|
||||
strcat (rule_buf, block_ptr[o[i]]);
|
||||
}
|
||||
|
||||
char out_buf[BLOCK_SIZE];
|
||||
|
||||
memset (out_buf, 0, sizeof (out_buf));
|
||||
|
||||
int out_len = apply_rule_cpu (rule_buf, strlen (rule_buf), word_buf, strlen (word_buf), out_buf);
|
||||
|
||||
if (out_len == final_len)
|
||||
{
|
||||
if (memcmp (final_buf, out_buf, out_len) == 0) return (1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int next_permutation (int *o, int *p, int k)
|
||||
{
|
||||
p[k]--;
|
||||
|
||||
int j = k % 2 * p[k];
|
||||
|
||||
int tmp = o[j];
|
||||
|
||||
o[j] = o[k];
|
||||
|
||||
o[k] = tmp;
|
||||
|
||||
for (k = 1; p[k] == 0; k++) p[k] = k;
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
FILE *fp = stdin;
|
||||
|
||||
char line_buf[BUFSIZ];
|
||||
|
||||
while (!feof (fp))
|
||||
{
|
||||
/*
|
||||
* line
|
||||
*/
|
||||
|
||||
char *line_ptr = fgets (line_buf, BUFSIZ, fp);
|
||||
|
||||
if (line_ptr == NULL) continue;
|
||||
|
||||
int line_len = strlen (line_ptr);
|
||||
|
||||
if (line_len && line_ptr[line_len - 1] == '\n') line_len--;
|
||||
if (line_len && line_ptr[line_len - 1] == '\r') line_len--;
|
||||
|
||||
line_ptr[line_len] = 0;
|
||||
|
||||
/*
|
||||
* split
|
||||
*/
|
||||
|
||||
char *word_buf = line_ptr;
|
||||
|
||||
char *sep = strchr (line_ptr, ':');
|
||||
|
||||
if (sep == NULL) continue;
|
||||
|
||||
*sep = 0;
|
||||
|
||||
int word_len = sep - word_buf;
|
||||
|
||||
if (strstr (word_buf, "$HEX[")) continue; // not yet supported
|
||||
|
||||
char *rule_buf = sep + 1;
|
||||
|
||||
if (strchr (rule_buf, ':')) continue; // another one? ignore line
|
||||
|
||||
/*
|
||||
* final
|
||||
*/
|
||||
|
||||
char final_buf[BLOCK_SIZE];
|
||||
|
||||
memset (final_buf, 0, sizeof (final_buf));
|
||||
|
||||
int final_len = apply_rule_cpu (rule_buf, strlen (rule_buf), word_buf, strlen (word_buf), final_buf);
|
||||
|
||||
if (final_len < 0) continue;
|
||||
|
||||
if ((final_len == word_len) && (memcmp (word_buf, final_buf, final_len)) == 0) continue;
|
||||
|
||||
/*
|
||||
* split into blocks
|
||||
*/
|
||||
|
||||
char *block_ptr[BLOCK_SIZE];
|
||||
int block_cnt = 0;
|
||||
|
||||
char *ptr = rule_buf;
|
||||
|
||||
for (char *next = NULL; (next = strchr (ptr, ' ')) != NULL; ptr = next + 1)
|
||||
{
|
||||
if (next[1] == ' ') next++;
|
||||
|
||||
*next = 0;
|
||||
|
||||
block_ptr[block_cnt] = ptr;
|
||||
|
||||
block_cnt++;
|
||||
}
|
||||
|
||||
block_ptr[block_cnt] = ptr;
|
||||
|
||||
block_cnt++;
|
||||
|
||||
if (block_cnt < MIN_FUNCTIONS) continue; // to many
|
||||
if (block_cnt > MAX_FUNCTIONS) continue; // to many
|
||||
|
||||
/*
|
||||
* permute blocks, this where the real work starts..
|
||||
*/
|
||||
|
||||
int o[BLOCK_SIZE];
|
||||
int p[BLOCK_SIZE];
|
||||
|
||||
for (int i = 0; i < block_cnt + 1; i++)
|
||||
{
|
||||
o[i] = i;
|
||||
p[i] = i;
|
||||
}
|
||||
|
||||
int k = 1;
|
||||
|
||||
rule_t *rules_buf = (rule_t *) calloc (120 * MAX_FUNCTIONS, sizeof (rule_t)); // 5! = 120, so its guaranteed
|
||||
int rules_cnt = 0;
|
||||
|
||||
char rule_out_buf[BLOCK_SIZE];
|
||||
|
||||
for (int i0 = 0, i1 = 1; i0 < block_cnt; i0++, i1++)
|
||||
{
|
||||
if (process_block (o, block_ptr, i1, word_buf, final_buf, final_len, rule_out_buf) == 1)
|
||||
{
|
||||
memcpy (rules_buf[rules_cnt].rule_buf, rule_out_buf, BLOCK_SIZE);
|
||||
|
||||
rules_buf[rules_cnt].rule_len = i1;
|
||||
|
||||
rules_cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
if (block_cnt >= 2)
|
||||
{
|
||||
while ((k = next_permutation (o, p, k)) != block_cnt)
|
||||
{
|
||||
for (int i0 = 0, i1 = 1; i0 < block_cnt; i0++, i1++)
|
||||
{
|
||||
if (process_block (o, block_ptr, i1, word_buf, final_buf, final_len, rule_out_buf) == 1)
|
||||
{
|
||||
memcpy (rules_buf[rules_cnt].rule_buf, rule_out_buf, BLOCK_SIZE);
|
||||
|
||||
rules_buf[rules_cnt].rule_len = i1;
|
||||
|
||||
rules_cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i0 = 0, i1 = 1; i0 < block_cnt; i0++, i1++)
|
||||
{
|
||||
if (process_block (o, block_ptr, i1, word_buf, final_buf, final_len, rule_out_buf) == 1)
|
||||
{
|
||||
memcpy (rules_buf[rules_cnt].rule_buf, rule_out_buf, BLOCK_SIZE);
|
||||
|
||||
rules_buf[rules_cnt].rule_len = i1;
|
||||
|
||||
rules_cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sort and output the ones with the less length
|
||||
*/
|
||||
|
||||
qsort (rules_buf, rules_cnt, sizeof (rule_t), cmp);
|
||||
|
||||
int first_len = rules_buf[0].rule_len;
|
||||
|
||||
for (int i = 0; i < rules_cnt; i++)
|
||||
{
|
||||
rule_t *rule_buf = &rules_buf[i];
|
||||
|
||||
if (rule_buf->rule_len > first_len) break;
|
||||
|
||||
puts (rule_buf->rule_buf);
|
||||
}
|
||||
|
||||
free (rules_buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
##
|
||||
## Author......: Jens Steube <jens.steube@gmail.com>
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
GCC := /usr/bin/x86_64-linux-gnu-gcc-4.6
|
||||
ROOT := ../../
|
||||
CFLAGS := -O2 -s -ansi -pipe -W -Wall -I$(ROOT)include/
|
||||
LIBS :=
|
||||
TARGET := gpu2cpu_rule_test
|
||||
INCLUDE := $(ROOT)src/rp_gpu_on_cpu.cpp cpu_rules.cpp
|
||||
|
||||
all: ${TARGET}.cpp
|
||||
${GCC} ${CFLAGS} ${INCLUDE} $< -o ${TARGET}.bin ${LIBS}
|
||||
|
||||
clean:
|
||||
rm -f *.bin
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#ifndef CPU_RULES_H
|
||||
#define CPU_RULES_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include "rp_cpu.h"
|
||||
#define BLOCK_SIZE 64
|
||||
#define RULE_RC_REJECT_ERROR -2
|
||||
#define RP_RULE_BUFSIZ 0x100
|
||||
#define RULE_RC_SYNTAX_ERROR -1
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint cmds[15];
|
||||
|
||||
} gpu_rule_t;
|
||||
|
||||
int mangle_lrest (char arr[BLOCK_SIZE], int arr_len);
|
||||
int mangle_urest (char arr[BLOCK_SIZE], int arr_len);
|
||||
int mangle_trest (char arr[BLOCK_SIZE], int arr_len);
|
||||
int mangle_reverse (char arr[BLOCK_SIZE], int arr_len);
|
||||
int mangle_double (char arr[BLOCK_SIZE], int arr_len);
|
||||
int mangle_double_times (char arr[BLOCK_SIZE], int arr_len, int times);
|
||||
int mangle_reflect (char arr[BLOCK_SIZE], int arr_len);
|
||||
int mangle_rotate_left (char arr[BLOCK_SIZE], int arr_len);
|
||||
int mangle_rotate_right (char arr[BLOCK_SIZE], int arr_len);
|
||||
int mangle_append (char arr[BLOCK_SIZE], int arr_len, char c);
|
||||
int mangle_prepend (char arr[BLOCK_SIZE], int arr_len, char c);
|
||||
int mangle_delete_at (char arr[BLOCK_SIZE], int arr_len, int upos);
|
||||
int mangle_extract (char arr[BLOCK_SIZE], int arr_len, int upos, int ulen);
|
||||
int mangle_omit (char arr[BLOCK_SIZE], int arr_len, int upos, int ulen);
|
||||
int mangle_insert (char arr[BLOCK_SIZE], int arr_len, int upos, char c);
|
||||
int mangle_insert_multi (char arr[BLOCK_SIZE], int arr_len, int arr_pos, char arr2[BLOCK_SIZE], int arr2_len, int arr2_pos, int arr2_cpy);
|
||||
int mangle_overstrike (char arr[BLOCK_SIZE], int arr_len, int upos, char c);
|
||||
int mangle_truncate_at (char arr[BLOCK_SIZE], int arr_len, int upos);
|
||||
int mangle_replace (char arr[BLOCK_SIZE], int arr_len, char oldc, char newc);
|
||||
int mangle_purgechar (char arr[BLOCK_SIZE], int arr_len, char c);
|
||||
int mangle_dupeblock_prepend (char arr[BLOCK_SIZE], int arr_len, int ulen);
|
||||
int mangle_dupeblock_append (char arr[BLOCK_SIZE], int arr_len, int ulen);
|
||||
int mangle_dupechar_at (char arr[BLOCK_SIZE], int arr_len, int upos, int ulen);
|
||||
int mangle_dupechar (char arr[BLOCK_SIZE], int arr_len);
|
||||
int mangle_switch_at_check (char arr[BLOCK_SIZE], int arr_len, int upos, int upos2);
|
||||
int mangle_switch_at (char arr[BLOCK_SIZE], int arr_len, int upos, int upos2);
|
||||
int mangle_chr_shiftl (uint8_t arr[BLOCK_SIZE], int arr_len, int upos);
|
||||
int mangle_chr_shiftr (uint8_t arr[BLOCK_SIZE], int arr_len, int upos);
|
||||
int mangle_chr_incr (uint8_t arr[BLOCK_SIZE], int arr_len, int upos);
|
||||
int mangle_chr_decr (uint8_t arr[BLOCK_SIZE], int arr_len, int upos);
|
||||
int mangle_title (char arr[BLOCK_SIZE], int arr_len);
|
||||
int generate_random_rule (char rule_buf[RP_RULE_BUFSIZ], uint32_t rp_gen_func_min, uint32_t rp_gen_func_max);
|
||||
int apply_rule_cpu (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len, char out[BLOCK_SIZE]);
|
||||
int cpu_rule_to_gpu_rule (char rule_buf[BUFSIZ], uint rule_len, gpu_rule_t *rule);
|
||||
|
||||
typedef int bool;
|
||||
|
||||
bool class_num (char c);
|
||||
bool class_lower (char c);
|
||||
bool class_upper (char c);
|
||||
bool class_alpha (char c);
|
||||
char conv_ctoi (char c);
|
||||
char conv_itoc (char c);
|
||||
|
||||
uint get_random_num (uint min, uint max);
|
||||
|
||||
void gen_cmask (const uint8_t *word, uint8_t *cmask, const uint len);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define RULES_PER_PLAIN_MIN 1
|
||||
#define RULES_PER_PLAIN_MAX 99
|
||||
#define RP_GEN_FUNC_MIN 1
|
||||
#define RP_GEN_FUNC_MAX 4
|
||||
#define PW_MAX 32
|
||||
#define LINE_SIG_LEN RP_GEN_FUNC_MAX * 2 + 1
|
||||
|
||||
int max_len = 0;
|
||||
|
||||
#include "cpu_rules.h"
|
||||
#include "rp_gpu_on_cpu.h"
|
||||
|
||||
void print_plain (char *plain, int plain_len)
|
||||
{
|
||||
int need_hexifly = 0;
|
||||
|
||||
unsigned char *plain_ptr = (unsigned char*) plain;
|
||||
|
||||
int k;
|
||||
|
||||
for (k = 0; k < plain_len; k++)
|
||||
{
|
||||
if ((plain_ptr[k] < 0x20) || (plain_ptr[k] > 0x7f))
|
||||
{
|
||||
need_hexifly = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (need_hexifly)
|
||||
{
|
||||
printf ("$HEX[");
|
||||
|
||||
for (k = 0; k < plain_len; k++)
|
||||
{
|
||||
printf ("%02x", plain_ptr[k]);
|
||||
}
|
||||
|
||||
printf ("]");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (k = 0; k < plain_len; k++)
|
||||
{
|
||||
printf ("%c", plain_ptr[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
FILE *fp = stdin;
|
||||
|
||||
char rule_buf[BUFSIZ];
|
||||
|
||||
int rp_gen_func_min = RP_GEN_FUNC_MIN;
|
||||
int rp_gen_func_max = RP_GEN_FUNC_MAX;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/*
|
||||
* line
|
||||
*/
|
||||
|
||||
if (feof (fp)) break;
|
||||
|
||||
char line_buf[BUFSIZ + 1];
|
||||
|
||||
char *line_ptr = fgets (line_buf, BUFSIZ, fp);
|
||||
|
||||
if (line_ptr == NULL) continue;
|
||||
|
||||
int line_len = strlen (line_ptr);
|
||||
|
||||
line_len--;
|
||||
|
||||
if (line_len < 0) continue;
|
||||
if (line_len > PW_MAX) continue;
|
||||
|
||||
memset (line_ptr + line_len, 0, PW_MAX - line_len);
|
||||
|
||||
/*
|
||||
* generate random rule and apply it afterwards
|
||||
*/
|
||||
|
||||
uint max;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
max = get_random_num (RULES_PER_PLAIN_MIN, RULES_PER_PLAIN_MAX);
|
||||
}
|
||||
else
|
||||
{
|
||||
max = 1;
|
||||
}
|
||||
|
||||
uint i;
|
||||
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
int rule_len;
|
||||
|
||||
memset (rule_buf, 0, BLOCK_SIZE);
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
rule_len = (int) generate_random_rule (rule_buf, rp_gen_func_min, rp_gen_func_max);
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy (rule_buf, argv[1], BUFSIZ);
|
||||
|
||||
rule_len = strlen (rule_buf);
|
||||
}
|
||||
|
||||
gpu_rule_t gpu_rule_buf;
|
||||
|
||||
memset (&gpu_rule_buf, 0, sizeof (gpu_rule_t));
|
||||
|
||||
if (cpu_rule_to_gpu_rule (rule_buf, rule_len, &gpu_rule_buf) == -1) continue;
|
||||
|
||||
// cpu
|
||||
char rule_buf_cpu[BLOCK_SIZE];
|
||||
|
||||
memset (rule_buf_cpu, 0, BLOCK_SIZE);
|
||||
|
||||
max_len = 0;
|
||||
|
||||
int out_len_cpu = apply_rule_cpu (rule_buf, rule_len, line_ptr, line_len, rule_buf_cpu);
|
||||
|
||||
if (max_len >= 32) continue;
|
||||
|
||||
// gpu
|
||||
char rule_buf_gpu[BLOCK_SIZE];
|
||||
|
||||
memset (rule_buf_gpu, 0, sizeof (rule_buf_gpu));
|
||||
|
||||
memcpy (rule_buf_gpu, line_buf, line_len);
|
||||
|
||||
uint32_t *plain_ptr = (uint32_t *) rule_buf_gpu;
|
||||
|
||||
int out_len_gpu = apply_rules (gpu_rule_buf.cmds, &plain_ptr[0], &plain_ptr[4], line_len);
|
||||
|
||||
/*
|
||||
* compare
|
||||
*/
|
||||
|
||||
if (out_len_cpu >= 0 && out_len_cpu < 32)
|
||||
{
|
||||
int failed = 1;
|
||||
|
||||
if (out_len_gpu == out_len_cpu)
|
||||
{
|
||||
if (memcmp (rule_buf_gpu, rule_buf_cpu, out_len_gpu) == 0)
|
||||
{
|
||||
failed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* print if failed
|
||||
*/
|
||||
|
||||
if (failed == 1)
|
||||
{
|
||||
printf ("Rule: %s", rule_buf);
|
||||
|
||||
// nicer output
|
||||
int spaces = LINE_SIG_LEN - rule_len;
|
||||
|
||||
if (rule_len > 10) spaces++;
|
||||
if (rule_len > 100) spaces++;
|
||||
|
||||
while (spaces--) printf (".");
|
||||
|
||||
printf (": ");
|
||||
|
||||
// initial line
|
||||
print_plain (line_buf, line_len);
|
||||
|
||||
printf (" %i => ", line_len);
|
||||
|
||||
// modified by cpu
|
||||
print_plain (rule_buf_cpu, out_len_cpu);
|
||||
|
||||
printf (" %i vs ", out_len_cpu);
|
||||
|
||||
// modified by gpu
|
||||
print_plain (rule_buf_gpu, out_len_gpu);
|
||||
|
||||
printf (" %i\n", out_len_gpu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+8579
File diff suppressed because it is too large
Load Diff
Executable
+1869
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user