This commit is contained in:
yck1509 2014-12-29 01:26:59 +08:00
Родитель d4c528a498
Коммит 8885b9778f
27 изменённых файлов: 307 добавлений и 40 удалений

Просмотреть файл

@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using Confuser.Core.Services;
using dnlib.DotNet;
namespace Confuser.Core.API {
internal class APIStore : IAPIStore {
readonly ConfuserContext context;
readonly RandomGenerator random;
readonly SortedList<int, List<IDataStore>> dataStores;
readonly List<IOpaquePredicateDescriptor> predicates;
/// <summary>
/// Initializes a new instance of the <see cref="APIStore" /> class.
/// </summary>
/// <param name="context">The working context.</param>
public APIStore(ConfuserContext context) {
this.context = context;
random = context.Registry.GetService<IRandomService>().GetRandomGenerator("APIStore");
dataStores = new SortedList<int, List<IDataStore>>();
predicates = new List<IOpaquePredicateDescriptor>();
}
/// <inheritdoc />
public void AddStore(IDataStore dataStore) {
dataStores.AddListEntry(dataStore.Priority, dataStore);
}
/// <inheritdoc />
public void AddPredicate(IOpaquePredicateDescriptor predicate) {
predicates.Add(predicate);
}
/// <inheritdoc />
public IDataStore GetStore(MethodDef method) {
for (int i = dataStores.Count - 1; i >= 0; i--) {
var list = dataStores[i];
for (int j = list.Count - 1; j >= 0; i--) {
if (list[j].IsUsable(method))
return list[j];
}
}
return null;
}
/// <inheritdoc />
public IOpaquePredicateDescriptor GetPredicate(MethodDef method, OpaquePredicateType? type, params int[] argCount) {
var randomPredicates = predicates.ToArray();
random.Shuffle(randomPredicates);
foreach (var predicate in randomPredicates) {
if (predicate.IsUsable(method) &&
(type == null || predicate.Type == type.Value) &&
(argCount == null || Array.IndexOf(argCount, predicate.ArgumentCount) != -1))
return predicate;
}
return null;
}
}
/// <summary>
/// Provides storage for API interfaces
/// </summary>
public interface IAPIStore {
/// <summary>
/// Adds the specified data store into this store.
/// </summary>
/// <param name="dataStore">The data store.</param>
void AddStore(IDataStore dataStore);
/// <summary>
/// Finds a suitable data store for the specified method, with the
/// specified number of keys.
/// </summary>
/// <param name="method">The method.</param>
/// <returns>The suitable data store if found, or <c>null</c> if not found.</returns>
/// <remarks>
/// It should never returns null --- ConfuserEx has internal data store.
/// </remarks>
IDataStore GetStore(MethodDef method);
/// <summary>
/// Adds the specified opaque predicate into this store.
/// </summary>
/// <param name="predicate">The opaque predicate.</param>
void AddPredicate(IOpaquePredicateDescriptor predicate);
/// <summary>
/// Finds a suitable opaque predicate for the specified method, with the
/// specified properties.
/// </summary>
/// <param name="method">The method.</param>
/// <param name="type">The required type of predicate, or <c>null</c> if it does not matter.</param>
/// <param name="argCount">The required numbers of arguments, or <c>null</c> if it does not matter.</param>
/// <returns>The suitable opaque predicate if found, or <c>null</c> if not found.</returns>
IOpaquePredicateDescriptor GetPredicate(MethodDef method, OpaquePredicateType? type, params int[] argCount);
}
}

Просмотреть файл

@ -0,0 +1,53 @@
using System;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Confuser.Core.API {
/// <summary>
/// A data store.
/// </summary>
public interface IDataStore {
/// <summary>
/// Gets the priority of this data store; higher priority means it
/// would be tried earlier.
/// </summary>
/// <value>The priority of this data store.</value>
int Priority { get; }
/// <summary>
/// Gets the number of keys this predicate has.
/// </summary>
/// <remarks>
/// Keys are used by the data store to encrypt data/whatever purpose.
/// </remarks>
/// <value>The number of keys this data store has.</value>
int KeyCount { get; }
/// <summary>
/// Determines whether this data store can be used in the specified method.
/// </summary>
/// <param name="method">The method.</param>
/// <value><c>true</c> if this data store can be used in the specified method; otherwise, <c>false</c>.</value>
bool IsUsable(MethodDef method);
/// <summary>
/// Creates an accessor of this data store for the specified method.
/// </summary>
/// <param name="method">The method.</param>
/// <param name="keys">The keys.</param>
/// <param name="data">The data to store.</param>
/// <returns>A newly accessor of this data store.</returns>
IDataStoreAccessor CreateAccessor(MethodDef method, uint[] keys, byte[] data);
}
/// <summary>
/// An accessor of data store.
/// </summary>
public interface IDataStoreAccessor {
/// <summary>
/// Emits the runtime instruction sequence for this accessor.
/// </summary>
/// <returns>An instruction sequence that returns the stored data.</returns>
Instruction[] Emit();
}
}

Просмотреть файл

@ -0,0 +1,79 @@
using System;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Confuser.Core.API {
/// <summary>
/// The descriptor of a type of opaque predicate.
/// </summary>
public interface IOpaquePredicateDescriptor {
/// <summary>
/// Gets the type of the opaque predicate.
/// </summary>
/// <value>The type of the opaque predicate.</value>
OpaquePredicateType Type { get; }
/// <summary>
/// Gets the number of arguments this predicate has.
/// </summary>
/// <remarks>
/// When <see cref="IOpaquePredicateDescriptor.Type" /> is <see cref="OpaquePredicateType.Invariant" />,
/// there can be 0 or more arguments.
/// When <see cref="IOpaquePredicateDescriptor.Type" /> is <see cref="OpaquePredicateType.Function" />,
/// there must be more than 0 arguments.
/// </remarks>
/// <value>The number of arguments this predicate has.</value>
int ArgumentCount { get; }
/// <summary>
/// Determines whether this predicate can be used with the specified method.
/// </summary>
/// <param name="method">The method.</param>
/// <value><c>true</c> if this predicate can be used with the specified method; otherwise, <c>false</c>.</value>
bool IsUsable(MethodDef method);
/// <summary>
/// Creates a new opaque predicate for the specified method.
/// </summary>
/// <param name="method">The method.</param>
/// <returns>A newly create opaque predicate.</returns>
IOpaquePredicate CreatePredicate(MethodDef method);
}
/// <summary>
/// An instance of opaque predicate.
/// </summary>
public interface IOpaquePredicate {
/// <summary>
/// Emits the runtime instruction sequence for this predicate.
/// </summary>
/// <param name="loadArg">
/// A function that returns an instruction sequence that returns the input value,
/// or <c>null</c> if <see cref="IOpaquePredicateDescriptor.ArgumentCount" /> is 0.
/// </param>
/// <returns>An instruction sequence that returns the value of this predicate.</returns>
Instruction[] Emit(Func<Instruction[]> loadArg);
/// <summary>
/// Computes the value of this predicate with the specified argument.
/// </summary>
/// <param name="arg">The argument to this predicate.</param>
/// <returns>The return value of this predicate.</returns>
uint GetValue(uint[] arg);
}
/// <summary>
/// The type of opaque predicate.
/// </summary>
public enum OpaquePredicateType {
/// <summary>
/// A function, in a mathematics sense, with one input and one output.
/// </summary>
Function,
/// <summary>
/// A constant function, always returning the same value.
/// </summary>
Invariant
}
}

Просмотреть файл

@ -52,6 +52,9 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Annotations.cs" />
<Compile Include="API\APIStore.cs" />
<Compile Include="API\IDataStore.cs" />
<Compile Include="API\IOpaquePredicate.cs" />
<Compile Include="Helpers\ControlFlowGraph.cs" />
<Compile Include="Helpers\KeySequence.cs" />
<Compile Include="LZMA\Common\CRC.cs" />

Просмотреть файл

@ -280,11 +280,11 @@ namespace Confuser.Core {
modType = new TypeDefUser("", "<Module>", null);
modType.Attributes = TypeAttributes.AnsiClass;
module.Types.Add(modType);
marker.Mark(modType);
marker.Mark(modType, null);
}
MethodDef cctor = modType.FindOrCreateStaticConstructor();
if (!marker.IsMarked(cctor))
marker.Mark(cctor);
marker.Mark(cctor, null);
}
context.Logger.Debug("Watermarking...");
@ -292,7 +292,7 @@ namespace Confuser.Core {
TypeRef attrRef = module.CorLibTypes.GetTypeRef("System", "Attribute");
var attrType = new TypeDefUser("", "ConfusedByAttribute", attrRef);
module.Types.Add(attrType);
marker.Mark(attrType);
marker.Mark(attrType, null);
var ctor = new MethodDefUser(
".ctor",
@ -305,7 +305,7 @@ namespace Confuser.Core {
ctor.Body.Instructions.Add(OpCodes.Call.ToInstruction(new MemberRefUser(module, ".ctor", MethodSig.CreateInstance(module.CorLibTypes.Void), attrRef)));
ctor.Body.Instructions.Add(OpCodes.Ret.ToInstruction());
attrType.Methods.Add(ctor);
marker.Mark(ctor);
marker.Mark(ctor, null);
var attr = new CustomAttribute(ctor);
attr.ConstructorArguments.Add(new CAArgument(module.CorLibTypes.String, Version));

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using Confuser.Core.API;
using Confuser.Core.Services;
namespace Confuser.Core {
@ -31,6 +32,11 @@ namespace Confuser.Core {
/// </summary>
public const string _CompressionServiceId = "Confuser.Compression";
/// <summary>
/// The service ID of API Store
/// </summary>
public const string _APIStoreId = "Confuser.APIStore";
readonly Marker marker;
readonly ConfuserParameters parameters;
@ -71,6 +77,7 @@ namespace Confuser.Core {
context.Registry.RegisterService(_TraceServiceId, typeof(ITraceService), new TraceService(context));
context.Registry.RegisterService(_RuntimeServiceId, typeof(IRuntimeService), new RuntimeService());
context.Registry.RegisterService(_CompressionServiceId, typeof(ICompressionService), new CompressionService(context));
context.Registry.RegisterService(_APIStoreId, typeof(IAPIStore), new APIStore(context));
}
/// <inheritdoc />

Просмотреть файл

@ -1,10 +1,12 @@
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<IDnlibDef, ConfuserComponent> helperParents;
/// <summary>
/// Initializes a new instance of the <see cref="MarkerService" /> class.
@ -14,10 +16,11 @@ namespace Confuser.Core.Services {
public MarkerService(ConfuserContext context, Marker marker) {
this.context = context;
this.marker = marker;
helperParents = new Dictionary<IDnlibDef, ConfuserComponent>();
}
/// <inheritdoc />
public void Mark(IDnlibDef member) {
public void Mark(IDnlibDef member, ConfuserComponent parentComp) {
if (member == null)
throw new ArgumentNullException("member");
if (member is ModuleDef)
@ -26,12 +29,22 @@ namespace Confuser.Core.Services {
return;
marker.MarkMember(member, context);
if (parentComp != null)
helperParents[member] = parentComp;
}
/// <inheritdoc />
public bool IsMarked(IDnlibDef def) {
return ProtectionParameters.GetParameters(context, def) != null;
}
/// <inheritdoc />
public ConfuserComponent GetHelperParent(IDnlibDef def) {
ConfuserComponent parent;
if (!helperParents.TryGetValue(def, out parent))
return null;
return parent;
}
}
/// <summary>
@ -42,9 +55,10 @@ namespace Confuser.Core.Services {
/// Marks the helper member.
/// </summary>
/// <param name="member">The helper member.</param>
/// <param name="parentComp">The parent component.</param>
/// <exception cref="System.ArgumentException"><paramref name="member" /> is a <see cref="ModuleDef" />.</exception>
/// <exception cref="System.ArgumentNullException"><paramref name="member" /> is <c>null</c>.</exception>
void Mark(IDnlibDef member);
void Mark(IDnlibDef member, ConfuserComponent parentComp);
/// <summary>
/// Determines whether the specified definition is marked.
@ -52,5 +66,12 @@ namespace Confuser.Core.Services {
/// <param name="def">The definition.</param>
/// <returns><c>true</c> if the specified definition is marked; otherwise, <c>false</c>.</returns>
bool IsMarked(IDnlibDef def);
/// <summary>
/// Gets the parent component of the specified helper.
/// </summary>
/// <param name="def">The helper definition.</param>
/// <returns>The parent component of the helper, or <c>null</c> if the specified definition is not a helper.</returns>
ConfuserComponent GetHelperParent(IDnlibDef def);
}
}

Просмотреть файл

@ -58,7 +58,7 @@ namespace Confuser.Core {
/// <param name="key">The key of the element to add.</param>
/// <param name="value">The value of the element to add.</param>
/// <exception cref="System.ArgumentNullException">key is <c>null</c>.</exception>
public static void AddListEntry<TKey, TValue>(this Dictionary<TKey, List<TValue>> self, TKey key, TValue value) {
public static void AddListEntry<TKey, TValue>(this IDictionary<TKey, List<TValue>> self, TKey key, TValue value) {
if (key == null)
throw new ArgumentNullException("key");
List<TValue> list;

Просмотреть файл

@ -78,7 +78,7 @@ namespace Confuser.Protections {
attr = rt.GetRuntimeType(attrName);
module.Types.Add(attr = InjectHelper.Inject(attr, module));
foreach (IDnlibDef member in attr.FindDefinitions()) {
marker.Mark(member);
marker.Mark(member, (Protection)Parent);
name.Analyze(member);
}
name.SetCanRename(attr, false);
@ -94,7 +94,7 @@ namespace Confuser.Protections {
cctor.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, init));
foreach (IDnlibDef member in members) {
marker.Mark(member);
marker.Mark(member, (Protection)Parent);
name.Analyze(member);
bool ren = true;

Просмотреть файл

@ -68,7 +68,7 @@ namespace Confuser.Protections {
cctor.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, init));
foreach (IDnlibDef member in members)
name.MarkHelper(member, marker);
name.MarkHelper(member, marker, (Protection)Parent);
}
}
}

Просмотреть файл

@ -113,7 +113,7 @@ namespace Confuser.Protections.AntiTamper {
cctorRepl.Body = new CilBody();
cctorRepl.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
context.CurrentModule.GlobalType.Methods.Add(cctorRepl);
name.MarkHelper(cctorRepl, marker);
name.MarkHelper(cctorRepl, marker, parent);
MutationHelper.InjectKeys(defs.OfType<MethodDef>().Single(method => method.Name == "HookHandler"),
new[] { 0 }, new[] { (int)key });
@ -131,7 +131,7 @@ namespace Confuser.Protections.AntiTamper {
foreach (FieldDef f in fields)
dataType.Fields.Add(f);
}
name.MarkHelper(def, marker);
name.MarkHelper(def, marker, parent);
if (def is MethodDef)
parent.ExcludeMethod(context, (MethodDef)def);
}

Просмотреть файл

@ -83,7 +83,7 @@ namespace Confuser.Protections.AntiTamper {
var name = context.Registry.GetService<INameService>();
var marker = context.Registry.GetService<IMarkerService>();
foreach (IDnlibDef def in members) {
name.MarkHelper(def, marker);
name.MarkHelper(def, marker, parent);
if (def is MethodDef)
parent.ExcludeMethod(context, (MethodDef)def);
}

Просмотреть файл

@ -10,6 +10,7 @@ using dnlib.DotNet.Emit;
namespace Confuser.Protections.Constants {
internal class CEContext {
public ConfuserContext Context;
public ConstantProtection Protection;
public ModuleDef Module;
public FieldDef BufferField;

Просмотреть файл

@ -31,6 +31,7 @@ namespace Confuser.Protections.Constants {
var marker = context.Registry.GetService<IMarkerService>();
var rt = context.Registry.GetService<IRuntimeService>();
var moduleCtx = new CEContext {
Protection = (ConstantProtection)Parent,
Random = context.Registry.GetService<IRandomService>().GetRandomGenerator(Parent.Id),
Context = context,
Module = context.CurrentModule,
@ -61,7 +62,7 @@ namespace Confuser.Protections.Constants {
// Inject helpers
MethodDef decomp = compression.GetRuntimeDecompressor(context.CurrentModule, member => {
name.MarkHelper(member, marker);
name.MarkHelper(member, marker, (Protection)Parent);
if (member is MethodDef)
ProtectionParameters.GetParameters(context, member).Remove(Parent);
});
@ -88,7 +89,7 @@ namespace Confuser.Protections.Constants {
moduleCtx.BufferField = (FieldDef)member;
else if (member.Name == "Initialize")
moduleCtx.InitMethod = (MethodDef)member;
moduleCtx.Name.MarkHelper(member, moduleCtx.Marker);
moduleCtx.Name.MarkHelper(member, moduleCtx.Marker, (Protection)Parent);
}
ProtectionParameters.GetParameters(context, moduleCtx.InitMethod).Remove(Parent);
@ -98,14 +99,14 @@ namespace Confuser.Protections.Constants {
dataType.IsSealed = true;
moduleCtx.DataType = dataType;
context.CurrentModule.GlobalType.NestedTypes.Add(dataType);
moduleCtx.Name.MarkHelper(dataType, moduleCtx.Marker);
moduleCtx.Name.MarkHelper(dataType, moduleCtx.Marker, (Protection)Parent);
moduleCtx.DataField = new FieldDefUser(moduleCtx.Name.RandomName(), new FieldSig(dataType.ToTypeSig())) {
IsStatic = true,
Access = FieldAttributes.CompilerControlled
};
context.CurrentModule.GlobalType.Fields.Add(moduleCtx.DataField);
moduleCtx.Name.MarkHelper(moduleCtx.DataField, moduleCtx.Marker);
moduleCtx.Name.MarkHelper(moduleCtx.DataField, moduleCtx.Marker, (Protection)Parent);
MethodDef decoder = rt.GetRuntimeType("Confuser.Runtime.Constant").FindMethod("Get");
moduleCtx.Decoders = new List<Tuple<MethodDef, DecoderDesc>>();
@ -127,7 +128,7 @@ namespace Confuser.Protections.Constants {
}
}
context.CurrentModule.GlobalType.Methods.Add(decoderInst);
moduleCtx.Name.MarkHelper(decoderInst, moduleCtx.Marker);
moduleCtx.Name.MarkHelper(decoderInst, moduleCtx.Marker, (Protection)Parent);
ProtectionParameters.GetParameters(context, decoderInst).Remove(Parent);
var decoderDesc = new DecoderDesc();

Просмотреть файл

@ -98,7 +98,7 @@ namespace Confuser.Protections.Constants {
//native.HasSecurity = true;
ctx.Module.GlobalType.Methods.Add(native);
ctx.Name.MarkHelper(native, ctx.Marker);
ctx.Name.MarkHelper(native, ctx.Marker, ctx.Protection);
x86Register? reg;
var codeGen = new x86CodeGen();

Просмотреть файл

@ -20,6 +20,7 @@ namespace Confuser.Protections.ControlFlow {
internal class CFContext {
public ConfuserContext Context;
public ControlFlowProtection Protection;
public int Depth;
public IDynCipherService DynCipher;

Просмотреть файл

@ -25,7 +25,7 @@ namespace Confuser.Protections.ControlFlow {
get { return "Control flow mangling"; }
}
static CFContext ParseParameters(MethodDef method, ConfuserContext context, ProtectionParameters parameters, RandomGenerator random, bool disableOpti) {
CFContext ParseParameters(MethodDef method, ConfuserContext context, ProtectionParameters parameters, RandomGenerator random, bool disableOpti) {
var ret = new CFContext();
ret.Type = parameters.GetParameter(context, method, "type", CFType.Switch);
ret.Predicate = parameters.GetParameter(context, method, "predicate", PredicateType.Normal);
@ -36,6 +36,7 @@ namespace Confuser.Protections.ControlFlow {
ret.JunkCode = parameters.GetParameter(context, method, "junk", false) && !disableOpti;
ret.Protection = (ControlFlowProtection)Parent;
ret.Random = random;
ret.Method = method;
ret.Context = context;

Просмотреть файл

@ -67,7 +67,7 @@ namespace Confuser.Protections.ControlFlow {
//native.HasSecurity = true;
ctx.Method.Module.GlobalType.Methods.Add(native);
ctx.Context.Registry.GetService<IMarkerService>().Mark(native);
ctx.Context.Registry.GetService<IMarkerService>().Mark(native, ctx.Protection);
ctx.Context.Registry.GetService<INameService>().SetCanRename(native, false);
x86Register? reg;

Просмотреть файл

@ -37,7 +37,7 @@ namespace Confuser.Protections.ReferenceProxy {
sig.Params.RemoveAt(0);
}
ctx.Marker.Mark(proxy);
ctx.Marker.Mark(proxy, ctx.Protection);
ctx.Name.Analyze(proxy);
ctx.Name.SetCanRename(proxy, false);

Просмотреть файл

@ -21,6 +21,7 @@ namespace Confuser.Protections.ReferenceProxy {
}
internal class RPContext {
public ReferenceProxyProtection Protection;
public CilBody Body;
public HashSet<Instruction> BranchTargets;
public ConfuserContext Context;

Просмотреть файл

@ -81,7 +81,7 @@ namespace Confuser.Protections.ReferenceProxy {
ctx.Module.Types.Add(ret);
foreach (IDnlibDef def in ret.FindDefinitions()) {
ctx.Marker.Mark(def);
ctx.Marker.Mark(def, ctx.Protection);
ctx.Name.SetCanRename(def, false);
}

Просмотреть файл

@ -22,7 +22,7 @@ namespace Confuser.Protections.ReferenceProxy {
get { return "Encoding reference proxies"; }
}
static RPContext ParseParameters(MethodDef method, ConfuserContext context, ProtectionParameters parameters, RPStore store) {
RPContext ParseParameters(MethodDef method, ConfuserContext context, ProtectionParameters parameters, RPStore store) {
var ret = new RPContext();
ret.Mode = parameters.GetParameter(context, method, "mode", Mode.Mild);
ret.Encoding = parameters.GetParameter(context, method, "encoding", EncodingType.Normal);
@ -41,6 +41,7 @@ namespace Confuser.Protections.ReferenceProxy {
.SelectMany(instr => (Instruction[])instr.Operand))
.Where(target => target != null));
ret.Protection = (ReferenceProxyProtection)Parent;
ret.Random = store.random;
ret.Context = context;
ret.Marker = context.Registry.GetService<IMarkerService>();

Просмотреть файл

@ -177,7 +177,7 @@ namespace Confuser.Protections.ReferenceProxy {
delegateType.Methods.Add(method);
ctx.Context.Registry.GetService<IMarkerService>().Mark(method);
ctx.Context.Registry.GetService<IMarkerService>().Mark(method, ctx.Protection);
ctx.Name.SetCanRename(method, false);
return method;
@ -196,7 +196,7 @@ namespace Confuser.Protections.ReferenceProxy {
field.CustomAttributes.Add(new CustomAttribute(GetKeyAttr(ctx).FindInstanceConstructors().First()));
delegateType.Fields.Add(field);
ctx.Marker.Mark(field);
ctx.Marker.Mark(field, ctx.Protection);
ctx.Name.SetCanRename(field, false);
return field;
@ -238,11 +238,11 @@ namespace Confuser.Protections.ReferenceProxy {
foreach (IDnlibDef def in injectedAttr.FindDefinitions()) {
if (def.Name == "GetHashCode") {
ctx.Name.MarkHelper(def, ctx.Marker);
ctx.Name.MarkHelper(def, ctx.Marker, ctx.Protection);
((MethodDef)def).Access = MethodAttributes.Public;
}
else
ctx.Name.MarkHelper(def, ctx.Marker);
ctx.Name.MarkHelper(def, ctx.Marker, ctx.Protection);
}
}
return keyAttrs[index].Item1;
@ -262,7 +262,7 @@ namespace Confuser.Protections.ReferenceProxy {
injectedMethod.Access = MethodAttributes.PrivateScope;
injectedMethod.Name = ctx.Name.RandomName();
ctx.Name.SetCanRename(injectedMethod, false);
ctx.Marker.Mark(injectedMethod);
ctx.Marker.Mark(injectedMethod, ctx.Protection);
var desc = new InitMethodDesc { Method = injectedMethod };
@ -318,7 +318,7 @@ namespace Confuser.Protections.ReferenceProxy {
foreach (TypeDef delegateType in ctx.Delegates.Values) {
MethodDef cctor = delegateType.FindOrCreateStaticConstructor();
ctx.Marker.Mark(cctor);
ctx.Marker.Mark(cctor, ctx.Protection);
ctx.Name.SetCanRename(cctor, false);
}

Просмотреть файл

@ -40,7 +40,7 @@ namespace Confuser.Protections.ReferenceProxy {
native.ImplAttributes = MethodImplAttributes.Native | MethodImplAttributes.Unmanaged | MethodImplAttributes.PreserveSig;
ctx.Module.GlobalType.Methods.Add(native);
ctx.Context.Registry.GetService<IMarkerService>().Mark(native);
ctx.Context.Registry.GetService<IMarkerService>().Mark(native, ctx.Protection);
ctx.Context.Registry.GetService<INameService>().SetCanRename(native, false);
x86Register? reg;

Просмотреть файл

@ -60,7 +60,7 @@ namespace Confuser.Protections.Resources {
// Inject helpers
MethodDef decomp = compression.GetRuntimeDecompressor(context.CurrentModule, member => {
name.MarkHelper(member, marker);
name.MarkHelper(member, marker, (Protection)Parent);
if (member is MethodDef)
ProtectionParameters.GetParameters(context, member).Remove(Parent);
});
@ -82,7 +82,7 @@ namespace Confuser.Protections.Resources {
foreach (IDnlibDef member in members) {
if (member.Name == "Initialize")
moduleCtx.InitMethod = (MethodDef)member;
moduleCtx.Name.MarkHelper(member, moduleCtx.Marker);
moduleCtx.Name.MarkHelper(member, moduleCtx.Marker, (Protection)Parent);
}
var dataType = new TypeDefUser("", moduleCtx.Name.RandomName(), context.CurrentModule.CorLibTypes.GetTypeRef("System", "ValueType"));
@ -92,7 +92,7 @@ namespace Confuser.Protections.Resources {
dataType.ClassLayout = new ClassLayoutUser(1, 0);
moduleCtx.DataType = dataType;
context.CurrentModule.GlobalType.NestedTypes.Add(dataType);
moduleCtx.Name.MarkHelper(dataType, moduleCtx.Marker);
moduleCtx.Name.MarkHelper(dataType, moduleCtx.Marker, (Protection)Parent);
moduleCtx.DataField = new FieldDefUser(moduleCtx.Name.RandomName(), new FieldSig(dataType.ToTypeSig())) {
IsStatic = true,
@ -101,7 +101,7 @@ namespace Confuser.Protections.Resources {
Access = FieldAttributes.CompilerControlled
};
context.CurrentModule.GlobalType.Fields.Add(moduleCtx.DataField);
moduleCtx.Name.MarkHelper(moduleCtx.DataField, moduleCtx.Marker);
moduleCtx.Name.MarkHelper(moduleCtx.DataField, moduleCtx.Marker, (Protection)Parent);
}
void MutateInitializer(REContext moduleCtx, MethodDef decomp) {

Просмотреть файл

@ -31,7 +31,7 @@ namespace Confuser.Renamer {
void SetOriginalName(object obj, string name);
void SetOriginalNamespace(object obj, string ns);
void MarkHelper(IDnlibDef def, IMarkerService marker);
void MarkHelper(IDnlibDef def, IMarkerService marker, ConfuserComponent parentComp);
}
internal class NameService : INameService {
@ -169,7 +169,7 @@ namespace Confuser.Renamer {
return Renamers.OfType<T>().Single();
}
public void MarkHelper(IDnlibDef def, IMarkerService marker) {
public void MarkHelper(IDnlibDef def, IMarkerService marker, ConfuserComponent parentComp) {
if (marker.IsMarked(def))
return;
if (def is MethodDef) {
@ -194,7 +194,7 @@ namespace Confuser.Renamer {
}
SetCanRename(def, false);
Analyze(def);
marker.Mark(def);
marker.Mark(def, parentComp);
}
#region Charsets

Просмотреть файл

@ -40,8 +40,8 @@ namespace Confuser.Renamer {
trap.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
newType.Methods.Add(trap);
marker.Mark(newType);
marker.Mark(trap);
marker.Mark(newType, null);
marker.Mark(trap, null);
nameService.SetCanRename(trap, false);
foreach (var method in module.GetTypes().SelectMany(type => type.Methods)) {