chovy-sign/PopsBuilder/Pops/PopsImg.cs

88 lines
2.7 KiB
C#
Raw Normal View History

2023-04-16 13:07:43 +00:00
using GameBuilder;
using GameBuilder.Psp;
2023-04-14 03:55:11 +00:00
using PspCrypto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
2023-04-16 13:07:43 +00:00
namespace GameBuilder.Pops
2023-04-14 03:55:11 +00:00
{
public class PopsImg : NpDrmPsar
{
2023-04-15 17:22:43 +00:00
public PopsImg(NpDrmInfo versionKey) : base(versionKey)
2023-04-14 03:55:11 +00:00
{
simple = new MemoryStream();
simpleUtil = new StreamUtil(simple);
2023-04-15 17:22:43 +00:00
StartDat = NpDrmPsar.CreateStartDat(Resources.STARTDATPOPS);
2023-04-14 03:55:11 +00:00
createSimpleDat();
SimplePgd = generateSimplePgd();
}
2023-04-15 17:22:43 +00:00
2023-04-14 03:55:11 +00:00
private MemoryStream simple;
private StreamUtil simpleUtil;
2023-04-15 17:22:43 +00:00
public byte[] StartDat;
2023-04-14 03:55:11 +00:00
public byte[] SimplePgd;
private void createSimpleDat()
{
simpleUtil.WriteStr("SIMPLE ");
simpleUtil.WriteInt32(100);
simpleUtil.WriteInt32(16);
simpleUtil.WriteInt32(Resources.SIMPLE.Length);
simpleUtil.WriteInt32(0);
simpleUtil.WriteInt32(0);
simpleUtil.WriteBytes(Resources.SIMPLE);
}
2023-04-15 17:22:43 +00:00
2023-04-14 03:55:11 +00:00
private byte[] generateSimplePgd()
{
simple.Seek(0x0, SeekOrigin.Begin);
byte[] simpleData = simple.ToArray();
int simpleSz = DNASHelper.CalculateSize(simpleData.Length, 0x400);
byte[] simpleEnc = new byte[simpleSz];
// get pgd
2023-04-15 17:22:43 +00:00
int sz = DNASHelper.Encrypt(simpleEnc, simpleData, DrmInfo.VersionKey, simpleData.Length, DrmInfo.KeyType, 1, blockSize: 0x400);
2023-04-14 03:55:11 +00:00
byte[] pgd = simpleEnc.ToArray();
Array.Resize(ref pgd, sz);
return pgd;
}
2023-04-15 17:22:43 +00:00
public override byte[] GenerateDataPsp()
2023-04-14 03:55:11 +00:00
{
Span<byte> loaderEnc = new byte[0x9B13];
byte[] dataPspElf = Resources.DATAPSPSD;
// calculate size low and high part ..
uint szLow = Convert.ToUInt32(Psar.Length) >> 16;
uint szHigh = Convert.ToUInt32(Psar.Length) & 0xFFFF;
// convert to big endain bytes
byte[] lowBits = BitConverter.GetBytes(Convert.ToUInt16(szLow)).ToArray();
byte[] highBits = BitConverter.GetBytes(Convert.ToUInt16(szHigh)).ToArray();
// overwrite data.psar size check ..
Array.ConstrainedCopy(lowBits, 0, dataPspElf, 0x68C, 0x2);
Array.ConstrainedCopy(highBits, 0, dataPspElf, 0x694, 0x2);
2023-04-15 17:22:43 +00:00
SceMesgLed.Encrypt(loaderEnc, dataPspElf, 0x0DAA06F0, SceExecFileDecryptMode.DECRYPT_MODE_POPS_EXEC, DrmInfo.VersionKey, DrmInfo.ContentId, Resources.DATAPSPSDCFG);
2023-04-14 03:55:11 +00:00
return loaderEnc.ToArray();
}
}
}