ctrtool: updated ncch/exheader code

updated ncch/exheader specs to latest format.
This commit is contained in:
3DSGuy
2014-04-14 11:57:35 +08:00
parent 5db59391ea
commit 7dbb107a81
9 changed files with 561 additions and 22 deletions
+159
View File
@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{96F5CA15-30DA-4DF5-9DFF-523D58D38001}</ProjectGuid>
<RootNamespace>ctrtooltje</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>windows;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DisableSpecificWarnings>4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<UseFullPaths>false</UseFullPaths>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>windows;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>c:\dev\tools\bin\ctrtool.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="cia.c" />
<ClCompile Include="ctr.c" />
<ClCompile Include="cwav.c" />
<ClCompile Include="exefs.c" />
<ClCompile Include="exheader.c" />
<ClCompile Include="filepath.c" />
<ClCompile Include="firm.c" />
<ClCompile Include="windows\getopt.c" />
<ClCompile Include="windows\getopt1.c" />
<ClCompile Include="ivfc.c" />
<ClCompile Include="keyset.cpp" />
<ClCompile Include="lzss.c" />
<ClCompile Include="main.c" />
<ClCompile Include="ncch.c" />
<ClCompile Include="ncsd.c" />
<ClCompile Include="romfs.c" />
<ClCompile Include="settings.c" />
<ClCompile Include="stream.c" />
<ClCompile Include="tik.c" />
<ClCompile Include="tmd.c" />
<ClCompile Include="utils.c" />
<ClCompile Include="polarssl\aes.c" />
<ClCompile Include="polarssl\bignum.c" />
<ClCompile Include="polarssl\rsa.c" />
<ClCompile Include="polarssl\sha2.c" />
<ClCompile Include="tinyxml\tinystr.cpp" />
<ClCompile Include="tinyxml\tinyxml.cpp" />
<ClCompile Include="tinyxml\tinyxmlerror.cpp" />
<ClCompile Include="tinyxml\tinyxmlparser.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="cia.h" />
<ClInclude Include="ctr.h" />
<ClInclude Include="cwav.h" />
<ClInclude Include="exefs.h" />
<ClInclude Include="exheader.h" />
<ClInclude Include="filepath.h" />
<ClInclude Include="firm.h" />
<ClInclude Include="windows\getopt.h" />
<ClInclude Include="info.h" />
<ClInclude Include="ivfc.h" />
<ClInclude Include="keyset.h" />
<ClInclude Include="lzss.h" />
<ClInclude Include="ncch.h" />
<ClInclude Include="ncsd.h" />
<ClInclude Include="romfs.h" />
<ClInclude Include="settings.h" />
<ClInclude Include="stream.h" />
<ClInclude Include="tik.h" />
<ClInclude Include="tmd.h" />
<ClInclude Include="types.h" />
<ClInclude Include="utils.h" />
<ClInclude Include="polarssl\aes.h" />
<ClInclude Include="polarssl\bignum.h" />
<ClInclude Include="polarssl\bn_mul.h" />
<ClInclude Include="polarssl\config.h" />
<ClInclude Include="polarssl\rsa.h" />
<ClInclude Include="polarssl\sha2.h" />
<ClInclude Include="tinyxml\tinystr.h" />
<ClInclude Include="tinyxml\tinyxml.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+207
View File
@@ -0,0 +1,207 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Source Files\polarssl">
<UniqueIdentifier>{dfec7c2d-ac92-481f-a1eb-732b0669b7d1}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\tinyxml">
<UniqueIdentifier>{dd509a5e-b804-4879-b0b7-876718c9621a}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Header Files\polarssl">
<UniqueIdentifier>{d16b9918-7159-4a81-a0b7-521c2b2f8a30}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\tinyxml">
<UniqueIdentifier>{492dc50f-e790-426b-b991-86306ad69fd4}</UniqueIdentifier>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="cia.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ctr.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cwav.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="exefs.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="exheader.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="filepath.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="firm.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="windows\getopt.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="windows\getopt1.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ivfc.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="keyset.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="lzss.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ncch.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ncsd.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="romfs.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="settings.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stream.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="tik.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="tmd.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utils.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="polarssl\aes.c">
<Filter>Source Files\polarssl</Filter>
</ClCompile>
<ClCompile Include="polarssl\bignum.c">
<Filter>Source Files\polarssl</Filter>
</ClCompile>
<ClCompile Include="polarssl\rsa.c">
<Filter>Source Files\polarssl</Filter>
</ClCompile>
<ClCompile Include="polarssl\sha2.c">
<Filter>Source Files\polarssl</Filter>
</ClCompile>
<ClCompile Include="tinyxml\tinystr.cpp">
<Filter>Source Files\tinyxml</Filter>
</ClCompile>
<ClCompile Include="tinyxml\tinyxml.cpp">
<Filter>Source Files\tinyxml</Filter>
</ClCompile>
<ClCompile Include="tinyxml\tinyxmlerror.cpp">
<Filter>Source Files\tinyxml</Filter>
</ClCompile>
<ClCompile Include="tinyxml\tinyxmlparser.cpp">
<Filter>Source Files\tinyxml</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cia.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ctr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="cwav.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="exefs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="exheader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="filepath.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="firm.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="windows\getopt.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="info.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ivfc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="keyset.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="lzss.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ncch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ncsd.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="romfs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="settings.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="tik.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="tmd.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="polarssl\aes.h">
<Filter>Header Files\polarssl</Filter>
</ClInclude>
<ClInclude Include="polarssl\bignum.h">
<Filter>Header Files\polarssl</Filter>
</ClInclude>
<ClInclude Include="polarssl\bn_mul.h">
<Filter>Header Files\polarssl</Filter>
</ClInclude>
<ClInclude Include="polarssl\config.h">
<Filter>Header Files\polarssl</Filter>
</ClInclude>
<ClInclude Include="polarssl\rsa.h">
<Filter>Header Files\polarssl</Filter>
</ClInclude>
<ClInclude Include="polarssl\sha2.h">
<Filter>Header Files\polarssl</Filter>
</ClInclude>
<ClInclude Include="tinyxml\tinystr.h">
<Filter>Header Files\tinyxml</Filter>
</ClInclude>
<ClInclude Include="tinyxml\tinyxml.h">
<Filter>Header Files\tinyxml</Filter>
</ClInclude>
</ItemGroup>
</Project>
+112 -6
View File
@@ -299,6 +299,114 @@ void exheader_print_arm11kernelcapabilities(exheader_context* ctx)
}
}
void exheader_print_arm11accessinfo(exheader_context* ctx)
{
u32 accessinfo = getle32(ctx->header.arm11systemlocalcaps.storageinfo.accessinfo);
if((accessinfo & (1 << 0) )== (1 << 0))
fprintf(stdout, " > Category System Application\n");
if((accessinfo & (1 << 1) )== (1 << 1))
fprintf(stdout, " > Category Hardware Check\n");
if((accessinfo & (1 << 2) )== (1 << 2))
fprintf(stdout, " > Category File System Tool\n");
if((accessinfo & (1 << 3) )== (1 << 3))
fprintf(stdout, " > Debug\n");
if((accessinfo & (1 << 4) )== (1 << 4))
fprintf(stdout, " > TWL Card Backup\n");
if((accessinfo & (1 << 5) )== (1 << 5))
fprintf(stdout, " > TWL Nand Data\n");
if((accessinfo & (1 << 6) )== (1 << 6))
fprintf(stdout, " > BOSS\n");
if((accessinfo & (1 << 7) )== (1 << 7))
fprintf(stdout, " > Direct SDMC\n");
if((accessinfo & (1 << 8) )== (1 << 8))
fprintf(stdout, " > Core\n");
if((accessinfo & (1 << 9) )== (1 << 9))
fprintf(stdout, " > CTR NAND RO\n");
if((accessinfo & (1 << 10) )== (1 << 10))
fprintf(stdout, " > CTR NAND RW\n");
if((accessinfo & (1 << 11) )== (1 << 11))
fprintf(stdout, " > CTR NAND RO (Write Access)\n");
if((accessinfo & (1 << 12) )== (1 << 12))
fprintf(stdout, " > Category System Settings\n");
if((accessinfo & (1 << 13) )== (1 << 13))
fprintf(stdout, " > CARD BOARD\n");
if((accessinfo & (1 << 14) )== (1 << 14))
fprintf(stdout, " > Export Import IVS\n");
if((accessinfo & (1 << 15) )== (1 << 15))
fprintf(stdout, " > Direct SDMC (Write Only)\n");
if((accessinfo & (1 << 16) )== (1 << 16))
fprintf(stdout, " > Switch Cleanup\n");
if((accessinfo & (1 << 17) )== (1 << 17))
fprintf(stdout, " > Save Data Move\n");
if((accessinfo & (1 << 18) )== (1 << 18))
fprintf(stdout, " > Shop\n");
if((accessinfo & (1 << 19) )== (1 << 19))
fprintf(stdout, " > Shell\n");
if((accessinfo & (1 << 20) )== (1 << 20))
fprintf(stdout, " > Category HomeMenu\n");
}
void exheader_print_arm11storageinfo(exheader_context* ctx)
{
u32 i;
// Storage Info
u32 systemsaveID[2];
u64 extdataID;
u32 otherusersaveID[3];
u32 accessiblesaveID[6];
u8 otherattibutes = ctx->header.arm11systemlocalcaps.storageinfo.otherattributes;
u8 accessOtherVariationSavedata = (getle64(ctx->header.arm11systemlocalcaps.storageinfo.accessibleuniqueids) & 0x1000000000000000) == 0x1000000000000000;
systemsaveID[0] = getle32(ctx->header.arm11systemlocalcaps.storageinfo.systemsavedataid);
systemsaveID[1] = getle32(ctx->header.arm11systemlocalcaps.storageinfo.systemsavedataid+4);
extdataID = getle64(ctx->header.arm11systemlocalcaps.storageinfo.extsavedataid);
for(i = 0; i < 3; i++)
{
accessiblesaveID[i] = 0xfffff & (getle64(ctx->header.arm11systemlocalcaps.storageinfo.accessibleuniqueids) >> 20*(2-i));
otherusersaveID[i] = 0xfffff & (getle64(ctx->header.arm11systemlocalcaps.storageinfo.accessibleuniqueids) >> 20*(2-i));
}
for(i = 0; i < 3; i++)
{
accessiblesaveID[i+3] = 0xfffff & (getle64(ctx->header.arm11systemlocalcaps.storageinfo.extsavedataid) >> 20*(2-i));
}
if(otherattibutes & 2)
{
extdataID = 0;
for(i = 0; i < 3; i++)
otherusersaveID[i] = 0;
}
else
{
for(i = 0; i < 6; i++)
accessiblesaveID[i] = 0;
}
fprintf(stdout, "Ext savedata id: 0x%llX\n",extdataID);
for(i = 0; i < 2; i++)
fprintf(stdout, "System savedata id %d: 0x%08x\n",i+1,systemsaveID[i]);
for(i = 0; i < 3; i++)
fprintf(stdout, "OtherUserSaveDataId%d: 0x%05x\n",i+1,otherusersaveID[i]);
fprintf(stdout, "Accessible Savedata Ids:\n");
for(i = 0; i < 6; i++)
fprintf(stdout, " > 0x%05x\n",accessiblesaveID[i]);
fprintf(stdout, "Other Variation Saves: %s\n", accessOtherVariationSavedata ? "Accessible" : "Inaccessible");
memdump(stdout, "Access info: ", ctx->header.arm11systemlocalcaps.storageinfo.accessinfo, 7);
exheader_print_arm11accessinfo(ctx);
fprintf(stdout, "Other attributes: %02X", ctx->header.arm11systemlocalcaps.storageinfo.otherattributes);
if(otherattibutes & 1)
fprintf(stdout," [no use romfs]");
if(otherattibutes & 2)
fprintf(stdout," [use extended savedata access control]");
printf("\n");
}
int exheader_signature_verify(exheader_context* ctx, rsakey2048* key)
{
u8 hash[0x20];
@@ -368,6 +476,8 @@ void exheader_print(exheader_context* ctx)
fprintf(stdout, "Flag: %02X ", codesetinfo->flags.flag);
if (codesetinfo->flags.flag & 1)
fprintf(stdout, "[compressed]");
if (codesetinfo->flags.flag & 2)
fprintf(stdout, "[sd application]");
fprintf(stdout, "\n");
fprintf(stdout, "Remaster version: %04X\n", getle16(codesetinfo->flags.remasterversion));
@@ -389,7 +499,7 @@ void exheader_print(exheader_context* ctx)
fprintf(stdout, "Dependency: %016llX\n", getle64(ctx->header.deplist.programid[i]));
}
fprintf(stdout, "Savedata size: 0x%08X\n", getle32(ctx->header.systeminfo.savedatasize));
fprintf(stdout, "Savedata size: 0x%016X\n", getle64(ctx->header.systeminfo.savedatasize));
fprintf(stdout, "Jump id: %016llX\n", getle64(ctx->header.systeminfo.jumpid));
fprintf(stdout, "Program id: %016llX %s\n", getle64(ctx->header.arm11systemlocalcaps.programid), exheader_getvalidstring(ctx->validprogramid));
@@ -400,11 +510,7 @@ void exheader_print(exheader_context* ctx)
fprintf(stdout, "Affinity mask: %d %s\n", (ctx->header.arm11systemlocalcaps.flags[6]>>2)&0x3, exheader_getvalidstring(ctx->validaffinitymask));
fprintf(stdout, "Main thread priority: %d %s\n", ctx->header.arm11systemlocalcaps.flags[7], exheader_getvalidstring(ctx->validpriority));
// print resource limit descriptor too? currently mostly zeroes...
fprintf(stdout, "Ext savedata id: %016llX\n", getle64(ctx->header.arm11systemlocalcaps.storageinfo.extsavedataid));
fprintf(stdout, "System savedata id: %016llX\n", getle64(ctx->header.arm11systemlocalcaps.storageinfo.systemsavedataid));
memdump(stdout, "Access info: ", ctx->header.arm11systemlocalcaps.storageinfo.accessinfo, 7);
fprintf(stdout, "Other attributes: %02X\n", ctx->header.arm11systemlocalcaps.storageinfo.otherattributes);
exheader_print_arm11storageinfo(ctx);
exheader_print_arm11kernelcapabilities(ctx);
exheader_print_arm9accesscontrol(ctx);
+2 -3
View File
@@ -39,8 +39,7 @@ typedef struct
typedef struct
{
u8 savedatasize[4];
u8 reserved[4];
u8 savedatasize[8];
u8 jumpid[8];
u8 reserved2[0x30];
} exheader_systeminfo;
@@ -49,7 +48,7 @@ typedef struct
{
u8 extsavedataid[8];
u8 systemsavedataid[8];
u8 reserved[8];
u8 accessibleuniqueids[8];
u8 accessinfo[7];
u8 otherattributes;
} exheader_storageinfo;
+3 -1
View File
@@ -66,6 +66,7 @@ static void usage(const char *argv0)
" --exefsdir=dir Specify ExeFS directory path.\n"
" --romfs=file Specify RomFS file path.\n"
" --exheader=file Specify Extended Header file path.\n"
" --logo=file Specify Logo file path.\n"
"CIA options:\n"
" --certs=file Specify Certificate chain file path.\n"
" --tik=file Specify Ticket file path.\n"
@@ -140,6 +141,7 @@ int main(int argc, char* argv[])
{"romfsdir", 1, NULL, 17},
{"listromfs", 0, NULL, 18},
{"wavloops", 1, NULL, 19},
{"logo", 1, NULL, 20},
{NULL},
};
@@ -223,7 +225,7 @@ int main(int argc, char* argv[])
case 17: settings_set_romfs_dir_path(&ctx.usersettings, optarg); break;
case 18: settings_set_list_romfs_files(&ctx.usersettings, 1); break;
case 19: settings_set_cwav_loopcount(&ctx.usersettings, strtoul(optarg, 0, 0)); break;
case 20: settings_set_logo_path(&ctx.usersettings, optarg); break;
default:
usage(argv[0]);
+53 -8
View File
@@ -108,6 +108,13 @@ int ncch_extract_prepare(ncch_context* ctx, u32 type, u32 flags)
}
break;
case NCCHTYPE_LOGO:
{
offset = ncch_get_logo_offset(ctx);
size = ncch_get_logo_size(ctx);
}
break;
default:
{
fprintf(stderr, "Error invalid NCCH type\n");
@@ -128,7 +135,7 @@ clean:
return 0;
}
int ncch_extract_buffer(ncch_context* ctx, u8* buffer, u32 buffersize, u32* outsize)
int ncch_extract_buffer(ncch_context* ctx, u8* buffer, u32 buffersize, u32* outsize, u8 nocrypto)
{
u32 max = buffersize;
@@ -145,7 +152,7 @@ int ncch_extract_buffer(ncch_context* ctx, u8* buffer, u32 buffersize, u32* outs
goto clean;
}
if (ctx->encrypted)
if (ctx->encrypted && !nocrypto)
ctr_crypt_counter(&ctx->aes, buffer, buffer, max);
ctx->extractsize -= max;
@@ -172,6 +179,7 @@ void ncch_save(ncch_context* ctx, u32 type, u32 flags)
case NCCHTYPE_EXEFS: path = settings_get_exefs_path(ctx->usersettings); break;
case NCCHTYPE_ROMFS: path = settings_get_romfs_path(ctx->usersettings); break;
case NCCHTYPE_EXHEADER: path = settings_get_exheader_path(ctx->usersettings); break;
case NCCHTYPE_LOGO: path = settings_get_logo_path(ctx->usersettings); break;
}
if (path == 0 || path->valid == 0)
@@ -189,13 +197,14 @@ void ncch_save(ncch_context* ctx, u32 type, u32 flags)
case NCCHTYPE_EXEFS: fprintf(stdout, "Saving ExeFS...\n"); break;
case NCCHTYPE_ROMFS: fprintf(stdout, "Saving RomFS...\n"); break;
case NCCHTYPE_EXHEADER: fprintf(stdout, "Saving Extended Header...\n"); break;
case NCCHTYPE_LOGO: fprintf(stdout, "Saving Logo...\n"); break;
}
while(1)
{
u32 max;
if (0 == ncch_extract_buffer(ctx, buffer, sizeof(buffer), &max))
if (0 == ncch_extract_buffer(ctx, buffer, sizeof(buffer), &max, type == NCCHTYPE_LOGO))
goto clean;
if (max == 0)
@@ -219,17 +228,21 @@ void ncch_verify(ncch_context* ctx, u32 flags)
u32 exefshashregionsize = getle32(ctx->header.exefshashregionsize) * mediaunitsize;
u32 romfshashregionsize = getle32(ctx->header.romfshashregionsize) * mediaunitsize;
u32 exheaderhashregionsize = getle32(ctx->header.extendedheadersize);
u32 logohashregionsize = getle32(ctx->header.logosize) * mediaunitsize;
u8* exefshashregion = 0;
u8* romfshashregion = 0;
u8* exheaderhashregion = 0;
u8* logohashregion = 0;
u8* tmphash = 0;
rsakey2048 ncchrsakey;
if (exefshashregionsize >= SIZE_128MB || romfshashregionsize >= SIZE_128MB || exheaderhashregionsize >= SIZE_128MB)
if (exefshashregionsize >= SIZE_128MB || romfshashregionsize >= SIZE_128MB || exheaderhashregionsize >= SIZE_128MB || logohashregionsize >= SIZE_128MB)
goto clean;
exefshashregion = malloc(exefshashregionsize);
romfshashregion = malloc(romfshashregionsize);
exheaderhashregion = malloc(exheaderhashregionsize);
logohashregion = malloc(logohashregionsize);
if (ctx->usersettings)
@@ -247,7 +260,7 @@ void ncch_verify(ncch_context* ctx, u32 flags)
{
if (0 == ncch_extract_prepare(ctx, NCCHTYPE_EXEFS, flags))
goto clean;
if (0 == ncch_extract_buffer(ctx, exefshashregion, exefshashregionsize, &exefshashregionsize))
if (0 == ncch_extract_buffer(ctx, exefshashregion, exefshashregionsize, &exefshashregionsize,0))
goto clean;
ctx->exefshashcheck = ctr_sha_256_verify(exefshashregion, exefshashregionsize, ctx->header.exefssuperblockhash);
}
@@ -255,7 +268,7 @@ void ncch_verify(ncch_context* ctx, u32 flags)
{
if (0 == ncch_extract_prepare(ctx, NCCHTYPE_ROMFS, flags))
goto clean;
if (0 == ncch_extract_buffer(ctx, romfshashregion, romfshashregionsize, &romfshashregionsize))
if (0 == ncch_extract_buffer(ctx, romfshashregion, romfshashregionsize, &romfshashregionsize,0))
goto clean;
ctx->romfshashcheck = ctr_sha_256_verify(romfshashregion, romfshashregionsize, ctx->header.romfssuperblockhash);
}
@@ -263,14 +276,24 @@ void ncch_verify(ncch_context* ctx, u32 flags)
{
if (0 == ncch_extract_prepare(ctx, NCCHTYPE_EXHEADER, flags))
goto clean;
if (0 == ncch_extract_buffer(ctx, exheaderhashregion, exheaderhashregionsize, &exheaderhashregionsize))
if (0 == ncch_extract_buffer(ctx, exheaderhashregion, exheaderhashregionsize, &exheaderhashregionsize,0))
goto clean;
ctx->exheaderhashcheck = ctr_sha_256_verify(exheaderhashregion, exheaderhashregionsize, ctx->header.extendedheaderhash);
}
if (logohashregionsize)
{
if (0 == ncch_extract_prepare(ctx, NCCHTYPE_LOGO, flags))
goto clean;
if (0 == ncch_extract_buffer(ctx, logohashregion, logohashregionsize, &logohashregionsize,1))
goto clean;
ctx->logohashcheck = ctr_sha_256_verify(logohashregion, logohashregionsize, ctx->header.logohash);
}
free(exefshashregion);
free(romfshashregion);
free(exheaderhashregion);
free(logohashregion);
clean:
return;
}
@@ -331,6 +354,7 @@ void ncch_process(ncch_context* ctx, u32 actions)
ncch_save(ctx, NCCHTYPE_EXEFS, actions);
ncch_save(ctx, NCCHTYPE_ROMFS, actions);
ncch_save(ctx, NCCHTYPE_EXHEADER, actions);
ncch_save(ctx, NCCHTYPE_LOGO, actions);
}
@@ -392,6 +416,18 @@ u32 ncch_get_exheader_size(ncch_context* ctx)
return getle32(ctx->header.extendedheadersize);
}
u32 ncch_get_logo_offset(ncch_context* ctx)
{
u32 mediaunitsize = ncch_get_mediaunit_size(ctx);
return ctx->offset + getle32(ctx->header.logooffset) * mediaunitsize;
}
u32 ncch_get_logo_size(ncch_context* ctx)
{
u32 mediaunitsize = ncch_get_mediaunit_size(ctx);
return getle32(ctx->header.logosize) * mediaunitsize;
}
u32 ncch_get_mediaunit_size(ncch_context* ctx)
{
unsigned int mediaunitsize = settings_get_mediaunit_size(ctx->usersettings);
@@ -534,7 +570,12 @@ void ncch_print(ncch_context* ctx)
fprintf(stdout, "Maker code: %04x\n", getle16(header->makercode));
fprintf(stdout, "Version: %04x\n", getle16(header->version));
fprintf(stdout, "Program id: %016llx\n", getle64(header->programid));
fprintf(stdout, "Temp flag: %02x\n", header->tempflag);
if(ctx->logohashcheck == Unchecked)
memdump(stdout, "Logo hash: ", header->logohash, 0x20);
else if(ctx->logohashcheck == Good)
memdump(stdout, "Logo hash (GOOD): ", header->logohash, 0x20);
else
memdump(stdout, "Logo hash (FAIL): ", header->logohash, 0x20);
fprintf(stdout, "Product code: %s\n", productcode);
fprintf(stdout, "Exheader size: %08x\n", getle32(header->extendedheadersize));
if (ctx->exheaderhashcheck == Unchecked)
@@ -549,6 +590,8 @@ void ncch_print(ncch_context* ctx)
fprintf(stdout, " > Crypto key: None\n");
else if (header->flags[7] & 1)
fprintf(stdout, " > Crypto key: %s\n", programid_is_system(header->programid)? "Fixed":"Zeros");
else if (header->flags[3] & 1)
fprintf(stdout, " > Crypto key: Secure2\n");
else
fprintf(stdout, " > Crypto key: Secure\n");
fprintf(stdout, " > Form type: %s\n", formtypetostring(header->flags[5]));
@@ -561,6 +604,8 @@ void ncch_print(ncch_context* ctx)
fprintf(stdout, "Plain region offset: 0x%08x\n", getle32(header->plainregionsize)? offset+getle32(header->plainregionoffset)*mediaunitsize : 0);
fprintf(stdout, "Plain region size: 0x%08x\n", getle32(header->plainregionsize)*mediaunitsize);
fprintf(stdout, "Logo offset: 0x%08x\n", getle32(header->logosize)? offset+getle32(header->logooffset)*mediaunitsize : 0);
fprintf(stdout, "Logo size: 0x%08x\n", getle32(header->logosize)*mediaunitsize);
fprintf(stdout, "ExeFS offset: 0x%08x\n", getle32(header->exefssize)? offset+getle32(header->exefsoffset)*mediaunitsize : 0);
fprintf(stdout, "ExeFS size: 0x%08x\n", getle32(header->exefssize)*mediaunitsize);
fprintf(stdout, "ExeFS hash region size: 0x%08x\n", getle32(header->exefshashregionsize)*mediaunitsize);
+9 -4
View File
@@ -15,6 +15,7 @@ typedef enum
NCCHTYPE_EXHEADER = 1,
NCCHTYPE_EXEFS = 2,
NCCHTYPE_ROMFS = 3,
NCCHTYPE_LOGO = 4,
} ctr_ncchtypes;
typedef struct
@@ -27,8 +28,8 @@ typedef struct
u8 version[2];
u8 reserved0[4];
u8 programid[8];
u8 tempflag;
u8 reserved1[0x2f];
u8 reserved1[0x10];
u8 logohash[0x20];
u8 productcode[0x10];
u8 extendedheaderhash[0x20];
u8 extendedheadersize[4];
@@ -36,7 +37,8 @@ typedef struct
u8 flags[8];
u8 plainregionoffset[4];
u8 plainregionsize[4];
u8 reserved3[8];
u8 logooffset[4];
u8 logosize[4];
u8 exefsoffset[4];
u8 exefssize[4];
u8 exefshashregionsize[4];
@@ -65,6 +67,7 @@ typedef struct
int exefshashcheck;
int romfshashcheck;
int exheaderhashcheck;
int logohashcheck;
int headersigcheck;
u32 extractsize;
u32 extractflags;
@@ -82,12 +85,14 @@ u32 ncch_get_romfs_offset(ncch_context* ctx);
u32 ncch_get_romfs_size(ncch_context* ctx);
u32 ncch_get_exheader_offset(ncch_context* ctx);
u32 ncch_get_exheader_size(ncch_context* ctx);
u32 ncch_get_logo_offset(ncch_context* ctx);
u32 ncch_get_logo_size(ncch_context* ctx);
void ncch_print(ncch_context* ctx);
int ncch_signature_verify(ncch_context* ctx, rsakey2048* key);
void ncch_verify(ncch_context* ctx, u32 flags);
void ncch_save(ncch_context* ctx, u32 type, u32 flags);
int ncch_extract_prepare(ncch_context* ctx, u32 type, u32 flags);
int ncch_extract_buffer(ncch_context* ctx, u8* buffer, u32 buffersize, u32* outsize);
int ncch_extract_buffer(ncch_context* ctx, u8* buffer, u32 buffersize, u32* outsize, u8 nocrypto);
u32 ncch_get_mediaunit_size(ncch_context* ctx);
void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type);
void ncch_determine_key(ncch_context* ctx, u32 actions);
+13
View File
@@ -47,6 +47,14 @@ filepath* settings_get_exheader_path(settings* usersettings)
return 0;
}
filepath* settings_get_logo_path(settings* usersettings)
{
if (usersettings)
return &usersettings->logopath;
else
return 0;
}
filepath* settings_get_exefs_dir_path(settings* usersettings)
{
if (usersettings)
@@ -200,6 +208,11 @@ void settings_set_exheader_path(settings* usersettings, const char* path)
filepath_set(&usersettings->exheaderpath, path);
}
void settings_set_logo_path(settings* usersettings, const char* path)
{
filepath_set(&usersettings->logopath, path);
}
void settings_set_certs_path(settings* usersettings, const char* path)
{
filepath_set(&usersettings->certspath, path);
+3
View File
@@ -14,6 +14,7 @@ typedef struct
filepath romfspath;
filepath romfsdirpath;
filepath exheaderpath;
filepath logopath;
filepath certspath;
filepath contentpath;
filepath tikpath;
@@ -32,6 +33,7 @@ filepath* settings_get_lzss_path(settings* usersettings);
filepath* settings_get_exefs_path(settings* usersettings);
filepath* settings_get_romfs_path(settings* usersettings);
filepath* settings_get_exheader_path(settings* usersettings);
filepath* settings_get_logo_path(settings* usersettings);
filepath* settings_get_certs_path(settings* usersettings);
filepath* settings_get_tik_path(settings* usersettings);
filepath* settings_get_tmd_path(settings* usersettings);
@@ -53,6 +55,7 @@ void settings_set_lzss_path(settings* usersettings, const char* path);
void settings_set_exefs_path(settings* usersettings, const char* path);
void settings_set_romfs_path(settings* usersettings, const char* path);
void settings_set_exheader_path(settings* usersettings, const char* path);
void settings_set_logo_path(settings* usersettings, const char* path);
void settings_set_certs_path(settings* usersettings, const char* path);
void settings_set_tik_path(settings* usersettings, const char* path);
void settings_set_tmd_path(settings* usersettings, const char* path);