mirror of
https://github.com/naehrwert/scetool.git
synced 2025-04-23 05:07:47 +00:00
Merge 2350b05701
into d78d8986c9
This commit is contained in:
commit
df23d634eb
3 changed files with 33 additions and 7 deletions
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
CC=gcc
|
CC=g++
|
||||||
CFLAGS=-g -O0 -Wall
|
CFLAGS=-g -O0 -Wall
|
||||||
OS_TARGET=scetool
|
OS_TARGET=scetool
|
||||||
LDFLAGS=-lz
|
LDFLAGS=-lz
|
||||||
|
|
15
frontend.cpp
15
frontend.cpp
|
@ -327,13 +327,19 @@ void frontend_print_infos(s8 *file)
|
||||||
if(sce_decrypt_header(ctxt, meta_info, keyset))
|
if(sce_decrypt_header(ctxt, meta_info, keyset))
|
||||||
{
|
{
|
||||||
_LOG_VERBOSE("Header decrypted.\n");
|
_LOG_VERBOSE("Header decrypted.\n");
|
||||||
if(sce_decrypt_data(ctxt))
|
|
||||||
_LOG_VERBOSE("Data decrypted.\n");
|
//Just deal with spkg_hdr.1 files now, no need to decrypt whole PKG.
|
||||||
else
|
if(ctxt->sceh->header_type != SCE_HEADER_TYPE_PKG)
|
||||||
printf("[*] Warning: Could not decrypt data.\n");
|
{
|
||||||
|
if(sce_decrypt_data(ctxt))
|
||||||
|
_LOG_VERBOSE("Data decrypted.\n");
|
||||||
|
else
|
||||||
|
printf("[*] Warning: Could not decrypt data.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf("[*] Warning: Could not decrypt header.\n");
|
printf("[*] Warning: Could not decrypt header.\n");
|
||||||
|
|
||||||
sce_print_info(stdout, ctxt);
|
sce_print_info(stdout, ctxt);
|
||||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF)
|
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF)
|
||||||
self_print_info(stdout, ctxt);
|
self_print_info(stdout, ctxt);
|
||||||
|
@ -341,6 +347,7 @@ void frontend_print_infos(s8 *file)
|
||||||
rvk_print(stdout, ctxt);
|
rvk_print(stdout, ctxt);
|
||||||
else if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SPP && ctxt->mdec == TRUE)
|
else if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SPP && ctxt->mdec == TRUE)
|
||||||
spp_print(stdout, ctxt);
|
spp_print(stdout, ctxt);
|
||||||
|
|
||||||
free(ctxt);
|
free(ctxt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
23
sce.cpp
23
sce.cpp
|
@ -26,7 +26,7 @@
|
||||||
void _print_sce_header(FILE *fp, sce_header_t *h)
|
void _print_sce_header(FILE *fp, sce_header_t *h)
|
||||||
{
|
{
|
||||||
const s8 *name;
|
const s8 *name;
|
||||||
const s8 *key_revision;
|
//const s8 *key_revision;
|
||||||
|
|
||||||
fprintf(fp, "[*] SCE Header:\n");
|
fprintf(fp, "[*] SCE Header:\n");
|
||||||
fprintf(fp, " Magic 0x%08X [%s]\n", h->magic, (h->magic == SCE_HEADER_MAGIC ? "OK" : "ERROR"));
|
fprintf(fp, " Magic 0x%08X [%s]\n", h->magic, (h->magic == SCE_HEADER_MAGIC ? "OK" : "ERROR"));
|
||||||
|
@ -320,7 +320,7 @@ void sce_compress_data(sce_buffer_ctxt_t *ctxt)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
free(buf);
|
free(buf);
|
||||||
_LOG_VERBOSE("Skipped compression of section %03d (0x%08X >= 0x%08X)\n", i, size_comp, sec->size);
|
_LOG_VERBOSE("Skipped compression of section %03d (0x%08lu >= 0x%08X)\n", i, size_comp, sec->size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -840,6 +840,9 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset)
|
||||||
aes_setkey_dec(&aes_ctxt, ks->erk, KEYBITS(ks->erklen));
|
aes_setkey_dec(&aes_ctxt, ks->erk, KEYBITS(ks->erklen));
|
||||||
memcpy(iv, ks->riv, 0x10); //!!!
|
memcpy(iv, ks->riv, 0x10); //!!!
|
||||||
aes_crypt_cbc(&aes_ctxt, AES_DECRYPT, sizeof(metadata_info_t), iv, (u8 *)ctxt->metai, (u8 *)ctxt->metai);
|
aes_crypt_cbc(&aes_ctxt, AES_DECRYPT, sizeof(metadata_info_t), iv, (u8 *)ctxt->metai, (u8 *)ctxt->metai);
|
||||||
|
|
||||||
|
//Dump to file.
|
||||||
|
_write_buffer("metai_dec.bin", (u8 *) ctxt->metai, sizeof(metadata_info_t));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -850,6 +853,10 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset)
|
||||||
if(ctxt->metai->key_pad[0] != 0x00 || ctxt->metai->iv_pad[0] != 0x00)
|
if(ctxt->metai->key_pad[0] != 0x00 || ctxt->metai->iv_pad[0] != 0x00)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
//Backup IV, next aes_crypt_ctr alters last 2 bytes
|
||||||
|
u8 biv[0x10];
|
||||||
|
memcpy(&biv, ctxt->metai->iv, 0x10);
|
||||||
|
|
||||||
//Decrypt metadata header, metadata section headers and keys.
|
//Decrypt metadata header, metadata section headers and keys.
|
||||||
nc_off = 0;
|
nc_off = 0;
|
||||||
aes_setkey_enc(&aes_ctxt, ctxt->metai->key, METADATA_INFO_KEYBITS);
|
aes_setkey_enc(&aes_ctxt, ctxt->metai->key, METADATA_INFO_KEYBITS);
|
||||||
|
@ -857,8 +864,16 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset)
|
||||||
ctxt->sceh->header_len - (sizeof(sce_header_t) + ctxt->sceh->metadata_offset + sizeof(metadata_info_t)),
|
ctxt->sceh->header_len - (sizeof(sce_header_t) + ctxt->sceh->metadata_offset + sizeof(metadata_info_t)),
|
||||||
&nc_off, ctxt->metai->iv, sblk, (u8 *)ctxt->metah, (u8 *)ctxt->metah);
|
&nc_off, ctxt->metai->iv, sblk, (u8 *)ctxt->metah, (u8 *)ctxt->metah);
|
||||||
|
|
||||||
|
//Restore IV from its backup if changed
|
||||||
|
if(memcmp(ctxt->metai->iv, biv, 0x10) != 0)
|
||||||
|
memcpy(ctxt->metai->iv, &biv, 0x10);
|
||||||
|
|
||||||
|
//Dump to file.
|
||||||
|
_write_buffer("metah_dec.bin", (u8 *) ctxt->metah, ctxt->sceh->header_len - (sizeof(sce_header_t) + ctxt->sceh->metadata_offset + sizeof(metadata_info_t)));
|
||||||
|
|
||||||
//Fixup headers.
|
//Fixup headers.
|
||||||
_es_metadata_header(ctxt->metah);
|
_es_metadata_header(ctxt->metah);
|
||||||
|
|
||||||
for(i = 0; i < ctxt->metah->section_count; i++)
|
for(i = 0; i < ctxt->metah->section_count; i++)
|
||||||
_es_metadata_section_header(&ctxt->metash[i]);
|
_es_metadata_section_header(&ctxt->metash[i]);
|
||||||
|
|
||||||
|
@ -869,6 +884,10 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset)
|
||||||
ctxt->keys = (u8 *)ctxt->metash + sizeof(metadata_section_header_t) * ctxt->metah->section_count;
|
ctxt->keys = (u8 *)ctxt->metash + sizeof(metadata_section_header_t) * ctxt->metah->section_count;
|
||||||
ctxt->keys_len = ctxt->metah->key_count * 0x10;
|
ctxt->keys_len = ctxt->metah->key_count * 0x10;
|
||||||
|
|
||||||
|
//Dump to file.
|
||||||
|
_write_buffer("keys_file.bin", (u8 *) ctxt->metash + sizeof(metadata_section_header_t) * ctxt->metah->section_count, ctxt->metah->key_count * 0x10);
|
||||||
|
_write_buffer("signature.bin", (u8 *) ctxt->keys + ctxt->metah->key_count * 0x10, 0x30);
|
||||||
|
|
||||||
//Set SELF only headers.
|
//Set SELF only headers.
|
||||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF)
|
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue