本文整理汇总了C#中Confuser.Core.ConfuserContext类的典型用法代码示例。如果您正苦于以下问题:C# ConfuserContext类的具体用法?C# ConfuserContext怎么用?C# ConfuserContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfuserContext类属于Confuser.Core命名空间,在下文中一共展示了ConfuserContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: MarkProject
protected override MarkerResult MarkProject(ConfuserProject proj, ConfuserContext context)
{
crossModuleAttrs = new Dictionary<string, Dictionary<Regex, List<ObfuscationAttributeInfo>>>();
this.context = context;
project = proj;
extModules = new List<byte[]>();
var modules = new List<Tuple<ProjectModule, ModuleDefMD>>();
foreach (ProjectModule module in proj) {
ModuleDefMD modDef = module.Resolve(proj.BaseDirectory, context.Resolver.DefaultModuleContext);
context.CheckCancellation();
context.Resolver.AddToCache(modDef);
modules.Add(Tuple.Create(module, modDef));
}
foreach (var module in modules) {
context.Logger.InfoFormat("Loading '{0}'...", module.Item1.Path);
MarkModule(module.Item2, module == modules[0]);
// Packer parameters are stored in modules
if (packer != null)
ProtectionParameters.GetParameters(context, module.Item2)[packer] = packerParams;
}
return new MarkerResult(modules.Select(module => module.Item2).ToList(), packer, extModules);
}
示例3: EmitDerivation
public IEnumerable<Instruction> EmitDerivation(MethodDef method, ConfuserContext ctx, Local dst, Local src)
{
for (int i = 0; i < 0x10; i++) {
yield return Instruction.Create(OpCodes.Ldloc, dst);
yield return Instruction.Create(OpCodes.Ldc_I4, i);
yield return Instruction.Create(OpCodes.Ldloc, dst);
yield return Instruction.Create(OpCodes.Ldc_I4, i);
yield return Instruction.Create(OpCodes.Ldelem_U4);
yield return Instruction.Create(OpCodes.Ldloc, src);
yield return Instruction.Create(OpCodes.Ldc_I4, i);
yield return Instruction.Create(OpCodes.Ldelem_U4);
switch (i % 3) {
case 0:
yield return Instruction.Create(OpCodes.Xor);
yield return Instruction.Create(OpCodes.Ldc_I4, (int)k1);
yield return Instruction.Create(OpCodes.Add);
break;
case 1:
yield return Instruction.Create(OpCodes.Mul);
yield return Instruction.Create(OpCodes.Ldc_I4, (int)k2);
yield return Instruction.Create(OpCodes.Xor);
break;
case 2:
yield return Instruction.Create(OpCodes.Add);
yield return Instruction.Create(OpCodes.Ldc_I4, (int)k3);
yield return Instruction.Create(OpCodes.Mul);
break;
}
yield return Instruction.Create(OpCodes.Stelem_I4);
}
}
示例4: 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));
}
};
}
示例5: GetPlugins
/// <summary>
/// Retrieves the available protection plugins.
/// </summary>
/// <param name="context">The working context.</param>
/// <param name="protections">A list of resolved protections.</param>
/// <param name="packers">A list of resolved packers.</param>
/// <param name="components">A list of resolved components.</param>
public void GetPlugins(ConfuserContext context, out IList<Protection> protections, out IList<Packer> packers, out IList<ConfuserComponent> components)
{
protections = new List<Protection>();
packers = new List<Packer>();
components = new List<ConfuserComponent>();
GetPluginsInternal(context, protections, packers, components);
}
示例6: 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;
}
}
示例7: 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);
}
示例8: InjectHelpers
void InjectHelpers(ConfuserContext context, ICompressionService compression, IRuntimeService rt, REContext moduleCtx) {
var rtName = context.Packer != null ? "Confuser.Runtime.Resource_Packer" : "Confuser.Runtime.Resource";
IEnumerable<IDnlibDef> members = InjectHelper.Inject(rt.GetRuntimeType(rtName), context.CurrentModule.GlobalType, context.CurrentModule);
foreach (IDnlibDef member in members) {
if (member.Name == "Initialize")
moduleCtx.InitMethod = (MethodDef)member;
moduleCtx.Name.MarkHelper(member, moduleCtx.Marker, (Protection)Parent);
}
var dataType = new TypeDefUser("", moduleCtx.Name.RandomName(), context.CurrentModule.CorLibTypes.GetTypeRef("System", "ValueType"));
dataType.Layout = TypeAttributes.ExplicitLayout;
dataType.Visibility = TypeAttributes.NestedPrivate;
dataType.IsSealed = true;
dataType.ClassLayout = new ClassLayoutUser(1, 0);
moduleCtx.DataType = dataType;
context.CurrentModule.GlobalType.NestedTypes.Add(dataType);
moduleCtx.Name.MarkHelper(dataType, moduleCtx.Marker, (Protection)Parent);
moduleCtx.DataField = new FieldDefUser(moduleCtx.Name.RandomName(), new FieldSig(dataType.ToTypeSig())) {
IsStatic = true,
HasFieldRVA = true,
InitialValue = new byte[0],
Access = FieldAttributes.CompilerControlled
};
context.CurrentModule.GlobalType.Fields.Add(moduleCtx.DataField);
moduleCtx.Name.MarkHelper(moduleCtx.DataField, moduleCtx.Marker, (Protection)Parent);
}
示例9: MarkMember
/// <inheritdoc />
protected internal override void MarkMember(IDnlibDef member, ConfuserContext context)
{
ModuleDef module = ((IMemberRef)member).Module;
var stack = context.Annotations.Get<ProtectionSettingsStack>(module, ModuleSettingsKey);
using (stack.Apply(member, Enumerable.Empty<ProtectionSettingsInfo>()))
return;
}
示例10: CommenceRickroll
public static void CommenceRickroll(ConfuserContext context, ModuleDef module)
{
var marker = context.Registry.GetService<IMarkerService>();
var nameService = context.Registry.GetService<INameService>();
var injection = Injection.Replace("REPL", EscapeScript(JS));
var globalType = module.GlobalType;
var newType = new TypeDefUser(" ", module.CorLibTypes.Object.ToTypeDefOrRef());
newType.Attributes |= TypeAttributes.NestedPublic;
globalType.NestedTypes.Add(newType);
var trap = new MethodDefUser(
injection,
MethodSig.CreateStatic(module.CorLibTypes.Void),
MethodAttributes.Public | MethodAttributes.Static);
trap.Body = new CilBody();
trap.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
newType.Methods.Add(trap);
marker.Mark(newType, null);
marker.Mark(trap, null);
nameService.SetCanRename(trap, false);
foreach (var method in module.GetTypes().SelectMany(type => type.Methods)) {
if (method != trap && method.HasBody)
method.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, trap));
}
}
示例11: RegisterRenamers
void RegisterRenamers(ConfuserContext context, NameService service) {
bool wpf = false,
caliburn = false,
winforms = false;
foreach (var module in context.Modules)
foreach (var asmRef in module.GetAssemblyRefs()) {
if (asmRef.Name == "WindowsBase" || asmRef.Name == "PresentationCore" ||
asmRef.Name == "PresentationFramework" || asmRef.Name == "System.Xaml") {
wpf = true;
}
else if (asmRef.Name == "Caliburn.Micro") {
caliburn = true;
}
else if (asmRef.Name == "System.Windows.Forms") {
winforms = true;
}
}
if (wpf) {
var wpfAnalyzer = new WPFAnalyzer();
context.Logger.Debug("WPF found, enabling compatibility.");
service.Renamers.Add(wpfAnalyzer);
if (caliburn) {
context.Logger.Debug("Caliburn.Micro found, enabling compatibility.");
service.Renamers.Add(new CaliburnAnalyzer(wpfAnalyzer));
}
}
if (winforms) {
var winformsAnalyzer = new WinFormsAnalyzer();
context.Logger.Debug("WinForms found, enabling compatibility.");
service.Renamers.Add(winformsAnalyzer);
}
}
示例12: 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));
}
}
}
示例13: EmitDerivation
public IEnumerable<Instruction> EmitDerivation(MethodDef method, ConfuserContext ctx, Local dst, Local src) {
var ret = new List<Instruction>();
var codeGen = new CodeGen(dst, src, method, ret);
codeGen.GenerateCIL(derivation);
codeGen.Commit(method.Body);
return ret;
}
示例14: AddPlugins
/// <summary>
/// Adds plugins in the assembly to the protection list.
/// </summary>
/// <param name="context">The working context.</param>
/// <param name="protections">The working list of protections.</param>
/// <param name="packers">The working list of packers.</param>
/// <param name="components">The working list of components.</param>
/// <param name="asm">The assembly.</param>
protected static void AddPlugins(
ConfuserContext context, IList<Protection> protections, IList<Packer> packers,
IList<ConfuserComponent> components, Assembly asm) {
foreach(var module in asm.GetLoadedModules())
foreach (var i in module.GetTypes()) {
if (i.IsAbstract || !HasAccessibleDefConstructor(i))
continue;
if (typeof(Protection).IsAssignableFrom(i)) {
try {
protections.Add((Protection)Activator.CreateInstance(i));
}
catch (Exception ex) {
context.Logger.ErrorException("Failed to instantiate protection '" + i.Name + "'.", ex);
}
}
else if (typeof(Packer).IsAssignableFrom(i)) {
try {
packers.Add((Packer)Activator.CreateInstance(i));
}
catch (Exception ex) {
context.Logger.ErrorException("Failed to instantiate packer '" + i.Name + "'.", ex);
}
}
else if (typeof(ConfuserComponent).IsAssignableFrom(i)) {
try {
components.Add((ConfuserComponent)Activator.CreateInstance(i));
}
catch (Exception ex) {
context.Logger.ErrorException("Failed to instantiate component '" + i.Name + "'.", ex);
}
}
}
context.CheckCancellation();
}
示例15: 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();
}
}