Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
sonik-br authored Jan 7, 2021
1 parent 3724028 commit 7f68bac
Show file tree
Hide file tree
Showing 40 changed files with 6,767 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/PS4RPI.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 Version 16
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PS4RPI", "PS4RPI\PS4RPI.csproj", "{A3202050-1A7E-4BB3-88BE-25E2F1641C15}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A3202050-1A7E-4BB3-88BE-25E2F1641C15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3202050-1A7E-4BB3-88BE-25E2F1641C15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3202050-1A7E-4BB3-88BE-25E2F1641C15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3202050-1A7E-4BB3-88BE-25E2F1641C15}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D9F7AA4E-648E-4E3A-82FD-D48A13508BF6}
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions src/PS4RPI/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="PS4RPI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PS4RPI"
Startup="Application_Startup">
<Application.Resources>

</Application.Resources>
</Application>
21 changes: 21 additions & 0 deletions src/PS4RPI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace PS4RPI
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
new MainWindow(e.Args).Show();
}
}
}
10 changes: 10 additions & 0 deletions src/PS4RPI/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
19 changes: 19 additions & 0 deletions src/PS4RPI/Converter/BoolToInverseBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace PS4RPI.Converter
{
public class BoolToInverseBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return !(bool)value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return !(bool)value;
}
}
}
20 changes: 20 additions & 0 deletions src/PS4RPI/Converter/ByteSizeToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace PS4RPI.Converter
{
class ByteSizeToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var bsize = (ByteSizeLib.ByteSize)value;
return bsize.ToBinaryString();
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
19 changes: 19 additions & 0 deletions src/PS4RPI/Converter/NotNullToBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace PS4RPI.Converter
{
class NotNullToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
67 changes: 67 additions & 0 deletions src/PS4RPI/LibOrbis/PKG/Entry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//Code adapted from https://github.com/xXxTheDarkprogramerxXx/PS4_Tools

using System.Collections.Generic;
using System.IO;
using PS4_Tools.LibOrbis.Util;

namespace PS4_Tools.LibOrbis.PKG
{
// Represents the data of an entry
public abstract class Entry
{
public abstract EntryId Id { get; }
public abstract uint Length { get; }
public abstract string Name { get; }
//public abstract void Write(Stream s);
public MetaEntry meta;
}

/// <summary>
/// The representation of an entry in the PKG entry table.
/// </summary>
public class MetaEntry
{
public EntryId id;
public uint NameTableOffset;
public uint Flags1;
public uint Flags2;
public uint DataOffset;
public uint DataSize;
// public ulong Pad; // zero-pad

public static MetaEntry Read(Stream s)
{
var ret = new MetaEntry();
ret.id = (EntryId)s.ReadUInt32BE();
ret.NameTableOffset = s.ReadUInt32BE();
ret.Flags1 = s.ReadUInt32BE();
ret.Flags2 = s.ReadUInt32BE();
ret.DataOffset = s.ReadUInt32BE();
ret.DataSize = s.ReadUInt32BE();
s.Position += 8;
return ret;
}
}

public class SfoEntry : Entry
{
public readonly SFO.ParamSfo ParamSfo;
public SfoEntry(SFO.ParamSfo paramSfo)
{
ParamSfo = paramSfo;
}
public override EntryId Id => EntryId.PARAM_SFO;
public override string Name => "param.sfo";
public override uint Length => (uint)ParamSfo.FileSize;
}


public class MetasEntry : Entry
{
public List<MetaEntry> Metas = new List<MetaEntry>();
public override EntryId Id => EntryId.METAS;
public override uint Length => (uint)Metas.Count * 32;
public override string Name => null;
}

}
115 changes: 115 additions & 0 deletions src/PS4RPI/LibOrbis/PKG/Pkg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//Code adapted from https://github.com/xXxTheDarkprogramerxXx/PS4_Tools

namespace PS4_Tools.LibOrbis.PKG
{
public class Pkg
{
// 0x0 - 0x5A0
public Header Header;
// 0xFE0 - 0xFFF
//public byte[] HeaderDigest;
// 0x1000 - 0x10FF
//public byte[] HeaderSignature;
// 0x2000 - 0x27FF
//public KeysEntry EntryKeys;
// 0x2800 - 0x28FF
//public GenericEntry ImageKey;
// 0x2900 - 0x2A7F
//public GeneralDigestsEntry GeneralDigests;
// 0x2A80 - 0x2xxx
public MetasEntry Metas;
// variable...
//public GenericEntry Digests;
//public NameTableEntry EntryNames;
//public GenericEntry LicenseDat;
//public GenericEntry LicenseInfo;
public SfoEntry ParamSfo;
//public GenericEntry PsReservedDat;
//public PlayGo.ChunkDat ChunkDat;
//public GenericEntry ChunkSha;
//public GenericEntry ChunkXml;

//public List<Entry> Entries;

// Constants
//const uint PKG_FLAG_FINALIZED = 1u << 31;
//const ulong PKG_PFS_FLAG_NESTED_IMAGE = 0x8000000000000000UL;
public const int PKG_TABLE_ENTRY_SIZE = 0x20;
public const int PKG_ENTRY_KEYSET_SIZE = 0x20;
public const int HASH_SIZE = 0x20;
public const string MAGIC = "\u007FCNT";

//const string PKG_ENTRY_NAME__PARAM_SFO = "param.sfo";
//const string PKG_ENTRY_NAME__SHAREPARAM_JSON = "shareparam.json";

//const uint PKG_SC_ENTRY_ID_START = (uint)EntryId.LICENSE_DAT;

const int PKG_MAX_ENTRY_KEYS = 7;
//const int PKG_CONTENT_ID_HASH_SIZE = HASH_SIZE;
//const int PKG_ENTRY_KEYS_XHASHES_SIZE = (PKG_MAX_ENTRY_KEYS * HASH_SIZE);
//const int PKG_PASSCODE_KEY_SIZE = 0x100;
//const int PKG_IMAGE_KEY_SIZE = 0x100;
//const int PKG_ENTRY_KEY_SIZE = 0x100;

//const int PKG_PLAYGO_CHUNK_HASH_TABLE_OFFSET = 0x40;
//const int PKG_PLAYGO_CHUNK_HASH_SIZE = 0x4;
//const int PKG_PLAYGO_PFS_CHUNK_SIZE = 0x10000;

//const int PKG_SHAREPARAM_FILE_VERSION_MAJOR = 1;
//const int PKG_SHAREPARAM_FILE_VERSION_MINOR = 10;

public const int PKG_CONTENT_ID_SIZE = 0x30;
public const int PKG_HEADER_SIZE = 0x5A0;
public const int PKG_ENTRY_KEYSET_ENC_SIZE = 0x100;
}



public struct Header
{
public string CNTMagic;
public PKGFlags flags;
public uint unk_0x08;
public uint unk_0x0C; /* 0xF */
public uint entry_count;
public ushort sc_entry_count;
public ushort entry_count_2; /* same as entry_count */
public uint entry_table_offset;
public uint main_ent_data_size;
public ulong body_offset;
public ulong body_size;
public string content_id; // Length = PKG_CONTENT_ID_SIZE
public DrmType drm_type;
public ContentType content_type;
public ContentFlags content_flags;
public uint promote_size;
public uint version_date;
public uint version_hash;
public uint unk_0x88; /* for delta patches only? */
public uint unk_0x8C; /* for delta patches only? */
public uint unk_0x90; /* for delta patches only? */
public uint unk_0x94; /* for delta patches only? */
public IROTag iro_tag;
public uint ekc_version; /* drm type version */
public byte[] sc_entries1_hash;
public byte[] sc_entries2_hash;
public byte[] digest_table_hash;
public byte[] body_digest;

// TODO: i think these fields are actually members of element of container array
public uint unk_0x400;
public uint pfs_image_count;
public ulong pfs_flags;
public ulong pfs_image_offset;
public ulong pfs_image_size;
public ulong mount_image_offset;
public ulong mount_image_size;
public ulong package_size;
public uint pfs_signed_size;
public uint pfs_cache_size;
public byte[] pfs_image_digest;
public byte[] pfs_signed_digest;
public ulong pfs_split_size_nth_0;
public ulong pfs_split_size_nth_1;
}
}
Loading

0 comments on commit 7f68bac

Please sign in to comment.