build matches file at end of execution
This commit is contained in:
parent
55937b0bba
commit
9d02d7280e
|
@ -1,13 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <iterator>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <format>
|
||||
#include <iterator>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#define _WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace swbf {
|
||||
|
@ -32,8 +32,35 @@ namespace swbf {
|
|||
std::FILE* file;
|
||||
};
|
||||
|
||||
template <class Os>
|
||||
struct OsIterator {
|
||||
using iterator_category = std::output_iterator_tag;
|
||||
using value_type = void;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = void;
|
||||
using reference = void;
|
||||
|
||||
OsIterator(Os& file) : os(&file) {}
|
||||
OsIterator& operator*() { return *this; }
|
||||
OsIterator& operator++() { return *this; }
|
||||
OsIterator& operator++(int) { return *this; }
|
||||
|
||||
OsIterator& operator=(const char& val) {
|
||||
os->put(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
Os* os;
|
||||
};
|
||||
|
||||
template <class Stream, class... Args>
|
||||
inline void fprint(Stream& file, std::string_view format, Args&&... args) {
|
||||
std::vformat_to(OsIterator<Stream>(file), format, std::make_format_args(args...));
|
||||
}
|
||||
|
||||
/// Poor Man's C++23
|
||||
template<class ...Args>
|
||||
template <class... Args>
|
||||
inline void fprint(std::FILE* file, std::string_view format, Args&&... args) {
|
||||
#ifdef _WIN32
|
||||
// windows vt handling is DOG slow. don't know why lmao
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "ansi.hpp"
|
||||
#include "fprint.hpp"
|
||||
#include "scramble.hpp"
|
||||
|
@ -23,6 +25,8 @@ namespace swbf {
|
|||
std::uint32_t codeHash;
|
||||
bool done = false;
|
||||
|
||||
std::vector<std::string> matches;
|
||||
|
||||
void DisplayProgress() {
|
||||
if(!done)
|
||||
swbf::fprint(stdout, "{}Thread {:2}: Trying code {}{} {}({:08x}){}", swbf::ansi::Line(threadIndex), threadIndex,
|
||||
|
@ -94,7 +98,8 @@ namespace swbf {
|
|||
|
||||
// There was a match!
|
||||
if(hash == options.targetHash)
|
||||
swbf::fprint(stderr, "match: {} ({:08x})\n", test_buffer, hash);
|
||||
DisplayData().matches.push_back(test_buffer);
|
||||
//swbf::fprint(stderr, "match: {} ({:08x})\n", test_buffer, hash);
|
||||
|
||||
CopyDisplayData();
|
||||
|
||||
|
@ -132,6 +137,23 @@ namespace swbf {
|
|||
}
|
||||
|
||||
pool.join(); // just in case!
|
||||
|
||||
// build the matches file
|
||||
fprint(stdout, "Writing matches file...");
|
||||
std::ofstream ofs("matches.txt");
|
||||
|
||||
if(options.exact)
|
||||
fprint(ofs, "Matches for hash {:8x} for length {}:\n", options.targetHash, options.startLength, options.endLength);
|
||||
else
|
||||
fprint(ofs, "Matches for hash {:8x} for lengths {}..{}:\n", options.targetHash, options.startLength, options.endLength);
|
||||
|
||||
for(auto& td : infoData) {
|
||||
for(auto& match : td.matches) {
|
||||
fprint(ofs, "{}\n", match);
|
||||
}
|
||||
|
||||
td.matches.clear();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace swbf
|
||||
|
|
Loading…
Reference in New Issue