本文整理汇总了C#中ProtectionParameters类的典型用法代码示例。如果您正苦于以下问题:C# ProtectionParameters类的具体用法?C# ProtectionParameters怎么用?C# ProtectionParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProtectionParameters类属于命名空间,在下文中一共展示了ProtectionParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) {
var field = context.CurrentModule.Types[0].FindField("DataField");
Debug.Assert(field != null);
context.Registry.GetService<INameService>().SetCanRename(field, true);
context.CurrentModuleWriterListener.OnWriterEvent += (sender, e) => {
if (e.WriterEvent == ModuleWriterEvent.MDBeginCreateTables) {
// Add key signature
var writer = (ModuleWriterBase)sender;
var prot = (StubProtection)Parent;
uint blob = writer.MetaData.BlobHeap.Add(prot.ctx.KeySig);
uint rid = writer.MetaData.TablesHeap.StandAloneSigTable.Add(new RawStandAloneSigRow(blob));
Debug.Assert((0x11000000 | rid) == prot.ctx.KeyToken);
if (prot.ctx.CompatMode)
return;
// Add File reference
byte[] hash = SHA1.Create().ComputeHash(prot.ctx.OriginModule);
uint hashBlob = writer.MetaData.BlobHeap.Add(hash);
MDTable<RawFileRow> fileTbl = writer.MetaData.TablesHeap.FileTable;
uint fileRid = fileTbl.Add(new RawFileRow(
(uint)FileAttributes.ContainsMetaData,
writer.MetaData.StringsHeap.Add("koi"),
hashBlob));
}
};
}
示例2: Pack
protected override void Pack(ConfuserContext context, ProtectionParameters parameters)
{
var ctx = context.Annotations.Get<CompressorContext>(context, ContextKey);
if (ctx == null) {
context.Logger.Error("No executable module!");
throw new ConfuserException(null);
}
ModuleDefMD originModule = context.Modules[ctx.ModuleIndex];
var stubModule = new ModuleDefUser(ctx.ModuleName, originModule.Mvid, originModule.CorLibTypes.AssemblyRef);
ctx.Assembly.Modules.Insert(0, stubModule);
stubModule.Characteristics = originModule.Characteristics;
stubModule.Cor20HeaderFlags = originModule.Cor20HeaderFlags;
stubModule.Cor20HeaderRuntimeVersion = originModule.Cor20HeaderRuntimeVersion;
stubModule.DllCharacteristics = originModule.DllCharacteristics;
stubModule.EncBaseId = originModule.EncBaseId;
stubModule.EncId = originModule.EncId;
stubModule.Generation = originModule.Generation;
stubModule.Kind = ctx.Kind;
stubModule.Machine = originModule.Machine;
stubModule.RuntimeVersion = originModule.RuntimeVersion;
stubModule.TablesHeaderVersion = originModule.TablesHeaderVersion;
stubModule.Win32Resources = originModule.Win32Resources;
InjectStub(context, ctx, parameters, stubModule);
var snKey = context.Annotations.Get<StrongNameKey>(originModule, Marker.SNKey);
using (var ms = new MemoryStream()) {
stubModule.Write(ms, new ModuleWriterOptions(stubModule, new KeyInjector(ctx)) {
StrongNameKey = snKey
});
context.CheckCancellation();
base.ProtectStub(context, context.OutputPaths[ctx.ModuleIndex], ms.ToArray(), snKey, new StubProtection(ctx));
}
}
示例3: Analyze
internal void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, IDnlibDef def, bool runAnalyzer)
{
if (def is TypeDef)
Analyze(service, context, parameters, (TypeDef)def);
else if (def is MethodDef)
Analyze(service, context, parameters, (MethodDef)def);
else if (def is FieldDef)
Analyze(service, context, parameters, (FieldDef)def);
else if (def is PropertyDef)
Analyze(service, context, parameters, (PropertyDef)def);
else if (def is EventDef)
Analyze(service, context, parameters, (EventDef)def);
else if (def is ModuleDef) {
var pass = parameters.GetParameter<string>(context, def, "password", null);
if (pass != null)
service.reversibleRenamer = new ReversibleRenamer(pass);
service.SetCanRename(def, false);
}
if (!runAnalyzer || parameters.GetParameter(context, def, "forceRen", false))
return;
foreach (IRenamer renamer in service.Renamers)
renamer.Analyze(context, service, parameters, def);
}
示例4: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters)
{
if (context.Packer == null)
return;
bool isExe = context.CurrentModule.Kind == ModuleKind.Windows ||
context.CurrentModule.Kind == ModuleKind.Console;
if (context.Annotations.Get<CompressorContext>(context, Compressor.ContextKey) != null) {
if (isExe) {
context.Logger.Error("Too many executable modules!");
throw new ConfuserException(null);
}
return;
}
if (isExe) {
var ctx = new CompressorContext {
ModuleIndex = context.CurrentModuleIndex,
Assembly = context.CurrentModule.Assembly
};
context.Annotations.Set(context, Compressor.ContextKey, ctx);
ctx.ModuleName = context.CurrentModule.Name;
context.CurrentModule.Name = "koi";
ctx.EntryPoint = context.CurrentModule.EntryPoint;
context.CurrentModule.EntryPoint = null;
ctx.Kind = context.CurrentModule.Kind;
context.CurrentModule.Kind = ModuleKind.NetModule;
context.CurrentModuleWriterListener.OnWriterEvent += new ResourceRecorder(ctx, context.CurrentModule).OnWriterEvent;
}
}
示例5: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters)
{
var service = (NameService)context.Registry.GetService<INameService>();
context.Logger.Debug("Building VTables & identifier list...");
foreach (IDnlibDef def in parameters.Targets.WithProgress(context.Logger)) {
ParseParameters(def, context, service, parameters);
if (def is ModuleDef) {
var module = (ModuleDef)def;
foreach (Resource res in module.Resources)
service.SetOriginalName(res, res.Name);
}
else
service.SetOriginalName(def, def.Name);
if (def is TypeDef) {
service.GetVTables().GetVTable((TypeDef)def);
service.SetOriginalNamespace(def, ((TypeDef)def).Namespace);
}
context.CheckCancellation();
}
context.Logger.Debug("Analyzing...");
RegisterRenamers(context, service);
IList<IRenamer> renamers = service.Renamers;
foreach (IDnlibDef def in parameters.Targets.WithProgress(context.Logger)) {
Analyze(service, context, parameters, def, true);
context.CheckCancellation();
}
}
示例6: Analyze
// i.e. Inter-Assembly References, e.g. InternalVisibleToAttributes
public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
{
var module = def as ModuleDefMD;
if (module == null) return;
// MemberRef/MethodSpec
var methods = module.GetTypes().SelectMany(type => type.Methods);
foreach(var methodDef in methods) {
foreach (var ov in methodDef.Overrides) {
ProcessMemberRef(context, service, module, ov.MethodBody);
ProcessMemberRef(context, service, module, ov.MethodDeclaration);
}
if (!methodDef.HasBody)
continue;
foreach (var instr in methodDef.Body.Instructions) {
if (instr.Operand is MemberRef || instr.Operand is MethodSpec)
ProcessMemberRef(context, service, module, (IMemberRef)instr.Operand);
}
}
// TypeRef
var table = module.TablesStream.Get(Table.TypeRef);
uint len = table.Rows;
for (uint i = 1; i <= len; i++) {
TypeRef typeRef = module.ResolveTypeRef(i);
TypeDef typeDef = typeRef.ResolveTypeDefThrow();
if (typeDef.Module != module && context.Modules.Contains((ModuleDefMD)typeDef.Module)) {
service.AddReference(typeDef, new TypeRefReference(typeRef, typeDef));
}
}
}
示例7: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters)
{
if (context.Packer == null)
return;
if (context.Annotations.Get<CompressorContext>(context, Compressor.ContextKey) != null)
return;
var mainModule = parameters.GetParameter<string>(context, null, "main");
if (context.CurrentModule.Name == mainModule) {
var ctx = new CompressorContext {
ModuleIndex = context.CurrentModuleIndex,
Assembly = context.CurrentModule.Assembly
};
context.Annotations.Set(context, Compressor.ContextKey, ctx);
ctx.ModuleName = context.CurrentModule.Name;
context.CurrentModule.Name = "koi";
ctx.EntryPoint = context.CurrentModule.EntryPoint;
context.CurrentModule.EntryPoint = null;
ctx.Kind = context.CurrentModule.Kind;
context.CurrentModule.Kind = ModuleKind.NetModule;
context.CurrentModule.Assembly.Modules.Remove(context.CurrentModule);
context.CurrentModuleWriterListener.OnWriterEvent += new ResourceRecorder(ctx, context.CurrentModule).OnWriterEvent;
}
}
示例8: ReplaceReference
public static void ReplaceReference(CEContext ctx, ProtectionParameters parameters) {
foreach (var entry in ctx.ReferenceRepl) {
if (parameters.GetParameter<bool>(ctx.Context, entry.Key, "cfg"))
ReplaceCFG(entry.Key, entry.Value, ctx);
else
ReplaceNormal(entry.Key, entry.Value);
}
}
示例9: Analyze
public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def) {
var method = def as MethodDef;
if (method == null || !method.HasBody)
return;
// When a ldtoken instruction reference a definition,
// most likely it would be used in reflection and thus probably should not be renamed.
// Also, when ToString is invoked on enum,
// the enum should not be renamed.
for (int i = 0; i < method.Body.Instructions.Count; i++) {
Instruction instr = method.Body.Instructions[i];
if (instr.OpCode.Code == Code.Ldtoken) {
if (instr.Operand is MemberRef) {
IMemberForwarded member = ((MemberRef)instr.Operand).ResolveThrow();
if (context.Modules.Contains((ModuleDefMD)member.Module))
service.SetCanRename(member, false);
}
else if (instr.Operand is IField) {
FieldDef field = ((IField)instr.Operand).ResolveThrow();
if (context.Modules.Contains((ModuleDefMD)field.Module))
service.SetCanRename(field, false);
}
else if (instr.Operand is IMethod) {
var im = (IMethod)instr.Operand;
if (!im.IsArrayAccessors()) {
MethodDef m = im.ResolveThrow();
if (context.Modules.Contains((ModuleDefMD)m.Module))
service.SetCanRename(method, false);
}
}
else if (instr.Operand is ITypeDefOrRef) {
if (!(instr.Operand is TypeSpec)) {
TypeDef type = ((ITypeDefOrRef)instr.Operand).ResolveTypeDefThrow();
if (context.Modules.Contains((ModuleDefMD)type.Module) &&
HandleTypeOf(context, service, method, i)) {
var t = type;
do {
DisableRename(service, t, false);
t = t.DeclaringType;
} while (t != null);
}
}
}
else
throw new UnreachableException();
}
else if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt) &&
((IMethod)instr.Operand).Name == "ToString") {
HandleEnum(context, service, method, i);
}
else if (instr.OpCode.Code == Code.Ldstr) {
TypeDef typeDef = method.Module.FindReflection((string)instr.Operand);
if (typeDef != null)
service.AddReference(typeDef, new StringTypeReference(instr, typeDef));
}
}
}
示例10: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) {
var service = (NameService)context.Registry.GetService<INameService>();
foreach (IRenamer renamer in service.Renamers) {
foreach (IDnlibDef def in parameters.Targets)
renamer.PostRename(context, service, parameters, def);
context.CheckCancellation();
}
}
示例11: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) {
foreach (ModuleDef module in parameters.Targets.OfType<ModuleDef>()) {
TypeRef attrRef = module.CorLibTypes.GetTypeRef("System.Runtime.CompilerServices", "SuppressIldasmAttribute");
var ctorRef = new MemberRefUser(module, ".ctor", MethodSig.CreateInstance(module.CorLibTypes.Void), attrRef);
var attr = new CustomAttribute(ctorRef);
module.CustomAttributes.Add(attr);
}
}
示例12: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters)
{
var service = (NameService)context.Registry.GetService<INameService>();
context.Logger.Debug("Renaming...");
foreach (IRenamer renamer in service.Renamers) {
foreach (IDnlibDef def in parameters.Targets)
renamer.PreRename(context, service, def);
context.CheckCancellation();
}
foreach (IDnlibDef def in parameters.Targets.WithProgress(context.Logger)) {
bool canRename = service.CanRename(def);
if (def is MethodDef)
if (canRename && parameters.GetParameter(context, def, "renameArgs", true)) {
foreach (ParamDef param in ((MethodDef)def).ParamDefs)
param.Name = null;
}
if (!canRename)
continue;
RenameMode mode = service.GetRenameMode(def);
IList<INameReference> references = service.GetReferences(def);
bool cancel = false;
foreach (INameReference refer in references) {
cancel |= refer.ShouldCancelRename();
if (cancel) break;
}
if (cancel)
continue;
if (def is TypeDef) {
var typeDef = (TypeDef)def;
if (parameters.GetParameter(context, def, "flatten", true)) {
typeDef.Name = service.ObfuscateName(typeDef.FullName, mode);
typeDef.Namespace = "";
}
else {
typeDef.Namespace = service.ObfuscateName(typeDef.Namespace, mode);
typeDef.Name = service.ObfuscateName(typeDef.Name, mode);
}
}
else
def.Name = service.ObfuscateName(def.Name, mode);
foreach (INameReference refer in references.ToList()) {
if (!refer.UpdateNameReference(context, service)) {
context.Logger.ErrorFormat("Failed to update name reference on '{0}'.", def);
throw new ConfuserException(null);
}
}
context.CheckCancellation();
}
}
示例13: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) {
bool disabledOpti = DisabledOptimization(context.CurrentModule);
RandomGenerator random = context.Registry.GetService<IRandomService>().GetRandomGenerator(ControlFlowProtection._FullId);
foreach (MethodDef method in parameters.Targets.OfType<MethodDef>().WithProgress(context.Logger))
if (method.HasBody && method.Body.Instructions.Count > 0) {
ProcessMethod(method.Body, ParseParameters(method, context, parameters, random, disabledOpti));
context.CheckCancellation();
}
}
示例14: Analyze
public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
{
if (def is TypeDef)
Analyze(context, service, (TypeDef)def, parameters);
else if (def is MethodDef)
Analyze(context, service, (MethodDef)def, parameters);
else if (def is PropertyDef)
Analyze(context, service, (PropertyDef)def, parameters);
else if (def is FieldDef)
Analyze(context, service, (FieldDef)def, parameters);
}
示例15: Analyze
public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
{
var module = def as ModuleDef;
if (module == null) return;
string asmName = module.Assembly.Name.String;
if (!string.IsNullOrEmpty(module.Assembly.Culture) &&
asmName.EndsWith(".resources")) {
// Satellite assembly
var satellitePattern = new Regex(string.Format("^(.*)\\.{0}\\.resources$", module.Assembly.Culture));
string nameAsmName = asmName.Substring(0, asmName.Length - ".resources".Length);
ModuleDef mainModule = context.Modules.SingleOrDefault(mod => mod.Assembly.Name == nameAsmName);
if (mainModule == null) {
context.Logger.ErrorFormat("Could not find main assembly of satellite assembly '{0}'.", module.Assembly.FullName);
throw new ConfuserException(null);
}
string format = "{0}." + module.Assembly.Culture + ".resources";
foreach (Resource res in module.Resources) {
Match match = satellitePattern.Match(res.Name);
if (!match.Success)
continue;
string typeName = match.Groups[1].Value;
TypeDef type = mainModule.FindReflectionThrow(typeName);
if (type == null) {
context.Logger.WarnFormat("Could not find resource type '{0}'.", typeName);
continue;
}
service.ReduceRenameMode(type, RenameMode.ASCII);
service.AddReference(type, new ResourceReference(res, type, format));
}
}
else {
string format = "{0}.resources";
foreach (Resource res in module.Resources) {
Match match = ResourceNamePattern.Match(res.Name);
if (!match.Success)
continue;
string typeName = match.Groups[1].Value;
if (typeName.EndsWith(".g")) // WPF resources, ignore
continue;
TypeDef type = module.FindReflection(typeName);
if (type == null) {
context.Logger.WarnFormat("Could not find resource type '{0}'.", typeName);
continue;
}
service.ReduceRenameMode(type, RenameMode.ASCII);
service.AddReference(type, new ResourceReference(res, type, format));
}
}
}