Skip to content

Commit

Permalink
Initiale
Browse files Browse the repository at this point in the history
Initiale release
  • Loading branch information
cfwprpht committed Jun 29, 2018
1 parent 6f8c8ab commit 75618b3
Show file tree
Hide file tree
Showing 12 changed files with 1,749 additions and 0 deletions.
Binary file added .vs/PSFSKKey/v14/.suo
Binary file not shown.
Binary file added .vs/PSFSKKey/v15/.suo
Binary file not shown.
Empty file.
Binary file added .vs/PSFSKKey/v15/Server/sqlite3/storage.ide
Binary file not shown.
6 changes: 6 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
79 changes: 79 additions & 0 deletions PSFSKKey.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2537FD87-B266-4F5C-935C-461B0FD4270C}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>PSFSKKey</RootNamespace>
<AssemblyName>PSFSKKey</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="savedatamasterhashkey1.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="savedatamasterhashkey2.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="savedatamasterhashkey3.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="savedatamasterhashkey4.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="savedatamasterkey1.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="savedatamasterkey2.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="savedatamasterkey3.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="savedatamasterkey4.bin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="TextFile1.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
9 changes: 9 additions & 0 deletions PSFSKKey.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>SAVEDATA00.bin SAVEDATA00</StartArguments>
</PropertyGroup>
</Project>
25 changes: 25 additions & 0 deletions PSFSKKey.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2024
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSFSKKey", "PSFSKKey.csproj", "{2537FD87-B266-4F5C-935C-461B0FD4270C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2537FD87-B266-4F5C-935C-461B0FD4270C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2537FD87-B266-4F5C-935C-461B0FD4270C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2537FD87-B266-4F5C-935C-461B0FD4270C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2537FD87-B266-4F5C-935C-461B0FD4270C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F3EEDE11-8166-4FB3-920E-89817CA62B53}
EndGlobalSection
EndGlobal
152 changes: 152 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace PSFSKKey
{
class Program
{
private static bool sceSblSsMemcmpConsttime(byte[] a, byte[] b, int len, int offsetA = 0, int offsetB = 0)
{
for (int i = 0; i < len; i++)
{
if (a[i + offsetA] != b[i + offsetB])
return false;
}

return true;
}

private static bool sceSblSsMemcmpConsttime(byte[] a, string b, int len, int offsetA = 0)
{
return ASCIIEncoding.ASCII.GetString(a, offsetA, len) == b;
}

private static void sceSblSsMemset(byte[] buffer, byte val, int len)
{
for (int i = 0; i < len; i++)
{
buffer[i] = val;
}
}


private static void Sha256Hmac(byte[] sha256HmacResult, byte[] enc, int datalen, byte[] sha256hmacKey, int keylen)
{
using (HMACSHA256 hmac = new HMACSHA256(sha256hmacKey))
{
var result = hmac.ComputeHash(enc, 0, datalen);
Buffer.BlockCopy(result, 0, sha256HmacResult, 0, sha256HmacResult.Length);
}
}

private static long sceSblSsDecryptSealedKey(byte[] enc, byte[] dec)
{
long errorCode = -2146499562;

if (enc != null && dec != null)
{
errorCode = -2146499532;
if (sceSblSsMemcmpConsttime(enc, "pfsSKKey", 8))
{
errorCode = -2146499538;
byte[] sha256hmacKey = new byte[16];
short keyVersion = (short) enc[8];
Console.WriteLine("Usering Keyset Version {0}", keyVersion);
var allKeybytes = File.ReadAllBytes(string.Format("savedatamasterhashkey{0}.bin", keyVersion));
Buffer.BlockCopy(allKeybytes, 0, sha256hmacKey, 0, 16);

byte[] sha256HmacResult = new byte[32];
Sha256Hmac(sha256HmacResult, enc, 0x40, sha256hmacKey, 0x10);
errorCode = -2146499531;
if (sceSblSsMemcmpConsttime(sha256HmacResult, enc, 32, 0, 64))
{
Console.WriteLine("HMAC Check... Success!");
byte[] iv = new byte[16];
Buffer.BlockCopy(enc, 16, iv, 0, iv.Length);

byte[] encryptedKey = new byte[32];
Buffer.BlockCopy(enc, 32, encryptedKey, 0, 32);

using (AesManaged aes = new AesManaged())
{
byte[] aesKey = new byte[16];
allKeybytes = File.ReadAllBytes(string.Format("savedatamasterkey{0}.bin", keyVersion));
Buffer.BlockCopy(allKeybytes, 0, aesKey, 0, 16);

aes.Mode = CipherMode.CBC;
aes.IV = iv;
aes.KeySize = 128;
aes.Key = aesKey;
aes.Padding = PaddingMode.None;
var stream = new MemoryStream();
using (var decryptor = aes.CreateDecryptor())
{
using (var cryptoStream = new CryptoStream(stream, decryptor, CryptoStreamMode.Write))
{
using (var writer = new BinaryWriter(cryptoStream))
{
writer.Write(encryptedKey);
}
}
}
byte[] cipherBytes = stream.ToArray();
Buffer.BlockCopy(cipherBytes, 0, dec, 0, 32);
}
errorCode = 0;
}
else
{
Console.WriteLine("HMAC Check... Failure!");
}
}
}

return errorCode;
}

static void Main(string[] args)
{
var bytes = File.ReadAllBytes(args[0]);
byte[] dec = new byte[32];
sceSblSsDecryptSealedKey(bytes, dec);

Console.WriteLine("Your PFS Key is {0}", BitConverter.ToString(dec).Replace("-", string.Empty));

var save = File.ReadAllBytes(args[1]);
byte[] iv = new byte[16];
Buffer.BlockCopy(bytes, 16, iv, 0, iv.Length);

// TODO Reverse SAMU for Decryption of PFS File System
/* using (AesManaged aes = new AesManaged())
{
aes.Mode = CipherMode.CBC;
aes.IV = iv;
aes.KeySize = 256;
aes.Key = dec;
aes.Padding = PaddingMode.None;
var stream = new MemoryStream();
using (var decryptor = aes.CreateDecryptor())
{
using (var cryptoStream = new CryptoStream(stream, decryptor, CryptoStreamMode.Write))
{
using (var writer = new BinaryWriter(cryptoStream))
{
writer.Write(save);
}
}
}
byte[] cipherBytes = stream.ToArray();
Console.WriteLine("PFS Save Content:");
Console.WriteLine(UTF8Encoding.UTF8.GetString(cipherBytes));
}*/

Console.ReadLine();
}
}
}
36 changes: 36 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PSFSKKey")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PSFSKKey")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2537fd87-b266-4f5c-935c-461b0fd4270c")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 75618b3

Please sign in to comment.