本文整理汇总了C#中IBinaryDocument类的典型用法代码示例。如果您正苦于以下问题:C# IBinaryDocument类的具体用法?C# IBinaryDocument怎么用?C# IBinaryDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IBinaryDocument类属于命名空间,在下文中一共展示了IBinaryDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MemoryMappedFile
private MemoryMappedFile(
IBinaryDocument binaryDocument,
byte* buffer,
uint length
) {
this.binaryDocument = binaryDocument;
this.buffer = buffer;
this.length = length;
}
示例2: OpenBinaryDocument
/// <summary>
/// Open the binary document as a memory block in host dependent fashion.
/// </summary>
/// <param name="sourceDocument">The binary document that is to be opened.</param>
/// <returns>The unmanaged memory block corresponding to the source document.</returns>
public override IBinaryDocumentMemoryBlock/*?*/ OpenBinaryDocument(IBinaryDocument sourceDocument) {
try {
IBinaryDocumentMemoryBlock binDocMemoryBlock = UnmanagedBinaryMemoryBlock.CreateUnmanagedBinaryMemoryBlock(sourceDocument.Location, sourceDocument);
this.disposableObjectAllocatedByThisHost.Add((IDisposable)binDocMemoryBlock);
return binDocMemoryBlock;
} catch (IOException) {
return null;
}
}
示例3: OpenBinaryDocument
public override IBinaryDocumentMemoryBlock OpenBinaryDocument(IBinaryDocument sourceDocument) {
VSServiceProvider.Current.Logger.WriteToLog("Opening document: " + sourceDocument.Name + " from: " + sourceDocument.Location);
try {
IBinaryDocumentMemoryBlock binDocMemoryBlock = UnmanagedBinaryMemoryBlock.CreateUnmanagedBinaryMemoryBlock(sourceDocument.Location, sourceDocument);
return binDocMemoryBlock;
} catch (IOException) {
VSServiceProvider.Current.Logger.WriteToLog("Failed to open document.");
return null;
}
}
示例4: CreateMemoryMappedFile
/// <summary>
/// Factory method for opening the memory mapped file. The content of the map is assumed to come from localFileName.
/// This can throw FileLoadException in case of error.
/// </summary>
/// <param name="localFileName">Name of the file from where the binary document needs to be opened.
/// This is useful in case we want to copy the file to temporary location and then open or when we want to open document on the network.</param>
/// <param name="binaryDocument">The binary document for which the memory mapping is requested.</param>
public static MemoryMappedFile CreateMemoryMappedFile(
string localFileName,
IBinaryDocument binaryDocument
) {
uint length;
Byte* buffer;
MemoryMappedFile.OpenFileMemoryMap(localFileName, out buffer, out length);
if (length != binaryDocument.Length)
throw new IOException("File size difference: " + localFileName);
return new MemoryMappedFile(
binaryDocument,
buffer,
length
);
}
示例5: OpenModule
/// <summary>
/// Method to open the module in the MetadataReader. This method loads the module and returns the object corresponding to the opened module.
/// Also returns the ModuleIDentifier corresponding to the module as the out parameter. Modules are opened as if they are not contained in any assembly.
/// </summary>
/// <param name="binaryDocument">The binary document that needes to be opened as an module.</param>
/// <param name="moduleIdentity">Contains the module identity of the binary document in case it is an module.</param>
/// <returns>Module that is loaded or Dummy.Module in case module could not be loaded.</returns>
public IModule OpenModule(
IBinaryDocument binaryDocument,
out ModuleIdentity/*?*/ moduleIdentity
) {
moduleIdentity = null;
lock (GlobalLock.LockingObject) {
IBinaryDocumentMemoryBlock/*?*/ binaryDocumentMemoryBlock = this.metadataReaderHost.OpenBinaryDocument(binaryDocument);
if (binaryDocumentMemoryBlock == null) {
// Error...
return Dummy.Module;
}
PEFileReader peFileReader = new PEFileReader(this, binaryDocumentMemoryBlock);
if (peFileReader.ReaderState < ReaderState.Metadata) {
// Error...
return Dummy.Module;
}
//^ assert peFileReader.ReaderState >= ReaderState.Metadata;
if (peFileReader.IsAssembly) {
AssemblyIdentity assemblyIdentity = this.GetAssemblyIdentifier(peFileReader);
moduleIdentity = assemblyIdentity;
Assembly/*?*/ lookupAssembly = this.LookupAssembly(null, assemblyIdentity);
if (lookupAssembly != null) {
return lookupAssembly;
}
} else {
moduleIdentity = this.GetModuleIdentifier(peFileReader);
Module/*?*/ lookupModule = this.LookupModule(null, moduleIdentity);
if (lookupModule != null) {
return lookupModule;
}
}
try {
PEFileToObjectModel peFileToObjectModel = new PEFileToObjectModel(this, peFileReader, moduleIdentity, null, this.metadataReaderHost.PointerSize);
this.LoadedModule(peFileToObjectModel.Module);
Assembly/*?*/ assembly = peFileToObjectModel.Module as Assembly;
if (assembly != null) {
this.OpenMemberModules(binaryDocument, assembly);
}
return peFileToObjectModel.Module;
} catch (MetadataReaderException) {
// Error...
}
}
return Dummy.Module;
}
示例6: OpenMemberModules
/// <summary>
/// This method is called when an assembly is loaded. This makes sure that all the member modules of the assembly are loaded.
/// </summary>
/// <param name="binaryDocument"></param>
/// <param name="assembly"></param>
void OpenMemberModules(IBinaryDocument binaryDocument, Assembly assembly) {
List<Module> memberModuleList = new List<Module>();
AssemblyIdentity assemblyIdentity = assembly.AssemblyIdentity;
foreach (IFileReference fileRef in assembly.PEFileToObjectModel.GetFiles()) {
if (!fileRef.HasMetadata)
continue;
IBinaryDocumentMemoryBlock/*?*/ binaryDocumentMemoryBlock = this.metadataReaderHost.OpenBinaryDocument(binaryDocument, fileRef.FileName.Value);
if (binaryDocumentMemoryBlock == null) {
// Error...
continue;
}
try {
PEFileReader peFileReader = new PEFileReader(this, binaryDocumentMemoryBlock);
if (peFileReader.ReaderState < ReaderState.Metadata) {
// Error...
continue;
}
if (peFileReader.IsAssembly) {
// Error...
continue;
}
ModuleIdentity moduleIdentity = this.GetModuleIdentifier(peFileReader, assemblyIdentity);
PEFileToObjectModel peFileToObjectModel = new PEFileToObjectModel(this, peFileReader, moduleIdentity, assembly, this.metadataReaderHost.PointerSize);
memberModuleList.Add(peFileToObjectModel.Module);
} catch (MetadataReaderException) {
continue;
}
}
if (memberModuleList.Count == 0)
return;
assembly.SetMemberModules(new EnumerableArrayWrapper<Module, IModule>(memberModuleList.ToArray(), Dummy.Module));
}
示例7: OpenAssembly
/// <summary>
/// Method to open the assembly in MetadataReader. This method loads the assembly and returns the object corresponding to the
/// opened assembly. Also returns the AssemblyIdentifier corresponding to the assembly as the out parameter.
/// Only assemblies that unify to themselves can be opened i.e. if the unification policy of the compilation host says that mscorlib 1.0 unifies to mscorlib 2.0
/// then only mscorlib 2.0 can be loaded.
/// </summary>
/// <param name="binaryDocument">The binary document that needes to be opened as an assembly.</param>
/// <param name="assemblyIdentity">Contains the assembly identifier of the binary document in case it is an assembly.</param>
/// <returns>Assembly that is loaded or Dummy.Assembly in case assembly could not be loaded.</returns>
public IAssembly OpenAssembly(
IBinaryDocument binaryDocument,
out AssemblyIdentity/*?*/ assemblyIdentity
) {
assemblyIdentity = null;
lock (GlobalLock.LockingObject) {
IBinaryDocumentMemoryBlock/*?*/ binaryDocumentMemoryBlock = this.metadataReaderHost.OpenBinaryDocument(binaryDocument);
if (binaryDocumentMemoryBlock == null) {
// Error...
return Dummy.Assembly;
}
PEFileReader peFileReader = new PEFileReader(this, binaryDocumentMemoryBlock);
if (peFileReader.ReaderState < ReaderState.Metadata) {
// Error...
return Dummy.Assembly;
}
//^ assert peFileReader.ReaderState >= ReaderState.Metadata;
if (!peFileReader.IsAssembly) {
// Error...
return Dummy.Assembly;
}
assemblyIdentity = this.GetAssemblyIdentifier(peFileReader);
Assembly/*?*/ lookupAssembly = this.LookupAssembly(null, assemblyIdentity);
if (lookupAssembly != null) {
return lookupAssembly;
}
try {
PEFileToObjectModel peFileToObjectModel = new PEFileToObjectModel(this, peFileReader, assemblyIdentity, null, this.metadataReaderHost.PointerSize);
Assembly/*?*/ assembly = peFileToObjectModel.Module as Assembly;
//^ assert assembly != null;
this.LoadedModule(assembly);
this.OpenMemberModules(binaryDocument, assembly);
return assembly;
} catch (MetadataReaderException) {
return Dummy.Assembly;
}
}
}
示例8: OpenBinaryDocument
/// <summary>
/// Opens a binary document.
/// </summary>
public override IBinaryDocumentMemoryBlock OpenBinaryDocument(IBinaryDocument sourceDocument) {
try {
IBinaryDocumentMemoryBlock binDocMemoryBlock = UnmanagedBinaryMemoryBlock.CreateUnmanagedBinaryMemoryBlock(sourceDocument.Location, sourceDocument);
return binDocMemoryBlock;
} catch (IOException) {
return null;
}
}
示例9: MetadataStreamLocation
internal MetadataStreamLocation(
IBinaryDocument binaryDocument,
string streamName,
uint offset
)
{
this.binaryDocument = binaryDocument;
this.streamName = streamName;
this.offset = offset;
}
示例10: GetAssemblyIdentifier
/// <summary>
/// If the given binary document contains a CLR assembly, return the identity of the assembly. Otherwise, return null.
/// </summary>
public AssemblyIdentity/*?*/ GetAssemblyIdentifier(IBinaryDocument binaryDocument) {
IBinaryDocumentMemoryBlock/*?*/ binaryDocumentMemoryBlock = this.metadataReaderHost.OpenBinaryDocument(binaryDocument);
if (binaryDocumentMemoryBlock == null) return null;
PEFileReader peFileReader = new PEFileReader(this, binaryDocumentMemoryBlock);
if (peFileReader.ReaderState < ReaderState.Metadata) return null;
if (!peFileReader.IsAssembly) return null;
return this.GetAssemblyIdentifier(peFileReader);
}
示例11: OpenModule
/// <summary>
/// Method to open the module in the MetadataReader. This method loads the module and returns the object corresponding to the opened module.
/// Also returns the ModuleIDentifier corresponding to the module as the out parameter. Modules are opened as if they are not contained in any assembly.
/// </summary>
/// <param name="binaryDocument">The binary document that needes to be opened as an module.</param>
/// <returns>Module that is loaded or Dummy.Module in case module could not be loaded.</returns>
public IModule OpenModule(IBinaryDocument binaryDocument) {
Contract.Requires(binaryDocument != null);
Contract.Ensures(Contract.Result<IModule>() != null);
ModuleIdentity/*?*/ retModuleIdentity;
return this.OpenModule(binaryDocument, out retModuleIdentity);
}
示例12: CreateUnmanagedBinaryMemoryBlock
/// <summary>
/// Creates an unmanaged binary memory block and copies the contents of the file at the given location into the block.
/// </summary>
/// <param name="localFileName">The path to the file to read.</param>
/// <param name="binaryDocument">The binary document whose contents are stored in the given file.</param>
/// <exception cref="System.ArgumentException">localFileName is an empty string (""), contains only white space, or contains one
/// or more invalid characters. -or- localFileName refers to a non-file device, such as "con:", "com1:", "lpt1:", etc. in an NTFS environment.</exception>
/// <exception cref="System.NotSupportedException">localFileName refers to a non-file device, such as "con:", "com1:", "lpt1:", etc. in a non-NTFS environment.</exception>
/// <exception cref="System.IO.FileNotFoundException">The file specified by localFileName does not exist.</exception>
/// <exception cref="System.Security.SecurityException">The caller does not have the required permission.</exception>
/// <exception cref="System.IO.DirectoryNotFoundException">The specified path is invalid, such as being on an unmapped drive.</exception>
/// <exception cref="System.UnauthorizedAccessException">The file cannot be be read, for example because it is already being accessed exclusively by another process.</exception>
/// <exception cref="System.IO.PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms,
/// paths must be less than 248 characters, and file names must be less than 260 characters.</exception>
public static UnmanagedBinaryMemoryBlock CreateUnmanagedBinaryMemoryBlock(string localFileName, IBinaryDocument binaryDocument)
{
using (FileStream stream = new FileStream(localFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
return CreateUnmanagedBinaryMemoryBlock(stream, binaryDocument);
}
}
示例13: OpenBinaryDocument
/// <summary>
/// Open the binary document as a memory block in host dependent fashion.
/// </summary>
/// <param name="sourceDocument">The binary document that is to be opened.</param>
/// <returns>The unmanaged memory block corresponding to the source document.</returns>
public virtual IBinaryDocumentMemoryBlock/*?*/ OpenBinaryDocument(IBinaryDocument sourceDocument) {
try {
#if !COMPACTFX
IBinaryDocumentMemoryBlock binDocMemoryBlock = MemoryMappedFile.CreateMemoryMappedFile(sourceDocument.Location, sourceDocument);
#else
IBinaryDocumentMemoryBlock binDocMemoryBlock = UnmanagedBinaryMemoryBlock.CreateUnmanagedBinaryMemoryBlock(sourceDocument.Location, sourceDocument);
#endif
return binDocMemoryBlock;
} catch (IOException) {
return null;
}
}
示例14: ILLocation
/// <summary>
/// Constructor for IL location
/// </summary>
/// <param name="binaryDocument"></param>
/// <param name="methodDefinition"></param>
/// <param name="offset"></param>
public ILLocation(
IBinaryDocument binaryDocument,
IMethodDefinition methodDefinition,
uint offset
)
{
this.binaryDocument = binaryDocument;
this.methodDefinition = methodDefinition;
this.offset = offset;
}
示例15: UnmanagedBinaryMemoryBlock
private UnmanagedBinaryMemoryBlock(IBinaryDocument binaryDocument)
{
this.binaryDocument = binaryDocument;
this.Pointer = Marshal.AllocHGlobal((int)binaryDocument.Length);
if (this.Pointer == IntPtr.Zero) {
throw new OutOfMemoryException();
}
}