Skip to content

Commit ec06d08

Browse files
committed
1.0.2
1 parent be4eb70 commit ec06d08

File tree

75 files changed

+93725
-117800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+93725
-117800
lines changed

Bcat Manager/Bcat Manager/AesCrypto.cs

Lines changed: 25 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -10,109 +10,43 @@ namespace Bcat_Manager
1010
{
1111
public class AesCrypto
1212
{
13-
public static byte[] EncryptAesBlock(byte[] Block, byte[] key)
14-
{
15-
byte[] decryptedBuffer = new byte[0x10];
16-
17-
Aes aes = Aes.Create();
18-
aes.Mode = CipherMode.ECB;
19-
aes.BlockSize = 128;
20-
aes.KeySize = key.Length * 8;
21-
aes.Key = key;
22-
23-
int transed = 0;
24-
using (var transform = aes.CreateEncryptor())
25-
{
26-
for (int i = 0; i < 0x10; i += transed)
27-
{
28-
transed = transform.TransformBlock(Block, i, 0x10, decryptedBuffer, i);
29-
}
30-
}
31-
32-
return decryptedBuffer;
33-
}
34-
//todo : remove or update
35-
public static void EncryptAesBlock(Stream inStream, Stream ouStream, byte[] key)
13+
public static byte[] PerformAesCTR(byte[] SourceBuffer, int Offset, int Size, byte[] key, byte[] iv)
3614
{
37-
BinaryReader br = new BinaryReader(inStream);
38-
BinaryWriter bw = new BinaryWriter(ouStream);
39-
40-
byte[] decryptedBuffer = new byte[0x10];
15+
byte[] encCounter = new byte[0x10];
16+
byte[] decryptedBuffer = new byte[Size];
17+
byte[] ctr = iv;
4118

4219
Aes aes = Aes.Create();
4320
aes.Mode = CipherMode.ECB;
4421
aes.BlockSize = 128;
4522
aes.KeySize = key.Length * 8;
4623
aes.Key = key;
4724

48-
int transed = 0;
49-
using (var transform = aes.CreateEncryptor())
50-
{
51-
byte[] inBlock = br.ReadBytes(0x10);
52-
byte[] outBlock = new byte[0x10];
53-
54-
for (int i = 0; i < 0x10; i += transed)
55-
{
56-
transed = transform.TransformBlock(inBlock, i, 0x10, outBlock, i);
57-
}
58-
59-
bw.Write(outBlock);
60-
}
61-
}
62-
63-
//todo : optimise the code to be faster
64-
public static void PerformAesCtr(Stream inStream, Stream ouStream, int Size, byte[] key, byte[] iv)
65-
{
66-
BinaryReader br = new BinaryReader(inStream);
67-
BinaryWriter bw = new BinaryWriter(ouStream);
68-
69-
for (var i = inStream.Position; i < Size; i += 0x10)
70-
{
71-
byte[] encCounter = EncryptAesBlock(iv, key);
72-
73-
var rest = Size - i;
74-
if (rest > 0x10) rest = 0x10;
75-
76-
//xor encrypted counter with ciphertext
77-
for (int j = 0; j < rest; j++)
78-
{
79-
bw.BaseStream.Position = i + j;
80-
br.BaseStream.Position = i + j;
81-
bw.Write(br.ReadByte() ^ encCounter[j]);
82-
}
83-
84-
//increment counter
85-
for (var j = iv.Length - 1; j >= 0; j--)
86-
{
87-
if (++iv[j] != 0)
88-
break;
89-
}
90-
}
91-
}
92-
public static byte[] PerformAesCTR(byte[] SourceBuffer, int Offset, int Size, byte[] key, byte[] iv)
93-
{
94-
byte[] decryptedBuffer = new byte[Size];
95-
96-
byte[] counter = iv;
97-
9825
for (int i = Offset; i < Size; i += 0x10)
9926
{
100-
byte[] encCounter = EncryptAesBlock(counter, key);
101-
102-
int rest = Size - i;
103-
if (rest > 0x10) rest = 0x10;
104-
105-
//xor encrypted counter with ciphertext
106-
for (int j = 0; j < rest; j++)
27+
using (var transform = aes.CreateEncryptor())
10728
{
108-
decryptedBuffer[i + j] = (byte)(encCounter[j] ^ SourceBuffer[i + j]);
109-
}
11029

111-
//increment counter
112-
for (var j = counter.Length - 1; j >= 0; j--)
113-
{
114-
if (++counter[j] != 0)
115-
break;
30+
int transed = 0;
31+
for (int j = 0; j < 0x10; j += transed)
32+
{
33+
transed = transform.TransformBlock(ctr, j, 0x10, encCounter, j);
34+
}
35+
36+
int rest = Size - i;
37+
if (rest > 0x10) rest = 0x10;
38+
39+
//xor encrypted counter with ciphertext
40+
for (int j = 0; j < rest; j++)
41+
{
42+
decryptedBuffer[i + j] = (byte)(encCounter[j] ^ SourceBuffer[i + j]);
43+
}
44+
//increment counter
45+
for (var j = ctr.Length - 1; j >= 0; j--)
46+
{
47+
if (++ctr[j] != 0)
48+
break;
49+
}
11650
}
11751
}
11852

Bcat Manager/Bcat Manager/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3+
<configSections>
4+
</configSections>
35
<startup>
46
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
57
</startup>
@@ -9,6 +11,10 @@
911
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
1012
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
1113
</dependentAssembly>
14+
<dependentAssembly>
15+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
16+
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
17+
</dependentAssembly>
1218
</assemblyBinding>
1319
</runtime>
1420
</configuration>

0 commit comments

Comments
 (0)