-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPRC.cs
58 lines (57 loc) · 2.04 KB
/
PRC.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSO.PRC
{
public class PRC
{
public static byte[] CipherBuffer(byte[] inBuf, UInt32 decompressedSize, UInt32 seedOverride = 0)
{
try
{
byte[] buffer = (byte[])inBuf.Clone();
UInt32 seed;
if (seedOverride > 0)
seed = seedOverride;
else
seed = Cipher.GenerateSeed();
if (Cipher.InitKey(seed) == false) return null;
buffer = Cipher.CipherBuffer(buffer, buffer.Length);
if (buffer == null) return null;
byte[] result = new byte[buffer.Length + 8];
Buffer.BlockCopy(buffer, 0, result, 8, buffer.Length);
Buffer.BlockCopy(BitConverter.GetBytes(decompressedSize), 0, result, 0, 4);
Buffer.BlockCopy(BitConverter.GetBytes(seed), 0, result, 4, 4);
return result;
}
catch (Exception)
{
return null;
}
}
public static byte[] DecipherBuffer(byte[] inBuf, ref UInt32 decompressedSize, UInt32 seedOverride = 0)
{
try
{
byte[] buffer = (byte[])inBuf.Clone();
decompressedSize = BitConverter.ToUInt32(buffer, 0);
UInt32 seed;
if (seedOverride > 0)
seed = seedOverride;
else
seed = BitConverter.ToUInt32(buffer, 4);
if (Cipher.InitKey(seed) == false) return null;
byte[] CipherBuffer = new byte[buffer.Length - 8];
Buffer.BlockCopy(buffer, 8, CipherBuffer, 0, buffer.Length - 8);
byte[] result = Cipher.CipherBuffer(CipherBuffer, CipherBuffer.Length);
return result;
}
catch (Exception)
{
return null;
}
}
}
}