public static void PatchISO(Stream file, IEnumerable <PatcherLib.Datatypes.PatchedByteArray> patches) { PspIsoInfo info = PspIsoInfo.GetPspIsoInfo(file); DecryptISO(file, info); patches.ForEach(p => ApplyPatch(file, info, p)); }
public static byte[] GetFile(Stream stream, PspIsoInfo info, PspIso.Sectors sector, int start, int length) { byte[] result = new byte[length]; stream.Seek(info[sector] * 2048 + start, SeekOrigin.Begin); stream.Read(result, 0, length); return(result); }
/// <summary> /// Determines whether the specified stream is US. /// </summary> /// <param name="stream">The stream.</param> /// <returns> /// <c>true</c> if the specified stream is US; otherwise, <c>false</c>. /// </returns> public static bool IsUS(Stream stream, PspIsoInfo info) { return (CheckString(stream, info[Sectors.UMD_DATA_BIN] * 2048 + 0, "ULUS-10297") && CheckString(stream, info[Sectors.PSP_GAME_PARAM_SFO] * 2048 + 0x128, "ULUS10297") && CheckString(stream, info[Sectors.PSP_GAME_SYSDIR_BOOT_BIN] * 2048 + 0x3143A8, "ULUS10297") && CheckString(stream, info[Sectors.PSP_GAME_SYSDIR_BOOT_BIN] * 2048 + 0x35A530, "ULUS10297")); }
private static PspIsoInfo GetPspIsoInfo(ImageMaster.ImageRecord record) { ImageMaster.ImageRecord myRecord = null; var myDict = new Dictionary <Sectors, long>(); var myOtherDict = new Dictionary <Sectors, long>(); MyFunc func = delegate(string path, Sectors sector, bool throwOnError) { myRecord = record.GetItemPath(path); if (myRecord != null) { myDict[sector] = myRecord.Location; myOtherDict[sector] = myRecord.Size; } else if (throwOnError) { throw new FileNotFoundException("couldn't find file in ISO", path); } }; myDict[Sectors.Root] = 22; myOtherDict[Sectors.Root] = 0x800; func("PSP_GAME", Sectors.PSP_GAME, true); func("PSP_GAME/ICON0.PNG", Sectors.PSP_GAME_ICON0_PNG, true); func("PSP_GAME/PARAM.SFO", Sectors.PSP_GAME_PARAM_SFO, true); func("PSP_GAME/PIC0.PNG", Sectors.PSP_GAME_PIC0_PNG, true); func("PSP_GAME/PIC1.PNG", Sectors.PSP_GAME_PIC1_PNG, true); func("PSP_GAME/SYSDIR", Sectors.PSP_GAME_SYSDIR, true); func("PSP_GAME/SYSDIR/BOOT.BIN", Sectors.PSP_GAME_SYSDIR_BOOT_BIN, true); func("PSP_GAME/SYSDIR/EBOOT.BIN", Sectors.PSP_GAME_SYSDIR_EBOOT_BIN, true); func("PSP_GAME/SYSDIR/UPDATE", Sectors.PSP_GAME_SYSDIR_UPDATE, true); func("PSP_GAME/SYSDIR/UPDATE/DATA.BIN", Sectors.PSP_GAME_SYSDIR_UPDATE_DATA_BIN, true); func("PSP_GAME/SYSDIR/UPDATE/EBOOT.BIN", Sectors.PSP_GAME_SYSDIR_UPDATE_EBOOT_BIN, true); func("PSP_GAME/SYSDIR/UPDATE/PARAM.SFO", Sectors.PSP_GAME_SYSDIR_UPDATE_PARAM_SFO, true); func("PSP_GAME/USRDIR", Sectors.PSP_GAME_USRDIR, true); func("PSP_GAME/USRDIR/fftpack.bin", Sectors.PSP_GAME_USRDIR_fftpack_bin, true); func("PSP_GAME/USRDIR/movie", Sectors.PSP_GAME_USRDIR_movie, true); func("PSP_GAME/USRDIR/movie/001_HolyStone.pmf", Sectors.PSP_GAME_USRDIR_movie_001_HolyStone_pmf, true); func("PSP_GAME/USRDIR/movie/002_Opening.pmf", Sectors.PSP_GAME_USRDIR_movie_002_Opening_pmf, true); func("PSP_GAME/USRDIR/movie/003_Abduction.pmf", Sectors.PSP_GAME_USRDIR_movie_003_Abduction_pmf, true); func("PSP_GAME/USRDIR/movie/004_Kusabue.pmf", Sectors.PSP_GAME_USRDIR_movie_004_Kusabue_pmf, true); func("PSP_GAME/USRDIR/movie/005_Get_away.pmf", Sectors.PSP_GAME_USRDIR_movie_005_Get_away_pmf, true); func("PSP_GAME/USRDIR/movie/006_Reassume_Dilita.pmf", Sectors.PSP_GAME_USRDIR_movie_006_Reassume_Dilita_pmf, true); func("PSP_GAME/USRDIR/movie/007_Dilita_Advice.pmf", Sectors.PSP_GAME_USRDIR_movie_007_Dilita_Advice_pmf, true); func("PSP_GAME/USRDIR/movie/008_Ovelia_and_Dilita.pmf", Sectors.PSP_GAME_USRDIR_movie_008_Ovelia_and_Dilita_pmf, true); func("PSP_GAME/USRDIR/movie/009_Dilita_Musing.pmf", Sectors.PSP_GAME_USRDIR_movie_009_Dilita_Musing_pmf, true); func("PSP_GAME/USRDIR/movie/010_Ending.pmf", Sectors.PSP_GAME_USRDIR_movie_010_Ending_pmf, true); func("PSP_GAME/USRDIR/movie/011_Russo.pmf", Sectors.PSP_GAME_USRDIR_movie_011_Russo_pmf, true); func("PSP_GAME/USRDIR/movie/012_Valuhurea.pmf", Sectors.PSP_GAME_USRDIR_movie_012_Valuhurea_pmf, true); func("PSP_GAME/USRDIR/movie/013_StaffRoll.pmf", Sectors.PSP_GAME_USRDIR_movie_013_StaffRoll_pmf, true); func("UMD_DATA.BIN", Sectors.UMD_DATA_BIN, true); func("PSP_GAME/USRDIR/CHARMAP", Sectors.PSP_GAME_USRDIR_CHARMAP, false); PspIsoInfo result = new PspIsoInfo(); result.fileToSectorMap = myDict; result.fileToSizeMap = myOtherDict; return(result); }
public static byte[] GetBlock(Stream iso, PspIsoInfo info, KnownPosition pos) { if (pos.FFTPack.HasValue) { return(GetFile(iso, info, pos.FFTPack.Value, pos.StartLocation, pos.Length)); } else if (pos.Sector.HasValue) { return(GetFile(iso, info, pos.Sector.Value, pos.StartLocation, pos.Length)); } else { throw new InvalidOperationException(); } }
/// <summary> /// Decrypts the ISO. /// </summary> /// <param name="stream">The stream of the ISO to decrypt.</param> public static void DecryptISO(Stream stream, PspIsoInfo info) { if (IsJP(stream, info)) { CopyBytes(stream, info[Sectors.PSP_GAME_SYSDIR_BOOT_BIN] * 2048, 0x37D9E4, info[Sectors.PSP_GAME_SYSDIR_EBOOT_BIN] * 2048, 0x37DB40); } else if (IsUS(stream, info) || IsEU(stream, info)) { CopyBytes(stream, info[Sectors.PSP_GAME_SYSDIR_BOOT_BIN] * 2048, 0x3A84A4, info[Sectors.PSP_GAME_SYSDIR_EBOOT_BIN] * 2048, 0x3A8600); } else { throw new NotSupportedException("Unrecognized image."); } }
private static PspIsoInfo GetPspIsoInfo( ImageMaster.ImageRecord record ) { ImageMaster.ImageRecord myRecord = null; var myDict = new Dictionary<Sectors, long>(); MyFunc func = delegate( string path, Sectors sector ) { myRecord = record.GetItemPath( path ); if (myRecord != null) { myDict[sector] = myRecord.Location; } else { throw new FileNotFoundException( "couldn't find file in ISO", path ); } }; func( "PSP_GAME/ICON0.PNG", Sectors.PSP_GAME_ICON0_PNG ); func( "PSP_GAME/PARAM.SFO", Sectors.PSP_GAME_PARAM_SFO ); func( "PSP_GAME/PIC0.PNG", Sectors.PSP_GAME_PIC0_PNG ); func( "PSP_GAME/PIC1.PNG", Sectors.PSP_GAME_PIC1_PNG ); func( "PSP_GAME/SYSDIR/BOOT.BIN", Sectors.PSP_GAME_SYSDIR_BOOT_BIN ); func( "PSP_GAME/SYSDIR/EBOOT.BIN", Sectors.PSP_GAME_SYSDIR_EBOOT_BIN ); func( "PSP_GAME/SYSDIR/UPDATE/DATA.BIN", Sectors.PSP_GAME_SYSDIR_UPDATE_DATA_BIN ); func( "PSP_GAME/SYSDIR/UPDATE/EBOOT.BIN", Sectors.PSP_GAME_SYSDIR_UPDATE_EBOOT_BIN ); func( "PSP_GAME/SYSDIR/UPDATE/PARAM.SFO", Sectors.PSP_GAME_SYSDIR_UPDATE_PARAM_SFO ); func( "PSP_GAME/USRDIR/fftpack.bin", Sectors.PSP_GAME_USRDIR_fftpack_bin ); func( "PSP_GAME/USRDIR/movie/001_HolyStone.pmf", Sectors.PSP_GAME_USRDIR_movie_001_HolyStone_pmf ); func( "PSP_GAME/USRDIR/movie/002_Opening.pmf", Sectors.PSP_GAME_USRDIR_movie_002_Opening_pmf ); func( "PSP_GAME/USRDIR/movie/003_Abduction.pmf", Sectors.PSP_GAME_USRDIR_movie_003_Abduction_pmf ); func( "PSP_GAME/USRDIR/movie/004_Kusabue.pmf", Sectors.PSP_GAME_USRDIR_movie_004_Kusabue_pmf ); func( "PSP_GAME/USRDIR/movie/005_Get_away.pmf", Sectors.PSP_GAME_USRDIR_movie_005_Get_away_pmf ); func( "PSP_GAME/USRDIR/movie/006_Reassume_Dilita.pmf", Sectors.PSP_GAME_USRDIR_movie_006_Reassume_Dilita_pmf ); func( "PSP_GAME/USRDIR/movie/007_Dilita_Advice.pmf", Sectors.PSP_GAME_USRDIR_movie_007_Dilita_Advice_pmf ); func( "PSP_GAME/USRDIR/movie/008_Ovelia_and_Dilita.pmf", Sectors.PSP_GAME_USRDIR_movie_008_Ovelia_and_Dilita_pmf ); func( "PSP_GAME/USRDIR/movie/009_Dilita_Musing.pmf", Sectors.PSP_GAME_USRDIR_movie_009_Dilita_Musing_pmf ); func( "PSP_GAME/USRDIR/movie/010_Ending.pmf", Sectors.PSP_GAME_USRDIR_movie_010_Ending_pmf ); func( "PSP_GAME/USRDIR/movie/011_Russo.pmf", Sectors.PSP_GAME_USRDIR_movie_011_Russo_pmf ); func( "PSP_GAME/USRDIR/movie/012_Valuhurea.pmf", Sectors.PSP_GAME_USRDIR_movie_012_Valuhurea_pmf ); func( "PSP_GAME/USRDIR/movie/013_StaffRoll.pmf", Sectors.PSP_GAME_USRDIR_movie_013_StaffRoll_pmf ); func( "UMD_DATA.BIN", Sectors.UMD_DATA_BIN ); PspIsoInfo result = new PspIsoInfo(); result.fileToSectorMap = myDict; return result; }
public static void ApplyPatch(Stream stream, PspIsoInfo info, PatcherLib.Datatypes.PatchedByteArray patch) { if (patch.SectorEnum != null) { if (patch.SectorEnum.GetType() == typeof(PspIso.Sectors)) { stream.WriteArrayToPosition(patch.GetBytes(), (int)(info[(PspIso.Sectors)patch.SectorEnum] * 2048) + patch.Offset); } else if (patch.SectorEnum.GetType() == typeof(FFTPack.Files)) { FFTPack.PatchFile(stream, info, (int)((FFTPack.Files)patch.SectorEnum), (int)patch.Offset, patch.GetBytes()); } else { throw new ArgumentException("invalid type"); } } }
/// <summary> /// Decrypts the ISO. /// </summary> /// <param name="filename">The filename of the ISO to decrypt.</param> public static void DecryptISO(string filename) { FileStream stream = null; try { stream = new FileStream(filename, FileMode.Open); PspIsoInfo info = PspIsoInfo.GetPspIsoInfo(stream); DecryptISO(stream, info); } catch (NotSupportedException) { throw; } finally { if (stream != null) { stream.Flush(); stream.Close(); stream = null; } } }
public static void ApplyPatch( Stream stream, PspIsoInfo info, PatcherLib.Datatypes.PatchedByteArray patch ) { if ( patch.SectorEnum != null ) { if ( patch.SectorEnum.GetType() == typeof( PspIso.Sectors ) ) { stream.WriteArrayToPosition( patch.Bytes, (int)( info[(PspIso.Sectors)patch.SectorEnum] * 2048 ) + patch.Offset ); } else if ( patch.SectorEnum.GetType() == typeof( FFTPack.Files ) ) { FFTPack.PatchFile( stream, info, (int)( (FFTPack.Files)patch.SectorEnum ), (int)patch.Offset, patch.Bytes ); } else { throw new ArgumentException( "invalid type" ); } } }
/// <summary> /// Determines whether the specified stream is US. /// </summary> /// <param name="stream">The stream.</param> /// <returns> /// <c>true</c> if the specified stream is US; otherwise, <c>false</c>. /// </returns> public static bool IsUS( Stream stream, PspIsoInfo info ) { return CheckString( stream, info[Sectors.UMD_DATA_BIN] * 2048 + 0, "ULUS-10297" ) && CheckString( stream, info[Sectors.PSP_GAME_PARAM_SFO] * 2048 + 0x128, "ULUS10297" ) && CheckString( stream, info[Sectors.PSP_GAME_SYSDIR_BOOT_BIN] * 2048 + 0x3143A8, "ULUS10297" ) && CheckString( stream, info[Sectors.PSP_GAME_SYSDIR_BOOT_BIN] * 2048 + 0x35A530, "ULUS10297" ); }
/// <summary> /// Determines whether the specified stream is JP. /// </summary> /// <param name="stream">The stream.</param> /// <returns> /// <c>true</c> if the specified stream is JP; otherwise, <c>false</c>. /// </returns> public static bool IsJP( Stream stream, PspIsoInfo info ) { //return CheckFile( stream, "ULJM-05194", "ULJM05194", new long[] { 0x8373, 0xE000 }, new long[] { 0x2BF0128, 0xFD619FC, 0xFD97A5C } ); return CheckString( stream, info[Sectors.UMD_DATA_BIN] * 2048 + 0, "ULJM-05194" ); }
/// <summary> /// Decrypts the ISO. /// </summary> /// <param name="stream">The stream of the ISO to decrypt.</param> public static void DecryptISO( Stream stream, PspIsoInfo info ) { if ( IsJP( stream, info ) ) { CopyBytes( stream, info[Sectors.PSP_GAME_SYSDIR_BOOT_BIN] * 2048, 0x37D9E4, info[Sectors.PSP_GAME_SYSDIR_EBOOT_BIN] * 2048, 0x37DB40 ); } else if ( IsUS( stream, info ) || IsEU( stream, info ) ) { CopyBytes( stream, info[Sectors.PSP_GAME_SYSDIR_BOOT_BIN] * 2048, 0x3A84A4, info[Sectors.PSP_GAME_SYSDIR_EBOOT_BIN] * 2048, 0x3A8600 ); } else { throw new NotSupportedException( "Unrecognized image." ); } }
public override void PatchIso(Stream iso, IList <byte> bytes) { PspIso.ApplyPatch(iso, PspIsoInfo.GetPspIsoInfo(iso), GetPatchedByteArray(bytes.ToArray())); }
public byte[] ReadIso(Stream iso, PspIsoInfo info) { return(PspIso.GetBlock(iso, info, this)); }
public override byte[] ReadIso(Stream iso) { return(ReadIso(iso, PspIsoInfo.GetPspIsoInfo(iso))); }
public byte[] ReadIso( Stream iso, PspIsoInfo info ) { return PspIso.GetBlock( iso, info, this ); }
public static byte[] GetFile( Stream stream, PspIsoInfo info, FFTPack.Files file ) { return FFTPack.GetFileFromIso( stream, info, file ); }
public static IList<byte> GetBlock(Stream iso, PspIsoInfo info, KnownPosition pos) { if (pos.FFTPack.HasValue) { return GetFile(iso, info, pos.FFTPack.Value, pos.StartLocation, pos.Length); } else if (pos.Sector.HasValue) { return GetFile(iso, info, pos.Sector.Value, pos.StartLocation, pos.Length); } else { throw new InvalidOperationException(); } }
public static IList<byte> GetFile( Stream stream, PspIsoInfo info, PspIso.Sectors sector, int start, int length ) { byte[] result = new byte[length]; stream.Seek( info[sector] * 2048 + start, SeekOrigin.Begin ); stream.Read( result, 0, length ); return result; }
public static IList <byte> GetFile(Stream stream, PspIsoInfo info, FFTPack.Files file, int start, int length) { byte[] result = FFTPack.GetFileFromIso(stream, info, file); return(result.Sub(start, start + length - 1)); }
/// <summary> /// Determines whether the specified stream is JP. /// </summary> /// <param name="stream">The stream.</param> /// <returns> /// <c>true</c> if the specified stream is JP; otherwise, <c>false</c>. /// </returns> public static bool IsJP(Stream stream, PspIsoInfo info) { //return CheckFile( stream, "ULJM-05194", "ULJM05194", new long[] { 0x8373, 0xE000 }, new long[] { 0x2BF0128, 0xFD619FC, 0xFD97A5C } ); return (CheckString(stream, info[Sectors.UMD_DATA_BIN] * 2048 + 0, "ULJM-05194")); }
public static IList<byte> GetFile( Stream stream, PspIsoInfo info, FFTPack.Files file, int start, int length ) { byte[] result = FFTPack.GetFileFromIso( stream, info, file ); return result.Sub( start, start + length - 1 ); }
public static byte[] GetFile(Stream stream, PspIsoInfo info, FFTPack.Files file, int start, int length) { return(FFTPack.GetFileFromIso(stream, info, file, start, length)); }
public static byte[] GetFile(Stream stream, PspIsoInfo info, FFTPack.Files file) { return(FFTPack.GetFileFromIso(stream, info, file)); }
public static byte[] GetFile( Stream stream, PspIsoInfo info, FFTPack.Files file, int start, int length ) { return FFTPack.GetFileFromIso( stream, info, file, start, length ); }