Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -1,59 +1,54 @@
//
// BlobHeap.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 Mono.Cecil.PE;
namespace Mono.Cecil.Metadata {
sealed class BlobHeap : Heap {
public BlobHeap (Section section, uint start, uint size)
: base (section, start, size)
public BlobHeap (byte [] data)
: base (data)
{
}
public byte [] Read (uint index)
{
if (index == 0 || index > Size - 1)
if (index == 0 || index > this.data.Length - 1)
return Empty<byte>.Array;
var data = Section.Data;
int position = (int) (index + Offset);
int position = (int) index;
int length = (int) data.ReadCompressedUInt32 (ref position);
if (length > data.Length - position)
return Empty<byte>.Array;
var buffer = new byte [length];
Buffer.BlockCopy (data, position, buffer, 0, length);
return buffer;
}
public void GetView (uint signature, out byte [] buffer, out int index, out int length)
{
if (signature == 0 || signature > data.Length - 1) {
buffer = null;
index = length = 0;
return;
}
buffer = data;
index = (int) signature;
length = (int) buffer.ReadCompressedUInt32 (ref index);
}
}
}

View File

@@ -1,29 +1,11 @@
//
// TableHeapBuffer.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;
@@ -43,11 +25,13 @@ namespace Mono.Cecil.Metadata {
readonly ModuleDefinition module;
readonly MetadataBuilder metadata;
internal MetadataTable [] tables = new MetadataTable [45];
internal MetadataTable [] tables = new MetadataTable [Mixin.TableCount];
bool large_string;
bool large_blob;
readonly int [] coded_index_sizes = new int [13];
bool large_guid;
readonly int [] coded_index_sizes = new int [Mixin.CodedIndexCount];
readonly Func<Table, int> counter;
public override bool IsEmpty {
@@ -105,6 +89,11 @@ namespace Mono.Cecil.Metadata {
WriteBySize (blob, large_blob);
}
public void WriteGuid (uint guid)
{
WriteBySize (guid, large_guid);
}
public void WriteRID (uint rid, Table table)
{
var md_table = tables [(int) table];
@@ -134,7 +123,7 @@ namespace Mono.Cecil.Metadata {
WriteByte (GetHeapSizes ()); // HeapSizes
WriteByte (10); // Reserved2
WriteUInt64 (GetValid ()); // Valid
WriteUInt64 (0x0016003301fa00); // Sorted
WriteUInt64 (0xc416003301fa00); // Sorted
WriteRowCount ();
WriteTables ();
@@ -187,6 +176,11 @@ namespace Mono.Cecil.Metadata {
heap_sizes |= 0x01;
}
if (metadata.guid_heap.IsLarge) {
large_guid = true;
heap_sizes |= 0x02;
}
if (metadata.blob_heap.IsLarge) {
large_blob = true;
heap_sizes |= 0x04;
@@ -272,6 +266,37 @@ namespace Mono.Cecil.Metadata {
}
}
sealed class GuidHeapBuffer : HeapBuffer {
readonly Dictionary<Guid, uint> guids = new Dictionary<Guid, uint> ();
public override bool IsEmpty {
get { return length == 0; }
}
public GuidHeapBuffer ()
: base (16)
{
}
public uint GetGuidIndex (Guid guid)
{
uint index;
if (guids.TryGetValue (guid, out index))
return index;
index = (uint) guids.Count + 1;
WriteGuid (guid);
guids.Add (guid, index);
return index;
}
void WriteGuid (Guid guid)
{
WriteBytes (guid.ToByteArray ());
}
}
class StringHeapBuffer : HeapBuffer {
readonly Dictionary<string, uint> strings = new Dictionary<string, uint> (StringComparer.Ordinal);
@@ -368,6 +393,18 @@ namespace Mono.Cecil.Metadata {
WriteByte (special);
}
}
sealed class PdbHeapBuffer : HeapBuffer {
public override bool IsEmpty {
get { return false; }
}
public PdbHeapBuffer ()
: base (0)
{
}
}
}
#endif

View File

@@ -1,29 +1,11 @@
//
// CodedIndex.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.
//
namespace Mono.Cecil.Metadata {
@@ -41,6 +23,7 @@ namespace Mono.Cecil.Metadata {
Implementation,
CustomAttributeType,
ResolutionScope,
TypeOrMethodDef
TypeOrMethodDef,
HasCustomDebugInformation,
}
}

View File

@@ -1,29 +1,11 @@
//
// ElementType.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.
//
namespace Mono.Cecil.Metadata {

View File

@@ -1,59 +1,36 @@
//
// GuidHeap.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 Mono.Cecil.PE;
namespace Mono.Cecil.Metadata {
sealed class GuidHeap : Heap {
public GuidHeap (Section section, uint start, uint size)
: base (section, start, size)
public GuidHeap (byte [] data)
: base (data)
{
}
public Guid Read (uint index)
{
if (index == 0)
return new Guid ();
const int guid_size = 16;
if (index == 0 || ((index - 1) + guid_size) > data.Length)
return new Guid ();
var buffer = new byte [guid_size];
index--;
Buffer.BlockCopy (Section.Data, (int) (Offset + index), buffer, 0, guid_size);
Buffer.BlockCopy (this.data, (int) ((index - 1) * guid_size), buffer, 0, guid_size);
return new Guid (buffer);
}
}
}

View File

@@ -1,32 +1,12 @@
//
// Heap.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:
// Licensed under the MIT/X11 license.
//
// 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.
//
using Mono.Cecil.PE;
namespace Mono.Cecil.Metadata {
@@ -34,15 +14,11 @@ namespace Mono.Cecil.Metadata {
public int IndexSize;
public readonly Section Section;
public readonly uint Offset;
public readonly uint Size;
internal byte [] data;
protected Heap (Section section, uint offset, uint size)
protected Heap (byte [] data)
{
this.Section = section;
this.Offset = offset;
this.Size = size;
this.data = data;
}
}
}

View File

@@ -1,34 +1,18 @@
//
// MetadataToken.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;
namespace Mono.Cecil {
public struct MetadataToken {
public struct MetadataToken : IEquatable<MetadataToken> {
readonly uint token;
@@ -77,6 +61,11 @@ namespace Mono.Cecil {
return (int) token;
}
public bool Equals (MetadataToken other)
{
return other.token == token;
}
public override bool Equals (object obj)
{
if (obj is MetadataToken) {

View File

@@ -0,0 +1,34 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using Mono.Cecil.PE;
using RID = System.UInt32;
namespace Mono.Cecil.Metadata {
sealed class PdbHeap : Heap {
public byte [] Id;
public RID EntryPoint;
public long TypeSystemTables;
public uint [] TypeSystemTableRows;
public PdbHeap (byte [] data)
: base (data)
{
}
public bool HasTable (Table table)
{
return (TypeSystemTables & (1L << (int) table)) != 0;
}
}
}

View File

@@ -1,29 +1,11 @@
//
// Row.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.Collections.Generic;

View File

@@ -1,45 +1,25 @@
//
// StringHeap.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.Collections.Generic;
using System.Text;
using Mono.Cecil.PE;
namespace Mono.Cecil.Metadata {
class StringHeap : Heap {
readonly Dictionary<uint, string> strings = new Dictionary<uint, string> ();
public StringHeap (Section section, uint start, uint size)
: base (section, start, size)
public StringHeap (byte [] data)
: base (data)
{
}
@@ -52,7 +32,7 @@ namespace Mono.Cecil.Metadata {
if (strings.TryGetValue (index, out @string))
return @string;
if (index > Size - 1)
if (index > data.Length - 1)
return string.Empty;
@string = ReadStringAt (index);
@@ -65,8 +45,7 @@ namespace Mono.Cecil.Metadata {
protected virtual string ReadStringAt (uint index)
{
int length = 0;
byte [] data = Section.Data;
int start = (int) (index + Offset);
int start = (int) index;
for (int i = start; ; i++) {
if (data [i] == 0)

View File

@@ -1,29 +1,11 @@
//
// TableHeap.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;
@@ -77,6 +59,15 @@ namespace Mono.Cecil.Metadata {
GenericParam = 0x2a,
MethodSpec = 0x2b,
GenericParamConstraint = 0x2c,
Document = 0x30,
MethodDebugInformation = 0x31,
LocalScope = 0x32,
LocalVariable = 0x33,
LocalConstant = 0x34,
ImportScope = 0x35,
StateMachineMethod = 0x36,
CustomDebugInformation = 0x37,
}
struct TableInformation {
@@ -90,16 +81,14 @@ namespace Mono.Cecil.Metadata {
public long Valid;
public long Sorted;
public const int TableCount = 45;
public readonly TableInformation [] Tables = new TableInformation [TableCount];
public readonly TableInformation [] Tables = new TableInformation [Mixin.TableCount];
public TableInformation this [Table table] {
get { return Tables [(int) table]; }
}
public TableHeap (Section section, uint start, uint size)
: base (section, start, size)
public TableHeap (byte [] data)
: base (data)
{
}

View File

@@ -1,29 +1,11 @@
//
// TokenType.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.
//
namespace Mono.Cecil {
@@ -51,6 +33,17 @@ namespace Mono.Cecil {
ManifestResource = 0x28000000,
GenericParam = 0x2a000000,
MethodSpec = 0x2b000000,
GenericParamConstraint = 0x2c000000,
Document = 0x30000000,
MethodDebugInformation = 0x31000000,
LocalScope = 0x32000000,
LocalVariable = 0x33000000,
LocalConstant = 0x34000000,
ImportScope = 0x35000000,
StateMachineMethod = 0x36000000,
CustomDebugInformation = 0x37000000,
String = 0x70000000,
}
}

View File

@@ -1,48 +1,25 @@
//
// UserStringHeap.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:
// Licensed under the MIT/X11 license.
//
// 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.
//
using System;
using Mono.Cecil.PE;
namespace Mono.Cecil.Metadata {
sealed class UserStringHeap : StringHeap {
public UserStringHeap (Section section, uint start, uint size)
: base (section, start, size)
public UserStringHeap (byte [] data)
: base (data)
{
}
protected override string ReadStringAt (uint index)
{
byte [] data = Section.Data;
int start = (int) (index + Offset);
int start = (int) index;
uint length = (uint) (data.ReadCompressedUInt32 (ref start) & ~1);
if (length < 1)

View File

@@ -1,29 +1,11 @@
//
// Utilities.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;
@@ -34,6 +16,9 @@ namespace Mono.Cecil {
static partial class Mixin {
public const int TableCount = 58;
public const int CodedIndexCount = 14;
public static uint ReadCompressedUInt32 (this byte [] data, ref int position)
{
uint integer;
@@ -126,6 +111,10 @@ namespace Mono.Cecil {
token_type = TokenType.ManifestResource; goto ret;
case 19:
token_type = TokenType.GenericParam; goto ret;
case 20:
token_type = TokenType.GenericParamConstraint; goto ret;
case 21:
token_type = TokenType.MethodSpec; goto ret;
default:
goto exit;
}
@@ -242,6 +231,66 @@ namespace Mono.Cecil {
token_type = TokenType.Method; goto ret;
default: goto exit;
}
case CodedIndex.HasCustomDebugInformation:
rid = data >> 5;
switch (data & 31) {
case 0:
token_type = TokenType.Method; goto ret;
case 1:
token_type = TokenType.Field; goto ret;
case 2:
token_type = TokenType.TypeRef; goto ret;
case 3:
token_type = TokenType.TypeDef; goto ret;
case 4:
token_type = TokenType.Param; goto ret;
case 5:
token_type = TokenType.InterfaceImpl; goto ret;
case 6:
token_type = TokenType.MemberRef; goto ret;
case 7:
token_type = TokenType.Module; goto ret;
case 8:
token_type = TokenType.Permission; goto ret;
case 9:
token_type = TokenType.Property; goto ret;
case 10:
token_type = TokenType.Event; goto ret;
case 11:
token_type = TokenType.Signature; goto ret;
case 12:
token_type = TokenType.ModuleRef; goto ret;
case 13:
token_type = TokenType.TypeSpec; goto ret;
case 14:
token_type = TokenType.Assembly; goto ret;
case 15:
token_type = TokenType.AssemblyRef; goto ret;
case 16:
token_type = TokenType.File; goto ret;
case 17:
token_type = TokenType.ExportedType; goto ret;
case 18:
token_type = TokenType.ManifestResource; goto ret;
case 19:
token_type = TokenType.GenericParam; goto ret;
case 20:
token_type = TokenType.GenericParamConstraint; goto ret;
case 21:
token_type = TokenType.MethodSpec; goto ret;
case 22:
token_type = TokenType.Document; goto ret;
case 23:
token_type = TokenType.LocalScope; goto ret;
case 24:
token_type = TokenType.LocalVariable; goto ret;
case 25:
token_type = TokenType.LocalConstant; goto ret;
case 26:
token_type = TokenType.ImportScope; goto ret;
default:
goto exit;
}
default:
goto exit;
}
@@ -325,6 +374,10 @@ namespace Mono.Cecil {
return ret | 18;
case TokenType.GenericParam:
return ret | 19;
case TokenType.GenericParamConstraint:
return ret | 20;
case TokenType.MethodSpec:
return ret | 21;
default:
goto exit;
}
@@ -442,6 +495,66 @@ namespace Mono.Cecil {
default:
goto exit;
}
case CodedIndex.HasCustomDebugInformation:
ret = token.RID << 5;
switch (token.TokenType) {
case TokenType.Method:
return ret | 0;
case TokenType.Field:
return ret | 1;
case TokenType.TypeRef:
return ret | 2;
case TokenType.TypeDef:
return ret | 3;
case TokenType.Param:
return ret | 4;
case TokenType.InterfaceImpl:
return ret | 5;
case TokenType.MemberRef:
return ret | 6;
case TokenType.Module:
return ret | 7;
case TokenType.Permission:
return ret | 8;
case TokenType.Property:
return ret | 9;
case TokenType.Event:
return ret | 10;
case TokenType.Signature:
return ret | 11;
case TokenType.ModuleRef:
return ret | 12;
case TokenType.TypeSpec:
return ret | 13;
case TokenType.Assembly:
return ret | 14;
case TokenType.AssemblyRef:
return ret | 15;
case TokenType.File:
return ret | 16;
case TokenType.ExportedType:
return ret | 17;
case TokenType.ManifestResource:
return ret | 18;
case TokenType.GenericParam:
return ret | 19;
case TokenType.GenericParamConstraint:
return ret | 20;
case TokenType.MethodSpec:
return ret | 21;
case TokenType.Document:
return ret | 22;
case TokenType.LocalScope:
return ret | 23;
case TokenType.LocalVariable:
return ret | 24;
case TokenType.LocalConstant:
return ret | 25;
case TokenType.ImportScope:
return ret | 26;
default:
goto exit;
}
default:
goto exit;
}
@@ -470,7 +583,7 @@ namespace Mono.Cecil {
Table.Method, Table.Field, Table.TypeRef, Table.TypeDef, Table.Param, Table.InterfaceImpl, Table.MemberRef,
Table.Module, Table.DeclSecurity, Table.Property, Table.Event, Table.StandAloneSig, Table.ModuleRef,
Table.TypeSpec, Table.Assembly, Table.AssemblyRef, Table.File, Table.ExportedType,
Table.ManifestResource, Table.GenericParam
Table.ManifestResource, Table.GenericParam, Table.GenericParamConstraint, Table.MethodSpec,
};
break;
case CodedIndex.HasFieldMarshal:
@@ -513,6 +626,16 @@ namespace Mono.Cecil {
bits = 1;
tables = new [] { Table.TypeDef, Table.Method };
break;
case CodedIndex.HasCustomDebugInformation:
bits = 5;
tables = new[] {
Table.Method, Table.Field, Table.TypeRef, Table.TypeDef, Table.Param, Table.InterfaceImpl, Table.MemberRef,
Table.Module, Table.DeclSecurity, Table.Property, Table.Event, Table.StandAloneSig, Table.ModuleRef,
Table.TypeSpec, Table.Assembly, Table.AssemblyRef, Table.File, Table.ExportedType,
Table.ManifestResource, Table.GenericParam, Table.GenericParamConstraint, Table.MethodSpec,
Table.Document, Table.LocalScope, Table.LocalVariable, Table.LocalConstant, Table.ImportScope,
};
break;
default:
throw new ArgumentException ();
}