Compare commits
74 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
0b6b8a92c0 | |
|
|
aefec5c024 | |
|
|
67f3dd4cf3 | |
|
|
79c81e234c | |
|
|
fa2345017a | |
|
|
977779c8b7 | |
|
|
7b06f0fed8 | |
|
|
3615bbcce9 | |
|
|
1ff3b5c324 | |
|
|
5932a6f9a6 | |
|
|
6c543d233a | |
|
|
81e0b412a3 | |
|
|
4bdf21349c | |
|
|
c9ea564544 | |
|
|
b582c1f24b | |
|
|
b40a063582 | |
|
|
747ee88fd3 | |
|
|
403764e7af | |
|
|
e12a0e26dc | |
|
|
daff29ea94 | |
|
|
eeff4a75ca | |
|
|
b0699ecf5c | |
|
|
5557b27724 | |
|
|
59b1166ff3 | |
|
|
4ad3ed76dc | |
|
|
2576236960 | |
|
|
c3c53b2797 | |
|
|
0889f730fd | |
|
|
87cd3caf44 | |
|
|
8dd6352028 | |
|
|
739fcb24c5 | |
|
|
246a49f8ba | |
|
|
1ec6e2f426 | |
|
|
b68571de7e | |
|
|
50fe1e1179 | |
|
|
d52a9e7016 | |
|
|
f5c2fe94ea | |
|
|
54bcae5178 | |
|
|
cfb544426b | |
|
|
1e027e6299 | |
|
|
4db68f707b | |
|
|
c596b58d3e | |
|
|
ddb144eac8 | |
|
|
1a240c47ac | |
|
|
2e48164ae9 | |
|
|
9b6e6375f6 | |
|
|
38ad0de746 | |
|
|
6ec1a74d57 | |
|
|
d6d9cde741 | |
|
|
87f086e310 | |
|
|
69b91575db | |
|
|
0985b3d06e | |
|
|
d4133f1e8a | |
|
|
3bcf204f69 | |
|
|
905351789e | |
|
|
3bcb093467 | |
|
|
49194ca1af | |
|
|
6a4f84a9b0 | |
|
|
083ddd3035 | |
|
|
2887231df7 | |
|
|
c3238c54a9 | |
|
|
f908b648c1 | |
|
|
29debc44bf | |
|
|
9cbb105405 | |
|
|
e3d9d7a08e | |
|
|
4b0c5d7521 | |
|
|
9b9eb6d12d | |
|
|
52d9ee1349 | |
|
|
bf3f6e4534 | |
|
|
655c2fe07f | |
|
|
02ed0608e4 | |
|
|
59db0dfaab | |
|
|
2b8e51b12d | |
|
|
df181ed5c1 |
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.ObfusPasses;
|
||||
using Obfuz.Utils;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
namespace Obfuz.Editor
|
||||
{
|
||||
public static class ConstValues
|
||||
|
|
@ -11,6 +31,7 @@
|
|||
public const string ObfuzScopeFullName = "Obfuz.ObfuzScope";
|
||||
|
||||
public const string EncryptFieldAttributeFullName = "Obfuz.EncryptFieldAttribute";
|
||||
public const string GeneratedEncryptionVirtualMachineFullName = "Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine";
|
||||
|
||||
public const string EmbeddedAttributeFullName = "Microsoft.CodeAnalysis.EmbeddedAttribute";
|
||||
|
||||
|
|
@ -19,5 +40,13 @@
|
|||
public const string ZluaLuaInvokeAttributeFullName = "Zlua.LuaInvokeAttribute";
|
||||
public const string ZluaLuaCallbackAttributeFullName = "Zlua.LuaCallbackAttribute";
|
||||
public const string ZluaLuaMarshalAsAttributeFullName = "Zlua.LuaMarshalAsAttribute";
|
||||
|
||||
public const string BurstCompileFullName = "Unity.Burst.BurstCompileAttribute";
|
||||
public const string DOTSCompilerGeneratedAttributeFullName = "Unity.Jobs.DOTSCompilerGeneratedAttribute";
|
||||
|
||||
public const string RuntimeInitializedOnLoadMethodAttributeFullName = "UnityEngine.RuntimeInitializeOnLoadMethodAttribute";
|
||||
public const string BlackboardEnumAttributeFullName = "Unity.Behavior.BlackboardEnumAttribute";
|
||||
|
||||
public const string CompilerGeneratedAttributeFullName = "System.Runtime.CompilerServices.CompilerGeneratedAttribute";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Editor;
|
||||
|
|
@ -10,13 +30,8 @@ using UnityEngine.Assertions;
|
|||
|
||||
namespace Obfuz.Data
|
||||
{
|
||||
public class ModuleConstFieldAllocator : IGroupByModuleEntity
|
||||
public class ConstFieldAllocator : GroupByModuleEntityBase
|
||||
{
|
||||
private ModuleDef _module;
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private readonly RvaDataAllocator _rvaDataAllocator;
|
||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||
private EncryptionScopeInfo _encryptionScope;
|
||||
private RandomCreator _randomCreator;
|
||||
private IEncryptor _encryptor;
|
||||
|
||||
|
|
@ -57,19 +72,14 @@ namespace Obfuz.Data
|
|||
private bool _done;
|
||||
|
||||
|
||||
public ModuleConstFieldAllocator(EncryptionScopeProvider encryptionScopeProvider, RvaDataAllocator rvaDataAllocator, GroupByModuleEntityManager moduleEntityManager)
|
||||
public ConstFieldAllocator()
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
_rvaDataAllocator = rvaDataAllocator;
|
||||
_moduleEntityManager = moduleEntityManager;
|
||||
}
|
||||
|
||||
public void Init(ModuleDef mod)
|
||||
public override void Init()
|
||||
{
|
||||
_module = mod;
|
||||
_encryptionScope = _encryptionScopeProvider.GetScope(mod);
|
||||
_randomCreator = _encryptionScope.localRandomCreator;
|
||||
_encryptor = _encryptionScope.encryptor;
|
||||
_randomCreator = EncryptionScope.localRandomCreator;
|
||||
_encryptor = EncryptionScope.encryptor;
|
||||
}
|
||||
|
||||
const int maxFieldCount = 1000;
|
||||
|
|
@ -77,30 +87,32 @@ namespace Obfuz.Data
|
|||
|
||||
private TypeSig GetTypeSigOfValue(object value)
|
||||
{
|
||||
ModuleDef mod = Module;
|
||||
if (value is int)
|
||||
return _module.CorLibTypes.Int32;
|
||||
return mod.CorLibTypes.Int32;
|
||||
if (value is long)
|
||||
return _module.CorLibTypes.Int64;
|
||||
return mod.CorLibTypes.Int64;
|
||||
if (value is float)
|
||||
return _module.CorLibTypes.Single;
|
||||
return mod.CorLibTypes.Single;
|
||||
if (value is double)
|
||||
return _module.CorLibTypes.Double;
|
||||
return mod.CorLibTypes.Double;
|
||||
if (value is string)
|
||||
return _module.CorLibTypes.String;
|
||||
return mod.CorLibTypes.String;
|
||||
if (value is byte[])
|
||||
return new SZArraySig(_module.CorLibTypes.Byte);
|
||||
return new SZArraySig(mod.CorLibTypes.Byte);
|
||||
throw new NotSupportedException($"Unsupported type: {value.GetType()}");
|
||||
}
|
||||
|
||||
private ConstFieldInfo CreateConstFieldInfo(object value)
|
||||
{
|
||||
ModuleDef mod = Module;
|
||||
if (_holderTypeDef == null || _holderTypeDef.Fields.Count >= maxFieldCount)
|
||||
{
|
||||
using (var scope = new DisableTypeDefFindCacheScope(_module))
|
||||
using (var scope = new DisableTypeDefFindCacheScope(mod))
|
||||
{
|
||||
ITypeDefOrRef objectTypeRef = _module.Import(typeof(object));
|
||||
ITypeDefOrRef objectTypeRef = mod.Import(typeof(object));
|
||||
_holderTypeDef = new TypeDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}ConstFieldHolder${_holderTypeDefs.Count}", objectTypeRef);
|
||||
_module.Types.Add(_holderTypeDef);
|
||||
mod.Types.Add(_holderTypeDef);
|
||||
_holderTypeDefs.Add(_holderTypeDef);
|
||||
}
|
||||
}
|
||||
|
|
@ -159,41 +171,35 @@ namespace Obfuz.Data
|
|||
return AllocateAny(value);
|
||||
}
|
||||
|
||||
private DefaultMetadataImporter GetModuleMetadataImporter()
|
||||
{
|
||||
return _moduleEntityManager.GetDefaultModuleMetadataImporter(_module, _encryptionScopeProvider);
|
||||
}
|
||||
|
||||
private void CreateCCtorOfRvaTypeDef(TypeDef type)
|
||||
{
|
||||
ModuleDef mod = Module;
|
||||
var cctor = new MethodDefUser(".cctor",
|
||||
MethodSig.CreateStatic(_module.CorLibTypes.Void),
|
||||
MethodSig.CreateStatic(mod.CorLibTypes.Void),
|
||||
MethodImplAttributes.IL | MethodImplAttributes.Managed,
|
||||
MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Private);
|
||||
cctor.DeclaringType = type;
|
||||
//_rvaTypeDef.Methods.Add(cctor);
|
||||
var body = new CilBody();
|
||||
cctor.Body = body;
|
||||
var ins = body.Instructions;
|
||||
|
||||
//IMethod method = _module.Import(typeof(System.Runtime.CompilerServices.RuntimeHelpers).GetMethod("InitializeArray", new[] { typeof(Array), typeof(RuntimeFieldHandle) }));
|
||||
//Assert.IsNotNull(method);
|
||||
|
||||
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter();
|
||||
DefaultMetadataImporter importer = this.GetDefaultModuleMetadataImporter();
|
||||
RvaDataAllocator rvaDataAllocator = GetEntity<RvaDataAllocator>();
|
||||
// TODO. obfuscate init codes
|
||||
foreach (var field in type.Fields)
|
||||
{
|
||||
ConstFieldInfo constInfo = _field2Fields[field];
|
||||
IRandom localRandom = _randomCreator(HashUtil.ComputePrimitiveOrStringOrBytesHashCode(constInfo.value));
|
||||
int ops = EncryptionUtil.GenerateEncryptionOpCodes(localRandom, _encryptor, 4);
|
||||
int ops = EncryptionUtil.GenerateEncryptionOpCodes(localRandom, _encryptor, EncryptionScopeInfo.MaxEncryptionLevel, false);
|
||||
int salt = localRandom.NextInt();
|
||||
switch (constInfo.value)
|
||||
{
|
||||
case int i:
|
||||
{
|
||||
int encryptedValue = _encryptor.Encrypt(i, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
ins.Add(Instruction.CreateLdcI4(ops));
|
||||
|
|
@ -204,7 +210,7 @@ namespace Obfuz.Data
|
|||
case long l:
|
||||
{
|
||||
long encryptedValue = _encryptor.Encrypt(l, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
ins.Add(Instruction.CreateLdcI4(ops));
|
||||
|
|
@ -215,7 +221,7 @@ namespace Obfuz.Data
|
|||
case float f:
|
||||
{
|
||||
float encryptedValue = _encryptor.Encrypt(f, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
ins.Add(Instruction.CreateLdcI4(ops));
|
||||
|
|
@ -226,7 +232,7 @@ namespace Obfuz.Data
|
|||
case double d:
|
||||
{
|
||||
double encryptedValue = _encryptor.Encrypt(d, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
ins.Add(Instruction.CreateLdcI4(ops));
|
||||
|
|
@ -237,7 +243,7 @@ namespace Obfuz.Data
|
|||
case string s:
|
||||
{
|
||||
byte[] encryptedValue = _encryptor.Encrypt(s, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
Assert.AreEqual(encryptedValue.Length, rvaData.size);
|
||||
|
|
@ -251,7 +257,7 @@ namespace Obfuz.Data
|
|||
{
|
||||
byte[] encryptedValue = _encryptor.Encrypt(bs, 0, bs.Length, ops, salt);
|
||||
Assert.AreEqual(encryptedValue.Length, bs.Length);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
ins.Add(Instruction.CreateLdcI4(bs.Length));
|
||||
|
|
@ -267,7 +273,7 @@ namespace Obfuz.Data
|
|||
ins.Add(Instruction.Create(OpCodes.Ret));
|
||||
}
|
||||
|
||||
public void Done()
|
||||
public override void Done()
|
||||
{
|
||||
if (_done)
|
||||
{
|
||||
|
|
@ -280,61 +286,4 @@ namespace Obfuz.Data
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ConstFieldAllocator
|
||||
{
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private readonly RvaDataAllocator _rvaDataAllocator;
|
||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||
|
||||
public ConstFieldAllocator(EncryptionScopeProvider encryptionScopeProvider, RvaDataAllocator rvaDataAllocator, GroupByModuleEntityManager moduleEntityManager)
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
_rvaDataAllocator = rvaDataAllocator;
|
||||
_moduleEntityManager = moduleEntityManager;
|
||||
}
|
||||
|
||||
public ModuleConstFieldAllocator GetModuleAllocator(ModuleDef mod)
|
||||
{
|
||||
return _moduleEntityManager.GetEntity<ModuleConstFieldAllocator>(mod, () => new ModuleConstFieldAllocator(_encryptionScopeProvider, _rvaDataAllocator, _moduleEntityManager));
|
||||
}
|
||||
|
||||
public FieldDef Allocate(ModuleDef mod, int value)
|
||||
{
|
||||
return GetModuleAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public FieldDef Allocate(ModuleDef mod, long value)
|
||||
{
|
||||
return GetModuleAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public FieldDef Allocate(ModuleDef mod, float value)
|
||||
{
|
||||
return GetModuleAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public FieldDef Allocate(ModuleDef mod, double value)
|
||||
{
|
||||
return GetModuleAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public FieldDef Allocate(ModuleDef mod, byte[] value)
|
||||
{
|
||||
return GetModuleAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public FieldDef Allocate(ModuleDef mod, string value)
|
||||
{
|
||||
return GetModuleAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public void Done()
|
||||
{
|
||||
foreach (var moduleAllocator in _moduleEntityManager.GetEntities<ModuleConstFieldAllocator>())
|
||||
{
|
||||
moduleAllocator.Done();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,30 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
|
|
@ -23,16 +44,13 @@ namespace Obfuz.Data
|
|||
}
|
||||
}
|
||||
|
||||
public class ModuleRvaDataAllocator : GroupByModuleEntityBase
|
||||
public class RvaDataAllocator : GroupByModuleEntityBase
|
||||
{
|
||||
// randomized
|
||||
const int maxRvaDataSize = 0x1000;
|
||||
const int maxRvaDataSize = 2 * 1024;
|
||||
|
||||
private ModuleDef _module;
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||
// in HybridCLR version below 8.3.0, the max total static field size of a type is 16KB, so we limit the total size of RVA data to 16KB
|
||||
const int maxTotalRvaDataFieldSizeInHybridCLR = 16 * 1024;
|
||||
|
||||
private EncryptionScopeInfo _encryptionScope;
|
||||
private IRandom _random;
|
||||
|
||||
class RvaField
|
||||
|
|
@ -62,64 +80,72 @@ namespace Obfuz.Data
|
|||
}
|
||||
}
|
||||
|
||||
private readonly List<RvaField> _rvaFields = new List<RvaField>();
|
||||
private class RvaTypeDefInfo
|
||||
{
|
||||
public readonly TypeDef typeDef;
|
||||
public readonly int index;
|
||||
public readonly List<RvaField> rvaFields = new List<RvaField>();
|
||||
|
||||
public RvaTypeDefInfo(TypeDef typeDef, int index)
|
||||
{
|
||||
this.typeDef = typeDef;
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
|
||||
private RvaField _currentField;
|
||||
|
||||
|
||||
private TypeDef _rvaTypeDef;
|
||||
private RvaTypeDefInfo _currentRvaType;
|
||||
private readonly List<RvaTypeDefInfo> _rvaTypeDefs = new List<RvaTypeDefInfo>();
|
||||
|
||||
private readonly Dictionary<int, TypeDef> _dataHolderTypeBySizes = new Dictionary<int, TypeDef>();
|
||||
private bool _done;
|
||||
|
||||
public ModuleRvaDataAllocator(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager)
|
||||
public RvaDataAllocator()
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
_moduleEntityManager = moduleEntityManager;
|
||||
}
|
||||
|
||||
public override void Init(ModuleDef mod)
|
||||
public override void Init()
|
||||
{
|
||||
_module = mod;
|
||||
_encryptionScope = _encryptionScopeProvider.GetScope(mod);
|
||||
_random = _encryptionScope.localRandomCreator(HashUtil.ComputeHash(mod.Name));
|
||||
_random = EncryptionScope.localRandomCreator(HashUtil.ComputeHash(Module.Name));
|
||||
}
|
||||
|
||||
private (FieldDef, FieldDef) CreateDataHolderRvaField(TypeDef dataHolderType)
|
||||
{
|
||||
if (_rvaTypeDef == null)
|
||||
if (_currentRvaType == null || _currentRvaType.rvaFields.Count >= maxTotalRvaDataFieldSizeInHybridCLR / maxRvaDataSize - 1)
|
||||
{
|
||||
using (var scope = new DisableTypeDefFindCacheScope(_module))
|
||||
using (var scope = new DisableTypeDefFindCacheScope(Module))
|
||||
{
|
||||
ITypeDefOrRef objectTypeRef = _module.Import(typeof(object));
|
||||
_rvaTypeDef = new TypeDefUser("$Obfuz$RVA$", objectTypeRef);
|
||||
_module.Types.Add(_rvaTypeDef);
|
||||
var rvaTypeDef = new TypeDefUser($"$Obfuz$RVA${_rvaTypeDefs.Count}", Module.CorLibTypes.Object.ToTypeDefOrRef());
|
||||
Module.Types.Add(rvaTypeDef);
|
||||
_currentRvaType = new RvaTypeDefInfo(rvaTypeDef, _rvaTypeDefs.Count);
|
||||
_rvaTypeDefs.Add(_currentRvaType);
|
||||
}
|
||||
}
|
||||
|
||||
var holderField = new FieldDefUser($"$RVA_Data{_currentRvaType.rvaFields.Count}", new FieldSig(dataHolderType.ToTypeSig()), FieldAttributes.InitOnly | FieldAttributes.Static | FieldAttributes.HasFieldRVA);
|
||||
holderField.DeclaringType = _currentRvaType.typeDef;
|
||||
|
||||
var holderField = new FieldDefUser($"$RVA_Data{_rvaFields.Count}", new FieldSig(dataHolderType.ToTypeSig()), FieldAttributes.InitOnly | FieldAttributes.Static | FieldAttributes.HasFieldRVA);
|
||||
holderField.DeclaringType = _rvaTypeDef;
|
||||
|
||||
var runtimeValueField = new FieldDefUser($"$RVA_Value{_rvaFields.Count}", new FieldSig(new SZArraySig(_module.CorLibTypes.Byte)), FieldAttributes.Static | FieldAttributes.Public);
|
||||
runtimeValueField.DeclaringType = _rvaTypeDef;
|
||||
var runtimeValueField = new FieldDefUser($"$RVA_Value{_currentRvaType.rvaFields.Count}", new FieldSig(new SZArraySig(Module.CorLibTypes.Byte)), FieldAttributes.Static | FieldAttributes.Public);
|
||||
runtimeValueField.DeclaringType = _currentRvaType.typeDef;
|
||||
return (holderField, runtimeValueField);
|
||||
}
|
||||
|
||||
private TypeDef GetDataHolderType(int size)
|
||||
{
|
||||
size = (size + 15) & ~15; // align to 6 bytes
|
||||
size = (size + 15) & ~15; // align to 16 bytes
|
||||
if (_dataHolderTypeBySizes.TryGetValue(size, out var type))
|
||||
return type;
|
||||
|
||||
using (var scope = new DisableTypeDefFindCacheScope(_module))
|
||||
using (var scope = new DisableTypeDefFindCacheScope(Module))
|
||||
{
|
||||
var dataHolderType = new TypeDefUser($"$ObfuzRVA$DataHolder{size}", _module.Import(typeof(ValueType)));
|
||||
var dataHolderType = new TypeDefUser($"$ObfuzRVA$DataHolder{size}", Module.Import(typeof(ValueType)));
|
||||
dataHolderType.Attributes = TypeAttributes.Public | TypeAttributes.Sealed;
|
||||
dataHolderType.Layout = TypeAttributes.ExplicitLayout;
|
||||
dataHolderType.PackingSize = 1;
|
||||
dataHolderType.ClassSize = (uint)size;
|
||||
_dataHolderTypeBySizes.Add(size, dataHolderType);
|
||||
_module.Types.Add(dataHolderType);
|
||||
Module.Types.Add(dataHolderType);
|
||||
return dataHolderType;
|
||||
}
|
||||
}
|
||||
|
|
@ -142,7 +168,7 @@ namespace Obfuz.Data
|
|||
encryptionOps = _random.NextInt(),
|
||||
salt = _random.NextInt(),
|
||||
};
|
||||
_rvaFields.Add(newRvaField);
|
||||
_currentRvaType.rvaFields.Add(newRvaField);
|
||||
return newRvaField;
|
||||
}
|
||||
|
||||
|
|
@ -230,10 +256,11 @@ namespace Obfuz.Data
|
|||
private void AddVerifyCodes(IList<Instruction> insts, DefaultMetadataImporter importer)
|
||||
{
|
||||
int verifyIntValue = 0x12345678;
|
||||
IRandom verifyRandom = _encryptionScope.localRandomCreator(verifyIntValue);
|
||||
int verifyOps = EncryptionUtil.GenerateEncryptionOpCodes(verifyRandom, _encryptionScope.encryptor, 4);
|
||||
EncryptionScopeInfo encryptionScope = this.EncryptionScope;
|
||||
IRandom verifyRandom = encryptionScope.localRandomCreator(verifyIntValue);
|
||||
int verifyOps = EncryptionUtil.GenerateEncryptionOpCodes(verifyRandom, encryptionScope.encryptor, EncryptionScopeInfo.MaxEncryptionLevel, false);
|
||||
int verifySalt = verifyRandom.NextInt();
|
||||
int encryptedVerifyIntValue = _encryptionScope.encryptor.Encrypt(verifyIntValue, verifyOps, verifySalt);
|
||||
int encryptedVerifyIntValue = encryptionScope.encryptor.Encrypt(verifyIntValue, verifyOps, verifySalt);
|
||||
|
||||
insts.Add(Instruction.Create(OpCodes.Ldc_I4, verifyIntValue));
|
||||
insts.Add(Instruction.CreateLdcI4(encryptedVerifyIntValue));
|
||||
|
|
@ -246,51 +273,50 @@ namespace Obfuz.Data
|
|||
|
||||
private void CreateCCtorOfRvaTypeDef()
|
||||
{
|
||||
if (_rvaTypeDef == null)
|
||||
foreach (RvaTypeDefInfo rvaTypeDef in _rvaTypeDefs)
|
||||
{
|
||||
return;
|
||||
ModuleDef mod = rvaTypeDef.typeDef.Module;
|
||||
var cctorMethod = new MethodDefUser(".cctor",
|
||||
MethodSig.CreateStatic(Module.CorLibTypes.Void),
|
||||
MethodImplAttributes.IL | MethodImplAttributes.Managed,
|
||||
MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Private);
|
||||
cctorMethod.DeclaringType = rvaTypeDef.typeDef;
|
||||
//_rvaTypeDef.Methods.Add(cctor);
|
||||
var body = new CilBody();
|
||||
cctorMethod.Body = body;
|
||||
var ins = body.Instructions;
|
||||
|
||||
DefaultMetadataImporter importer = this.GetDefaultModuleMetadataImporter();
|
||||
AddVerifyCodes(ins, importer);
|
||||
foreach (var field in rvaTypeDef.rvaFields)
|
||||
{
|
||||
// ldc
|
||||
// newarr
|
||||
// dup
|
||||
// stsfld
|
||||
// ldtoken
|
||||
// RuntimeHelpers.InitializeArray(array, fieldHandle);
|
||||
ins.Add(Instruction.Create(OpCodes.Ldc_I4, (int)field.size));
|
||||
ins.Add(Instruction.Create(OpCodes.Newarr, field.runtimeValueField.FieldType.Next.ToTypeDefOrRef()));
|
||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
||||
ins.Add(Instruction.Create(OpCodes.Stsfld, field.runtimeValueField));
|
||||
ins.Add(Instruction.Create(OpCodes.Ldtoken, field.holderDataField));
|
||||
ins.Add(Instruction.Create(OpCodes.Call, importer.InitializedArray));
|
||||
|
||||
// EncryptionService.DecryptBlock(array, field.encryptionOps, field.salt);
|
||||
ins.Add(Instruction.CreateLdcI4(field.encryptionOps));
|
||||
ins.Add(Instruction.Create(OpCodes.Ldc_I4, field.salt));
|
||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptBlock));
|
||||
|
||||
}
|
||||
ins.Add(Instruction.Create(OpCodes.Ret));
|
||||
}
|
||||
ModuleDef mod = _rvaTypeDef.Module;
|
||||
var cctorMethod = new MethodDefUser(".cctor",
|
||||
MethodSig.CreateStatic(_module.CorLibTypes.Void),
|
||||
MethodImplAttributes.IL | MethodImplAttributes.Managed,
|
||||
MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Private);
|
||||
cctorMethod.DeclaringType = _rvaTypeDef;
|
||||
//_rvaTypeDef.Methods.Add(cctor);
|
||||
var body = new CilBody();
|
||||
cctorMethod.Body = body;
|
||||
var ins = body.Instructions;
|
||||
|
||||
DefaultMetadataImporter importer = _moduleEntityManager.GetDefaultModuleMetadataImporter(mod, _encryptionScopeProvider);
|
||||
AddVerifyCodes(ins, importer);
|
||||
foreach (var field in _rvaFields)
|
||||
{
|
||||
// ldc
|
||||
// newarr
|
||||
// dup
|
||||
// stsfld
|
||||
// ldtoken
|
||||
// RuntimeHelpers.InitializeArray(array, fieldHandle);
|
||||
ins.Add(Instruction.Create(OpCodes.Ldc_I4, (int)field.size));
|
||||
ins.Add(Instruction.Create(OpCodes.Newarr, field.runtimeValueField.FieldType.Next.ToTypeDefOrRef()));
|
||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
||||
ins.Add(Instruction.Create(OpCodes.Stsfld, field.runtimeValueField));
|
||||
ins.Add(Instruction.Create(OpCodes.Ldtoken, field.holderDataField));
|
||||
ins.Add(Instruction.Create(OpCodes.Call, importer.InitializedArray));
|
||||
|
||||
// EncryptionService.DecryptBlock(array, field.encryptionOps, field.salt);
|
||||
ins.Add(Instruction.CreateLdcI4(field.encryptionOps));
|
||||
ins.Add(Instruction.Create(OpCodes.Ldc_I4, field.salt));
|
||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptBlock));
|
||||
|
||||
}
|
||||
ins.Add(Instruction.Create(OpCodes.Ret));
|
||||
}
|
||||
|
||||
private void SetFieldsRVA()
|
||||
{
|
||||
foreach (var field in _rvaFields)
|
||||
foreach (var field in _rvaTypeDefs.SelectMany(t => t.rvaFields))
|
||||
{
|
||||
Assert.IsTrue(field.bytes.Count <= field.size);
|
||||
if (field.bytes.Count < field.size)
|
||||
|
|
@ -298,12 +324,12 @@ namespace Obfuz.Data
|
|||
field.FillPaddingToEnd();
|
||||
}
|
||||
byte[] data = field.bytes.ToArray();
|
||||
_encryptionScope.encryptor.EncryptBlock(data, field.encryptionOps, field.salt);
|
||||
EncryptionScope.encryptor.EncryptBlock(data, field.encryptionOps, field.salt);
|
||||
field.holderDataField.InitialValue = data;
|
||||
}
|
||||
}
|
||||
|
||||
public void Done()
|
||||
public override void Done()
|
||||
{
|
||||
if (_done)
|
||||
{
|
||||
|
|
@ -314,59 +340,4 @@ namespace Obfuz.Data
|
|||
CreateCCtorOfRvaTypeDef();
|
||||
}
|
||||
}
|
||||
|
||||
public class RvaDataAllocator
|
||||
{
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||
|
||||
public RvaDataAllocator(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager)
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
_moduleEntityManager = moduleEntityManager;
|
||||
}
|
||||
|
||||
private ModuleRvaDataAllocator GetModuleRvaDataAllocator(ModuleDef mod)
|
||||
{
|
||||
return _moduleEntityManager.GetEntity<ModuleRvaDataAllocator>(mod, () => new ModuleRvaDataAllocator(_encryptionScopeProvider, _moduleEntityManager));
|
||||
}
|
||||
|
||||
public RvaData Allocate(ModuleDef mod, int value)
|
||||
{
|
||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public RvaData Allocate(ModuleDef mod, long value)
|
||||
{
|
||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public RvaData Allocate(ModuleDef mod, float value)
|
||||
{
|
||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public RvaData Allocate(ModuleDef mod, double value)
|
||||
{
|
||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public RvaData Allocate(ModuleDef mod, string value)
|
||||
{
|
||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public RvaData Allocate(ModuleDef mod, byte[] value)
|
||||
{
|
||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
||||
}
|
||||
|
||||
public void Done()
|
||||
{
|
||||
foreach (var allocator in _moduleEntityManager.GetEntities<ModuleRvaDataAllocator>())
|
||||
{
|
||||
allocator.Done();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
|
@ -104,30 +124,27 @@ namespace Obfuz.Emit
|
|||
Assert.IsNotNull(_decryptFromRvaBytes);
|
||||
_decryptFromRvaString = mod.Import(encryptionServiceType.GetMethod("DecryptFromRvaString", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) }));
|
||||
Assert.IsNotNull(_decryptFromRvaString);
|
||||
_decryptInitializeArray = mod.Import(encryptionServiceType.GetMethod("DecryptInitializeArray", new[] { typeof(System.Array), typeof(System.RuntimeFieldHandle), typeof(int), typeof(int), typeof(int) }));
|
||||
_decryptInitializeArray = mod.Import(encryptionServiceType.GetMethod("DecryptInitializeArray", new[] { typeof(System.Array), typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) }));
|
||||
Assert.IsNotNull(_decryptInitializeArray);
|
||||
}
|
||||
}
|
||||
|
||||
public class DefaultMetadataImporter : GroupByModuleEntityBase
|
||||
{
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private EncryptionScopeInfo _encryptionScope;
|
||||
private EncryptionServiceMetadataImporter _defaultEncryptionServiceMetadataImporter;
|
||||
|
||||
|
||||
private EncryptionServiceMetadataImporter _staticDefaultEncryptionServiceMetadataImporter;
|
||||
private EncryptionServiceMetadataImporter _dynamicDefaultEncryptionServiceMetadataImporter;
|
||||
|
||||
public DefaultMetadataImporter(EncryptionScopeProvider encryptionScopeProvider)
|
||||
public DefaultMetadataImporter()
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
}
|
||||
|
||||
public override void Init(ModuleDef mod)
|
||||
public override void Init()
|
||||
{
|
||||
_module = mod;
|
||||
_encryptionScope = _encryptionScopeProvider.GetScope(mod);
|
||||
ModuleDef mod = Module;
|
||||
|
||||
var constUtilityType = typeof(ConstUtility);
|
||||
|
||||
_castIntAsFloat = mod.Import(constUtilityType.GetMethod("CastIntAsFloat"));
|
||||
|
|
@ -141,7 +158,7 @@ namespace Obfuz.Emit
|
|||
|
||||
_initializeArray = mod.Import(typeof(System.Runtime.CompilerServices.RuntimeHelpers).GetMethod("InitializeArray", new[] { typeof(Array), typeof(RuntimeFieldHandle) }));
|
||||
Assert.IsNotNull(_initializeArray);
|
||||
_verifySecretKey = mod.Import(typeof(AssetUtility).GetMethod("VerifySecretKey", new[] { typeof(int), typeof(int) }));
|
||||
_verifySecretKey = mod.Import(typeof(AssertUtility).GetMethod("VerifySecretKey", new[] { typeof(int), typeof(int) }));
|
||||
Assert.IsNotNull(_verifySecretKey, "VerifySecretKey not found");
|
||||
|
||||
_obfuscationTypeMapperRegisterType = mod.Import(typeof(ObfuscationTypeMapper).GetMethod("RegisterType", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(string) }, null));
|
||||
|
|
@ -156,6 +173,11 @@ namespace Obfuz.Emit
|
|||
Assert.IsNotNull(_addFloat, "ExprUtility.Add(float, float) not found");
|
||||
_addDouble = mod.Import(exprUtilityType.GetMethod("Add", new[] { typeof(double), typeof(double) }));
|
||||
Assert.IsNotNull(_addDouble, "ExprUtility.Add(double, double) not found");
|
||||
_addIntPtr = mod.Import(exprUtilityType.GetMethod("Add", new[] { typeof(IntPtr), typeof(IntPtr) }));
|
||||
Assert.IsNotNull(_addIntPtr, "ExprUtility.Add(IntPtr, IntPtr) not found");
|
||||
_addIntPtrInt = mod.Import(exprUtilityType.GetMethod("Add", new[] { typeof(IntPtr), typeof(int) }));
|
||||
Assert.IsNotNull(_addIntPtrInt, "ExprUtility.Add(IntPtr, int) not found");
|
||||
|
||||
_subtractInt = mod.Import(exprUtilityType.GetMethod("Subtract", new[] { typeof(int), typeof(int) }));
|
||||
Assert.IsNotNull(_subtractInt, "ExprUtility.Subtract(int, int) not found");
|
||||
_subtractLong = mod.Import(exprUtilityType.GetMethod("Subtract", new[] { typeof(long), typeof(long) }));
|
||||
|
|
@ -164,6 +186,11 @@ namespace Obfuz.Emit
|
|||
Assert.IsNotNull(_subtractFloat, "ExprUtility.Subtract(float, float) not found");
|
||||
_subtractDouble = mod.Import(exprUtilityType.GetMethod("Subtract", new[] { typeof(double), typeof(double) }));
|
||||
Assert.IsNotNull(_subtractDouble, "ExprUtility.Subtract(double, double) not found");
|
||||
_subtractIntPtr = mod.Import(exprUtilityType.GetMethod("Subtract", new[] { typeof(IntPtr), typeof(IntPtr) }));
|
||||
Assert.IsNotNull(_subtractIntPtr, "ExprUtility.Subtract(IntPtr, IntPtr) not found");
|
||||
_subtractIntPtrInt = mod.Import(exprUtilityType.GetMethod("Subtract", new[] { typeof(IntPtr), typeof(int) }));
|
||||
Assert.IsNotNull(_subtractIntPtrInt, "ExprUtility.Subtract(IntPtr, int) not found");
|
||||
|
||||
_multiplyInt = mod.Import(exprUtilityType.GetMethod("Multiply", new[] { typeof(int), typeof(int) }));
|
||||
Assert.IsNotNull(_multiplyInt, "ExprUtility.Multiply(int, int) not found");
|
||||
_multiplyLong = mod.Import(exprUtilityType.GetMethod("Multiply", new[] { typeof(long), typeof(long) }));
|
||||
|
|
@ -172,6 +199,11 @@ namespace Obfuz.Emit
|
|||
Assert.IsNotNull(_multiplyFloat, "ExprUtility.Multiply(float, float) not found");
|
||||
_multiplyDouble = mod.Import(exprUtilityType.GetMethod("Multiply", new[] { typeof(double), typeof(double) }));
|
||||
Assert.IsNotNull(_multiplyDouble, "ExprUtility.Multiply(double, double) not found");
|
||||
_multiplyIntPtr = mod.Import(exprUtilityType.GetMethod("Multiply", new[] { typeof(IntPtr), typeof(IntPtr) }));
|
||||
Assert.IsNotNull(_multiplyIntPtr, "ExprUtility.Multiply(IntPtr, IntPtr) not found");
|
||||
_multiplyIntPtrInt = mod.Import(exprUtilityType.GetMethod("Multiply", new[] { typeof(IntPtr), typeof(int) }));
|
||||
Assert.IsNotNull(_multiplyIntPtrInt, "ExprUtility.Multiply(IntPtr, int) not found");
|
||||
|
||||
_divideInt = mod.Import(exprUtilityType.GetMethod("Divide", new[] { typeof(int), typeof(int) }));
|
||||
Assert.IsNotNull(_divideInt, "ExprUtility.Divide(int, int) not found");
|
||||
_divideLong = mod.Import(exprUtilityType.GetMethod("Divide", new[] { typeof(long), typeof(long) }));
|
||||
|
|
@ -238,7 +270,7 @@ namespace Obfuz.Emit
|
|||
|
||||
_staticDefaultEncryptionServiceMetadataImporter = new EncryptionServiceMetadataImporter(mod, typeof(EncryptionService<DefaultStaticEncryptionScope>));
|
||||
_dynamicDefaultEncryptionServiceMetadataImporter = new EncryptionServiceMetadataImporter(mod, typeof(EncryptionService<DefaultDynamicEncryptionScope>));
|
||||
if (_encryptionScopeProvider.IsDynamicSecretAssembly(mod))
|
||||
if (EncryptionScopeProvider.IsDynamicSecretAssembly(mod))
|
||||
{
|
||||
_defaultEncryptionServiceMetadataImporter = _dynamicDefaultEncryptionServiceMetadataImporter;
|
||||
}
|
||||
|
|
@ -248,9 +280,14 @@ namespace Obfuz.Emit
|
|||
}
|
||||
}
|
||||
|
||||
public override void Done()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EncryptionServiceMetadataImporter GetEncryptionServiceMetadataImporterOfModule(ModuleDef mod)
|
||||
{
|
||||
return _encryptionScopeProvider.IsDynamicSecretAssembly(mod) ? _dynamicDefaultEncryptionServiceMetadataImporter : _staticDefaultEncryptionServiceMetadataImporter;
|
||||
return EncryptionScopeProvider.IsDynamicSecretAssembly(mod) ? _dynamicDefaultEncryptionServiceMetadataImporter : _staticDefaultEncryptionServiceMetadataImporter;
|
||||
}
|
||||
|
||||
private ModuleDef _module;
|
||||
|
|
@ -267,14 +304,20 @@ namespace Obfuz.Emit
|
|||
private IMethod _addLong;
|
||||
private IMethod _addFloat;
|
||||
private IMethod _addDouble;
|
||||
private IMethod _addIntPtr;
|
||||
private IMethod _addIntPtrInt;
|
||||
private IMethod _subtractInt;
|
||||
private IMethod _subtractLong;
|
||||
private IMethod _subtractFloat;
|
||||
private IMethod _subtractDouble;
|
||||
private IMethod _subtractIntPtr;
|
||||
private IMethod _subtractIntPtrInt;
|
||||
private IMethod _multiplyInt;
|
||||
private IMethod _multiplyLong;
|
||||
private IMethod _multiplyFloat;
|
||||
private IMethod _multiplyDouble;
|
||||
private IMethod _multiplyIntPtr;
|
||||
private IMethod _multiplyIntPtrInt;
|
||||
private IMethod _divideInt;
|
||||
private IMethod _divideLong;
|
||||
private IMethod _divideFloat;
|
||||
|
|
@ -348,14 +391,22 @@ namespace Obfuz.Emit
|
|||
public IMethod AddLong => _addLong;
|
||||
public IMethod AddFloat => _addFloat;
|
||||
public IMethod AddDouble => _addDouble;
|
||||
public IMethod AddIntPtr => _addIntPtr;
|
||||
public IMethod AddIntPtrInt => _addIntPtrInt;
|
||||
public IMethod SubtractInt => _subtractInt;
|
||||
public IMethod SubtractLong => _subtractLong;
|
||||
public IMethod SubtractFloat => _subtractFloat;
|
||||
public IMethod SubtractDouble => _subtractDouble;
|
||||
public IMethod SubtractIntPtr => _subtractIntPtr;
|
||||
public IMethod SubtractIntPtrInt => _subtractIntPtrInt;
|
||||
|
||||
public IMethod MultiplyInt => _multiplyInt;
|
||||
public IMethod MultiplyLong => _multiplyLong;
|
||||
public IMethod MultiplyFloat => _multiplyFloat;
|
||||
public IMethod MultiplyDouble => _multiplyDouble;
|
||||
public IMethod MultiplyIntPtr => _multiplyIntPtr;
|
||||
public IMethod MultiplyIntPtrInt => _multiplyIntPtrInt;
|
||||
|
||||
public IMethod DivideInt => _divideInt;
|
||||
public IMethod DivideLong => _divideLong;
|
||||
public IMethod DivideFloat => _divideFloat;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
namespace Obfuz.Emit
|
||||
{
|
||||
public static class EntityExtensions
|
||||
{
|
||||
public static T GetEntity<T>(this IGroupByModuleEntity entity) where T : IGroupByModuleEntity, new()
|
||||
{
|
||||
return entity.Manager.GetEntity<T>(entity.Module);
|
||||
}
|
||||
|
||||
public static DefaultMetadataImporter GetDefaultModuleMetadataImporter(this IGroupByModuleEntity entity)
|
||||
{
|
||||
return entity.GetEntity<DefaultMetadataImporter>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e9557733f180764692756653eb60f88
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -6,19 +26,46 @@ namespace Obfuz.Emit
|
|||
{
|
||||
public interface IGroupByModuleEntity
|
||||
{
|
||||
void Init(ModuleDef mod);
|
||||
GroupByModuleEntityManager Manager { get; set; }
|
||||
|
||||
ModuleDef Module { get; set; }
|
||||
|
||||
EncryptionScopeProvider EncryptionScopeProvider { get; }
|
||||
|
||||
EncryptionScopeInfo EncryptionScope { get; set; }
|
||||
|
||||
void Init();
|
||||
|
||||
void Done();
|
||||
}
|
||||
|
||||
public abstract class GroupByModuleEntityBase : IGroupByModuleEntity
|
||||
{
|
||||
public abstract void Init(ModuleDef mod);
|
||||
public GroupByModuleEntityManager Manager { get; set; }
|
||||
|
||||
public ModuleDef Module { get; set; }
|
||||
|
||||
public EncryptionScopeInfo EncryptionScope { get; set; }
|
||||
|
||||
public EncryptionScopeProvider EncryptionScopeProvider => Manager.EncryptionScopeProvider;
|
||||
|
||||
public T GetEntity<T>() where T : IGroupByModuleEntity, new()
|
||||
{
|
||||
return Manager.GetEntity<T>(Module);
|
||||
}
|
||||
|
||||
public abstract void Init();
|
||||
|
||||
public abstract void Done();
|
||||
}
|
||||
|
||||
public class GroupByModuleEntityManager
|
||||
{
|
||||
private readonly Dictionary<(ModuleDef, Type), IGroupByModuleEntity> _moduleEntityManagers = new Dictionary<(ModuleDef, Type), IGroupByModuleEntity>();
|
||||
|
||||
public T GetEntity<T>(ModuleDef mod, Func<T> creator = null) where T : IGroupByModuleEntity
|
||||
public EncryptionScopeProvider EncryptionScopeProvider { get; set; }
|
||||
|
||||
public T GetEntity<T>(ModuleDef mod) where T : IGroupByModuleEntity, new()
|
||||
{
|
||||
var key = (mod, typeof(T));
|
||||
if (_moduleEntityManagers.TryGetValue(key, out var emitManager))
|
||||
|
|
@ -27,22 +74,17 @@ namespace Obfuz.Emit
|
|||
}
|
||||
else
|
||||
{
|
||||
T newEmitManager;
|
||||
if (creator != null)
|
||||
{
|
||||
newEmitManager = creator();
|
||||
}
|
||||
else
|
||||
{
|
||||
newEmitManager = (T)Activator.CreateInstance(typeof(T));
|
||||
}
|
||||
newEmitManager.Init(mod);
|
||||
T newEmitManager = new T();
|
||||
newEmitManager.Manager = this;
|
||||
newEmitManager.Module = mod;
|
||||
newEmitManager.EncryptionScope = EncryptionScopeProvider.GetScope(mod);
|
||||
newEmitManager.Init();
|
||||
_moduleEntityManagers[key] = newEmitManager;
|
||||
return newEmitManager;
|
||||
}
|
||||
}
|
||||
|
||||
public List<T> GetEntities<T>() where T : IGroupByModuleEntity
|
||||
public List<T> GetEntities<T>() where T : IGroupByModuleEntity, new()
|
||||
{
|
||||
var managers = new List<T>();
|
||||
foreach (var kv in _moduleEntityManagers)
|
||||
|
|
@ -55,9 +97,13 @@ namespace Obfuz.Emit
|
|||
return managers;
|
||||
}
|
||||
|
||||
public DefaultMetadataImporter GetDefaultModuleMetadataImporter(ModuleDef module, EncryptionScopeProvider encryptionScopeProvider)
|
||||
public void Done<T>() where T : IGroupByModuleEntity, new()
|
||||
{
|
||||
return GetEntity<DefaultMetadataImporter>(module, () => new DefaultMetadataImporter(encryptionScopeProvider));
|
||||
var managers = GetEntities<T>();
|
||||
foreach (var manager in managers)
|
||||
{
|
||||
manager.Done();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using System;
|
||||
|
|
@ -11,6 +31,8 @@ namespace Obfuz.Emit
|
|||
|
||||
private readonly List<Local> _allocatedVars = new List<Local>();
|
||||
|
||||
public IReadOnlyList<Local> AllocatedLocals => _allocatedVars;
|
||||
|
||||
|
||||
public ScopeLocalVariables(LocalVariableAllocator localVariableAllocator)
|
||||
{
|
||||
|
|
@ -63,5 +85,10 @@ namespace Obfuz.Emit
|
|||
{
|
||||
_freeLocals.Add(local);
|
||||
}
|
||||
|
||||
public ScopeLocalVariables CreateScope()
|
||||
{
|
||||
return new ScopeLocalVariables(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
namespace Obfuz.EncryptionVM
|
||||
{
|
||||
public class EncryptionInstructionWithOpCode
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.EncryptionVM
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.EncryptionVM.Instructions
|
||||
|
|
@ -29,7 +49,7 @@ namespace Obfuz.EncryptionVM.Instructions
|
|||
|
||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
||||
{
|
||||
lines.Add(indent + $"value = ((value - {_addValue}) ^ salt) - _secretKey[{_opKeyIndex}];");
|
||||
lines.Add(indent + $"value = ((value - {_addValue}) ^ salt) - _secretKey[{_opKeyIndex}];");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.EncryptionVM.Instructions
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.EncryptionVM.Instructions
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.EncryptionVM.Instructions
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,24 @@
|
|||
using NUnit.Framework;
|
||||
using Obfuz.Utils;
|
||||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.EncryptionVM.Instructions
|
||||
|
|
@ -21,7 +40,7 @@ namespace Obfuz.EncryptionVM.Instructions
|
|||
private void Verify()
|
||||
{
|
||||
int a = 1122334;
|
||||
Assert.AreEqual(a, a * _multiValue * _revertMultiValue);
|
||||
UnityEngine.Assertions.Assert.AreEqual(a, a * _multiValue * _revertMultiValue);
|
||||
}
|
||||
|
||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
||||
|
|
@ -36,7 +55,7 @@ namespace Obfuz.EncryptionVM.Instructions
|
|||
|
||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
||||
{
|
||||
lines.Add(indent + $"value = value * {_multiValue} + _secretKey[{_opKeyIndex}] + salt;");
|
||||
lines.Add(indent + $"value = value * {_multiValue} + _secretKey[{_opKeyIndex}] + salt;");
|
||||
}
|
||||
|
||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.EncryptionVM.Instructions
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.EncryptionVM.Instructions
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
namespace Obfuz.EncryptionVM
|
||||
{
|
||||
public class VirtualMachine
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
@ -73,7 +93,7 @@ namespace Obfuz.EncryptionVM
|
|||
{");
|
||||
foreach (var opCode in _vm.opCodes)
|
||||
{
|
||||
lines.Add($@" case {opCode.code}:
|
||||
lines.Add($@" case {opCode.code}:
|
||||
{{
|
||||
// {opCode.function.GetType().Name}");
|
||||
AppendEncryptCode(lines, opCode.function);
|
||||
|
|
@ -82,8 +102,7 @@ namespace Obfuz.EncryptionVM
|
|||
}
|
||||
|
||||
lines.Add(@"
|
||||
default:
|
||||
throw new System.Exception($""Invalid opCode:{opCode}"");
|
||||
default: throw new System.Exception($""Invalid opCode:{opCode}"");
|
||||
}
|
||||
}");
|
||||
}
|
||||
|
|
@ -97,7 +116,7 @@ namespace Obfuz.EncryptionVM
|
|||
{");
|
||||
foreach (var opCode in _vm.opCodes)
|
||||
{
|
||||
lines.Add($@" case {opCode.code}:
|
||||
lines.Add($@" case {opCode.code}:
|
||||
{{
|
||||
// {opCode.function.GetType().Name}");
|
||||
AppendDecryptCode(lines, opCode.function);
|
||||
|
|
@ -106,8 +125,7 @@ namespace Obfuz.EncryptionVM
|
|||
}
|
||||
|
||||
lines.Add(@"
|
||||
default:
|
||||
throw new System.Exception($""Invalid opCode:{opCode}"");
|
||||
default: throw new System.Exception($""Invalid opCode:{opCode}"");
|
||||
}
|
||||
}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.EncryptionVM.Instructions;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Assertions;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,25 @@
|
|||
using dnlib.DotNet;
|
||||
using NUnit.Framework;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,26 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obfuz.GarbageCodeGeneration
|
||||
|
|
@ -14,10 +30,10 @@ namespace Obfuz.GarbageCodeGeneration
|
|||
{
|
||||
private const int CodeGenerationSecretKeyLength = 1024;
|
||||
|
||||
private readonly GarbageCodeGeneratorSettings _settings;
|
||||
private readonly GarbageCodeGenerationSettings _settings;
|
||||
private readonly int[] _intGenerationSecretKey;
|
||||
|
||||
public GarbageCodeGenerator(GarbageCodeGeneratorSettings settings)
|
||||
public GarbageCodeGenerator(GarbageCodeGenerationSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
|
||||
|
|
@ -55,14 +71,14 @@ namespace Obfuz.GarbageCodeGeneration
|
|||
|
||||
private void GenerateTask(GarbageCodeGenerationTask task)
|
||||
{
|
||||
Debug.Log($"Generating garbage code with seed: {task.codeGenerationRandomSeed}, class count: {task.classCount}, method count per class: {task.methodCountPerClass}, types: {task.garbageCodeTypes}, output path: {task.outputPath}");
|
||||
Debug.Log($"Generating garbage code with seed: {task.codeGenerationRandomSeed}, class count: {task.classCount}, method count per class: {task.methodCountPerClass}, types: {task.garbageCodeType}, output path: {task.outputPath}");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(task.outputPath))
|
||||
{
|
||||
throw new Exception("outputPath of GarbageCodeGenerationTask is empty!");
|
||||
}
|
||||
|
||||
var generator = CreateSpecificCodeGenerator(task.garbageCodeTypes);
|
||||
var generator = CreateSpecificCodeGenerator(task.garbageCodeType);
|
||||
|
||||
var parameters = new GenerationParameters
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,24 @@
|
|||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
|
||||
namespace Obfuz.GarbageCodeGeneration
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,25 @@
|
|||
using dnlib.DotNet;
|
||||
using NUnit.Framework;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using Obfuz.ObfusPasses;
|
||||
|
||||
namespace Obfuz
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
|
|
@ -7,19 +27,30 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
public class CallObfusPass : BasicBlockObfuscationPassBase
|
||||
class ObfusMethodContext
|
||||
{
|
||||
public MethodDef method;
|
||||
public LocalVariableAllocator localVariableAllocator;
|
||||
public IRandom localRandom;
|
||||
public EncryptionScopeInfo encryptionScope;
|
||||
}
|
||||
|
||||
public class CallObfusPass : ObfuscationMethodPassBase
|
||||
{
|
||||
public static CallObfuscationSettingsFacade CurrentSettings { get; private set; }
|
||||
|
||||
private readonly CallObfuscationSettingsFacade _settings;
|
||||
private SpecialWhiteListMethodCalculator _specialWhiteListMethodCache;
|
||||
|
||||
private IObfuscator _dynamicProxyObfuscator;
|
||||
private IObfuscationPolicy _dynamicProxyPolicy;
|
||||
private readonly CachedDictionary<IMethod, bool> _specialwhiteListMethodCache;
|
||||
|
||||
public override ObfuscationPassType Type => ObfuscationPassType.CallObfus;
|
||||
|
||||
public CallObfusPass(CallObfuscationSettingsFacade settings)
|
||||
{
|
||||
_settings = settings;
|
||||
_specialwhiteListMethodCache = new CachedDictionary<IMethod, bool>(MethodEqualityComparer.CompareDeclaringTypes, this.ComputeIsInWhiteList);
|
||||
CurrentSettings = settings;
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
|
|
@ -30,117 +61,82 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
public override void Start()
|
||||
{
|
||||
var ctx = ObfuscationPassContext.Current;
|
||||
_dynamicProxyObfuscator = new DefaultCallProxyObfuscator(ctx.encryptionScopeProvider, ctx.constFieldAllocator, ctx.moduleEntityManager, _settings);
|
||||
|
||||
_specialWhiteListMethodCache = new SpecialWhiteListMethodCalculator(ctx.coreSettings.targetRuntime, _settings.obfuscateCallToMethodInMscorlib);
|
||||
_dynamicProxyObfuscator = CreateObfuscator(ctx, _settings.proxyMode);
|
||||
_dynamicProxyPolicy = new ConfigurableObfuscationPolicy(ctx.coreSettings.assembliesToObfuscate, _settings.ruleFiles);
|
||||
}
|
||||
|
||||
private IObfuscator CreateObfuscator(ObfuscationPassContext ctx, ProxyMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case ProxyMode.Dispatch:
|
||||
return new DispatchProxyObfuscator(ctx.moduleEntityManager);
|
||||
case ProxyMode.Delegate:
|
||||
return new DelegateProxyObfuscator(ctx.moduleEntityManager);
|
||||
default:
|
||||
throw new System.NotSupportedException($"Unsupported proxy mode: {mode}");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ObfuscateData(MethodDef method)
|
||||
{
|
||||
BasicBlockCollection bbc = new BasicBlockCollection(method, false);
|
||||
|
||||
IList<Instruction> instructions = method.Body.Instructions;
|
||||
|
||||
var outputInstructions = new List<Instruction>();
|
||||
var totalFinalInstructions = new List<Instruction>();
|
||||
|
||||
ObfuscationPassContext ctx = ObfuscationPassContext.Current;
|
||||
var encryptionScope = ctx.moduleEntityManager.EncryptionScopeProvider.GetScope(method.Module);
|
||||
var localRandom = encryptionScope.localRandomCreator(MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method));
|
||||
var omc = new ObfusMethodContext
|
||||
{
|
||||
method = method,
|
||||
localVariableAllocator = new LocalVariableAllocator(method),
|
||||
localRandom = localRandom,
|
||||
encryptionScope = encryptionScope,
|
||||
};
|
||||
Instruction lastInst = null;
|
||||
for (int i = 0; i < instructions.Count; i++)
|
||||
{
|
||||
Instruction inst = instructions[i];
|
||||
BasicBlock block = bbc.GetBasicBlockByInstruction(inst);
|
||||
outputInstructions.Clear();
|
||||
if (TryObfuscateInstruction(method, lastInst, inst, outputInstructions, omc))
|
||||
{
|
||||
// current instruction may be the target of control flow instruction, so we can't remove it directly.
|
||||
// we replace it with nop now, then remove it in CleanUpInstructionPass
|
||||
inst.OpCode = outputInstructions[0].OpCode;
|
||||
inst.Operand = outputInstructions[0].Operand;
|
||||
totalFinalInstructions.Add(inst);
|
||||
for (int k = 1; k < outputInstructions.Count; k++)
|
||||
{
|
||||
totalFinalInstructions.Add(outputInstructions[k]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
totalFinalInstructions.Add(inst);
|
||||
}
|
||||
lastInst = inst;
|
||||
}
|
||||
|
||||
instructions.Clear();
|
||||
foreach (var obInst in totalFinalInstructions)
|
||||
{
|
||||
instructions.Add(obInst);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool NeedObfuscateMethod(MethodDef method)
|
||||
{
|
||||
return _dynamicProxyPolicy.NeedObfuscateCallInMethod(method);
|
||||
}
|
||||
|
||||
|
||||
private static readonly HashSet<string> _specialTypeFullNames = new HashSet<string>
|
||||
{
|
||||
"System.Enum",
|
||||
"System.Delegate",
|
||||
"System.MulticastDelegate",
|
||||
"Obfuz.EncryptionService`1",
|
||||
};
|
||||
|
||||
private static readonly HashSet<string> _specialMethodNames = new HashSet<string>
|
||||
{
|
||||
"GetEnumerator", // List<T>.Enumerator.GetEnumerator()
|
||||
".ctor", // constructor
|
||||
};
|
||||
|
||||
private static readonly HashSet<string> _specialMethodFullNames = new HashSet<string>
|
||||
{
|
||||
"System.Reflection.MethodBase.GetCurrentMethod",
|
||||
"System.Reflection.Assembly.GetCallingAssembly",
|
||||
"System.Reflection.Assembly.GetExecutingAssembly",
|
||||
"System.Reflection.Assembly.GetEntryAssembly",
|
||||
};
|
||||
|
||||
private bool ComputeIsInWhiteList(IMethod calledMethod)
|
||||
{
|
||||
MethodDef calledMethodDef = calledMethod.ResolveMethodDef();
|
||||
// mono has more strict access control, calls non-public method will raise exception.
|
||||
if (PlatformUtil.IsMonoBackend())
|
||||
{
|
||||
if (calledMethodDef != null && (!calledMethodDef.IsPublic || !IsTypeSelfAndParentPublic(calledMethodDef.DeclaringType)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ITypeDefOrRef declaringType = calledMethod.DeclaringType;
|
||||
TypeSig declaringTypeSig = calledMethod.DeclaringType.ToTypeSig();
|
||||
declaringTypeSig = declaringTypeSig.RemovePinnedAndModifiers();
|
||||
switch (declaringTypeSig.ElementType)
|
||||
{
|
||||
case ElementType.ValueType:
|
||||
case ElementType.Class:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case ElementType.GenericInst:
|
||||
{
|
||||
if (MetaUtil.ContainsContainsGenericParameter(calledMethod))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: return true;
|
||||
}
|
||||
|
||||
TypeDef typeDef = declaringType.ResolveTypeDef();
|
||||
|
||||
if (!_settings.obfuscateCallToMethodInMscorlib && typeDef.Module.IsCoreLibraryModule == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeDef.IsDelegate || typeDef.IsEnum)
|
||||
return true;
|
||||
|
||||
string fullName = typeDef.FullName;
|
||||
if (_specialTypeFullNames.Contains(fullName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//if (fullName.StartsWith("System.Runtime.CompilerServices."))
|
||||
//{
|
||||
// return true;
|
||||
//}
|
||||
|
||||
string methodName = calledMethod.Name;
|
||||
if (_specialMethodNames.Contains(methodName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
string methodFullName = $"{fullName}.{methodName}";
|
||||
if (_specialMethodFullNames.Contains(methodFullName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsTypeSelfAndParentPublic(TypeDef type)
|
||||
{
|
||||
if (type.DeclaringType != null && !IsTypeSelfAndParentPublic(type.DeclaringType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return type.IsPublic;
|
||||
}
|
||||
|
||||
protected override bool TryObfuscateInstruction(MethodDef callerMethod, Instruction inst, BasicBlock block,
|
||||
int instructionIndex, IList<Instruction> globalInstructions, List<Instruction> outputInstructions, List<Instruction> totalFinalInstructions)
|
||||
private bool TryObfuscateInstruction(MethodDef callerMethod, Instruction lastInst, Instruction inst, List<Instruction> outputInstructions, ObfusMethodContext ctx)
|
||||
{
|
||||
IMethod calledMethod = inst.Operand as IMethod;
|
||||
if (calledMethod == null || !calledMethod.IsMethod)
|
||||
|
|
@ -162,7 +158,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
}
|
||||
case Code.Callvirt:
|
||||
{
|
||||
if (instructionIndex > 0 && globalInstructions[instructionIndex - 1].OpCode.Code == Code.Constrained)
|
||||
if (lastInst != null && lastInst.OpCode.Code == Code.Constrained)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -173,21 +169,18 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
}
|
||||
|
||||
|
||||
if (_specialwhiteListMethodCache.GetValue(calledMethod))
|
||||
if (_specialWhiteListMethodCache.IsInWhiteList(calledMethod))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!_dynamicProxyPolicy.NeedObfuscateCalledMethod(callerMethod, calledMethod, callVir, block.inLoop))
|
||||
if (!_dynamicProxyPolicy.NeedObfuscateCalledMethod(callerMethod, calledMethod, callVir))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ObfuscationCachePolicy cachePolicy = _dynamicProxyPolicy.GetMethodObfuscationCachePolicy(callerMethod);
|
||||
bool cachedCallIndex = block.inLoop ? cachePolicy.cacheInLoop : cachePolicy.cacheNotInLoop;
|
||||
_dynamicProxyObfuscator.Obfuscate(callerMethod, calledMethod, callVir, cachedCallIndex, outputInstructions);
|
||||
return true;
|
||||
return _dynamicProxyObfuscator.Obfuscate(callerMethod, calledMethod, callVir, outputInstructions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,26 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Conf;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -34,29 +55,12 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
class ObfuscationRule : IRule<ObfuscationRule>
|
||||
{
|
||||
public bool? disableObfuscation;
|
||||
public bool? obfuscateCallInLoop;
|
||||
public bool? cacheCallIndexInLoop;
|
||||
public bool? cacheCallIndexNotLoop;
|
||||
public ObfuscationLevel? obfuscationLevel;
|
||||
|
||||
public void InheritParent(ObfuscationRule parentRule)
|
||||
{
|
||||
if (disableObfuscation == null)
|
||||
{
|
||||
disableObfuscation = parentRule.disableObfuscation;
|
||||
}
|
||||
if (obfuscateCallInLoop == null)
|
||||
{
|
||||
obfuscateCallInLoop = parentRule.obfuscateCallInLoop;
|
||||
}
|
||||
if (cacheCallIndexInLoop == null)
|
||||
{
|
||||
cacheCallIndexInLoop = parentRule.cacheCallIndexInLoop;
|
||||
}
|
||||
if (cacheCallIndexNotLoop == null)
|
||||
{
|
||||
cacheCallIndexNotLoop = parentRule.cacheCallIndexNotLoop;
|
||||
}
|
||||
if (obfuscationLevel == null)
|
||||
obfuscationLevel = parentRule.obfuscationLevel;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,10 +79,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
private static readonly ObfuscationRule s_default = new ObfuscationRule()
|
||||
{
|
||||
disableObfuscation = false,
|
||||
obfuscateCallInLoop = true,
|
||||
cacheCallIndexInLoop = true,
|
||||
cacheCallIndexNotLoop = true,
|
||||
obfuscationLevel = ObfuscationLevel.Basic,
|
||||
};
|
||||
|
||||
private readonly XmlAssemblyTypeMethodRuleParser<AssemblySpec, TypeSpec, MethodSpec, ObfuscationRule> _configParser;
|
||||
|
|
@ -147,21 +148,9 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
private ObfuscationRule ParseObfuscationRule(string configFile, XmlElement ele)
|
||||
{
|
||||
var rule = new ObfuscationRule();
|
||||
if (ele.HasAttribute("disableObfuscation"))
|
||||
if (ele.HasAttribute("obfuscationLevel"))
|
||||
{
|
||||
rule.disableObfuscation = ConfigUtil.ParseBool(ele.GetAttribute("disableObfuscation"));
|
||||
}
|
||||
if (ele.HasAttribute("obfuscateCallInLoop"))
|
||||
{
|
||||
rule.obfuscateCallInLoop = ConfigUtil.ParseBool(ele.GetAttribute("obfuscateCallInLoop"));
|
||||
}
|
||||
if (ele.HasAttribute("cacheCallIndexInLoop"))
|
||||
{
|
||||
rule.cacheCallIndexInLoop = ConfigUtil.ParseBool(ele.GetAttribute("cacheCallIndexInLoop"));
|
||||
}
|
||||
if (ele.HasAttribute("cacheCallIndexNotLoop"))
|
||||
{
|
||||
rule.cacheCallIndexNotLoop = ConfigUtil.ParseBool(ele.GetAttribute("cacheCallIndexNotLoop"));
|
||||
rule.obfuscationLevel = ConfigUtil.ParseObfuscationLevel(ele.GetAttribute("obfuscationLevel"));
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
|
@ -262,17 +251,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
public override bool NeedObfuscateCallInMethod(MethodDef method)
|
||||
{
|
||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
||||
return rule.disableObfuscation != true;
|
||||
}
|
||||
|
||||
public override ObfuscationCachePolicy GetMethodObfuscationCachePolicy(MethodDef method)
|
||||
{
|
||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
||||
return new ObfuscationCachePolicy()
|
||||
{
|
||||
cacheInLoop = rule.cacheCallIndexInLoop.Value,
|
||||
cacheNotInLoop = rule.cacheCallIndexNotLoop.Value,
|
||||
};
|
||||
return rule.obfuscationLevel != null && rule.obfuscationLevel.Value >= ObfuscationLevel.Basic;
|
||||
}
|
||||
|
||||
private bool ComputeIsInWhiteList(IMethod calledMethod)
|
||||
|
|
@ -329,18 +308,12 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
return false;
|
||||
}
|
||||
|
||||
public override bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool currentInLoop)
|
||||
public override bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir)
|
||||
{
|
||||
if (_whiteListMethodCache.GetValue(calledMethod))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ObfuscationRule rule = GetMethodObfuscationRule(callerMethod);
|
||||
if (currentInLoop && rule.obfuscateCallInLoop == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Data;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
public class DefaultCallProxyObfuscator : ObfuscatorBase
|
||||
{
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private readonly ConstFieldAllocator _constFieldAllocator;
|
||||
private readonly CallProxyAllocator _proxyCallAllocator;
|
||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||
|
||||
public DefaultCallProxyObfuscator(EncryptionScopeProvider encryptionScopeProvider, ConstFieldAllocator constFieldAllocator, GroupByModuleEntityManager moduleEntityManager, CallObfuscationSettingsFacade settings)
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
_constFieldAllocator = constFieldAllocator;
|
||||
_moduleEntityManager = moduleEntityManager;
|
||||
_proxyCallAllocator = new CallProxyAllocator(encryptionScopeProvider, moduleEntityManager, settings);
|
||||
}
|
||||
|
||||
public override void Done()
|
||||
{
|
||||
_proxyCallAllocator.Done();
|
||||
}
|
||||
|
||||
public override void Obfuscate(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool needCacheCall, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
|
||||
MethodSig sharedMethodSig = MetaUtil.ToSharedMethodSig(calledMethod.Module.CorLibTypes, MetaUtil.GetInflatedMethodSig(calledMethod, null));
|
||||
ProxyCallMethodData proxyCallMethodData = _proxyCallAllocator.Allocate(callerMethod.Module, calledMethod, callVir);
|
||||
DefaultMetadataImporter importer = _moduleEntityManager.GetDefaultModuleMetadataImporter(callerMethod.Module, _encryptionScopeProvider);
|
||||
|
||||
if (needCacheCall)
|
||||
{
|
||||
FieldDef cacheField = _constFieldAllocator.Allocate(callerMethod.Module, proxyCallMethodData.index);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
}
|
||||
else
|
||||
{
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(proxyCallMethodData.encryptedIndex));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(proxyCallMethodData.encryptOps));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(proxyCallMethodData.salt));
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptInt));
|
||||
}
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, proxyCallMethodData.proxyMethod));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,285 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Data;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
|
||||
struct DelegateProxyMethodData
|
||||
{
|
||||
public readonly FieldDef delegateInstanceField;
|
||||
public readonly MethodDef delegateInvokeMethod;
|
||||
|
||||
public DelegateProxyMethodData(FieldDef delegateInstanceField, MethodDef delegateInvokeMethod)
|
||||
{
|
||||
this.delegateInstanceField = delegateInstanceField;
|
||||
this.delegateInvokeMethod = delegateInvokeMethod;
|
||||
}
|
||||
}
|
||||
|
||||
class DelegateProxyAllocator : GroupByModuleEntityBase
|
||||
{
|
||||
private readonly CachedDictionary<MethodSig, TypeDef> _delegateTypes;
|
||||
private readonly HashSet<string> _allocatedDelegateNames = new HashSet<string>();
|
||||
|
||||
private TypeDef _delegateInstanceHolderType;
|
||||
private bool _done;
|
||||
|
||||
class CallInfo
|
||||
{
|
||||
public string key1;
|
||||
public int key2;
|
||||
public IMethod method;
|
||||
public bool callVir;
|
||||
|
||||
public int index;
|
||||
public TypeDef delegateType;
|
||||
public FieldDef delegateInstanceField;
|
||||
public MethodDef delegateInvokeMethod;
|
||||
public MethodDef proxyMethod;
|
||||
}
|
||||
private readonly Dictionary<MethodKey, CallInfo> _callMethods = new Dictionary<MethodKey, CallInfo>();
|
||||
private CallObfuscationSettingsFacade _settings;
|
||||
|
||||
public DelegateProxyAllocator()
|
||||
{
|
||||
_delegateTypes = new CachedDictionary<MethodSig, TypeDef>(SignatureEqualityComparer.Instance, CreateDelegateForSignature);
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
_delegateInstanceHolderType = CreateDelegateInstanceHolderTypeDef();
|
||||
_settings = CallObfusPass.CurrentSettings;
|
||||
}
|
||||
|
||||
private string AllocateDelegateTypeName(MethodSig delegateInvokeSig)
|
||||
{
|
||||
uint hashCode = (uint)SignatureEqualityComparer.Instance.GetHashCode(delegateInvokeSig);
|
||||
string typeName = $"$Obfuz$Delegate_{hashCode}";
|
||||
if (_allocatedDelegateNames.Add(typeName))
|
||||
{
|
||||
return typeName;
|
||||
}
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
typeName = $"$Obfuz$Delegate_{hashCode}_{i}";
|
||||
if (_allocatedDelegateNames.Add(typeName))
|
||||
{
|
||||
return typeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TypeDef CreateDelegateForSignature(MethodSig delegateInvokeSig)
|
||||
{
|
||||
ModuleDef mod = Module;
|
||||
using (var scope = new DisableTypeDefFindCacheScope(mod))
|
||||
{
|
||||
|
||||
string typeName = AllocateDelegateTypeName(delegateInvokeSig);
|
||||
mod.Import(typeof(MulticastDelegate));
|
||||
|
||||
TypeDef delegateType = new TypeDefUser("", typeName, mod.CorLibTypes.GetTypeRef("System", "MulticastDelegate"));
|
||||
delegateType.Attributes = TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public;
|
||||
mod.Types.Add(delegateType);
|
||||
|
||||
MethodDef ctor = new MethodDefUser(
|
||||
".ctor",
|
||||
MethodSig.CreateInstance(mod.CorLibTypes.Void, mod.CorLibTypes.Object, mod.CorLibTypes.IntPtr),
|
||||
MethodImplAttributes.Runtime,
|
||||
MethodAttributes.RTSpecialName | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public
|
||||
);
|
||||
ctor.DeclaringType = delegateType;
|
||||
|
||||
|
||||
MethodDef invokeMethod = new MethodDefUser(
|
||||
"Invoke",
|
||||
MethodSig.CreateInstance(delegateInvokeSig.RetType, delegateInvokeSig.Params.ToArray()),
|
||||
MethodImplAttributes.Runtime,
|
||||
MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.NewSlot | MethodAttributes.Virtual
|
||||
);
|
||||
invokeMethod.DeclaringType = delegateType;
|
||||
return delegateType;
|
||||
}
|
||||
}
|
||||
|
||||
private TypeDef CreateDelegateInstanceHolderTypeDef()
|
||||
{
|
||||
ModuleDef mod = Module;
|
||||
using (var scope = new DisableTypeDefFindCacheScope(mod))
|
||||
{
|
||||
string typeName = "$Obfuz$DelegateInstanceHolder";
|
||||
TypeDef holderType = new TypeDefUser("", typeName, mod.CorLibTypes.Object.ToTypeDefOrRef());
|
||||
holderType.Attributes = TypeAttributes.Class | TypeAttributes.Public;
|
||||
mod.Types.Add(holderType);
|
||||
return holderType;
|
||||
}
|
||||
}
|
||||
|
||||
private string AllocateFieldName(IMethod method, bool callVir)
|
||||
{
|
||||
uint hashCode = (uint)MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method);
|
||||
string typeName = $"$Obfuz$Delegate$Field_{hashCode}_{callVir}";
|
||||
if (_allocatedDelegateNames.Add(typeName))
|
||||
{
|
||||
return typeName;
|
||||
}
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
typeName = $"$Obfuz$Delegate$Field_{hashCode}_{callVir}_{i}";
|
||||
if (_allocatedDelegateNames.Add(typeName))
|
||||
{
|
||||
return typeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MethodDef CreateProxyMethod(string name, IMethod calledMethod, bool callVir, MethodSig delegateInvokeSig)
|
||||
{
|
||||
var proxyMethod = new MethodDefUser(name, delegateInvokeSig, MethodImplAttributes.Managed, MethodAttributes.Public | MethodAttributes.Static);
|
||||
var body = new CilBody();
|
||||
proxyMethod.Body = body;
|
||||
var ins = body.Instructions;
|
||||
|
||||
foreach (Parameter param in proxyMethod.Parameters)
|
||||
{
|
||||
ins.Add(Instruction.Create(OpCodes.Ldarg, param));
|
||||
}
|
||||
|
||||
ins.Add(Instruction.Create(callVir ? OpCodes.Callvirt : OpCodes.Call, calledMethod));
|
||||
ins.Add(Instruction.Create(OpCodes.Ret));
|
||||
return proxyMethod;
|
||||
}
|
||||
|
||||
public DelegateProxyMethodData Allocate(IMethod method, bool callVir, MethodSig delegateInvokeSig)
|
||||
{
|
||||
var key = new MethodKey(method, callVir);
|
||||
if (!_callMethods.TryGetValue(key, out var callInfo))
|
||||
{
|
||||
TypeDef delegateType = _delegateTypes.GetValue(delegateInvokeSig);
|
||||
MethodDef delegateInvokeMethod = delegateType.FindMethod("Invoke");
|
||||
string fieldName = AllocateFieldName(method, callVir);
|
||||
FieldDef delegateInstanceField = new FieldDefUser(fieldName, new FieldSig(delegateType.ToTypeSig()), FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.InitOnly);
|
||||
string key1 = $"{method.FullName}_{callVir}";
|
||||
callInfo = new CallInfo
|
||||
{
|
||||
key1 = key1,
|
||||
key2 = HashUtil.ComputePrimitiveOrStringOrBytesHashCode(key1) * 33445566,
|
||||
method = method,
|
||||
callVir = callVir,
|
||||
delegateType = delegateType,
|
||||
delegateInstanceField = delegateInstanceField,
|
||||
delegateInvokeMethod = delegateInvokeMethod,
|
||||
proxyMethod = CreateProxyMethod($"{fieldName}$Proxy", method, callVir, delegateInvokeSig),
|
||||
};
|
||||
_callMethods.Add(key, callInfo);
|
||||
}
|
||||
return new DelegateProxyMethodData(callInfo.delegateInstanceField, callInfo.delegateInvokeMethod);
|
||||
}
|
||||
|
||||
public override void Done()
|
||||
{
|
||||
if (_done)
|
||||
{
|
||||
throw new Exception("Already done");
|
||||
}
|
||||
_done = true;
|
||||
|
||||
ModuleDef mod = Module;
|
||||
|
||||
// for stable order, we sort methods by name
|
||||
List<CallInfo> callMethodList = _callMethods.Values.ToList();
|
||||
callMethodList.Sort((a, b) => a.key1.CompareTo(b.key1));
|
||||
|
||||
var cctor = new MethodDefUser(".cctor",
|
||||
MethodSig.CreateStatic(mod.CorLibTypes.Void),
|
||||
MethodImplAttributes.IL | MethodImplAttributes.Managed,
|
||||
MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Private);
|
||||
cctor.DeclaringType = _delegateInstanceHolderType;
|
||||
//_rvaTypeDef.Methods.Add(cctor);
|
||||
var body = new CilBody();
|
||||
cctor.Body = body;
|
||||
var ins = body.Instructions;
|
||||
|
||||
// var arr = new array[];
|
||||
// var d = new delegate;
|
||||
// arr[index] = d;
|
||||
int index = 0;
|
||||
ins.Add(Instruction.CreateLdcI4(callMethodList.Count));
|
||||
ins.Add(Instruction.Create(OpCodes.Newarr, mod.CorLibTypes.Object));
|
||||
foreach (CallInfo ci in callMethodList)
|
||||
{
|
||||
ci.index = index;
|
||||
_delegateInstanceHolderType.Methods.Add(ci.proxyMethod);
|
||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
||||
ins.Add(Instruction.CreateLdcI4(index));
|
||||
ins.Add(Instruction.Create(OpCodes.Ldnull));
|
||||
ins.Add(Instruction.Create(OpCodes.Ldftn, ci.proxyMethod));
|
||||
MethodDef ctor = ci.delegateType.FindMethod(".ctor");
|
||||
UnityEngine.Assertions.Assert.IsNotNull(ctor, $"Delegate type {ci.delegateType.FullName} does not have a constructor.");
|
||||
ins.Add(Instruction.Create(OpCodes.Newobj, ctor));
|
||||
ins.Add(Instruction.Create(OpCodes.Stelem_Ref));
|
||||
++index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<CallInfo> callMethodList2 = callMethodList.ToList();
|
||||
callMethodList2.Sort((a, b) => a.key2.CompareTo(b.key2));
|
||||
|
||||
EncryptionScopeInfo encryptionScope = EncryptionScope;
|
||||
DefaultMetadataImporter importer = this.GetDefaultModuleMetadataImporter();
|
||||
RvaDataAllocator rvaDataAllocator = this.GetEntity<RvaDataAllocator>();
|
||||
foreach (CallInfo ci in callMethodList2)
|
||||
{
|
||||
_delegateInstanceHolderType.Fields.Add(ci.delegateInstanceField);
|
||||
|
||||
|
||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
||||
|
||||
IRandom localRandom = encryptionScope.localRandomCreator(HashUtil.ComputePrimitiveOrStringOrBytesHashCode(ci.key1));
|
||||
int ops = EncryptionUtil.GenerateEncryptionOpCodes(localRandom, encryptionScope.encryptor, _settings.obfuscationLevel);
|
||||
int salt = localRandom.NextInt();
|
||||
|
||||
int encryptedValue = encryptionScope.encryptor.Encrypt(ci.index, ops, salt);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
ins.Add(Instruction.CreateLdcI4(ops));
|
||||
ins.Add(Instruction.CreateLdcI4(salt));
|
||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaInt));
|
||||
ins.Add(Instruction.Create(OpCodes.Ldelem_Ref));
|
||||
ins.Add(Instruction.Create(OpCodes.Stsfld, ci.delegateInstanceField));
|
||||
}
|
||||
|
||||
ins.Add(Instruction.Create(OpCodes.Pop));
|
||||
ins.Add(Instruction.Create(OpCodes.Ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 02761bacbed8a8b489ae3e7f49f0f84a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
|
||||
public class DelegateProxyObfuscator : ObfuscatorBase
|
||||
{
|
||||
private readonly GroupByModuleEntityManager _entityManager;
|
||||
|
||||
public DelegateProxyObfuscator(GroupByModuleEntityManager moduleEntityManager)
|
||||
{
|
||||
_entityManager = moduleEntityManager;
|
||||
}
|
||||
|
||||
public override void Done()
|
||||
{
|
||||
_entityManager.Done<DelegateProxyAllocator>();
|
||||
}
|
||||
|
||||
private MethodSig CreateProxyMethodSig(ModuleDef module, IMethod method)
|
||||
{
|
||||
MethodSig methodSig = MetaUtil.ToSharedMethodSig(module.CorLibTypes, MetaUtil.GetInflatedMethodSig(method, null));
|
||||
//MethodSig methodSig = MetaUtil.GetInflatedMethodSig(method).Clone();
|
||||
//methodSig.Params
|
||||
switch (MetaUtil.GetThisArgType(method))
|
||||
{
|
||||
case ThisArgType.Class:
|
||||
{
|
||||
methodSig.Params.Insert(0, module.CorLibTypes.Object);
|
||||
break;
|
||||
}
|
||||
case ThisArgType.ValueType:
|
||||
{
|
||||
methodSig.Params.Insert(0, module.CorLibTypes.IntPtr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return MethodSig.CreateStatic(methodSig.RetType, methodSig.Params.ToArray());
|
||||
}
|
||||
|
||||
public override bool Obfuscate(MethodDef callingMethod, IMethod calledMethod, bool callVir, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
DelegateProxyAllocator allocator = _entityManager.GetEntity<DelegateProxyAllocator>(callingMethod.Module);
|
||||
LocalVariableAllocator localVarAllocator = new LocalVariableAllocator(callingMethod);
|
||||
MethodSig methodSig = CreateProxyMethodSig(callingMethod.Module, calledMethod);
|
||||
DelegateProxyMethodData proxyData = allocator.Allocate(calledMethod, callVir, methodSig);
|
||||
bool isVoidReturn = MetaUtil.IsVoidType(methodSig.RetType);
|
||||
|
||||
using (var varScope = localVarAllocator.CreateScope())
|
||||
{
|
||||
List<Local> localVars = new List<Local>();
|
||||
if (!isVoidReturn)
|
||||
{
|
||||
varScope.AllocateLocal(methodSig.RetType);
|
||||
}
|
||||
foreach (var p in methodSig.Params)
|
||||
{
|
||||
localVars.Add(varScope.AllocateLocal(p));
|
||||
}
|
||||
// save args
|
||||
for (int i = localVars.Count - 1; i >= 0; i--)
|
||||
{
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Stloc, localVars[i]));
|
||||
}
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, proxyData.delegateInstanceField));
|
||||
foreach (var local in localVars)
|
||||
{
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldloc, local));
|
||||
}
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Callvirt, proxyData.delegateInvokeMethod));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1102cd9f03de27c4b9fde3d6a87277c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Editor;
|
||||
|
|
@ -12,6 +32,7 @@ using TypeAttributes = dnlib.DotNet.TypeAttributes;
|
|||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
|
||||
public struct ProxyCallMethodData
|
||||
{
|
||||
public readonly MethodDef proxyMethod;
|
||||
|
|
@ -30,38 +51,11 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
}
|
||||
}
|
||||
|
||||
class ModuleCallProxyAllocator : IGroupByModuleEntity
|
||||
class ModuleDispatchProxyAllocator : GroupByModuleEntityBase
|
||||
{
|
||||
private ModuleDef _module;
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private readonly CallObfuscationSettingsFacade _settings;
|
||||
|
||||
private EncryptionScopeInfo _encryptionScope;
|
||||
private bool _done;
|
||||
private CallObfuscationSettingsFacade _settings;
|
||||
|
||||
class MethodKey : IEquatable<MethodKey>
|
||||
{
|
||||
public readonly IMethod _method;
|
||||
public readonly bool _callVir;
|
||||
private readonly int _hashCode;
|
||||
|
||||
public MethodKey(IMethod method, bool callVir)
|
||||
{
|
||||
_method = method;
|
||||
_callVir = callVir;
|
||||
_hashCode = HashUtil.CombineHash(MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method), callVir ? 1 : 0);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _hashCode;
|
||||
}
|
||||
|
||||
public bool Equals(MethodKey other)
|
||||
{
|
||||
return MethodEqualityComparer.CompareDeclaringTypes.Equals(_method, other._method) && _callVir == other._callVir;
|
||||
}
|
||||
}
|
||||
|
||||
class MethodProxyInfo
|
||||
{
|
||||
|
|
@ -93,25 +87,23 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
private TypeDef _proxyTypeDef;
|
||||
|
||||
public ModuleCallProxyAllocator(EncryptionScopeProvider encryptionScopeProvider, CallObfuscationSettingsFacade settings)
|
||||
public ModuleDispatchProxyAllocator()
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public void Init(ModuleDef mod)
|
||||
public override void Init()
|
||||
{
|
||||
_module = mod;
|
||||
_encryptionScope = _encryptionScopeProvider.GetScope(mod);
|
||||
_settings = CallObfusPass.CurrentSettings;
|
||||
}
|
||||
|
||||
private TypeDef CreateProxyTypeDef()
|
||||
{
|
||||
using (var scope = new DisableTypeDefFindCacheScope(_module))
|
||||
ModuleDef mod = Module;
|
||||
using (var scope = new DisableTypeDefFindCacheScope(mod))
|
||||
{
|
||||
var typeDef = new TypeDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}ProxyCall", _module.CorLibTypes.Object.ToTypeDefOrRef());
|
||||
var typeDef = new TypeDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}ProxyCall", mod.CorLibTypes.Object.ToTypeDefOrRef());
|
||||
typeDef.Attributes = TypeAttributes.NotPublic | TypeAttributes.Sealed;
|
||||
_module.Types.Add(typeDef);
|
||||
mod.Types.Add(typeDef);
|
||||
return typeDef;
|
||||
}
|
||||
}
|
||||
|
|
@ -157,24 +149,25 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
private MethodSig CreateDispatchMethodSig(IMethod method)
|
||||
{
|
||||
MethodSig methodSig = MetaUtil.ToSharedMethodSig(_module.CorLibTypes, MetaUtil.GetInflatedMethodSig(method, null));
|
||||
ModuleDef mod = Module;
|
||||
MethodSig methodSig = MetaUtil.ToSharedMethodSig(mod.CorLibTypes, MetaUtil.GetInflatedMethodSig(method, null));
|
||||
//MethodSig methodSig = MetaUtil.GetInflatedMethodSig(method).Clone();
|
||||
//methodSig.Params
|
||||
switch (MetaUtil.GetThisArgType(method))
|
||||
{
|
||||
case ThisArgType.Class:
|
||||
{
|
||||
methodSig.Params.Insert(0, _module.CorLibTypes.Object);
|
||||
methodSig.Params.Insert(0, mod.CorLibTypes.Object);
|
||||
break;
|
||||
}
|
||||
case ThisArgType.ValueType:
|
||||
{
|
||||
methodSig.Params.Insert(0, _module.CorLibTypes.IntPtr);
|
||||
methodSig.Params.Insert(0, mod.CorLibTypes.IntPtr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// extra param for index
|
||||
methodSig.Params.Add(_module.CorLibTypes.Int32);
|
||||
methodSig.Params.Add(mod.CorLibTypes.Int32);
|
||||
return MethodSig.CreateStatic(methodSig.RetType, methodSig.Params.ToArray());
|
||||
}
|
||||
|
||||
|
|
@ -185,7 +178,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
private int GenerateEncryptOps(IRandom random)
|
||||
{
|
||||
return EncryptionUtil.GenerateEncryptionOpCodes(random, _encryptionScope.encryptor, _settings.obfuscationLevel);
|
||||
return EncryptionUtil.GenerateEncryptionOpCodes(random, EncryptionScope.encryptor, _settings.obfuscationLevel);
|
||||
}
|
||||
|
||||
private DispatchMethodInfo GetDispatchMethod(IMethod method)
|
||||
|
|
@ -210,7 +203,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
private IRandom CreateRandomForMethod(IMethod method, bool callVir)
|
||||
{
|
||||
int seed = MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method);
|
||||
return _encryptionScope.localRandomCreator(seed);
|
||||
return EncryptionScope.localRandomCreator(seed);
|
||||
}
|
||||
|
||||
public ProxyCallMethodData Allocate(IMethod method, bool callVir)
|
||||
|
|
@ -228,7 +221,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
IRandom localRandom = CreateRandomForMethod(method, callVir);
|
||||
int encryptOps = GenerateEncryptOps(localRandom);
|
||||
int salt = GenerateSalt(localRandom);
|
||||
int encryptedIndex = _encryptionScope.encryptor.Encrypt(index, encryptOps, salt);
|
||||
int encryptedIndex = EncryptionScope.encryptor.Encrypt(index, encryptOps, salt);
|
||||
proxyInfo = new MethodProxyInfo()
|
||||
{
|
||||
proxyMethod = methodDispatcher.methodDef,
|
||||
|
|
@ -243,7 +236,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
return new ProxyCallMethodData(proxyInfo.proxyMethod, proxyInfo.encryptedOps, proxyInfo.salt, proxyInfo.encryptedIndex, proxyInfo.index);
|
||||
}
|
||||
|
||||
public void Done()
|
||||
public override void Done()
|
||||
{
|
||||
if (_done)
|
||||
{
|
||||
|
|
@ -297,37 +290,4 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CallProxyAllocator
|
||||
{
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private GroupByModuleEntityManager _moduleEntityManager;
|
||||
private readonly CallObfuscationSettingsFacade _settings;
|
||||
|
||||
public CallProxyAllocator(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager, CallObfuscationSettingsFacade settings)
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
_moduleEntityManager = moduleEntityManager;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
private ModuleCallProxyAllocator GetModuleAllocator(ModuleDef mod)
|
||||
{
|
||||
return _moduleEntityManager.GetEntity<ModuleCallProxyAllocator>(mod, () => new ModuleCallProxyAllocator(_encryptionScopeProvider, _settings));
|
||||
}
|
||||
|
||||
public ProxyCallMethodData Allocate(ModuleDef mod, IMethod method, bool callVir)
|
||||
{
|
||||
ModuleCallProxyAllocator allocator = GetModuleAllocator(mod);
|
||||
return allocator.Allocate(method, callVir);
|
||||
}
|
||||
|
||||
public void Done()
|
||||
{
|
||||
foreach (var allocator in _moduleEntityManager.GetEntities<ModuleCallProxyAllocator>())
|
||||
{
|
||||
allocator.Done();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Data;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
|
||||
public class DispatchProxyObfuscator : ObfuscatorBase
|
||||
{
|
||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||
|
||||
public DispatchProxyObfuscator(GroupByModuleEntityManager moduleEntityManager)
|
||||
{
|
||||
_moduleEntityManager = moduleEntityManager;
|
||||
}
|
||||
|
||||
public override void Done()
|
||||
{
|
||||
_moduleEntityManager.Done<ModuleDispatchProxyAllocator>();
|
||||
}
|
||||
|
||||
public override bool Obfuscate(MethodDef callerMethod, IMethod calledMethod, bool callVir, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
ModuleDispatchProxyAllocator proxyCallAllocator = _moduleEntityManager.GetEntity<ModuleDispatchProxyAllocator>(callerMethod.Module);
|
||||
MethodSig sharedMethodSig = MetaUtil.ToSharedMethodSig(calledMethod.Module.CorLibTypes, MetaUtil.GetInflatedMethodSig(calledMethod, null));
|
||||
ProxyCallMethodData proxyCallMethodData = proxyCallAllocator.Allocate(calledMethod, callVir);
|
||||
DefaultMetadataImporter importer = proxyCallAllocator.GetDefaultModuleMetadataImporter();
|
||||
|
||||
//if (needCacheCall)
|
||||
//{
|
||||
// FieldDef cacheField = _constFieldAllocator.Allocate(callerMethod.Module, proxyCallMethodData.index);
|
||||
// obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// obfuscatedInstructions.Add(Instruction.CreateLdcI4(proxyCallMethodData.encryptedIndex));
|
||||
// obfuscatedInstructions.Add(Instruction.CreateLdcI4(proxyCallMethodData.encryptOps));
|
||||
// obfuscatedInstructions.Add(Instruction.CreateLdcI4(proxyCallMethodData.salt));
|
||||
// obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptInt));
|
||||
//}
|
||||
|
||||
ConstFieldAllocator constFieldAllocator = proxyCallAllocator.GetEntity<ConstFieldAllocator>();
|
||||
FieldDef cacheField = constFieldAllocator.Allocate(proxyCallMethodData.index);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, proxyCallMethodData.proxyMethod));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +1,39 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
|
||||
public struct ObfuscationCachePolicy
|
||||
{
|
||||
public bool cacheInLoop;
|
||||
public bool cacheNotInLoop;
|
||||
}
|
||||
|
||||
public interface IObfuscationPolicy
|
||||
{
|
||||
bool NeedObfuscateCallInMethod(MethodDef method);
|
||||
|
||||
ObfuscationCachePolicy GetMethodObfuscationCachePolicy(MethodDef method);
|
||||
|
||||
bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool currentInLoop);
|
||||
bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir);
|
||||
}
|
||||
|
||||
public abstract class ObfuscationPolicyBase : IObfuscationPolicy
|
||||
{
|
||||
public abstract bool NeedObfuscateCallInMethod(MethodDef method);
|
||||
|
||||
public abstract ObfuscationCachePolicy GetMethodObfuscationCachePolicy(MethodDef method);
|
||||
|
||||
public abstract bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool currentInLoop);
|
||||
public abstract bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -6,14 +26,15 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
{
|
||||
public interface IObfuscator
|
||||
{
|
||||
void Obfuscate(MethodDef callingMethod, IMethod calledMethod, bool callVir, bool needCacheCall, List<Instruction> obfuscatedInstructions);
|
||||
bool Obfuscate(MethodDef callingMethod, IMethod calledMethod, bool callVir, List<Instruction> obfuscatedInstructions);
|
||||
|
||||
void Done();
|
||||
}
|
||||
|
||||
public abstract class ObfuscatorBase : IObfuscator
|
||||
{
|
||||
public abstract void Obfuscate(MethodDef callingMethod, IMethod calledMethod, bool callVir, bool needCacheCall, List<Instruction> obfuscatedInstructions);
|
||||
public abstract bool Obfuscate(MethodDef callingMethod, IMethod calledMethod, bool callVir, List<Instruction> obfuscatedInstructions);
|
||||
|
||||
public abstract void Done();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
class MethodKey : IEquatable<MethodKey>
|
||||
{
|
||||
public readonly IMethod _method;
|
||||
public readonly bool _callVir;
|
||||
private readonly int _hashCode;
|
||||
|
||||
public MethodKey(IMethod method, bool callVir)
|
||||
{
|
||||
_method = method;
|
||||
_callVir = callVir;
|
||||
_hashCode = HashUtil.CombineHash(MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method), callVir ? 1 : 0);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _hashCode;
|
||||
}
|
||||
|
||||
public bool Equals(MethodKey other)
|
||||
{
|
||||
return MethodEqualityComparer.CompareDeclaringTypes.Equals(_method, other._method) && _callVir == other._callVir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1193647b317b56f4b83aa080d0a17f7a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
class SpecialWhiteListMethodCalculator
|
||||
{
|
||||
private readonly RuntimeType _targetRuntime;
|
||||
private readonly bool _obfuscateCallToMethodInMscorlib;
|
||||
private readonly CachedDictionary<IMethod, bool> _specialWhiteListMethodCache;
|
||||
|
||||
public SpecialWhiteListMethodCalculator(RuntimeType targetRuntime, bool obfuscateCallToMethodInMscorlib)
|
||||
{
|
||||
_targetRuntime = targetRuntime;
|
||||
_obfuscateCallToMethodInMscorlib = obfuscateCallToMethodInMscorlib;
|
||||
_specialWhiteListMethodCache = new CachedDictionary<IMethod, bool>(MethodEqualityComparer.CompareDeclaringTypes, this.ComputeIsInWhiteList);
|
||||
}
|
||||
|
||||
public bool IsInWhiteList(IMethod calledMethod)
|
||||
{
|
||||
return _specialWhiteListMethodCache.GetValue(calledMethod);
|
||||
}
|
||||
|
||||
private static readonly HashSet<string> _specialTypeFullNames = new HashSet<string>
|
||||
{
|
||||
"System.Enum",
|
||||
"System.Delegate",
|
||||
"System.MulticastDelegate",
|
||||
"Obfuz.EncryptionService`1",
|
||||
};
|
||||
|
||||
private static readonly HashSet<string> _specialMethodNames = new HashSet<string>
|
||||
{
|
||||
"GetEnumerator", // List<T>.Enumerator.GetEnumerator()
|
||||
".ctor", // constructor
|
||||
};
|
||||
|
||||
private static readonly HashSet<string> _specialMethodFullNames = new HashSet<string>
|
||||
{
|
||||
"System.Reflection.MethodBase.GetCurrentMethod",
|
||||
"System.Reflection.Assembly.GetCallingAssembly",
|
||||
"System.Reflection.Assembly.GetExecutingAssembly",
|
||||
"System.Reflection.Assembly.GetEntryAssembly",
|
||||
};
|
||||
|
||||
private bool ComputeIsInWhiteList(IMethod calledMethod)
|
||||
{
|
||||
MethodDef calledMethodDef = calledMethod.ResolveMethodDef();
|
||||
// mono has more strict access control, calls non-public method will raise exception.
|
||||
if (_targetRuntime == RuntimeType.Mono)
|
||||
{
|
||||
if (calledMethodDef != null && (!calledMethodDef.IsPublic || !IsTypeSelfAndParentPublic(calledMethodDef.DeclaringType)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ITypeDefOrRef declaringType = calledMethod.DeclaringType;
|
||||
TypeSig declaringTypeSig = calledMethod.DeclaringType.ToTypeSig();
|
||||
declaringTypeSig = declaringTypeSig.RemovePinnedAndModifiers();
|
||||
switch (declaringTypeSig.ElementType)
|
||||
{
|
||||
case ElementType.ValueType:
|
||||
case ElementType.Class:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case ElementType.GenericInst:
|
||||
{
|
||||
if (MetaUtil.ContainsContainsGenericParameter(calledMethod))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: return true;
|
||||
}
|
||||
|
||||
TypeDef typeDef = declaringType.ResolveTypeDef();
|
||||
|
||||
if (!_obfuscateCallToMethodInMscorlib && typeDef.Module.IsCoreLibraryModule == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeDef.IsDelegate || typeDef.IsEnum)
|
||||
return true;
|
||||
|
||||
string fullName = typeDef.FullName;
|
||||
if (_specialTypeFullNames.Contains(fullName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//if (fullName.StartsWith("System.Runtime.CompilerServices."))
|
||||
//{
|
||||
// return true;
|
||||
//}
|
||||
|
||||
string methodName = calledMethod.Name;
|
||||
if (_specialMethodNames.Contains(methodName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
string methodFullName = $"{fullName}.{methodName}";
|
||||
if (_specialMethodFullNames.Contains(methodFullName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsTypeSelfAndParentPublic(TypeDef type)
|
||||
{
|
||||
if (type.DeclaringType != null && !IsTypeSelfAndParentPublic(type.DeclaringType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return type.IsPublic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 904e80c4b98911c40b6a9173ca24f3ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Editor;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Conf;
|
||||
using Obfuz.Utils;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
|
|
@ -23,7 +43,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
{
|
||||
var ctx = ObfuscationPassContext.Current;
|
||||
_dataObfuscatorPolicy = new ConfigurableEncryptPolicy(ctx.coreSettings.assembliesToObfuscate, _settings.ruleFiles);
|
||||
_dataObfuscator = new DefaultConstEncryptor(ctx.encryptionScopeProvider, ctx.rvaDataAllocator, ctx.constFieldAllocator, ctx.moduleEntityManager, _settings);
|
||||
_dataObfuscator = new DefaultConstEncryptor(ctx.moduleEntityManager, _settings);
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
|
|
@ -123,6 +143,9 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
{
|
||||
// don't need cache for byte array obfuscation
|
||||
needCache = false;
|
||||
// Drop ldtoken RuntimeFieldHandle; DecryptInitializeArray now loads from RvaDataAllocator byte[].
|
||||
prevInst.OpCode = OpCodes.Nop;
|
||||
prevInst.Operand = null;
|
||||
_dataObfuscator.ObfuscateBytes(method, needCache, ravFieldDef, data, outputInstructions);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,42 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using NUnit.Framework;
|
||||
using Obfuz.Data;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||
{
|
||||
public class DefaultConstEncryptor : IConstEncryptor
|
||||
{
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private readonly RvaDataAllocator _rvaDataAllocator;
|
||||
private readonly ConstFieldAllocator _constFieldAllocator;
|
||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||
private readonly ConstEncryptionSettingsFacade _settings;
|
||||
|
||||
public DefaultConstEncryptor(EncryptionScopeProvider encryptionScopeProvider, RvaDataAllocator rvaDataAllocator, ConstFieldAllocator constFieldAllocator, GroupByModuleEntityManager moduleEntityManager, ConstEncryptionSettingsFacade settings)
|
||||
public DefaultConstEncryptor(GroupByModuleEntityManager moduleEntityManager, ConstEncryptionSettingsFacade settings)
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
_rvaDataAllocator = rvaDataAllocator;
|
||||
_constFieldAllocator = constFieldAllocator;
|
||||
_moduleEntityManager = moduleEntityManager;
|
||||
_settings = settings;
|
||||
}
|
||||
|
|
@ -44,20 +58,23 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
|
||||
private DefaultMetadataImporter GetModuleMetadataImporter(MethodDef method)
|
||||
{
|
||||
return _moduleEntityManager.GetDefaultModuleMetadataImporter(method.Module, _encryptionScopeProvider);
|
||||
return _moduleEntityManager.GetEntity<DefaultMetadataImporter>(method.Module);
|
||||
}
|
||||
|
||||
public void ObfuscateInt(MethodDef method, bool needCacheValue, int value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
EncryptionScopeInfo encryptionScope = _encryptionScopeProvider.GetScope(method.Module);
|
||||
EncryptionScopeInfo encryptionScope = _moduleEntityManager.EncryptionScopeProvider.GetScope(method.Module);
|
||||
IRandom random = CreateRandomForValue(encryptionScope, value.GetHashCode());
|
||||
ModuleConstFieldAllocator moduleConstFieldAllocator = _constFieldAllocator.GetModuleAllocator(method.Module);
|
||||
ConstFieldAllocator constFieldAllocator = _moduleEntityManager.GetEntity<ConstFieldAllocator>(method.Module);
|
||||
RvaDataAllocator rvaDataAllocator = _moduleEntityManager.GetEntity<RvaDataAllocator>(method.Module);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
|
||||
switch (random.NextInt(5))
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
// = c = encrypted static field
|
||||
FieldDef cacheField = _constFieldAllocator.Allocate(method.Module, value);
|
||||
FieldDef cacheField = constFieldAllocator.Allocate(value);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
break;
|
||||
}
|
||||
|
|
@ -67,7 +84,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
int a = random.NextInt();
|
||||
int b = value - a;
|
||||
float constProbability = 0.5f;
|
||||
ConstObfusUtil.LoadConstTwoInt(a, b, random, constProbability, moduleConstFieldAllocator, obfuscatedInstructions);
|
||||
ConstObfusUtil.LoadConstTwoInt(a, b, random, constProbability, constFieldAllocator, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Add));
|
||||
break;
|
||||
}
|
||||
|
|
@ -78,7 +95,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
int ra = MathUtil.ModInverse32(a);
|
||||
int b = ra * value;
|
||||
float constProbability = 0.5f;
|
||||
ConstObfusUtil.LoadConstTwoInt(a, b, random, constProbability, moduleConstFieldAllocator, obfuscatedInstructions);
|
||||
ConstObfusUtil.LoadConstTwoInt(a, b, random, constProbability, constFieldAllocator, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Mul));
|
||||
break;
|
||||
}
|
||||
|
|
@ -88,7 +105,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
int a = random.NextInt();
|
||||
int b = a ^ value;
|
||||
float constProbability = 0.5f;
|
||||
ConstObfusUtil.LoadConstTwoInt(a, b, random, constProbability, moduleConstFieldAllocator, obfuscatedInstructions);
|
||||
ConstObfusUtil.LoadConstTwoInt(a, b, random, constProbability, constFieldAllocator, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Xor));
|
||||
break;
|
||||
}
|
||||
|
|
@ -96,16 +113,14 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
{
|
||||
if (needCacheValue)
|
||||
{
|
||||
FieldDef cacheField = moduleConstFieldAllocator.Allocate(value);
|
||||
FieldDef cacheField = constFieldAllocator.Allocate(value);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
return;
|
||||
}
|
||||
int ops = GenerateEncryptionOperations(encryptionScope, random);
|
||||
int salt = GenerateSalt(random);
|
||||
int encryptedValue = encryptionScope.encryptor.Encrypt(value, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops));
|
||||
|
|
@ -120,16 +135,18 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
|
||||
public void ObfuscateLong(MethodDef method, bool needCacheValue, long value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
EncryptionScopeInfo encryptionScope = _encryptionScopeProvider.GetScope(method.Module);
|
||||
EncryptionScopeInfo encryptionScope = _moduleEntityManager.EncryptionScopeProvider.GetScope(method.Module);
|
||||
IRandom random = CreateRandomForValue(encryptionScope, value.GetHashCode());
|
||||
ModuleConstFieldAllocator moduleConstFieldAllocator = _constFieldAllocator.GetModuleAllocator(method.Module);
|
||||
ConstFieldAllocator constFieldAllocator = _moduleEntityManager.GetEntity<ConstFieldAllocator>(method.Module);
|
||||
RvaDataAllocator rvaDataAllocator = _moduleEntityManager.GetEntity<RvaDataAllocator>(method.Module);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
|
||||
switch (random.NextInt(5))
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
// c = encrypted static field
|
||||
FieldDef cacheField = _constFieldAllocator.Allocate(method.Module, value);
|
||||
FieldDef cacheField = constFieldAllocator.Allocate(value);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
break;
|
||||
}
|
||||
|
|
@ -139,7 +156,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
long a = random.NextLong();
|
||||
long b = value - a;
|
||||
float constProbability = 0.5f;
|
||||
ConstObfusUtil.LoadConstTwoLong(a, b, random, constProbability, moduleConstFieldAllocator, obfuscatedInstructions);
|
||||
ConstObfusUtil.LoadConstTwoLong(a, b, random, constProbability, constFieldAllocator, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Add));
|
||||
break;
|
||||
}
|
||||
|
|
@ -150,7 +167,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
long ra = MathUtil.ModInverse64(a);
|
||||
long b = ra * value;
|
||||
float constProbability = 0.5f;
|
||||
ConstObfusUtil.LoadConstTwoLong(a, b, random, constProbability, moduleConstFieldAllocator, obfuscatedInstructions);
|
||||
ConstObfusUtil.LoadConstTwoLong(a, b, random, constProbability, constFieldAllocator, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Mul));
|
||||
break;
|
||||
}
|
||||
|
|
@ -160,7 +177,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
long a = random.NextLong();
|
||||
long b = a ^ value;
|
||||
float constProbability = 0.5f;
|
||||
ConstObfusUtil.LoadConstTwoLong(a, b, random, constProbability, moduleConstFieldAllocator, obfuscatedInstructions);
|
||||
ConstObfusUtil.LoadConstTwoLong(a, b, random, constProbability, constFieldAllocator, obfuscatedInstructions);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Xor));
|
||||
break;
|
||||
}
|
||||
|
|
@ -168,7 +185,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
{
|
||||
if (needCacheValue)
|
||||
{
|
||||
FieldDef cacheField = _constFieldAllocator.Allocate(method.Module, value);
|
||||
FieldDef cacheField = constFieldAllocator.Allocate(value);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
return;
|
||||
}
|
||||
|
|
@ -176,9 +193,8 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
int ops = GenerateEncryptionOperations(encryptionScope, random);
|
||||
int salt = GenerateSalt(random);
|
||||
long encryptedValue = encryptionScope.encryptor.Encrypt(value, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops));
|
||||
|
|
@ -193,21 +209,25 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
|
||||
public void ObfuscateFloat(MethodDef method, bool needCacheValue, float value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
EncryptionScopeInfo encryptionScope = _moduleEntityManager.EncryptionScopeProvider.GetScope(method.Module);
|
||||
IRandom random = CreateRandomForValue(encryptionScope, value.GetHashCode());
|
||||
ConstFieldAllocator constFieldAllocator = _moduleEntityManager.GetEntity<ConstFieldAllocator>(method.Module);
|
||||
RvaDataAllocator rvaDataAllocator = _moduleEntityManager.GetEntity<RvaDataAllocator>(method.Module);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
|
||||
if (needCacheValue)
|
||||
{
|
||||
FieldDef cacheField = _constFieldAllocator.Allocate(method.Module, value);
|
||||
FieldDef cacheField = constFieldAllocator.Allocate(value);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
return;
|
||||
}
|
||||
|
||||
EncryptionScopeInfo encryptionScope = _encryptionScopeProvider.GetScope(method.Module);
|
||||
IRandom random = CreateRandomForValue(encryptionScope, value.GetHashCode());
|
||||
|
||||
int ops = GenerateEncryptionOperations(encryptionScope, random);
|
||||
int salt = GenerateSalt(random);
|
||||
float encryptedValue = encryptionScope.encryptor.Encrypt(value, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops));
|
||||
|
|
@ -217,21 +237,25 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
|
||||
public void ObfuscateDouble(MethodDef method, bool needCacheValue, double value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
EncryptionScopeInfo encryptionScope = _moduleEntityManager.EncryptionScopeProvider.GetScope(method.Module);
|
||||
IRandom random = CreateRandomForValue(encryptionScope, value.GetHashCode());
|
||||
ConstFieldAllocator constFieldAllocator = _moduleEntityManager.GetEntity<ConstFieldAllocator>(method.Module);
|
||||
RvaDataAllocator rvaDataAllocator = _moduleEntityManager.GetEntity<RvaDataAllocator>(method.Module);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
|
||||
if (needCacheValue)
|
||||
{
|
||||
FieldDef cacheField = _constFieldAllocator.Allocate(method.Module, value);
|
||||
FieldDef cacheField = constFieldAllocator.Allocate(value);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
return;
|
||||
}
|
||||
|
||||
EncryptionScopeInfo encryptionScope = _encryptionScopeProvider.GetScope(method.Module);
|
||||
IRandom random = CreateRandomForValue(encryptionScope, value.GetHashCode());
|
||||
|
||||
int ops = GenerateEncryptionOperations(encryptionScope, random);
|
||||
int salt = GenerateSalt(random);
|
||||
double encryptedValue = encryptionScope.encryptor.Encrypt(value, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops));
|
||||
|
|
@ -242,15 +266,15 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
|
||||
class EncryptedRvaDataInfo
|
||||
{
|
||||
public readonly FieldDef fieldDef;
|
||||
public readonly RvaData rvaData;
|
||||
public readonly byte[] originalBytes;
|
||||
public readonly byte[] encryptedBytes;
|
||||
public readonly int opts;
|
||||
public readonly int salt;
|
||||
|
||||
public EncryptedRvaDataInfo(FieldDef fieldDef, byte[] originalBytes, byte[] encryptedBytes, int opts, int salt)
|
||||
public EncryptedRvaDataInfo(RvaData rvaData, byte[] originalBytes, byte[] encryptedBytes, int opts, int salt)
|
||||
{
|
||||
this.fieldDef = fieldDef;
|
||||
this.rvaData = rvaData;
|
||||
this.originalBytes = originalBytes;
|
||||
this.encryptedBytes = encryptedBytes;
|
||||
this.opts = opts;
|
||||
|
|
@ -264,7 +288,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
{
|
||||
if (!_encryptedRvaFields.TryGetValue(fieldDef, out var encryptedRvaData))
|
||||
{
|
||||
EncryptionScopeInfo encryptionScope = _encryptionScopeProvider.GetScope(fieldDef.Module);
|
||||
EncryptionScopeInfo encryptionScope = _moduleEntityManager.EncryptionScopeProvider.GetScope(fieldDef.Module);
|
||||
IRandom random = CreateRandomForValue(encryptionScope, FieldEqualityComparer.CompareDeclaringTypes.GetHashCode(fieldDef));
|
||||
int ops = GenerateEncryptionOperations(encryptionScope, random);
|
||||
int salt = GenerateSalt(random);
|
||||
|
|
@ -272,12 +296,15 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
byte[] encryptedBytes = (byte[])originalBytes.Clone();
|
||||
encryptionScope.encryptor.EncryptBlock(encryptedBytes, ops, salt);
|
||||
Assert.AreNotEqual(originalBytes, encryptedBytes, "Original bytes should not be the same as encrypted bytes.");
|
||||
encryptedRvaData = new EncryptedRvaDataInfo(fieldDef, originalBytes, encryptedBytes, ops, salt);
|
||||
RvaDataAllocator rvaDataAllocator = _moduleEntityManager.GetEntity<RvaDataAllocator>(fieldDef.Module);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedBytes);
|
||||
encryptedRvaData = new EncryptedRvaDataInfo(rvaData, originalBytes, encryptedBytes, ops, salt);
|
||||
_encryptedRvaFields.Add(fieldDef, encryptedRvaData);
|
||||
// Keep ciphertext in the original RVA field so plaintext is not shipped; runtime loads via RvaDataAllocator.
|
||||
fieldDef.InitialValue = encryptedBytes;
|
||||
byte[] decryptedBytes = (byte[])encryptedBytes.Clone();
|
||||
encryptionScope.encryptor.DecryptBlock(decryptedBytes, ops, salt);
|
||||
Assert.AreEqual(originalBytes, decryptedBytes, "Decrypted bytes should match the original bytes after encryption and decryption.");
|
||||
AssertUtil.AreArrayEqual(originalBytes, decryptedBytes, "Decrypted bytes should match the original bytes after encryption and decryption.");
|
||||
}
|
||||
return encryptedRvaData;
|
||||
}
|
||||
|
|
@ -289,6 +316,8 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
Assert.AreEqual(value.Length, encryptedData.encryptedBytes.Length);
|
||||
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, encryptedData.rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(encryptedData.rvaData.offset));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(encryptedData.encryptedBytes.Length));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(encryptedData.opts));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(encryptedData.salt));
|
||||
|
|
@ -297,23 +326,26 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
|
||||
public void ObfuscateString(MethodDef method, bool needCacheValue, string value, List<Instruction> obfuscatedInstructions)
|
||||
{
|
||||
EncryptionScopeInfo encryptionScope = _moduleEntityManager.EncryptionScopeProvider.GetScope(method.Module);
|
||||
IRandom random = CreateRandomForValue(encryptionScope, value.GetHashCode());
|
||||
ConstFieldAllocator constFieldAllocator = _moduleEntityManager.GetEntity<ConstFieldAllocator>(method.Module);
|
||||
RvaDataAllocator rvaDataAllocator = _moduleEntityManager.GetEntity<RvaDataAllocator>(method.Module);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
|
||||
if (needCacheValue)
|
||||
{
|
||||
FieldDef cacheField = _constFieldAllocator.Allocate(method.Module, value);
|
||||
FieldDef cacheField = constFieldAllocator.Allocate(value);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
||||
return;
|
||||
}
|
||||
|
||||
EncryptionScopeInfo encryptionScope = _encryptionScopeProvider.GetScope(method.Module);
|
||||
IRandom random = CreateRandomForValue(encryptionScope, value.GetHashCode());
|
||||
int ops = GenerateEncryptionOperations(encryptionScope, random);
|
||||
int salt = GenerateSalt(random);
|
||||
int stringByteLength = Encoding.UTF8.GetByteCount(value);
|
||||
byte[] encryptedValue = encryptionScope.encryptor.Encrypt(value, ops, salt);
|
||||
Assert.AreEqual(stringByteLength, encryptedValue.Length);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
RvaData rvaData = rvaDataAllocator.Allocate(encryptedValue);
|
||||
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
// should use stringByteLength, can't use rvaData.size, because rvaData.size is align to 4, it's not the actual length.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||
|
|
|
|||
|
|
@ -1,6 +1,27 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Conf;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
|
@ -97,17 +118,12 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
}
|
||||
}
|
||||
|
||||
private ObfuscationLevel ParseObfuscationLevel(string str)
|
||||
{
|
||||
return (ObfuscationLevel)Enum.Parse(typeof(ObfuscationLevel), str);
|
||||
}
|
||||
|
||||
private ObfuscationRule ParseObfuscationRule(string configFile, XmlElement ele)
|
||||
{
|
||||
var rule = new ObfuscationRule();
|
||||
if (ele.HasAttribute("obfuscationLevel"))
|
||||
{
|
||||
rule.obfuscationLevel = ParseObfuscationLevel(ele.GetAttribute("obfuscationLevel"));
|
||||
rule.obfuscationLevel = ConfigUtil.ParseObfuscationLevel(ele.GetAttribute("obfuscationLevel"));
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Data;
|
||||
using Obfuz.Emit;
|
||||
|
|
@ -13,7 +33,7 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
public IRandom localRandom;
|
||||
public EncryptionScopeInfo encryptionScope;
|
||||
public DefaultMetadataImporter importer;
|
||||
public ModuleConstFieldAllocator constFieldAllocator;
|
||||
public ConstFieldAllocator constFieldAllocator;
|
||||
public int minInstructionCountOfBasicBlockToObfuscate;
|
||||
|
||||
public IRandom CreateRandom()
|
||||
|
|
@ -60,7 +80,8 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
//Debug.Log($"Obfuscating method: {method.FullName} with EvalStackObfusPass");
|
||||
|
||||
ObfuscationPassContext ctx = ObfuscationPassContext.Current;
|
||||
var encryptionScope = ctx.encryptionScopeProvider.GetScope(method.Module);
|
||||
GroupByModuleEntityManager moduleEntityManager = ctx.moduleEntityManager;
|
||||
var encryptionScope = moduleEntityManager.EncryptionScopeProvider.GetScope(method.Module);
|
||||
var ruleData = _obfuscationPolicy.GetObfuscationRuleData(method);
|
||||
var localRandom = encryptionScope.localRandomCreator(MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method));
|
||||
var obfusMethodCtx = new ObfusMethodContext
|
||||
|
|
@ -68,9 +89,9 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
method = method,
|
||||
localVariableAllocator = new LocalVariableAllocator(method),
|
||||
encryptionScope = encryptionScope,
|
||||
constFieldAllocator = ctx.constFieldAllocator.GetModuleAllocator(method.Module),
|
||||
constFieldAllocator = moduleEntityManager.GetEntity<ConstFieldAllocator>(method.Module),
|
||||
localRandom = localRandom,
|
||||
importer = ctx.moduleEntityManager.GetDefaultModuleMetadataImporter(method.Module, ctx.encryptionScopeProvider),
|
||||
importer = moduleEntityManager.GetEntity<DefaultMetadataImporter>(method.Module),
|
||||
minInstructionCountOfBasicBlockToObfuscate = _settings.minInstructionCountOfBasicBlockToObfuscate,
|
||||
};
|
||||
_obfuscator.Obfuscate(method, obfusMethodCtx);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,24 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ControlFlowObfus
|
||||
{
|
||||
|
|
@ -11,7 +30,7 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
var mcfc = new MethodControlFlowCalculator(method, ctx.CreateRandom(), ctx.constFieldAllocator, ctx.minInstructionCountOfBasicBlockToObfuscate);
|
||||
if (!mcfc.TryObfus())
|
||||
{
|
||||
Debug.LogWarning($"not obfuscate method: {method.FullName}");
|
||||
//Debug.LogWarning($"not obfuscate method: {method.FullName}");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,24 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Emit;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ControlFlowObfus
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Data;
|
||||
|
|
@ -6,7 +26,6 @@ using Obfuz.Utils;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
|
|
@ -35,15 +54,16 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
|
||||
private TypeSig GetLocalTypeSig(ICorLibTypes corLibTypes, EvalDataTypeWithSig type)
|
||||
{
|
||||
TypeSig typeSig = type.typeSig;
|
||||
switch (type.type)
|
||||
{
|
||||
case EvalDataType.Int32: return corLibTypes.Int32;
|
||||
case EvalDataType.Int64: return corLibTypes.Int64;
|
||||
case EvalDataType.Float: return corLibTypes.Single;
|
||||
case EvalDataType.Double: return corLibTypes.Double;
|
||||
case EvalDataType.I: return corLibTypes.IntPtr;
|
||||
case EvalDataType.Ref: Assert.IsNotNull(type.typeSig); return type.typeSig;
|
||||
case EvalDataType.ValueType: Assert.IsNotNull(type.typeSig); return type.typeSig;
|
||||
case EvalDataType.I: return typeSig ?? corLibTypes.IntPtr;
|
||||
case EvalDataType.Ref: return typeSig == null || MetaUtil.IsValueType(typeSig) ? corLibTypes.Object : typeSig;
|
||||
case EvalDataType.ValueType: Assert.IsNotNull(typeSig); return typeSig;
|
||||
case EvalDataType.Token: throw new System.NotSupportedException("Token type is not supported in BasicBlockInputOutputArguments");
|
||||
default: throw new System.NotSupportedException("not supported EvalDataType");
|
||||
}
|
||||
|
|
@ -155,11 +175,11 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
|
||||
private readonly MethodDef _method;
|
||||
private readonly IRandom _random;
|
||||
private readonly ModuleConstFieldAllocator _constFieldAllocator;
|
||||
private readonly ConstFieldAllocator _constFieldAllocator;
|
||||
private readonly int _minInstructionCountOfBasicBlockToObfuscate;
|
||||
private readonly BasicBlockInfo _bbHead;
|
||||
|
||||
public MethodControlFlowCalculator(MethodDef method, IRandom random, ModuleConstFieldAllocator constFieldAllocator, int minInstructionCountOfBasicBlockToObfuscate)
|
||||
public MethodControlFlowCalculator(MethodDef method, IRandom random, ConstFieldAllocator constFieldAllocator, int minInstructionCountOfBasicBlockToObfuscate)
|
||||
{
|
||||
_method = method;
|
||||
_random = random;
|
||||
|
|
@ -329,9 +349,10 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
|
||||
BlockGroup group = to.group;
|
||||
group.basicBlocks.Insert(group.basicBlocks.IndexOf(to), saveLocalBasicBlock);
|
||||
group.switchMachineCases.Add(new SwitchMachineCase { index = -1, prepareBlock = saveLocalBasicBlock, targetBlock = to});
|
||||
group.switchMachineCases.Add(new SwitchMachineCase { index = -1, prepareBlock = saveLocalBasicBlock, targetBlock = to });
|
||||
saveLocalBasicBlock.instructions.Add(Instruction.Create(OpCodes.Ldsfld, (FieldDef)null));
|
||||
saveLocalBasicBlock.instructions.Add(Instruction.Create(OpCodes.Br, group.switchMachineInst));
|
||||
saveLocalBasicBlock.instructions.Add(Instruction.Create(OpCodes.Stloc, GlobalSwitchIndexLocal));
|
||||
saveLocalBasicBlock.instructions.Add(Instruction.Create(OpCodes.Br, group.switchMachineEntryInst));
|
||||
|
||||
|
||||
return saveLocalBasicBlock;
|
||||
|
|
@ -359,72 +380,114 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
{
|
||||
Dictionary<Instruction, BasicBlockInfo> inst2bb = BuildInstructionToBasicBlockInfoDic();
|
||||
|
||||
InsertSwitchMachineBasicBlockForGroup(rootGroup, inst2bb);
|
||||
InsertSwitchMachineBasicBlockForGroup(rootGroup, inst2bb);
|
||||
}
|
||||
|
||||
//private void ShuffleBasicBlocks0(List<BasicBlockInfo> bbs)
|
||||
//{
|
||||
// int n = bbs.Count;
|
||||
// if (n <= 1)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
private void ShuffleBasicBlocks0(List<BasicBlockInfo> bbs)
|
||||
{
|
||||
if (bbs.Count <= 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// var firstSection = new List<BasicBlockInfo>() { bbs[0] };
|
||||
// var sectionsExcludeFirstLast = new List<List<BasicBlockInfo>>();
|
||||
// List<BasicBlockInfo> currentSection = firstSection;
|
||||
// for (int i = 1; i < n; i++)
|
||||
// {
|
||||
// BasicBlockInfo cur = bbs[i];
|
||||
// if (cur.inputArgs.locals.Count == 0)
|
||||
// {
|
||||
// currentSection = new List<BasicBlockInfo>() { cur };
|
||||
// sectionsExcludeFirstLast.Add(currentSection);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// currentSection.Add(cur);
|
||||
// }
|
||||
// }
|
||||
// if (sectionsExcludeFirstLast.Count <= 1)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// var lastSection = sectionsExcludeFirstLast.Last();
|
||||
// sectionsExcludeFirstLast.RemoveAt(sectionsExcludeFirstLast.Count - 1);
|
||||
var subBlocksExcludeFirstLast = bbs.GetRange(1, bbs.Count - 2);
|
||||
|
||||
var blocksInputArgsCountZero = new List<BasicBlockInfo>();
|
||||
var blocksInputArgsCountNonZero = new List<BasicBlockInfo>();
|
||||
foreach (var bb in subBlocksExcludeFirstLast)
|
||||
{
|
||||
if (bb.inputArgs.locals.Count == 0)
|
||||
{
|
||||
blocksInputArgsCountZero.Add(bb);
|
||||
}
|
||||
else
|
||||
{
|
||||
blocksInputArgsCountNonZero.Add(bb);
|
||||
}
|
||||
}
|
||||
RandomUtil.ShuffleList(blocksInputArgsCountZero, _random);
|
||||
|
||||
int index = 1;
|
||||
foreach (var bb in blocksInputArgsCountZero)
|
||||
{
|
||||
bbs[index++] = bb;
|
||||
}
|
||||
foreach (var bb in blocksInputArgsCountNonZero)
|
||||
{
|
||||
bbs[index++] = bb;
|
||||
}
|
||||
Assert.AreEqual(bbs.Count - 1, index, "Shuffled basic blocks count should be the same as original count minus first and last blocks");
|
||||
|
||||
//var firstSection = new List<BasicBlockInfo>() { bbs[0] };
|
||||
//var sectionsExcludeFirstLast = new List<List<BasicBlockInfo>>();
|
||||
//List<BasicBlockInfo> currentSection = firstSection;
|
||||
//for (int i = 1; i < n; i++)
|
||||
//{
|
||||
// BasicBlockInfo cur = bbs[i];
|
||||
// if (cur.inputArgs.locals.Count == 0)
|
||||
// {
|
||||
// currentSection = new List<BasicBlockInfo>() { cur };
|
||||
// sectionsExcludeFirstLast.Add(currentSection);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// currentSection.Add(cur);
|
||||
// }
|
||||
//}
|
||||
//if (sectionsExcludeFirstLast.Count <= 1)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//var lastSection = sectionsExcludeFirstLast.Last();
|
||||
//sectionsExcludeFirstLast.RemoveAt(sectionsExcludeFirstLast.Count - 1);
|
||||
|
||||
|
||||
// RandomUtil.ShuffleList(sectionsExcludeFirstLast, _random);
|
||||
//RandomUtil.ShuffleList(sectionsExcludeFirstLast, _random);
|
||||
|
||||
// bbs.Clear();
|
||||
// bbs.AddRange(firstSection);
|
||||
// bbs.AddRange(sectionsExcludeFirstLast.SelectMany(section => section));
|
||||
// bbs.AddRange(lastSection);
|
||||
// Assert.AreEqual(n, bbs.Count, "Shuffled basic blocks count should be the same as original count");
|
||||
//}
|
||||
//bbs.Clear();
|
||||
//bbs.AddRange(firstSection);
|
||||
//bbs.AddRange(sectionsExcludeFirstLast.SelectMany(section => section));
|
||||
//bbs.AddRange(lastSection);
|
||||
//Assert.AreEqual(n, bbs.Count, "Shuffled basic blocks count should be the same as original count");
|
||||
}
|
||||
|
||||
private void ShuffleBasicBlocks(List<BasicBlockInfo> bbs)
|
||||
{
|
||||
// TODO
|
||||
|
||||
//int n = bbs.Count;
|
||||
//BasicBlockInfo groupPrev = bbs[0].prev;
|
||||
//BasicBlockInfo groupNext = bbs[n - 1].next;
|
||||
////RandomUtil.ShuffleList(bbs, _random);
|
||||
//ShuffleBasicBlocks0(bbs);
|
||||
//BasicBlockInfo prev = groupPrev;
|
||||
//for (int i = 0; i < n; i++)
|
||||
//{
|
||||
// BasicBlockInfo cur = bbs[i];
|
||||
// cur.prev = prev;
|
||||
// prev.next = cur;
|
||||
// prev = cur;
|
||||
//}
|
||||
//prev.next = groupNext;
|
||||
//if (groupNext != null)
|
||||
//{
|
||||
// groupNext.prev = prev;
|
||||
//}
|
||||
int n = bbs.Count;
|
||||
BasicBlockInfo groupPrev = bbs[0].prev;
|
||||
BasicBlockInfo groupNext = bbs[n - 1].next;
|
||||
//RandomUtil.ShuffleList(bbs, _random);
|
||||
ShuffleBasicBlocks0(bbs);
|
||||
BasicBlockInfo prev = groupPrev;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
BasicBlockInfo cur = bbs[i];
|
||||
cur.prev = prev;
|
||||
prev.next = cur;
|
||||
prev = cur;
|
||||
}
|
||||
prev.next = groupNext;
|
||||
if (groupNext != null)
|
||||
{
|
||||
groupNext.prev = prev;
|
||||
}
|
||||
}
|
||||
|
||||
private Local _globalSwitchIndexLocal;
|
||||
|
||||
Local GlobalSwitchIndexLocal
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_globalSwitchIndexLocal == null)
|
||||
{
|
||||
_globalSwitchIndexLocal = new Local(_method.Module.CorLibTypes.Int32);
|
||||
_method.Body.Variables.Add(_globalSwitchIndexLocal);
|
||||
}
|
||||
return _globalSwitchIndexLocal;
|
||||
}
|
||||
}
|
||||
|
||||
private void InsertSwitchMachineBasicBlockForGroup(BlockGroup group, Dictionary<Instruction, BasicBlockInfo> inst2bb)
|
||||
|
|
@ -450,6 +513,8 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
var instructions = new List<Instruction>()
|
||||
{
|
||||
Instruction.Create(OpCodes.Ldsfld, (FieldDef)null),
|
||||
Instruction.Create(OpCodes.Stloc, GlobalSwitchIndexLocal),
|
||||
group.switchMachineEntryInst,
|
||||
group.switchMachineInst,
|
||||
Instruction.Create(OpCodes.Br, firstCase.targetBlock.FirstInstruction),
|
||||
};
|
||||
|
|
@ -457,7 +522,7 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
{
|
||||
instructions.Insert(0, Instruction.Create(OpCodes.Br, firstBlock.FirstInstruction));
|
||||
}
|
||||
|
||||
|
||||
var switchMachineBb = new BasicBlockInfo()
|
||||
{
|
||||
group = group,
|
||||
|
|
@ -481,7 +546,7 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
switchMachineCase.index = i;
|
||||
List<Instruction> prepareBlockInstructions = switchMachineCase.prepareBlock.instructions;
|
||||
|
||||
Instruction setBranchIndexInst = prepareBlockInstructions[prepareBlockInstructions.Count - 2];
|
||||
Instruction setBranchIndexInst = prepareBlockInstructions[prepareBlockInstructions.Count - 3];
|
||||
Assert.AreEqual(setBranchIndexInst.OpCode, OpCodes.Ldsfld, "first instruction of prepareBlock should be Ldsfld");
|
||||
//setBranchIndexInst.Operand = i;
|
||||
var indexField = _constFieldAllocator.Allocate(i);
|
||||
|
|
@ -490,9 +555,10 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
}
|
||||
|
||||
// after shuffle
|
||||
Assert.IsTrue(instructions.Count == 3 || instructions.Count == 4, "Switch machine basic block should contain 3 or 4 instructions");
|
||||
Assert.AreEqual(Code.Ldsfld, instructions[instructions.Count - 3].OpCode.Code, "First instruction should be Ldsfld");
|
||||
instructions[instructions.Count - 3].Operand = _constFieldAllocator.Allocate(firstCase.index);
|
||||
//Assert.IsTrue(instructions.Count == 4 || instructions.Count == 5, "Switch machine basic block should contain 4 or 5 instructions");
|
||||
Instruction loadFirstIndex = instructions[instructions.Count - 5];
|
||||
Assert.AreEqual(Code.Ldsfld, loadFirstIndex.OpCode.Code, "First instruction should be Ldsfld");
|
||||
loadFirstIndex.Operand = _constFieldAllocator.Allocate(firstCase.index);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -554,6 +620,7 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
|
||||
public List<BasicBlockInfo> basicBlocks;
|
||||
|
||||
public Instruction switchMachineEntryInst;
|
||||
public Instruction switchMachineInst;
|
||||
public List<SwitchMachineCase> switchMachineCases;
|
||||
|
||||
|
|
@ -664,7 +731,7 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
this.subGroups = finalGroupList;
|
||||
}
|
||||
|
||||
public void ComputeBasicBlocks(Dictionary<Instruction, BasicBlockInfo> inst2bb)
|
||||
public void ComputeBasicBlocks(Dictionary<Instruction, BasicBlockInfo> inst2bb, Func<Local> switchIndexLocalGetter)
|
||||
{
|
||||
if (subGroups == null || subGroups.Count == 0)
|
||||
{
|
||||
|
|
@ -685,13 +752,14 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
basicBlocks.Add(block);
|
||||
}
|
||||
}
|
||||
switchMachineEntryInst = Instruction.Create(OpCodes.Ldloc, switchIndexLocalGetter());
|
||||
switchMachineInst = Instruction.Create(OpCodes.Switch, new List<Instruction>());
|
||||
switchMachineCases = new List<SwitchMachineCase>();
|
||||
return;
|
||||
}
|
||||
foreach (var subGroup in subGroups)
|
||||
{
|
||||
subGroup.ComputeBasicBlocks(inst2bb);
|
||||
subGroup.ComputeBasicBlocks(inst2bb, switchIndexLocalGetter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -726,13 +794,13 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
private class ExceptionHandlerWithFilterGroup : BlockGroup
|
||||
{
|
||||
public readonly ExceptionHandler exceptionHandler;
|
||||
//public readonly ExceptionFilterGroup filterGroup;
|
||||
//public readonly ExceptionHandlerGroup handlerGroup;
|
||||
public ExceptionHandlerWithFilterGroup(ExceptionHandler exceptionHandler, List<Instruction> filterInstructions, List<Instruction> handlerInstructions, List<Instruction> allInstructions, Dictionary<Instruction, BlockGroup> inst2group) : base(allInstructions, inst2group)
|
||||
public readonly ExceptionFilterGroup filterGroup;
|
||||
public readonly ExceptionHandlerGroup handlerGroup;
|
||||
public ExceptionHandlerWithFilterGroup(ExceptionHandler exceptionHandler, ExceptionFilterGroup filterGroup, ExceptionHandlerGroup handlerGroup, List<Instruction> instructions, Dictionary<Instruction, BlockGroup> inst2group) : base(instructions, inst2group)
|
||||
{
|
||||
this.exceptionHandler = exceptionHandler;
|
||||
var filterGroup = new ExceptionFilterGroup(exceptionHandler, filterInstructions, inst2group);
|
||||
var handlerGroup = new ExceptionHandlerGroup(exceptionHandler, handlerInstructions, inst2group);
|
||||
this.filterGroup = filterGroup;
|
||||
this.handlerGroup = handlerGroup;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -765,7 +833,7 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
var tryBlocks = new List<TryBlockInfo>();
|
||||
foreach (var ex in _method.Body.ExceptionHandlers)
|
||||
{
|
||||
TryBlockInfo tryBlock = tryBlocks.Find(tryBlocks => tryBlocks.tryStart == ex.TryStart && tryBlocks.tryEnd == ex.TryEnd);
|
||||
TryBlockInfo tryBlock = tryBlocks.Find(block => block.tryStart == ex.TryStart && block.tryEnd == ex.TryEnd);
|
||||
if (tryBlock == null)
|
||||
{
|
||||
int startIndex = inst2Index[ex.TryStart];
|
||||
|
|
@ -785,9 +853,10 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
int filterEndIndex = ex.HandlerStart != null ? inst2Index[ex.HandlerStart] : inst2Index.Count;
|
||||
int handlerStartIndex = filterEndIndex;
|
||||
int handlerEndIndex = ex.HandlerEnd != null ? inst2Index[ex.HandlerEnd] : inst2Index.Count;
|
||||
var filterHandlerGroup = new ExceptionHandlerWithFilterGroup(ex,
|
||||
instructions.GetRange(filterStartIndex, filterEndIndex - filterStartIndex),
|
||||
instructions.GetRange(handlerStartIndex, handlerEndIndex - handlerStartIndex),
|
||||
|
||||
var filterGroup = new ExceptionFilterGroup(ex, instructions.GetRange(filterStartIndex, filterEndIndex - filterStartIndex), inst2blockGroup);
|
||||
var handlerGroup = new ExceptionHandlerGroup(ex, instructions.GetRange(handlerStartIndex, handlerEndIndex - handlerStartIndex), inst2blockGroup);
|
||||
var filterHandlerGroup = new ExceptionHandlerWithFilterGroup(ex, filterGroup, handlerGroup,
|
||||
instructions.GetRange(filterStartIndex, handlerEndIndex - filterStartIndex), inst2blockGroup);
|
||||
}
|
||||
else
|
||||
|
|
@ -800,7 +869,7 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
var rootGroup = new BlockGroup(new List<Instruction>(instructions), inst2blockGroup);
|
||||
rootGroup.SplitInstructionsNotInAnySubGroupsToIndividualGroups(inst2blockGroup);
|
||||
|
||||
rootGroup.ComputeBasicBlocks(BuildInstructionToBasicBlockInfoDic());
|
||||
rootGroup.ComputeBasicBlocks(BuildInstructionToBasicBlockInfoDic(), () => GlobalSwitchIndexLocal);
|
||||
return rootGroup;
|
||||
}
|
||||
|
||||
|
|
@ -870,6 +939,10 @@ namespace Obfuz.ObfusPasses.ControlFlowObfus
|
|||
//{
|
||||
// return false;
|
||||
//}
|
||||
if (_method.HasGenericParameters || _method.DeclaringType.HasGenericParameters)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var evc = new EvalStackCalculator(_method);
|
||||
BuildBasicBlockLink(evc);
|
||||
if (!CheckNotContainsNotSupportedEvalStackData())
|
||||
|
|
|
|||
|
|
@ -1,6 +1,27 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Conf;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
|
@ -63,7 +84,7 @@ namespace Obfuz.ObfusPasses.EvalStackObfus
|
|||
private static readonly ObfuscationRule s_default = new ObfuscationRule()
|
||||
{
|
||||
obfuscationLevel = ObfuscationLevel.Basic,
|
||||
obfuscationPercentage = 0.5f,
|
||||
obfuscationPercentage = 0.05f,
|
||||
};
|
||||
|
||||
private ObfuscationRule _global;
|
||||
|
|
@ -91,6 +112,10 @@ namespace Obfuz.ObfusPasses.EvalStackObfus
|
|||
{
|
||||
_global.InheritParent(s_default);
|
||||
}
|
||||
if (_global.obfuscationPercentage.Value > 0.1f)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"EvalStackObfus significantly increases the size of the obfuscated hot-update DLL. It is recommended to keep the obfuscationPercentage ≤ 0.1 (currently set to {_global.obfuscationPercentage.Value}).");
|
||||
}
|
||||
_xmlParser.InheritParentRules(_global);
|
||||
}
|
||||
|
||||
|
|
@ -103,17 +128,12 @@ namespace Obfuz.ObfusPasses.EvalStackObfus
|
|||
}
|
||||
}
|
||||
|
||||
private ObfuscationLevel ParseObfuscationLevel(string str)
|
||||
{
|
||||
return (ObfuscationLevel)Enum.Parse(typeof(ObfuscationLevel), str);
|
||||
}
|
||||
|
||||
private ObfuscationRule ParseObfuscationRule(string configFile, XmlElement ele)
|
||||
{
|
||||
var rule = new ObfuscationRule();
|
||||
if (ele.HasAttribute("obfuscationLevel"))
|
||||
{
|
||||
rule.obfuscationLevel = ParseObfuscationLevel(ele.GetAttribute("obfuscationLevel"));
|
||||
rule.obfuscationLevel = ConfigUtil.ParseObfuscationLevel(ele.GetAttribute("obfuscationLevel"));
|
||||
}
|
||||
if (ele.HasAttribute("obfuscationPercentage"))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Utils;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Data;
|
||||
|
|
@ -16,7 +36,7 @@ namespace Obfuz.ObfusPasses.EvalStackObfus
|
|||
public IRandom localRandom;
|
||||
public EncryptionScopeInfo encryptionScope;
|
||||
public DefaultMetadataImporter importer;
|
||||
public ModuleConstFieldAllocator constFieldAllocator;
|
||||
public ConstFieldAllocator constFieldAllocator;
|
||||
public float obfuscationPercentage;
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +94,9 @@ namespace Obfuz.ObfusPasses.EvalStackObfus
|
|||
|
||||
ObfuscationPassContext ctx = ObfuscationPassContext.Current;
|
||||
var calc = new EvalStackCalculator(method);
|
||||
var encryptionScope = ctx.encryptionScopeProvider.GetScope(method.Module);
|
||||
|
||||
GroupByModuleEntityManager moduleEntityManager = ctx.moduleEntityManager;
|
||||
var encryptionScope = moduleEntityManager.EncryptionScopeProvider.GetScope(method.Module);
|
||||
var ruleData = _obfuscationPolicy.GetObfuscationRuleData(method);
|
||||
var localRandom = encryptionScope.localRandomCreator(MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method));
|
||||
var obfusMethodCtx = new ObfusMethodContext
|
||||
|
|
@ -83,9 +105,9 @@ namespace Obfuz.ObfusPasses.EvalStackObfus
|
|||
evalStackCalculator = calc,
|
||||
localVariableAllocator = new LocalVariableAllocator(method),
|
||||
encryptionScope = encryptionScope,
|
||||
constFieldAllocator = ctx.constFieldAllocator.GetModuleAllocator(method.Module),
|
||||
constFieldAllocator = moduleEntityManager.GetEntity<ConstFieldAllocator>(method.Module),
|
||||
localRandom = localRandom,
|
||||
importer = ctx.moduleEntityManager.GetDefaultModuleMetadataImporter(method.Module, ctx.encryptionScopeProvider),
|
||||
importer = moduleEntityManager.GetEntity<DefaultMetadataImporter>(method.Module),
|
||||
obfuscationPercentage = ruleData.obfuscationPercentage,
|
||||
};
|
||||
for (int i = 0; i < instructions.Count; i++)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet.Emit;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,27 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Conf;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
|
@ -103,17 +124,12 @@ namespace Obfuz.ObfusPasses.ExprObfus
|
|||
}
|
||||
}
|
||||
|
||||
private ObfuscationLevel ParseObfuscationLevel(string str)
|
||||
{
|
||||
return (ObfuscationLevel)Enum.Parse(typeof(ObfuscationLevel), str);
|
||||
}
|
||||
|
||||
private ObfuscationRule ParseObfuscationRule(string configFile, XmlElement ele)
|
||||
{
|
||||
var rule = new ObfuscationRule();
|
||||
if (ele.HasAttribute("obfuscationLevel"))
|
||||
{
|
||||
rule.obfuscationLevel = ParseObfuscationLevel(ele.GetAttribute("obfuscationLevel"));
|
||||
rule.obfuscationLevel = ConfigUtil.ParseObfuscationLevel(ele.GetAttribute("obfuscationLevel"));
|
||||
}
|
||||
if (ele.HasAttribute("obfuscationPercentage"))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Data;
|
||||
|
|
@ -17,7 +37,7 @@ namespace Obfuz.ObfusPasses.ExprObfus
|
|||
public IRandom localRandom;
|
||||
public EncryptionScopeInfo encryptionScope;
|
||||
public DefaultMetadataImporter importer;
|
||||
public ModuleConstFieldAllocator constFieldAllocator;
|
||||
public ConstFieldAllocator constFieldAllocator;
|
||||
public float obfuscationPercentage;
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +140,9 @@ namespace Obfuz.ObfusPasses.ExprObfus
|
|||
|
||||
ObfuscationPassContext ctx = ObfuscationPassContext.Current;
|
||||
var calc = new EvalStackCalculator(method);
|
||||
var encryptionScope = ctx.encryptionScopeProvider.GetScope(method.Module);
|
||||
|
||||
GroupByModuleEntityManager moduleEntityManager = ctx.moduleEntityManager;
|
||||
var encryptionScope = moduleEntityManager.EncryptionScopeProvider.GetScope(method.Module);
|
||||
var ruleData = _obfuscationPolicy.GetObfuscationRuleData(method);
|
||||
var obfuscator = GetObfuscator(ruleData.obfuscationLevel);
|
||||
var obfusMethodCtx = new ObfusMethodContext
|
||||
|
|
@ -129,9 +151,9 @@ namespace Obfuz.ObfusPasses.ExprObfus
|
|||
evalStackCalculator = calc,
|
||||
localVariableAllocator = new LocalVariableAllocator(method),
|
||||
encryptionScope = encryptionScope,
|
||||
constFieldAllocator = ctx.constFieldAllocator.GetModuleAllocator(method.Module),
|
||||
constFieldAllocator = moduleEntityManager.GetEntity<ConstFieldAllocator>(method.Module),
|
||||
localRandom = encryptionScope.localRandomCreator(MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method)),
|
||||
importer = ctx.moduleEntityManager.GetDefaultModuleMetadataImporter(method.Module, ctx.encryptionScopeProvider),
|
||||
importer = moduleEntityManager.GetEntity<DefaultMetadataImporter>(method.Module),
|
||||
obfuscationPercentage = ruleData.obfuscationPercentage,
|
||||
};
|
||||
for (int i = 0; i < instructions.Count; i++)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Data;
|
||||
using Obfuz.Emit;
|
||||
|
|
@ -11,7 +31,7 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
protected bool GenerateIdentityTransformForArgument(Instruction inst, EvalDataType op, List<Instruction> outputInsts, ObfusMethodContext ctx)
|
||||
{
|
||||
IRandom random = ctx.localRandom;
|
||||
ModuleConstFieldAllocator constFieldAllocator = ctx.constFieldAllocator;
|
||||
ConstFieldAllocator constFieldAllocator = ctx.constFieldAllocator;
|
||||
switch (op)
|
||||
{
|
||||
case EvalDataType.Int32:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
|
|
@ -9,7 +29,35 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
|
||||
class BasicObfuscator : ObfuscatorBase
|
||||
{
|
||||
private IMethod GetMethod(DefaultMetadataImporter importer, Code code, EvalDataType op1)
|
||||
private IMethod GetUnaryOpMethod(DefaultMetadataImporter importer, Code code, EvalDataType op1)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case Code.Neg:
|
||||
{
|
||||
switch (op1)
|
||||
{
|
||||
case EvalDataType.Int32: return importer.NegInt;
|
||||
case EvalDataType.Int64: return importer.NegLong;
|
||||
case EvalDataType.Float: return importer.NegFloat;
|
||||
case EvalDataType.Double: return importer.NegDouble;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
case Code.Not:
|
||||
{
|
||||
switch (op1)
|
||||
{
|
||||
case EvalDataType.Int32: return importer.NotInt;
|
||||
case EvalDataType.Int64: return importer.NotLong;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
private IMethod GetBinaryOpMethod(DefaultMetadataImporter importer, Code code, EvalDataType op1, EvalDataType op2)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
|
|
@ -17,10 +65,19 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
{
|
||||
switch (op1)
|
||||
{
|
||||
case EvalDataType.Int32: return importer.AddInt;
|
||||
case EvalDataType.Int64: return importer.AddLong;
|
||||
case EvalDataType.Float: return importer.AddFloat;
|
||||
case EvalDataType.Double: return importer.AddDouble;
|
||||
case EvalDataType.Int32: return op2 == op1 ? importer.AddInt : null;
|
||||
case EvalDataType.Int64: return op2 == op1 ? importer.AddLong : null;
|
||||
case EvalDataType.Float: return op2 == op1 ? importer.AddFloat : null;
|
||||
case EvalDataType.Double: return op2 == op1 ? importer.AddDouble : null;
|
||||
case EvalDataType.I:
|
||||
{
|
||||
switch (op2)
|
||||
{
|
||||
case EvalDataType.I: return importer.AddIntPtr;
|
||||
case EvalDataType.Int32: return importer.AddIntPtrInt;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,10 +85,19 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
{
|
||||
switch (op1)
|
||||
{
|
||||
case EvalDataType.Int32: return importer.SubtractInt;
|
||||
case EvalDataType.Int64: return importer.SubtractLong;
|
||||
case EvalDataType.Float: return importer.SubtractFloat;
|
||||
case EvalDataType.Double: return importer.SubtractDouble;
|
||||
case EvalDataType.Int32: return op2 == op1 ? importer.SubtractInt : null;
|
||||
case EvalDataType.Int64: return op2 == op1 ? importer.SubtractLong : null;
|
||||
case EvalDataType.Float: return op2 == op1 ? importer.SubtractFloat : null;
|
||||
case EvalDataType.Double: return op2 == op1 ? importer.SubtractDouble : null;
|
||||
case EvalDataType.I:
|
||||
{
|
||||
switch (op2)
|
||||
{
|
||||
case EvalDataType.I: return importer.SubtractIntPtr;
|
||||
case EvalDataType.Int32: return importer.SubtractIntPtrInt;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -39,10 +105,19 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
{
|
||||
switch (op1)
|
||||
{
|
||||
case EvalDataType.Int32: return importer.MultiplyInt;
|
||||
case EvalDataType.Int64: return importer.MultiplyLong;
|
||||
case EvalDataType.Float: return importer.MultiplyFloat;
|
||||
case EvalDataType.Double: return importer.MultiplyDouble;
|
||||
case EvalDataType.Int32: return op2 == op1 ? importer.MultiplyInt : null;
|
||||
case EvalDataType.Int64: return op2 == op1 ? importer.MultiplyLong : null;
|
||||
case EvalDataType.Float: return op2 == op1 ? importer.MultiplyFloat : null;
|
||||
case EvalDataType.Double: return op2 == op1 ? importer.MultiplyDouble : null;
|
||||
case EvalDataType.I:
|
||||
{
|
||||
switch (op2)
|
||||
{
|
||||
case EvalDataType.I: return importer.MultiplyIntPtr;
|
||||
case EvalDataType.Int32: return importer.MultiplyIntPtrInt;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -166,9 +241,10 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
|
||||
public override bool ObfuscateBasicUnaryOp(Instruction inst, EvalDataType op, EvalDataType ret, List<Instruction> outputInsts, ObfusMethodContext ctx)
|
||||
{
|
||||
IMethod opMethod = GetMethod(ctx.importer, inst.OpCode.Code, op);
|
||||
IMethod opMethod = GetUnaryOpMethod(ctx.importer, inst.OpCode.Code, op);
|
||||
if (opMethod == null)
|
||||
{
|
||||
Debug.LogWarning($"BasicObfuscator: Cannot obfuscate unary operation {inst.OpCode.Code} with different operand types: op={op}. This is a limitation of the BasicObfuscator.");
|
||||
return false;
|
||||
}
|
||||
outputInsts.Add(Instruction.Create(OpCodes.Call, opMethod));
|
||||
|
|
@ -177,14 +253,10 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
|
||||
public override bool ObfuscateBasicBinOp(Instruction inst, EvalDataType op1, EvalDataType op2, EvalDataType ret, List<Instruction> outputInsts, ObfusMethodContext ctx)
|
||||
{
|
||||
if (op1 != op2)
|
||||
{
|
||||
Debug.LogWarning($"BasicObfuscator: Cannot obfuscate binary operation {inst.OpCode.Code} with different operand types: op1={op1}, op2={op2}, ret={ret}. This is a limitation of the BasicObfuscator.");
|
||||
return false;
|
||||
}
|
||||
IMethod opMethod = GetMethod(ctx.importer, inst.OpCode.Code, op1);
|
||||
IMethod opMethod = GetBinaryOpMethod(ctx.importer, inst.OpCode.Code, op1, op2);
|
||||
if (opMethod == null)
|
||||
{
|
||||
Debug.LogWarning($"BasicObfuscator: Cannot obfuscate binary operation {inst.OpCode.Code} with different operand types: op1={op1}, op2={op2}, ret={ret}. This is a limitation of the BasicObfuscator.");
|
||||
return false;
|
||||
}
|
||||
outputInsts.Add(Instruction.Create(OpCodes.Call, opMethod));
|
||||
|
|
@ -193,9 +265,10 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
|
||||
public override bool ObfuscateUnaryBitwiseOp(Instruction inst, EvalDataType op, EvalDataType ret, List<Instruction> outputInsts, ObfusMethodContext ctx)
|
||||
{
|
||||
IMethod opMethod = GetMethod(ctx.importer, inst.OpCode.Code, op);
|
||||
IMethod opMethod = GetUnaryOpMethod(ctx.importer, inst.OpCode.Code, op);
|
||||
if (opMethod == null)
|
||||
{
|
||||
Debug.LogWarning($"BasicObfuscator: Cannot obfuscate unary operation {inst.OpCode.Code} with different operand types: op={op}. This is a limitation of the BasicObfuscator.");
|
||||
return false;
|
||||
}
|
||||
outputInsts.Add(Instruction.Create(OpCodes.Call, opMethod));
|
||||
|
|
@ -204,14 +277,10 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
|
||||
public override bool ObfuscateBinBitwiseOp(Instruction inst, EvalDataType op1, EvalDataType op2, EvalDataType ret, List<Instruction> outputInsts, ObfusMethodContext ctx)
|
||||
{
|
||||
if (op1 != op2)
|
||||
{
|
||||
Debug.LogWarning($"BasicObfuscator: Cannot obfuscate binary operation {inst.OpCode.Code} with different operand types: op1={op1}, op2={op2}, ret={ret}. This is a limitation of the BasicObfuscator.");
|
||||
return false;
|
||||
}
|
||||
IMethod opMethod = GetMethod(ctx.importer, inst.OpCode.Code, op1);
|
||||
IMethod opMethod = GetBinaryOpMethod(ctx.importer, inst.OpCode.Code, op1, op2);
|
||||
if (opMethod == null)
|
||||
{
|
||||
Debug.LogWarning($"BasicObfuscator: Cannot obfuscate binary operation {inst.OpCode.Code} with different operand types: op1={op1}, op2={op2}, ret={ret}. This is a limitation of the BasicObfuscator.");
|
||||
return false;
|
||||
}
|
||||
outputInsts.Add(Instruction.Create(OpCodes.Call, opMethod));
|
||||
|
|
@ -220,14 +289,10 @@ namespace Obfuz.ObfusPasses.ExprObfus.Obfuscators
|
|||
|
||||
public override bool ObfuscateBitShiftOp(Instruction inst, EvalDataType op1, EvalDataType op2, EvalDataType ret, List<Instruction> outputInsts, ObfusMethodContext ctx)
|
||||
{
|
||||
if (op2 != EvalDataType.Int32)
|
||||
{
|
||||
Debug.LogWarning($"BasicObfuscator: Cannot obfuscate binary operation {inst.OpCode.Code} with operand type {op2}. This is a limitation of the BasicObfuscator.");
|
||||
return false;
|
||||
}
|
||||
IMethod opMethod = GetMethod(ctx.importer, inst.OpCode.Code, op1);
|
||||
IMethod opMethod = GetBinaryOpMethod(ctx.importer, inst.OpCode.Code, op1, op2);
|
||||
if (opMethod == null)
|
||||
{
|
||||
Debug.LogWarning($"BasicObfuscator: Cannot obfuscate binary operation {inst.OpCode.Code} with operand type {op2}. This is a limitation of the BasicObfuscator.");
|
||||
return false;
|
||||
}
|
||||
outputInsts.Add(Instruction.Create(OpCodes.Call, opMethod));
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Conf;
|
||||
using Obfuz.Utils;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
|
|
@ -11,22 +31,15 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
|||
{
|
||||
public class DefaultFieldEncryptor : FieldEncryptorBase
|
||||
{
|
||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||
private readonly FieldEncryptionSettingsFacade _settings;
|
||||
|
||||
public DefaultFieldEncryptor(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager, FieldEncryptionSettingsFacade settings)
|
||||
public DefaultFieldEncryptor(GroupByModuleEntityManager moduleEntityManager, FieldEncryptionSettingsFacade settings)
|
||||
{
|
||||
_encryptionScopeProvider = encryptionScopeProvider;
|
||||
_moduleEntityManager = moduleEntityManager;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
private DefaultMetadataImporter GetMetadataImporter(MethodDef method)
|
||||
{
|
||||
return _moduleEntityManager.GetDefaultModuleMetadataImporter(method.Module, _encryptionScopeProvider);
|
||||
}
|
||||
|
||||
class FieldEncryptInfo
|
||||
{
|
||||
public int encryptOps;
|
||||
|
|
@ -77,7 +90,7 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
|||
{
|
||||
return info;
|
||||
}
|
||||
EncryptionScopeInfo encryptionScope = _encryptionScopeProvider.GetScope(field.Module);
|
||||
EncryptionScopeInfo encryptionScope = _moduleEntityManager.EncryptionScopeProvider.GetScope(field.Module);
|
||||
|
||||
IRandom random = CreateRandomForField(encryptionScope.localRandomCreator, field);
|
||||
IEncryptor encryptor = encryptionScope.encryptor;
|
||||
|
|
@ -99,7 +112,7 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
|||
|
||||
public override void Encrypt(MethodDef method, FieldDef field, List<Instruction> outputInstructions, Instruction currentInstruction)
|
||||
{
|
||||
DefaultMetadataImporter importer = GetMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = _moduleEntityManager.GetEntity<DefaultMetadataImporter>(method.Module);
|
||||
EncryptionServiceMetadataImporter encryptionServiceMetadataImporter = importer.GetEncryptionServiceMetadataImporterOfModule(field.Module);
|
||||
FieldEncryptInfo fei = GetFieldEncryptInfo(field);
|
||||
if (fei.fieldType == ElementType.I4 || fei.fieldType == ElementType.U4 || fei.fieldType == ElementType.R4)
|
||||
|
|
@ -154,7 +167,7 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
|||
public override void Decrypt(MethodDef method, FieldDef field, List<Instruction> outputInstructions, Instruction currentInstruction)
|
||||
{
|
||||
outputInstructions.Add(currentInstruction.Clone());
|
||||
DefaultMetadataImporter importer = GetMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = _moduleEntityManager.GetEntity<DefaultMetadataImporter>(method.Module);
|
||||
EncryptionServiceMetadataImporter encryptionServiceMetadataImporter = importer.GetEncryptionServiceMetadataImporterOfModule(field.Module);
|
||||
FieldEncryptInfo fei = GetFieldEncryptInfo(field);
|
||||
if (fei.fieldType == ElementType.I4 || fei.fieldType == ElementType.U4 || fei.fieldType == ElementType.R4)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Settings;
|
||||
|
|
@ -24,7 +44,7 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
|||
public override void Start()
|
||||
{
|
||||
var ctx = ObfuscationPassContext.Current;
|
||||
_memoryEncryptor = new DefaultFieldEncryptor(ctx.encryptionScopeProvider, ctx.moduleEntityManager, _settings);
|
||||
_memoryEncryptor = new DefaultFieldEncryptor(ctx.moduleEntityManager, _settings);
|
||||
_encryptionPolicy = new ConfigurableEncryptPolicy(ctx.obfuzIgnoreScopeComputeCache, ctx.coreSettings.assembliesToObfuscate, _settings.ruleFiles);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.FieldEncrypt
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,27 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Editor;
|
||||
using Obfuz.Emit;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -89,7 +110,7 @@ namespace Obfuz.ObfusPasses.Instinct
|
|||
}
|
||||
|
||||
ObfuscationPassContext ctx = ObfuscationPassContext.Current;
|
||||
var importer = ctx.moduleEntityManager.GetDefaultModuleMetadataImporter(callingMethod.Module, ctx.encryptionScopeProvider);
|
||||
var importer = ctx.moduleEntityManager.GetEntity<DefaultMetadataImporter>(callingMethod.Module);
|
||||
|
||||
string methodName = methodDef.Name;
|
||||
switch (methodName)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using System.Linq;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
namespace Obfuz.ObfusPasses
|
||||
{
|
||||
public abstract class ObfuscationPassBase : IObfuscationPass
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Obfuz.ObfusPasses
|
||||
|
|
@ -16,6 +36,9 @@ namespace Obfuz.ObfusPasses
|
|||
ControlFlowObfus = 0x800,
|
||||
EvalStackObfus = 0x1000,
|
||||
|
||||
RemoveConstField = 0x100000,
|
||||
WaterMark = 0x200000,
|
||||
|
||||
AllObfus = SymbolObfus | CallObfus | ExprObfus | ControlFlowObfus | EvalStackObfus,
|
||||
AllEncrypt = ConstEncrypt | FieldEncrypt,
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d2c28a04d2997bc4d91a4c7693983d12
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Conf;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
||||
namespace Obfuz.ObfusPasses.RemoveConstField
|
||||
{
|
||||
public class ConfigurableRemoveConstFieldPolicy : RemoveConstFieldBase
|
||||
{
|
||||
class ObfuscationRule
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private readonly XmlFieldRuleParser<ObfuscationRule> _configParser;
|
||||
|
||||
public ConfigurableRemoveConstFieldPolicy(List<string> toObfuscatedAssemblyNames, List<string> configFiles)
|
||||
{
|
||||
_configParser = new XmlFieldRuleParser<ObfuscationRule>(toObfuscatedAssemblyNames, ParseRule, null);
|
||||
_configParser.LoadConfigs(configFiles);
|
||||
}
|
||||
|
||||
private ObfuscationRule ParseRule(string configFile, XmlElement ele)
|
||||
{
|
||||
return new ObfuscationRule();
|
||||
}
|
||||
|
||||
public override bool NeedPreserved(FieldDef field)
|
||||
{
|
||||
var rule = _configParser.GetFieldRule(field);
|
||||
return rule != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e3b708559fbf755419d7daf4ddce72f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.RemoveConstField
|
||||
{
|
||||
public interface IRemoveConstFieldPolicy
|
||||
{
|
||||
bool NeedPreserved(FieldDef field);
|
||||
}
|
||||
|
||||
public abstract class RemoveConstFieldBase : IRemoveConstFieldPolicy
|
||||
{
|
||||
public abstract bool NeedPreserved(FieldDef field);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5fad0b7ef9225b24cacc94f8dcaee26d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using Obfuz.Settings;
|
||||
using Obfuz.Utils;
|
||||
using System.Linq;
|
||||
|
||||
namespace Obfuz.ObfusPasses.RemoveConstField
|
||||
{
|
||||
|
||||
public class RemoveConstFieldPass : ObfuscationPassBase
|
||||
{
|
||||
private RemoveConstFieldSettingsFacade _settings;
|
||||
private ObfuzIgnoreScopeComputeCache _obfuzIgnoreScopeComputeCache;
|
||||
private IRemoveConstFieldPolicy _removeConstFieldPolicy;
|
||||
|
||||
public override ObfuscationPassType Type => ObfuscationPassType.RemoveConstField;
|
||||
|
||||
public RemoveConstFieldPass(RemoveConstFieldSettingsFacade settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
var ctx = ObfuscationPassContext.Current;
|
||||
_obfuzIgnoreScopeComputeCache = ctx.obfuzIgnoreScopeComputeCache;
|
||||
_removeConstFieldPolicy = new ConfigurableRemoveConstFieldPolicy(ctx.coreSettings.assembliesToObfuscate, _settings.ruleFiles);
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Process()
|
||||
{
|
||||
var ctx = ObfuscationPassContext.Current;
|
||||
var modules = ctx.modulesToObfuscate;
|
||||
ConfigurablePassPolicy passPolicy = ctx.passPolicy;
|
||||
foreach (ModuleDef mod in modules)
|
||||
{
|
||||
// ToArray to avoid modify list exception
|
||||
foreach (TypeDef type in mod.GetTypes())
|
||||
{
|
||||
if (type.IsEnum)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach (FieldDef field in type.Fields.ToArray())
|
||||
{
|
||||
if (!field.IsLiteral)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!Support(passPolicy.GetFieldObfuscationPasses(field)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_obfuzIgnoreScopeComputeCache.HasSelfOrDeclaringOrEnclosingOrInheritObfuzIgnoreScope(field, field.DeclaringType, ObfuzScope.Field))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_removeConstFieldPolicy.NeedPreserved(field))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
field.DeclaringType = null;
|
||||
//Debug.Log($"Remove const field {field.FullName} in type {type.FullName} in module {mod.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3188de094ab4cdd47b55c2f622251cf5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.SymbolObfus
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.SymbolObfus
|
||||
|
|
|
|||
|
|
@ -1,6 +1,24 @@
|
|||
using System.Text;
|
||||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
namespace Obfuz.ObfusPasses.SymbolObfus.NameMakers
|
||||
namespace Obfuz.ObfusPasses.SymbolObfus.NameMakers
|
||||
{
|
||||
public class DebugNameMaker : NameMakerBase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
namespace Obfuz.ObfusPasses.SymbolObfus.NameMakers
|
||||
{
|
||||
public interface INameScope
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using dnlib.DotNet;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Assertions;
|
||||
|
|
@ -95,7 +115,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus.NameMakers
|
|||
|
||||
public virtual string GetNewName(ParamDef param, string originalName)
|
||||
{
|
||||
return "1";
|
||||
return $"_{param.Sequence}";
|
||||
}
|
||||
|
||||
public string GetNewName(FieldDef fieldDef, string originalName)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.ObfusPasses.SymbolObfus.NameMakers
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
// Copyright 2025 Code Philosophy
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue