本文整理汇总了C#中ProtectionParameters.GetParameter方法的典型用法代码示例。如果您正苦于以下问题:C# ProtectionParameters.GetParameter方法的具体用法?C# ProtectionParameters.GetParameter怎么用?C# ProtectionParameters.GetParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtectionParameters
的用法示例。
在下文中一共展示了ProtectionParameters.GetParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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();
}
}
示例3: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters)
{
if (parameters.Targets.Any()) {
var compression = context.Registry.GetService<ICompressionService>();
var name = context.Registry.GetService<INameService>();
var marker = context.Registry.GetService<IMarkerService>();
var rt = context.Registry.GetService<IRuntimeService>();
var moduleCtx = new CEContext {
Random = context.Registry.GetService<IRandomService>().GetRandomGenerator(Parent.Id),
Context = context,
Module = context.CurrentModule,
Marker = marker,
DynCipher = context.Registry.GetService<IDynCipherService>(),
Name = name
};
// Extract parameters
moduleCtx.Mode = parameters.GetParameter(context, context.CurrentModule, "mode", Mode.Normal);
moduleCtx.DecoderCount = parameters.GetParameter(context, context.CurrentModule, "decoderCount", 5);
switch (moduleCtx.Mode) {
case Mode.Normal:
moduleCtx.ModeHandler = new NormalMode();
break;
case Mode.Dynamic:
moduleCtx.ModeHandler = new DynamicMode();
break;
case Mode.x86:
moduleCtx.ModeHandler = new x86Mode();
if ((context.CurrentModule.Cor20HeaderFlags & ComImageFlags.ILOnly) != 0)
context.CurrentModuleWriterOptions.Cor20HeaderOptions.Flags &= ~ComImageFlags.ILOnly;
break;
default:
throw new UnreachableException();
}
// Inject helpers
MethodDef decomp = compression.GetRuntimeDecompressor(context.CurrentModule, member => {
name.MarkHelper(member, marker);
if (member is MethodDef)
ProtectionParameters.GetParameters(context, member).Remove(Parent);
});
InjectHelpers(context, compression, rt, moduleCtx);
// Mutate codes
MutateInitializer(moduleCtx, decomp);
MethodDef cctor = context.CurrentModule.GlobalType.FindStaticConstructor();
cctor.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, moduleCtx.InitMethod));
context.Annotations.Set(context.CurrentModule, ConstantProtection.ContextKey, moduleCtx);
}
}
示例4: 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;
}
}
示例5: 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);
}
}
示例6: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) {
if (parameters.Targets.Any()) {
if (!UTF8String.IsNullOrEmpty(context.CurrentModule.Assembly.Culture)) {
context.Logger.DebugFormat("Skipping resource encryption for satellite assembly '{0}'.",
context.CurrentModule.Assembly.FullName);
return;
}
var compression = context.Registry.GetService<ICompressionService>();
var name = context.Registry.GetService<INameService>();
var marker = context.Registry.GetService<IMarkerService>();
var rt = context.Registry.GetService<IRuntimeService>();
var moduleCtx = new REContext {
Random = context.Registry.GetService<IRandomService>().GetRandomGenerator(Parent.Id),
Context = context,
Module = context.CurrentModule,
Marker = marker,
DynCipher = context.Registry.GetService<IDynCipherService>(),
Name = name
};
// Extract parameters
moduleCtx.Mode = parameters.GetParameter(context, context.CurrentModule, "mode", Mode.Normal);
switch (moduleCtx.Mode) {
case Mode.Normal:
moduleCtx.ModeHandler = new NormalMode();
break;
case Mode.Dynamic:
moduleCtx.ModeHandler = new DynamicMode();
break;
default:
throw new UnreachableException();
}
// Inject helpers
MethodDef decomp = compression.GetRuntimeDecompressor(context.CurrentModule, member => {
name.MarkHelper(member, marker, (Protection)Parent);
if (member is MethodDef)
ProtectionParameters.GetParameters(context, member).Remove(Parent);
});
InjectHelpers(context, compression, rt, moduleCtx);
// Mutate codes
MutateInitializer(moduleCtx, decomp);
MethodDef cctor = context.CurrentModule.GlobalType.FindStaticConstructor();
cctor.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, moduleCtx.InitMethod));
new MDPhase(moduleCtx).Hook();
}
}
示例7: ParseParameters
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);
int rawIntensity = parameters.GetParameter(context, method, "intensity", 60);
ret.Intensity = rawIntensity / 100.0;
ret.Depth = parameters.GetParameter(context, method, "depth", 4);
ret.JunkCode = parameters.GetParameter(context, method, "junk", false) && !disableOpti;
ret.Protection = (ControlFlowProtection)Parent;
ret.Random = random;
ret.Method = method;
ret.Context = context;
ret.DynCipher = context.Registry.GetService<IDynCipherService>();
if (ret.Predicate == PredicateType.x86) {
if ((context.CurrentModule.Cor20HeaderFlags & ComImageFlags.ILOnly) != 0)
context.CurrentModuleWriterOptions.Cor20HeaderOptions.Flags &= ~ComImageFlags.ILOnly;
}
return ret;
}
示例8: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) {
if (!parameters.Targets.Any())
return;
Mode mode = parameters.GetParameter(context, context.CurrentModule, "mode", Mode.Normal);
IModeHandler modeHandler;
switch (mode) {
case Mode.Normal:
modeHandler = new NormalMode();
break;
case Mode.JIT:
modeHandler = new JITMode();
break;
default:
throw new UnreachableException();
}
modeHandler.HandleInject((AntiTamperProtection)Parent, context, parameters);
context.Annotations.Set(context.CurrentModule, HandlerKey, modeHandler);
}
示例9: 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)
service.SetCanRename(def, false);
if (!runAnalyzer || parameters.GetParameter<bool>(context, def, "forceRen", false))
return;
foreach (IRenamer renamer in service.Renamers)
renamer.Analyze(context, service, def);
}
示例10: 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,
CompatMode = parameters.GetParameter(context, null, "compat", false)
};
context.Annotations.Set(context, Compressor.ContextKey, ctx);
ctx.ModuleName = context.CurrentModule.Name;
ctx.EntryPoint = context.CurrentModule.EntryPoint;
ctx.Kind = context.CurrentModule.Kind;
if (!ctx.CompatMode) {
context.CurrentModule.Name = "koi";
context.CurrentModule.EntryPoint = null;
context.CurrentModule.Kind = ModuleKind.NetModule;
}
context.CurrentModuleWriterListener.OnWriterEvent += new ResourceRecorder(ctx, context.CurrentModule).OnWriterEvent;
}
}
示例11: Analyze
void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, EventDef evt)
{
if (evt.DeclaringType.IsVisibleOutside() &&
!parameters.GetParameter(context, evt, "renPublic", false))
service.SetCanRename(evt, false);
else if (evt.IsRuntimeSpecialName)
service.SetCanRename(evt, false);
}
示例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, parameters, def);
context.CheckCancellation();
}
var pdbDocs = new HashSet<string>();
foreach (IDnlibDef def in parameters.Targets.WithProgress(context.Logger)) {
if (def is ModuleDef && parameters.GetParameter(context, def, "rickroll", false))
RickRoller.CommenceRickroll(context, (ModuleDef)def);
bool canRename = service.CanRename(def);
RenameMode mode = service.GetRenameMode(def);
if (def is MethodDef) {
var method = (MethodDef)def;
if ((canRename || method.IsConstructor) && parameters.GetParameter(context, def, "renameArgs", true)) {
foreach (ParamDef param in ((MethodDef)def).ParamDefs)
param.Name = null;
}
if (parameters.GetParameter(context, def, "renPdb", false) && method.HasBody) {
foreach (var instr in method.Body.Instructions) {
if (instr.SequencePoint != null && !pdbDocs.Contains(instr.SequencePoint.Document.Url)) {
instr.SequencePoint.Document.Url = service.ObfuscateName(instr.SequencePoint.Document.Url, mode);
pdbDocs.Add(instr.SequencePoint.Document.Url);
}
}
foreach (var local in method.Body.Variables) {
if (!string.IsNullOrEmpty(local.Name))
local.Name = service.ObfuscateName(local.Name, mode);
}
method.Body.Scope = null;
}
}
if (!canRename)
continue;
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);
}
foreach (var param in typeDef.GenericParameters)
param.Name = ((char)(param.Number + 1)).ToString();
}
else if (def is MethodDef) {
foreach (var param in ((MethodDef)def).GenericParameters)
param.Name = ((char)(param.Number + 1)).ToString();
def.Name = service.ObfuscateName(def.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: PreRename
public void PreRename(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
{
var module = def as ModuleDefMD;
if (module == null || !parameters.GetParameter<bool>(context, def, "renXaml", true))
return;
var wpfResInfo = context.Annotations.Get<Dictionary<string, Dictionary<string, BamlDocument>>>(module, BAMLKey);
if (wpfResInfo == null)
return;
foreach (var res in wpfResInfo.Values)
foreach (var doc in res.Values) {
List<IBAMLReference> references;
if (bamlRefs.TryGetValue(doc.DocumentName, out references)) {
var newName = doc.DocumentName.ToUpperInvariant();
if (newName.EndsWith(".BAML"))
newName = service.RandomName(RenameMode.Letters).ToLowerInvariant() + ".baml";
else if (newName.EndsWith(".XAML"))
newName = service.RandomName(RenameMode.Letters).ToLowerInvariant() + ".xaml";
bool renameOk = true;
foreach (var bamlRef in references)
if (!bamlRef.CanRename(doc.DocumentName, newName)) {
renameOk = false;
break;
}
if (renameOk) {
foreach (var bamlRef in references)
bamlRef.Rename(doc.DocumentName, newName);
doc.DocumentName = newName;
}
}
}
}
示例14: Execute
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) {
var rt = context.Registry.GetService<IRuntimeService>();
var marker = context.Registry.GetService<IMarkerService>();
var name = context.Registry.GetService<INameService>();
foreach (ModuleDef module in parameters.Targets.OfType<ModuleDef>()) {
AntiMode mode = parameters.GetParameter(context, module, "mode", AntiMode.Safe);
TypeDef rtType;
TypeDef attr = null;
const string attrName = "System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute";
switch (mode) {
case AntiMode.Safe:
rtType = rt.GetRuntimeType("Confuser.Runtime.AntiDebugSafe");
break;
case AntiMode.Win32:
rtType = rt.GetRuntimeType("Confuser.Runtime.AntiDebugWin32");
break;
case AntiMode.Antinet:
rtType = rt.GetRuntimeType("Confuser.Runtime.AntiDebugAntinet");
attr = rt.GetRuntimeType(attrName);
module.Types.Add(attr = InjectHelper.Inject(attr, module));
foreach (IDnlibDef member in attr.FindDefinitions()) {
marker.Mark(member, (Protection)Parent);
name.Analyze(member);
}
name.SetCanRename(attr, false);
break;
default:
throw new UnreachableException();
}
IEnumerable<IDnlibDef> members = InjectHelper.Inject(rtType, module.GlobalType, module);
MethodDef cctor = module.GlobalType.FindStaticConstructor();
var init = (MethodDef)members.Single(method => method.Name == "Initialize");
cctor.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, init));
foreach (IDnlibDef member in members) {
marker.Mark(member, (Protection)Parent);
name.Analyze(member);
bool ren = true;
if (member is MethodDef) {
var method = (MethodDef)member;
if (method.Access == MethodAttributes.Public)
method.Access = MethodAttributes.Assembly;
if (!method.IsConstructor)
method.IsSpecialName = false;
else
ren = false;
CustomAttribute ca = method.CustomAttributes.Find(attrName);
if (ca != null)
ca.Constructor = attr.FindMethod(".ctor");
}
else if (member is FieldDef) {
var field = (FieldDef)member;
if (field.Access == FieldAttributes.Public)
field.Access = FieldAttributes.Assembly;
if (field.IsLiteral) {
field.DeclaringType.Fields.Remove(field);
continue;
}
}
if (ren) {
member.Name = name.ObfuscateName(member.Name, RenameMode.Unicode);
name.SetCanRename(member, false);
}
}
}
}
示例15: InjectStub
void InjectStub(ConfuserContext context, CompressorContext compCtx, ProtectionParameters parameters, ModuleDef stubModule)
{
var rt = context.Registry.GetService<IRuntimeService>();
RandomGenerator random = context.Registry.GetService<IRandomService>().GetRandomGenerator(Id);
var comp = context.Registry.GetService<ICompressionService>();
IEnumerable<IDnlibDef> defs = InjectHelper.Inject(rt.GetRuntimeType("Confuser.Runtime.Compressor"), stubModule.GlobalType, stubModule);
switch (parameters.GetParameter(context, context.CurrentModule, "key", Mode.Normal)) {
case Mode.Normal:
compCtx.Deriver = new NormalDeriver();
break;
case Mode.Dynamic:
compCtx.Deriver = new DynamicDeriver();
break;
default:
throw new UnreachableException();
}
compCtx.Deriver.Init(context, random);
context.Logger.Debug("Encrypting modules...");
// Main
MethodDef entryPoint = defs.OfType<MethodDef>().Single(method => method.Name == "Main");
stubModule.EntryPoint = entryPoint;
if (compCtx.EntryPoint.HasAttribute("System.STAThreadAttribute")) {
var attrType = stubModule.CorLibTypes.GetTypeRef("System", "STAThreadAttribute");
var ctorSig = MethodSig.CreateInstance(stubModule.CorLibTypes.Void);
entryPoint.CustomAttributes.Add(new CustomAttribute(
new MemberRefUser(stubModule, ".ctor", ctorSig, attrType)));
}
else if (compCtx.EntryPoint.HasAttribute("System.MTAThreadAttribute")) {
var attrType = stubModule.CorLibTypes.GetTypeRef("System", "MTAThreadAttribute");
var ctorSig = MethodSig.CreateInstance(stubModule.CorLibTypes.Void);
entryPoint.CustomAttributes.Add(new CustomAttribute(
new MemberRefUser(stubModule, ".ctor", ctorSig, attrType)));
}
uint seed = random.NextUInt32();
compCtx.OriginModule = context.OutputModules[compCtx.ModuleIndex];
byte[] encryptedModule = compCtx.Encrypt(comp, compCtx.OriginModule, seed,
progress => context.Logger.Progress((int)(progress * 10000), 10000));
context.Logger.EndProgress();
context.CheckCancellation();
compCtx.EncryptedModule = encryptedModule;
MutationHelper.InjectKeys(entryPoint,
new[] { 0, 1 },
new[] { encryptedModule.Length >> 2, (int)seed });
InjectData(stubModule, entryPoint, encryptedModule);
// Decrypt
MethodDef decrypter = defs.OfType<MethodDef>().Single(method => method.Name == "Decrypt");
decrypter.Body.SimplifyMacros(decrypter.Parameters);
List<Instruction> instrs = decrypter.Body.Instructions.ToList();
for (int i = 0; i < instrs.Count; i++) {
Instruction instr = instrs[i];
if (instr.OpCode == OpCodes.Call) {
var method = (IMethod)instr.Operand;
if (method.DeclaringType.Name == "Mutation" &&
method.Name == "Crypt") {
Instruction ldDst = instrs[i - 2];
Instruction ldSrc = instrs[i - 1];
Debug.Assert(ldDst.OpCode == OpCodes.Ldloc && ldSrc.OpCode == OpCodes.Ldloc);
instrs.RemoveAt(i);
instrs.RemoveAt(i - 1);
instrs.RemoveAt(i - 2);
instrs.InsertRange(i - 2, compCtx.Deriver.EmitDerivation(decrypter, context, (Local)ldDst.Operand, (Local)ldSrc.Operand));
}
else if (method.DeclaringType.Name == "Lzma" &&
method.Name == "Decompress") {
MethodDef decomp = comp.GetRuntimeDecompressor(stubModule, member => { });
instr.Operand = decomp;
}
}
}
decrypter.Body.Instructions.Clear();
foreach (Instruction instr in instrs)
decrypter.Body.Instructions.Add(instr);
// Pack modules
PackModules(context, compCtx, stubModule, comp, random);
}