using System; using System.Collections.Generic; using dnlib.DotNet; namespace Confuser.Core.Services { internal class MarkerService : IMarkerService { readonly ConfuserContext context; readonly Marker marker; readonly Dictionary helperParents; /// /// Initializes a new instance of the class. /// /// The working context. /// The marker. public MarkerService(ConfuserContext context, Marker marker) { this.context = context; this.marker = marker; helperParents = new Dictionary(); } /// public void Mark(IDnlibDef member, ConfuserComponent parentComp) { if (member == null) throw new ArgumentNullException("member"); if (member is ModuleDef) throw new ArgumentException("New ModuleDef cannot be marked."); if (IsMarked(member)) // avoid double marking return; marker.MarkMember(member, context); if (parentComp != null) helperParents[member] = parentComp; } /// public bool IsMarked(IDnlibDef def) { return ProtectionParameters.GetParameters(context, def) != null; } /// public ConfuserComponent GetHelperParent(IDnlibDef def) { ConfuserComponent parent; if (!helperParents.TryGetValue(def, out parent)) return null; return parent; } } /// /// Provides methods to access the obfuscation marker. /// public interface IMarkerService { /// /// Marks the helper member. /// /// The helper member. /// The parent component. /// is a . /// is null. void Mark(IDnlibDef member, ConfuserComponent parentComp); /// /// Determines whether the specified definition is marked. /// /// The definition. /// true if the specified definition is marked; otherwise, false. bool IsMarked(IDnlibDef def); /// /// Gets the parent component of the specified helper. /// /// The helper definition. /// The parent component of the helper, or null if the specified definition is not a helper. ConfuserComponent GetHelperParent(IDnlibDef def); } }