Add StickGame Assets
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// 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 System;
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
sealed class BlobHeap : Heap {
|
||||
|
||||
public BlobHeap (byte [] data)
|
||||
: base (data)
|
||||
{
|
||||
}
|
||||
|
||||
public byte [] Read (uint index)
|
||||
{
|
||||
if (index == 0 || index > this.data.Length - 1)
|
||||
return Empty<byte>.Array;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33eef67f4a74e1c40a6bdb3da9d22d00
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,499 @@
|
||||
//
|
||||
// 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 MonoFN.Cecil.PE;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using RVA = System.UInt32;
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
sealed class TableHeapBuffer : HeapBuffer {
|
||||
|
||||
readonly ModuleDefinition module;
|
||||
readonly MetadataBuilder metadata;
|
||||
|
||||
readonly internal TableInformation [] table_infos = new TableInformation [Mixin.TableCount];
|
||||
readonly internal MetadataTable [] tables = new MetadataTable [Mixin.TableCount];
|
||||
|
||||
bool large_string;
|
||||
bool large_blob;
|
||||
bool large_guid;
|
||||
|
||||
readonly int [] coded_index_sizes = new int [Mixin.CodedIndexCount];
|
||||
readonly Func<Table, int> counter;
|
||||
|
||||
internal uint [] string_offsets;
|
||||
|
||||
public override bool IsEmpty {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public TableHeapBuffer (ModuleDefinition module, MetadataBuilder metadata)
|
||||
: base (24)
|
||||
{
|
||||
this.module = module;
|
||||
this.metadata = metadata;
|
||||
this.counter = GetTableLength;
|
||||
}
|
||||
|
||||
int GetTableLength (Table table)
|
||||
{
|
||||
return (int)table_infos [(int)table].Length;
|
||||
}
|
||||
|
||||
public TTable GetTable<TTable> (Table table) where TTable : MetadataTable, new()
|
||||
{
|
||||
var md_table = (TTable)tables [(int)table];
|
||||
if (md_table != null)
|
||||
return md_table;
|
||||
|
||||
md_table = new TTable ();
|
||||
tables [(int)table] = md_table;
|
||||
return md_table;
|
||||
}
|
||||
|
||||
public void WriteBySize (uint value, int size)
|
||||
{
|
||||
if (size == 4)
|
||||
WriteUInt32 (value);
|
||||
else
|
||||
WriteUInt16 ((ushort)value);
|
||||
}
|
||||
|
||||
public void WriteBySize (uint value, bool large)
|
||||
{
|
||||
if (large)
|
||||
WriteUInt32 (value);
|
||||
else
|
||||
WriteUInt16 ((ushort)value);
|
||||
}
|
||||
|
||||
public void WriteString (uint @string)
|
||||
{
|
||||
WriteBySize (string_offsets [@string], large_string);
|
||||
}
|
||||
|
||||
public void WriteBlob (uint blob)
|
||||
{
|
||||
WriteBySize (blob, large_blob);
|
||||
}
|
||||
|
||||
public void WriteGuid (uint guid)
|
||||
{
|
||||
WriteBySize (guid, large_guid);
|
||||
}
|
||||
|
||||
public void WriteRID (uint rid, Table table)
|
||||
{
|
||||
WriteBySize (rid, table_infos [(int)table].IsLarge);
|
||||
}
|
||||
|
||||
int GetCodedIndexSize (CodedIndex coded_index)
|
||||
{
|
||||
var index = (int)coded_index;
|
||||
var size = coded_index_sizes [index];
|
||||
if (size != 0)
|
||||
return size;
|
||||
|
||||
return coded_index_sizes [index] = coded_index.GetSize (counter);
|
||||
}
|
||||
|
||||
public void WriteCodedRID (uint rid, CodedIndex coded_index)
|
||||
{
|
||||
WriteBySize (rid, GetCodedIndexSize (coded_index));
|
||||
}
|
||||
|
||||
public void WriteTableHeap ()
|
||||
{
|
||||
WriteUInt32 (0); // Reserved
|
||||
WriteByte (GetTableHeapVersion ()); // MajorVersion
|
||||
WriteByte (0); // MinorVersion
|
||||
WriteByte (GetHeapSizes ()); // HeapSizes
|
||||
WriteByte (10); // Reserved2
|
||||
WriteUInt64 (GetValid ()); // Valid
|
||||
WriteUInt64 (0xc416003301fa00); // Sorted
|
||||
|
||||
WriteRowCount ();
|
||||
WriteTables ();
|
||||
}
|
||||
|
||||
void WriteRowCount ()
|
||||
{
|
||||
for (int i = 0; i < tables.Length; i++) {
|
||||
var table = tables [i];
|
||||
if (table == null || table.Length == 0)
|
||||
continue;
|
||||
|
||||
WriteUInt32 ((uint)table.Length);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteTables ()
|
||||
{
|
||||
for (int i = 0; i < tables.Length; i++) {
|
||||
var table = tables [i];
|
||||
if (table == null || table.Length == 0)
|
||||
continue;
|
||||
|
||||
table.Write (this);
|
||||
}
|
||||
}
|
||||
|
||||
ulong GetValid ()
|
||||
{
|
||||
ulong valid = 0;
|
||||
|
||||
for (int i = 0; i < tables.Length; i++) {
|
||||
var table = tables [i];
|
||||
if (table == null || table.Length == 0)
|
||||
continue;
|
||||
|
||||
table.Sort ();
|
||||
valid |= (1UL << i);
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void ComputeTableInformations ()
|
||||
{
|
||||
if (metadata.metadata_builder != null)
|
||||
ComputeTableInformations (metadata.metadata_builder.table_heap);
|
||||
|
||||
ComputeTableInformations (metadata.table_heap);
|
||||
}
|
||||
|
||||
void ComputeTableInformations (TableHeapBuffer table_heap)
|
||||
{
|
||||
var tables = table_heap.tables;
|
||||
for (int i = 0; i < tables.Length; i++) {
|
||||
var table = tables [i];
|
||||
if (table != null && table.Length > 0)
|
||||
table_infos [i].Length = (uint)table.Length;
|
||||
}
|
||||
}
|
||||
|
||||
byte GetHeapSizes ()
|
||||
{
|
||||
byte heap_sizes = 0;
|
||||
|
||||
if (metadata.string_heap.IsLarge) {
|
||||
large_string = true;
|
||||
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;
|
||||
}
|
||||
|
||||
return heap_sizes;
|
||||
}
|
||||
|
||||
byte GetTableHeapVersion ()
|
||||
{
|
||||
switch (module.Runtime) {
|
||||
case TargetRuntime.Net_1_0:
|
||||
case TargetRuntime.Net_1_1:
|
||||
return 1;
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
public void FixupData (RVA data_rva)
|
||||
{
|
||||
var table = GetTable<FieldRVATable> (Table.FieldRVA);
|
||||
if (table.length == 0)
|
||||
return;
|
||||
|
||||
var field_idx_size = GetTable<FieldTable> (Table.Field).IsLarge ? 4 : 2;
|
||||
var previous = this.position;
|
||||
|
||||
base.position = table.position;
|
||||
for (int i = 0; i < table.length; i++) {
|
||||
var rva = ReadUInt32 ();
|
||||
base.position -= 4;
|
||||
WriteUInt32 (rva + data_rva);
|
||||
base.position += field_idx_size;
|
||||
}
|
||||
|
||||
base.position = previous;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ResourceBuffer : ByteBuffer {
|
||||
|
||||
public ResourceBuffer ()
|
||||
: base (0)
|
||||
{
|
||||
}
|
||||
|
||||
public uint AddResource (byte [] resource)
|
||||
{
|
||||
var offset = (uint)this.position;
|
||||
WriteInt32 (resource.Length);
|
||||
WriteBytes (resource);
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class DataBuffer : ByteBuffer {
|
||||
|
||||
public DataBuffer ()
|
||||
: base (0)
|
||||
{
|
||||
}
|
||||
|
||||
public RVA AddData (byte [] data)
|
||||
{
|
||||
var rva = (RVA)position;
|
||||
WriteBytes (data);
|
||||
return rva;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class HeapBuffer : ByteBuffer {
|
||||
|
||||
public bool IsLarge {
|
||||
get { return base.length > 65535; }
|
||||
}
|
||||
|
||||
public abstract bool IsEmpty { get; }
|
||||
|
||||
protected HeapBuffer (int length)
|
||||
: base (length)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
protected Dictionary<string, uint> strings = new Dictionary<string, uint> (StringComparer.Ordinal);
|
||||
|
||||
public sealed override bool IsEmpty {
|
||||
get { return length <= 1; }
|
||||
}
|
||||
|
||||
public StringHeapBuffer ()
|
||||
: base (1)
|
||||
{
|
||||
WriteByte (0);
|
||||
}
|
||||
|
||||
public virtual uint GetStringIndex (string @string)
|
||||
{
|
||||
uint index;
|
||||
if (strings.TryGetValue (@string, out index))
|
||||
return index;
|
||||
|
||||
index = (uint)strings.Count + 1;
|
||||
strings.Add (@string, index);
|
||||
return index;
|
||||
}
|
||||
|
||||
public uint [] WriteStrings ()
|
||||
{
|
||||
var sorted = SortStrings (strings);
|
||||
strings = null;
|
||||
|
||||
// Add 1 for empty string whose index and offset are both 0
|
||||
var string_offsets = new uint [sorted.Count + 1];
|
||||
string_offsets [0] = 0;
|
||||
|
||||
// Find strings that can be folded
|
||||
var previous = string.Empty;
|
||||
foreach (var entry in sorted) {
|
||||
var @string = entry.Key;
|
||||
var index = entry.Value;
|
||||
var position = base.position;
|
||||
|
||||
if (previous.EndsWith (@string, StringComparison.Ordinal) && !IsLowSurrogateChar (entry.Key [0])) {
|
||||
// Map over the tail of prev string. Watch for null-terminator of prev string.
|
||||
string_offsets [index] = (uint)(position - (Encoding.UTF8.GetByteCount (entry.Key) + 1));
|
||||
} else {
|
||||
string_offsets [index] = (uint)position;
|
||||
WriteString (@string);
|
||||
}
|
||||
|
||||
previous = entry.Key;
|
||||
}
|
||||
|
||||
return string_offsets;
|
||||
}
|
||||
|
||||
static List<KeyValuePair<string, uint>> SortStrings (Dictionary<string, uint> strings)
|
||||
{
|
||||
var sorted = new List<KeyValuePair<string, uint>> (strings);
|
||||
sorted.Sort (new SuffixSort ());
|
||||
return sorted;
|
||||
}
|
||||
|
||||
static bool IsLowSurrogateChar (int c)
|
||||
{
|
||||
return unchecked((uint)(c - 0xDC00)) <= 0xDFFF - 0xDC00;
|
||||
}
|
||||
|
||||
protected virtual void WriteString (string @string)
|
||||
{
|
||||
WriteBytes (Encoding.UTF8.GetBytes (@string));
|
||||
WriteByte (0);
|
||||
}
|
||||
|
||||
// Sorts strings such that a string is followed immediately by all strings
|
||||
// that are a suffix of it.
|
||||
private class SuffixSort : IComparer<KeyValuePair<string, uint>> {
|
||||
|
||||
public int Compare (KeyValuePair<string, uint> xPair, KeyValuePair<string, uint> yPair)
|
||||
{
|
||||
var x = xPair.Key;
|
||||
var y = yPair.Key;
|
||||
|
||||
for (int i = x.Length - 1, j = y.Length - 1; i >= 0 & j >= 0; i--, j--) {
|
||||
if (x [i] < y [j]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x [i] > y [j]) {
|
||||
return +1;
|
||||
}
|
||||
}
|
||||
|
||||
return y.Length.CompareTo (x.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class BlobHeapBuffer : HeapBuffer {
|
||||
|
||||
readonly Dictionary<ByteBuffer, uint> blobs = new Dictionary<ByteBuffer, uint> (new ByteBufferEqualityComparer ());
|
||||
|
||||
public override bool IsEmpty {
|
||||
get { return length <= 1; }
|
||||
}
|
||||
|
||||
public BlobHeapBuffer ()
|
||||
: base (1)
|
||||
{
|
||||
WriteByte (0);
|
||||
}
|
||||
|
||||
public uint GetBlobIndex (ByteBuffer blob)
|
||||
{
|
||||
uint index;
|
||||
if (blobs.TryGetValue (blob, out index))
|
||||
return index;
|
||||
|
||||
index = (uint)base.position;
|
||||
WriteBlob (blob);
|
||||
blobs.Add (blob, index);
|
||||
return index;
|
||||
}
|
||||
|
||||
void WriteBlob (ByteBuffer blob)
|
||||
{
|
||||
WriteCompressedUInt32 ((uint)blob.length);
|
||||
WriteBytes (blob);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class UserStringHeapBuffer : StringHeapBuffer {
|
||||
|
||||
public override uint GetStringIndex (string @string)
|
||||
{
|
||||
uint index;
|
||||
if (strings.TryGetValue (@string, out index))
|
||||
return index;
|
||||
|
||||
index = (uint)base.position;
|
||||
WriteString (@string);
|
||||
strings.Add (@string, index);
|
||||
return index;
|
||||
}
|
||||
|
||||
protected override void WriteString (string @string)
|
||||
{
|
||||
WriteCompressedUInt32 ((uint)@string.Length * 2 + 1);
|
||||
|
||||
byte special = 0;
|
||||
|
||||
for (int i = 0; i < @string.Length; i++) {
|
||||
var @char = @string [i];
|
||||
WriteUInt16 (@char);
|
||||
|
||||
if (special == 1)
|
||||
continue;
|
||||
|
||||
if (@char < 0x20 || @char > 0x7e) {
|
||||
if (@char > 0x7e
|
||||
|| (@char >= 0x01 && @char <= 0x08)
|
||||
|| (@char >= 0x0e && @char <= 0x1f)
|
||||
|| @char == 0x27
|
||||
|| @char == 0x2d) {
|
||||
|
||||
special = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WriteByte (special);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class PdbHeapBuffer : HeapBuffer {
|
||||
|
||||
public override bool IsEmpty {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public PdbHeapBuffer ()
|
||||
: base (0)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b1d0a81b66e78341ab77acdd3b15234
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
enum CodedIndex {
|
||||
TypeDefOrRef,
|
||||
HasConstant,
|
||||
HasCustomAttribute,
|
||||
HasFieldMarshal,
|
||||
HasDeclSecurity,
|
||||
MemberRefParent,
|
||||
HasSemantics,
|
||||
MethodDefOrRef,
|
||||
MemberForwarded,
|
||||
Implementation,
|
||||
CustomAttributeType,
|
||||
ResolutionScope,
|
||||
TypeOrMethodDef,
|
||||
HasCustomDebugInformation,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd50ffa8272dac444831e33b1b9d7f56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
enum ElementType : byte {
|
||||
None = 0x00,
|
||||
Void = 0x01,
|
||||
Boolean = 0x02,
|
||||
Char = 0x03,
|
||||
I1 = 0x04,
|
||||
U1 = 0x05,
|
||||
I2 = 0x06,
|
||||
U2 = 0x07,
|
||||
I4 = 0x08,
|
||||
U4 = 0x09,
|
||||
I8 = 0x0a,
|
||||
U8 = 0x0b,
|
||||
R4 = 0x0c,
|
||||
R8 = 0x0d,
|
||||
String = 0x0e,
|
||||
Ptr = 0x0f, // Followed by <type> token
|
||||
ByRef = 0x10, // Followed by <type> token
|
||||
ValueType = 0x11, // Followed by <type> token
|
||||
Class = 0x12, // Followed by <type> token
|
||||
Var = 0x13, // Followed by generic parameter number
|
||||
Array = 0x14, // <type> <rank> <boundsCount> <bound1> <loCount> <lo1>
|
||||
GenericInst = 0x15, // <type> <type-arg-count> <type-1> ... <type-n> */
|
||||
TypedByRef = 0x16,
|
||||
I = 0x18, // System.IntPtr
|
||||
U = 0x19, // System.UIntPtr
|
||||
FnPtr = 0x1b, // Followed by full method signature
|
||||
Object = 0x1c, // System.Object
|
||||
SzArray = 0x1d, // Single-dim array with 0 lower bound
|
||||
MVar = 0x1e, // Followed by generic parameter number
|
||||
CModReqD = 0x1f, // Required modifier : followed by a TypeDef or TypeRef token
|
||||
CModOpt = 0x20, // Optional modifier : followed by a TypeDef or TypeRef token
|
||||
Internal = 0x21, // Implemented within the CLI
|
||||
Modifier = 0x40, // Or'd with following element types
|
||||
Sentinel = 0x41, // Sentinel for varargs method signature
|
||||
Pinned = 0x45, // Denotes a local variable that points at a pinned object
|
||||
|
||||
// special undocumented constants
|
||||
Type = 0x50,
|
||||
Boxed = 0x51,
|
||||
Enum = 0x55
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94c4cb498ef60034d83bb60d3f743832
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// 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 System;
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
sealed class GuidHeap : Heap {
|
||||
|
||||
public GuidHeap (byte [] data)
|
||||
: base (data)
|
||||
{
|
||||
}
|
||||
|
||||
public Guid Read (uint index)
|
||||
{
|
||||
const int guid_size = 16;
|
||||
|
||||
if (index == 0 || ((index - 1) + guid_size) > data.Length)
|
||||
return new Guid ();
|
||||
|
||||
var buffer = new byte [guid_size];
|
||||
|
||||
Buffer.BlockCopy (this.data, (int)((index - 1) * guid_size), buffer, 0, guid_size);
|
||||
|
||||
return new Guid (buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bb39ab6484eb114b91a85d4b53f0f28
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
abstract class Heap {
|
||||
|
||||
public int IndexSize;
|
||||
|
||||
readonly internal byte [] data;
|
||||
|
||||
protected Heap (byte [] data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c343466f40d68574499155a2acd05e6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// 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 System;
|
||||
|
||||
namespace MonoFN.Cecil {
|
||||
|
||||
public struct MetadataToken : IEquatable<MetadataToken> {
|
||||
|
||||
readonly uint token;
|
||||
|
||||
public uint RID {
|
||||
get { return token & 0x00ffffff; }
|
||||
}
|
||||
|
||||
public TokenType TokenType {
|
||||
get { return (TokenType)(token & 0xff000000); }
|
||||
}
|
||||
|
||||
public static readonly MetadataToken Zero = new MetadataToken ((uint)0);
|
||||
|
||||
public MetadataToken (uint token)
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public MetadataToken (TokenType type)
|
||||
: this (type, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public MetadataToken (TokenType type, uint rid)
|
||||
{
|
||||
token = (uint)type | rid;
|
||||
}
|
||||
|
||||
public MetadataToken (TokenType type, int rid)
|
||||
{
|
||||
token = (uint)type | (uint)rid;
|
||||
}
|
||||
|
||||
public int ToInt32 ()
|
||||
{
|
||||
return (int)token;
|
||||
}
|
||||
|
||||
public uint ToUInt32 ()
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
return (int)token;
|
||||
}
|
||||
|
||||
public bool Equals (MetadataToken other)
|
||||
{
|
||||
return other.token == token;
|
||||
}
|
||||
|
||||
public override bool Equals (object obj)
|
||||
{
|
||||
if (obj is MetadataToken) {
|
||||
var other = (MetadataToken)obj;
|
||||
return other.token == token;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator == (MetadataToken one, MetadataToken other)
|
||||
{
|
||||
return one.token == other.token;
|
||||
}
|
||||
|
||||
public static bool operator != (MetadataToken one, MetadataToken other)
|
||||
{
|
||||
return one.token != other.token;
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return string.Format ("[{0}:0x{1}]", TokenType, RID.ToString ("x4"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 755d1954236c374458be77d93493faf8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// 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 RID = System.UInt32;
|
||||
|
||||
namespace MonoFN.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c64dd6e20a2b11c44ad424d29380c14c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,152 @@
|
||||
//
|
||||
// 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 System.Collections.Generic;
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
struct Row<T1, T2> {
|
||||
internal T1 Col1;
|
||||
internal T2 Col2;
|
||||
|
||||
public Row (T1 col1, T2 col2)
|
||||
{
|
||||
Col1 = col1;
|
||||
Col2 = col2;
|
||||
}
|
||||
}
|
||||
|
||||
struct Row<T1, T2, T3> {
|
||||
internal T1 Col1;
|
||||
internal T2 Col2;
|
||||
internal T3 Col3;
|
||||
|
||||
public Row (T1 col1, T2 col2, T3 col3)
|
||||
{
|
||||
Col1 = col1;
|
||||
Col2 = col2;
|
||||
Col3 = col3;
|
||||
}
|
||||
}
|
||||
|
||||
struct Row<T1, T2, T3, T4> {
|
||||
internal T1 Col1;
|
||||
internal T2 Col2;
|
||||
internal T3 Col3;
|
||||
internal T4 Col4;
|
||||
|
||||
public Row (T1 col1, T2 col2, T3 col3, T4 col4)
|
||||
{
|
||||
Col1 = col1;
|
||||
Col2 = col2;
|
||||
Col3 = col3;
|
||||
Col4 = col4;
|
||||
}
|
||||
}
|
||||
|
||||
struct Row<T1, T2, T3, T4, T5> {
|
||||
internal T1 Col1;
|
||||
internal T2 Col2;
|
||||
internal T3 Col3;
|
||||
internal T4 Col4;
|
||||
internal T5 Col5;
|
||||
|
||||
public Row (T1 col1, T2 col2, T3 col3, T4 col4, T5 col5)
|
||||
{
|
||||
Col1 = col1;
|
||||
Col2 = col2;
|
||||
Col3 = col3;
|
||||
Col4 = col4;
|
||||
Col5 = col5;
|
||||
}
|
||||
}
|
||||
|
||||
struct Row<T1, T2, T3, T4, T5, T6> {
|
||||
internal T1 Col1;
|
||||
internal T2 Col2;
|
||||
internal T3 Col3;
|
||||
internal T4 Col4;
|
||||
internal T5 Col5;
|
||||
internal T6 Col6;
|
||||
|
||||
public Row (T1 col1, T2 col2, T3 col3, T4 col4, T5 col5, T6 col6)
|
||||
{
|
||||
Col1 = col1;
|
||||
Col2 = col2;
|
||||
Col3 = col3;
|
||||
Col4 = col4;
|
||||
Col5 = col5;
|
||||
Col6 = col6;
|
||||
}
|
||||
}
|
||||
|
||||
struct Row<T1, T2, T3, T4, T5, T6, T7, T8, T9> {
|
||||
internal T1 Col1;
|
||||
internal T2 Col2;
|
||||
internal T3 Col3;
|
||||
internal T4 Col4;
|
||||
internal T5 Col5;
|
||||
internal T6 Col6;
|
||||
internal T7 Col7;
|
||||
internal T8 Col8;
|
||||
internal T9 Col9;
|
||||
|
||||
public Row (T1 col1, T2 col2, T3 col3, T4 col4, T5 col5, T6 col6, T7 col7, T8 col8, T9 col9)
|
||||
{
|
||||
Col1 = col1;
|
||||
Col2 = col2;
|
||||
Col3 = col3;
|
||||
Col4 = col4;
|
||||
Col5 = col5;
|
||||
Col6 = col6;
|
||||
Col7 = col7;
|
||||
Col8 = col8;
|
||||
Col9 = col9;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class RowEqualityComparer : IEqualityComparer<Row<string, string>>, IEqualityComparer<Row<uint, uint>>, IEqualityComparer<Row<uint, uint, uint>> {
|
||||
|
||||
public bool Equals (Row<string, string> x, Row<string, string> y)
|
||||
{
|
||||
return x.Col1 == y.Col1
|
||||
&& x.Col2 == y.Col2;
|
||||
}
|
||||
|
||||
public int GetHashCode (Row<string, string> obj)
|
||||
{
|
||||
string x = obj.Col1, y = obj.Col2;
|
||||
return (x != null ? x.GetHashCode () : 0) ^ (y != null ? y.GetHashCode () : 0);
|
||||
}
|
||||
|
||||
public bool Equals (Row<uint, uint> x, Row<uint, uint> y)
|
||||
{
|
||||
return x.Col1 == y.Col1
|
||||
&& x.Col2 == y.Col2;
|
||||
}
|
||||
|
||||
public int GetHashCode (Row<uint, uint> obj)
|
||||
{
|
||||
return (int)(obj.Col1 ^ obj.Col2);
|
||||
}
|
||||
|
||||
public bool Equals (Row<uint, uint, uint> x, Row<uint, uint, uint> y)
|
||||
{
|
||||
return x.Col1 == y.Col1
|
||||
&& x.Col2 == y.Col2
|
||||
&& x.Col3 == y.Col3;
|
||||
}
|
||||
|
||||
public int GetHashCode (Row<uint, uint, uint> obj)
|
||||
{
|
||||
return (int)(obj.Col1 ^ obj.Col2 ^ obj.Col3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89fd184bcc2b97840a2c0dfeec671be2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// 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 System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
class StringHeap : Heap {
|
||||
|
||||
readonly Dictionary<uint, string> strings = new Dictionary<uint, string> ();
|
||||
|
||||
public StringHeap (byte [] data)
|
||||
: base (data)
|
||||
{
|
||||
}
|
||||
|
||||
public string Read (uint index)
|
||||
{
|
||||
if (index == 0)
|
||||
return string.Empty;
|
||||
|
||||
string @string;
|
||||
if (strings.TryGetValue (index, out @string))
|
||||
return @string;
|
||||
|
||||
if (index > data.Length - 1)
|
||||
return string.Empty;
|
||||
|
||||
@string = ReadStringAt (index);
|
||||
if (@string.Length != 0)
|
||||
strings.Add (index, @string);
|
||||
|
||||
return @string;
|
||||
}
|
||||
|
||||
protected virtual string ReadStringAt (uint index)
|
||||
{
|
||||
int length = 0;
|
||||
int start = (int)index;
|
||||
|
||||
for (int i = start; ; i++) {
|
||||
if (data [i] == 0)
|
||||
break;
|
||||
|
||||
length++;
|
||||
}
|
||||
|
||||
return Encoding.UTF8.GetString (data, start, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0fc64863ca825b4e994640b0be9a938
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
enum Table : byte {
|
||||
Module = 0x00,
|
||||
TypeRef = 0x01,
|
||||
TypeDef = 0x02,
|
||||
FieldPtr = 0x03,
|
||||
Field = 0x04,
|
||||
MethodPtr = 0x05,
|
||||
Method = 0x06,
|
||||
ParamPtr = 0x07,
|
||||
Param = 0x08,
|
||||
InterfaceImpl = 0x09,
|
||||
MemberRef = 0x0a,
|
||||
Constant = 0x0b,
|
||||
CustomAttribute = 0x0c,
|
||||
FieldMarshal = 0x0d,
|
||||
DeclSecurity = 0x0e,
|
||||
ClassLayout = 0x0f,
|
||||
FieldLayout = 0x10,
|
||||
StandAloneSig = 0x11,
|
||||
EventMap = 0x12,
|
||||
EventPtr = 0x13,
|
||||
Event = 0x14,
|
||||
PropertyMap = 0x15,
|
||||
PropertyPtr = 0x16,
|
||||
Property = 0x17,
|
||||
MethodSemantics = 0x18,
|
||||
MethodImpl = 0x19,
|
||||
ModuleRef = 0x1a,
|
||||
TypeSpec = 0x1b,
|
||||
ImplMap = 0x1c,
|
||||
FieldRVA = 0x1d,
|
||||
EncLog = 0x1e,
|
||||
EncMap = 0x1f,
|
||||
Assembly = 0x20,
|
||||
AssemblyProcessor = 0x21,
|
||||
AssemblyOS = 0x22,
|
||||
AssemblyRef = 0x23,
|
||||
AssemblyRefProcessor = 0x24,
|
||||
AssemblyRefOS = 0x25,
|
||||
File = 0x26,
|
||||
ExportedType = 0x27,
|
||||
ManifestResource = 0x28,
|
||||
NestedClass = 0x29,
|
||||
GenericParam = 0x2a,
|
||||
MethodSpec = 0x2b,
|
||||
GenericParamConstraint = 0x2c,
|
||||
|
||||
Document = 0x30,
|
||||
MethodDebugInformation = 0x31,
|
||||
LocalScope = 0x32,
|
||||
LocalVariable = 0x33,
|
||||
LocalConstant = 0x34,
|
||||
ImportScope = 0x35,
|
||||
StateMachineMethod = 0x36,
|
||||
CustomDebugInformation = 0x37,
|
||||
}
|
||||
|
||||
struct TableInformation {
|
||||
public uint Offset;
|
||||
public uint Length;
|
||||
public uint RowSize;
|
||||
|
||||
public bool IsLarge {
|
||||
get { return Length > ushort.MaxValue; }
|
||||
}
|
||||
}
|
||||
|
||||
sealed class TableHeap : Heap {
|
||||
|
||||
public long Valid;
|
||||
public long Sorted;
|
||||
|
||||
public readonly TableInformation [] Tables = new TableInformation [Mixin.TableCount];
|
||||
|
||||
public TableInformation this [Table table] {
|
||||
get { return Tables [(int)table]; }
|
||||
}
|
||||
|
||||
public TableHeap (byte [] data)
|
||||
: base (data)
|
||||
{
|
||||
}
|
||||
|
||||
public bool HasTable (Table table)
|
||||
{
|
||||
return (Valid & (1L << (int)table)) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 978b1609b2ddc0c4baf628cc608456a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
namespace MonoFN.Cecil {
|
||||
|
||||
public enum TokenType : uint {
|
||||
Module = 0x00000000,
|
||||
TypeRef = 0x01000000,
|
||||
TypeDef = 0x02000000,
|
||||
Field = 0x04000000,
|
||||
Method = 0x06000000,
|
||||
Param = 0x08000000,
|
||||
InterfaceImpl = 0x09000000,
|
||||
MemberRef = 0x0a000000,
|
||||
CustomAttribute = 0x0c000000,
|
||||
Permission = 0x0e000000,
|
||||
Signature = 0x11000000,
|
||||
Event = 0x14000000,
|
||||
Property = 0x17000000,
|
||||
ModuleRef = 0x1a000000,
|
||||
TypeSpec = 0x1b000000,
|
||||
Assembly = 0x20000000,
|
||||
AssemblyRef = 0x23000000,
|
||||
File = 0x26000000,
|
||||
ExportedType = 0x27000000,
|
||||
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,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dba0af6138c6a084b8787e88b20b142a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
namespace MonoFN.Cecil.Metadata {
|
||||
|
||||
sealed class UserStringHeap : StringHeap {
|
||||
|
||||
public UserStringHeap (byte [] data)
|
||||
: base (data)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ReadStringAt (uint index)
|
||||
{
|
||||
int start = (int)index;
|
||||
|
||||
uint length = (uint)(data.ReadCompressedUInt32 (ref start) & ~1);
|
||||
if (length < 1)
|
||||
return string.Empty;
|
||||
|
||||
var chars = new char [length / 2];
|
||||
|
||||
for (int i = start, j = 0; i < start + length; i += 2)
|
||||
chars [j++] = (char)(data [i] | (data [i + 1] << 8));
|
||||
|
||||
return new string (chars);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d89100b382ef8e4ea67917917d04db6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,649 @@
|
||||
//
|
||||
// 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 MonoFN.Cecil.Metadata;
|
||||
using System;
|
||||
|
||||
namespace MonoFN.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;
|
||||
if ((data [position] & 0x80) == 0) {
|
||||
integer = data [position];
|
||||
position++;
|
||||
} else if ((data [position] & 0x40) == 0) {
|
||||
integer = (uint)(data [position] & ~0x80) << 8;
|
||||
integer |= data [position + 1];
|
||||
position += 2;
|
||||
} else {
|
||||
integer = (uint)(data [position] & ~0xc0) << 24;
|
||||
integer |= (uint)data [position + 1] << 16;
|
||||
integer |= (uint)data [position + 2] << 8;
|
||||
integer |= (uint)data [position + 3];
|
||||
position += 4;
|
||||
}
|
||||
return integer;
|
||||
}
|
||||
|
||||
public static MetadataToken GetMetadataToken (this CodedIndex self, uint data)
|
||||
{
|
||||
uint rid;
|
||||
TokenType token_type;
|
||||
switch (self) {
|
||||
case CodedIndex.TypeDefOrRef:
|
||||
rid = data >> 2;
|
||||
switch (data & 3) {
|
||||
case 0:
|
||||
token_type = TokenType.TypeDef; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.TypeRef; goto ret;
|
||||
case 2:
|
||||
token_type = TokenType.TypeSpec; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasConstant:
|
||||
rid = data >> 2;
|
||||
switch (data & 3) {
|
||||
case 0:
|
||||
token_type = TokenType.Field; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.Param; goto ret;
|
||||
case 2:
|
||||
token_type = TokenType.Property; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasCustomAttribute:
|
||||
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;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasFieldMarshal:
|
||||
rid = data >> 1;
|
||||
switch (data & 1) {
|
||||
case 0:
|
||||
token_type = TokenType.Field; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.Param; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasDeclSecurity:
|
||||
rid = data >> 2;
|
||||
switch (data & 3) {
|
||||
case 0:
|
||||
token_type = TokenType.TypeDef; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.Method; goto ret;
|
||||
case 2:
|
||||
token_type = TokenType.Assembly; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.MemberRefParent:
|
||||
rid = data >> 3;
|
||||
switch (data & 7) {
|
||||
case 0:
|
||||
token_type = TokenType.TypeDef; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.TypeRef; goto ret;
|
||||
case 2:
|
||||
token_type = TokenType.ModuleRef; goto ret;
|
||||
case 3:
|
||||
token_type = TokenType.Method; goto ret;
|
||||
case 4:
|
||||
token_type = TokenType.TypeSpec; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasSemantics:
|
||||
rid = data >> 1;
|
||||
switch (data & 1) {
|
||||
case 0:
|
||||
token_type = TokenType.Event; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.Property; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.MethodDefOrRef:
|
||||
rid = data >> 1;
|
||||
switch (data & 1) {
|
||||
case 0:
|
||||
token_type = TokenType.Method; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.MemberRef; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.MemberForwarded:
|
||||
rid = data >> 1;
|
||||
switch (data & 1) {
|
||||
case 0:
|
||||
token_type = TokenType.Field; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.Method; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.Implementation:
|
||||
rid = data >> 2;
|
||||
switch (data & 3) {
|
||||
case 0:
|
||||
token_type = TokenType.File; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.AssemblyRef; goto ret;
|
||||
case 2:
|
||||
token_type = TokenType.ExportedType; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.CustomAttributeType:
|
||||
rid = data >> 3;
|
||||
switch (data & 7) {
|
||||
case 2:
|
||||
token_type = TokenType.Method; goto ret;
|
||||
case 3:
|
||||
token_type = TokenType.MemberRef; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.ResolutionScope:
|
||||
rid = data >> 2;
|
||||
switch (data & 3) {
|
||||
case 0:
|
||||
token_type = TokenType.Module; goto ret;
|
||||
case 1:
|
||||
token_type = TokenType.ModuleRef; goto ret;
|
||||
case 2:
|
||||
token_type = TokenType.AssemblyRef; goto ret;
|
||||
case 3:
|
||||
token_type = TokenType.TypeRef; goto ret;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.TypeOrMethodDef:
|
||||
rid = data >> 1;
|
||||
switch (data & 1) {
|
||||
case 0:
|
||||
token_type = TokenType.TypeDef; goto ret;
|
||||
case 1:
|
||||
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;
|
||||
}
|
||||
ret:
|
||||
return new MetadataToken (token_type, rid);
|
||||
exit:
|
||||
return MetadataToken.Zero;
|
||||
}
|
||||
|
||||
public static uint CompressMetadataToken (this CodedIndex self, MetadataToken token)
|
||||
{
|
||||
uint ret = 0;
|
||||
if (token.RID == 0)
|
||||
return ret;
|
||||
switch (self) {
|
||||
case CodedIndex.TypeDefOrRef:
|
||||
ret = token.RID << 2;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.TypeDef:
|
||||
return ret | 0;
|
||||
case TokenType.TypeRef:
|
||||
return ret | 1;
|
||||
case TokenType.TypeSpec:
|
||||
return ret | 2;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasConstant:
|
||||
ret = token.RID << 2;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.Field:
|
||||
return ret | 0;
|
||||
case TokenType.Param:
|
||||
return ret | 1;
|
||||
case TokenType.Property:
|
||||
return ret | 2;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasCustomAttribute:
|
||||
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;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasFieldMarshal:
|
||||
ret = token.RID << 1;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.Field:
|
||||
return ret | 0;
|
||||
case TokenType.Param:
|
||||
return ret | 1;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasDeclSecurity:
|
||||
ret = token.RID << 2;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.TypeDef:
|
||||
return ret | 0;
|
||||
case TokenType.Method:
|
||||
return ret | 1;
|
||||
case TokenType.Assembly:
|
||||
return ret | 2;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.MemberRefParent:
|
||||
ret = token.RID << 3;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.TypeDef:
|
||||
return ret | 0;
|
||||
case TokenType.TypeRef:
|
||||
return ret | 1;
|
||||
case TokenType.ModuleRef:
|
||||
return ret | 2;
|
||||
case TokenType.Method:
|
||||
return ret | 3;
|
||||
case TokenType.TypeSpec:
|
||||
return ret | 4;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.HasSemantics:
|
||||
ret = token.RID << 1;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.Event:
|
||||
return ret | 0;
|
||||
case TokenType.Property:
|
||||
return ret | 1;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.MethodDefOrRef:
|
||||
ret = token.RID << 1;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.Method:
|
||||
return ret | 0;
|
||||
case TokenType.MemberRef:
|
||||
return ret | 1;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.MemberForwarded:
|
||||
ret = token.RID << 1;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.Field:
|
||||
return ret | 0;
|
||||
case TokenType.Method:
|
||||
return ret | 1;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.Implementation:
|
||||
ret = token.RID << 2;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.File:
|
||||
return ret | 0;
|
||||
case TokenType.AssemblyRef:
|
||||
return ret | 1;
|
||||
case TokenType.ExportedType:
|
||||
return ret | 2;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.CustomAttributeType:
|
||||
ret = token.RID << 3;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.Method:
|
||||
return ret | 2;
|
||||
case TokenType.MemberRef:
|
||||
return ret | 3;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.ResolutionScope:
|
||||
ret = token.RID << 2;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.Module:
|
||||
return ret | 0;
|
||||
case TokenType.ModuleRef:
|
||||
return ret | 1;
|
||||
case TokenType.AssemblyRef:
|
||||
return ret | 2;
|
||||
case TokenType.TypeRef:
|
||||
return ret | 3;
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
case CodedIndex.TypeOrMethodDef:
|
||||
ret = token.RID << 1;
|
||||
switch (token.TokenType) {
|
||||
case TokenType.TypeDef:
|
||||
return ret | 0;
|
||||
case TokenType.Method:
|
||||
return ret | 1;
|
||||
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;
|
||||
}
|
||||
exit:
|
||||
throw new ArgumentException ();
|
||||
}
|
||||
|
||||
public static int GetSize (this CodedIndex self, Func<Table, int> counter)
|
||||
{
|
||||
int bits;
|
||||
Table [] tables;
|
||||
|
||||
switch (self) {
|
||||
case CodedIndex.TypeDefOrRef:
|
||||
bits = 2;
|
||||
tables = new [] { Table.TypeDef, Table.TypeRef, Table.TypeSpec };
|
||||
break;
|
||||
case CodedIndex.HasConstant:
|
||||
bits = 2;
|
||||
tables = new [] { Table.Field, Table.Param, Table.Property };
|
||||
break;
|
||||
case CodedIndex.HasCustomAttribute:
|
||||
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,
|
||||
};
|
||||
break;
|
||||
case CodedIndex.HasFieldMarshal:
|
||||
bits = 1;
|
||||
tables = new [] { Table.Field, Table.Param };
|
||||
break;
|
||||
case CodedIndex.HasDeclSecurity:
|
||||
bits = 2;
|
||||
tables = new [] { Table.TypeDef, Table.Method, Table.Assembly };
|
||||
break;
|
||||
case CodedIndex.MemberRefParent:
|
||||
bits = 3;
|
||||
tables = new [] { Table.TypeDef, Table.TypeRef, Table.ModuleRef, Table.Method, Table.TypeSpec };
|
||||
break;
|
||||
case CodedIndex.HasSemantics:
|
||||
bits = 1;
|
||||
tables = new [] { Table.Event, Table.Property };
|
||||
break;
|
||||
case CodedIndex.MethodDefOrRef:
|
||||
bits = 1;
|
||||
tables = new [] { Table.Method, Table.MemberRef };
|
||||
break;
|
||||
case CodedIndex.MemberForwarded:
|
||||
bits = 1;
|
||||
tables = new [] { Table.Field, Table.Method };
|
||||
break;
|
||||
case CodedIndex.Implementation:
|
||||
bits = 2;
|
||||
tables = new [] { Table.File, Table.AssemblyRef, Table.ExportedType };
|
||||
break;
|
||||
case CodedIndex.CustomAttributeType:
|
||||
bits = 3;
|
||||
tables = new [] { Table.Method, Table.MemberRef };
|
||||
break;
|
||||
case CodedIndex.ResolutionScope:
|
||||
bits = 2;
|
||||
tables = new [] { Table.Module, Table.ModuleRef, Table.AssemblyRef, Table.TypeRef };
|
||||
break;
|
||||
case CodedIndex.TypeOrMethodDef:
|
||||
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 ();
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
|
||||
for (int i = 0; i < tables.Length; i++) {
|
||||
max = System.Math.Max (counter (tables [i]), max);
|
||||
}
|
||||
|
||||
return max < (1 << (16 - bits)) ? 2 : 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4785957c0c546de4680e1196a57f66d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user