435 lines
16 KiB
C#
435 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using BestHTTP.Logger;
|
|
using Cpp2IlInjected;
|
|
|
|
namespace BestHTTP.Extensions
|
|
{
|
|
// Token: 0x020019BF RID: 6591
|
|
[Token(Token = "0x20019BF")]
|
|
[StructLayout(3)]
|
|
public static class VariableSizedBufferPool
|
|
{
|
|
// Token: 0x17001C99 RID: 7321
|
|
// (get) Token: 0x0600B12B RID: 45355 RVA: 0x002960C0 File Offset: 0x002942C0
|
|
// (set) Token: 0x0600B12C RID: 45356 RVA: 0x002960D4 File Offset: 0x002942D4
|
|
[Token(Token = "0x17001C99")]
|
|
public static bool IsEnabled
|
|
{
|
|
[Token(Token = "0x600B12B")]
|
|
[Address(RVA = "0x1CA11A0", Offset = "0x1C9FBA0", VA = "0x181CA11A0")]
|
|
get
|
|
{
|
|
return VariableSizedBufferPool._isEnabled;
|
|
}
|
|
[Token(Token = "0x600B12C")]
|
|
[Address(RVA = "0x1CA1210", Offset = "0x1C9FC10", VA = "0x181CA1210")]
|
|
set
|
|
{
|
|
VariableSizedBufferPool._isEnabled = value;
|
|
if (!VariableSizedBufferPool._isEnabled)
|
|
{
|
|
VariableSizedBufferPool.Clear();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600B12D RID: 45357 RVA: 0x002960F8 File Offset: 0x002942F8
|
|
[Token(Token = "0x600B12D")]
|
|
[Address(RVA = "0x1CA0F80", Offset = "0x1C9F980", VA = "0x181CA0F80")]
|
|
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: 0x0600B12E RID: 45358 RVA: 0x00296160 File Offset: 0x00294360
|
|
[Token(Token = "0x600B12E")]
|
|
[Address(RVA = "0x1C9FEA0", Offset = "0x1C9E8A0", VA = "0x181C9FEA0")]
|
|
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++;
|
|
if (num != 0)
|
|
{
|
|
VariableSizedBufferPool.GetBuffers += 1U;
|
|
VariableSizedBufferPool.PoolSize = VariableSizedBufferPool.PoolSize;
|
|
}
|
|
if (canBeLarger && num != -1)
|
|
{
|
|
uint num3;
|
|
num3 += num3;
|
|
while (num3 <= (uint)num)
|
|
{
|
|
}
|
|
byte[] array = new byte[VariableSizedBufferPool.MinBufferSize];
|
|
byte[] array2 = new byte[size];
|
|
Monitor.Exit(freeBuffers);
|
|
if (num != -1)
|
|
{
|
|
}
|
|
if (num == 0)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return new byte[size];
|
|
}
|
|
|
|
// Token: 0x0600B12F RID: 45359 RVA: 0x0000220F File Offset: 0x0000040F
|
|
[Token(Token = "0x600B12F")]
|
|
[Address(RVA = "0x1CA0D50", Offset = "0x1C9F750", VA = "0x181CA0D50")]
|
|
public static void Release(List<byte[]> buffers)
|
|
{
|
|
throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
|
|
}
|
|
|
|
// Token: 0x0600B130 RID: 45360 RVA: 0x00296248 File Offset: 0x00294448
|
|
[Token(Token = "0x600B130")]
|
|
[Address(RVA = "0x1CA0AE0", Offset = "0x1C9F4E0", VA = "0x181CA0AE0")]
|
|
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);
|
|
if (num != -1)
|
|
{
|
|
}
|
|
}
|
|
while (num != 0);
|
|
}
|
|
|
|
// Token: 0x0600B131 RID: 45361 RVA: 0x002962A4 File Offset: 0x002944A4
|
|
[Token(Token = "0x600B131")]
|
|
[Address(RVA = "0x1CA0E30", Offset = "0x1C9F830", VA = "0x181CA0E30")]
|
|
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: 0x0600B132 RID: 45362 RVA: 0x002962DC File Offset: 0x002944DC
|
|
[Token(Token = "0x600B132")]
|
|
[Address(RVA = "0x1C9FA00", Offset = "0x1C9E400", VA = "0x181C9FA00")]
|
|
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);
|
|
if (num != -1)
|
|
{
|
|
}
|
|
}
|
|
while (num != 0);
|
|
throw new NullReferenceException();
|
|
}
|
|
|
|
// Token: 0x0600B133 RID: 45363 RVA: 0x002963D8 File Offset: 0x002945D8
|
|
[Token(Token = "0x600B133")]
|
|
[Address(RVA = "0x1C9F6C0", Offset = "0x1C9E0C0", VA = "0x181C9F6C0")]
|
|
public static void Clear()
|
|
{
|
|
int num;
|
|
do
|
|
{
|
|
num = 0;
|
|
List<BufferStore> freeBuffers = VariableSizedBufferPool.FreeBuffers;
|
|
VariableSizedBufferPool.FreeBuffers.Clear();
|
|
VariableSizedBufferPool.PoolSize = num;
|
|
Monitor.Exit(freeBuffers);
|
|
if (num != -1)
|
|
{
|
|
}
|
|
}
|
|
while (num != 0);
|
|
}
|
|
|
|
// Token: 0x0600B134 RID: 45364 RVA: 0x00296414 File Offset: 0x00294614
|
|
[Token(Token = "0x600B134")]
|
|
[Address(RVA = "0x1CA0460", Offset = "0x1C9EE60", VA = "0x181CA0460")]
|
|
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(num3);
|
|
if (num != -1)
|
|
{
|
|
}
|
|
}
|
|
while (num != 0);
|
|
}
|
|
|
|
// Token: 0x0600B135 RID: 45365 RVA: 0x00296578 File Offset: 0x00294778
|
|
[Token(Token = "0x600B135")]
|
|
[Address(RVA = "0x1CA0450", Offset = "0x1C9EE50", VA = "0x181CA0450")]
|
|
private static bool IsPowerOfTwo(long x)
|
|
{
|
|
long num = x - 1L;
|
|
return x == num;
|
|
}
|
|
|
|
// Token: 0x0600B136 RID: 45366 RVA: 0x00296590 File Offset: 0x00294790
|
|
[Token(Token = "0x600B136")]
|
|
[Address(RVA = "0x1CA0AC0", Offset = "0x1C9F4C0", VA = "0x181CA0AC0")]
|
|
private static long NextPowerOf2(long x)
|
|
{
|
|
/*
|
|
An exception occurred when decompiling this method (0600B136)
|
|
|
|
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: 0x0600B137 RID: 45367 RVA: 0x002965A4 File Offset: 0x002947A4
|
|
[Token(Token = "0x600B137")]
|
|
[Address(RVA = "0x1C9F810", Offset = "0x1C9E210", VA = "0x181C9F810")]
|
|
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: 0x0600B138 RID: 45368 RVA: 0x002965EC File Offset: 0x002947EC
|
|
[Token(Token = "0x600B138")]
|
|
[Address(RVA = "0x1C9F370", Offset = "0x1C9DD70", VA = "0x181C9F370")]
|
|
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: 0x04007436 RID: 29750
|
|
[Token(Token = "0x4007436")]
|
|
public static readonly byte[] NoData = new byte[0];
|
|
|
|
// Token: 0x04007437 RID: 29751
|
|
[Token(Token = "0x4007437")]
|
|
public static bool _isEnabled;
|
|
|
|
// Token: 0x04007438 RID: 29752
|
|
[Token(Token = "0x4007438")]
|
|
public static TimeSpan RemoveOlderThan;
|
|
|
|
// Token: 0x04007439 RID: 29753
|
|
[Token(Token = "0x4007439")]
|
|
public static TimeSpan RunMaintenanceEvery;
|
|
|
|
// Token: 0x0400743A RID: 29754
|
|
[Token(Token = "0x400743A")]
|
|
public static long MinBufferSize;
|
|
|
|
// Token: 0x0400743B RID: 29755
|
|
[Token(Token = "0x400743B")]
|
|
public static long MaxBufferSize;
|
|
|
|
// Token: 0x0400743C RID: 29756
|
|
[Token(Token = "0x400743C")]
|
|
public static long MaxPoolSize;
|
|
|
|
// Token: 0x0400743D RID: 29757
|
|
[Token(Token = "0x400743D")]
|
|
public static bool RemoveEmptyLists;
|
|
|
|
// Token: 0x0400743E RID: 29758
|
|
[Token(Token = "0x400743E")]
|
|
public static bool IsDoubleReleaseCheckEnabled;
|
|
|
|
// Token: 0x0400743F RID: 29759
|
|
[Token(Token = "0x400743F")]
|
|
private static List<BufferStore> FreeBuffers;
|
|
|
|
// Token: 0x04007440 RID: 29760
|
|
[Token(Token = "0x4007440")]
|
|
private static DateTime lastMaintenance;
|
|
|
|
// Token: 0x04007441 RID: 29761
|
|
[Token(Token = "0x4007441")]
|
|
private static int PoolSize;
|
|
|
|
// Token: 0x04007442 RID: 29762
|
|
[Token(Token = "0x4007442")]
|
|
private static uint GetBuffers;
|
|
|
|
// Token: 0x04007443 RID: 29763
|
|
[Token(Token = "0x4007443")]
|
|
private static uint ReleaseBuffers;
|
|
|
|
// Token: 0x04007444 RID: 29764
|
|
[Token(Token = "0x4007444")]
|
|
private static StringBuilder statiscticsBuilder;
|
|
}
|
|
}
|