You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.309
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
parent
ee1447783b
commit
94b2861243
115
external/cecil/Mono.Cecil.PE/Image.cs
vendored
115
external/cecil/Mono.Cecil.PE/Image.cs
vendored
@@ -1,34 +1,16 @@
|
||||
//
|
||||
// Image.cs
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2011 Jb Evain
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Mono;
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil.Metadata;
|
||||
|
||||
@@ -36,13 +18,15 @@ using RVA = System.UInt32;
|
||||
|
||||
namespace Mono.Cecil.PE {
|
||||
|
||||
sealed class Image {
|
||||
sealed class Image : IDisposable {
|
||||
|
||||
public Disposable<Stream> Stream;
|
||||
public string FileName;
|
||||
|
||||
public ModuleKind Kind;
|
||||
public TargetRuntime Runtime;
|
||||
public string RuntimeVersion;
|
||||
public TargetArchitecture Architecture;
|
||||
public ModuleCharacteristics Characteristics;
|
||||
public string FileName;
|
||||
|
||||
public Section [] Sections;
|
||||
|
||||
@@ -60,8 +44,9 @@ namespace Mono.Cecil.PE {
|
||||
public UserStringHeap UserStringHeap;
|
||||
public GuidHeap GuidHeap;
|
||||
public TableHeap TableHeap;
|
||||
public PdbHeap PdbHeap;
|
||||
|
||||
readonly int [] coded_index_sizes = new int [13];
|
||||
readonly int [] coded_index_sizes = new int [14];
|
||||
|
||||
readonly Func<Table, int> counter;
|
||||
|
||||
@@ -133,34 +118,72 @@ namespace Mono.Cecil.PE {
|
||||
return null;
|
||||
}
|
||||
|
||||
BinaryStreamReader GetReaderAt (RVA rva)
|
||||
{
|
||||
var section = GetSectionAtVirtualAddress (rva);
|
||||
if (section == null)
|
||||
return null;
|
||||
|
||||
var reader = new BinaryStreamReader (Stream.value);
|
||||
reader.MoveTo (ResolveVirtualAddressInSection (rva, section));
|
||||
return reader;
|
||||
}
|
||||
|
||||
public TRet GetReaderAt<TItem, TRet> (RVA rva, TItem item, Func<TItem, BinaryStreamReader, TRet> read) where TRet : class
|
||||
{
|
||||
var position = Stream.value.Position;
|
||||
try {
|
||||
var reader = GetReaderAt (rva);
|
||||
if (reader == null)
|
||||
return null;
|
||||
|
||||
return read (item, reader);
|
||||
} finally {
|
||||
Stream.value.Position = position;
|
||||
}
|
||||
}
|
||||
|
||||
public ImageDebugDirectory GetDebugHeader (out byte [] header)
|
||||
{
|
||||
var section = GetSectionAtVirtualAddress (Debug.VirtualAddress);
|
||||
var buffer = new ByteBuffer (section.Data);
|
||||
buffer.position = (int) (Debug.VirtualAddress - section.VirtualAddress);
|
||||
|
||||
var directory = new ImageDebugDirectory {
|
||||
Characteristics = buffer.ReadInt32 (),
|
||||
TimeDateStamp = buffer.ReadInt32 (),
|
||||
MajorVersion = buffer.ReadInt16 (),
|
||||
MinorVersion = buffer.ReadInt16 (),
|
||||
Type = buffer.ReadInt32 (),
|
||||
SizeOfData = buffer.ReadInt32 (),
|
||||
AddressOfRawData = buffer.ReadInt32 (),
|
||||
PointerToRawData = buffer.ReadInt32 (),
|
||||
};
|
||||
|
||||
if (directory.SizeOfData == 0 || directory.PointerToRawData == 0) {
|
||||
var reader = GetReaderAt (Debug.VirtualAddress);
|
||||
if (reader == null) {
|
||||
header = Empty<byte>.Array;
|
||||
return directory;
|
||||
return new ImageDebugDirectory ();
|
||||
}
|
||||
|
||||
buffer.position = (int) (directory.PointerToRawData - section.PointerToRawData);
|
||||
var directory = new ImageDebugDirectory {
|
||||
Characteristics = reader.ReadInt32 (),
|
||||
TimeDateStamp = reader.ReadInt32 (),
|
||||
MajorVersion = reader.ReadInt16 (),
|
||||
MinorVersion = reader.ReadInt16 (),
|
||||
Type = reader.ReadInt32 (),
|
||||
SizeOfData = reader.ReadInt32 (),
|
||||
AddressOfRawData = reader.ReadInt32 (),
|
||||
PointerToRawData = reader.ReadInt32 (),
|
||||
};
|
||||
|
||||
header = new byte [directory.SizeOfData];
|
||||
Buffer.BlockCopy (buffer.buffer, buffer.position, header, 0, header.Length);
|
||||
reader = GetReaderAt ((uint) directory.AddressOfRawData);
|
||||
header = reader != null
|
||||
? reader.ReadBytes (directory.SizeOfData)
|
||||
: Empty<byte>.Array;
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
public bool HasDebugTables ()
|
||||
{
|
||||
return HasTable (Table.Document)
|
||||
|| HasTable (Table.MethodDebugInformation)
|
||||
|| HasTable (Table.LocalScope)
|
||||
|| HasTable (Table.LocalVariable)
|
||||
|| HasTable (Table.LocalConstant)
|
||||
|| HasTable (Table.StateMachineMethod)
|
||||
|| HasTable (Table.CustomDebugInformation);
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
Stream.Dispose ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user