424 lines
15 KiB
C#
424 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using BestHTTP.Logger;
|
|
using Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.Extensions
|
|
{
|
|
// Token: 0x02001F9C RID: 8092
|
|
[Token(Token = "0x2001F9C")]
|
|
public static class VariableSizedBufferPool
|
|
{
|
|
// Token: 0x1700209A RID: 8346
|
|
// (get) Token: 0x0600CD05 RID: 52485 RVA: 0x002EE614 File Offset: 0x002EC814
|
|
// (set) Token: 0x0600CD06 RID: 52486 RVA: 0x002EE628 File Offset: 0x002EC828
|
|
[Token(Token = "0x1700209A")]
|
|
public static bool IsEnabled
|
|
{
|
|
[Token(Token = "0x600CD05")]
|
|
[Address(RVA = "0x172BBE0", Offset = "0x172A9E0", VA = "0x18172BBE0")]
|
|
get
|
|
{
|
|
return VariableSizedBufferPool._isEnabled;
|
|
}
|
|
[Token(Token = "0x600CD06")]
|
|
[Address(RVA = "0x172BC50", Offset = "0x172AA50", VA = "0x18172BC50")]
|
|
set
|
|
{
|
|
VariableSizedBufferPool._isEnabled = value;
|
|
if (!VariableSizedBufferPool._isEnabled)
|
|
{
|
|
VariableSizedBufferPool.Clear();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600CD07 RID: 52487 RVA: 0x002EE64C File Offset: 0x002EC84C
|
|
[Token(Token = "0x600CD07")]
|
|
[Address(RVA = "0x172B9C0", Offset = "0x172A7C0", VA = "0x18172B9C0")]
|
|
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: 0x0600CD08 RID: 52488 RVA: 0x002EE6B4 File Offset: 0x002EC8B4
|
|
[Token(Token = "0x600CD08")]
|
|
[Address(RVA = "0x172A980", Offset = "0x1729780", VA = "0x18172A980")]
|
|
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: 0x0600CD09 RID: 52489 RVA: 0x0000220F File Offset: 0x0000040F
|
|
[Token(Token = "0x600CD09")]
|
|
[Address(RVA = "0x172B790", Offset = "0x172A590", VA = "0x18172B790")]
|
|
public static void Release(List<byte[]> buffers)
|
|
{
|
|
throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
|
|
}
|
|
|
|
// Token: 0x0600CD0A RID: 52490 RVA: 0x002EE7A8 File Offset: 0x002EC9A8
|
|
[Token(Token = "0x600CD0A")]
|
|
[Address(RVA = "0x172B540", Offset = "0x172A340", VA = "0x18172B540")]
|
|
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: 0x0600CD0B RID: 52491 RVA: 0x002EE800 File Offset: 0x002ECA00
|
|
[Token(Token = "0x600CD0B")]
|
|
[Address(RVA = "0x172B870", Offset = "0x172A670", VA = "0x18172B870")]
|
|
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: 0x0600CD0C RID: 52492 RVA: 0x002EE838 File Offset: 0x002ECA38
|
|
[Token(Token = "0x600CD0C")]
|
|
[Address(RVA = "0x172A500", Offset = "0x1729300", VA = "0x18172A500")]
|
|
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: 0x0600CD0D RID: 52493 RVA: 0x002EE930 File Offset: 0x002ECB30
|
|
[Token(Token = "0x600CD0D")]
|
|
[Address(RVA = "0x172A1E0", Offset = "0x1728FE0", VA = "0x18172A1E0")]
|
|
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: 0x0600CD0E RID: 52494 RVA: 0x002EE968 File Offset: 0x002ECB68
|
|
[Token(Token = "0x600CD0E")]
|
|
[Address(RVA = "0x172AF00", Offset = "0x1729D00", VA = "0x18172AF00")]
|
|
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: 0x0600CD0F RID: 52495 RVA: 0x002EEAC4 File Offset: 0x002ECCC4
|
|
[Token(Token = "0x600CD0F")]
|
|
[Address(RVA = "0x172AEF0", Offset = "0x1729CF0", VA = "0x18172AEF0")]
|
|
private static bool IsPowerOfTwo(long x)
|
|
{
|
|
long num = x - 1L;
|
|
return x == num;
|
|
}
|
|
|
|
// Token: 0x0600CD10 RID: 52496 RVA: 0x002EEADC File Offset: 0x002ECCDC
|
|
[Token(Token = "0x600CD10")]
|
|
[Address(RVA = "0x172B520", Offset = "0x172A320", VA = "0x18172B520")]
|
|
private static long NextPowerOf2(long x)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600CD10)
|
|
|
|
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 1660
|
|
*/;
|
|
}
|
|
|
|
// Token: 0x0600CD11 RID: 52497 RVA: 0x002EEAF0 File Offset: 0x002ECCF0
|
|
[Token(Token = "0x600CD11")]
|
|
[Address(RVA = "0x172A310", Offset = "0x1729110", VA = "0x18172A310")]
|
|
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: 0x0600CD12 RID: 52498 RVA: 0x002EEB38 File Offset: 0x002ECD38
|
|
[Token(Token = "0x600CD12")]
|
|
[Address(RVA = "0x1729E90", Offset = "0x1728C90", VA = "0x181729E90")]
|
|
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;
|
|
int num4 = 0;
|
|
VariableSizedBufferPool.FreeBuffers.Add(num4);
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x04008279 RID: 33401
|
|
[Token(Token = "0x4008279")]
|
|
public static readonly byte[] NoData = new byte[0];
|
|
|
|
// Token: 0x0400827A RID: 33402
|
|
[Token(Token = "0x400827A")]
|
|
public static bool _isEnabled;
|
|
|
|
// Token: 0x0400827B RID: 33403
|
|
[Token(Token = "0x400827B")]
|
|
public static TimeSpan RemoveOlderThan;
|
|
|
|
// Token: 0x0400827C RID: 33404
|
|
[Token(Token = "0x400827C")]
|
|
public static TimeSpan RunMaintenanceEvery;
|
|
|
|
// Token: 0x0400827D RID: 33405
|
|
[Token(Token = "0x400827D")]
|
|
public static long MinBufferSize;
|
|
|
|
// Token: 0x0400827E RID: 33406
|
|
[Token(Token = "0x400827E")]
|
|
public static long MaxBufferSize;
|
|
|
|
// Token: 0x0400827F RID: 33407
|
|
[Token(Token = "0x400827F")]
|
|
public static long MaxPoolSize;
|
|
|
|
// Token: 0x04008280 RID: 33408
|
|
[Token(Token = "0x4008280")]
|
|
public static bool RemoveEmptyLists;
|
|
|
|
// Token: 0x04008281 RID: 33409
|
|
[Token(Token = "0x4008281")]
|
|
public static bool IsDoubleReleaseCheckEnabled;
|
|
|
|
// Token: 0x04008282 RID: 33410
|
|
[Token(Token = "0x4008282")]
|
|
private static List<BufferStore> FreeBuffers;
|
|
|
|
// Token: 0x04008283 RID: 33411
|
|
[Token(Token = "0x4008283")]
|
|
private static DateTime lastMaintenance;
|
|
|
|
// Token: 0x04008284 RID: 33412
|
|
[Token(Token = "0x4008284")]
|
|
private static int PoolSize;
|
|
|
|
// Token: 0x04008285 RID: 33413
|
|
[Token(Token = "0x4008285")]
|
|
private static uint GetBuffers;
|
|
|
|
// Token: 0x04008286 RID: 33414
|
|
[Token(Token = "0x4008286")]
|
|
private static uint ReleaseBuffers;
|
|
|
|
// Token: 0x04008287 RID: 33415
|
|
[Token(Token = "0x4008287")]
|
|
private static StringBuilder statiscticsBuilder;
|
|
}
|
|
}
|