Skip to content

Commit

Permalink
fixed compatibility of renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
yck1509 committed Mar 6, 2014
1 parent b92e4c5 commit 79fa58e
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 18 deletions.
5 changes: 4 additions & 1 deletion Confuser.Core/DependencyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public IList<Protection> SortDependency()
if (after != null)
{
//targetNodes --> protNode
IEnumerable<DependencyGraphNode> targetNodes = before.Ids.Select(id => id2Nodes[id]);
IEnumerable<DependencyGraphNode> targetNodes = after.Ids.Select(id => id2Nodes[id]);
foreach (var node in targetNodes)
{
node.TargetNodes.Add(protNode);
Expand All @@ -126,6 +126,8 @@ DependencyGraphNode[] SortNodes(DependencyGraphNode root)
Action<DependencyGraphNode> visit = null;
visit = node =>
{
if (ret.Contains(node))
return;
visited.Add(node);
foreach (var targetNode in node.TargetNodes)
{
Expand All @@ -134,6 +136,7 @@ DependencyGraphNode[] SortNodes(DependencyGraphNode root)
visit(targetNode);
}
ret.Add(node);
visited.Remove(node);
};
visit(root);
ret.Reverse();
Expand Down
4 changes: 2 additions & 2 deletions Confuser.Core/ProtectionDependencyAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Confuser.Core
/// Indicates the <see cref="Protection"/> must initialize before the specified protections.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
class BeforeProtectionAttribute : Attribute
public class BeforeProtectionAttribute : Attribute
{
/// <summary>
/// Gets the full IDs of the specified protections.
Expand All @@ -31,7 +31,7 @@ public BeforeProtectionAttribute(params string[] ids)
/// Indicates the <see cref="Protection"/> must initialize after the specified protections.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
class AfterProtectionAttribute : Attribute
public class AfterProtectionAttribute : Attribute
{
/// <summary>
/// Gets the full IDs of the specified protections.
Expand Down
4 changes: 3 additions & 1 deletion Confuser.Protections/AntiDebugProtection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected override void Execute(ConfuserContext context, ProtectionParameters pa
marker.Mark(member);
name.Analyze(member);
}
name.SetCanRename(attr, false);
break;
default:
throw new UnreachableException();
Expand All @@ -120,7 +121,8 @@ protected override void Execute(ConfuserContext context, ProtectionParameters pa
MethodDef method = (MethodDef)member;
if (method.Access == MethodAttributes.Public)
method.Access = MethodAttributes.Assembly;
method.IsSpecialName = false;
if (!method.IsConstructor)
method.IsSpecialName = false;
var ca = method.CustomAttributes.Find(attrName);
if (ca != null)
ca.Constructor = attr.FindMethod(".ctor");
Expand Down
5 changes: 5 additions & 0 deletions Confuser.Renamer/AnalyzePhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ void Analyze(NameService service, ConfuserContext context, TypeDef type)
// Courtesy
service.SetCanRename(type, false);
}

if (type.BaseType != null && type.BaseType.DefinitionAssembly.IsCorLib() && type.BaseType.FullName == "System.Attribute")
{
service.SetRenameMode(type, RenameMode.Letters);
}
}

void Analyze(NameService service, ConfuserContext context, MethodDef method)
Expand Down
5 changes: 5 additions & 0 deletions Confuser.Renamer/BAML/BAMLAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ void AddTypeSigReference(TypeSig typeSig, INameReference<IDefinition> reference)
{
var typeDef = type.ResolveTypeDefThrow();
if (context.Modules.Contains((ModuleDefMD)typeDef.Module))
{
service.SetRenameMode(typeDef, RenameMode.Letters);
service.AddReference(typeDef, reference);
}
}
}

Expand Down Expand Up @@ -472,13 +475,15 @@ void ProcessConverter(PropertyWithConverterRecord rec, TypeDef type)
{
var reference = new BAMLConverterMemberReference(xmlnsCtx, sig, property, rec);
AddTypeSigReference(sig, reference);
service.SetRenameMode(property, RenameMode.Letters);
service.AddReference(property, reference);
}
FieldDef field = typeDef.FindField(cmdName);
if (field != null)
{
var reference = new BAMLConverterMemberReference(xmlnsCtx, sig, field, rec);
AddTypeSigReference(sig, reference);
service.SetRenameMode(field, RenameMode.Letters);
service.AddReference(field, reference);
}
if (property == null && field == null)
Expand Down
2 changes: 1 addition & 1 deletion Confuser.Renamer/NameProtection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void PopulatePipeline(ProtectionPipeline pipeline)
{
pipeline.InsertPostStage(PipelineStage.Inspection, new AnalyzePhase(this));
pipeline.InsertPreStage(PipelineStage.EndModule, new RenamePhase(this));
pipeline.InsertPostStage(PipelineStage.OptimizeMethods, new PostRenamePhase(this));
pipeline.InsertPostStage(PipelineStage.EndModule, new PostRenamePhase(this));
}

public override string Name
Expand Down
9 changes: 7 additions & 2 deletions Confuser.Runtime/AntiDebug.Antinet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ static partial class AntiDebugAntinet
{
static unsafe void Initialize()
{
if (!InitializeAntiDebugger() || !InitializeAntiProfiler())
if (!InitializeAntiDebugger())
Environment.FailFast(null);
PreventActiveProfilerFromReceivingProfilingMessages();
InitializeAntiProfiler();
if (IsProfilerAttached)
{
Environment.FailFast(null);
PreventActiveProfilerFromReceivingProfilingMessages();
}
}
}
}
10 changes: 5 additions & 5 deletions Confuser.Runtime/antinet/AntiManagedProfiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ static partial class AntiDebugAntinet
/// pipe anymore.
/// </para>
/// </remarks>
static IProfilerDetector profilerDetector;
static ProfilerDetector profilerDetector;

abstract class IProfilerDetector
abstract class ProfilerDetector
{
public abstract bool IsProfilerAttached();
public abstract bool WasProfilerAttached();
public abstract bool Init();
public abstract void PreventActiveProfilerFromReceivingProfilingMessages();
}

class ProfilerDetectorCLR20 : IProfilerDetector
class ProfilerDetectorCLR20 : ProfilerDetector
{
/// <summary>
/// Address of CLR 2.0's profiler status flag. If one or both of bits 1 or 2 is set,
Expand Down Expand Up @@ -182,7 +182,7 @@ public override unsafe void PreventActiveProfilerFromReceivingProfilingMessages(
}
}

class ProfilerDetectorCLR40 : IProfilerDetector
class ProfilerDetectorCLR40 : ProfilerDetector
{
const uint PIPE_ACCESS_DUPLEX = 3;
const uint PIPE_TYPE_MESSAGE = 4;
Expand Down Expand Up @@ -925,7 +925,7 @@ static bool InitializeAntiProfiler()
return profilerDetector.Init();
}

static IProfilerDetector CreateProfilerDetector()
static ProfilerDetector CreateProfilerDetector()
{
if (Environment.Version.Major == 2)
return new ProfilerDetectorCLR20();
Expand Down
6 changes: 0 additions & 6 deletions Confuser.Runtime/antinet/PEInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@ public static bool IsAligned(IntPtr addr, uint alignment)
{
return ((uint)addr.ToInt64() & (alignment - 1)) == 0;
}

/// <inheritdoc/>
public override string ToString()
{
return string.Format("{0:X8} - {1:X8}", (ulong)imageBase.ToInt64(), (ulong)imageEnd.ToInt64());
}
}
}
}

0 comments on commit 79fa58e

Please sign in to comment.