修复给虚函数分配名字时未考虑到不要与每个虚函数所在命名空间不冲突的bug
parent
5de469c4a6
commit
5f4083066b
|
@ -22,6 +22,8 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
|||
|
||||
string GetNewName(MethodDef methodDef, string originalName);
|
||||
|
||||
string GetNewName(VirtualMethodGroup virtualMethodGroup, string originalName);
|
||||
|
||||
string GetNewName(ParamDef param, string originalName);
|
||||
|
||||
string GetNewName(FieldDef fieldDef, string originalName);
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
{
|
||||
public interface INameScope
|
||||
{
|
||||
void AddPreservedName(string name);
|
||||
bool AddPreservedName(string name);
|
||||
|
||||
bool IsNamePreserved(string name);
|
||||
|
||||
string GetNewName(string originalName, bool reuse);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Obfuz.ObfusPasses.SymbolObfus.NameMakers
|
||||
{
|
||||
|
@ -77,7 +78,29 @@ namespace Obfuz.ObfusPasses.SymbolObfus.NameMakers
|
|||
|
||||
public string GetNewName(MethodDef methodDef, string originalName)
|
||||
{
|
||||
return (methodDef.IsVirtual ? ">" : "") + GetDefaultNewName(methodDef.DeclaringType, originalName);
|
||||
Assert.IsFalse(methodDef.IsVirtual);
|
||||
return GetDefaultNewName(methodDef.DeclaringType, originalName);
|
||||
}
|
||||
|
||||
public string GetNewName(VirtualMethodGroup virtualMethodGroup, string originalName)
|
||||
{
|
||||
var scope = GetNameScope(virtualMethodGroup);
|
||||
while (true)
|
||||
{
|
||||
string newName = scope.GetNewName(originalName, false);
|
||||
if (virtualMethodGroup.methods.Any(m => GetNameScope(m).IsNamePreserved(newName)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var method in virtualMethodGroup.methods)
|
||||
{
|
||||
GetNameScope(method).AddPreservedName(newName);
|
||||
}
|
||||
return newName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string GetNewName(ParamDef param, string originalName)
|
||||
|
|
|
@ -11,12 +11,18 @@ namespace Obfuz.ObfusPasses.SymbolObfus.NameMakers
|
|||
private readonly HashSet<string> _preservedNames = new HashSet<string>();
|
||||
|
||||
|
||||
public void AddPreservedName(string name)
|
||||
public bool AddPreservedName(string name)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
_preservedNames.Add(name);
|
||||
return _preservedNames.Add(name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsNamePreserved(string name)
|
||||
{
|
||||
return _preservedNames.Contains(name);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue