mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-03 08:39:04 +00:00
core: Makes it possible to skip decryption part in QuickDecryptor
Bad name, huh?
This commit is contained in:
@@ -65,8 +65,8 @@ bool SDMCDecryptor::DecryptAndWriteFile(const std::string& source, const std::st
|
||||
auto key = Key::GetNormalKey(Key::SDKey);
|
||||
auto ctr = GetFileCTR(source);
|
||||
return quick_decryptor.DecryptAndWriteFile(std::move(source_file), size,
|
||||
std::move(destination_file), std::move(key),
|
||||
std::move(ctr), callback);
|
||||
std::move(destination_file), callback, true,
|
||||
std::move(key), std::move(ctr));
|
||||
}
|
||||
|
||||
void SDMCDecryptor::Abort() {
|
||||
|
||||
@@ -25,8 +25,8 @@ QuickDecryptor<In, Out>::~QuickDecryptor() = default;
|
||||
template <typename In, typename Out>
|
||||
bool QuickDecryptor<In, Out>::DecryptAndWriteFile(std::unique_ptr<In> source_, std::size_t size,
|
||||
std::unique_ptr<Out> destination_,
|
||||
Core::Key::AESKey key_, Core::Key::AESKey ctr_,
|
||||
const ProgressCallback& callback_) {
|
||||
const ProgressCallback& callback_, bool decrypt_,
|
||||
Core::Key::AESKey key_, Core::Key::AESKey ctr_) {
|
||||
if (is_running) {
|
||||
LOG_ERROR(Core, "Decryptor is running");
|
||||
return false;
|
||||
@@ -45,6 +45,7 @@ bool QuickDecryptor<In, Out>::DecryptAndWriteFile(std::unique_ptr<In> source_, s
|
||||
|
||||
source = std::move(source_);
|
||||
destination = std::move(destination_);
|
||||
decrypt = decrypt_;
|
||||
key = std::move(key_);
|
||||
ctr = std::move(ctr_);
|
||||
callback = callback_;
|
||||
@@ -54,15 +55,19 @@ bool QuickDecryptor<In, Out>::DecryptAndWriteFile(std::unique_ptr<In> source_, s
|
||||
is_good = is_running = true;
|
||||
|
||||
read_thread = std::make_unique<std::thread>(&QuickDecryptor::DataReadLoop, this);
|
||||
decrypt_thread = std::make_unique<std::thread>(&QuickDecryptor::DataDecryptLoop, this);
|
||||
write_thread = std::make_unique<std::thread>(&QuickDecryptor::DataWriteLoop, this);
|
||||
if (decrypt) {
|
||||
decrypt_thread = std::make_unique<std::thread>(&QuickDecryptor::DataDecryptLoop, this);
|
||||
}
|
||||
|
||||
completion_event.Wait();
|
||||
is_running = false;
|
||||
|
||||
read_thread->join();
|
||||
decrypt_thread->join();
|
||||
write_thread->join();
|
||||
if (decrypt) {
|
||||
decrypt_thread->join();
|
||||
}
|
||||
|
||||
// Release the files
|
||||
source.reset();
|
||||
@@ -152,7 +157,11 @@ void QuickDecryptor<In, Out>::DataWriteLoop() {
|
||||
|
||||
iteration++;
|
||||
|
||||
data_decrypted_event[current_buffer].Wait();
|
||||
if (decrypt) {
|
||||
data_decrypted_event[current_buffer].Wait();
|
||||
} else {
|
||||
data_read_event[current_buffer].Wait();
|
||||
}
|
||||
|
||||
const auto bytes_to_write = std::min(BufferSize, file_size);
|
||||
if (destination->WriteBytes(buffers[current_buffer].data(), bytes_to_write) !=
|
||||
|
||||
@@ -34,9 +34,10 @@ public:
|
||||
~QuickDecryptor();
|
||||
|
||||
bool DecryptAndWriteFile(std::unique_ptr<In> source, std::size_t size,
|
||||
std::unique_ptr<Out> destination, Core::Key::AESKey key,
|
||||
Core::Key::AESKey ctr,
|
||||
const ProgressCallback& callback = [](std::size_t, std::size_t) {});
|
||||
std::unique_ptr<Out> destination,
|
||||
const ProgressCallback& callback = [](std::size_t, std::size_t) {},
|
||||
bool decrypt = false, Core::Key::AESKey key = {},
|
||||
Core::Key::AESKey ctr = {});
|
||||
|
||||
void DataReadLoop();
|
||||
void DataDecryptLoop();
|
||||
@@ -52,6 +53,7 @@ private:
|
||||
|
||||
std::unique_ptr<In> source;
|
||||
std::unique_ptr<Out> destination;
|
||||
bool decrypt{};
|
||||
Core::Key::AESKey key;
|
||||
Core::Key::AESKey ctr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user