Пример #1
0
        public static INode Read(InspectableAssembly ia, MethodSignature signature, MethodBodyBlock rawBody)
        {
            /*Console.WriteLine("=== IL Bytes ===");
            foreach (var b in ilBytes)
                Console.Write("{0:X2} ", b);
            Console.WriteLine();*/

            var parser = new ILMethodParser(ia, signature, rawBody);
            return parser.Parse();
        }
Пример #2
0
        /// <summary>
        /// Returns a body block of a method with specified Relative Virtual Address (RVA);
        /// </summary>
        /// <exception cref="ArgumentNullException"><paramref name="peReader"/> is null.</exception>
        /// <exception cref="BadImageFormatException">The body is not found in the metadata or is invalid.</exception>
        /// <exception cref="InvalidOperationException">Section where the method is stored is not available.</exception>
        /// <exception cref="IOException">IO error while reading from the underlying stream.</exception>
        public static MethodBodyBlock GetMethodBody(this PEReader peReader, int relativeVirtualAddress)
        {
            if (peReader is null)
            {
                Throw.ArgumentNull(nameof(peReader));
            }

            var block = peReader.GetSectionData(relativeVirtualAddress);

            if (block.Length == 0)
            {
                throw new BadImageFormatException(SR.Format(SR.InvalidMethodRva, relativeVirtualAddress));
            }

            // Call to validating public BlobReader constructor is by design -- we need to throw PlatformNotSupported on big-endian architecture.
            return(MethodBodyBlock.Create(block.GetReader()));
        }
Пример #3
0
        /// <summary>
        /// Returns a body block of a method with specified Relative Virtual Address (RVA);
        /// </summary>
        /// <exception cref="ArgumentNullException"><paramref name="peReader"/> is null.</exception>
        /// <exception cref="BadImageFormatException">The body is not found in the metadata or is invalid.</exception>
        /// <exception cref="InvalidOperationException">Section where the method is stored is not available.</exception>
        public static unsafe MethodBodyBlock GetMethodBody(this PEReader peReader, int relativeVirtualAddress)
        {
            if (peReader == null)
            {
                throw new ArgumentNullException("peReader");
            }

            var block = peReader.GetSectionData(relativeVirtualAddress);

            if (block.Length == 0)
            {
                throw new BadImageFormatException(string.Format(MetadataResources.InvalidMethodRva, relativeVirtualAddress));
            }

            // Call to validating public BlobReader constructor is by design -- we need to throw PlatformNotSupported on big-endian architecture.
            var blobReader = new BlobReader(block.Pointer, block.Length);

            return(MethodBodyBlock.Create(blobReader));
        }
Пример #4
0
 private EcmaMethodIL(EcmaMethod method, int rva)
 {
     _method = method;
     _module = method.Module;
     _methodBody = _module.PEReader.GetMethodBody(rva);
 }
Пример #5
0
 public EcmaMethodIL(EcmaModule module, MethodBodyBlock methodBody)
 {
     _module = module;
     _methodBody = methodBody;
 }
Пример #6
0
 private EcmaMethodIL(EcmaModule module, int rva)
 {
     _module = module;
     _methodBody = module.PEReader.GetMethodBody(rva);
 }