Merge remote-tracking branch 'upstream/main'
commit
e6fd9d404c
|
|
@ -49,6 +49,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
private readonly Dictionary<ModuleDef, List<CustomAttributeInfo>> _customAttributeArgumentsWithTypeByMods = new Dictionary<ModuleDef, List<CustomAttributeInfo>>();
|
private readonly Dictionary<ModuleDef, List<CustomAttributeInfo>> _customAttributeArgumentsWithTypeByMods = new Dictionary<ModuleDef, List<CustomAttributeInfo>>();
|
||||||
private readonly RenameRecordMap _renameRecordMap;
|
private readonly RenameRecordMap _renameRecordMap;
|
||||||
private readonly VirtualMethodGroupCalculator _virtualMethodGroupCalculator;
|
private readonly VirtualMethodGroupCalculator _virtualMethodGroupCalculator;
|
||||||
|
private readonly List<MethodDef> _virtualMethods = new List<MethodDef>();
|
||||||
private readonly List<Type> _customPolicyTypes;
|
private readonly List<Type> _customPolicyTypes;
|
||||||
|
|
||||||
class CustomAttributeInfo
|
class CustomAttributeInfo
|
||||||
|
|
@ -205,6 +206,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
public void Process()
|
public void Process()
|
||||||
{
|
{
|
||||||
_renameRecordMap.Init(_toObfuscatedModules, _nameMaker);
|
_renameRecordMap.Init(_toObfuscatedModules, _nameMaker);
|
||||||
|
BuildVirtualMethodGroup();
|
||||||
RenameTypes();
|
RenameTypes();
|
||||||
RenameFields();
|
RenameFields();
|
||||||
RenameMethods();
|
RenameMethods();
|
||||||
|
|
@ -525,11 +527,28 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BuildVirtualMethodGroup()
|
||||||
|
{
|
||||||
|
foreach (ModuleDef mod in _obfuscatedAndNotObfuscatedModules)
|
||||||
|
{
|
||||||
|
foreach (TypeDef type in mod.GetTypes())
|
||||||
|
{
|
||||||
|
_virtualMethodGroupCalculator.CalculateType(type);
|
||||||
|
foreach (MethodDef method in type.Methods)
|
||||||
|
{
|
||||||
|
if (method.IsVirtual)
|
||||||
|
{
|
||||||
|
_virtualMethods.Add(method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RenameMethods()
|
private void RenameMethods()
|
||||||
{
|
{
|
||||||
//Debug.Log("Rename methods begin");
|
//Debug.Log("Rename methods begin");
|
||||||
//Debug.Log("Rename not virtual methods begin");
|
//Debug.Log("Rename not virtual methods begin");
|
||||||
var virtualMethods = new List<MethodDef>();
|
|
||||||
var refMethodMetasMap = new Dictionary<MethodDef, RefMethodMetas>();
|
var refMethodMetasMap = new Dictionary<MethodDef, RefMethodMetas>();
|
||||||
BuildRefMethodMetasMap(refMethodMetasMap);
|
BuildRefMethodMetasMap(refMethodMetasMap);
|
||||||
foreach (ModuleDef mod in _toObfuscatedModules)
|
foreach (ModuleDef mod in _toObfuscatedModules)
|
||||||
|
|
@ -538,6 +557,8 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
{
|
{
|
||||||
foreach (MethodDef method in type.Methods)
|
foreach (MethodDef method in type.Methods)
|
||||||
{
|
{
|
||||||
|
// always rename method params, even if the method is not renamed
|
||||||
|
RenameMethodParams(method);
|
||||||
if (method.IsVirtual)
|
if (method.IsVirtual)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -550,28 +571,13 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (ModuleDef mod in _obfuscatedAndNotObfuscatedModules)
|
|
||||||
{
|
|
||||||
foreach (TypeDef type in mod.GetTypes())
|
|
||||||
{
|
|
||||||
_virtualMethodGroupCalculator.CalculateType(type);
|
|
||||||
foreach (MethodDef method in type.Methods)
|
|
||||||
{
|
|
||||||
if (method.IsVirtual)
|
|
||||||
{
|
|
||||||
virtualMethods.Add(method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Debug.Log("Rename not virtual methods end");
|
//Debug.Log("Rename not virtual methods end");
|
||||||
|
|
||||||
|
|
||||||
//Debug.Log("Rename virtual methods begin");
|
//Debug.Log("Rename virtual methods begin");
|
||||||
var visitedVirtualMethods = new HashSet<MethodDef>();
|
var visitedVirtualMethods = new HashSet<MethodDef>();
|
||||||
var groupNeedRenames = new Dictionary<VirtualMethodGroup, bool>();
|
var groupNeedRenames = new Dictionary<VirtualMethodGroup, bool>();
|
||||||
foreach (var method in virtualMethods)
|
foreach (var method in _virtualMethods)
|
||||||
{
|
{
|
||||||
if (!visitedVirtualMethods.Add(method))
|
if (!visitedVirtualMethods.Add(method))
|
||||||
{
|
{
|
||||||
|
|
@ -751,7 +757,8 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
foreach (TypeRef typeRef in refTypeDefMeta.typeRefs)
|
foreach (TypeRef typeRef in refTypeDefMeta.typeRefs)
|
||||||
{
|
{
|
||||||
Assert.AreEqual(typeRef.FullName, oldFullName);
|
Assert.AreEqual(typeRef.FullName, oldFullName);
|
||||||
Assert.IsTrue(typeRef.DefinitionAssembly.Name == moduleName);
|
// Assert fail when typeRef to a fowarded type
|
||||||
|
// Assert.IsTrue(typeRef.DefinitionAssembly.Name == moduleName);
|
||||||
if (!string.IsNullOrEmpty(oldNamespace))
|
if (!string.IsNullOrEmpty(oldNamespace))
|
||||||
{
|
{
|
||||||
typeRef.Namespace = newNamespace;
|
typeRef.Namespace = newNamespace;
|
||||||
|
|
@ -805,7 +812,6 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
private void Rename(MethodDef method, RefMethodMetas refMethodMetas, string newName)
|
private void Rename(MethodDef method, RefMethodMetas refMethodMetas, string newName)
|
||||||
{
|
{
|
||||||
ModuleDefMD mod = (ModuleDefMD)method.DeclaringType.Module;
|
ModuleDefMD mod = (ModuleDefMD)method.DeclaringType.Module;
|
||||||
RenameMethodParams(method);
|
|
||||||
RenameMethodBody(method);
|
RenameMethodBody(method);
|
||||||
if (refMethodMetas != null)
|
if (refMethodMetas != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,15 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
case ElementType.Class:
|
case ElementType.Class:
|
||||||
case ElementType.ValueType:
|
case ElementType.ValueType:
|
||||||
{
|
{
|
||||||
return t1.AssemblyQualifiedName == t2.AssemblyQualifiedName;
|
if (t1.AssemblyQualifiedName == t2.AssemblyQualifiedName)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (t1.FullName == t2.FullName)
|
||||||
|
{
|
||||||
|
return t1.ToTypeDefOrRef().ResolveTypeDefThrow() == t2.ToTypeDefOrRef().ResolveTypeDefThrow();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
case ElementType.Ptr:
|
case ElementType.Ptr:
|
||||||
case ElementType.ByRef:
|
case ElementType.ByRef:
|
||||||
|
|
|
||||||
|
|
@ -330,6 +330,7 @@ namespace Obfuz
|
||||||
|
|
||||||
private void LoadAssemblies(AssemblyCache assemblyCache, List<ModuleDef> modulesToObfuscate, List<ModuleDef> allObfuscationRelativeModules)
|
private void LoadAssemblies(AssemblyCache assemblyCache, List<ModuleDef> modulesToObfuscate, List<ModuleDef> allObfuscationRelativeModules)
|
||||||
{
|
{
|
||||||
|
assemblyCache.LoadModule("Obfuz.Runtime");
|
||||||
foreach (string assName in _allObfuscationRelativeAssemblyNames)
|
foreach (string assName in _allObfuscationRelativeAssemblyNames)
|
||||||
{
|
{
|
||||||
ModuleDefMD mod = assemblyCache.TryLoadModule(assName);
|
ModuleDefMD mod = assemblyCache.TryLoadModule(assName);
|
||||||
|
|
|
||||||
|
|
@ -90,23 +90,28 @@ namespace Obfuz
|
||||||
|
|
||||||
public static List<string> BuildUnityAssemblySearchPaths(bool searchPathIncludeUnityEditorDll = false)
|
public static List<string> BuildUnityAssemblySearchPaths(bool searchPathIncludeUnityEditorDll = false)
|
||||||
{
|
{
|
||||||
|
#if UNITY_6000_3_OR_NEWER && UNITY_EDITOR_OSX
|
||||||
|
string monoBleedingEdgePath = "Resources/Scripting/MonoBleedingEdge";
|
||||||
|
#else
|
||||||
|
string monoBleedingEdgePath = "MonoBleedingEdge";
|
||||||
|
#endif
|
||||||
string applicationContentsPath = EditorApplication.applicationContentsPath;
|
string applicationContentsPath = EditorApplication.applicationContentsPath;
|
||||||
var searchPaths = new List<string>
|
var searchPaths = new List<string>
|
||||||
{
|
{
|
||||||
#if UNITY_2021_1_OR_NEWER
|
#if UNITY_2021_1_OR_NEWER
|
||||||
#if UNITY_STANDALONE_WIN || (UNITY_EDITOR_WIN && UNITY_SERVER) || UNITY_WSA || UNITY_LUMIN
|
#if UNITY_STANDALONE_WIN || (UNITY_EDITOR_WIN && UNITY_SERVER) || UNITY_WSA || UNITY_LUMIN
|
||||||
"MonoBleedingEdge/lib/mono/unityaot-win32",
|
$"{monoBleedingEdgePath}/lib/mono/unityaot-win32",
|
||||||
"MonoBleedingEdge/lib/mono/unityaot-win32/Facades",
|
$"{monoBleedingEdgePath}/lib/mono/unityaot-win32/Facades",
|
||||||
#elif UNITY_STANDALONE_OSX || (UNITY_EDITOR_OSX && UNITY_SERVER) || UNITY_IOS || UNITY_TVOS
|
#elif UNITY_STANDALONE_OSX || (UNITY_EDITOR_OSX && UNITY_SERVER) || UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS
|
||||||
"MonoBleedingEdge/lib/mono/unityaot-macos",
|
$"{monoBleedingEdgePath}/lib/mono/unityaot-macos",
|
||||||
"MonoBleedingEdge/lib/mono/unityaot-macos/Facades",
|
$"{monoBleedingEdgePath}/lib/mono/unityaot-macos/Facades",
|
||||||
|
#else
|
||||||
|
$"{monoBleedingEdgePath}/lib/mono/unityaot-linux",
|
||||||
|
$"{monoBleedingEdgePath}/lib/mono/unityaot-linux/Facades",
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
"MonoBleedingEdge/lib/mono/unityaot-linux",
|
$"{monoBleedingEdgePath}/lib/mono/unityaot",
|
||||||
"MonoBleedingEdge/lib/mono/unityaot-linux/Facades",
|
$"{monoBleedingEdgePath}/lib/mono/unityaot/Facades",
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
"MonoBleedingEdge/lib/mono/unityaot",
|
|
||||||
"MonoBleedingEdge/lib/mono/unityaot/Facades",
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if UNITY_STANDALONE_WIN || (UNITY_EDITOR_WIN && UNITY_SERVER)
|
#if UNITY_STANDALONE_WIN || (UNITY_EDITOR_WIN && UNITY_SERVER)
|
||||||
|
|
@ -135,6 +140,8 @@ namespace Obfuz
|
||||||
"PlaybackEngines/WSASupport/Variations/il2cpp/Managed",
|
"PlaybackEngines/WSASupport/Variations/il2cpp/Managed",
|
||||||
#elif UNITY_LUMIN
|
#elif UNITY_LUMIN
|
||||||
"PlaybackEngines/LuminSupport/Variations/il2cpp/Managed",
|
"PlaybackEngines/LuminSupport/Variations/il2cpp/Managed",
|
||||||
|
#elif UNITY_PS5
|
||||||
|
"PlaybackEngines/PS5Player/Variations/il2cpp/Managed",
|
||||||
#else
|
#else
|
||||||
#error "Unsupported platform, please report to us"
|
#error "Unsupported platform, please report to us"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,13 @@ namespace Obfuz.Utils
|
||||||
{
|
{
|
||||||
public static bool IsMonoBackend()
|
public static bool IsMonoBackend()
|
||||||
{
|
{
|
||||||
return PlayerSettings.GetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup)
|
BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||||
== ScriptingImplementation.Mono2x;
|
#if UNITY_6000_0_OR_NEWER
|
||||||
|
var namedBuildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
|
||||||
|
return PlayerSettings.GetScriptingBackend(namedBuildTarget) == ScriptingImplementation.Mono2x;
|
||||||
|
#else
|
||||||
|
return PlayerSettings.GetScriptingBackend(buildTargetGroup) == ScriptingImplementation.Mono2x;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue