PERWAPI.PEFile.MakeDebuggable C# (CSharp) Method

MakeDebuggable() public method

Makes the assembly debuggable by attaching the DebuggableAttribute to the Assembly. Call immediately before calling WritePEFile.
public MakeDebuggable ( bool allowDebug, bool suppressOpt ) : void
allowDebug bool set true to enable debugging, false otherwise
suppressOpt bool set true to disable optimizations that affect debugging
return void
        public void MakeDebuggable(bool allowDebug, bool suppressOpt)
        {
            ClassRef debugRef = null;
            MethodRef dCtor = null;
            Type[] twoBools = new Type[] { PrimitiveType.Boolean, PrimitiveType.Boolean };
            debugRef = MSCorLib.mscorlib.GetClass("System.Diagnostics", "DebuggableAttribute");
            if (debugRef == null)
                debugRef = MSCorLib.mscorlib.AddClass("System.Diagnostics", "DebuggableAttribute");
            dCtor = debugRef.GetMethod(".ctor", twoBools);
            if (dCtor == null)
            {
                dCtor = debugRef.AddMethod(".ctor", PrimitiveType.Void, twoBools);
                dCtor.AddCallConv(CallConv.Instance);
            }
            Constant[] dbgArgs = new Constant[] { new BoolConst(allowDebug), new BoolConst(suppressOpt) };
            thisAssembly.AddCustomAttribute(dCtor, dbgArgs);
        }

Usage Example

Ejemplo n.º 1
0
        internal static System.Reflection.Assembly Load(PEFile assembly) {
            MemoryStream binaryStream = new MemoryStream();
            assembly.SetOutputStream(binaryStream);
            assembly.MakeDebuggable(false, false);
            assembly.WritePEFile(false);
            byte[] assemblyBytes = binaryStream.ToArray();

            System.Reflection.Assembly loadedAssembly = System.Reflection.Assembly.Load(assemblyBytes);
            loaded.Add(loadedAssembly);
            return loadedAssembly;
        }