internal void loadInstructions(MetaDataLoader mdLoader, PELoader peLoader, Stream fileStream, int[] lines, int[] columns, int[] offsets, String srcFileName, int count) { if (this.rva != 0) { if ((this.flags & (short)MethodAttributes.PinvokeImpl) == 0 || (this.flags & (short)MethodAttributes.UnmanagedExport) != 0) { int codeOffset = peLoader.VaToOffset(rva); this.instructions = Instruction.getInstructions(mdLoader, fileStream, codeOffset, lines, columns, offsets, srcFileName, count, out this.ehTable, out this.bbTable, out this.maxStack, out this.locals, out this.initLocals); } else { Console.WriteLine("Not loading embedded native code for " + this); } } }
public static MetaData loadMetaData(String name, PELoader peLoader, bool fLoadCode, bool fLoadDebugInfo) { return(MetaDataLoader.getMetaData(name, peLoader, fLoadCode, fLoadDebugInfo)); }
public void LoadSection(PELoader peLoader) { Stream fileStream = peLoader.getStream(); fileStream.Seek(peLoader.VaToOffset(header.virtualAddress), SeekOrigin.Begin); BinaryReader reader = new BinaryReader(fileStream); this.rawData = reader.ReadBytes(header.sizeOfRawData); }
internal void resolveReferences(MetaDataLoader loader, PELoader peLoader, Stream fileStream) { this.field.resolveReferences(this); int dataOffset = peLoader.VaToOffsetSafe(this.rva); if (dataOffset != -1) { fileStream.Seek(dataOffset, SeekOrigin.Begin); BinaryReader reader = new BinaryReader(fileStream); SignatureField fieldSignature = (SignatureField) this.field.Signature; Signature.Type fieldType = fieldSignature.FieldType; int dataSize = this.getFieldSize(fieldType); byte[] data = new byte[dataSize]; int count = reader.Read(data, 0, dataSize); if (loader.HasVtableFixup() && loader.RVAHasRelocation(dataOffset) && dataSize == 4) { // if this corresponds to a vtable label, we need to fix it int location = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); int imageBase = peLoader.getImageBase(); location -= imageBase; // use RVA fileStream.Seek(location, SeekOrigin.Begin); BinaryReader binaryReader = new BinaryReader(fileStream); short prefix = binaryReader.ReadInt16(); if (prefix == 0x25FF) // this starts a vtable lable { count = binaryReader.Read(data, 0, 4); } } this.dataBytes = data; if (count != dataSize) { throw new MetaDataLoader.IllegalMetaDataFormatException("Only got " + count + " out of " + dataSize + " data bytes for FieldRVA " + this.rva); } } else { Console.WriteLine("Found no data for " + this.field); } }
private void LoadMetaData(ArrayList loadedStreams, bool fLoadCode, bool fLoadSectionsFromExecutable, bool fLoadDebugInfo) { // try to load the metadata for all streams in loadedStreams. this.entryList = new ArrayList(); this.metaDataList = new ArrayList(); foreach (LoadedStream stream in loadedStreams) { PELoader loader = null; try { if (fDebug) { Console.Out.WriteLine("loading " + stream.Name + "'"); } loader = new PELoader(stream.Content, stream.Name); } catch (FileNotFoundException) { // failed on raw filename; try prefixing with libDirNames elts if (fDebug) { Console.Out.WriteLine("...failed"); } } StringBuilder sb = new StringBuilder(); if (loader == null) { sb.Append("Unable to load '"); sb.Append(stream.Name); sb.Append("'"); Console.Out.WriteLine(sb.ToString()); Console.Out.WriteLine("Aborting!"); String stackTrace = System.Environment.StackTrace; Console.Out.WriteLine(stackTrace); throw new Exception(sb.ToString()); } TimeSpan diffSpan = System.DateTime.Now.Subtract(startTime); int diffMsec = (int)diffSpan.TotalMilliseconds; String secString = (diffMsec / 1000).ToString(); sb.Append(" ", 0, (8 - secString.Length)); sb.Append(secString); sb.Append('.'); sb.Append((diffMsec % 1000).ToString("000")); sb.Append(": "); sb.Append("Loading metadata "); if (fLoadCode) { sb.Append("with code "); } sb.Append("from '"); sb.Append(stream.Name); sb.Append("'"); Console.Out.WriteLine(sb.ToString()); MetaData metaData = MetaData.loadMetaData(stream.Path, loader, fLoadCode, fLoadDebugInfo); metaDataList.Add(metaData); ResolverEntry entry = new ResolverEntry(metaData, stream.Name); entryList.Add(entry); // if (fLoadSectionsFromExecutable && loader.IsExecutableImage()) { // Console.Out.WriteLine("loading all sections from " + fileName); // loader.loadSections(); // } loader.getStream().Close(); } }
// Constructor Methods public static MetaData loadMetaData(String name, PELoader peLoader) { return(MetaDataLoader.getMetaData(name, peLoader, false, false)); }