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