本文整理汇总了C#中ModuleDef类的典型用法代码示例。如果您正苦于以下问题:C# ModuleDef类的具体用法?C# ModuleDef怎么用?C# ModuleDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModuleDef类属于命名空间,在下文中一共展示了ModuleDef类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetImageData
public static bool GetImageData(ModuleDef module, string typeName, byte[] serializedData, out byte[] imageData)
{
imageData = null;
if (CouldBeBitmap(module, typeName)) {
var dict = Deserializer.Deserialize(SystemDrawingBitmap.DefinitionAssembly.FullName, SystemDrawingBitmap.ReflectionFullName, serializedData);
// Bitmap loops over every item looking for "Data" (case insensitive)
foreach (var v in dict.Values) {
var d = v.Value as byte[];
if (d == null)
continue;
if ("Data".Equals(v.Name, StringComparison.OrdinalIgnoreCase)) {
imageData = d;
return true;
}
}
return false;
}
if (CouldBeIcon(module, typeName)) {
var dict = Deserializer.Deserialize(SystemDrawingIcon.DefinitionAssembly.FullName, SystemDrawingIcon.ReflectionFullName, serializedData);
DeserializedDataInfo info;
if (!dict.TryGetValue("IconData", out info))
return false;
imageData = info.Value as byte[];
return imageData != null;
}
return false;
}
开发者ID:GreenDamTan,项目名称:dnSpy,代码行数:29,代码来源:SerializedImageUtils.cs
示例2: Copy
public static void Copy(this TypeDef sourceTypeDef, ModuleDef moduleDef)
{
var targetType = new TypeDefUser(sourceTypeDef.Namespace, sourceTypeDef.Name, sourceTypeDef.BaseType);
targetType.Attributes = sourceTypeDef.Attributes;
moduleDef.Types.Add(targetType);
Copy(sourceTypeDef, targetType);
}
开发者ID:picrap,项目名称:VersionStitcher,代码行数:7,代码来源:ModuleUtility.cs
示例3: Decompile
void Decompile(ModuleDef module, BamlDocument document, IDecompiler lang,
IDecompilerOutput output, CancellationToken token) {
var decompiler = new XamlDecompiler();
var xaml = decompiler.Decompile(module, document, token, BamlDecompilerOptions.Create(lang), null);
var xamlText = new XamlOutputCreator(xamlOutputOptionsProvider.Default).CreateText(xaml);
documentWriterService.Write(output, xamlText, ContentTypes.Xaml);
}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:7,代码来源:BamlResourceElementNode.cs
示例4: CilBodyVM
public CilBodyVM(CilBodyOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType, MethodDef ownerMethod)
{
this.ownerModule = ownerModule;
this.ownerMethod = ownerMethod;
this.origOptions = options;
typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language) {
CanAddGenericTypeVar = ownerType.HasGenericParameters,
CanAddGenericMethodVar = ownerMethod.MethodSig.GetGenParamCount() > 0,
OwnerType = ownerType,
OwnerMethod = ownerMethod,
};
this.localsListVM = new IndexObservableCollection<LocalVM>(() => new LocalVM(typeSigCreatorOptions, new LocalOptions(new Local(ownerModule.CorLibTypes.Int32))));
this.instructionsListVM = new IndexObservableCollection<InstructionVM>(() => CreateInstructionVM());
this.exceptionHandlersListVM = new IndexObservableCollection<ExceptionHandlerVM>(() => new ExceptionHandlerVM(typeSigCreatorOptions, new ExceptionHandlerOptions()));
this.LocalsListVM.UpdateIndexesDelegate = LocalsUpdateIndexes;
this.InstructionsListVM.UpdateIndexesDelegate = InstructionsUpdateIndexes;
this.ExceptionHandlersListVM.UpdateIndexesDelegate = ExceptionHandlersUpdateIndexes;
this.InstructionsListVM.CollectionChanged += InstructionsListVM_CollectionChanged;
this.LocalsListVM.CollectionChanged += LocalsListVM_CollectionChanged;
this.ExceptionHandlersListVM.CollectionChanged += ExceptionHandlersListVM_CollectionChanged;
this.maxStack = new UInt16VM(a => CallHasErrorUpdated());
this.localVarSigTok = new UInt32VM(a => CallHasErrorUpdated());
this.headerSize = new ByteVM(a => CallHasErrorUpdated());
this.headerRVA = new UInt32VM(a => CallHasErrorUpdated());
this.headerFileOffset = new UInt64VM(a => CallHasErrorUpdated());
this.rva = new UInt32VM(a => CallHasErrorUpdated());
this.fileOffset = new UInt64VM(a => CallHasErrorUpdated());
Reinitialize();
}
开发者ID:BahNahNah,项目名称:dnSpy,代码行数:32,代码来源:CilBodyVM.cs
示例5: GetModule
static MModule GetModule(ModuleDef moduleDef) {
foreach (var mm in modules.Values) {
if (mm.moduleDef == moduleDef)
return mm;
}
return null;
}
开发者ID:GodLesZ,项目名称:de4dot,代码行数:7,代码来源:Resolver.cs
示例6: DerivedTypesEntryNode
public DerivedTypesEntryNode(TypeDef type, ModuleDef[] modules)
{
this.type = type;
this.modules = modules;
this.LazyLoading = true;
threading = new ThreadingSupport();
}
开发者ID:nakijun,项目名称:dnSpy,代码行数:7,代码来源:DerivedTypesEntryNode.cs
示例7: DecryptStrings
private int DecryptStrings(ModuleDef moduleDef, IMDTokenProvider decryptionMethod, IFullName declaringType)
{
var assembly = Assembly.LoadFile(moduleDef.Location);
var decryptCount = 0;
foreach (var type in moduleDef.Types)
{
foreach (var method in type.Methods)
{
if (!method.HasBody || !method.Body.HasInstructions)
continue;
var instructions = method.Body.Instructions;
for (var i = 0; i < instructions.Count; i++)
{
if (instructions[i].OpCode != OpCodes.Ldstr)
continue;
if (instructions[i + 1].OpCode != OpCodes.Ldstr)
continue;
if (!instructions[i + 2].Operand.ToString().
Equals(decryptionMethod.ToString()))
continue;
var param1 = instructions[i].Operand.ToString();
var param2 = instructions[i + 1].Operand.ToString();
var methodType = assembly.GetType(declaringType.Name);
if (methodType == null)
continue;
var metaData = decryptionMethod.MDToken.ToInt32();
var methodBase = methodType.Module.ResolveMethod(metaData);
if (methodBase == null)
continue;
var parameters = methodBase.GetParameters();
if (parameters.Length == 0)
continue;
var result
= methodBase.Invoke(null, new object[] { param1, param2 });
var body = method.Body;
body.Instructions[i].OpCode = OpCodes.Ldstr;
body.Instructions[i].Operand = result.ToString();
body.Instructions.RemoveAt(i + 1);
body.Instructions.RemoveAt(i + 1);
decryptCount++;
}
}
}
return decryptCount;
}
开发者ID:Virility,项目名称:OutStringDecrypter,代码行数:60,代码来源:StringDeobfuscator.cs
示例8: 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));
}
}
开发者ID:MetSystem,项目名称:ConfuserEx,代码行数:28,代码来源:RickRoller.cs
示例9: ResolveNormal
DnSpyFile ResolveNormal(IAssembly assembly, ModuleDef sourceModule, bool delayLoad) {
var existingFile = fileList.FindAssembly(assembly);
if (existingFile != null)
return existingFile;
var file = LookupFromSearchPaths(assembly, sourceModule, true);
if (file != null)
return fileList.AddFile(file, fileList.AssemblyLoadEnabled, delayLoad);
if (fileList.UseGAC) {
var gacFile = GacInterop.FindAssemblyInNetGac(assembly);
if (gacFile != null)
return fileList.GetOrCreate(gacFile, fileList.AssemblyLoadEnabled, true, delayLoad);
foreach (var path in GacInfo.OtherGacPaths) {
file = TryLoadFromDir(assembly, true, path);
if (file != null)
return fileList.AddFile(file, fileList.AssemblyLoadEnabled, delayLoad);
}
}
file = LookupFromSearchPaths(assembly, sourceModule, false);
if (file != null)
return fileList.AddFile(file, fileList.AssemblyLoadEnabled, delayLoad);
return null;
}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:26,代码来源:AssemblyResolver.cs
示例10: DynamicMethodBodyReader
/// <summary>
/// Constructor
/// </summary>
/// <param name="module">Module that will own the method body</param>
/// <param name="obj">This can be one of several supported types: the delegate instance
/// created by DynamicMethod.CreateDelegate(), a DynamicMethod instance, a RTDynamicMethod
/// instance or a DynamicResolver instance.</param>
/// <param name="gpContext">Generic parameter context</param>
public DynamicMethodBodyReader(ModuleDef module, object obj, GenericParamContext gpContext)
{
this.module = module;
this.importer = new Importer(module, ImporterOptions.TryToUseDefs, gpContext);
this.gpContext = gpContext;
this.methodName = null;
if (obj == null)
throw new ArgumentNullException("obj");
var del = obj as Delegate;
if (del != null) {
obj = del.Method;
if (obj == null)
throw new Exception("Delegate.Method == null");
}
if (obj.GetType().ToString() == "System.Reflection.Emit.DynamicMethod+RTDynamicMethod") {
obj = rtdmOwnerFieldInfo.Read(obj) as DynamicMethod;
if (obj == null)
throw new Exception("RTDynamicMethod.m_owner is null or invalid");
}
if (obj is DynamicMethod) {
methodName = ((DynamicMethod)obj).Name;
obj = dmResolverFieldInfo.Read(obj);
if (obj == null)
throw new Exception("No resolver found");
}
if (obj.GetType().ToString() != "System.Reflection.Emit.DynamicResolver")
throw new Exception("Couldn't find DynamicResolver");
var code = rslvCodeFieldInfo.Read(obj) as byte[];
if (code == null)
throw new Exception("No code");
codeSize = code.Length;
var delMethod = rslvMethodFieldInfo.Read(obj) as SR.MethodBase;
if (delMethod == null)
throw new Exception("No method");
maxStack = (int)rslvMaxStackFieldInfo.Read(obj);
var scope = rslvDynamicScopeFieldInfo.Read(obj);
if (scope == null)
throw new Exception("No scope");
var tokensList = scopeTokensFieldInfo.Read(scope) as System.Collections.IList;
if (tokensList == null)
throw new Exception("No tokens");
tokens = new List<object>(tokensList.Count);
for (int i = 0; i < tokensList.Count; i++)
tokens.Add(tokensList[i]);
ehInfos = (IList<object>)rslvExceptionsFieldInfo.Read(obj);
ehHeader = rslvExceptionHeaderFieldInfo.Read(obj) as byte[];
UpdateLocals(rslvLocalsFieldInfo.Read(obj) as byte[]);
this.reader = MemoryImageStream.Create(code);
this.method = CreateMethodDef(delMethod);
this.parameters = this.method.Parameters;
}
开发者ID:0xd4d,项目名称:dnlib,代码行数:68,代码来源:DynamicMethodBodyReader.cs
示例11: ResourceWriter
ResourceWriter(ModuleDef module, Stream stream, ResourceElementSet resources)
{
this.module = module;
this.typeCreator = new ResourceDataCreator(module);
this.writer = new BinaryWriter(stream);
this.resources = resources;
}
开发者ID:sthiy,项目名称:dnlib,代码行数:7,代码来源:ResourceWriter.cs
示例12: GetRuntimeDecompressor
/// <inheritdoc />
public MethodDef GetRuntimeDecompressor(ModuleDef module, Action<IDnlibDef> init) {
Tuple<MethodDef, List<IDnlibDef>> decompressor = context.Annotations.GetOrCreate(module, Decompressor, m => {
var rt = context.Registry.GetService<IRuntimeService>();
List<IDnlibDef> members = InjectHelper.Inject(rt.GetRuntimeType("Confuser.Runtime.Lzma"), module.GlobalType, module).ToList();
MethodDef decomp = null;
foreach (IDnlibDef member in members) {
if (member is MethodDef) {
var method = (MethodDef)member;
if (method.Access == MethodAttributes.Public)
method.Access = MethodAttributes.Assembly;
if (!method.IsConstructor)
method.IsSpecialName = false;
if (method.Name == "Decompress")
decomp = method;
}
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);
}
}
}
members.RemoveWhere(def => def is FieldDef && ((FieldDef)def).IsLiteral);
Debug.Assert(decomp != null);
return Tuple.Create(decomp, members);
});
foreach (IDnlibDef member in decompressor.Item2)
init(member);
return decompressor.Item1;
}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:36,代码来源:CompressionService.cs
示例13: AddToNewAssemblyDef
public static AssemblyDef AddToNewAssemblyDef(ModuleDef module, ModuleKind moduleKind, out Characteristics characteristics)
{
var asmDef = module.UpdateRowId(new AssemblyDefUser(GetAssemblyName(module)));
asmDef.Modules.Add(module);
WriteNewModuleKind(module, moduleKind, out characteristics);
return asmDef;
}
开发者ID:BahNahNah,项目名称:dnSpy,代码行数:7,代码来源:ModuleUtils.cs
示例14: MethodOverrideVM
public MethodOverrideVM(MethodOverrideOptions options, ModuleDef ownerModule)
{
this.ownerModule = ownerModule;
this.origOptions = options;
Reinitialize();
}
开发者ID:BahNahNah,项目名称:dnSpy,代码行数:7,代码来源:MethodOverrideVM.cs
示例15: Inject
/// <summary>
/// Injects the specified MethodDef to another module.
/// </summary>
/// <param name="methodDef">The source MethodDef.</param>
/// <param name="target">The target module.</param>
/// <returns>The injected MethodDef.</returns>
public static MethodDef Inject(MethodDef methodDef, ModuleDef target)
{
var ctx = new InjectContext(methodDef.Module, target);
ctx.Map[methodDef] = Clone(methodDef);
CopyMethodDef(methodDef, ctx);
return (MethodDef)ctx.Map[methodDef];
}
开发者ID:MetSystem,项目名称:ConfuserEx,代码行数:13,代码来源:InjectHelper.cs
示例16: InstructionVM
public InstructionVM(ModuleDef ownerModule)
{
this.ownerModule = ownerModule;
this.instructionOperandVM = new InstructionOperandVM();
this.InstructionOperandVM.PropertyChanged += (a, b) => HasErrorUpdated();
this.codeVM = new ListVM<Code>(codeList, (a, b) => OnCodeUpdated());
}
开发者ID:BahNahNah,项目名称:dnSpy,代码行数:7,代码来源:InstructionVM.cs
示例17: RemoveModule
public void RemoveModule(ModuleDef module) {
var assembly = module.Assembly;
if (assembly == null)
return;
Remove(module.Assembly);
}
开发者ID:RafaelRMachado,项目名称:de4dot,代码行数:7,代码来源:AssemblyResolver.cs
示例18: DecompileAssemblyInfo
/// <summary>
/// Constructor
/// </summary>
/// <param name="output">Output</param>
/// <param name="ctx">Context</param>
/// <param name="module">Type</param>
public DecompileAssemblyInfo(IDecompilerOutput output, DecompilationContext ctx, ModuleDef module)
: base(output, ctx) {
if (module == null)
throw new ArgumentNullException(nameof(module));
Module = module;
KeepAllAttributes = false;
}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:13,代码来源:DecompileAssemblyInfo.cs
示例19: FieldOptionsVM
public FieldOptionsVM(FieldDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType)
{
this.ownerModule = ownerModule;
var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language) {
IsLocal = false,
CanAddGenericTypeVar = true,
CanAddGenericMethodVar = false,
OwnerType = ownerType,
};
if (ownerType != null && ownerType.GenericParameters.Count == 0)
typeSigCreatorOptions.CanAddGenericTypeVar = false;
this.typeSigCreator = new TypeSigCreatorVM(typeSigCreatorOptions);
TypeSigCreator.PropertyChanged += typeSigCreator_PropertyChanged;
this.customAttributesVM = new CustomAttributesVM(ownerModule, language);
this.origOptions = options;
this.constantVM = new ConstantVM(ownerModule, options.Constant == null ? null : options.Constant.Value, "Default value for this field");
ConstantVM.PropertyChanged += constantVM_PropertyChanged;
this.marshalTypeVM = new MarshalTypeVM(ownerModule, language, ownerType, null);
MarshalTypeVM.PropertyChanged += marshalTypeVM_PropertyChanged;
this.fieldOffset = new NullableUInt32VM(a => HasErrorUpdated());
this.initialValue = new HexStringVM(a => HasErrorUpdated());
this.rva = new UInt32VM(a => HasErrorUpdated());
this.implMapVM = new ImplMapVM(ownerModule);
ImplMapVM.PropertyChanged += implMapVM_PropertyChanged;
this.typeSigCreator.CanAddFnPtr = false;
ConstantVM.IsEnabled = HasDefault;
MarshalTypeVM.IsEnabled = HasFieldMarshal;
ImplMapVM.IsEnabled = PinvokeImpl;
Reinitialize();
}
开发者ID:se7ensoft,项目名称:dnSpy,代码行数:33,代码来源:FieldOptionsVM.cs
示例20: ConstantVM
public ConstantVM(ModuleDef ownerModule, object value, string constantCheckBoxToolTip) {
ConstantTypeVM = new ConstantTypeVM(ownerModule, value, constantTypes, true, false);
ConstantCheckBoxToolTip = constantCheckBoxToolTip;
ConstantTypeVM.PropertyChanged += ConstantTypeVM_PropertyChanged;
IsEnabled = ConstantTypeVM.IsEnabled;
}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:7,代码来源:ConstantVM.cs
注:本文中的ModuleDef类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论