|
|
|
@ -94,7 +94,7 @@ typedef struct seven_zip_hook_salt
|
|
|
|
|
|
|
|
|
|
static const char *SIGNATURE_SEVEN_ZIP = "$7z$";
|
|
|
|
|
|
|
|
|
|
void module_hook23 (hc_device_param_t *device_param, const void *hook_salts_buf, const u32 salt_pos, const u64 pws_cnt)
|
|
|
|
|
void module_hook23 (hc_device_param_t *device_param, const void *hook_salts_buf, const u32 salt_pos, const u64 pw_pos)
|
|
|
|
|
{
|
|
|
|
|
seven_zip_hook_t *hook_items = (seven_zip_hook_t *) device_param->hooks_buf;
|
|
|
|
|
|
|
|
|
@ -105,67 +105,40 @@ void module_hook23 (hc_device_param_t *device_param, const void *hook_salts_buf,
|
|
|
|
|
u32 *data_buf = seven_zip->data_buf;
|
|
|
|
|
u32 unpack_size = seven_zip->unpack_size;
|
|
|
|
|
|
|
|
|
|
for (u64 pw_pos = 0; pw_pos < pws_cnt; pw_pos++)
|
|
|
|
|
{
|
|
|
|
|
// this hook data needs to be updated (the "hook_success" variable):
|
|
|
|
|
|
|
|
|
|
seven_zip_hook_t *hook_item = &hook_items[pw_pos];
|
|
|
|
|
|
|
|
|
|
const u32 *ukey = (const u32 *) hook_item->ukey;
|
|
|
|
|
// this hook data needs to be updated (the "hook_success" variable):
|
|
|
|
|
|
|
|
|
|
// init AES
|
|
|
|
|
seven_zip_hook_t *hook_item = &hook_items[pw_pos];
|
|
|
|
|
|
|
|
|
|
AES_KEY aes_key;
|
|
|
|
|
const u32 *ukey = (const u32 *) hook_item->ukey;
|
|
|
|
|
|
|
|
|
|
memset (&aes_key, 0, sizeof (aes_key));
|
|
|
|
|
// init AES
|
|
|
|
|
|
|
|
|
|
aes256_set_decrypt_key (aes_key.rdk, ukey, (u32 *) te0, (u32 *) te1, (u32 *) te2, (u32 *) te3, (u32 *) td0, (u32 *) td1, (u32 *) td2, (u32 *) td3);
|
|
|
|
|
AES_KEY aes_key;
|
|
|
|
|
|
|
|
|
|
int aes_len = seven_zip->aes_len;
|
|
|
|
|
memset (&aes_key, 0, sizeof (aes_key));
|
|
|
|
|
|
|
|
|
|
u32 data[4];
|
|
|
|
|
u32 out[4];
|
|
|
|
|
u32 iv[4];
|
|
|
|
|
aes256_set_decrypt_key (aes_key.rdk, ukey, (u32 *) te0, (u32 *) te1, (u32 *) te2, (u32 *) te3, (u32 *) td0, (u32 *) td1, (u32 *) td2, (u32 *) td3);
|
|
|
|
|
|
|
|
|
|
iv[0] = seven_zip->iv_buf[0];
|
|
|
|
|
iv[1] = seven_zip->iv_buf[1];
|
|
|
|
|
iv[2] = seven_zip->iv_buf[2];
|
|
|
|
|
iv[3] = seven_zip->iv_buf[3];
|
|
|
|
|
int aes_len = seven_zip->aes_len;
|
|
|
|
|
|
|
|
|
|
u32 out_full[81882];
|
|
|
|
|
u32 data[4];
|
|
|
|
|
u32 out[4];
|
|
|
|
|
u32 iv[4];
|
|
|
|
|
|
|
|
|
|
// if aes_len > 16 we need to loop
|
|
|
|
|
iv[0] = seven_zip->iv_buf[0];
|
|
|
|
|
iv[1] = seven_zip->iv_buf[1];
|
|
|
|
|
iv[2] = seven_zip->iv_buf[2];
|
|
|
|
|
iv[3] = seven_zip->iv_buf[3];
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
int j = 0;
|
|
|
|
|
u32 out_full[81882];
|
|
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < aes_len - 16; i += 16, j += 4)
|
|
|
|
|
{
|
|
|
|
|
data[0] = data_buf[j + 0];
|
|
|
|
|
data[1] = data_buf[j + 1];
|
|
|
|
|
data[2] = data_buf[j + 2];
|
|
|
|
|
data[3] = data_buf[j + 3];
|
|
|
|
|
|
|
|
|
|
aes256_decrypt (aes_key.rdk, data, out, (u32 *) td0, (u32 *) td1, (u32 *) td2, (u32 *) td3, (u32 *) td4);
|
|
|
|
|
|
|
|
|
|
out[0] ^= iv[0];
|
|
|
|
|
out[1] ^= iv[1];
|
|
|
|
|
out[2] ^= iv[2];
|
|
|
|
|
out[3] ^= iv[3];
|
|
|
|
|
|
|
|
|
|
iv[0] = data[0];
|
|
|
|
|
iv[1] = data[1];
|
|
|
|
|
iv[2] = data[2];
|
|
|
|
|
iv[3] = data[3];
|
|
|
|
|
|
|
|
|
|
out_full[j + 0] = out[0];
|
|
|
|
|
out_full[j + 1] = out[1];
|
|
|
|
|
out_full[j + 2] = out[2];
|
|
|
|
|
out_full[j + 3] = out[3];
|
|
|
|
|
}
|
|
|
|
|
// if aes_len > 16 we need to loop
|
|
|
|
|
|
|
|
|
|
// we need to run it at least once:
|
|
|
|
|
int i = 0;
|
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < aes_len - 16; i += 16, j += 4)
|
|
|
|
|
{
|
|
|
|
|
data[0] = data_buf[j + 0];
|
|
|
|
|
data[1] = data_buf[j + 1];
|
|
|
|
|
data[2] = data_buf[j + 2];
|
|
|
|
@ -178,105 +151,129 @@ void module_hook23 (hc_device_param_t *device_param, const void *hook_salts_buf,
|
|
|
|
|
out[2] ^= iv[2];
|
|
|
|
|
out[3] ^= iv[3];
|
|
|
|
|
|
|
|
|
|
iv[0] = data[0];
|
|
|
|
|
iv[1] = data[1];
|
|
|
|
|
iv[2] = data[2];
|
|
|
|
|
iv[3] = data[3];
|
|
|
|
|
|
|
|
|
|
out_full[j + 0] = out[0];
|
|
|
|
|
out_full[j + 1] = out[1];
|
|
|
|
|
out_full[j + 2] = out[2];
|
|
|
|
|
out_full[j + 3] = out[3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* check the CRC32 "hash"
|
|
|
|
|
*/
|
|
|
|
|
// we need to run it at least once:
|
|
|
|
|
|
|
|
|
|
u32 seven_zip_crc = seven_zip->crc;
|
|
|
|
|
data[0] = data_buf[j + 0];
|
|
|
|
|
data[1] = data_buf[j + 1];
|
|
|
|
|
data[2] = data_buf[j + 2];
|
|
|
|
|
data[3] = data_buf[j + 3];
|
|
|
|
|
|
|
|
|
|
u32 crc;
|
|
|
|
|
aes256_decrypt (aes_key.rdk, data, out, (u32 *) td0, (u32 *) td1, (u32 *) td2, (u32 *) td3, (u32 *) td4);
|
|
|
|
|
|
|
|
|
|
if (data_type == 0) // uncompressed
|
|
|
|
|
{
|
|
|
|
|
crc = cpu_crc32_buffer ((u8 *) out_full, unpack_size);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
u32 crc_len = seven_zip->crc_len;
|
|
|
|
|
out[0] ^= iv[0];
|
|
|
|
|
out[1] ^= iv[1];
|
|
|
|
|
out[2] ^= iv[2];
|
|
|
|
|
out[3] ^= iv[3];
|
|
|
|
|
|
|
|
|
|
char *coder_attributes = seven_zip->coder_attributes;
|
|
|
|
|
out_full[j + 0] = out[0];
|
|
|
|
|
out_full[j + 1] = out[1];
|
|
|
|
|
out_full[j + 2] = out[2];
|
|
|
|
|
out_full[j + 3] = out[3];
|
|
|
|
|
|
|
|
|
|
// input buffers and length
|
|
|
|
|
/*
|
|
|
|
|
* check the CRC32 "hash"
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
u8 *compressed_data = (u8 *) out_full;
|
|
|
|
|
u32 seven_zip_crc = seven_zip->crc;
|
|
|
|
|
|
|
|
|
|
SizeT compressed_data_len = aes_len;
|
|
|
|
|
u32 crc;
|
|
|
|
|
|
|
|
|
|
// output buffers and length
|
|
|
|
|
if (data_type == 0) // uncompressed
|
|
|
|
|
{
|
|
|
|
|
crc = cpu_crc32_buffer ((u8 *) out_full, unpack_size);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
u32 crc_len = seven_zip->crc_len;
|
|
|
|
|
|
|
|
|
|
unsigned char *decompressed_data;
|
|
|
|
|
char *coder_attributes = seven_zip->coder_attributes;
|
|
|
|
|
|
|
|
|
|
decompressed_data = (unsigned char *) hcmalloc (crc_len);
|
|
|
|
|
// input buffers and length
|
|
|
|
|
|
|
|
|
|
SizeT decompressed_data_len = crc_len;
|
|
|
|
|
u8 *compressed_data = (u8 *) out_full;
|
|
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
SizeT compressed_data_len = aes_len;
|
|
|
|
|
|
|
|
|
|
if (data_type == 1) // LZMA1
|
|
|
|
|
{
|
|
|
|
|
ret = hc_lzma1_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes);
|
|
|
|
|
}
|
|
|
|
|
else if (data_type == 7) // inflate using zlib (DEFLATE compression)
|
|
|
|
|
{
|
|
|
|
|
ret = SZ_ERROR_DATA;
|
|
|
|
|
// output buffers and length
|
|
|
|
|
|
|
|
|
|
z_stream inf;
|
|
|
|
|
unsigned char *decompressed_data;
|
|
|
|
|
|
|
|
|
|
inf.zalloc = Z_NULL;
|
|
|
|
|
inf.zfree = Z_NULL;
|
|
|
|
|
inf.opaque = Z_NULL;
|
|
|
|
|
decompressed_data = (unsigned char *) hcmalloc (crc_len);
|
|
|
|
|
|
|
|
|
|
inf.avail_in = compressed_data_len;
|
|
|
|
|
inf.next_in = compressed_data;
|
|
|
|
|
SizeT decompressed_data_len = crc_len;
|
|
|
|
|
|
|
|
|
|
inf.avail_out = decompressed_data_len;
|
|
|
|
|
inf.next_out = decompressed_data;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
// inflate:
|
|
|
|
|
if (data_type == 1) // LZMA1
|
|
|
|
|
{
|
|
|
|
|
ret = hc_lzma1_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes);
|
|
|
|
|
}
|
|
|
|
|
else if (data_type == 7) // inflate using zlib (DEFLATE compression)
|
|
|
|
|
{
|
|
|
|
|
ret = SZ_ERROR_DATA;
|
|
|
|
|
|
|
|
|
|
inflateInit2 (&inf, -MAX_WBITS);
|
|
|
|
|
z_stream inf;
|
|
|
|
|
|
|
|
|
|
int zlib_ret = inflate (&inf, Z_NO_FLUSH);
|
|
|
|
|
inf.zalloc = Z_NULL;
|
|
|
|
|
inf.zfree = Z_NULL;
|
|
|
|
|
inf.opaque = Z_NULL;
|
|
|
|
|
|
|
|
|
|
inflateEnd (&inf);
|
|
|
|
|
inf.avail_in = compressed_data_len;
|
|
|
|
|
inf.next_in = compressed_data;
|
|
|
|
|
|
|
|
|
|
if ((zlib_ret == Z_OK) || (zlib_ret == Z_STREAM_END))
|
|
|
|
|
{
|
|
|
|
|
ret = SZ_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // we only support LZMA2 in addition to LZMA1
|
|
|
|
|
{
|
|
|
|
|
ret = hc_lzma2_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes);
|
|
|
|
|
}
|
|
|
|
|
inf.avail_out = decompressed_data_len;
|
|
|
|
|
inf.next_out = decompressed_data;
|
|
|
|
|
|
|
|
|
|
if (ret != SZ_OK)
|
|
|
|
|
{
|
|
|
|
|
hook_item->hook_success = 0;
|
|
|
|
|
// inflate:
|
|
|
|
|
|
|
|
|
|
hcfree (decompressed_data);
|
|
|
|
|
inflateInit2 (&inf, -MAX_WBITS);
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
int zlib_ret = inflate (&inf, Z_NO_FLUSH);
|
|
|
|
|
|
|
|
|
|
crc = cpu_crc32_buffer (decompressed_data, crc_len);
|
|
|
|
|
inflateEnd (&inf);
|
|
|
|
|
|
|
|
|
|
hcfree (decompressed_data);
|
|
|
|
|
if ((zlib_ret == Z_OK) || (zlib_ret == Z_STREAM_END))
|
|
|
|
|
{
|
|
|
|
|
ret = SZ_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (crc == seven_zip_crc)
|
|
|
|
|
else // we only support LZMA2 in addition to LZMA1
|
|
|
|
|
{
|
|
|
|
|
hook_item->hook_success = 1;
|
|
|
|
|
ret = hc_lzma2_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
if (ret != SZ_OK)
|
|
|
|
|
{
|
|
|
|
|
hook_item->hook_success = 0;
|
|
|
|
|
|
|
|
|
|
hcfree (decompressed_data);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
crc = cpu_crc32_buffer (decompressed_data, crc_len);
|
|
|
|
|
|
|
|
|
|
hcfree (decompressed_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (crc == seven_zip_crc)
|
|
|
|
|
{
|
|
|
|
|
hook_item->hook_success = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
hook_item->hook_success = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|