本文整理汇总了C#中Mono.Cecil.ModuleDefinition类的典型用法代码示例。如果您正苦于以下问题:C# ModuleDefinition类的具体用法?C# ModuleDefinition怎么用?C# ModuleDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModuleDefinition类属于Mono.Cecil命名空间,在下文中一共展示了ModuleDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Phase1
public void Phase1(ModuleDefinition mod)
{
AssemblyDefinition i = AssemblyDefinition.ReadAssembly(typeof(Iid).Assembly.Location);
i.MainModule.ReadSymbols();
root = CecilHelper.Inject(mod, i.MainModule.GetType("AntiTamperMem"));
mod.Types.Add(root);
MethodDefinition cctor = mod.GetType("<Module>").GetStaticConstructor();
cctor.Body.GetILProcessor().InsertBefore(0, Instruction.Create(OpCodes.Call, root.Methods.FirstOrDefault(mtd => mtd.Name == "Initalize")));
Mutator mutator = new Mutator();
mutator.IntKeys = new int[]
{
key0,
(int)sectName.ToCharArray().Sum(_ => (int)_),
key2,
key3,
key4,
key5,
key6
};
mutator.LongKeys = new long[] { key1 };
mutator.Mutate(Confuser.Random, root);
root.Name = Confuser.ObfuscationHelper.GetRandomName();
root.Namespace = "";
AddHelper(root, HelperAttribute.NoInjection);
foreach (MethodDefinition mtdDef in root.Methods)
{
mtdDef.Name = Confuser.ObfuscationHelper.GetRandomName();
AddHelper(mtdDef, HelperAttribute.NoInjection);
}
Confuser.Database.AddEntry("AntiTamper", "Helper", root.FullName);
}
示例2: PatchModule
public static void PatchModule(ModuleDefinition baseModule)
{
var type = baseModule.AllNestedTypes().Single(t => t.FullName == "TowerFall.TeamSelectOverlay");
var method = type.Methods.Single(m => m.FullName == "System.Void TowerFall.TeamSelectOverlay::.ctor(TowerFall.CustomMapButton)");
var instructions = method.Body.Instructions.ToList();
instructions.ForEach(i => ChangeFoursToEights(i));
}
示例3: EntryPoint
public void EntryPoint (ModuleDefinition module)
{
var entry_point = module.EntryPoint;
Assert.IsNotNull (entry_point);
Assert.AreEqual ("System.Void Program::Main()", entry_point.ToString ());
}
示例4: ProcessAssemblyReferences
protected override void ProcessAssemblyReferences(ModuleDefinition moduleDef, IList<AssemblyNameReference> assemblyNameRefs)
{
for (int i = assemblyNameRefs.Count - 1; i >= 0; --i) {
AssemblyNameReference replacement = null;
var other = assemblyNameRefs[i];
var otherName = other.Name + "," + other.Version;
if (_assemblyReplacements.TryGetValue(other.Name, out replacement)) {
assemblyNameRefs[i].Version = replacement.Version;
assemblyNameRefs[i].PublicKeyToken = replacement.PublicKeyToken;
assemblyNameRefs[i].IsRetargetable = replacement.IsRetargetable;
var replacementName = replacement.Name + "," + replacement.Version;
Trace.WriteLine(string.Format("Replacing {0} with {1}.", otherName, replacementName), "RetargetReferences");
} else {
if (_removeOthers) {
try {
var otherAss = moduleDef.AssemblyResolver.Resolve(other);
var otherProfile = otherAss.GetAssemblyProfileFromAttribute();
if (otherProfile != null && otherProfile.IsPortable) {
Trace.WriteLine(string.Format("Keeping {0}.", otherName), "RetargetReferences");
continue;
}
} catch(Exception ex) {
Trace.WriteLine(string.Format("Failed resolving {0}.", otherName), "RetargetReferences");
}
Trace.WriteLine(string.Format("Removing {0}.", otherName), "RetargetReferences");
assemblyNameRefs.RemoveAt(i);
} else {
Trace.WriteLine(string.Format("Keeping {0}.", otherName), "RetargetReferences");
}
}
}
base.ProcessAssemblyReferences(moduleDef, assemblyNameRefs);
}
示例5: Rewrite
public void Rewrite(ModuleDefinition module, IEnumerable<ImplementedEventSource> loggers)
{
var tmp = from l in loggers
let old = l.Old.FindMethod("IsEnabled")
where old != null
select new
{
Old = old,
New = l.New.BaseType.Resolve().FindMethod("IsEnabled").ImportInto(module)
};
var fixMap = tmp.ToDictionary(a => a.Old.FullName, a => a.New);
var moduleMethods = module.Types.SelectMany(t => t.Methods).Where(m => m.HasBody).ToArray();
MethodReference impl;
foreach (var method in moduleMethods)
{
var ops = method.GetOpsOf(OpCodes.Callvirt).ToArray();
foreach (var o in ops)
{
var fullName = (o.Operand as MethodReference)?.FullName;
if (fullName != null && fixMap.TryGetValue(fullName, out impl))
{
o.OpCode = OpCodes.Call;
o.Operand = impl;
}
}
}
}
示例6: GetFrameworkVersionForModule
protected FrameworkVersion GetFrameworkVersionForModule(ModuleDefinition module, IFrameworkResolver frameworkResolver)
{
//TODO: handle Silverlight/WinPhone projects
TargetPlatform platform = module.AssemblyResolver.GetTargetPlatform(module.FilePath);
switch (platform)
{
case TargetPlatform.CLR_1:
return FrameworkVersion.v1_1;
case TargetPlatform.CLR_2:
return FrameworkVersion.v2_0;
case TargetPlatform.CLR_2_3:
case TargetPlatform.CLR_3_5:
return FrameworkVersion.v3_5;
case TargetPlatform.CLR_4:
return GetFramework4Version(module, frameworkResolver);
case TargetPlatform.WinRT:
return FrameworkVersion.WinRT;
case TargetPlatform.Silverlight:
return FrameworkVersion.Silverlight;
case TargetPlatform.WindowsCE:
return FrameworkVersion.WindowsCE;
case TargetPlatform.WindowsPhone:
return FrameworkVersion.WindowsPhone;
default:
return FrameworkVersion.Unknown;
}
}
示例7: CreateUsage
private MethodUsage CreateUsage(MemberReference operand, ModuleDefinition assembly, TypeDefinition type, MethodDefinition method, string testAssemblyPath)
{
if (operand == null)
return null;
Test test = new Test
{
PathToAssembly = Path.GetDirectoryName(testAssemblyPath),
AssemblyName = assembly.Assembly.Name.Name,
NamespaceName = type.Namespace,
ClassName = type.Name,
MethodName = method.Name
};
var instructionCall = new MethodUsage
{
AssemblyName = operand.DeclaringType.Scope.Name + ".dll",
NamespaceName = operand.DeclaringType.Namespace,
ClassName = operand.DeclaringType.Name,
MethodName = operand.Name,
TestCoverage = new List<Test> {test}
};
return instructionCall;
}
示例8: Read
public static ModuleReader Read(ModuleDefinition module)
{
var reader = new ModuleReader();
if (module.AssemblyReferences.All(reference => reference.Name != "Stiletto"))
{
return reader;
}
var allTypes = module.GetTypes();
foreach (var t in allTypes)
{
if (IsModule(t))
{
reader.ModuleTypes.Add(t);
}
if (IsInject(t))
{
reader.InjectTypes.Add(t);
}
}
return reader;
}
示例9: ImageReader
public ImageReader(IDeobfuscatorContext deobfuscatorContext, ModuleDefinition module, byte[] data)
{
this.deobfuscatorContext = deobfuscatorContext;
this.module = module;
this.reader = new BinaryReader(new MemoryStream(data));
this.memberReferenceConverter = new MemberReferenceConverter(module);
}
示例10: ImportReferences
public override void ImportReferences(ModuleDefinition module)
{
// Import the references from the base class
base.ImportReferences(module);
_modifiableInterfaceType = module.ImportType<IModifiableType>();
}
示例11: Convert
public Either<MemberReference, PropertyReferenceContainer> Convert(IAstReference astReference, ModuleDefinition module)
{
var reflectedType = astReference as AstReflectedType;
if (reflectedType != null)
return module.Import(reflectedType.ActualType);
var reflectedMethod = astReference as AstReflectedMethod;
if (reflectedMethod != null)
return module.Import(reflectedMethod.Method);
var reflectedConstructor = astReference as AstReflectedConstructor;
if (reflectedConstructor != null)
return module.Import(reflectedConstructor.Constructor);
var reflectedProperty = astReference as AstReflectedProperty;
if (reflectedProperty != null) {
var getMethod = reflectedProperty.Property.GetGetMethod();
var setMethod = reflectedProperty.Property.GetSetMethod();
return new PropertyReferenceContainer(
getMethod != null ? module.Import(getMethod) : null,
setMethod != null ? module.Import(setMethod) : null
);
}
return null;
}
示例12: AssemblyResolver
public AssemblyResolver(ModuleDefinition module, DecrypterType decrypterType)
{
this.module = module;
this.frameworkType = DotNetUtils.getFrameworkType(module);
this.decrypterType = decrypterType;
this.codeCompilerMethodCallRestorer = new CodeCompilerMethodCallRestorer(module);
}
示例13: ReturnGenericInstance
public void ReturnGenericInstance (ModuleDefinition module)
{
var bar = module.GetType ("Bar`1");
var self = bar.GetMethod ("Self");
Assert.IsNotNull (self);
var bar_t = self.ReturnType;
Assert.IsTrue (bar_t.IsGenericInstance);
var bar_t_instance = (GenericInstanceType) bar_t;
Assert.AreEqual (bar.GenericParameters [0], bar_t_instance.GenericArguments [0]);
var self_str = bar.GetMethod ("SelfString");
Assert.IsNotNull (self_str);
var bar_str = self_str.ReturnType;
Assert.IsTrue (bar_str.IsGenericInstance);
var bar_str_instance = (GenericInstanceType) bar_str;
Assert.AreEqual ("System.String", bar_str_instance.GenericArguments [0].FullName);
}
示例14: Replace
public void Replace(IMethodContext context, ModuleDefinition targetModule)
{
var currentMethod = context.CurrentMethod;
var currentArguments = context.CurrentArguments;
var currentArgument = context.CurrentArgument;
var pushMethod = targetModule.ImportMethod<Stack<object>>("Push");
var worker = context.CilWorker;
var methodMap = _context.MethodMap;
var targetDependency = _context.TargetDependency;
var interfaceType = _context.InterfaceType;
var adapterConstructor = _adapterBuilder.CreateAdapterConstructor(methodMap);
foreach (ParameterReference param in currentMethod.Parameters)
{
var arguments = new ParameterContext(worker,
interfaceType,
pushMethod,
currentArguments,
currentArgument,
targetDependency, adapterConstructor, param);
// Save the current argument
_pushParameter.Adapt(arguments);
}
}
示例15: GetInjecteeCecilType
internal virtual TypeDefinition GetInjecteeCecilType(ModuleDefinition module)
{
if (_injecteeCecilDef == null)
_injecteeCecilDef = module.FindMatchingType(InjecteeType, true);
return _injecteeCecilDef;
}