本文整理汇总了C#中IPEImage类的典型用法代码示例。如果您正苦于以下问题:C# IPEImage类的具体用法?C# IPEImage怎么用?C# IPEImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPEImage类属于命名空间,在下文中一共展示了IPEImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static ImageCor20HeaderTreeNode Create(HexDocument doc, IPEImage peImage)
{
var dnDir = peImage.ImageNTHeaders.OptionalHeader.DataDirectories[14];
if (dnDir.VirtualAddress != 0 && dnDir.Size >= 0x48)
return new ImageCor20HeaderTreeNode(doc, (ulong)peImage.ToFileOffset(dnDir.VirtualAddress));
return null;
}
示例2: GetOrCreate
public AsmEdHexDocument GetOrCreate(IPEImage peImage) {
var filename = GetFullPath(peImage.FileName);
lock (lockObj) {
var doc = TryGet_NoLock(filename);
if (doc != null)
return doc;
using (var stream = peImage.CreateFullStream()) {
var data = stream.ReadAllBytes();
doc = new AsmEdHexDocument(data, filename);
filenameToDoc[filename] = new WeakReference(doc);
return doc;
}
}
}
示例3: Win32ResourcesPE
/// <summary>
/// Constructor
/// </summary>
/// <param name="peImage">The PE image</param>
/// <param name="rsrcReader">Reader for the whole Win32 resources section (usually
/// the .rsrc section) or <c>null</c> if we should create one from the resource data
/// directory in the optional header. This instance owns the reader.</param>
public Win32ResourcesPE(IPEImage peImage, IBinaryReader rsrcReader) {
this.rvaConverter = peImage;
this.dataReader = peImage.CreateFullStream();
if (rsrcReader != null)
this.rsrcReader = rsrcReader;
else {
var dataDir = peImage.ImageNTHeaders.OptionalHeader.DataDirectories[2];
if (dataDir.VirtualAddress != 0 && dataDir.Size != 0)
this.rsrcReader = peImage.CreateStream(dataDir.VirtualAddress, dataDir.Size);
else
this.rsrcReader = MemoryImageStream.CreateEmpty();
}
Initialize();
}
示例4: Load
/// <summary>
/// Create a <see cref="DotNetFile"/> instance
/// </summary>
/// <param name="peImage">The PE image</param>
/// <param name="verify"><c>true</c> if we should verify that it's a .NET PE file</param>
/// <returns>A new <see cref="DotNetFile"/> instance</returns>
public static DotNetFile Load(IPEImage peImage, bool verify) {
IImageStream cor20HeaderStream = null, mdHeaderStream = null;
MetaData md = null;
try {
var dotNetDir = peImage.ImageNTHeaders.OptionalHeader.DataDirectories[14];
if (dotNetDir.VirtualAddress == 0)
throw new BadImageFormatException(".NET data directory RVA is 0");
if (dotNetDir.Size < 0x48)
throw new BadImageFormatException(".NET data directory size < 0x48");
var cor20Header = new ImageCor20Header(cor20HeaderStream = peImage.CreateStream(dotNetDir.VirtualAddress, 0x48), verify);
if (cor20Header.MetaData.VirtualAddress == 0)
throw new BadImageFormatException(".NET MetaData RVA is 0");
if (cor20Header.MetaData.Size < 16)
throw new BadImageFormatException(".NET MetaData size is too small");
var mdSize = cor20Header.MetaData.Size;
var mdRva = cor20Header.MetaData.VirtualAddress;
var mdHeader = new MetaDataHeader(mdHeaderStream = peImage.CreateStream(mdRva, mdSize), verify);
if (verify) {
foreach (var sh in mdHeader.StreamHeaders) {
if (sh.Offset + sh.StreamSize < sh.Offset || sh.Offset + sh.StreamSize > mdSize)
throw new BadImageFormatException("Invalid stream header");
}
}
switch (GetMetaDataType(mdHeader.StreamHeaders)) {
case MetaDataType.Compressed:
md = new CompressedMetaData(peImage, cor20Header, mdHeader);
break;
case MetaDataType.ENC:
md = new ENCMetaData(peImage, cor20Header, mdHeader);
break;
default:
throw new BadImageFormatException("No #~ or #- stream found");
}
md.Initialize();
return new DotNetFile(md);
}
catch {
if (md != null)
md.Dispose();
throw;
}
finally {
if (cor20HeaderStream != null)
cor20HeaderStream.Dispose();
if (mdHeaderStream != null)
mdHeaderStream.Dispose();
}
}
示例5: DisableMemoryMappedIO
static void DisableMemoryMappedIO(HashSet<string> filenames, IPEImage peImage) {
if (peImage != null && filenames.Contains(peImage.FileName))
peImage.UnsafeDisableMemoryMappedIO();
}
示例6: UnpackNativeFile1
// Old CS versions
byte[] UnpackNativeFile1(IPEImage peImage) {
const int dataDirNum = 6; // debug dir
const int dotNetDirNum = 14;
var optHeader = peImage.ImageNTHeaders.OptionalHeader;
if (optHeader.DataDirectories[dataDirNum].VirtualAddress == 0)
return null;
if (optHeader.DataDirectories[dataDirNum].Size != 0x48)
return null;
var fileData = peImage.GetImageAsByteArray();
long dataDirBaseOffset = (long)optHeader.DataDirectories[0].StartOffset;
int dataDir = (int)dataDirBaseOffset + dataDirNum * 8;
int dotNetDir = (int)dataDirBaseOffset + dotNetDirNum * 8;
WriteUInt32(fileData, dotNetDir, BitConverter.ToUInt32(fileData, dataDir));
WriteUInt32(fileData, dotNetDir + 4, BitConverter.ToUInt32(fileData, dataDir + 4));
WriteUInt32(fileData, dataDir, 0);
WriteUInt32(fileData, dataDir + 4, 0);
ModuleBytes = fileData;
return fileData;
}
示例7: Load
/// <summary>
/// Creates a <see cref="ModuleDefMD"/> instance
/// </summary>
/// <param name="peImage">PE image</param>
/// <param name="options">Module creation options or <c>null</c></param>
/// <returns>A new <see cref="ModuleDefMD"/> instance</returns>
public static ModuleDefMD Load(IPEImage peImage, ModuleCreationOptions options)
{
return Load(MetaDataCreator.Load(peImage), options);
}
示例8: MyPEImage
public MyPEImage(IPEImage peImage) {
Initialize(peImage);
}
示例9: CompressedMetaData
/// <inheritdoc/>
public CompressedMetaData(IPEImage peImage, ImageCor20Header cor20Header, MetaDataHeader mdHeader)
: base(peImage, cor20Header, mdHeader) {
}
示例10: UnpackNativeFile
public override byte[] UnpackNativeFile(IPEImage peImage) {
var data = new NativeImageUnpacker(peImage).Unpack();
if (data == null)
return null;
unpackedNativeFile = true;
ModuleBytes = data;
return data;
}
示例11: MetaData
/// <summary>
/// Constructor
/// </summary>
/// <param name="peImage">The PE image</param>
/// <param name="cor20Header">The .NET header</param>
/// <param name="mdHeader">The MD header</param>
protected MetaData(IPEImage peImage, ImageCor20Header cor20Header, MetaDataHeader mdHeader)
{
try {
this.allStreams = ThreadSafeListCreator.Create<DotNetStream>();
this.peImage = peImage;
this.cor20Header = cor20Header;
this.mdHeader = mdHeader;
}
catch {
if (peImage != null)
peImage.Dispose();
throw;
}
}
示例12: IsExe
static bool IsExe(IPEImage peImage)
{
return peImage != null && (peImage.ImageNTHeaders.FileHeader.Characteristics & Characteristics.Dll) == 0;
}
示例13: PECLIModel
public PECLIModel(IPEImage image, ImageCor20Header header) {
Image = image;
CLIHeader = header;
}
示例14: Initialize
void Initialize(IPEImage peImage) {
this.peImage = peImage;
this.peStream = peImage.CreateFullStream();
}
示例15: InitializeExeFieldsFrom
void InitializeExeFieldsFrom(IPEImage peImage) {
isExe = (peImage.ImageNTHeaders.FileHeader.Characteristics & Characteristics.Dll) == 0;
timestamp = peImage.ImageNTHeaders.FileHeader.TimeDateStamp;
using (var mod = ModuleDefMD.Load(peImage)) {
var asm = mod.Assembly;
version = asm == null ? null : asm.Version;
}
}