diff --git a/bfcl.c b/bfcl.c index 204c161..c6c7f49 100644 --- a/bfcl.c +++ b/bfcl.c @@ -1,6 +1,5 @@ #include <string.h> #include <stdio.h> -#include <stdint.h> #include "utils.h" #include "ocl.h" #include "ocl_brute.h" @@ -18,9 +17,9 @@ static inline cl_ushort u16be(const unsigned char *in){ const char invalid_parameters[] = "invalid parameters\n"; int main(int argc, const char *argv[]) { - stop_bfcl = 0; + stop_bfcl = 0; // Not really used at the moment seedminer_mode = 0; - rws_mode = 0; + reduced_work_size_mode = 0; int ret = 0; if (argc == 1) { ret = ocl_test(); @@ -28,42 +27,29 @@ int main(int argc, const char *argv[]) { cl_uint num_platforms; ocl_info(&num_platforms, 1); // Extremely condensed argument parsing incoming! - } else if ((argc == 5 && !strcmp(argv[1], "msky")) || ((argc == 6 && !strcmp(argv[1], "msky")) && (!strcmp(argv[5], "sws") || !strcmp(argv[5], "rws"))) || ((argc == 7 && !strcmp(argv[1], "msky")) && ((!strcmp(argv[5], "sws") && !strcmp(argv[6], "sm")) || (!strcmp(argv[5], "rws") && !strcmp(argv[6], "sm"))))) { - uint32_t msky[4], ver[4], msky_offset; + } else if (((argc == 7 && !strcmp(argv[1], "msky")) && (!strcmp(argv[6], "sws") || !strcmp(argv[6], "rws"))) || ((argc == 8 && !strcmp(argv[1], "msky")) && ((!strcmp(argv[6], "sws") && !strcmp(argv[7], "sm")) || (!strcmp(argv[6], "rws") && !strcmp(argv[7], "sm"))))) { + uint32_t msky[4], ver[4], msky_offset, msky_max_offset; hex2bytes((unsigned char*)msky, 16, argv[2], 1); hex2bytes((unsigned char*)ver, 16, argv[3], 1); hex2bytes((unsigned char*)&msky_offset, 4, argv[4], 1); - if (argc == 5 && !strcmp(argv[1], "msky")) { - group_bits = 28; - /*Uncomment the following (and delete this current line) when a new Seedminer Python script is released: - deprecation_notice_and_input();*/ - } else if ((argc == 6 || argc == 7) && !strcmp(argv[5], "sws")) { - group_bits = 28; - } else if ((argc == 6 || argc == 7) && !strcmp(argv[5], "rws")) { - rws_mode = 1; - group_bits = 20; + hex2bytes((unsigned char*)&msky_max_offset, 4, argv[5], 1); + if ((argc == 7 || argc == 8) && !strcmp(argv[6], "rws")) { + reduced_work_size_mode = 1; } - if (argc == 7 && !strcmp(argv[6], "sm")) { + if (argc == 8 && !strcmp(argv[7], "sm")) { seedminer_mode = 1; } - ret = ocl_brute_msky(msky, ver, msky_offset); + ret = ocl_brute_msky(msky, ver, msky_offset, msky_max_offset); // More extremely condensed argument parsing incoming! - } else if ((argc == 6 && !strcmp(argv[1], "lfcs")) || ((argc == 7 && !strcmp(argv[1], "lfcs")) && (!strcmp(argv[6], "sws") || !strcmp(argv[6], "rws"))) || ((argc == 8 && !strcmp(argv[1], "msky")) && ((!strcmp(argv[6], "sws") && !strcmp(argv[7], "sm")) || (!strcmp(argv[6], "rws") && !strcmp(argv[7], "sm"))))) { + } else if (((argc == 7 && !strcmp(argv[1], "lfcs")) && (!strcmp(argv[6], "sws") || !strcmp(argv[6], "rws"))) || ((argc == 8 && !strcmp(argv[1], "msky")) && ((!strcmp(argv[6], "sws") && !strcmp(argv[7], "sm")) || (!strcmp(argv[6], "rws") && !strcmp(argv[7], "sm"))))) { uint32_t lfcs, ver[2], lfcs_offset; uint16_t newflag; hex2bytes((unsigned char*)&lfcs, 4, argv[2], 1); hex2bytes((unsigned char*)&newflag, 2, argv[3], 1); hex2bytes((unsigned char*)ver, 8, argv[4], 1); hex2bytes((unsigned char*)&lfcs_offset, 4, argv[5], 1); - if (argc == 6 && !strcmp(argv[1], "lfcs")) { - group_bits = 28; - /*Uncomment the following (and delete this current line) when a new Seedminer Python script is released: - deprecation_notice_and_input();*/ - } else if ((argc == 7 || argc == 8) && !strcmp(argv[6], "sws")) { - group_bits = 28; - } else if ((argc == 7 || argc == 8) && !strcmp(argv[6], "rws")) { - rws_mode = 1; - group_bits = 20; + if ((argc == 7 || argc == 8) && !strcmp(argv[6], "rws")) { + reduced_work_size_mode = 1; } if (argc == 8 && !strcmp(argv[7], "sm")) { seedminer_mode = 1; diff --git a/ocl_brute.c b/ocl_brute.c index db308ea..9383f10 100644 --- a/ocl_brute.c +++ b/ocl_brute.c @@ -317,7 +317,7 @@ int ocl_brute_emmc_cid(const cl_uchar *console_id, cl_uchar *emmc_cid, * https://gbatemp.net/threads/eol-is-lol-the-34c3-talk-for-3ds-that-never-was.494698/ * what I'm doing here is simply brute the 3rd u32 of a u128 so that the first half of sha256 matches ver */ -int ocl_brute_msky(const cl_uint *msky, const cl_uint *ver, cl_uint msky_offset) +int ocl_brute_msky(const cl_uint *msky, const cl_uint *ver, cl_uint msky_offset, cl_uint msky_max_offset) { TimeHP t0, t1; long long td = 0; @@ -343,7 +343,7 @@ int ocl_brute_msky(const cl_uint *msky, const cl_uint *ver, cl_uint msky_offset) size_t local; OCL_ASSERT(clGetKernelWorkGroupInfo(kernel, device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(local), &local, NULL)); - if (seedminer_mode != 1 || rws_mode != 1) { + if (seedminer_mode != 1 || reduced_work_size_mode != 1) { printf("local work size: %u\n", (unsigned)local); } @@ -353,6 +353,10 @@ int ocl_brute_msky(const cl_uint *msky, const cl_uint *ver, cl_uint msky_offset) OCL_ASSERT(clEnqueueWriteBuffer(command_queue, mem_out, CL_TRUE, 0, sizeof(cl_uint), &out, 0, NULL, NULL)); unsigned brute_bits = 32; + unsigned group_bits = 28; + if (reduced_work_size_mode == 1) { + group_bits = 20; + } unsigned loop_bits = brute_bits - group_bits; unsigned loops = 1ull << loop_bits; size_t num_items = 1ull << group_bits; @@ -368,7 +372,7 @@ int ocl_brute_msky(const cl_uint *msky, const cl_uint *ver, cl_uint msky_offset) OCL_ASSERT(clSetKernelArg(kernel, 7, sizeof(cl_uint), &ver[3])); OCL_ASSERT(clSetKernelArg(kernel, 8, sizeof(cl_mem), &mem_out)); get_hp_time(&t0); - int msky3_range = 16384; // "fan out" +/-8192 on msky3 + int msky3_range = msky_max_offset; // You should in theory, at the most, "fan out" +/-8192 on msky3; that being said, an msky_max_offset is required from the user unsigned i, j, k=0; for (j = msky_offset; j < msky3_range; ++j) { int msky3_offset = (j & 1 ? 1 : -1) * ((j + 1) >> 1); @@ -410,7 +414,7 @@ int ocl_brute_msky(const cl_uint *msky, const cl_uint *ver, cl_uint msky_offset) mdata.seedtype=seedtype; snprintf(filename, 0x100, "msed_data_%08X.bin", rnd); printf("msed_data will also be written to\n%s\n",filename); - printf("please share if you can!\n\n"); + printf("just keep it handy if you don't know what to do with it!\n\n"); dump_to_file(filename, &mdata, 12); printf("done.\n"); break; @@ -429,13 +433,17 @@ int ocl_brute_msky(const cl_uint *msky, const cl_uint *ver, cl_uint msky_offset) tested = out + (1ull << brute_bits) * k; } printf("%.2f seconds, %.2f M/s\n", td / 1000000.0, tested * 1.0 / td); - clReleaseKernel(kernel); clReleaseMemObject(mem_out); clReleaseProgram(program); clReleaseCommandQueue(command_queue); clReleaseContext(context); - return !out; + if (!out) { // Could any problems happen because of this? + printf("Max offset reached! Brute-forcing will now terminate!\n"); + exit(101); // For lack of a better exit code + } else { + return !out; + } } // LFCS brute force, https://gist.github.com/zoogie/4046726878dba89eddfa1fc07c8a27da @@ -465,7 +473,7 @@ int ocl_brute_lfcs(cl_uint lfcs_template, cl_ushort newflag, const cl_uint *ver, size_t local; OCL_ASSERT(clGetKernelWorkGroupInfo(kernel, device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(local), &local, NULL)); - if (seedminer_mode != 1 || rws_mode != 1) { + if (seedminer_mode != 1 || reduced_work_size_mode != 1) { printf("local work size: %u\n", (unsigned)local); } @@ -475,6 +483,10 @@ int ocl_brute_lfcs(cl_uint lfcs_template, cl_ushort newflag, const cl_uint *ver, OCL_ASSERT(clEnqueueWriteBuffer(command_queue, mem_out, CL_TRUE, 0, sizeof(cl_uint), &out, 0, NULL, NULL)); unsigned brute_bits = 32; + unsigned group_bits = 28; + if (reduced_work_size_mode == 1) { + group_bits = 20; + } unsigned loop_bits = brute_bits - group_bits; unsigned loops = 1ull << loop_bits; size_t num_items = 1ull << group_bits; @@ -507,7 +519,7 @@ int ocl_brute_lfcs(cl_uint lfcs_template, cl_ushort newflag, const cl_uint *ver, if((int)lfcs_block + fan < lower_bound) continue;//check to see if bf exhausted in - direction, skip iteration if so } - printf("%d \r", fan); + printf("offset: %d \r", fan); fflush(stdout); for (i = 0; i < loops; ++i) { cl_uint lfcs = lfcs_template + fan * 0x10000 + (i << (group_bits - 16)); diff --git a/ocl_brute.h b/ocl_brute.h index a583993..ea435cf 100644 --- a/ocl_brute.h +++ b/ocl_brute.h @@ -14,8 +14,6 @@ int ocl_brute_console_id(const cl_uchar *console_id, const cl_uchar *emmc_cid, int ocl_brute_emmc_cid(const cl_uchar *console_id, cl_uchar *emmc_cid, cl_uint offset, const cl_uchar *src, const cl_uchar *ver); -int ocl_brute_msky(const cl_uint *msky, const cl_uint *ver, cl_uint msky_offset); +int ocl_brute_msky(const cl_uint *msky, const cl_uint *ver, cl_uint msky_offset, cl_uint msky_max_offset); -int ocl_brute_lfcs(cl_uint lfcs_template, cl_ushort newflag, const cl_uint *ver, cl_uint lfcs_offset); - -unsigned group_bits; \ No newline at end of file +int ocl_brute_lfcs(cl_uint lfcs_template, cl_ushort newflag, const cl_uint *ver, cl_uint lfcs_offset); \ No newline at end of file diff --git a/ocl_util.c b/ocl_util.c index b9485c9..35f4c94 100644 --- a/ocl_util.c +++ b/ocl_util.c @@ -207,7 +207,7 @@ void ocl_get_device(cl_platform_id *p_platform_id, cl_device_id *p_device_id) { } } if (maximum > 0) { - if (seedminer_mode != 1 || rws_mode != 1) { + if (seedminer_mode != 1 || reduced_work_size_mode != 1) { printf("selected device %s on platform %s\n", trim((char*)platforms[pl_idx].devices[dev_idx].name), trim((char*)platforms[pl_idx].name)); } @@ -239,7 +239,7 @@ cl_program ocl_build_from_sources( // printf("compiler options: %s\n", options); err = clBuildProgram(program, 0, NULL, options, NULL, NULL); get_hp_time(&t1); - if (seedminer_mode != 1 || rws_mode != 1) { + if (seedminer_mode != 1 || reduced_work_size_mode != 1) { printf("%.3f seconds for OpenCL compiling\n", hp_time_diff(&t0, &t1) / 1000000.0); } if (err != CL_SUCCESS) { diff --git a/utils.h b/utils.h index b579e0c..c909264 100644 --- a/utils.h +++ b/utils.h @@ -1,6 +1,7 @@ #pragma once #include <signal.h> // I sure do hope this works on MS VS; for use with signal handling. +#include <stdint.h> // a crude cross Windows/POSIX high precision timer #ifdef _WIN32 @@ -39,11 +40,11 @@ int rdrand_fill(unsigned long long *p, size_t size); char * trim(char *in); -int stop_bfcl; +uint32_t stop_bfcl; -int seedminer_mode; +uint32_t seedminer_mode; -int rws_mode; +uint32_t reduced_work_size_mode; void real_sleep(int sleep_sec);