mirror of
https://github.com/naehrwert/scetool.git
synced 2025-04-25 14:17:46 +00:00
Updated to v. 0.2.10
- Added ECDSA Signature parsing and validation. - Added klicensee parsing for raw mode. - Fixed metadata info IV parsing. - Fixed Makefile. - Enabled Individuals seed functions for <public build> configuration.
This commit is contained in:
parent
d78d8986c9
commit
e5b9ac8a9b
54 changed files with 1108 additions and 667 deletions
201
sce_inlines.h
201
sce_inlines.h
|
@ -1,201 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011-2013 by naehrwert
|
||||
* This file is released under the GPLv2.
|
||||
*/
|
||||
|
||||
#ifndef _SCE_INLINES_H_
|
||||
#define _SCE_INLINES_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "sce.h"
|
||||
|
||||
static inline void _es_sce_header(sce_header_t *h)
|
||||
{
|
||||
h->magic = _ES32(h->magic);
|
||||
h->version = _ES32(h->version);
|
||||
h->key_revision = _ES16(h->key_revision);
|
||||
h->header_type = _ES16(h->header_type);
|
||||
h->metadata_offset = _ES32(h->metadata_offset);
|
||||
h->header_len = _ES64(h->header_len);
|
||||
h->data_len = _ES64(h->data_len);
|
||||
}
|
||||
|
||||
static inline void _copy_es_sce_header(sce_header_t *dst, sce_header_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(sce_header_t));
|
||||
_es_sce_header(dst);
|
||||
}
|
||||
|
||||
static inline void _es_metadata_header(metadata_header_t *h)
|
||||
{
|
||||
h->sig_input_length = _ES64(h->sig_input_length);
|
||||
h->unknown_0 = _ES32(h->unknown_0);
|
||||
h->section_count = _ES32(h->section_count);
|
||||
h->key_count = _ES32(h->key_count);
|
||||
h->opt_header_size = _ES32(h->opt_header_size);
|
||||
h->unknown_1 = _ES32(h->unknown_1);
|
||||
h->unknown_2 = _ES32(h->unknown_2);
|
||||
}
|
||||
|
||||
static inline void _copy_es_metadata_header(metadata_header_t *dst, metadata_header_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(metadata_header_t));
|
||||
_es_metadata_header(dst);
|
||||
}
|
||||
|
||||
static inline void _es_metadata_section_header(metadata_section_header_t *h)
|
||||
{
|
||||
h->data_offset = _ES64(h->data_offset);
|
||||
h->data_size = _ES64(h->data_size);
|
||||
h->type = _ES32(h->type);
|
||||
h->index = _ES32(h->index);
|
||||
h->hashed = _ES32(h->hashed);
|
||||
h->sha1_index = _ES32(h->sha1_index);
|
||||
h->encrypted = _ES32(h->encrypted);
|
||||
h->key_index = _ES32(h->key_index);
|
||||
h->iv_index = _ES32(h->iv_index);
|
||||
h->compressed = _ES32(h->compressed);
|
||||
}
|
||||
|
||||
static inline void _copy_es_metadata_section_header(metadata_section_header_t *dst, metadata_section_header_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(metadata_section_header_t));
|
||||
_es_metadata_section_header(dst);
|
||||
}
|
||||
|
||||
static inline void _es_self_header(self_header_t *h)
|
||||
{
|
||||
h->header_type = _ES64(h->header_type);
|
||||
h->app_info_offset = _ES64(h->app_info_offset);
|
||||
h->elf_offset = _ES64(h->elf_offset);
|
||||
h->phdr_offset = _ES64(h->phdr_offset);
|
||||
h->shdr_offset = _ES64(h->shdr_offset);
|
||||
h->section_info_offset = _ES64(h->section_info_offset);
|
||||
h->sce_version_offset = _ES64(h->sce_version_offset);
|
||||
h->control_info_offset = _ES64(h->control_info_offset);
|
||||
h->control_info_size = _ES64(h->control_info_size);
|
||||
h->padding = _ES64(h->padding);
|
||||
}
|
||||
|
||||
static inline void _copy_es_self_header(self_header_t *dst, self_header_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(self_header_t));
|
||||
_es_self_header(dst);
|
||||
}
|
||||
|
||||
static inline void _es_section_info(section_info_t *si)
|
||||
{
|
||||
si->offset = _ES64(si->offset);
|
||||
si->size = _ES64(si->size);
|
||||
si->compressed = _ES32(si->compressed);
|
||||
si->unknown_0 = _ES32(si->unknown_0);
|
||||
si->unknown_1 = _ES32(si->unknown_1);
|
||||
si->encrypted = _ES32(si->encrypted);
|
||||
}
|
||||
|
||||
static inline void _copy_es_section_info(section_info_t *dst, section_info_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(section_info_t));
|
||||
_es_section_info(dst);
|
||||
}
|
||||
|
||||
static inline void _es_sce_version(sce_version_t *sv)
|
||||
{
|
||||
sv->header_type = _ES32(sv->header_type);
|
||||
sv->present = _ES32(sv->present);
|
||||
sv->size = _ES32(sv->size);
|
||||
sv->unknown_3 = _ES32(sv->unknown_3);
|
||||
}
|
||||
|
||||
static inline void _copy_es_sce_version(sce_version_t *dst, sce_version_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(sce_version_t));
|
||||
_es_sce_version(dst);
|
||||
}
|
||||
|
||||
static inline void _es_app_info(app_info_t *ai)
|
||||
{
|
||||
ai->auth_id = _ES64(ai->auth_id);
|
||||
ai->vendor_id = _ES32(ai->vendor_id);
|
||||
ai->self_type = _ES32(ai->self_type);
|
||||
ai->version = _ES64(ai->version);
|
||||
ai->padding = _ES64(ai->padding);
|
||||
}
|
||||
|
||||
static inline void _copy_es_app_info(app_info_t *dst, app_info_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(app_info_t));
|
||||
_es_app_info(dst);
|
||||
}
|
||||
|
||||
static inline void _es_control_info(control_info_t *ci)
|
||||
{
|
||||
ci->type = _ES32(ci->type);
|
||||
ci->size = _ES32(ci->size);
|
||||
ci->next = _ES64(ci->next);
|
||||
}
|
||||
|
||||
static inline void _copy_es_control_info(control_info_t *dst, control_info_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(control_info_t));
|
||||
_es_control_info(dst);
|
||||
}
|
||||
|
||||
static inline void _es_ci_data_digest_40(ci_data_digest_40_t *dig)
|
||||
{
|
||||
dig->fw_version = _ES64(dig->fw_version);
|
||||
}
|
||||
|
||||
static inline void _copy_es_ci_data_digest_40(ci_data_digest_40_t *dst, ci_data_digest_40_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(ci_data_digest_40_t));
|
||||
_es_ci_data_digest_40(dst);
|
||||
}
|
||||
|
||||
static inline void _es_ci_data_npdrm(ci_data_npdrm_t *np)
|
||||
{
|
||||
np->magic = _ES32(np->magic);
|
||||
np->unknown_0 = _ES32(np->unknown_0);
|
||||
np->license_type = _ES32(np->license_type);
|
||||
np->app_type = _ES32(np->app_type);
|
||||
np->unknown_1 = _ES64(np->unknown_1);
|
||||
np->unknown_2 = _ES64(np->unknown_2);
|
||||
}
|
||||
|
||||
static inline void _copy_es_ci_data_npdrm(ci_data_npdrm_t *dst, ci_data_npdrm_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(ci_data_npdrm_t));
|
||||
_es_ci_data_npdrm(dst);
|
||||
}
|
||||
|
||||
static inline void _es_opt_header(opt_header_t *oh)
|
||||
{
|
||||
oh->type = _ES32(oh->type);
|
||||
oh->size = _ES32(oh->size);
|
||||
oh->next = _ES64(oh->next);
|
||||
}
|
||||
|
||||
static inline void _copy_es_opt_header(opt_header_t *dst, opt_header_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(opt_header_t));
|
||||
_es_opt_header(dst);
|
||||
}
|
||||
|
||||
static inline void _es_oh_data_cap_flags(oh_data_cap_flags_t *cf)
|
||||
{
|
||||
cf->unk3 = _ES64(cf->unk3);
|
||||
cf->unk4 = _ES64(cf->unk4);
|
||||
cf->flags = _ES64(cf->flags);
|
||||
cf->unk6 = _ES32(cf->unk6);
|
||||
cf->unk7 = _ES32(cf->unk7);
|
||||
}
|
||||
|
||||
static inline void _copy_es_cap_flags(oh_data_cap_flags_t *dst, oh_data_cap_flags_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(oh_data_cap_flags_t));
|
||||
_es_oh_data_cap_flags(dst);
|
||||
}
|
||||
|
||||
#endif
|
22
scetool.sln
Normal file
22
scetool.sln
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.30723.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scetool", "scetool.vcxproj", "{39DC2066-1E3C-488C-8A76-1BB64ABF6C99}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{39DC2066-1E3C-488C-8A76-1BB64ABF6C99}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{39DC2066-1E3C-488C-8A76-1BB64ABF6C99}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{39DC2066-1E3C-488C-8A76-1BB64ABF6C99}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{39DC2066-1E3C-488C-8A76-1BB64ABF6C99}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
128
scetool.vcxproj
Normal file
128
scetool.vcxproj
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.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>{39DC2066-1E3C-488C-8A76-1BB64ABF6C99}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<Optimization>Disabled</Optimization>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;zlibd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/SUBSYSTEM:CONSOLE,5.01 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>/SUBSYSTEM:CONSOLE,5.01 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\aes.cpp" />
|
||||
<ClCompile Include="src\aes_omac.cpp" />
|
||||
<ClCompile Include="src\bn.cpp" />
|
||||
<ClCompile Include="src\ec.cpp" />
|
||||
<ClCompile Include="src\ecdsa.cpp" />
|
||||
<ClCompile Include="src\frontend.cpp" />
|
||||
<ClCompile Include="src\getopt.cpp" />
|
||||
<ClCompile Include="src\keys.cpp" />
|
||||
<ClCompile Include="src\list.cpp" />
|
||||
<ClCompile Include="src\main.cpp" />
|
||||
<ClCompile Include="src\mt19937.cpp" />
|
||||
<ClCompile Include="src\np.cpp" />
|
||||
<ClCompile Include="src\pkg.cpp" />
|
||||
<ClCompile Include="src\rvk.cpp" />
|
||||
<ClCompile Include="src\sce.cpp" />
|
||||
<ClCompile Include="src\self.cpp" />
|
||||
<ClCompile Include="src\sha1.cpp" />
|
||||
<ClCompile Include="src\spp.cpp" />
|
||||
<ClCompile Include="src\tables.cpp" />
|
||||
<ClCompile Include="src\util.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\aes.h" />
|
||||
<ClInclude Include="src\aes_omac.h" />
|
||||
<ClInclude Include="src\config.h" />
|
||||
<ClInclude Include="src\ecdsa.h" />
|
||||
<ClInclude Include="src\elf.h" />
|
||||
<ClInclude Include="src\elf_inlines.h" />
|
||||
<ClInclude Include="src\frontend.h" />
|
||||
<ClInclude Include="src\getopt.h" />
|
||||
<ClInclude Include="src\keys.h" />
|
||||
<ClInclude Include="src\list.h" />
|
||||
<ClInclude Include="src\mt19937.h" />
|
||||
<ClInclude Include="src\np.h" />
|
||||
<ClInclude Include="src\pkg.h" />
|
||||
<ClInclude Include="src\rvk.h" />
|
||||
<ClInclude Include="src\sce.h" />
|
||||
<ClInclude Include="src\sce_inlines.h" />
|
||||
<ClInclude Include="src\self.h" />
|
||||
<ClInclude Include="src\sha1.h" />
|
||||
<ClInclude Include="src\spp.h" />
|
||||
<ClInclude Include="src\tables.h" />
|
||||
<ClInclude Include="src\types.h" />
|
||||
<ClInclude Include="src\util.h" />
|
||||
<ClInclude Include="src\zconf.h" />
|
||||
<ClInclude Include="src\zlib.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
153
scetool.vcxproj.filters
Normal file
153
scetool.vcxproj.filters
Normal file
|
@ -0,0 +1,153 @@
|
|||
<?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="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</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="src\aes.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\aes_omac.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\bn.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ecdsa.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\frontend.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\getopt.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\keys.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\list.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\mt19937.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\np.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\pkg.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\rvk.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\sce.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\self.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\sha1.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\spp.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\tables.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\util.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\aes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\aes_omac.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\config.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\ecdsa.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\elf.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\elf_inlines.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\frontend.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\getopt.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\keys.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\list.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\mt19937.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\np.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\pkg.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\rvk.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\sce.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\sce_inlines.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\self.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\sha1.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\spp.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\tables.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\types.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\util.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\zconf.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\zlib.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
8
scetool.vcxproj.user
Normal file
8
scetool.vcxproj.user
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerCommandArguments>
|
||||
</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -1,4 +1,4 @@
|
|||
CC=gcc
|
||||
CC=g++
|
||||
CFLAGS=-g -O0 -Wall
|
||||
OS_TARGET=scetool
|
||||
LDFLAGS=-lz
|
|
@ -84,6 +84,11 @@ OPTIONS Possible Values Explanation
|
|||
-j, --np-add-sig TRUE/FALSE(default) Whether to add a NP sig. or not.
|
||||
|
||||
==> History <==
|
||||
Version 0.2.10
|
||||
- Added ECDSA Signature parsing and validation.
|
||||
- Added klicensee parsing.
|
||||
- Fixed metadata info IV parsing.
|
||||
- Enabled Individuals seed functions for <public build> configuration.
|
||||
Version 0.2.9
|
||||
- Plaintext sections will now take less space in metadata header keys array.
|
||||
- Added option to specifiy a template SELF to take configuration values from.
|
|
@ -7,7 +7,7 @@
|
|||
#define _CONFIG_H_
|
||||
|
||||
/*! scetool base version. */
|
||||
#define SCETOOL_VERSION_BASE "0.2.9"
|
||||
#define SCETOOL_VERSION_BASE "0.2.10"
|
||||
|
||||
/*! Private build. */
|
||||
//#define CONFIG_PRIVATE_BUILD
|
||||
|
@ -26,10 +26,10 @@
|
|||
#endif
|
||||
|
||||
/*! Private build options. */
|
||||
#ifdef CONFIG_PRIVATE_BUILD
|
||||
//#ifdef CONFIG_PRIVATE_BUILD
|
||||
#define CONFIG_CUSTOM_INDIV_SEED
|
||||
#define CONFIG_DUMP_INDIV_SEED
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#if 0
|
||||
/*! scetool API. */
|
|
@ -74,15 +74,15 @@ static BOOL _fill_self_config_template(s8 *file, self_config_t *sconf)
|
|||
_LOG_VERBOSE("Template header decrypted.\n");
|
||||
|
||||
_LOG_VERBOSE("Using:\n");
|
||||
sconf->key_revision = ctxt->sceh->key_revision;
|
||||
sconf->key_revision = _ES16(ctxt->sceh->key_revision);
|
||||
_IF_VERBOSE(printf(" Key Revision 0x%04X\n", sconf->key_revision));
|
||||
sconf->auth_id = ctxt->self.ai->auth_id;
|
||||
sconf->auth_id = _ES64(ctxt->self.ai->auth_id);
|
||||
_IF_VERBOSE(printf(" Auth-ID 0x%016llX\n", sconf->auth_id));
|
||||
sconf->vendor_id = ctxt->self.ai->vendor_id;
|
||||
sconf->vendor_id = _ES32(ctxt->self.ai->vendor_id);
|
||||
_IF_VERBOSE(printf(" Vendor-ID 0x%08X\n", sconf->vendor_id));
|
||||
sconf->self_type = ctxt->self.ai->self_type;
|
||||
sconf->self_type = _ES32(ctxt->self.ai->self_type);
|
||||
_IF_VERBOSE(printf(" SELF-Type 0x%08X\n", sconf->self_type));
|
||||
sconf->app_version = ctxt->self.ai->version;
|
||||
sconf->app_version = _ES64(ctxt->self.ai->version);
|
||||
_IF_VERBOSE(printf(" APP Version 0x%016llX\n", sconf->app_version));
|
||||
|
||||
control_info_t *ci = sce_get_ctrl_info(ctxt, CONTROL_INFO_TYPE_DIGEST);
|
||||
|
@ -102,11 +102,11 @@ static BOOL _fill_self_config_template(s8 *file, self_config_t *sconf)
|
|||
|
||||
#ifdef CONFIG_CUSTOM_INDIV_SEED
|
||||
sconf->indiv_seed = NULL;
|
||||
if(ctxt->self.ai->self_type == SELF_TYPE_ISO)
|
||||
if(_ES32(ctxt->self.ai->self_type) == SELF_TYPE_ISO)
|
||||
{
|
||||
oh = sce_get_opt_header(ctxt, OPT_HEADER_TYPE_INDIV_SEED);
|
||||
sconf->indiv_seed = (u8 *)_memdup(((u8 *)oh) + sizeof(opt_header_t), oh->size - sizeof(opt_header_t));
|
||||
sconf->indiv_seed_size = oh->size - sizeof(opt_header_t);
|
||||
sconf->indiv_seed = (u8 *)_memdup(((u8 *)oh) + sizeof(opt_header_t), _ES32(oh->size) - sizeof(opt_header_t));
|
||||
sconf->indiv_seed_size = _ES32(oh->size) - sizeof(opt_header_t);
|
||||
_IF_VERBOSE(_hexdump(stdout, " Individuals Seed", 0, sconf->indiv_seed, sconf->indiv_seed_size, 0));
|
||||
}
|
||||
#endif
|
||||
|
@ -334,12 +334,12 @@ void frontend_print_infos(s8 *file)
|
|||
}
|
||||
else
|
||||
printf("[*] Warning: Could not decrypt header.\n");
|
||||
sce_print_info(stdout, ctxt);
|
||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF)
|
||||
sce_print_info(stdout, ctxt, keyset);
|
||||
if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SELF)
|
||||
self_print_info(stdout, ctxt);
|
||||
else if(ctxt->sceh->header_type == SCE_HEADER_TYPE_RVK && ctxt->mdec == TRUE)
|
||||
else if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_RVK && ctxt->mdec == TRUE)
|
||||
rvk_print(stdout, ctxt);
|
||||
else if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SPP && ctxt->mdec == TRUE)
|
||||
else if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SPP && ctxt->mdec == TRUE)
|
||||
spp_print(stdout, ctxt);
|
||||
free(ctxt);
|
||||
}
|
||||
|
@ -387,34 +387,34 @@ void frontend_decrypt(s8 *file_in, s8 *file_out)
|
|||
if(sce_decrypt_data(ctxt))
|
||||
{
|
||||
_LOG_VERBOSE("Data decrypted.\n");
|
||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF)
|
||||
if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SELF)
|
||||
{
|
||||
if(self_write_to_elf(ctxt, file_out) == TRUE)
|
||||
printf("[*] ELF written to %s.\n", file_out);
|
||||
else
|
||||
printf("[*] Error: Could not write ELF.\n");
|
||||
}
|
||||
else if(ctxt->sceh->header_type == SCE_HEADER_TYPE_RVK)
|
||||
else if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_RVK)
|
||||
{
|
||||
if(_write_buffer(file_out, ctxt->scebuffer + ctxt->metash[0].data_offset,
|
||||
ctxt->metash[0].data_size + ctxt->metash[1].data_size))
|
||||
if(_write_buffer(file_out, ctxt->scebuffer + _ES64(ctxt->metash[0].data_offset),
|
||||
_ES64(ctxt->metash[0].data_size) + _ES64(ctxt->metash[1].data_size)))
|
||||
printf("[*] RVK written to %s.\n", file_out);
|
||||
else
|
||||
printf("[*] Error: Could not write RVK.\n");
|
||||
}
|
||||
else if(ctxt->sceh->header_type == SCE_HEADER_TYPE_PKG)
|
||||
else if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_PKG)
|
||||
{
|
||||
/*if(_write_buffer(file_out, ctxt->scebuffer + ctxt->metash[0].data_offset,
|
||||
ctxt->metash[0].data_size + ctxt->metash[1].data_size + ctxt->metash[2].data_size))
|
||||
/*if(_write_buffer(file_out, ctxt->scebuffer + _ES64(ctxt->metash[0].data_offset),
|
||||
_ES64(ctxt->metash[0].data_size) + _ES64(ctxt->metash[1].data_size) + _ES64(ctxt->metash[2].data_size)))
|
||||
printf("[*] PKG written to %s.\n", file_out);
|
||||
else
|
||||
printf("[*] Error: Could not write PKG.\n");*/
|
||||
printf("soon...\n");
|
||||
}
|
||||
else if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SPP)
|
||||
else if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SPP)
|
||||
{
|
||||
if(_write_buffer(file_out, ctxt->scebuffer + ctxt->metash[0].data_offset,
|
||||
ctxt->metash[0].data_size + ctxt->metash[1].data_size))
|
||||
if(_write_buffer(file_out, ctxt->scebuffer + _ES64(ctxt->metash[0].data_offset),
|
||||
_ES64(ctxt->metash[0].data_size) + _ES64(ctxt->metash[1].data_size)))
|
||||
printf("[*] SPP written to %s.\n", file_out);
|
||||
else
|
||||
printf("[*] Error: Could not write SPP.\n");
|
|
@ -351,24 +351,24 @@ keyset_t *keyset_find(sce_buffer_ctxt_t *ctxt)
|
|||
{
|
||||
keyset_t *res = NULL;
|
||||
|
||||
switch(ctxt->sceh->header_type)
|
||||
switch(_ES16(ctxt->sceh->header_type))
|
||||
{
|
||||
case SCE_HEADER_TYPE_SELF:
|
||||
res = _keyset_find_for_self(ctxt->self.ai->self_type, ctxt->sceh->key_revision, ctxt->self.ai->version);
|
||||
res = _keyset_find_for_self(_ES32(ctxt->self.ai->self_type), _ES16(ctxt->sceh->key_revision), _ES64(ctxt->self.ai->version));
|
||||
break;
|
||||
case SCE_HEADER_TYPE_RVK:
|
||||
res = _keyset_find_for_rvk(ctxt->sceh->key_revision);
|
||||
res = _keyset_find_for_rvk(_ES16(ctxt->sceh->key_revision));
|
||||
break;
|
||||
case SCE_HEADER_TYPE_PKG:
|
||||
res = _keyset_find_for_pkg(ctxt->sceh->key_revision);
|
||||
res = _keyset_find_for_pkg(_ES16(ctxt->sceh->key_revision));
|
||||
break;
|
||||
case SCE_HEADER_TYPE_SPP:
|
||||
res = _keyset_find_for_spp(ctxt->sceh->key_revision);
|
||||
res = _keyset_find_for_spp(_ES16(ctxt->sceh->key_revision));
|
||||
break;
|
||||
}
|
||||
|
||||
if(res == NULL)
|
||||
printf("[*] Error: Could not find keyset for %s.\n", _get_name(_sce_header_types, ctxt->sceh->header_type));
|
||||
printf("[*] Error: Could not find keyset for %s.\n", _get_name(_sce_header_types, _ES16(ctxt->sceh->header_type)));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -698,10 +698,10 @@ BOOL klicensee_by_content_id(const s8 *content_id, u8 *klicensee)
|
|||
|
||||
free(rif);
|
||||
|
||||
_LOG_VERBOSE("klicensee decrypted.\n");
|
||||
_LOG_VERBOSE("Klicensee decrypted.\n");
|
||||
}
|
||||
else
|
||||
_LOG_VERBOSE("klicensee converted from %s.rap.\n", content_id);
|
||||
_LOG_VERBOSE("Klicensee converted from %s.rap.\n", content_id);
|
||||
|
||||
return TRUE;
|
||||
}
|
|
@ -348,7 +348,6 @@ static void parse_args(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef _DEBUG
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
s8 *ps3 = NULL, path[256];
|
||||
|
@ -447,4 +446,4 @@ int main(int argc, char **argv)
|
|||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -30,11 +30,9 @@ static ci_data_npdrm_t *_sce_find_ci_npdrm(sce_buffer_ctxt_t *ctxt)
|
|||
{
|
||||
control_info_t *ci = (control_info_t *)iter->value;
|
||||
|
||||
if(ci->type == CONTROL_INFO_TYPE_NPDRM)
|
||||
if(_ES32(ci->type) == CONTROL_INFO_TYPE_NPDRM)
|
||||
{
|
||||
ci_data_npdrm_t *np = (ci_data_npdrm_t *)((u8 *)ci + sizeof(control_info_t));
|
||||
//Fixup.
|
||||
_es_ci_data_npdrm(np);
|
||||
return np;
|
||||
}
|
||||
}
|
||||
|
@ -65,14 +63,14 @@ BOOL np_decrypt_npdrm(sce_buffer_ctxt_t *ctxt)
|
|||
return FALSE;
|
||||
if(_klicensee_key != NULL)
|
||||
memcpy(npdrm_key, _klicensee_key, 0x10);
|
||||
else if(np->license_type == NP_LICENSE_FREE)
|
||||
else if(_ES32(np->license_type) == NP_LICENSE_FREE)
|
||||
{
|
||||
ks_np_klic_free = keyset_find_by_name(CONFIG_NP_KLIC_FREE_KNAME);
|
||||
if(ks_np_klic_free == NULL)
|
||||
return FALSE;
|
||||
memcpy(npdrm_key, ks_np_klic_free->erk, 0x10);
|
||||
}
|
||||
else if(np->license_type == NP_LICENSE_LOCAL)
|
||||
else if(_ES32(np->license_type) == NP_LICENSE_LOCAL)
|
||||
{
|
||||
if ((klicensee_by_content_id((s8 *)np->content_id, npdrm_key)) == FALSE)
|
||||
return FALSE;
|
||||
|
@ -80,6 +78,14 @@ BOOL np_decrypt_npdrm(sce_buffer_ctxt_t *ctxt)
|
|||
else
|
||||
return FALSE;
|
||||
|
||||
if(_raw == TRUE)
|
||||
{
|
||||
printf("[*] Klicensee: ");
|
||||
int i;
|
||||
for(i = 0; i < 0x10; i++)
|
||||
printf("%02X ", npdrm_key[i]);
|
||||
printf("\n");
|
||||
}
|
||||
aes_setkey_dec(&aes_ctxt, ks_klic_key->erk, METADATA_INFO_KEYBITS);
|
||||
aes_crypt_ecb(&aes_ctxt, AES_DECRYPT, npdrm_key, npdrm_key);
|
||||
|
||||
|
@ -107,14 +113,14 @@ BOOL np_encrypt_npdrm(sce_buffer_ctxt_t *ctxt)
|
|||
return FALSE;
|
||||
if(_klicensee_key != NULL)
|
||||
memcpy(npdrm_key, _klicensee_key, 0x10);
|
||||
else if(np->license_type == NP_LICENSE_FREE)
|
||||
else if(_ES32(np->license_type) == NP_LICENSE_FREE)
|
||||
{
|
||||
ks_np_klic_free = keyset_find_by_name(CONFIG_NP_KLIC_FREE_KNAME);
|
||||
if(ks_np_klic_free == NULL)
|
||||
return FALSE;
|
||||
memcpy(npdrm_key, ks_np_klic_free->erk, 0x10);
|
||||
}
|
||||
else if(np->license_type == NP_LICENSE_LOCAL)
|
||||
else if(_ES32(np->license_type) == NP_LICENSE_LOCAL)
|
||||
{
|
||||
if ((klicensee_by_content_id((s8 *)np->content_id, npdrm_key)) == FALSE)
|
||||
return FALSE;
|
||||
|
@ -163,10 +169,10 @@ BOOL np_create_ci(npdrm_config_t *npconf, ci_data_npdrm_t *cinp)
|
|||
else
|
||||
return FALSE;
|
||||
|
||||
cinp->magic = NP_CI_MAGIC;
|
||||
cinp->unknown_0 = 1;
|
||||
cinp->license_type = npconf->license_type;
|
||||
cinp->app_type = npconf->app_type;
|
||||
cinp->magic = _ES32(NP_CI_MAGIC);
|
||||
cinp->unknown_0 = _ES32(1);
|
||||
cinp->license_type = _ES32(npconf->license_type);
|
||||
cinp->app_type = _ES32(npconf->app_type);
|
||||
memcpy(cinp->content_id, npconf->content_id, 0x30);
|
||||
#ifdef CONFIG_PRIVATE_BUILD
|
||||
_fill_rand_bytes(cinp->rndpad, 0x10);
|
||||
|
@ -174,11 +180,8 @@ BOOL np_create_ci(npdrm_config_t *npconf, ci_data_npdrm_t *cinp)
|
|||
//Better than boring random bytes!
|
||||
memcpy(cinp->rndpad, CONFIG_NPDRM_WATERMARK, 0x10);
|
||||
#endif
|
||||
cinp->unknown_1 = 0;
|
||||
cinp->unknown_2 = 0;
|
||||
|
||||
//Fixup before hashing.
|
||||
_es_ci_data_npdrm(cinp);
|
||||
cinp->unknown_1 = _ES64(0);
|
||||
cinp->unknown_2 = _ES64(0);
|
||||
|
||||
//Generate control info hash key.
|
||||
for(i = 0; i < 0x10; i++)
|
|
@ -94,7 +94,7 @@ void rvk_print(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
{
|
||||
u32 i;
|
||||
|
||||
rvk_header_t *rvkh = (rvk_header_t *)(ctxt->scebuffer + ctxt->metash[0].data_offset);
|
||||
rvk_header_t *rvkh = (rvk_header_t *)(ctxt->scebuffer + _ES64(ctxt->metash[0].data_offset));
|
||||
_es_rvk_header(rvkh);
|
||||
|
||||
_print_rvk_header(fp, rvkh);
|
||||
|
@ -102,7 +102,7 @@ void rvk_print(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
//Program revoke.
|
||||
if(rvkh->type_0 == 4)
|
||||
{
|
||||
prg_rvk_entry_t *ent = (prg_rvk_entry_t *)(ctxt->scebuffer + ctxt->metash[1].data_offset);
|
||||
prg_rvk_entry_t *ent = (prg_rvk_entry_t *)(ctxt->scebuffer + _ES64(ctxt->metash[1].data_offset));
|
||||
_print_prg_rvk_entry_header(fp);
|
||||
for(i = 0; i < rvkh->entcnt; i++)
|
||||
{
|
||||
|
@ -113,7 +113,7 @@ void rvk_print(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
else if(rvkh->type_0 == 3)
|
||||
{
|
||||
fprintf(fp, "[*] Package Revoke List Entries:\n");
|
||||
u8 *ent = (u8 *)(ctxt->scebuffer + ctxt->metash[1].data_offset);
|
||||
u8 *ent = (u8 *)(ctxt->scebuffer + _ES64(ctxt->metash[1].data_offset));
|
||||
for(i = 0; i < rvkh->entcnt; i++)
|
||||
{
|
||||
_hexdump(fp, " ent", i*0x20, ent, 0x20, TRUE);
|
|
@ -29,23 +29,23 @@ void _print_sce_header(FILE *fp, sce_header_t *h)
|
|||
const s8 *key_revision;
|
||||
|
||||
fprintf(fp, "[*] SCE Header:\n");
|
||||
fprintf(fp, " Magic 0x%08X [%s]\n", h->magic, (h->magic == SCE_HEADER_MAGIC ? "OK" : "ERROR"));
|
||||
fprintf(fp, " Version 0x%08X\n", h->version);
|
||||
fprintf(fp, " Magic 0x%08X [%s]\n", _ES32(h->magic), (_ES32(h->magic) == SCE_HEADER_MAGIC ? "OK" : "ERROR"));
|
||||
fprintf(fp, " Version 0x%08X\n", _ES32(h->version));
|
||||
|
||||
if(h->key_revision == KEY_REVISION_DEBUG)
|
||||
if(_ES16(h->key_revision) == KEY_REVISION_DEBUG)
|
||||
fprintf(fp, " Key Revision [DEBUG]\n");
|
||||
else
|
||||
fprintf(fp, " Key Revision 0x%04X\n", h->key_revision);
|
||||
fprintf(fp, " Key Revision 0x%04X\n", _ES16(h->key_revision));
|
||||
|
||||
name = _get_name(_sce_header_types, h->header_type);
|
||||
name = _get_name(_sce_header_types, _ES16(h->header_type));
|
||||
if(name != NULL)
|
||||
fprintf(fp, " Header Type [%s]\n", name);
|
||||
else
|
||||
fprintf(fp, " Header Type 0x%04X\n", h->header_type);
|
||||
fprintf(fp, " Header Type 0x%04X\n", _ES16(h->header_type));
|
||||
|
||||
fprintf(fp, " Metadata Offset 0x%08X\n", h->metadata_offset);
|
||||
fprintf(fp, " Header Length 0x%016llX\n", h->header_len);
|
||||
fprintf(fp, " Data Length 0x%016llX\n", h->data_len);
|
||||
fprintf(fp, " Metadata Offset 0x%08X\n", _ES32(h->metadata_offset));
|
||||
fprintf(fp, " Header Length 0x%016llX\n", _ES64(h->header_len));
|
||||
fprintf(fp, " Data Length 0x%016llX\n", _ES64(h->data_len));
|
||||
}
|
||||
|
||||
void _print_metadata_info(FILE *fp, metadata_info_t *mi)
|
||||
|
@ -58,13 +58,13 @@ void _print_metadata_info(FILE *fp, metadata_info_t *mi)
|
|||
void _print_metadata_header(FILE *fp, metadata_header_t *mh)
|
||||
{
|
||||
fprintf(fp, "[*] Metadata Header:\n");
|
||||
fprintf(fp, " Signature Input Length 0x%016llX\n", mh->sig_input_length);
|
||||
fprintf(fp, " unknown_0 0x%08X\n", mh->unknown_0);
|
||||
fprintf(fp, " Section Count 0x%08X\n", mh->section_count);
|
||||
fprintf(fp, " Key Count 0x%08X\n", mh->key_count);
|
||||
fprintf(fp, " Optional Header Size 0x%08X\n", mh->opt_header_size);
|
||||
fprintf(fp, " unknown_1 0x%08X\n", mh->unknown_1);
|
||||
fprintf(fp, " unknown_2 0x%08X\n", mh->unknown_2);
|
||||
fprintf(fp, " Signature Input Length 0x%016llX\n", _ES64(mh->sig_input_length));
|
||||
fprintf(fp, " unknown_0 0x%08X\n", _ES32(mh->unknown_0));
|
||||
fprintf(fp, " Section Count 0x%08X\n", _ES32(mh->section_count));
|
||||
fprintf(fp, " Key Count 0x%08X\n", _ES32(mh->key_count));
|
||||
fprintf(fp, " Optional Header Size 0x%08X\n", _ES32(mh->opt_header_size));
|
||||
fprintf(fp, " unknown_1 0x%08X\n", _ES32(mh->unknown_1));
|
||||
fprintf(fp, " unknown_2 0x%08X\n", _ES32(mh->unknown_2));
|
||||
}
|
||||
|
||||
static void _print_metadata_section_header_header(FILE *fp)
|
||||
|
@ -76,19 +76,19 @@ static void _print_metadata_section_header_header(FILE *fp)
|
|||
void _print_metadata_section_header(FILE *fp, metadata_section_header_t *msh, u32 idx)
|
||||
{
|
||||
fprintf(fp, " %03d %08llX %08llX %02X %02X ",
|
||||
idx, msh->data_offset, msh->data_size, msh->type, msh->index);
|
||||
idx, _ES64(msh->data_offset), _ES64(msh->data_size), _ES32(msh->type), _ES32(msh->index));
|
||||
|
||||
if(msh->hashed == METADATA_SECTION_HASHED)
|
||||
fprintf(fp, "[YES] %02X ", msh->sha1_index);
|
||||
if(_ES32(msh->hashed) == METADATA_SECTION_HASHED)
|
||||
fprintf(fp, "[YES] %02X ", _ES32(msh->sha1_index));
|
||||
else
|
||||
fprintf(fp, "[NO ] -- ");
|
||||
|
||||
if(msh->encrypted == METADATA_SECTION_ENCRYPTED)
|
||||
fprintf(fp, "[YES] %02X %02X ", msh->key_index, msh->iv_index);
|
||||
if(_ES32(msh->encrypted) == METADATA_SECTION_ENCRYPTED)
|
||||
fprintf(fp, "[YES] %02X %02X ", _ES32(msh->key_index), _ES32(msh->iv_index));
|
||||
else
|
||||
fprintf(fp, "[NO ] -- -- ");
|
||||
|
||||
if(msh->compressed == METADATA_SECTION_COMPRESSED)
|
||||
if(_ES32(msh->compressed) == METADATA_SECTION_COMPRESSED)
|
||||
fprintf(fp, "[YES]\n");
|
||||
else
|
||||
fprintf(fp, "[NO ]\n");
|
||||
|
@ -99,16 +99,48 @@ void _print_sce_file_keys(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
u32 i;
|
||||
|
||||
//Get start of keys.
|
||||
u8 *keys = (u8 *)ctxt->metash + sizeof(metadata_section_header_t) * ctxt->metah->section_count;
|
||||
u8 *keys = (u8 *)ctxt->metash + sizeof(metadata_section_header_t) * _ES32(ctxt->metah->section_count);
|
||||
|
||||
fprintf(fp, "[*] SCE File Keys:\n");
|
||||
for(i = 0; i < ctxt->metah->key_count; i++)
|
||||
for(i = 0; i < _ES32(ctxt->metah->key_count); i++)
|
||||
{
|
||||
fprintf(fp, " %02X:", i);
|
||||
_hexdump(fp, "", i, keys+i*0x10, 0x10, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
void _print_sce_signature(FILE *fp, signature_t *sig)
|
||||
{
|
||||
fprintf(fp, "[*] Signature:\n");
|
||||
_hexdump(fp, " R", 0, sig->r, SIGNATURE_R_SIZE, FALSE);
|
||||
_hexdump(fp, " S", 0, sig->s, SIGNATURE_S_SIZE, FALSE);
|
||||
}
|
||||
|
||||
void _print_sce_signature_status(FILE *fp, sce_buffer_ctxt_t *ctxt, u8 *keyset)
|
||||
{
|
||||
u8 hash[0x14];
|
||||
keyset_t *ks;
|
||||
|
||||
//Check if a keyset is provided.
|
||||
if(keyset == NULL)
|
||||
{
|
||||
//Try to find keyset.
|
||||
ks = keyset_find(ctxt);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Use the provided keyset.
|
||||
ks = keyset_from_buffer(keyset);
|
||||
}
|
||||
//Generate header hash.
|
||||
sha1(ctxt->scebuffer, _ES64(ctxt->metah->sig_input_length), hash);
|
||||
|
||||
//Validate the signature.
|
||||
ecdsa_set_curve(ks->ctype);
|
||||
ecdsa_set_pub(ks->pub);
|
||||
fprintf(fp, "[*] Signature status: %s\n", (ecdsa_verify(hash, ctxt->sig->r, ctxt->sig->s) == TRUE ? "OK" : "FAIL"));
|
||||
}
|
||||
|
||||
static sce_buffer_ctxt_t *_sce_create_ctxt()
|
||||
{
|
||||
sce_buffer_ctxt_t *res;
|
||||
|
@ -156,46 +188,41 @@ sce_buffer_ctxt_t *sce_create_ctxt_from_buffer(u8 *scebuffer)
|
|||
|
||||
//Set pointer to SCE header.
|
||||
res->sceh = (sce_header_t *)scebuffer;
|
||||
_es_sce_header(res->sceh);
|
||||
|
||||
//Set pointers to file type specific headers.
|
||||
switch(res->sceh->header_type)
|
||||
switch(_ES16(res->sceh->header_type))
|
||||
{
|
||||
case SCE_HEADER_TYPE_SELF:
|
||||
{
|
||||
//SELF header.
|
||||
res->self.selfh = (self_header_t *)(res->scebuffer + sizeof(sce_header_t));
|
||||
_es_self_header(res->self.selfh);
|
||||
|
||||
//Application info.
|
||||
res->self.ai = (app_info_t *)(res->scebuffer + res->self.selfh->app_info_offset);
|
||||
_es_app_info(res->self.ai);
|
||||
res->self.ai = (app_info_t *)(res->scebuffer + _ES64(res->self.selfh->app_info_offset));
|
||||
|
||||
//Section infos.
|
||||
res->self.si = (section_info_t *)(res->scebuffer + res->self.selfh->section_info_offset);
|
||||
res->self.si = (section_info_t *)(res->scebuffer + _ES64(res->self.selfh->section_info_offset));
|
||||
|
||||
//SCE version.
|
||||
if(res->self.selfh->sce_version_offset != NULL)
|
||||
if(_ES64(res->self.selfh->sce_version_offset) != NULL)
|
||||
{
|
||||
res->self.sv = (sce_version_t *)(res->scebuffer + res->self.selfh->sce_version_offset);
|
||||
_es_sce_version(res->self.sv);
|
||||
res->self.sv = (sce_version_t *)(res->scebuffer + _ES64(res->self.selfh->sce_version_offset));
|
||||
}
|
||||
else
|
||||
res->self.sv = 0;
|
||||
|
||||
//Get pointers to all control infos.
|
||||
u32 len = (u32)res->self.selfh->control_info_size;
|
||||
u32 len = (u32)(_ES64(res->self.selfh->control_info_size));
|
||||
if(len > 0)
|
||||
{
|
||||
u8 *ptr = res->scebuffer + res->self.selfh->control_info_offset;
|
||||
u8 *ptr = res->scebuffer + _ES64(res->self.selfh->control_info_offset);
|
||||
res->self.cis = list_create();
|
||||
|
||||
while(len > 0)
|
||||
{
|
||||
control_info_t *tci = (control_info_t *)ptr;
|
||||
_es_control_info(tci);
|
||||
ptr += tci->size;
|
||||
len -= tci->size;
|
||||
ptr += _ES32(tci->size);
|
||||
len -= _ES32(tci->size);
|
||||
list_add_back(res->self.cis, tci);
|
||||
}
|
||||
}
|
||||
|
@ -219,7 +246,7 @@ sce_buffer_ctxt_t *sce_create_ctxt_from_buffer(u8 *scebuffer)
|
|||
}
|
||||
|
||||
//Set pointers to metadata headers.
|
||||
res->metai = (metadata_info_t *)(scebuffer + sizeof(sce_header_t) + res->sceh->metadata_offset);
|
||||
res->metai = (metadata_info_t *)(scebuffer + sizeof(sce_header_t) + _ES32(res->sceh->metadata_offset));
|
||||
res->metah = (metadata_header_t *)((u8 *)res->metai + sizeof(metadata_info_t));
|
||||
res->metash = (metadata_section_header_t *)((u8 *)res->metah + sizeof(metadata_header_t));
|
||||
|
||||
|
@ -233,14 +260,14 @@ sce_buffer_ctxt_t *sce_create_ctxt_build_self(u8 *elf, u32 elf_len)
|
|||
if((res = _sce_create_ctxt()) == NULL)
|
||||
return NULL;
|
||||
|
||||
res->sceh->magic = SCE_HEADER_MAGIC;
|
||||
res->sceh->version = SCE_HEADER_VERSION_2;
|
||||
res->sceh->header_type = SCE_HEADER_TYPE_SELF;
|
||||
res->sceh->magic = _ES32(SCE_HEADER_MAGIC);
|
||||
res->sceh->version = _ES32(SCE_HEADER_VERSION_2);
|
||||
res->sceh->header_type = _ES16(SCE_HEADER_TYPE_SELF);
|
||||
|
||||
//Allocate SELF header.
|
||||
res->self.selfh = (self_header_t *)malloc(sizeof(self_header_t));
|
||||
memset(res->self.selfh, 0, sizeof(self_header_t));
|
||||
res->self.selfh->header_type = SUB_HEADER_TYPE_SELF;
|
||||
res->self.selfh->header_type = _ES64(SUB_HEADER_TYPE_SELF);
|
||||
//Allocate application info.
|
||||
res->self.ai = (app_info_t *)malloc(sizeof(app_info_t));
|
||||
memset(res->self.ai, 0, sizeof(app_info_t));
|
||||
|
@ -275,11 +302,11 @@ void sce_add_data_section(sce_buffer_ctxt_t *ctxt, void *buffer, u32 size, BOOL
|
|||
|
||||
void sce_set_metash(sce_buffer_ctxt_t *ctxt, u32 type, BOOL encrypted, u32 idx)
|
||||
{
|
||||
ctxt->metash[idx].type = type;
|
||||
ctxt->metash[idx].index = (type == METADATA_SECTION_TYPE_PHDR ? idx : type == METADATA_SECTION_TYPE_SHDR ? idx + 1 : idx);
|
||||
ctxt->metash[idx].hashed = METADATA_SECTION_HASHED;
|
||||
ctxt->metash[idx].encrypted = (encrypted == TRUE ? METADATA_SECTION_ENCRYPTED : METADATA_SECTION_NOT_ENCRYPTED);
|
||||
ctxt->metash[idx].compressed = METADATA_SECTION_NOT_COMPRESSED;
|
||||
ctxt->metash[idx].type = _ES32(type);
|
||||
ctxt->metash[idx].index = _ES32(_ES32(type) == METADATA_SECTION_TYPE_PHDR ? idx : _ES32(type) == METADATA_SECTION_TYPE_SHDR ? idx + 1 : idx);
|
||||
ctxt->metash[idx].hashed = _ES32(METADATA_SECTION_HASHED);
|
||||
ctxt->metash[idx].encrypted = _ES32(encrypted == TRUE ? METADATA_SECTION_ENCRYPTED : METADATA_SECTION_NOT_ENCRYPTED);
|
||||
ctxt->metash[idx].compressed = _ES32(METADATA_SECTION_NOT_COMPRESSED);
|
||||
}
|
||||
|
||||
void sce_compress_data(sce_buffer_ctxt_t *ctxt)
|
||||
|
@ -307,15 +334,15 @@ void sce_compress_data(sce_buffer_ctxt_t *ctxt)
|
|||
sec->size = size_comp;
|
||||
|
||||
//Set compression in section info.
|
||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF && i < ctxt->makeself->si_sec_cnt)
|
||||
if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SELF && i < ctxt->makeself->si_sec_cnt)
|
||||
{
|
||||
ctxt->self.si[i].compressed = SECTION_INFO_COMPRESSED;
|
||||
//Update size too.
|
||||
ctxt->self.si[i].size = size_comp;
|
||||
}
|
||||
|
||||
//Set compression in maetadata section header.
|
||||
ctxt->metash[i].compressed = METADATA_SECTION_COMPRESSED;
|
||||
//Set compression in metadata section header.
|
||||
ctxt->metash[i].compressed = _ES32(METADATA_SECTION_COMPRESSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -336,7 +363,7 @@ static u32 _sce_get_ci_len(sce_buffer_ctxt_t *ctxt)
|
|||
u32 res = 0;
|
||||
|
||||
LIST_FOREACH(iter, ctxt->self.cis)
|
||||
res += ((control_info_t *)iter->value)->size;
|
||||
res += _ES32(((control_info_t *)iter->value)->size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -346,7 +373,7 @@ static u32 _sce_get_oh_len(sce_buffer_ctxt_t *ctxt)
|
|||
u32 res = 0;
|
||||
|
||||
LIST_FOREACH(iter, ctxt->self.ohs)
|
||||
res += ((opt_header_t *)iter->value)->size;
|
||||
res += _ES32(((opt_header_t *)iter->value)->size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -356,7 +383,7 @@ void _sce_fixup_ctxt(sce_buffer_ctxt_t *ctxt)
|
|||
u32 i = 0, base_off, last_off;
|
||||
|
||||
//Set section info data.
|
||||
base_off = ctxt->sceh->header_len;
|
||||
base_off = _ES64(ctxt->sceh->header_len);
|
||||
LIST_FOREACH(iter, ctxt->secs)
|
||||
{
|
||||
//Save last offset.
|
||||
|
@ -367,52 +394,52 @@ void _sce_fixup_ctxt(sce_buffer_ctxt_t *ctxt)
|
|||
sec->offset = base_off;
|
||||
|
||||
//Section infos for SELF (that are present as data sections).
|
||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF && i < ctxt->makeself->si_sec_cnt)
|
||||
if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SELF && i < ctxt->makeself->si_sec_cnt)
|
||||
//{
|
||||
ctxt->self.si[i].offset = base_off;
|
||||
// ctxt->self.si[i].size = sec->size;
|
||||
//}
|
||||
|
||||
//Metadata section headers.
|
||||
ctxt->metash[i].data_offset = base_off;
|
||||
ctxt->metash[i].data_size = sec->size;
|
||||
ctxt->metash[i].data_offset = _ES64(base_off);
|
||||
ctxt->metash[i].data_size = _ES64(sec->size);
|
||||
|
||||
//Update offset and data length.
|
||||
base_off += sec->size;
|
||||
ctxt->sceh->data_len = base_off - ctxt->sceh->header_len;
|
||||
ctxt->sceh->data_len = _ES64(base_off - _ES64(ctxt->sceh->header_len));
|
||||
base_off = ALIGN(base_off, SCE_ALIGN);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
//Set metadata offset (counted from after SCE header).
|
||||
ctxt->sceh->metadata_offset = ctxt->off_metai - sizeof(sce_header_t);
|
||||
ctxt->sceh->metadata_offset = _ES32(ctxt->off_metai - sizeof(sce_header_t));
|
||||
|
||||
//Set metadata header values.
|
||||
ctxt->metah->sig_input_length = ctxt->off_sig;
|
||||
ctxt->metah->unknown_0 = 1;
|
||||
ctxt->metah->opt_header_size = _sce_get_oh_len(ctxt);
|
||||
ctxt->metah->unknown_1 = 0;
|
||||
ctxt->metah->unknown_2 = 0;
|
||||
ctxt->metah->sig_input_length = _ES64(ctxt->off_sig);
|
||||
ctxt->metah->unknown_0 = _ES32(1);
|
||||
ctxt->metah->opt_header_size = _ES32(_sce_get_oh_len(ctxt));
|
||||
ctxt->metah->unknown_1 = _ES32(0);
|
||||
ctxt->metah->unknown_2 = _ES32(0);
|
||||
|
||||
switch(ctxt->sceh->header_type)
|
||||
switch(_ES16(ctxt->sceh->header_type))
|
||||
{
|
||||
case SCE_HEADER_TYPE_SELF:
|
||||
{
|
||||
//Set header offsets.
|
||||
ctxt->self.selfh->app_info_offset = ctxt->off_self.off_ai;
|
||||
ctxt->self.selfh->elf_offset = ctxt->off_self.off_ehdr;
|
||||
ctxt->self.selfh->phdr_offset = ctxt->off_self.off_phdr;
|
||||
ctxt->self.selfh->section_info_offset = ctxt->off_self.off_si;
|
||||
ctxt->self.selfh->sce_version_offset = ctxt->off_self.off_sv;
|
||||
ctxt->self.selfh->control_info_offset = ctxt->off_self.off_cis;
|
||||
ctxt->self.selfh->control_info_size = _sce_get_ci_len(ctxt);
|
||||
ctxt->self.selfh->app_info_offset = _ES64(ctxt->off_self.off_ai);
|
||||
ctxt->self.selfh->elf_offset = _ES64(ctxt->off_self.off_ehdr);
|
||||
ctxt->self.selfh->phdr_offset = _ES64(ctxt->off_self.off_phdr);
|
||||
ctxt->self.selfh->section_info_offset = _ES64(ctxt->off_self.off_si);
|
||||
ctxt->self.selfh->sce_version_offset = _ES64(ctxt->off_self.off_sv);
|
||||
ctxt->self.selfh->control_info_offset = _ES64(ctxt->off_self.off_cis);
|
||||
ctxt->self.selfh->control_info_size = _ES64(_sce_get_ci_len(ctxt));
|
||||
|
||||
//Set section headers offset in SELF header (last data section) if available.
|
||||
if(ctxt->makeself->shdrs != NULL)
|
||||
ctxt->self.selfh->shdr_offset = last_off;
|
||||
ctxt->self.selfh->shdr_offset = _ES64(last_off);
|
||||
else
|
||||
ctxt->self.selfh->shdr_offset = 0;
|
||||
ctxt->self.selfh->shdr_offset = _ES64(0);
|
||||
}
|
||||
break;
|
||||
case SCE_HEADER_TYPE_RVK:
|
||||
|
@ -436,24 +463,24 @@ void _sce_fixup_keys(sce_buffer_ctxt_t *ctxt)
|
|||
|
||||
//Build keys array.
|
||||
ctxt->keys_len = 0;
|
||||
ctxt->metah->key_count = 0;
|
||||
for(i = 0; i < ctxt->metah->section_count; i++)
|
||||
ctxt->metah->key_count = _ES32(0);
|
||||
for(i = 0; i < _ES32(ctxt->metah->section_count); i++)
|
||||
{
|
||||
if(ctxt->metash[i].encrypted == METADATA_SECTION_ENCRYPTED)
|
||||
if(_ES32(ctxt->metash[i].encrypted) == METADATA_SECTION_ENCRYPTED)
|
||||
{
|
||||
ctxt->keys_len += 0x80; //0x60 HMAC, 0x20 key/iv
|
||||
ctxt->metah->key_count += 8;
|
||||
ctxt->metash[i].sha1_index = ctxt->metah->key_count - 8;
|
||||
ctxt->metash[i].key_index = ctxt->metah->key_count - 2;
|
||||
ctxt->metash[i].iv_index = ctxt->metah->key_count - 1;
|
||||
ctxt->metah->key_count += _ES32(8);
|
||||
ctxt->metash[i].sha1_index = _ES32(_ES32(ctxt->metah->key_count) - 8);
|
||||
ctxt->metash[i].key_index = _ES32(_ES32(ctxt->metah->key_count) - 2);
|
||||
ctxt->metash[i].iv_index = _ES32(_ES32(ctxt->metah->key_count) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ctxt->keys_len += 0x60; //0x60 HMAC
|
||||
ctxt->metah->key_count += 6;
|
||||
ctxt->metash[i].sha1_index = ctxt->metah->key_count - 6;
|
||||
ctxt->metash[i].key_index = 0xFFFFFFFF;
|
||||
ctxt->metash[i].iv_index = 0xFFFFFFFF;
|
||||
ctxt->metah->key_count += _ES32(6);
|
||||
ctxt->metash[i].sha1_index = _ES32(_ES32(ctxt->metah->key_count) - 6);
|
||||
ctxt->metash[i].key_index = _ES32(0xFFFFFFFF);
|
||||
ctxt->metash[i].iv_index = _ES32(0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -495,7 +522,7 @@ void sce_layout_ctxt(sce_buffer_ctxt_t *ctxt)
|
|||
//SCE header.
|
||||
ctxt->off_sceh = _INC_OFF_TYPE(coff, sce_header_t);
|
||||
|
||||
switch(ctxt->sceh->header_type)
|
||||
switch(_ES16(ctxt->sceh->header_type))
|
||||
{
|
||||
case SCE_HEADER_TYPE_SELF:
|
||||
{
|
||||
|
@ -534,13 +561,13 @@ void sce_layout_ctxt(sce_buffer_ctxt_t *ctxt)
|
|||
//Metadata header.
|
||||
ctxt->off_metah = _INC_OFF_TYPE(coff, metadata_header_t);
|
||||
//Metadata section headers.
|
||||
ctxt->off_metash = _INC_OFF_SIZE(coff, ctxt->metah->section_count * sizeof(metadata_section_header_t));
|
||||
ctxt->off_metash = _INC_OFF_SIZE(coff, _ES32(ctxt->metah->section_count) * sizeof(metadata_section_header_t));
|
||||
//Keys.
|
||||
_sce_fixup_keys(ctxt);
|
||||
ctxt->off_keys = _INC_OFF_SIZE(coff, ctxt->keys_len);
|
||||
|
||||
//SELF only headers.
|
||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF)
|
||||
if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SELF)
|
||||
{
|
||||
//Optional headers.
|
||||
ctxt->off_self.off_ohs = _INC_OFF_SIZE(coff, _sce_get_oh_len(ctxt));
|
||||
|
@ -554,7 +581,7 @@ void sce_layout_ctxt(sce_buffer_ctxt_t *ctxt)
|
|||
coff = ALIGN(coff, HEADER_ALIGN);
|
||||
|
||||
//Set header length.
|
||||
ctxt->sceh->header_len = coff;
|
||||
ctxt->sceh->header_len = _ES64(coff);
|
||||
|
||||
//Set missing values, etc.
|
||||
_sce_fixup_ctxt(ctxt);
|
||||
|
@ -565,21 +592,21 @@ static void _sce_build_header(sce_buffer_ctxt_t *ctxt)
|
|||
u32 i;
|
||||
|
||||
//Allocate header buffer.
|
||||
ctxt->scebuffer = (u8*)malloc(sizeof(u8) * ctxt->sceh->header_len);
|
||||
memset(ctxt->scebuffer, 0, sizeof(u8) * ctxt->sceh->header_len);
|
||||
ctxt->scebuffer = (u8*)malloc(sizeof(u8) * _ES64(ctxt->sceh->header_len));
|
||||
memset(ctxt->scebuffer, 0, sizeof(u8) * _ES64(ctxt->sceh->header_len));
|
||||
|
||||
//SCE header.
|
||||
_copy_es_sce_header((sce_header_t *)(ctxt->scebuffer + ctxt->off_sceh), ctxt->sceh);
|
||||
memcpy((sce_header_t *)(ctxt->scebuffer + ctxt->off_sceh), ctxt->sceh, sizeof(sce_header_t));
|
||||
|
||||
//File type dependent headers.
|
||||
switch(ctxt->sceh->header_type)
|
||||
switch(_ES16(ctxt->sceh->header_type))
|
||||
{
|
||||
case SCE_HEADER_TYPE_SELF:
|
||||
{
|
||||
//SELF header.
|
||||
_copy_es_self_header((self_header_t *)(ctxt->scebuffer + ctxt->off_self.off_selfh), ctxt->self.selfh);
|
||||
memcpy((self_header_t *)(ctxt->scebuffer + ctxt->off_self.off_selfh), ctxt->self.selfh, sizeof(self_header_t));
|
||||
//Application info.
|
||||
_copy_es_app_info((app_info_t *)(ctxt->scebuffer + ctxt->off_self.off_ai), ctxt->self.ai);
|
||||
memcpy((app_info_t *)(ctxt->scebuffer + ctxt->off_self.off_ai), ctxt->self.ai, sizeof(app_info_t));
|
||||
//ELF header.
|
||||
memcpy(ctxt->scebuffer + ctxt->off_self.off_ehdr, ctxt->makeself->ehdr, ctxt->makeself->ehsize);
|
||||
//ELF program headers.
|
||||
|
@ -591,7 +618,7 @@ static void _sce_build_header(sce_buffer_ctxt_t *ctxt)
|
|||
_copy_es_section_info((section_info_t *)(ctxt->scebuffer + ctxt->off_self.off_si + sizeof(section_info_t) * i), &ctxt->self.si[i]);
|
||||
|
||||
//SCE version.
|
||||
_copy_es_sce_version((sce_version_t *)(ctxt->scebuffer + ctxt->off_self.off_sv), ctxt->self.sv);
|
||||
memcpy((sce_version_t *)(ctxt->scebuffer + ctxt->off_self.off_sv), ctxt->self.sv, sizeof(sce_version_t));
|
||||
|
||||
//Control infos.
|
||||
u32 ci_base = ctxt->off_self.off_cis;
|
||||
|
@ -600,11 +627,11 @@ static void _sce_build_header(sce_buffer_ctxt_t *ctxt)
|
|||
control_info_t *ci = (control_info_t *)iter->value;
|
||||
|
||||
//Copy control info header.
|
||||
_copy_es_control_info((control_info_t *)(ctxt->scebuffer + ci_base), ci);
|
||||
memcpy((control_info_t *)(ctxt->scebuffer + ci_base), ci, sizeof(control_info_t));
|
||||
//Copy data.
|
||||
memcpy(ctxt->scebuffer + ci_base + sizeof(control_info_t), ((u8 *)ci) + sizeof(control_info_t), ci->size - sizeof(control_info_t));
|
||||
memcpy(ctxt->scebuffer + ci_base + sizeof(control_info_t), ((u8 *)ci) + sizeof(control_info_t), _ES32(ci->size) - sizeof(control_info_t));
|
||||
|
||||
ci_base += ci->size;
|
||||
ci_base += _ES32(ci->size);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -625,16 +652,16 @@ static void _sce_build_header(sce_buffer_ctxt_t *ctxt)
|
|||
//Metadata info.
|
||||
memcpy(ctxt->scebuffer + ctxt->off_metai, ctxt->metai, sizeof(metadata_info_t));
|
||||
//Metadata header.
|
||||
_copy_es_metadata_header((metadata_header_t *)(ctxt->scebuffer + ctxt->off_metah), ctxt->metah);
|
||||
memcpy((metadata_header_t *)(ctxt->scebuffer + ctxt->off_metah), ctxt->metah, sizeof(metadata_header_t));
|
||||
//Metadata section headers.
|
||||
for(i = 0; i < ctxt->metah->section_count; i++)
|
||||
_copy_es_metadata_section_header((metadata_section_header_t *)(ctxt->scebuffer + ctxt->off_metash + sizeof(metadata_section_header_t) * i), &ctxt->metash[i]);
|
||||
for(i = 0; i < _ES32(ctxt->metah->section_count); i++)
|
||||
memcpy((metadata_section_header_t *)(ctxt->scebuffer + ctxt->off_metash + sizeof(metadata_section_header_t) * i), &ctxt->metash[i], sizeof(metadata_section_header_t));
|
||||
|
||||
//Keys.
|
||||
//memcpy(ctxt->scebuffer + ctxt->off_keys, ctxt->keys, ctxt->keys_len);
|
||||
|
||||
//SELF only headers.
|
||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF)
|
||||
if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SELF)
|
||||
{
|
||||
//Optional headers.
|
||||
u32 oh_base = ctxt->off_self.off_ohs;
|
||||
|
@ -643,11 +670,11 @@ static void _sce_build_header(sce_buffer_ctxt_t *ctxt)
|
|||
opt_header_t *oh = (opt_header_t *)iter->value;
|
||||
|
||||
//Copy optional header.
|
||||
_copy_es_opt_header((opt_header_t *)(ctxt->scebuffer + oh_base), oh);
|
||||
memcpy((opt_header_t *)(ctxt->scebuffer + oh_base), oh, sizeof(opt_header_t));
|
||||
//Copy data.
|
||||
memcpy(ctxt->scebuffer + oh_base + sizeof(opt_header_t), ((u8 *)oh) + sizeof(opt_header_t), oh->size - sizeof(opt_header_t));
|
||||
memcpy(ctxt->scebuffer + oh_base + sizeof(opt_header_t), ((u8 *)oh) + sizeof(opt_header_t), _ES32(oh->size) - sizeof(opt_header_t));
|
||||
|
||||
oh_base += oh->size;
|
||||
oh_base += _ES32(oh->size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -661,7 +688,7 @@ static BOOL _sce_sign_header(sce_buffer_ctxt_t *ctxt, keyset_t *ks)
|
|||
return FALSE;
|
||||
|
||||
//Generate header hash.
|
||||
sha1(ctxt->scebuffer, ctxt->metah->sig_input_length, hash);
|
||||
sha1(ctxt->scebuffer, _ES64(ctxt->metah->sig_input_length), hash);
|
||||
|
||||
//Generate signature.
|
||||
ecdsa_set_curve(ks->ctype);
|
||||
|
@ -683,7 +710,7 @@ static void _sce_calculate_hashes(sce_buffer_ctxt_t *ctxt)
|
|||
{
|
||||
sce_section_ctxt_t *sec = (sce_section_ctxt_t *)iter->value;
|
||||
|
||||
sha1_idx = ctxt->metash[i].sha1_index;
|
||||
sha1_idx = _ES32(ctxt->metash[i].sha1_index);
|
||||
memset(ctxt->keys + sha1_idx * 0x10, 0, 0x20);
|
||||
sha1_hmac(ctxt->keys + (sha1_idx + 2) * 0x10, 0x40, (u8 *)sec->buffer, sec->size, ctxt->keys + sha1_idx * 0x10);
|
||||
|
||||
|
@ -727,7 +754,7 @@ static BOOL _sce_encrypt_header(sce_buffer_ctxt_t *ctxt, u8 *keyset)
|
|||
aes_setkey_enc(&aes_ctxt, ctxt->metai->key, METADATA_INFO_KEYBITS);
|
||||
memcpy(iv, ctxt->metai->iv, 0x10);
|
||||
aes_crypt_ctr(&aes_ctxt,
|
||||
ctxt->sceh->header_len - (sizeof(sce_header_t) + ctxt->sceh->metadata_offset + sizeof(metadata_info_t)),
|
||||
_ES64(ctxt->sceh->header_len) - (sizeof(sce_header_t) + _ES32(ctxt->sceh->metadata_offset) + sizeof(metadata_info_t)),
|
||||
&nc_off, iv, sblk, ptr, ptr);
|
||||
|
||||
//Encrypt metadata info.
|
||||
|
@ -736,7 +763,7 @@ static BOOL _sce_encrypt_header(sce_buffer_ctxt_t *ctxt, u8 *keyset)
|
|||
aes_crypt_cbc(&aes_ctxt, AES_ENCRYPT, sizeof(metadata_info_t), ks->riv, ptr, ptr);
|
||||
|
||||
//Add NPDRM layer.
|
||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF && ctxt->self.ai->self_type == SELF_TYPE_NPDRM)
|
||||
if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SELF && _ES32(ctxt->self.ai->self_type) == SELF_TYPE_NPDRM)
|
||||
if(np_encrypt_npdrm(ctxt) == FALSE)
|
||||
return FALSE;
|
||||
|
||||
|
@ -756,10 +783,10 @@ static void _sce_encrypt_data(sce_buffer_ctxt_t *ctxt)
|
|||
u8 buf[16];
|
||||
u8 iv[16];
|
||||
|
||||
if(ctxt->metash[i].encrypted == METADATA_SECTION_ENCRYPTED)
|
||||
if(_ES32(ctxt->metash[i].encrypted) == METADATA_SECTION_ENCRYPTED)
|
||||
{
|
||||
memcpy(iv, ctxt->keys + ctxt->metash[i].iv_index * 0x10, 0x10);
|
||||
aes_setkey_enc(&aes_ctxt, ctxt->keys + ctxt->metash[i].key_index * 0x10, 128);
|
||||
memcpy(iv, ctxt->keys + _ES32(ctxt->metash[i].iv_index) * 0x10, 0x10);
|
||||
aes_setkey_enc(&aes_ctxt, ctxt->keys + _ES32(ctxt->metash[i].key_index) * 0x10, 128);
|
||||
aes_crypt_ctr(&aes_ctxt, sec->size, &nc_off, iv, buf, (u8 *)sec->buffer, (u8 *)sec->buffer);
|
||||
}
|
||||
|
||||
|
@ -790,7 +817,7 @@ BOOL sce_write_ctxt(sce_buffer_ctxt_t *ctxt, s8 *fname)
|
|||
return FALSE;
|
||||
|
||||
//Write SCE file header.
|
||||
fwrite(ctxt->scebuffer, sizeof(u8), ctxt->sceh->header_len, fp);
|
||||
fwrite(ctxt->scebuffer, sizeof(u8), _ES64(ctxt->sceh->header_len), fp);
|
||||
|
||||
//Write SCE file sections.
|
||||
LIST_FOREACH(iter, ctxt->secs)
|
||||
|
@ -809,7 +836,7 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset)
|
|||
{
|
||||
u32 i;
|
||||
size_t nc_off;
|
||||
u8 sblk[0x10], iv[0x10];
|
||||
u8 sblk[0x10], iv[0x10], ctr_iv[0x10];
|
||||
keyset_t *ks;
|
||||
aes_context aes_ctxt;
|
||||
|
||||
|
@ -832,7 +859,7 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset)
|
|||
}
|
||||
|
||||
//Remove NPDRM layer.
|
||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF && ctxt->self.ai->self_type == SELF_TYPE_NPDRM)
|
||||
if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SELF && _ES32(ctxt->self.ai->self_type) == SELF_TYPE_NPDRM)
|
||||
if(np_decrypt_npdrm(ctxt) == FALSE)
|
||||
return FALSE;
|
||||
|
||||
|
@ -852,43 +879,37 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset)
|
|||
|
||||
//Decrypt metadata header, metadata section headers and keys.
|
||||
nc_off = 0;
|
||||
memcpy (ctr_iv, ctxt->metai->iv ,0x10);
|
||||
aes_setkey_enc(&aes_ctxt, ctxt->metai->key, METADATA_INFO_KEYBITS);
|
||||
aes_crypt_ctr(&aes_ctxt,
|
||||
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);
|
||||
|
||||
//Fixup headers.
|
||||
_es_metadata_header(ctxt->metah);
|
||||
for(i = 0; i < ctxt->metah->section_count; i++)
|
||||
_es_metadata_section_header(&ctxt->metash[i]);
|
||||
_ES64(ctxt->sceh->header_len) - (sizeof(sce_header_t) + _ES32(ctxt->sceh->metadata_offset) + sizeof(metadata_info_t)),
|
||||
&nc_off, ctr_iv, sblk, (u8 *)ctxt->metah, (u8 *)ctxt->metah);
|
||||
|
||||
//Metadata decrypted.
|
||||
ctxt->mdec = TRUE;
|
||||
|
||||
//Set start of SCE file keys.
|
||||
ctxt->keys = (u8 *)ctxt->metash + sizeof(metadata_section_header_t) * ctxt->metah->section_count;
|
||||
ctxt->keys_len = ctxt->metah->key_count * 0x10;
|
||||
ctxt->keys = (u8 *)ctxt->metash + sizeof(metadata_section_header_t) * _ES32(ctxt->metah->section_count);
|
||||
ctxt->keys_len = _ES32(ctxt->metah->key_count) * 0x10;
|
||||
|
||||
//Set SELF only headers.
|
||||
if(ctxt->sceh->header_type == SCE_HEADER_TYPE_SELF)
|
||||
if(_ES16(ctxt->sceh->header_type) == SCE_HEADER_TYPE_SELF)
|
||||
{
|
||||
//Get pointers to all optional headers.
|
||||
ctxt->self.ohs = list_create();
|
||||
opt_header_t *oh = (opt_header_t *)(ctxt->keys + ctxt->metah->key_count * 0x10);
|
||||
_es_opt_header(oh);
|
||||
opt_header_t *oh = (opt_header_t *)(ctxt->keys + _ES32(ctxt->metah->key_count) * 0x10);
|
||||
list_add_back(ctxt->self.ohs, oh);
|
||||
while(oh->next != 0)
|
||||
while(_ES64(oh->next) != 0)
|
||||
{
|
||||
oh = (opt_header_t *)((u8 *)oh + oh->size);
|
||||
_es_opt_header(oh);
|
||||
oh = (opt_header_t *)((u8 *)oh + _ES32(oh->size));
|
||||
list_add_back(ctxt->self.ohs, oh);
|
||||
}
|
||||
|
||||
//Signature.
|
||||
ctxt->sig = (signature_t *)((u8 *)oh + oh->size);
|
||||
ctxt->sig = (signature_t *)((u8 *)oh + _ES32(oh->size));
|
||||
}
|
||||
else
|
||||
ctxt->sig = (signature_t *)(ctxt->keys + ctxt->metah->key_count * 0x10);
|
||||
ctxt->sig = (signature_t *)(ctxt->keys + _ES32(ctxt->metah->key_count) * 0x10);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -899,23 +920,23 @@ BOOL sce_decrypt_data(sce_buffer_ctxt_t *ctxt)
|
|||
aes_context aes_ctxt;
|
||||
|
||||
//Decrypt sections.
|
||||
for(i = 0; i < ctxt->metah->section_count; i++)
|
||||
for(i = 0; i < _ES32(ctxt->metah->section_count); i++)
|
||||
{
|
||||
size_t nc_off = 0;
|
||||
u8 buf[16];
|
||||
u8 iv[16];
|
||||
|
||||
//Only decrypt encrypted sections.
|
||||
if(ctxt->metash[i].encrypted == METADATA_SECTION_ENCRYPTED)
|
||||
if(_ES32(ctxt->metash[i].encrypted) == METADATA_SECTION_ENCRYPTED)
|
||||
{
|
||||
if(ctxt->metash[i].key_index > ctxt->metah->key_count - 1 || ctxt->metash[i].iv_index > ctxt->metah->key_count)
|
||||
if(_ES32(ctxt->metash[i].key_index) > _ES32(ctxt->metah->key_count) - 1 || _ES32(ctxt->metash[i].iv_index) > _ES32(ctxt->metah->key_count))
|
||||
printf("[*] Warning: Skipped decryption of section %03d (marked encrypted but key/iv index out of range)\n", i);
|
||||
else
|
||||
{
|
||||
memcpy(iv, ctxt->keys + ctxt->metash[i].iv_index * 0x10, 0x10);
|
||||
aes_setkey_enc(&aes_ctxt, ctxt->keys + ctxt->metash[i].key_index * 0x10, 128);
|
||||
u8 *ptr = ctxt->scebuffer + ctxt->metash[i].data_offset;
|
||||
aes_crypt_ctr(&aes_ctxt, ctxt->metash[i].data_size, &nc_off, iv, buf, ptr, ptr);
|
||||
memcpy(iv, ctxt->keys + _ES32(ctxt->metash[i].iv_index) * 0x10, 0x10);
|
||||
aes_setkey_enc(&aes_ctxt, ctxt->keys + _ES32(ctxt->metash[i].key_index) * 0x10, 128);
|
||||
u8 *ptr = ctxt->scebuffer + _ES64(ctxt->metash[i].data_offset);
|
||||
aes_crypt_ctr(&aes_ctxt, _ES64(ctxt->metash[i].data_size), &nc_off, iv, buf, ptr, ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -923,7 +944,7 @@ BOOL sce_decrypt_data(sce_buffer_ctxt_t *ctxt)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
void sce_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
||||
void sce_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt, u8 *keyset)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
|
@ -940,11 +961,17 @@ void sce_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
|
||||
//Print section infos.
|
||||
_print_metadata_section_header_header(fp);
|
||||
for(i = 0; i < ctxt->metah->section_count; i++)
|
||||
for(i = 0; i < _ES32(ctxt->metah->section_count); i++)
|
||||
_print_metadata_section_header(fp, &ctxt->metash[i], i);
|
||||
|
||||
//Print keys.
|
||||
_print_sce_file_keys(fp, ctxt);
|
||||
|
||||
//Print signature.
|
||||
_print_sce_signature(fp, ctxt->sig);
|
||||
|
||||
//Print signature status.
|
||||
_print_sce_signature_status(fp, ctxt, keyset);
|
||||
}
|
||||
|
||||
static s8 _sce_tmp_vstr[16];
|
||||
|
@ -981,7 +1008,7 @@ control_info_t *sce_get_ctrl_info(sce_buffer_ctxt_t *ctxt, u32 type)
|
|||
LIST_FOREACH(iter, ctxt->self.cis)
|
||||
{
|
||||
control_info_t *ci = (control_info_t *)iter->value;
|
||||
if(ci->type == type)
|
||||
if(_ES32(ci->type) == type)
|
||||
return ci;
|
||||
}
|
||||
|
||||
|
@ -993,7 +1020,7 @@ opt_header_t *sce_get_opt_header(sce_buffer_ctxt_t *ctxt, u32 type)
|
|||
LIST_FOREACH(iter, ctxt->self.ohs)
|
||||
{
|
||||
opt_header_t *oh = (opt_header_t *)iter->value;
|
||||
if(oh->type == type)
|
||||
if(_ES32(oh->type) == type)
|
||||
return oh;
|
||||
}
|
||||
|
|
@ -596,7 +596,7 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset);
|
|||
BOOL sce_decrypt_data(sce_buffer_ctxt_t *ctxt);
|
||||
|
||||
/*! Print SCE file info. */
|
||||
void sce_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt);
|
||||
void sce_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt, u8 *keyset);
|
||||
|
||||
/*! Get version string from version. */
|
||||
s8 *sce_version_to_str(u64 version);
|
57
src/sce_inlines.h
Normal file
57
src/sce_inlines.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2011-2013 by naehrwert
|
||||
* This file is released under the GPLv2.
|
||||
*/
|
||||
|
||||
#ifndef _SCE_INLINES_H_
|
||||
#define _SCE_INLINES_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "sce.h"
|
||||
|
||||
|
||||
static inline void _es_section_info(section_info_t *si)
|
||||
{
|
||||
si->offset = _ES64(si->offset);
|
||||
si->size = _ES64(si->size);
|
||||
si->compressed = _ES32(si->compressed);
|
||||
si->unknown_0 = _ES32(si->unknown_0);
|
||||
si->unknown_1 = _ES32(si->unknown_1);
|
||||
si->encrypted = _ES32(si->encrypted);
|
||||
}
|
||||
|
||||
static inline void _copy_es_section_info(section_info_t *dst, section_info_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(section_info_t));
|
||||
_es_section_info(dst);
|
||||
}
|
||||
|
||||
static inline void _es_ci_data_digest_40(ci_data_digest_40_t *dig)
|
||||
{
|
||||
dig->fw_version = _ES64(dig->fw_version);
|
||||
}
|
||||
|
||||
static inline void _copy_es_ci_data_digest_40(ci_data_digest_40_t *dst, ci_data_digest_40_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(ci_data_digest_40_t));
|
||||
_es_ci_data_digest_40(dst);
|
||||
}
|
||||
|
||||
static inline void _es_oh_data_cap_flags(oh_data_cap_flags_t *cf)
|
||||
{
|
||||
cf->unk3 = _ES64(cf->unk3);
|
||||
cf->unk4 = _ES64(cf->unk4);
|
||||
cf->flags = _ES64(cf->flags);
|
||||
cf->unk6 = _ES32(cf->unk6);
|
||||
cf->unk7 = _ES32(cf->unk7);
|
||||
}
|
||||
|
||||
static inline void _copy_es_cap_flags(oh_data_cap_flags_t *dst, oh_data_cap_flags_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(oh_data_cap_flags_t));
|
||||
_es_oh_data_cap_flags(dst);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -47,16 +47,16 @@ static void _get_phdr_flags(s8 *str, u64 flags)
|
|||
void _print_self_header(FILE *fp, self_header_t *h)
|
||||
{
|
||||
fprintf(fp, "[*] SELF Header:\n");
|
||||
fprintf(fp, " Header Type 0x%016llX\n", h->header_type);
|
||||
fprintf(fp, " App Info Offset 0x%016llX\n", h->app_info_offset);
|
||||
fprintf(fp, " ELF Offset 0x%016llX\n", h->elf_offset);
|
||||
fprintf(fp, " PH Offset 0x%016llX\n", h->phdr_offset);
|
||||
fprintf(fp, " SH Offset 0x%016llX\n", h->shdr_offset);
|
||||
fprintf(fp, " Section Info Offset 0x%016llX\n", h->section_info_offset);
|
||||
fprintf(fp, " SCE Version Offset 0x%016llX\n", h->sce_version_offset);
|
||||
fprintf(fp, " Control Info Offset 0x%016llX\n", h->control_info_offset);
|
||||
fprintf(fp, " Control Info Size 0x%016llX\n", h->control_info_size);
|
||||
//fprintf(fp, " padding 0x%016llX\n", h->padding);
|
||||
fprintf(fp, " Header Type 0x%016llX\n", _ES64(h->header_type));
|
||||
fprintf(fp, " App Info Offset 0x%016llX\n", _ES64(h->app_info_offset));
|
||||
fprintf(fp, " ELF Offset 0x%016llX\n", _ES64(h->elf_offset));
|
||||
fprintf(fp, " PH Offset 0x%016llX\n", _ES64(h->phdr_offset));
|
||||
fprintf(fp, " SH Offset 0x%016llX\n", _ES64(h->shdr_offset));
|
||||
fprintf(fp, " Section Info Offset 0x%016llX\n", _ES64(h->section_info_offset));
|
||||
fprintf(fp, " SCE Version Offset 0x%016llX\n", _ES64(h->sce_version_offset));
|
||||
fprintf(fp, " Control Info Offset 0x%016llX\n", _ES64(h->control_info_offset));
|
||||
fprintf(fp, " Control Info Size 0x%016llX\n", _ES64(h->control_info_size));
|
||||
//fprintf(fp, " padding 0x%016llX\n", _ES64(h->padding));
|
||||
}
|
||||
|
||||
void _print_app_info(FILE *fp, app_info_t *ai)
|
||||
|
@ -65,34 +65,34 @@ void _print_app_info(FILE *fp, app_info_t *ai)
|
|||
|
||||
fprintf(fp, "[*] Application Info:\n");
|
||||
|
||||
name = _get_name(_auth_ids, ai->auth_id);
|
||||
name = _get_name(_auth_ids, _ES64(ai->auth_id));
|
||||
if(name != NULL)
|
||||
{
|
||||
fprintf(fp, " Auth-ID ");
|
||||
_PRINT_RAW(fp, "0x%016llX ", ai->auth_id);
|
||||
_PRINT_RAW(fp, "0x%016llX ", _ES64(ai->auth_id));
|
||||
fprintf(fp, "[%s]\n", name);
|
||||
}
|
||||
else
|
||||
fprintf(fp, " Auth-ID 0x%016llX\n", ai->auth_id);
|
||||
fprintf(fp, " Auth-ID 0x%016llX\n", _ES64(ai->auth_id));
|
||||
|
||||
name = _get_name(_vendor_ids, ai->vendor_id);
|
||||
name = _get_name(_vendor_ids, _ES32(ai->vendor_id));
|
||||
if(name != NULL)
|
||||
{
|
||||
fprintf(fp, " Vendor-ID ");
|
||||
_PRINT_RAW(fp, "0x%08X ", ai->vendor_id);
|
||||
_PRINT_RAW(fp, "0x%08X ", _ES32(ai->vendor_id));
|
||||
fprintf(fp, "[%s]\n", name);
|
||||
}
|
||||
else
|
||||
fprintf(fp, " Vendor-ID 0x%08X\n", ai->vendor_id);
|
||||
fprintf(fp, " Vendor-ID 0x%08X\n", _ES32(ai->vendor_id));
|
||||
|
||||
name = _get_name(_self_types, ai->self_type);
|
||||
name = _get_name(_self_types, _ES32(ai->self_type));
|
||||
if(name != NULL)
|
||||
fprintf(fp, " SELF-Type [%s]\n", name);
|
||||
else
|
||||
fprintf(fp, " SELF-Type 0x%08X\n", ai->self_type);
|
||||
fprintf(fp, " SELF-Type 0x%08X\n", _ES32(ai->self_type));
|
||||
|
||||
fprintf(fp, " Version %s\n", sce_version_to_str(ai->version));
|
||||
//fprintf(fp, " padding 0x%016llX\n", ai->padding);
|
||||
fprintf(fp, " Version %s\n", sce_version_to_str(_ES64(ai->version)));
|
||||
//fprintf(fp, " padding 0x%016llX\n", _ES64(ai->padding));
|
||||
}
|
||||
|
||||
void _print_section_info_header(FILE *fp)
|
||||
|
@ -111,10 +111,10 @@ void _print_section_info(FILE *fp, section_info_t *si, u32 idx)
|
|||
void _print_sce_version(FILE *fp, sce_version_t *sv)
|
||||
{
|
||||
fprintf(fp, "[*] SCE Version:\n");
|
||||
fprintf(fp, " Header Type 0x%08X\n", sv->header_type);
|
||||
fprintf(fp, " Present [%s]\n", sv->present == SCE_VERSION_PRESENT ? "TRUE" : "FALSE");
|
||||
fprintf(fp, " Size 0x%08X\n", sv->size);
|
||||
fprintf(fp, " unknown_3 0x%08X\n", sv->unknown_3);
|
||||
fprintf(fp, " Header Type 0x%08X\n", _ES32(sv->header_type));
|
||||
fprintf(fp, " Present [%s]\n", _ES32(sv->present) == SCE_VERSION_PRESENT ? "TRUE" : "FALSE");
|
||||
fprintf(fp, " Size 0x%08X\n", _ES32(sv->size));
|
||||
fprintf(fp, " unknown_3 0x%08X\n", _ES32(sv->unknown_3));
|
||||
}
|
||||
|
||||
void _print_control_info(FILE *fp, control_info_t *ci)
|
||||
|
@ -123,27 +123,27 @@ void _print_control_info(FILE *fp, control_info_t *ci)
|
|||
|
||||
fprintf(fp, "[*] Control Info\n");
|
||||
|
||||
name = _get_name(_control_info_types, ci->type);
|
||||
name = _get_name(_control_info_types, _ES32(ci->type));
|
||||
if(name != NULL)
|
||||
fprintf(fp, " Type %s\n", name);
|
||||
else
|
||||
fprintf(fp, " Type 0x%08X\n", ci->type);
|
||||
fprintf(fp, " Type 0x%08X\n", _ES32(ci->type));
|
||||
|
||||
fprintf(fp, " Size 0x%08X\n", ci->size);
|
||||
fprintf(fp, " Next [%s]\n", ci->next == 1 ? "TRUE" : "FALSE");
|
||||
fprintf(fp, " Size 0x%08X\n", _ES32(ci->size));
|
||||
fprintf(fp, " Next [%s]\n", _ES64(ci->next) == 1 ? "TRUE" : "FALSE");
|
||||
|
||||
switch(ci->type)
|
||||
switch(_ES32(ci->type))
|
||||
{
|
||||
case CONTROL_INFO_TYPE_FLAGS:
|
||||
_hexdump(fp, " Flags", 0, (u8 *)ci + sizeof(control_info_t), ci->size - sizeof(control_info_t), FALSE);
|
||||
_hexdump(fp, " Flags", 0, (u8 *)ci + sizeof(control_info_t), _ES32(ci->size) - sizeof(control_info_t), FALSE);
|
||||
break;
|
||||
case CONTROL_INFO_TYPE_DIGEST:
|
||||
if(ci->size == 0x30)
|
||||
if(_ES32(ci->size) == 0x30)
|
||||
{
|
||||
ci_data_digest_30_t *dig = (ci_data_digest_30_t *)((u8 *)ci + sizeof(control_info_t));
|
||||
_hexdump(fp, " Digest", 0, dig->digest, 20, FALSE);
|
||||
}
|
||||
else if(ci->size == 0x40)
|
||||
else if(_ES32(ci->size) == 0x40)
|
||||
{
|
||||
ci_data_digest_40_t *dig = (ci_data_digest_40_t *)((u8 *)ci + sizeof(control_info_t));
|
||||
_es_ci_data_digest_40(dig);
|
||||
|
@ -158,16 +158,16 @@ void _print_control_info(FILE *fp, control_info_t *ci)
|
|||
ci_data_npdrm_t *np = (ci_data_npdrm_t *)((u8 *)ci + sizeof(control_info_t));
|
||||
//Was already fixed in decrypt_header.
|
||||
//_es_ci_data_npdrm(np);
|
||||
fprintf(fp, " Magic 0x%08X [%s]\n", np->magic, (np->magic == NP_CI_MAGIC ? "OK" : "ERROR"));
|
||||
fprintf(fp, " unknown_0 0x%08X\n", np->unknown_0);
|
||||
fprintf(fp, " Licence Type 0x%08X\n", np->license_type);
|
||||
fprintf(fp, " App Type 0x%08X\n", np->app_type);
|
||||
fprintf(fp, " Magic 0x%08X [%s]\n", _ES32(np->magic), (_ES32(np->magic) == NP_CI_MAGIC ? "OK" : "ERROR"));
|
||||
fprintf(fp, " unknown_0 0x%08X\n", _ES32(np->unknown_0));
|
||||
fprintf(fp, " Licence Type 0x%08X\n", _ES32(np->license_type));
|
||||
fprintf(fp, " App Type 0x%08X\n", _ES32(np->app_type));
|
||||
fprintf(fp, " ContentID %s\n", np->content_id);
|
||||
_hexdump(fp, " Random Pad ", 0, np->rndpad, 0x10, FALSE);
|
||||
_hexdump(fp, " CID_FN Hash ", 0, np->hash_cid_fname, 0x10, FALSE);
|
||||
_hexdump(fp, " CI Hash ", 0, np->hash_ci, 0x10, FALSE);
|
||||
fprintf(fp, " unknown_1 0x%016llX\n", np->unknown_1);
|
||||
fprintf(fp, " unknown_2 0x%016llX\n", np->unknown_2);
|
||||
fprintf(fp, " unknown_1 0x%016llX\n", _ES64(np->unknown_1));
|
||||
fprintf(fp, " unknown_2 0x%016llX\n", _ES64(np->unknown_2));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -197,16 +197,16 @@ void _print_opt_header(FILE *fp, opt_header_t *oh)
|
|||
|
||||
fprintf(fp, "[*] Optional Header\n");
|
||||
|
||||
name = _get_name(_optional_header_types, oh->type);
|
||||
name = _get_name(_optional_header_types, _ES32(oh->type));
|
||||
if(name != NULL)
|
||||
fprintf(fp, " Type %s\n", name);
|
||||
else
|
||||
fprintf(fp, " Type 0x%08X\n", oh->type);
|
||||
fprintf(fp, " Type 0x%08X\n", _ES32(oh->type));
|
||||
|
||||
fprintf(fp, " Size 0x%08X\n", oh->size);
|
||||
fprintf(fp, " Next [%s]\n", oh->next == 1 ? "TRUE" : "FALSE");
|
||||
fprintf(fp, " Size 0x%08X\n", _ES32(oh->size));
|
||||
fprintf(fp, " Next [%s]\n", _ES64(oh->next) == 1 ? "TRUE" : "FALSE");
|
||||
|
||||
switch(oh->type)
|
||||
switch(_ES32(oh->type))
|
||||
{
|
||||
case OPT_HEADER_TYPE_CAP_FLAGS:
|
||||
{
|
||||
|
@ -231,7 +231,7 @@ void _print_opt_header(FILE *fp, opt_header_t *oh)
|
|||
case OPT_HEADER_TYPE_INDIV_SEED:
|
||||
{
|
||||
u8 *is = (u8 *)oh + sizeof(opt_header_t);
|
||||
_hexdump(fp, " Seed", 0, is, oh->size - sizeof(opt_header_t), TRUE);
|
||||
_hexdump(fp, " Seed", 0, is, _ES32(oh->size) - sizeof(opt_header_t), TRUE);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
@ -404,7 +404,7 @@ BOOL self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
const u8 *eident;
|
||||
|
||||
//Check for SELF.
|
||||
if(ctxt->sceh->header_type != SCE_HEADER_TYPE_SELF)
|
||||
if(_ES16(ctxt->sceh->header_type) != SCE_HEADER_TYPE_SELF)
|
||||
return FALSE;
|
||||
|
||||
//Print SELF infos.
|
||||
|
@ -424,7 +424,7 @@ BOOL self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
LIST_FOREACH(iter, ctxt->self.ohs)
|
||||
{
|
||||
#ifndef CONFIG_DUMP_INDIV_SEED
|
||||
if(((opt_header_t *)iter->value)->type != OPT_HEADER_TYPE_INDIV_SEED)
|
||||
if(_ES32(((opt_header_t *)iter->value)->type) != OPT_HEADER_TYPE_INDIV_SEED)
|
||||
_print_opt_header(fp, (opt_header_t *)iter->value);
|
||||
#else
|
||||
_print_opt_header(fp, (opt_header_t *)iter->value);
|
||||
|
@ -432,14 +432,14 @@ BOOL self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
}
|
||||
}
|
||||
|
||||
self_type = ctxt->self.ai->self_type;
|
||||
eident = ctxt->scebuffer + ctxt->self.selfh->elf_offset;
|
||||
self_type = _ES32(ctxt->self.ai->self_type);
|
||||
eident = ctxt->scebuffer + _ES64(ctxt->self.selfh->elf_offset);
|
||||
|
||||
//SPU is 32 bit.
|
||||
if(self_type == SELF_TYPE_LDR || self_type == SELF_TYPE_ISO || eident[EI_CLASS] == ELFCLASS32)
|
||||
{
|
||||
//32 bit ELF.
|
||||
Elf32_Ehdr *eh = (Elf32_Ehdr *)(ctxt->scebuffer + ctxt->self.selfh->elf_offset);
|
||||
Elf32_Ehdr *eh = (Elf32_Ehdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->elf_offset));
|
||||
_es_elf32_ehdr(eh);
|
||||
|
||||
//Print section infos.
|
||||
|
@ -453,7 +453,7 @@ BOOL self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
//Print ELF header.
|
||||
_print_elf32_ehdr(fp, eh);
|
||||
|
||||
Elf32_Phdr *ph = (Elf32_Phdr *)(ctxt->scebuffer + ctxt->self.selfh->phdr_offset);
|
||||
Elf32_Phdr *ph = (Elf32_Phdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->phdr_offset));
|
||||
|
||||
//Print program headers.
|
||||
_print_elf32_phdr_header(fp);
|
||||
|
@ -465,7 +465,7 @@ BOOL self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
|
||||
if(eh->e_shnum > 0)
|
||||
{
|
||||
Elf32_Shdr *sh = (Elf32_Shdr *)(ctxt->scebuffer + ctxt->self.selfh->shdr_offset);
|
||||
Elf32_Shdr *sh = (Elf32_Shdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->shdr_offset));
|
||||
|
||||
//Print section headers.
|
||||
_print_elf32_shdr_header(fp);
|
||||
|
@ -479,7 +479,7 @@ BOOL self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
else
|
||||
{
|
||||
//64 bit ELF.
|
||||
Elf64_Ehdr *eh = (Elf64_Ehdr *)(ctxt->scebuffer + ctxt->self.selfh->elf_offset);
|
||||
Elf64_Ehdr *eh = (Elf64_Ehdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->elf_offset));
|
||||
_es_elf64_ehdr(eh);
|
||||
|
||||
//Print section infos.
|
||||
|
@ -493,7 +493,7 @@ BOOL self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
//Print ELF header.
|
||||
_print_elf64_ehdr(stdout, eh);
|
||||
|
||||
Elf64_Phdr *ph = (Elf64_Phdr *)(ctxt->scebuffer + ctxt->self.selfh->phdr_offset);
|
||||
Elf64_Phdr *ph = (Elf64_Phdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->phdr_offset));
|
||||
|
||||
//Print program headers.
|
||||
_print_elf64_phdr_header(fp);
|
||||
|
@ -505,7 +505,7 @@ BOOL self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
|
||||
if(eh->e_shnum > 0)
|
||||
{
|
||||
Elf64_Shdr *sh = (Elf64_Shdr *)(ctxt->scebuffer + ctxt->self.selfh->shdr_offset);
|
||||
Elf64_Shdr *sh = (Elf64_Shdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->shdr_offset));
|
||||
|
||||
//Print section headers.
|
||||
_print_elf64_shdr_header(fp);
|
||||
|
@ -529,14 +529,14 @@ BOOL self_write_to_elf(sce_buffer_ctxt_t *ctxt, const s8 *elf_out)
|
|||
const u8 *eident;
|
||||
|
||||
//Check for SELF.
|
||||
if(ctxt->sceh->header_type != SCE_HEADER_TYPE_SELF)
|
||||
if(_ES16(ctxt->sceh->header_type) != SCE_HEADER_TYPE_SELF)
|
||||
return FALSE;
|
||||
|
||||
if((fp = fopen(elf_out, "wb")) == NULL)
|
||||
return FALSE;
|
||||
|
||||
self_type = ctxt->self.ai->self_type;
|
||||
eident = ctxt->scebuffer + ctxt->self.selfh->elf_offset;
|
||||
self_type = _ES32(ctxt->self.ai->self_type);
|
||||
eident = ctxt->scebuffer + _ES64(ctxt->self.selfh->elf_offset);
|
||||
|
||||
//SPU is 32 bit.
|
||||
if(self_type == SELF_TYPE_LDR || self_type == SELF_TYPE_ISO || eident[EI_CLASS] == ELFCLASS32)
|
||||
|
@ -557,32 +557,32 @@ BOOL self_write_to_elf(sce_buffer_ctxt_t *ctxt, const s8 *elf_out)
|
|||
#endif
|
||||
|
||||
//32 bit ELF.
|
||||
Elf32_Ehdr ceh, *eh = (Elf32_Ehdr *)(ctxt->scebuffer + ctxt->self.selfh->elf_offset);
|
||||
Elf32_Ehdr ceh, *eh = (Elf32_Ehdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->elf_offset));
|
||||
_copy_es_elf32_ehdr(&ceh, eh);
|
||||
|
||||
//Write ELF header.
|
||||
fwrite(eh, sizeof(Elf32_Ehdr), 1, fp);
|
||||
|
||||
//Write program headers.
|
||||
Elf32_Phdr *ph = (Elf32_Phdr *)(ctxt->scebuffer + ctxt->self.selfh->phdr_offset);
|
||||
Elf32_Phdr *ph = (Elf32_Phdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->phdr_offset));
|
||||
fwrite(ph, sizeof(Elf32_Phdr), ceh.e_phnum, fp);
|
||||
|
||||
//Write program data.
|
||||
metadata_section_header_t *msh = ctxt->metash;
|
||||
for(i = 0; i < ctxt->metah->section_count; i++)
|
||||
for(i = 0; i < _ES32(ctxt->metah->section_count); i++)
|
||||
{
|
||||
if(msh[i].type == METADATA_SECTION_TYPE_PHDR)
|
||||
if(_ES32(msh[i].type) == METADATA_SECTION_TYPE_PHDR)
|
||||
{
|
||||
_es_elf32_phdr(&ph[msh[i].index]);
|
||||
fseek(fp, ph[msh[i].index].p_offset, SEEK_SET);
|
||||
fwrite(ctxt->scebuffer + msh[i].data_offset, sizeof(u8), msh[i].data_size, fp);
|
||||
_es_elf32_phdr(&ph[_ES32(msh[i].index)]);
|
||||
fseek(fp, ph[_ES32(msh[i].index)].p_offset, SEEK_SET);
|
||||
fwrite(ctxt->scebuffer + _ES64(msh[i].data_offset), sizeof(u8), _ES64(msh[i].data_size), fp);
|
||||
}
|
||||
}
|
||||
|
||||
//Write section headers.
|
||||
if(ctxt->self.selfh->shdr_offset != 0)
|
||||
if(_ES64(ctxt->self.selfh->shdr_offset) != 0)
|
||||
{
|
||||
Elf32_Shdr *sh = (Elf32_Shdr *)(ctxt->scebuffer + ctxt->self.selfh->shdr_offset);
|
||||
Elf32_Shdr *sh = (Elf32_Shdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->shdr_offset));
|
||||
fseek(fp, ceh.e_shoff, SEEK_SET);
|
||||
fwrite(sh, sizeof(Elf32_Shdr), ceh.e_shnum, fp);
|
||||
}
|
||||
|
@ -590,46 +590,46 @@ BOOL self_write_to_elf(sce_buffer_ctxt_t *ctxt, const s8 *elf_out)
|
|||
else
|
||||
{
|
||||
//64 bit ELF.
|
||||
Elf64_Ehdr ceh, *eh = (Elf64_Ehdr *)(ctxt->scebuffer + ctxt->self.selfh->elf_offset);
|
||||
Elf64_Ehdr ceh, *eh = (Elf64_Ehdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->elf_offset));
|
||||
_copy_es_elf64_ehdr(&ceh, eh);
|
||||
|
||||
//Write ELF header.
|
||||
fwrite(eh, sizeof(Elf64_Ehdr), 1, fp);
|
||||
|
||||
//Write program headers.
|
||||
Elf64_Phdr *ph = (Elf64_Phdr *)(ctxt->scebuffer + ctxt->self.selfh->phdr_offset);
|
||||
Elf64_Phdr *ph = (Elf64_Phdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->phdr_offset));
|
||||
fwrite(ph, sizeof(Elf64_Phdr), ceh.e_phnum, fp);
|
||||
|
||||
//Write program data.
|
||||
metadata_section_header_t *msh = ctxt->metash;
|
||||
for(i = 0; i < ctxt->metah->section_count; i++)
|
||||
for(i = 0; i < _ES32(ctxt->metah->section_count); i++)
|
||||
{
|
||||
if(msh[i].type == METADATA_SECTION_TYPE_PHDR)
|
||||
if(_ES32(msh[i].type) == METADATA_SECTION_TYPE_PHDR)
|
||||
{
|
||||
if(msh[i].compressed == METADATA_SECTION_COMPRESSED)
|
||||
if(_ES32(msh[i].compressed) == METADATA_SECTION_COMPRESSED)
|
||||
{
|
||||
_es_elf64_phdr(&ph[msh[i].index]);
|
||||
u8 *data = (u8 *)malloc(ph[msh[i].index].p_filesz);
|
||||
_es_elf64_phdr(&ph[_ES32(msh[i].index)]);
|
||||
u8 *data = (u8 *)malloc(ph[_ES32(msh[i].index)].p_filesz);
|
||||
|
||||
_zlib_inflate(ctxt->scebuffer + msh[i].data_offset, msh[i].data_size, data, ph[msh[i].index].p_filesz);
|
||||
fseek(fp, ph[msh[i].index].p_offset, SEEK_SET);
|
||||
fwrite(data, sizeof(u8), ph[msh[i].index].p_filesz, fp);
|
||||
_zlib_inflate(ctxt->scebuffer + _ES64(msh[i].data_offset), _ES64(msh[i].data_size), data, ph[_ES32(msh[i].index)].p_filesz);
|
||||
fseek(fp, ph[_ES32(msh[i].index)].p_offset, SEEK_SET);
|
||||
fwrite(data, sizeof(u8), ph[_ES32(msh[i].index)].p_filesz, fp);
|
||||
|
||||
free(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
_es_elf64_phdr(&ph[msh[i].index]);
|
||||
fseek(fp, ph[msh[i].index].p_offset, SEEK_SET);
|
||||
fwrite(ctxt->scebuffer + msh[i].data_offset, sizeof(u8), msh[i].data_size, fp);
|
||||
_es_elf64_phdr(&ph[_ES32(msh[i].index)]);
|
||||
fseek(fp, ph[_ES32(msh[i].index)].p_offset, SEEK_SET);
|
||||
fwrite(ctxt->scebuffer + _ES64(msh[i].data_offset), sizeof(u8), _ES64(msh[i].data_size), fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Write section headers.
|
||||
if(ctxt->self.selfh->shdr_offset != 0)
|
||||
if(_ES64(ctxt->self.selfh->shdr_offset) != 0)
|
||||
{
|
||||
Elf64_Shdr *sh = (Elf64_Shdr *)(ctxt->scebuffer + ctxt->self.selfh->shdr_offset);
|
||||
Elf64_Shdr *sh = (Elf64_Shdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->shdr_offset));
|
||||
fseek(fp, ceh.e_shoff, SEEK_SET);
|
||||
fwrite(sh, sizeof(Elf64_Shdr), ceh.e_shnum, fp);
|
||||
}
|
||||
|
@ -656,7 +656,7 @@ static u8 _static_control_digest[0x14] =
|
|||
static BOOL _create_control_infos(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
||||
{
|
||||
control_info_t *ci;
|
||||
u32 self_type = ctxt->self.ai->self_type;
|
||||
u32 self_type = _ES32(ctxt->self.ai->self_type);
|
||||
|
||||
//Step 1.
|
||||
switch(self_type)
|
||||
|
@ -671,9 +671,9 @@ static BOOL _create_control_infos(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
{
|
||||
//Add control flags.
|
||||
ci = (control_info_t *)malloc(sizeof(control_info_t) + sizeof(ci_data_flags_t));
|
||||
ci->type = CONTROL_INFO_TYPE_FLAGS;
|
||||
ci->size = sizeof(control_info_t) + sizeof(ci_data_flags_t);
|
||||
ci->next = 1;
|
||||
ci->type = _ES32(CONTROL_INFO_TYPE_FLAGS);
|
||||
ci->size = _ES32(sizeof(control_info_t) + sizeof(ci_data_flags_t));
|
||||
ci->next = _ES64(1);
|
||||
|
||||
ci_data_flags_t *cif = (ci_data_flags_t *)((u8 *)ci + sizeof(control_info_t));
|
||||
|
||||
|
@ -701,12 +701,12 @@ static BOOL _create_control_infos(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
{
|
||||
//Add digest 0x40.
|
||||
ci = (control_info_t *)malloc(sizeof(control_info_t) + sizeof(ci_data_digest_40_t));
|
||||
ci->type = CONTROL_INFO_TYPE_DIGEST;
|
||||
ci->size = sizeof(control_info_t) + sizeof(ci_data_digest_40_t);
|
||||
ci->type = _ES32(CONTROL_INFO_TYPE_DIGEST);
|
||||
ci->size = _ES32(sizeof(control_info_t) + sizeof(ci_data_digest_40_t));
|
||||
if(self_type == SELF_TYPE_NPDRM)
|
||||
ci->next = 1;
|
||||
ci->next = _ES64(1);
|
||||
else
|
||||
ci->next = 0;
|
||||
ci->next = _ES64(0);
|
||||
|
||||
ci_data_digest_40_t *cid = (ci_data_digest_40_t *)((u8 *)ci + sizeof(control_info_t));
|
||||
memcpy(cid->digest1, _static_control_digest, 0x14);
|
||||
|
@ -737,9 +737,9 @@ static BOOL _create_control_infos(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
return FALSE;
|
||||
|
||||
ci = (control_info_t *)malloc(sizeof(control_info_t) + sizeof(ci_data_npdrm_t));
|
||||
ci->type = CONTROL_INFO_TYPE_NPDRM;
|
||||
ci->size = sizeof(control_info_t) + sizeof(ci_data_npdrm_t);
|
||||
ci->next = 0;
|
||||
ci->type = _ES32(CONTROL_INFO_TYPE_NPDRM);
|
||||
ci->size = _ES32(sizeof(control_info_t) + sizeof(ci_data_npdrm_t));
|
||||
ci->next = _ES64(0);
|
||||
|
||||
ci_data_npdrm_t *cinp = (ci_data_npdrm_t *)((u8 *)ci + sizeof(control_info_t));
|
||||
|
||||
|
@ -798,7 +798,7 @@ static void _set_cap_flags(u32 self_type, oh_data_cap_flags_t *capf)
|
|||
static BOOL _create_optional_headers(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
||||
{
|
||||
opt_header_t *oh;
|
||||
u32 self_type = ctxt->self.ai->self_type;
|
||||
u32 self_type = _ES32(ctxt->self.ai->self_type);
|
||||
|
||||
//Step 1.
|
||||
switch(self_type)
|
||||
|
@ -813,12 +813,12 @@ static BOOL _create_optional_headers(sce_buffer_ctxt_t *ctxt, self_config_t *sco
|
|||
{
|
||||
//Add capability flags.
|
||||
oh = (opt_header_t *)malloc(sizeof(opt_header_t) + sizeof(oh_data_cap_flags_t));
|
||||
oh->type = OPT_HEADER_TYPE_CAP_FLAGS;
|
||||
oh->size = sizeof(opt_header_t) + sizeof(oh_data_cap_flags_t);
|
||||
oh->type = _ES32(OPT_HEADER_TYPE_CAP_FLAGS);
|
||||
oh->size = _ES32(sizeof(opt_header_t) + sizeof(oh_data_cap_flags_t));
|
||||
if(self_type == SELF_TYPE_ISO)
|
||||
oh->next = 1;
|
||||
oh->next = _ES64(1);
|
||||
else
|
||||
oh->next = 0;
|
||||
oh->next = _ES64(0);
|
||||
|
||||
oh_data_cap_flags_t *capf = (oh_data_cap_flags_t *)((u8 *)oh + sizeof(opt_header_t));
|
||||
|
||||
|
@ -840,9 +840,9 @@ static BOOL _create_optional_headers(sce_buffer_ctxt_t *ctxt, self_config_t *sco
|
|||
{
|
||||
//Add individuals seed.
|
||||
oh = (opt_header_t *)malloc(sizeof(opt_header_t) + 0x100);
|
||||
oh->type = OPT_HEADER_TYPE_INDIV_SEED;
|
||||
oh->size = sizeof(opt_header_t) + 0x100;
|
||||
oh->next = 0;
|
||||
oh->type = _ES32(OPT_HEADER_TYPE_INDIV_SEED);
|
||||
oh->size = _ES32(sizeof(opt_header_t) + 0x100);
|
||||
oh->next = _ES64(0);
|
||||
|
||||
u8 *is = (u8 *)oh + sizeof(opt_header_t);
|
||||
memset(is, 0, 0x100);
|
||||
|
@ -861,10 +861,10 @@ static BOOL _create_optional_headers(sce_buffer_ctxt_t *ctxt, self_config_t *sco
|
|||
|
||||
static void _fill_sce_version(sce_buffer_ctxt_t *ctxt)
|
||||
{
|
||||
ctxt->self.sv->header_type = SUB_HEADER_TYPE_SCEVERSION;
|
||||
ctxt->self.sv->present = SCE_VERSION_NOT_PRESENT;
|
||||
ctxt->self.sv->size = sizeof(sce_version_t);
|
||||
ctxt->self.sv->unknown_3 = 0x00000000;
|
||||
ctxt->self.sv->header_type = _ES32(SUB_HEADER_TYPE_SCEVERSION);
|
||||
ctxt->self.sv->present = _ES32(SCE_VERSION_NOT_PRESENT);
|
||||
ctxt->self.sv->size = _ES32(sizeof(sce_version_t));
|
||||
ctxt->self.sv->unknown_3 = _ES32(0x00000000);
|
||||
}
|
||||
|
||||
static void _add_phdr_section(sce_buffer_ctxt_t *ctxt, u32 p_type, u32 size, u32 idx)
|
||||
|
@ -957,7 +957,7 @@ static BOOL _build_self_32(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
i++;
|
||||
|
||||
//Metadata.
|
||||
ctxt->metah->section_count = i;
|
||||
ctxt->metah->section_count = _ES32(i);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1036,7 +1036,7 @@ static BOOL _build_self_64(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
|
||||
//Metadata.
|
||||
i -= skip;
|
||||
ctxt->metah->section_count = i;
|
||||
ctxt->metah->section_count = _ES32(i);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1046,11 +1046,11 @@ BOOL self_build_self(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
//const u8 *eident;
|
||||
|
||||
//Fill config values.
|
||||
ctxt->sceh->key_revision = sconf->key_revision;
|
||||
ctxt->self.ai->auth_id = sconf->auth_id;
|
||||
ctxt->self.ai->vendor_id = sconf->vendor_id;
|
||||
ctxt->self.ai->self_type = sconf->self_type;
|
||||
ctxt->self.ai->version = sconf->app_version;
|
||||
ctxt->sceh->key_revision = _ES16(sconf->key_revision);
|
||||
ctxt->self.ai->auth_id = _ES64(sconf->auth_id);
|
||||
ctxt->self.ai->vendor_id = _ES32(sconf->vendor_id);
|
||||
ctxt->self.ai->self_type = _ES32(sconf->self_type);
|
||||
ctxt->self.ai->version = _ES64(sconf->app_version);
|
||||
|
||||
//Create control infos.
|
||||
if(_create_control_infos(ctxt, sconf) == FALSE)
|
|
@ -38,11 +38,11 @@ void spp_print(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
u32 i;
|
||||
|
||||
//First section contains the SPP header.
|
||||
spp_header_t *header = (spp_header_t *)(ctxt->scebuffer + ctxt->metash[0].data_offset);
|
||||
spp_header_t *header = (spp_header_t *)(ctxt->scebuffer + _ES64(ctxt->metash[0].data_offset));
|
||||
_es_spp_header(header);
|
||||
|
||||
//Second section contains the entries.
|
||||
u8 *ent = ctxt->scebuffer + ctxt->metash[1].data_offset;
|
||||
u8 *ent = ctxt->scebuffer + _ES64(ctxt->metash[1].data_offset);
|
||||
|
||||
_print_spp_header(fp, header);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2013 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -15,11 +15,13 @@
|
|||
* this permanently in zconf.h using "./configure --zprefix".
|
||||
*/
|
||||
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||
# define Z_PREFIX_SET
|
||||
|
||||
/* all linked symbols */
|
||||
# define _dist_code z__dist_code
|
||||
# define _length_code z__length_code
|
||||
# define _tr_align z__tr_align
|
||||
# define _tr_flush_bits z__tr_flush_bits
|
||||
# define _tr_flush_block z__tr_flush_block
|
||||
# define _tr_init z__tr_init
|
||||
# define _tr_stored_block z__tr_stored_block
|
||||
|
@ -27,9 +29,11 @@
|
|||
# define adler32 z_adler32
|
||||
# define adler32_combine z_adler32_combine
|
||||
# define adler32_combine64 z_adler32_combine64
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# ifndef Z_SOLO
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# endif
|
||||
# define crc32 z_crc32
|
||||
# define crc32_combine z_crc32_combine
|
||||
# define crc32_combine64 z_crc32_combine64
|
||||
|
@ -40,44 +44,53 @@
|
|||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflatePending z_deflatePending
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateResetKeep z_deflateResetKeep
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateSetHeader z_deflateSetHeader
|
||||
# define deflateTune z_deflateTune
|
||||
# define deflate_copyright z_deflate_copyright
|
||||
# define get_crc_table z_get_crc_table
|
||||
# define gz_error z_gz_error
|
||||
# define gz_intmax z_gz_intmax
|
||||
# define gz_strwinerror z_gz_strwinerror
|
||||
# define gzbuffer z_gzbuffer
|
||||
# define gzclearerr z_gzclearerr
|
||||
# define gzclose z_gzclose
|
||||
# define gzclose_r z_gzclose_r
|
||||
# define gzclose_w z_gzclose_w
|
||||
# define gzdirect z_gzdirect
|
||||
# define gzdopen z_gzdopen
|
||||
# define gzeof z_gzeof
|
||||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgets z_gzgets
|
||||
# define gzoffset z_gzoffset
|
||||
# define gzoffset64 z_gzoffset64
|
||||
# define gzopen z_gzopen
|
||||
# define gzopen64 z_gzopen64
|
||||
# define gzprintf z_gzprintf
|
||||
# define gzputc z_gzputc
|
||||
# define gzputs z_gzputs
|
||||
# define gzread z_gzread
|
||||
# define gzrewind z_gzrewind
|
||||
# define gzseek z_gzseek
|
||||
# define gzseek64 z_gzseek64
|
||||
# define gzsetparams z_gzsetparams
|
||||
# define gztell z_gztell
|
||||
# define gztell64 z_gztell64
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzwrite z_gzwrite
|
||||
# ifndef Z_SOLO
|
||||
# define gz_error z_gz_error
|
||||
# define gz_intmax z_gz_intmax
|
||||
# define gz_strwinerror z_gz_strwinerror
|
||||
# define gzbuffer z_gzbuffer
|
||||
# define gzclearerr z_gzclearerr
|
||||
# define gzclose z_gzclose
|
||||
# define gzclose_r z_gzclose_r
|
||||
# define gzclose_w z_gzclose_w
|
||||
# define gzdirect z_gzdirect
|
||||
# define gzdopen z_gzdopen
|
||||
# define gzeof z_gzeof
|
||||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgetc_ z_gzgetc_
|
||||
# define gzgets z_gzgets
|
||||
# define gzoffset z_gzoffset
|
||||
# define gzoffset64 z_gzoffset64
|
||||
# define gzopen z_gzopen
|
||||
# define gzopen64 z_gzopen64
|
||||
# ifdef _WIN32
|
||||
# define gzopen_w z_gzopen_w
|
||||
# endif
|
||||
# define gzprintf z_gzprintf
|
||||
# define gzvprintf z_gzvprintf
|
||||
# define gzputc z_gzputc
|
||||
# define gzputs z_gzputs
|
||||
# define gzread z_gzread
|
||||
# define gzrewind z_gzrewind
|
||||
# define gzseek z_gzseek
|
||||
# define gzseek64 z_gzseek64
|
||||
# define gzsetparams z_gzsetparams
|
||||
# define gztell z_gztell
|
||||
# define gztell64 z_gztell64
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzwrite z_gzwrite
|
||||
# endif
|
||||
# define inflate z_inflate
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
|
@ -92,16 +105,22 @@
|
|||
# define inflateReset z_inflateReset
|
||||
# define inflateReset2 z_inflateReset2
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateGetDictionary z_inflateGetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateUndermine z_inflateUndermine
|
||||
# define inflateResetKeep z_inflateResetKeep
|
||||
# define inflate_copyright z_inflate_copyright
|
||||
# define inflate_fast z_inflate_fast
|
||||
# define inflate_table z_inflate_table
|
||||
# define uncompress z_uncompress
|
||||
# ifndef Z_SOLO
|
||||
# define uncompress z_uncompress
|
||||
# endif
|
||||
# define zError z_zError
|
||||
# define zcalloc z_zcalloc
|
||||
# define zcfree z_zcfree
|
||||
# ifndef Z_SOLO
|
||||
# define zcalloc z_zcalloc
|
||||
# define zcfree z_zcfree
|
||||
# endif
|
||||
# define zlibCompileFlags z_zlibCompileFlags
|
||||
# define zlibVersion z_zlibVersion
|
||||
|
||||
|
@ -111,7 +130,9 @@
|
|||
# define alloc_func z_alloc_func
|
||||
# define charf z_charf
|
||||
# define free_func z_free_func
|
||||
# define gzFile z_gzFile
|
||||
# ifndef Z_SOLO
|
||||
# define gzFile z_gzFile
|
||||
# endif
|
||||
# define gz_header z_gz_header
|
||||
# define gz_headerp z_gz_headerp
|
||||
# define in_func z_in_func
|
||||
|
@ -197,6 +218,12 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(ZLIB_CONST) && !defined(z_const)
|
||||
# define z_const const
|
||||
#else
|
||||
# define z_const
|
||||
#endif
|
||||
|
||||
/* Some Mac compilers merge all .h files incorrectly: */
|
||||
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
||||
# define NO_DUMMY_DECL
|
||||
|
@ -243,6 +270,14 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef Z_ARG /* function prototypes for stdarg */
|
||||
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# define Z_ARG(args) args
|
||||
# else
|
||||
# define Z_ARG(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
|
@ -356,12 +391,47 @@ typedef uLong FAR uLongf;
|
|||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
|
||||
# include <limits.h>
|
||||
# if (UINT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned
|
||||
# elif (ULONG_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned long
|
||||
# elif (USHRT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned short
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef Z_U4
|
||||
typedef Z_U4 z_crc_t;
|
||||
#else
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_STDARG_H
|
||||
#endif
|
||||
|
||||
#ifdef STDC
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# ifndef Z_SOLO
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifndef Z_SOLO
|
||||
# include <stdarg.h> /* for va_list */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef Z_SOLO
|
||||
# include <stddef.h> /* for wchar_t */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
|
@ -370,21 +440,38 @@ typedef uLong FAR uLongf;
|
|||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if -_LARGEFILE64_SOURCE - -1 == 1
|
||||
#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
#ifndef Z_SOLO
|
||||
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
|
||||
# define Z_LFS64
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
|
||||
# define Z_LARGE64
|
||||
#endif
|
||||
|
||||
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
|
||||
# define Z_WANT64
|
||||
#endif
|
||||
|
||||
#if !defined(SEEK_SET) && !defined(Z_SOLO)
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
|
@ -394,18 +481,14 @@ typedef uLong FAR uLongf;
|
|||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# define z_off64_t z_off_t
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__)
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
|
||||
# define z_off64_t __int64
|
||||
# else
|
||||
# define z_off64_t z_off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
|
@ -1,7 +1,7 @@
|
|||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.2.5, April 19th, 2010
|
||||
version 1.2.8, April 28th, 2013
|
||||
|
||||
Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
|
||||
Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@ -24,8 +24,8 @@
|
|||
|
||||
|
||||
The data format used by the zlib library is described by RFCs (Request for
|
||||
Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
|
||||
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||
Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
|
||||
(zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
|
||||
*/
|
||||
|
||||
#ifndef ZLIB_H
|
||||
|
@ -37,11 +37,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZLIB_VERSION "1.2.5"
|
||||
#define ZLIB_VERNUM 0x1250
|
||||
#define ZLIB_VERSION "1.2.8"
|
||||
#define ZLIB_VERNUM 0x1280
|
||||
#define ZLIB_VER_MAJOR 1
|
||||
#define ZLIB_VER_MINOR 2
|
||||
#define ZLIB_VER_REVISION 5
|
||||
#define ZLIB_VER_REVISION 8
|
||||
#define ZLIB_VER_SUBREVISION 0
|
||||
|
||||
/*
|
||||
|
@ -83,15 +83,15 @@ typedef void (*free_func) OF((voidpf opaque, voidpf address));
|
|||
struct internal_state;
|
||||
|
||||
typedef struct z_stream_s {
|
||||
Bytef *next_in; /* next input byte */
|
||||
z_const Bytef *next_in; /* next input byte */
|
||||
uInt avail_in; /* number of bytes available at next_in */
|
||||
uLong total_in; /* total nb of input bytes read so far */
|
||||
uLong total_in; /* total number of input bytes read so far */
|
||||
|
||||
Bytef *next_out; /* next output byte should be put there */
|
||||
uInt avail_out; /* remaining free space at next_out */
|
||||
uLong total_out; /* total nb of bytes output so far */
|
||||
uLong total_out; /* total number of bytes output so far */
|
||||
|
||||
char *msg; /* last error message, NULL if no error */
|
||||
z_const char *msg; /* last error message, NULL if no error */
|
||||
struct internal_state FAR *state; /* not visible by applications */
|
||||
|
||||
alloc_func zalloc; /* used to allocate the internal state */
|
||||
|
@ -327,8 +327,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
|||
|
||||
Z_FINISH can be used immediately after deflateInit if all the compression
|
||||
is to be done in a single step. In this case, avail_out must be at least the
|
||||
value returned by deflateBound (see below). If deflate does not return
|
||||
Z_STREAM_END, then it must be called again as described above.
|
||||
value returned by deflateBound (see below). Then deflate is guaranteed to
|
||||
return Z_STREAM_END. If not enough output space is provided, deflate will
|
||||
not return Z_STREAM_END, and it must be called again as described above.
|
||||
|
||||
deflate() sets strm->adler to the adler32 checksum of all input read
|
||||
so far (that is, total_in bytes).
|
||||
|
@ -451,23 +452,29 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
|||
error. However if all decompression is to be performed in a single step (a
|
||||
single call of inflate), the parameter flush should be set to Z_FINISH. In
|
||||
this case all pending input is processed and all pending output is flushed;
|
||||
avail_out must be large enough to hold all the uncompressed data. (The size
|
||||
of the uncompressed data may have been saved by the compressor for this
|
||||
purpose.) The next operation on this stream must be inflateEnd to deallocate
|
||||
the decompression state. The use of Z_FINISH is never required, but can be
|
||||
used to inform inflate that a faster approach may be used for the single
|
||||
inflate() call.
|
||||
avail_out must be large enough to hold all of the uncompressed data for the
|
||||
operation to complete. (The size of the uncompressed data may have been
|
||||
saved by the compressor for this purpose.) The use of Z_FINISH is not
|
||||
required to perform an inflation in one step. However it may be used to
|
||||
inform inflate that a faster approach can be used for the single inflate()
|
||||
call. Z_FINISH also informs inflate to not maintain a sliding window if the
|
||||
stream completes, which reduces inflate's memory footprint. If the stream
|
||||
does not complete, either because not all of the stream is provided or not
|
||||
enough output space is provided, then a sliding window will be allocated and
|
||||
inflate() can be called again to continue the operation as if Z_NO_FLUSH had
|
||||
been used.
|
||||
|
||||
In this implementation, inflate() always flushes as much output as
|
||||
possible to the output buffer, and always uses the faster approach on the
|
||||
first call. So the only effect of the flush parameter in this implementation
|
||||
is on the return value of inflate(), as noted below, or when it returns early
|
||||
because Z_BLOCK or Z_TREES is used.
|
||||
first call. So the effects of the flush parameter in this implementation are
|
||||
on the return value of inflate() as noted below, when inflate() returns early
|
||||
when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
|
||||
memory for a sliding window when Z_FINISH is used.
|
||||
|
||||
If a preset dictionary is needed after this call (see inflateSetDictionary
|
||||
below), inflate sets strm->adler to the adler32 checksum of the dictionary
|
||||
below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
|
||||
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
|
||||
strm->adler to the adler32 checksum of all output produced so far (that is,
|
||||
strm->adler to the Adler-32 checksum of all output produced so far (that is,
|
||||
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
|
||||
below. At the end of the stream, inflate() checks that its computed adler32
|
||||
checksum is equal to that saved by the compressor and returns Z_STREAM_END
|
||||
|
@ -478,7 +485,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
|||
initializing with inflateInit2(). Any information contained in the gzip
|
||||
header is not retained, so applications that need that information should
|
||||
instead use raw inflate, see inflateInit2() below, or inflateBack() and
|
||||
perform their own processing of the gzip header and trailer.
|
||||
perform their own processing of the gzip header and trailer. When processing
|
||||
gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
|
||||
producted so far. The CRC-32 is checked against the gzip trailer.
|
||||
|
||||
inflate() returns Z_OK if some progress has been made (more input processed
|
||||
or more output produced), Z_STREAM_END if the end of the compressed data has
|
||||
|
@ -580,10 +589,15 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
|||
uInt dictLength));
|
||||
/*
|
||||
Initializes the compression dictionary from the given byte sequence
|
||||
without producing any compressed output. This function must be called
|
||||
immediately after deflateInit, deflateInit2 or deflateReset, before any call
|
||||
of deflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see inflateSetDictionary).
|
||||
without producing any compressed output. When using the zlib format, this
|
||||
function must be called immediately after deflateInit, deflateInit2 or
|
||||
deflateReset, and before any call of deflate. When doing raw deflate, this
|
||||
function must be called either before any call of deflate, or immediately
|
||||
after the completion of a deflate block, i.e. after all input has been
|
||||
consumed and all output has been delivered when using any of the flush
|
||||
options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
|
||||
compressor and decompressor must use exactly the same dictionary (see
|
||||
inflateSetDictionary).
|
||||
|
||||
The dictionary should consist of strings (byte sequences) that are likely
|
||||
to be encountered later in the data to be compressed, with the most commonly
|
||||
|
@ -610,8 +624,8 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
|||
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
|
||||
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
|
||||
inconsistent (for example if deflate has already been called for this stream
|
||||
or if the compression method is bsort). deflateSetDictionary does not
|
||||
perform any compression: this will be done by deflate().
|
||||
or if not at a block boundary for raw deflate). deflateSetDictionary does
|
||||
not perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
|
||||
|
@ -688,9 +702,29 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
|
|||
deflation of sourceLen bytes. It must be called after deflateInit() or
|
||||
deflateInit2(), and after deflateSetHeader(), if used. This would be used
|
||||
to allocate an output buffer for deflation in a single pass, and so would be
|
||||
called before deflate().
|
||||
called before deflate(). If that first deflate() call is provided the
|
||||
sourceLen input bytes, an output buffer allocated to the size returned by
|
||||
deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
|
||||
to return Z_STREAM_END. Note that it is possible for the compressed size to
|
||||
be larger than the value returned by deflateBound() if flush options other
|
||||
than Z_FINISH or Z_NO_FLUSH are used.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
|
||||
unsigned *pending,
|
||||
int *bits));
|
||||
/*
|
||||
deflatePending() returns the number of bytes and bits of output that have
|
||||
been generated, but not yet provided in the available output. The bytes not
|
||||
provided would be due to the available output space having being consumed.
|
||||
The number of bits of output not provided are between 0 and 7, where they
|
||||
await more bits to join them in order to fill out a full byte. If pending
|
||||
or bits are Z_NULL, then those values are not set.
|
||||
|
||||
deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
|
||||
int bits,
|
||||
int value));
|
||||
|
@ -703,8 +737,9 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
|
|||
than or equal to 16, and that many of the least significant bits of value
|
||||
will be inserted in the output.
|
||||
|
||||
deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent.
|
||||
deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
|
||||
room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
|
||||
source stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
|
||||
|
@ -790,10 +825,11 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
|||
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||
can be determined from the adler32 value returned by that call of inflate.
|
||||
The compressor and decompressor must use exactly the same dictionary (see
|
||||
deflateSetDictionary). For raw inflate, this function can be called
|
||||
immediately after inflateInit2() or inflateReset() and before any call of
|
||||
inflate() to set the dictionary. The application must insure that the
|
||||
dictionary that was used for compression is provided.
|
||||
deflateSetDictionary). For raw inflate, this function can be called at any
|
||||
time to set the dictionary. If the provided dictionary is smaller than the
|
||||
window and there is already data in the window, then the provided dictionary
|
||||
will amend what's there. The application must insure that the dictionary
|
||||
that was used for compression is provided.
|
||||
|
||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
|
||||
|
@ -803,19 +839,38 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
|||
inflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm,
|
||||
Bytef *dictionary,
|
||||
uInt *dictLength));
|
||||
/*
|
||||
Returns the sliding dictionary being maintained by inflate. dictLength is
|
||||
set to the number of bytes in the dictionary, and that many bytes are copied
|
||||
to dictionary. dictionary must have enough space, where 32768 bytes is
|
||||
always enough. If inflateGetDictionary() is called with dictionary equal to
|
||||
Z_NULL, then only the dictionary length is returned, and nothing is copied.
|
||||
Similary, if dictLength is Z_NULL, then it is not set.
|
||||
|
||||
inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
|
||||
stream state is inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
|
||||
/*
|
||||
Skips invalid compressed data until a full flush point (see above the
|
||||
description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
Skips invalid compressed data until a possible full flush point (see above
|
||||
for the description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
available input is skipped. No output is provided.
|
||||
|
||||
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
|
||||
if no more input was provided, Z_DATA_ERROR if no flush point has been
|
||||
found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the
|
||||
success case, the application may save the current current value of total_in
|
||||
which indicates where valid compressed data was found. In the error case,
|
||||
the application may repeatedly call inflateSync, providing more input each
|
||||
time, until success or end of the input data.
|
||||
inflateSync searches for a 00 00 FF FF pattern in the compressed data.
|
||||
All full flush points have this pattern, but not all occurrences of this
|
||||
pattern are full flush points.
|
||||
|
||||
inflateSync returns Z_OK if a possible full flush point has been found,
|
||||
Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
|
||||
has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
|
||||
In the success case, the application may save the current current value of
|
||||
total_in which indicates where valid compressed data was found. In the
|
||||
error case, the application may repeatedly call inflateSync, providing more
|
||||
input each time, until success or end of the input data.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
|
||||
|
@ -962,12 +1017,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
|
|||
See inflateBack() for the usage of these routines.
|
||||
|
||||
inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
|
||||
the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
|
||||
the parameters are invalid, Z_MEM_ERROR if the internal state could not be
|
||||
allocated, or Z_VERSION_ERROR if the version of the library does not match
|
||||
the version of the header file.
|
||||
*/
|
||||
|
||||
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
|
||||
typedef unsigned (*in_func) OF((void FAR *,
|
||||
z_const unsigned char FAR * FAR *));
|
||||
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
|
||||
|
||||
ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
|
||||
|
@ -975,11 +1031,12 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
|
|||
out_func out, void FAR *out_desc));
|
||||
/*
|
||||
inflateBack() does a raw inflate with a single call using a call-back
|
||||
interface for input and output. This is more efficient than inflate() for
|
||||
file i/o applications in that it avoids copying between the output and the
|
||||
sliding window by simply making the window itself the output buffer. This
|
||||
function trusts the application to not change the output buffer passed by
|
||||
the output function, at least until inflateBack() returns.
|
||||
interface for input and output. This is potentially more efficient than
|
||||
inflate() for file i/o applications, in that it avoids copying between the
|
||||
output and the sliding window by simply making the window itself the output
|
||||
buffer. inflate() can be faster on modern CPUs when used with large
|
||||
buffers. inflateBack() trusts the application to not change the output
|
||||
buffer passed by the output function, at least until inflateBack() returns.
|
||||
|
||||
inflateBackInit() must be called first to allocate the internal state
|
||||
and to initialize the state with the user-provided window buffer.
|
||||
|
@ -1088,6 +1145,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
|
|||
27-31: 0 (reserved)
|
||||
*/
|
||||
|
||||
#ifndef Z_SOLO
|
||||
|
||||
/* utility functions */
|
||||
|
||||
|
@ -1149,10 +1207,11 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
|||
|
||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
|
||||
the case where there is not enough room, uncompress() will fill the output
|
||||
buffer with the uncompressed data up to that point.
|
||||
*/
|
||||
|
||||
|
||||
/* gzip file access functions */
|
||||
|
||||
/*
|
||||
|
@ -1162,7 +1221,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
|||
wrapper, documented in RFC 1952, wrapped around a deflate stream.
|
||||
*/
|
||||
|
||||
typedef voidp gzFile; /* opaque gzip file descriptor */
|
||||
typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
|
||||
|
||||
/*
|
||||
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
|
||||
|
@ -1172,13 +1231,28 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
|
|||
a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
|
||||
compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
|
||||
for fixed code compression as in "wb9F". (See the description of
|
||||
deflateInit2 for more information about the strategy parameter.) Also "a"
|
||||
can be used instead of "w" to request that the gzip stream that will be
|
||||
written be appended to the file. "+" will result in an error, since reading
|
||||
and writing to the same gzip file is not supported.
|
||||
deflateInit2 for more information about the strategy parameter.) 'T' will
|
||||
request transparent writing or appending with no compression and not using
|
||||
the gzip format.
|
||||
|
||||
"a" can be used instead of "w" to request that the gzip stream that will
|
||||
be written be appended to the file. "+" will result in an error, since
|
||||
reading and writing to the same gzip file is not supported. The addition of
|
||||
"x" when writing will create the file exclusively, which fails if the file
|
||||
already exists. On systems that support it, the addition of "e" when
|
||||
reading or writing will set the flag to close the file on an execve() call.
|
||||
|
||||
These functions, as well as gzip, will read and decode a sequence of gzip
|
||||
streams in a file. The append function of gzopen() can be used to create
|
||||
such a file. (Also see gzflush() for another way to do this.) When
|
||||
appending, gzopen does not test whether the file begins with a gzip stream,
|
||||
nor does it look for the end of the gzip streams to begin appending. gzopen
|
||||
will simply append a gzip stream to the existing file.
|
||||
|
||||
gzopen can be used to read a file which is not in gzip format; in this
|
||||
case gzread will directly read from the file without decompression.
|
||||
case gzread will directly read from the file without decompression. When
|
||||
reading, this will be detected automatically by looking for the magic two-
|
||||
byte gzip header.
|
||||
|
||||
gzopen returns NULL if the file could not be opened, if there was
|
||||
insufficient memory to allocate the gzFile state, or if an invalid mode was
|
||||
|
@ -1197,7 +1271,11 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
|
|||
descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
|
||||
fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
|
||||
mode);. The duplicated descriptor should be saved to avoid a leak, since
|
||||
gzdopen does not close fd if it fails.
|
||||
gzdopen does not close fd if it fails. If you are using fileno() to get the
|
||||
file descriptor from a FILE *, then you will have to use dup() to avoid
|
||||
double-close()ing the file descriptor. Both gzclose() and fclose() will
|
||||
close the associated file descriptor, so they need to have different file
|
||||
descriptors.
|
||||
|
||||
gzdopen returns NULL if there was insufficient memory to allocate the
|
||||
gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
|
||||
|
@ -1235,14 +1313,26 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
|
|||
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
/*
|
||||
Reads the given number of uncompressed bytes from the compressed file. If
|
||||
the input file was not in gzip format, gzread copies the given number of
|
||||
bytes into the buffer.
|
||||
the input file is not in gzip format, gzread copies the given number of
|
||||
bytes into the buffer directly from the file.
|
||||
|
||||
After reaching the end of a gzip stream in the input, gzread will continue
|
||||
to read, looking for another gzip stream, or failing that, reading the rest
|
||||
of the input file directly without decompression. The entire input file
|
||||
will be read if gzread is called until it returns less than the requested
|
||||
len.
|
||||
to read, looking for another gzip stream. Any number of gzip streams may be
|
||||
concatenated in the input file, and will all be decompressed by gzread().
|
||||
If something other than a gzip stream is encountered after a gzip stream,
|
||||
that remaining trailing garbage is ignored (and no error is returned).
|
||||
|
||||
gzread can be used to read a gzip file that is being concurrently written.
|
||||
Upon reaching the end of the input, gzread will return with the available
|
||||
data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
|
||||
gzclearerr can be used to clear the end of file indicator in order to permit
|
||||
gzread to be tried again. Z_OK indicates that a gzip stream was completed
|
||||
on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
|
||||
middle of a gzip stream. Note that gzread does not return -1 in the event
|
||||
of an incomplete gzip stream. This error is deferred until gzclose(), which
|
||||
will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
|
||||
stream. Alternatively, gzerror can be used before gzclose to detect this
|
||||
case.
|
||||
|
||||
gzread returns the number of uncompressed bytes actually read, less than
|
||||
len for end of file, or -1 for error.
|
||||
|
@ -1256,7 +1346,7 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
|
|||
error.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
|
||||
ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
|
||||
/*
|
||||
Converts, formats, and writes the arguments to the compressed file under
|
||||
control of the format string, as in fprintf. gzprintf returns the number of
|
||||
|
@ -1301,7 +1391,10 @@ ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
|
|||
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
|
||||
/*
|
||||
Reads one byte from the compressed file. gzgetc returns this byte or -1
|
||||
in case of end of file or error.
|
||||
in case of end of file or error. This is implemented as a macro for speed.
|
||||
As such, it does not do all of the checking the other functions do. I.e.
|
||||
it does not check to see if file is NULL, nor whether the structure file
|
||||
points to has been clobbered or not.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
|
||||
|
@ -1397,9 +1490,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
|
|||
ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
|
||||
/*
|
||||
Returns true (1) if file is being copied directly while reading, or false
|
||||
(0) if file is a gzip stream being decompressed. This state can change from
|
||||
false to true while reading the input file if the end of a gzip stream is
|
||||
reached, but is followed by data that is not another gzip stream.
|
||||
(0) if file is a gzip stream being decompressed.
|
||||
|
||||
If the input file is empty, gzdirect() will return true, since the input
|
||||
does not contain a gzip stream.
|
||||
|
@ -1408,6 +1499,13 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
|
|||
cause buffers to be allocated to allow reading the file to determine if it
|
||||
is a gzip file. Therefore if gzbuffer() is used, it should be called before
|
||||
gzdirect().
|
||||
|
||||
When writing, gzdirect() returns true (1) if transparent writing was
|
||||
requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
|
||||
gzdirect() is not needed when writing. Transparent writing must be
|
||||
explicitly requested, so the application already knows the answer. When
|
||||
linking statically, using gzdirect() will include all of the zlib code for
|
||||
gzip file reading and decompression, which may not be desired.)
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
||||
|
@ -1419,7 +1517,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
|||
must not be called more than once on the same allocation.
|
||||
|
||||
gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
|
||||
file operation error, or Z_OK on success.
|
||||
file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
|
||||
last read ended in the middle of a gzip stream, or Z_OK on success.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
|
||||
|
@ -1457,6 +1556,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
|
|||
file that is being written concurrently.
|
||||
*/
|
||||
|
||||
#endif /* !Z_SOLO */
|
||||
|
||||
/* checksum functions */
|
||||
|
||||
|
@ -1492,16 +1592,17 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
|
|||
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
|
||||
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
|
||||
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
|
||||
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
|
||||
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
|
||||
that the z_off_t type (like off_t) is a signed integer. If len2 is
|
||||
negative, the result has no meaning or utility.
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
/*
|
||||
Update a running CRC-32 with the bytes buf[0..len-1] and return the
|
||||
updated CRC-32. If buf is Z_NULL, this function returns the required
|
||||
initial value for the for the crc. Pre- and post-conditioning (one's
|
||||
complement) is performed within this function so it shouldn't be done by the
|
||||
application.
|
||||
initial value for the crc. Pre- and post-conditioning (one's complement) is
|
||||
performed within this function so it shouldn't be done by the application.
|
||||
|
||||
Usage example:
|
||||
|
||||
|
@ -1544,17 +1645,42 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
const char *version,
|
||||
int stream_size));
|
||||
#define deflateInit(strm, level) \
|
||||
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
||||
deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
|
||||
#define inflateInit(strm) \
|
||||
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
||||
inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
|
||||
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
|
||||
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
|
||||
(strategy), ZLIB_VERSION, sizeof(z_stream))
|
||||
(strategy), ZLIB_VERSION, (int)sizeof(z_stream))
|
||||
#define inflateInit2(strm, windowBits) \
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
|
||||
(int)sizeof(z_stream))
|
||||
#define inflateBackInit(strm, windowBits, window) \
|
||||
inflateBackInit_((strm), (windowBits), (window), \
|
||||
ZLIB_VERSION, sizeof(z_stream))
|
||||
ZLIB_VERSION, (int)sizeof(z_stream))
|
||||
|
||||
#ifndef Z_SOLO
|
||||
|
||||
/* gzgetc() macro and its supporting function and exposed data structure. Note
|
||||
* that the real internal state is much larger than the exposed structure.
|
||||
* This abbreviated structure exposes just enough for the gzgetc() macro. The
|
||||
* user should not mess with these exposed elements, since their names or
|
||||
* behavior could change in the future, perhaps even capriciously. They can
|
||||
* only be used by the gzgetc() macro. You have been warned.
|
||||
*/
|
||||
struct gzFile_s {
|
||||
unsigned have;
|
||||
unsigned char *next;
|
||||
z_off64_t pos;
|
||||
};
|
||||
ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
|
||||
#ifdef Z_PREFIX_SET
|
||||
# undef z_gzgetc
|
||||
# define z_gzgetc(g) \
|
||||
((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
|
||||
#else
|
||||
# define gzgetc(g) \
|
||||
((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
|
||||
#endif
|
||||
|
||||
/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
|
||||
* change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
|
||||
|
@ -1562,7 +1688,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
* functions are changed to 64 bits) -- in case these are set on systems
|
||||
* without large file support, _LFS64_LARGEFILE must also be true
|
||||
*/
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
#ifdef Z_LARGE64
|
||||
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
||||
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
|
||||
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
|
||||
|
@ -1571,14 +1697,23 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
|
||||
#endif
|
||||
|
||||
#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0
|
||||
# define gzopen gzopen64
|
||||
# define gzseek gzseek64
|
||||
# define gztell gztell64
|
||||
# define gzoffset gzoffset64
|
||||
# define adler32_combine adler32_combine64
|
||||
# define crc32_combine crc32_combine64
|
||||
# ifdef _LARGEFILE64_SOURCE
|
||||
#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
|
||||
# ifdef Z_PREFIX_SET
|
||||
# define z_gzopen z_gzopen64
|
||||
# define z_gzseek z_gzseek64
|
||||
# define z_gztell z_gztell64
|
||||
# define z_gzoffset z_gzoffset64
|
||||
# define z_adler32_combine z_adler32_combine64
|
||||
# define z_crc32_combine z_crc32_combine64
|
||||
# else
|
||||
# define gzopen gzopen64
|
||||
# define gzseek gzseek64
|
||||
# define gztell gztell64
|
||||
# define gzoffset gzoffset64
|
||||
# define adler32_combine adler32_combine64
|
||||
# define crc32_combine crc32_combine64
|
||||
# endif
|
||||
# ifndef Z_LARGE64
|
||||
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
||||
ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
|
||||
ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
|
||||
|
@ -1595,6 +1730,13 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
|
||||
#endif
|
||||
|
||||
#else /* Z_SOLO */
|
||||
|
||||
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
|
||||
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
|
||||
|
||||
#endif /* !Z_SOLO */
|
||||
|
||||
/* hack for buggy compilers */
|
||||
#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
|
||||
struct internal_state {int dummy;};
|
||||
|
@ -1603,8 +1745,21 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
|||
/* undocumented functions */
|
||||
ZEXTERN const char * ZEXPORT zError OF((int));
|
||||
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
|
||||
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
|
||||
ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
|
||||
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
|
||||
ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
|
||||
ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
|
||||
#if defined(_WIN32) && !defined(Z_SOLO)
|
||||
ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
|
||||
const char *mode));
|
||||
#endif
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifndef Z_SOLO
|
||||
ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file,
|
||||
const char *format,
|
||||
va_list va));
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
2
zlib/Readme
Normal file
2
zlib/Readme
Normal file
|
@ -0,0 +1,2 @@
|
|||
Take both .lib files and put it to Visual_Studio installation folder\VC\lib\
|
||||
or compile it yourself from the official source code (http://zlib.net/zlib-1.2.8.tar.gz)
|
BIN
zlib/zlib.lib
Normal file
BIN
zlib/zlib.lib
Normal file
Binary file not shown.
BIN
zlib/zlibd.lib
Normal file
BIN
zlib/zlibd.lib
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue