mirror of
https://github.com/korenkonder/ReDIVA.git
synced 2026-10-13 09:38:14 +03:00
Temp commit. Sound
This commit is contained in:
+31
-22
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "divafile.hpp"
|
||||
#include "io/file_stream.hpp"
|
||||
#include "aes.hpp"
|
||||
#include "str_utils.hpp"
|
||||
|
||||
@@ -16,14 +17,14 @@ namespace divafile {
|
||||
void decrypt(const char* path) {
|
||||
wchar_t* file_buf = utf8_to_utf16(path);
|
||||
decrypt(file_buf);
|
||||
free(file_buf);
|
||||
free_def(file_buf);
|
||||
}
|
||||
|
||||
void decrypt(const wchar_t* path) {
|
||||
wchar_t* file_temp = str_utils_add(path, L"_dec");
|
||||
stream s_enc;
|
||||
file_stream s_enc;
|
||||
s_enc.open(path, L"rb");
|
||||
if (s_enc.io.stream) {
|
||||
if (s_enc.check_not_null()) {
|
||||
uint64_t signature = s_enc.read_uint64_t();
|
||||
if (signature == 0x454C494641564944) {
|
||||
uint32_t stream_length = s_enc.read_uint32_t();
|
||||
@@ -35,13 +36,13 @@ namespace divafile {
|
||||
aes128_init_ctx(&ctx, key);
|
||||
aes128_ecb_decrypt_buffer(&ctx, (uint8_t*)data, stream_length);
|
||||
|
||||
stream s_dec;
|
||||
file_stream s_dec;
|
||||
s_dec.open(file_temp, L"wb");
|
||||
s_dec.write(data, min(file_length, stream_length));
|
||||
free(data);
|
||||
s_dec.write(data, min_def(file_length, stream_length));
|
||||
free_def(data);
|
||||
}
|
||||
}
|
||||
free(file_temp);
|
||||
free_def(file_temp);
|
||||
}
|
||||
|
||||
void decrypt(void* enc_data, void** dec_data, size_t* dec_size) {
|
||||
@@ -70,38 +71,46 @@ namespace divafile {
|
||||
*dec_size = file_length;
|
||||
}
|
||||
|
||||
void decrypt(stream& s) {
|
||||
size_t pos = s.get_position();
|
||||
uint64_t signature = s.read_uint64_t();
|
||||
void decrypt(stream& enc, memory_stream& dec) {
|
||||
size_t pos = enc.get_position();
|
||||
uint64_t signature = enc.read_uint64_t();
|
||||
if (signature != 0x454C494641564944) {
|
||||
s.set_position(pos, SEEK_SET);
|
||||
std::vector<uint8_t> data;
|
||||
enc.set_position(0, SEEK_SET);
|
||||
int64_t length = enc.get_length();
|
||||
data.resize(length);
|
||||
enc.read(data.data(), length);
|
||||
enc.set_position(pos, SEEK_SET);
|
||||
dec.open(data);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t stream_length = s.read_uint32_t();
|
||||
uint32_t file_length = s.read_uint32_t();
|
||||
uint32_t stream_length = enc.read_uint32_t();
|
||||
uint32_t file_length = enc.read_uint32_t();
|
||||
void* data = force_malloc(stream_length);
|
||||
s.read(data, stream_length);
|
||||
enc.read(data, stream_length);
|
||||
|
||||
aes128_ctx ctx;
|
||||
aes128_init_ctx(&ctx, key);
|
||||
aes128_ecb_decrypt_buffer(&ctx, (uint8_t*)data, stream_length);
|
||||
|
||||
s.open(data, file_length);
|
||||
free(data);
|
||||
dec.open(data, file_length);
|
||||
free_def(data);
|
||||
}
|
||||
void decrypt(memory_stream& s) {
|
||||
}
|
||||
|
||||
void encrypt(const char* path) {
|
||||
wchar_t* file_buf = utf8_to_utf16(path);
|
||||
encrypt(file_buf);
|
||||
free(file_buf);
|
||||
free_def(file_buf);
|
||||
}
|
||||
|
||||
void encrypt(const wchar_t* path) {
|
||||
wchar_t* file_temp = str_utils_add(path, L"_enc");
|
||||
stream s_dec;
|
||||
file_stream s_dec;
|
||||
s_dec.open(path, L"rb");
|
||||
if (s_dec.io.stream) {
|
||||
if (s_dec.check_not_null()) {
|
||||
size_t len = s_dec.length;
|
||||
size_t len_align = align_val(len, 0x10);
|
||||
|
||||
@@ -112,15 +121,15 @@ namespace divafile {
|
||||
aes128_init_ctx(&ctx, key);
|
||||
aes128_ecb_encrypt_buffer(&ctx, (uint8_t*)data, len_align);
|
||||
|
||||
stream s_enc;
|
||||
file_stream s_enc;
|
||||
s_enc.open(file_temp, L"wb");
|
||||
s_enc.write_uint64_t(0x454C494641564944);
|
||||
s_enc.write_uint32_t((uint32_t)len_align);
|
||||
s_enc.write_uint32_t((uint32_t)len);
|
||||
s_enc.write(data, len_align);
|
||||
free(data);
|
||||
free_def(data);
|
||||
}
|
||||
free(file_temp);
|
||||
free_def(file_temp);
|
||||
}
|
||||
|
||||
void encrypt(void* dec_data, size_t dec_size, void** enc_data, size_t* enc_size) {
|
||||
|
||||
Reference in New Issue
Block a user