mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00
Simplify string obfuscation processing
This commit is contained in:
parent
8534c08f49
commit
56875e0641
@ -64,7 +64,7 @@ namespace UnityExplorer
|
|||||||
#region Deobfuscation cache
|
#region Deobfuscation cache
|
||||||
|
|
||||||
private static readonly Dictionary<string, Type> DeobfuscatedTypes = new Dictionary<string, Type>();
|
private static readonly Dictionary<string, Type> DeobfuscatedTypes = new Dictionary<string, Type>();
|
||||||
//internal static Dictionary<string, string> s_deobfuscatedTypeNames = new Dictionary<string, string>();
|
private static readonly Dictionary<string, string> reverseDeobCache = new Dictionary<string, string>();
|
||||||
|
|
||||||
private static void BuildDeobfuscationCache()
|
private static void BuildDeobfuscationCache()
|
||||||
{
|
{
|
||||||
@ -83,7 +83,6 @@ namespace UnityExplorer
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Thanks to Slaynash for this
|
// Thanks to Slaynash for this
|
||||||
|
|
||||||
if (type.CustomAttributes.Any(it => it.AttributeType.Name == "ObfuscatedNameAttribute"))
|
if (type.CustomAttributes.Any(it => it.AttributeType.Name == "ObfuscatedNameAttribute"))
|
||||||
{
|
{
|
||||||
var cppType = Il2CppType.From(type);
|
var cppType = Il2CppType.From(type);
|
||||||
@ -91,13 +90,21 @@ namespace UnityExplorer
|
|||||||
if (!DeobfuscatedTypes.ContainsKey(cppType.FullName))
|
if (!DeobfuscatedTypes.ContainsKey(cppType.FullName))
|
||||||
{
|
{
|
||||||
DeobfuscatedTypes.Add(cppType.FullName, type);
|
DeobfuscatedTypes.Add(cppType.FullName, type);
|
||||||
//s_deobfuscatedTypeNames.Add(cppType.FullName, type.FullName);
|
reverseDeobCache.Add(type.FullName, cppType.FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal override string Internal_ProcessTypeInString(string theString, Type type)
|
||||||
|
{
|
||||||
|
if (reverseDeobCache.TryGetValue(type.FullName, out string obName))
|
||||||
|
return theString.Replace(obName, type.FullName);
|
||||||
|
|
||||||
|
return theString;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// Get type by name
|
// Get type by name
|
||||||
@ -287,10 +294,7 @@ namespace UnityExplorer
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (type.IsEnum)
|
if (type.IsEnum)
|
||||||
{
|
|
||||||
// TODO not tested
|
|
||||||
return Il2CppSystem.Enum.ToObject(Il2CppType.From(type), (ulong)value);
|
return Il2CppSystem.Enum.ToObject(Il2CppType.From(type), (ulong)value);
|
||||||
}
|
|
||||||
|
|
||||||
if (type.IsPrimitive && AllTypes.TryGetValue($"Il2Cpp{type.FullName}", out Type cppType))
|
if (type.IsPrimitive && AllTypes.TryGetValue($"Il2Cpp{type.FullName}", out Type cppType))
|
||||||
{
|
{
|
||||||
@ -358,22 +362,6 @@ namespace UnityExplorer
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override string Internal_ProcessTypeInString(string theString, Type type, ref string typeName)
|
|
||||||
{
|
|
||||||
if (!Il2CppTypeNotNull(type))
|
|
||||||
return theString;
|
|
||||||
|
|
||||||
var cppType = Il2CppType.From(type);
|
|
||||||
if (cppType != null && DeobfuscatedTypes.ContainsKey(cppType.FullName))
|
|
||||||
{
|
|
||||||
typeName = DeobfuscatedTypes[cppType.FullName].FullName;
|
|
||||||
theString = theString.Replace(cppType.FullName, typeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return theString;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,10 +105,10 @@ namespace UnityExplorer
|
|||||||
=> obj;
|
=> obj;
|
||||||
|
|
||||||
// Processing deobfuscated type names in strings
|
// Processing deobfuscated type names in strings
|
||||||
public static string ProcessTypeInString(Type type, string theString, ref string typeName)
|
public static string ProcessTypeInString(Type type, string theString)
|
||||||
=> Instance.Internal_ProcessTypeInString(theString, type, ref typeName);
|
=> Instance.Internal_ProcessTypeInString(theString, type);
|
||||||
|
|
||||||
internal virtual string Internal_ProcessTypeInString(string theString, Type type, ref string typeName)
|
internal virtual string Internal_ProcessTypeInString(string theString, Type type)
|
||||||
=> theString;
|
=> theString;
|
||||||
|
|
||||||
// Force loading modules
|
// Force loading modules
|
||||||
|
@ -166,15 +166,14 @@ namespace UnityExplorer.UI.Utility
|
|||||||
toString = ex.ReflectionExToString();
|
toString = ex.ReflectionExToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
string _ = null;
|
toString = ReflectionUtility.ProcessTypeInString(type, toString);
|
||||||
toString = ReflectionUtility.ProcessTypeInString(type, toString, ref _);
|
|
||||||
|
|
||||||
#if CPP
|
#if CPP
|
||||||
if (value is Il2CppSystem.Type cppType)
|
if (value is Il2CppSystem.Type cppType)
|
||||||
{
|
{
|
||||||
var monoType = Il2CppReflection.GetUnhollowedType(cppType);
|
var monoType = Il2CppReflection.GetUnhollowedType(cppType);
|
||||||
if (monoType != null)
|
if (monoType != null)
|
||||||
toString = ReflectionUtility.ProcessTypeInString(monoType, toString, ref _);
|
toString = ReflectionUtility.ProcessTypeInString(monoType, toString);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user