425 lines
16 KiB
C#
425 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using BestHTTP.Logger;
|
|
using Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.Extensions
|
|
{
|
|
// Token: 0x0200207C RID: 8316
|
|
[Token(Token = "0x200207C")]
|
|
public static class VariableSizedBufferPool
|
|
{
|
|
// Token: 0x17002137 RID: 8503
|
|
// (get) Token: 0x0600D0D3 RID: 53459 RVA: 0x002F6D6C File Offset: 0x002F4F6C
|
|
// (set) Token: 0x0600D0D4 RID: 53460 RVA: 0x002F6D80 File Offset: 0x002F4F80
|
|
[Token(Token = "0x17002137")]
|
|
public static bool IsEnabled
|
|
{
|
|
[Token(Token = "0x600D0D3")]
|
|
[Address(RVA = "0x2A83050", Offset = "0x2A82050", VA = "0x182A83050")]
|
|
get
|
|
{
|
|
return VariableSizedBufferPool._isEnabled;
|
|
}
|
|
[Token(Token = "0x600D0D4")]
|
|
[Address(RVA = "0x2A830C0", Offset = "0x2A820C0", VA = "0x182A830C0")]
|
|
set
|
|
{
|
|
VariableSizedBufferPool._isEnabled = value;
|
|
if (!VariableSizedBufferPool._isEnabled)
|
|
{
|
|
VariableSizedBufferPool.Clear();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600D0D5 RID: 53461 RVA: 0x002F6DA4 File Offset: 0x002F4FA4
|
|
[Token(Token = "0x600D0D5")]
|
|
[Address(RVA = "0x2A82E30", Offset = "0x2A81E30", VA = "0x182A82E30")]
|
|
static VariableSizedBufferPool()
|
|
{
|
|
TimeSpan timeSpan;
|
|
VariableSizedBufferPool.RemoveOlderThan = timeSpan;
|
|
TimeSpan timeSpan2;
|
|
VariableSizedBufferPool.RunMaintenanceEvery = timeSpan2;
|
|
VariableSizedBufferPool.MaxBufferSize = (long)((ulong)long.MaxValue);
|
|
VariableSizedBufferPool.FreeBuffers = new List();
|
|
VariableSizedBufferPool.lastMaintenance = DateTime.MinValue;
|
|
int num = 0;
|
|
VariableSizedBufferPool.PoolSize = num;
|
|
VariableSizedBufferPool.GetBuffers = (uint)num;
|
|
VariableSizedBufferPool.ReleaseBuffers = (uint)num;
|
|
VariableSizedBufferPool.statiscticsBuilder = new StringBuilder();
|
|
}
|
|
|
|
// Token: 0x0600D0D6 RID: 53462 RVA: 0x002F6E0C File Offset: 0x002F500C
|
|
[Token(Token = "0x600D0D6")]
|
|
[Address(RVA = "0x2A81DF0", Offset = "0x2A80DF0", VA = "0x182A81DF0")]
|
|
public static byte[] Get(long size, bool canBeLarger)
|
|
{
|
|
for (;;)
|
|
{
|
|
int num = 0;
|
|
if (!VariableSizedBufferPool._isEnabled)
|
|
{
|
|
break;
|
|
}
|
|
List<BufferStore> freeBuffers = VariableSizedBufferPool.FreeBuffers;
|
|
Monitor.Enter(freeBuffers, canBeLarger);
|
|
List<BufferStore> freeBuffers2 = VariableSizedBufferPool.FreeBuffers;
|
|
List<BufferStore> freeBuffers3 = VariableSizedBufferPool.FreeBuffers;
|
|
List<BufferStore> freeBuffers4 = VariableSizedBufferPool.FreeBuffers;
|
|
int num2 = 0;
|
|
ThrowHelper.ThrowArgumentOutOfRangeException();
|
|
num += 2;
|
|
num += num;
|
|
if ((long)num2 == size || (canBeLarger && (long)num2 > size))
|
|
{
|
|
ThrowHelper.ThrowArgumentOutOfRangeException();
|
|
}
|
|
num++;
|
|
int poolSize;
|
|
if (num != 0)
|
|
{
|
|
VariableSizedBufferPool.GetBuffers += 1U;
|
|
poolSize = VariableSizedBufferPool.PoolSize;
|
|
VariableSizedBufferPool.PoolSize = poolSize;
|
|
}
|
|
if (canBeLarger)
|
|
{
|
|
int num3 = poolSize - 1;
|
|
if (poolSize != num3)
|
|
{
|
|
uint num4;
|
|
num4 += num4;
|
|
while (num4 <= (uint)poolSize)
|
|
{
|
|
}
|
|
byte[] array = new byte[VariableSizedBufferPool.MinBufferSize];
|
|
byte[] array2 = new byte[size];
|
|
Monitor.Exit(freeBuffers);
|
|
if (num == 0)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return new byte[size];
|
|
}
|
|
|
|
// Token: 0x0600D0D7 RID: 53463 RVA: 0x0000220F File Offset: 0x0000040F
|
|
[Token(Token = "0x600D0D7")]
|
|
[Address(RVA = "0x2A82C00", Offset = "0x2A81C00", VA = "0x182A82C00")]
|
|
public static void Release(List<byte[]> buffers)
|
|
{
|
|
throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
|
|
}
|
|
|
|
// Token: 0x0600D0D8 RID: 53464 RVA: 0x002F6F00 File Offset: 0x002F5100
|
|
[Token(Token = "0x600D0D8")]
|
|
[Address(RVA = "0x2A829B0", Offset = "0x2A819B0", VA = "0x182A829B0")]
|
|
public static void Release(byte[] buffer)
|
|
{
|
|
int num;
|
|
do
|
|
{
|
|
num = 0;
|
|
if (!VariableSizedBufferPool._isEnabled || buffer == 0 || buffer.Length == 0)
|
|
{
|
|
break;
|
|
}
|
|
List<BufferStore> freeBuffers = VariableSizedBufferPool.FreeBuffers;
|
|
long maxPoolSize = VariableSizedBufferPool.MaxPoolSize;
|
|
VariableSizedBufferPool.PoolSize = typeof(VariableSizedBufferPool).TypeHandle;
|
|
VariableSizedBufferPool.ReleaseBuffers += 1U;
|
|
VariableSizedBufferPool.AddFreeBuffer(buffer);
|
|
Monitor.Exit(freeBuffers);
|
|
}
|
|
while (num != 0);
|
|
}
|
|
|
|
// Token: 0x0600D0D9 RID: 53465 RVA: 0x002F6F58 File Offset: 0x002F5158
|
|
[Token(Token = "0x600D0D9")]
|
|
[Address(RVA = "0x2A82CE0", Offset = "0x2A81CE0", VA = "0x182A82CE0")]
|
|
public static byte[] Resize(ref byte[] buffer, int newSize, bool canBeLarger)
|
|
{
|
|
if (VariableSizedBufferPool._isEnabled)
|
|
{
|
|
byte[] array = VariableSizedBufferPool.Get((long)newSize, canBeLarger);
|
|
int num = Math.Min(array.Length, canBeLarger ? 1 : 0);
|
|
buffer.m_value = array;
|
|
}
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600D0DA RID: 53466 RVA: 0x002F6F90 File Offset: 0x002F5190
|
|
[Token(Token = "0x600D0DA")]
|
|
[Address(RVA = "0x2A81970", Offset = "0x2A80970", VA = "0x182A81970")]
|
|
public static string GetStatistics(bool showEmptyBuffers = true)
|
|
{
|
|
int num;
|
|
do
|
|
{
|
|
num = 0;
|
|
List<BufferStore> freeBuffers = VariableSizedBufferPool.FreeBuffers;
|
|
StringBuilder stringBuilder = VariableSizedBufferPool.statiscticsBuilder;
|
|
int num2 = 0;
|
|
stringBuilder.Length = num2;
|
|
uint num3;
|
|
StringBuilder stringBuilder2 = VariableSizedBufferPool.statiscticsBuilder.AppendFormat("Pooled array reused count: {0:N0}\n", num3);
|
|
StringBuilder stringBuilder3 = VariableSizedBufferPool.statiscticsBuilder;
|
|
StringBuilder stringBuilder4 = VariableSizedBufferPool.statiscticsBuilder;
|
|
StringBuilder stringBuilder5 = VariableSizedBufferPool.statiscticsBuilder;
|
|
int size = VariableSizedBufferPool.FreeBuffers._size;
|
|
StringBuilder stringBuilder6 = stringBuilder5.AppendFormat("Buffers: {0}\n", size);
|
|
List<BufferStore> freeBuffers2 = VariableSizedBufferPool.FreeBuffers;
|
|
List<BufferStore> freeBuffers3 = VariableSizedBufferPool.FreeBuffers;
|
|
ThrowHelper.ThrowArgumentOutOfRangeException();
|
|
num += 2;
|
|
num += num;
|
|
if (!showEmptyBuffers)
|
|
{
|
|
}
|
|
StringBuilder stringBuilder7 = VariableSizedBufferPool.statiscticsBuilder;
|
|
num++;
|
|
int hashCode = VariableSizedBufferPool.statiscticsBuilder.GetHashCode();
|
|
Monitor.Exit(freeBuffers);
|
|
}
|
|
while (num != 0);
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600D0DB RID: 53467 RVA: 0x002F7088 File Offset: 0x002F5288
|
|
[Token(Token = "0x600D0DB")]
|
|
[Address(RVA = "0x2A81650", Offset = "0x2A80650", VA = "0x182A81650")]
|
|
public static void Clear()
|
|
{
|
|
int num;
|
|
do
|
|
{
|
|
num = 0;
|
|
List<BufferStore> freeBuffers = VariableSizedBufferPool.FreeBuffers;
|
|
VariableSizedBufferPool.FreeBuffers.Clear();
|
|
VariableSizedBufferPool.PoolSize = num;
|
|
Monitor.Exit(freeBuffers);
|
|
}
|
|
while (num != 0);
|
|
}
|
|
|
|
// Token: 0x0600D0DC RID: 53468 RVA: 0x002F70C0 File Offset: 0x002F52C0
|
|
[Token(Token = "0x600D0DC")]
|
|
[Address(RVA = "0x2A82370", Offset = "0x2A81370", VA = "0x182A82370")]
|
|
internal static void Maintain()
|
|
{
|
|
int num;
|
|
do
|
|
{
|
|
num = 0;
|
|
DateTime utcNow = DateTime.UtcNow;
|
|
if (!VariableSizedBufferPool._isEnabled)
|
|
{
|
|
break;
|
|
}
|
|
DateTime dateTime = VariableSizedBufferPool.lastMaintenance;
|
|
TimeSpan runMaintenanceEvery = VariableSizedBufferPool.RunMaintenanceEvery;
|
|
if (dateTime + runMaintenanceEvery > utcNow)
|
|
{
|
|
break;
|
|
}
|
|
VariableSizedBufferPool.lastMaintenance = utcNow;
|
|
TimeSpan removeOlderThan = VariableSizedBufferPool.RemoveOlderThan;
|
|
DateTime dateTime2 = utcNow - removeOlderThan;
|
|
List<BufferStore> freeBuffers = VariableSizedBufferPool.FreeBuffers;
|
|
if (HTTPManager.Logger == 0)
|
|
{
|
|
ILogger logger = HTTPManager.Logger;
|
|
ulong num2;
|
|
string statistics = VariableSizedBufferPool.GetStatistics(num2 != 0UL);
|
|
string text = "Before Maintain: " + statistics;
|
|
}
|
|
List<BufferStore> freeBuffers2 = VariableSizedBufferPool.FreeBuffers;
|
|
List<BufferStore> list = VariableSizedBufferPool.FreeBuffers;
|
|
ThrowHelper.ThrowArgumentOutOfRangeException();
|
|
num += 2;
|
|
num += num;
|
|
ThrowHelper.ThrowArgumentOutOfRangeException();
|
|
list += list;
|
|
bool flag;
|
|
if (!flag)
|
|
{
|
|
}
|
|
int num3 = VariableSizedBufferPool.PoolSize;
|
|
num3 -= typeof(VariableSizedBufferPool).TypeHandle;
|
|
VariableSizedBufferPool.PoolSize = num3;
|
|
if (!runMaintenanceEvery._legacyConfigChecked)
|
|
{
|
|
VariableSizedBufferPool.FreeBuffers.RemoveAt(num);
|
|
}
|
|
num++;
|
|
if (HTTPManager.Logger == 0)
|
|
{
|
|
ILogger logger2 = HTTPManager.Logger;
|
|
ulong num4;
|
|
string statistics2 = VariableSizedBufferPool.GetStatistics(num4 != 0UL);
|
|
string text2 = "After Maintain: " + statistics2;
|
|
}
|
|
Monitor.Exit(freeBuffers);
|
|
}
|
|
while (num != 0);
|
|
}
|
|
|
|
// Token: 0x0600D0DD RID: 53469 RVA: 0x002F721C File Offset: 0x002F541C
|
|
[Token(Token = "0x600D0DD")]
|
|
[Address(RVA = "0x2A82360", Offset = "0x2A81360", VA = "0x182A82360")]
|
|
private static bool IsPowerOfTwo(long x)
|
|
{
|
|
long num = x - 1L;
|
|
return x == num;
|
|
}
|
|
|
|
// Token: 0x0600D0DE RID: 53470 RVA: 0x002F7234 File Offset: 0x002F5434
|
|
[Token(Token = "0x600D0DE")]
|
|
[Address(RVA = "0x2A82990", Offset = "0x2A81990", VA = "0x182A82990")]
|
|
private static long NextPowerOf2(long x)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600D0DE)
|
|
|
|
ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Int64 BestHTTP.Extensions.VariableSizedBufferPool::NextPowerOf2(System.Int64)
|
|
|
|
---> System.Exception: Basic block has to end with unconditional control flow.
|
|
{
|
|
IL_04:
|
|
brtrue(IL_04, cle:bool(ldloc:uint32[exp:int64](var_0), ldloc:int64(x)))
|
|
}
|
|
|
|
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1852
|
|
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1878
|
|
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1878
|
|
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.FlattenBasicBlocks(ILNode node) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 1846
|
|
at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.Optimize(DecompilerContext context, ILBlock method, AutoPropertyProvider autoPropertyProvider, StateMachineKind& stateMachineKind, MethodDef& inlinedMethod, AsyncMethodDebugInfo& asyncInfo, ILAstOptimizationStep abortBeforeStep) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstOptimizer.cs:line 355
|
|
at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable`1 parameters, MethodDebugInfoBuilder& builder) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 123
|
|
at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDef methodDef, DecompilerContext context, AutoPropertyProvider autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, MethodDebugInfoBuilder& stmtsBuilder) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 88
|
|
--- End of inner exception stack trace ---
|
|
at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDef methodDef, DecompilerContext context, AutoPropertyProvider autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, MethodDebugInfoBuilder& stmtsBuilder) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 92
|
|
at ICSharpCode.Decompiler.Ast.AstBuilder.AddMethodBody(EntityDeclaration methodNode, EntityDeclaration& updatedNode, MethodDef method, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, MethodKind methodKind) in D:\a\dnSpy\dnSpy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstBuilder.cs:line 1663
|
|
*/;
|
|
}
|
|
|
|
// Token: 0x0600D0DF RID: 53471 RVA: 0x002F7248 File Offset: 0x002F5448
|
|
[Token(Token = "0x600D0DF")]
|
|
[Address(RVA = "0x2A81780", Offset = "0x2A80780", VA = "0x182A81780")]
|
|
private static BufferDesc FindFreeBuffer(long size, bool canBeLarger)
|
|
{
|
|
int num = 0;
|
|
List<BufferStore> freeBuffers = VariableSizedBufferPool.FreeBuffers;
|
|
List<BufferStore> freeBuffers2 = VariableSizedBufferPool.FreeBuffers;
|
|
int num2 = 0;
|
|
ThrowHelper.ThrowArgumentOutOfRangeException();
|
|
if (num2 != (canBeLarger ? 1 : 0))
|
|
{
|
|
num++;
|
|
}
|
|
int num3 = 0;
|
|
ThrowHelper.ThrowArgumentOutOfRangeException();
|
|
num3 += num3;
|
|
size.m_value = 0L;
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600D0E0 RID: 53472 RVA: 0x002F7290 File Offset: 0x002F5490
|
|
[Token(Token = "0x600D0E0")]
|
|
[Address(RVA = "0x2A812F0", Offset = "0x2A802F0", VA = "0x182A812F0")]
|
|
private static void AddFreeBuffer(byte[] buffer)
|
|
{
|
|
int length = buffer.Length;
|
|
int num = 0;
|
|
List<BufferStore> freeBuffers = VariableSizedBufferPool.FreeBuffers;
|
|
List<BufferStore> freeBuffers2 = VariableSizedBufferPool.FreeBuffers;
|
|
ThrowHelper.ThrowArgumentOutOfRangeException();
|
|
if ("{il2cpp array field local7->}" != length)
|
|
{
|
|
num++;
|
|
uint num2;
|
|
num2 += (uint)16;
|
|
int num3 = 0;
|
|
VariableSizedBufferPool.FreeBuffers.Insert(num, num3);
|
|
return;
|
|
}
|
|
ThrowHelper.ThrowArgumentOutOfRangeException();
|
|
if (typeof(VariableSizedBufferPool).TypeHandle != buffer)
|
|
{
|
|
}
|
|
ILogger logger = HTTPManager.Logger;
|
|
DateTime utcNow = DateTime.UtcNow;
|
|
int num4 = 0;
|
|
VariableSizedBufferPool.FreeBuffers.Add(num4);
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x04008432 RID: 33842
|
|
[Token(Token = "0x4008432")]
|
|
public static readonly byte[] NoData = new byte[0];
|
|
|
|
// Token: 0x04008433 RID: 33843
|
|
[Token(Token = "0x4008433")]
|
|
public static bool _isEnabled;
|
|
|
|
// Token: 0x04008434 RID: 33844
|
|
[Token(Token = "0x4008434")]
|
|
public static TimeSpan RemoveOlderThan;
|
|
|
|
// Token: 0x04008435 RID: 33845
|
|
[Token(Token = "0x4008435")]
|
|
public static TimeSpan RunMaintenanceEvery;
|
|
|
|
// Token: 0x04008436 RID: 33846
|
|
[Token(Token = "0x4008436")]
|
|
public static long MinBufferSize;
|
|
|
|
// Token: 0x04008437 RID: 33847
|
|
[Token(Token = "0x4008437")]
|
|
public static long MaxBufferSize;
|
|
|
|
// Token: 0x04008438 RID: 33848
|
|
[Token(Token = "0x4008438")]
|
|
public static long MaxPoolSize;
|
|
|
|
// Token: 0x04008439 RID: 33849
|
|
[Token(Token = "0x4008439")]
|
|
public static bool RemoveEmptyLists;
|
|
|
|
// Token: 0x0400843A RID: 33850
|
|
[Token(Token = "0x400843A")]
|
|
public static bool IsDoubleReleaseCheckEnabled;
|
|
|
|
// Token: 0x0400843B RID: 33851
|
|
[Token(Token = "0x400843B")]
|
|
private static List<BufferStore> FreeBuffers;
|
|
|
|
// Token: 0x0400843C RID: 33852
|
|
[Token(Token = "0x400843C")]
|
|
private static DateTime lastMaintenance;
|
|
|
|
// Token: 0x0400843D RID: 33853
|
|
[Token(Token = "0x400843D")]
|
|
private static int PoolSize;
|
|
|
|
// Token: 0x0400843E RID: 33854
|
|
[Token(Token = "0x400843E")]
|
|
private static uint GetBuffers;
|
|
|
|
// Token: 0x0400843F RID: 33855
|
|
[Token(Token = "0x400843F")]
|
|
private static uint ReleaseBuffers;
|
|
|
|
// Token: 0x04008440 RID: 33856
|
|
[Token(Token = "0x4008440")]
|
|
private static StringBuilder statiscticsBuilder;
|
|
}
|
|
}
|