// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
get { return base.position - start; }
}
- CodeReader (Section section, MetadataReader reader)
+ public CodeReader (Section section, MetadataReader reader)
: base (section.Data)
{
this.code_section = section;
this.reader = reader;
}
- public static CodeReader CreateCodeReader (MetadataReader metadata)
- {
- return new CodeReader (metadata.image.MetadataSection, metadata);
- }
-
public MethodBody ReadMethodBody (MethodDefinition method)
{
this.method = method;
break;
case ExceptionHandlerType.Filter:
handler.FilterStart = GetInstruction (ReadInt32 ());
- handler.FilterEnd = handler.HandlerStart.Previous;
break;
default:
Advance (4);
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
return true;
if (handler.HandlerType == ExceptionHandlerType.Filter
- && IsFatRange (handler.FilterStart, handler.FilterEnd))
+ && IsFatRange (handler.FilterStart, handler.HandlerStart))
return true;
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Instruction try_start;
Instruction try_end;
Instruction filter_start;
- Instruction filter_end;
Instruction handler_start;
Instruction handler_end;
set { filter_start = value; }
}
- public Instruction FilterEnd {
- get { return filter_end; }
- set { filter_end = value; }
- }
-
public Instruction HandlerStart {
get { return handler_start; }
set { handler_start = value; }
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
readonly byte stack_behavior_push;
public string Name {
- get { return OpCodeNames.names [op1 == 0xff ? op2 : op2 + 256]; }
+ get { return OpCodeNames.names [(int) Code]; }
}
public int Size {
}
public short Value {
- get { return (short) ((op1 << 8) | op2); }
+ get { return op1 == 0xff ? op2 : (short) ((op1 << 8) | op2); }
}
public Code Code {
static class OpCodeNames {
- internal static readonly string [] names = {
- "nop",
- "break",
- "ldarg.0",
- "ldarg.1",
- "ldarg.2",
- "ldarg.3",
- "ldloc.0",
- "ldloc.1",
- "ldloc.2",
- "ldloc.3",
- "stloc.0",
- "stloc.1",
- "stloc.2",
- "stloc.3",
- "ldarg.s",
- "ldarga.s",
- "starg.s",
- "ldloc.s",
- "ldloca.s",
- "stloc.s",
- "ldnull",
- "ldc.i4.m1",
- "ldc.i4.0",
- "ldc.i4.1",
- "ldc.i4.2",
- "ldc.i4.3",
- "ldc.i4.4",
- "ldc.i4.5",
- "ldc.i4.6",
- "ldc.i4.7",
- "ldc.i4.8",
- "ldc.i4.s",
- "ldc.i4",
- "ldc.i8",
- "ldc.r4",
- "ldc.r8",
- null,
- "dup",
- "pop",
- "jmp",
- "call",
- "calli",
- "ret",
- "br.s",
- "brfalse.s",
- "brtrue.s",
- "beq.s",
- "bge.s",
- "bgt.s",
- "ble.s",
- "blt.s",
- "bne.un.s",
- "bge.un.s",
- "bgt.un.s",
- "ble.un.s",
- "blt.un.s",
- "br",
- "brfalse",
- "brtrue",
- "beq",
- "bge",
- "bgt",
- "ble",
- "blt",
- "bne.un",
- "bge.un",
- "bgt.un",
- "ble.un",
- "blt.un",
- "switch",
- "ldind.i1",
- "ldind.u1",
- "ldind.i2",
- "ldind.u2",
- "ldind.i4",
- "ldind.u4",
- "ldind.i8",
- "ldind.i",
- "ldind.r4",
- "ldind.r8",
- "ldind.ref",
- "stind.ref",
- "stind.i1",
- "stind.i2",
- "stind.i4",
- "stind.i8",
- "stind.r4",
- "stind.r8",
- "add",
- "sub",
- "mul",
- "div",
- "div.un",
- "rem",
- "rem.un",
- "and",
- "or",
- "xor",
- "shl",
- "shr",
- "shr.un",
- "neg",
- "not",
- "conv.i1",
- "conv.i2",
- "conv.i4",
- "conv.i8",
- "conv.r4",
- "conv.r8",
- "conv.u4",
- "conv.u8",
- "callvirt",
- "cpobj",
- "ldobj",
- "ldstr",
- "newobj",
- "castclass",
- "isinst",
- "conv.r.un",
- null,
- null,
- "unbox",
- "throw",
- "ldfld",
- "ldflda",
- "stfld",
- "ldsfld",
- "ldsflda",
- "stsfld",
- "stobj",
- "conv.ovf.i1.un",
- "conv.ovf.i2.un",
- "conv.ovf.i4.un",
- "conv.ovf.i8.un",
- "conv.ovf.u1.un",
- "conv.ovf.u2.un",
- "conv.ovf.u4.un",
- "conv.ovf.u8.un",
- "conv.ovf.i.un",
- "conv.ovf.u.un",
- "box",
- "newarr",
- "ldlen",
- "ldelema",
- "ldelem.i1",
- "ldelem.u1",
- "ldelem.i2",
- "ldelem.u2",
- "ldelem.i4",
- "ldelem.u4",
- "ldelem.i8",
- "ldelem.i",
- "ldelem.r4",
- "ldelem.r8",
- "ldelem.ref",
- "stelem.i",
- "stelem.i1",
- "stelem.i2",
- "stelem.i4",
- "stelem.i8",
- "stelem.r4",
- "stelem.r8",
- "stelem.ref",
- "ldelem.any",
- "stelem.any",
- "unbox.any",
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- "conv.ovf.i1",
- "conv.ovf.u1",
- "conv.ovf.i2",
- "conv.ovf.u2",
- "conv.ovf.i4",
- "conv.ovf.u4",
- "conv.ovf.i8",
- "conv.ovf.u8",
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- "refanyval",
- "ckfinite",
- null,
- null,
- "mkrefany",
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- "ldtoken",
- "conv.u2",
- "conv.u1",
- "conv.i",
- "conv.ovf.i",
- "conv.ovf.u",
- "add.ovf",
- "add.ovf.un",
- "mul.ovf",
- "mul.ovf.un",
- "sub.ovf",
- "sub.ovf.un",
- "endfinally",
- "leave",
- "leave.s",
- "stind.i",
- "conv.u",
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- "prefix7",
- "prefix6",
- "prefix5",
- "prefix4",
- "prefix3",
- "prefix2",
- "prefix1",
- "prefixref",
- "arglist",
- "ceq",
- "cgt",
- "cgt.un",
- "clt",
- "clt.un",
- "ldftn",
- "ldvirtftn",
- null,
- "ldarg",
- "ldarga",
- "starg",
- "ldloc",
- "ldloca",
- "stloc",
- "localloc",
- null,
- "endfilter",
- "unaligned.",
- "volatile.",
- "tail.",
- "initobj",
- "constrained.",
- "cpblk",
- "initblk",
- "no.", // added by spouliot to match Cecil existing definitions
- "rethrow",
- null,
- "sizeof",
- "refanytype",
- "readonly.", // added by spouliot to match Cecil existing definitions
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- };
+ internal static readonly string [] names;
+
+ static OpCodeNames ()
+ {
+ var table = new byte [] {
+ 3, 110, 111, 112,
+ 5, 98, 114, 101, 97, 107,
+ 7, 108, 100, 97, 114, 103, 46, 48,
+ 7, 108, 100, 97, 114, 103, 46, 49,
+ 7, 108, 100, 97, 114, 103, 46, 50,
+ 7, 108, 100, 97, 114, 103, 46, 51,
+ 7, 108, 100, 108, 111, 99, 46, 48,
+ 7, 108, 100, 108, 111, 99, 46, 49,
+ 7, 108, 100, 108, 111, 99, 46, 50,
+ 7, 108, 100, 108, 111, 99, 46, 51,
+ 7, 115, 116, 108, 111, 99, 46, 48,
+ 7, 115, 116, 108, 111, 99, 46, 49,
+ 7, 115, 116, 108, 111, 99, 46, 50,
+ 7, 115, 116, 108, 111, 99, 46, 51,
+ 7, 108, 100, 97, 114, 103, 46, 115,
+ 8, 108, 100, 97, 114, 103, 97, 46, 115,
+ 7, 115, 116, 97, 114, 103, 46, 115,
+ 7, 108, 100, 108, 111, 99, 46, 115,
+ 8, 108, 100, 108, 111, 99, 97, 46, 115,
+ 7, 115, 116, 108, 111, 99, 46, 115,
+ 6, 108, 100, 110, 117, 108, 108,
+ 9, 108, 100, 99, 46, 105, 52, 46, 109, 49,
+ 8, 108, 100, 99, 46, 105, 52, 46, 48,
+ 8, 108, 100, 99, 46, 105, 52, 46, 49,
+ 8, 108, 100, 99, 46, 105, 52, 46, 50,
+ 8, 108, 100, 99, 46, 105, 52, 46, 51,
+ 8, 108, 100, 99, 46, 105, 52, 46, 52,
+ 8, 108, 100, 99, 46, 105, 52, 46, 53,
+ 8, 108, 100, 99, 46, 105, 52, 46, 54,
+ 8, 108, 100, 99, 46, 105, 52, 46, 55,
+ 8, 108, 100, 99, 46, 105, 52, 46, 56,
+ 8, 108, 100, 99, 46, 105, 52, 46, 115,
+ 6, 108, 100, 99, 46, 105, 52,
+ 6, 108, 100, 99, 46, 105, 56,
+ 6, 108, 100, 99, 46, 114, 52,
+ 6, 108, 100, 99, 46, 114, 56,
+ 3, 100, 117, 112,
+ 3, 112, 111, 112,
+ 3, 106, 109, 112,
+ 4, 99, 97, 108, 108,
+ 5, 99, 97, 108, 108, 105,
+ 3, 114, 101, 116,
+ 4, 98, 114, 46, 115,
+ 9, 98, 114, 102, 97, 108, 115, 101, 46, 115,
+ 8, 98, 114, 116, 114, 117, 101, 46, 115,
+ 5, 98, 101, 113, 46, 115,
+ 5, 98, 103, 101, 46, 115,
+ 5, 98, 103, 116, 46, 115,
+ 5, 98, 108, 101, 46, 115,
+ 5, 98, 108, 116, 46, 115,
+ 8, 98, 110, 101, 46, 117, 110, 46, 115,
+ 8, 98, 103, 101, 46, 117, 110, 46, 115,
+ 8, 98, 103, 116, 46, 117, 110, 46, 115,
+ 8, 98, 108, 101, 46, 117, 110, 46, 115,
+ 8, 98, 108, 116, 46, 117, 110, 46, 115,
+ 2, 98, 114,
+ 7, 98, 114, 102, 97, 108, 115, 101,
+ 6, 98, 114, 116, 114, 117, 101,
+ 3, 98, 101, 113,
+ 3, 98, 103, 101,
+ 3, 98, 103, 116,
+ 3, 98, 108, 101,
+ 3, 98, 108, 116,
+ 6, 98, 110, 101, 46, 117, 110,
+ 6, 98, 103, 101, 46, 117, 110,
+ 6, 98, 103, 116, 46, 117, 110,
+ 6, 98, 108, 101, 46, 117, 110,
+ 6, 98, 108, 116, 46, 117, 110,
+ 6, 115, 119, 105, 116, 99, 104,
+ 8, 108, 100, 105, 110, 100, 46, 105, 49,
+ 8, 108, 100, 105, 110, 100, 46, 117, 49,
+ 8, 108, 100, 105, 110, 100, 46, 105, 50,
+ 8, 108, 100, 105, 110, 100, 46, 117, 50,
+ 8, 108, 100, 105, 110, 100, 46, 105, 52,
+ 8, 108, 100, 105, 110, 100, 46, 117, 52,
+ 8, 108, 100, 105, 110, 100, 46, 105, 56,
+ 7, 108, 100, 105, 110, 100, 46, 105,
+ 8, 108, 100, 105, 110, 100, 46, 114, 52,
+ 8, 108, 100, 105, 110, 100, 46, 114, 56,
+ 9, 108, 100, 105, 110, 100, 46, 114, 101, 102,
+ 9, 115, 116, 105, 110, 100, 46, 114, 101, 102,
+ 8, 115, 116, 105, 110, 100, 46, 105, 49,
+ 8, 115, 116, 105, 110, 100, 46, 105, 50,
+ 8, 115, 116, 105, 110, 100, 46, 105, 52,
+ 8, 115, 116, 105, 110, 100, 46, 105, 56,
+ 8, 115, 116, 105, 110, 100, 46, 114, 52,
+ 8, 115, 116, 105, 110, 100, 46, 114, 56,
+ 3, 97, 100, 100,
+ 3, 115, 117, 98,
+ 3, 109, 117, 108,
+ 3, 100, 105, 118,
+ 6, 100, 105, 118, 46, 117, 110,
+ 3, 114, 101, 109,
+ 6, 114, 101, 109, 46, 117, 110,
+ 3, 97, 110, 100,
+ 2, 111, 114,
+ 3, 120, 111, 114,
+ 3, 115, 104, 108,
+ 3, 115, 104, 114,
+ 6, 115, 104, 114, 46, 117, 110,
+ 3, 110, 101, 103,
+ 3, 110, 111, 116,
+ 7, 99, 111, 110, 118, 46, 105, 49,
+ 7, 99, 111, 110, 118, 46, 105, 50,
+ 7, 99, 111, 110, 118, 46, 105, 52,
+ 7, 99, 111, 110, 118, 46, 105, 56,
+ 7, 99, 111, 110, 118, 46, 114, 52,
+ 7, 99, 111, 110, 118, 46, 114, 56,
+ 7, 99, 111, 110, 118, 46, 117, 52,
+ 7, 99, 111, 110, 118, 46, 117, 56,
+ 8, 99, 97, 108, 108, 118, 105, 114, 116,
+ 5, 99, 112, 111, 98, 106,
+ 5, 108, 100, 111, 98, 106,
+ 5, 108, 100, 115, 116, 114,
+ 6, 110, 101, 119, 111, 98, 106,
+ 9, 99, 97, 115, 116, 99, 108, 97, 115, 115,
+ 6, 105, 115, 105, 110, 115, 116,
+ 9, 99, 111, 110, 118, 46, 114, 46, 117, 110,
+ 5, 117, 110, 98, 111, 120,
+ 5, 116, 104, 114, 111, 119,
+ 5, 108, 100, 102, 108, 100,
+ 6, 108, 100, 102, 108, 100, 97,
+ 5, 115, 116, 102, 108, 100,
+ 6, 108, 100, 115, 102, 108, 100,
+ 7, 108, 100, 115, 102, 108, 100, 97,
+ 6, 115, 116, 115, 102, 108, 100,
+ 5, 115, 116, 111, 98, 106,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 49, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 50, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 52, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 56, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 49, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 50, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 52, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 56, 46, 117, 110,
+ 13, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 46, 117, 110,
+ 13, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 46, 117, 110,
+ 3, 98, 111, 120,
+ 6, 110, 101, 119, 97, 114, 114,
+ 5, 108, 100, 108, 101, 110,
+ 7, 108, 100, 101, 108, 101, 109, 97,
+ 9, 108, 100, 101, 108, 101, 109, 46, 105, 49,
+ 9, 108, 100, 101, 108, 101, 109, 46, 117, 49,
+ 9, 108, 100, 101, 108, 101, 109, 46, 105, 50,
+ 9, 108, 100, 101, 108, 101, 109, 46, 117, 50,
+ 9, 108, 100, 101, 108, 101, 109, 46, 105, 52,
+ 9, 108, 100, 101, 108, 101, 109, 46, 117, 52,
+ 9, 108, 100, 101, 108, 101, 109, 46, 105, 56,
+ 8, 108, 100, 101, 108, 101, 109, 46, 105,
+ 9, 108, 100, 101, 108, 101, 109, 46, 114, 52,
+ 9, 108, 100, 101, 108, 101, 109, 46, 114, 56,
+ 10, 108, 100, 101, 108, 101, 109, 46, 114, 101, 102,
+ 8, 115, 116, 101, 108, 101, 109, 46, 105,
+ 9, 115, 116, 101, 108, 101, 109, 46, 105, 49,
+ 9, 115, 116, 101, 108, 101, 109, 46, 105, 50,
+ 9, 115, 116, 101, 108, 101, 109, 46, 105, 52,
+ 9, 115, 116, 101, 108, 101, 109, 46, 105, 56,
+ 9, 115, 116, 101, 108, 101, 109, 46, 114, 52,
+ 9, 115, 116, 101, 108, 101, 109, 46, 114, 56,
+ 10, 115, 116, 101, 108, 101, 109, 46, 114, 101, 102,
+ 10, 108, 100, 101, 108, 101, 109, 46, 97, 110, 121,
+ 10, 115, 116, 101, 108, 101, 109, 46, 97, 110, 121,
+ 9, 117, 110, 98, 111, 120, 46, 97, 110, 121,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 49,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 49,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 50,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 50,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 52,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 52,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 56,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 56,
+ 9, 114, 101, 102, 97, 110, 121, 118, 97, 108,
+ 8, 99, 107, 102, 105, 110, 105, 116, 101,
+ 8, 109, 107, 114, 101, 102, 97, 110, 121,
+ 7, 108, 100, 116, 111, 107, 101, 110,
+ 7, 99, 111, 110, 118, 46, 117, 50,
+ 7, 99, 111, 110, 118, 46, 117, 49,
+ 6, 99, 111, 110, 118, 46, 105,
+ 10, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105,
+ 10, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117,
+ 7, 97, 100, 100, 46, 111, 118, 102,
+ 10, 97, 100, 100, 46, 111, 118, 102, 46, 117, 110,
+ 7, 109, 117, 108, 46, 111, 118, 102,
+ 10, 109, 117, 108, 46, 111, 118, 102, 46, 117, 110,
+ 7, 115, 117, 98, 46, 111, 118, 102,
+ 10, 115, 117, 98, 46, 111, 118, 102, 46, 117, 110,
+ 10, 101, 110, 100, 102, 105, 110, 97, 108, 108, 121,
+ 5, 108, 101, 97, 118, 101,
+ 7, 108, 101, 97, 118, 101, 46, 115,
+ 7, 115, 116, 105, 110, 100, 46, 105,
+ 6, 99, 111, 110, 118, 46, 117,
+ 7, 97, 114, 103, 108, 105, 115, 116,
+ 3, 99, 101, 113,
+ 3, 99, 103, 116,
+ 6, 99, 103, 116, 46, 117, 110,
+ 3, 99, 108, 116,
+ 6, 99, 108, 116, 46, 117, 110,
+ 5, 108, 100, 102, 116, 110,
+ 9, 108, 100, 118, 105, 114, 116, 102, 116, 110,
+ 5, 108, 100, 97, 114, 103,
+ 6, 108, 100, 97, 114, 103, 97,
+ 5, 115, 116, 97, 114, 103,
+ 5, 108, 100, 108, 111, 99,
+ 6, 108, 100, 108, 111, 99, 97,
+ 5, 115, 116, 108, 111, 99,
+ 8, 108, 111, 99, 97, 108, 108, 111, 99,
+ 9, 101, 110, 100, 102, 105, 108, 116, 101, 114,
+ 10, 117, 110, 97, 108, 105, 103, 110, 101, 100, 46,
+ 9, 118, 111, 108, 97, 116, 105, 108, 101, 46,
+ 5, 116, 97, 105, 108, 46,
+ 7, 105, 110, 105, 116, 111, 98, 106,
+ 12, 99, 111, 110, 115, 116, 114, 97, 105, 110, 101, 100, 46,
+ 5, 99, 112, 98, 108, 107,
+ 7, 105, 110, 105, 116, 98, 108, 107,
+ 3, 110, 111, 46,
+ 7, 114, 101, 116, 104, 114, 111, 119,
+ 6, 115, 105, 122, 101, 111, 102,
+ 10, 114, 101, 102, 97, 110, 121, 116, 121, 112, 101,
+ 9, 114, 101, 97, 100, 111, 110, 108, 121, 46,
+ };
+
+ names = new string [219];
+
+ for (int i = 0, p = 0; i < names.Length; i++) {
+ var buffer = new char [table [p++]];
+
+ for (int j = 0; j < buffer.Length; j++)
+ buffer [j] = (char) table [p++];
+
+ names [i] = new string (buffer);
+ }
+ }
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
get { return local_var_token; }
}
- public MethodSymbols (string methodName)
+ internal MethodSymbols (string methodName)
{
this.method_name = methodName;
}
+
+ public MethodSymbols (MetadataToken methodToken)
+ {
+ this.method_token = methodToken;
+ }
}
public delegate Instruction InstructionMapper (int offset);
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
abstract class HeapBuffer : ByteBuffer {
public bool IsLarge {
- get { return base.length > 65536; }
+ get { return base.length > 65535; }
}
public abstract bool IsEmpty { get; }
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
TypeSpec = 0x1b,
ImplMap = 0x1c,
FieldRVA = 0x1d,
+ EncLog = 0x1e,
+ EncMap = 0x1f,
Assembly = 0x20,
AssemblyProcessor = 0x21,
AssemblyOS = 0x22,
public long Valid;
public long Sorted;
- public static readonly Table [] TableIdentifiers = new [] {
- Table.Module,
- Table.TypeRef,
- Table.TypeDef,
- Table.FieldPtr,
- Table.Field,
- Table.MethodPtr,
- Table.Method,
- Table.ParamPtr,
- Table.Param,
- Table.InterfaceImpl,
- Table.MemberRef,
- Table.Constant,
- Table.CustomAttribute,
- Table.FieldMarshal,
- Table.DeclSecurity,
- Table.ClassLayout,
- Table.FieldLayout,
- Table.StandAloneSig,
- Table.EventMap,
- Table.EventPtr,
- Table.Event,
- Table.PropertyMap,
- Table.PropertyPtr,
- Table.Property,
- Table.MethodSemantics,
- Table.MethodImpl,
- Table.ModuleRef,
- Table.TypeSpec,
- Table.ImplMap,
- Table.FieldRVA,
- Table.Assembly,
- Table.AssemblyProcessor,
- Table.AssemblyOS,
- Table.AssemblyRef,
- Table.AssemblyRefProcessor,
- Table.AssemblyRefOS,
- Table.File,
- Table.ExportedType,
- Table.ManifestResource,
- Table.NestedClass,
- Table.GenericParam,
- Table.MethodSpec,
- Table.GenericParamConstraint,
- };
+ public const int TableCount = 45;
- public readonly TableInformation [] Tables = new TableInformation [45];
+ public readonly TableInformation [] Tables = new TableInformation [TableCount];
public TableInformation this [Table table] {
get { return Tables [(int) table]; }
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Sorted 8
heap.Sorted = ReadInt64 ();
- for (int i = 0; i < TableHeap.TableIdentifiers.Length; i++) {
- var table = TableHeap.TableIdentifiers [i];
- if (!heap.HasTable (table))
+ for (int i = 0; i < TableHeap.TableCount; i++) {
+ if (!heap.HasTable ((Table) i))
continue;
- heap.Tables [(int) table].Length = ReadUInt32 ();
+ heap.Tables [i].Length = ReadUInt32 ();
}
SetIndexSize (image.StringHeap, sizes, 0x1);
var heap = image.TableHeap;
var tables = heap.Tables;
- for (int i = 0; i < TableHeap.TableIdentifiers.Length; i++) {
- var table = TableHeap.TableIdentifiers [i];
+ for (int i = 0; i < TableHeap.TableCount; i++) {
+ var table = (Table) i;
if (!heap.HasTable (table))
continue;
size = 4 // RVA
+ GetTableIndexSize (Table.Field); // Field
break;
+ case Table.EncLog:
+ case Table.EncMap:
+ size = 4;
+ break;
case Table.Assembly:
size = 16 // HashAlgId 4, Version 4 * 2, Flags 4
+ blobidx_size // PublicKey
throw new NotSupportedException ();
}
- int index = (int) table;
-
- tables [index].RowSize = (uint) size;
- tables [index].Offset = offset;
+ tables [i].RowSize = (uint) size;
+ tables [i].Offset = offset;
- offset += (uint) size * tables [index].Length;
+ offset += (uint) size * tables [i].Length;
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
if (main_module.HasImage)
return modules = main_module.Read (this, (_, reader) => reader.ReadModules ());
- return modules = new Collection<ModuleDefinition> { main_module };
+ return modules = new Collection<ModuleDefinition> (1) { main_module };
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
this.image = module.Image;
this.module = module;
this.metadata = module.MetadataSystem;
- this.code = CodeReader.CreateCodeReader (this);
+ this.code = new CodeReader (image.MetadataSection, this);
}
int GetCodedIndexSize (CodedIndex index)
return module;
}
- public Collection<AssemblyNameReference> ReadAssemblyReferences ()
+ void InitializeAssemblyReferences ()
{
+ if (metadata.AssemblyReferences != null)
+ return;
+
int length = MoveTo (Table.AssemblyRef);
- var references = new Collection<AssemblyNameReference> (length);
+ var references = metadata.AssemblyReferences = new AssemblyNameReference [length];
- for (uint i = 1; i <= length; i++) {
+ for (uint i = 0; i < length; i++) {
var reference = new AssemblyNameReference ();
- reference.token = new MetadataToken (TokenType.AssemblyRef, i);
+ reference.token = new MetadataToken (TokenType.AssemblyRef, i + 1);
PopulateVersionAndFlags (reference);
- reference.PublicKeyToken = ReadBlob ();
+ var key_or_token = ReadBlob ();
+
+ if (reference.HasPublicKey)
+ reference.PublicKey = key_or_token;
+ else
+ reference.PublicKeyToken = key_or_token;
PopulateNameAndCulture (reference);
reference.Hash = ReadBlob ();
- references.Add (reference);
+ references [i] = reference;
}
+ }
- return references;
+ public Collection<AssemblyNameReference> ReadAssemblyReferences ()
+ {
+ InitializeAssemblyReferences ();
+
+ return new Collection<AssemblyNameReference> (metadata.AssemblyReferences);
}
public MethodDefinition ReadEntryPoint ()
return Path.Combine (path, name);
}
- public Collection<ModuleReference> ReadModuleReferences ()
+ void InitializeModuleReferences ()
{
+ if (metadata.ModuleReferences != null)
+ return;
+
int length = MoveTo (Table.ModuleRef);
- var references = new Collection<ModuleReference> (length);
+ var references = metadata.ModuleReferences = new ModuleReference [length];
- for (uint i = 1; i <= length; i++) {
+ for (uint i = 0; i < length; i++) {
var reference = new ModuleReference (ReadString ());
- reference.token = new MetadataToken (TokenType.ModuleRef, i);
+ reference.token = new MetadataToken (TokenType.ModuleRef, i + 1);
- references.Add (reference);
+ references [i] = reference;
}
+ }
- return references;
+ public Collection<ModuleReference> ReadModuleReferences ()
+ {
+ InitializeModuleReferences ();
+
+ return new Collection<ModuleReference> (metadata.ModuleReferences);
}
public bool HasFileResource ()
types.Add (type);
}
+ if (image.HasTable (Table.MethodPtr) || image.HasTable (Table.FieldPtr))
+ CompleteTypes ();
+
return types;
}
+ void CompleteTypes ()
+ {
+ var types = metadata.Types;
+
+ for (int i = 0; i < types.Length; i++) {
+ var type = types [i];
+
+ InitializeCollection (type.Fields);
+ InitializeCollection (type.Methods);
+ }
+ }
+
void InitializeTypeDefinitions ()
{
if (metadata.Types != null)
IMetadataScope GetTypeReferenceScope (MetadataToken scope)
{
switch (scope.TokenType) {
- // FIXME: both assembly refs and module refs should be in their
- // own arrays, in case of someone modify the collections before
- // this code is called
case TokenType.AssemblyRef:
- return module.AssemblyReferences [(int) scope.RID - 1];
+ InitializeAssemblyReferences ();
+ return metadata.AssemblyReferences [(int) scope.RID - 1];
case TokenType.ModuleRef:
- return module.ModuleReferences [(int) scope.RID - 1];
+ InitializeModuleReferences ();
+ return metadata.ModuleReferences [(int) scope.RID - 1];
case TokenType.Module:
return module;
default:
var fields = new MemberDefinitionCollection<FieldDefinition> (type, (int) fields_range.Length);
this.context = type;
- MoveTo (Table.Field, fields_range.Start);
- for (uint i = 0; i < fields_range.Length; i++)
- fields.Add (ReadField (fields_range.Start + i));
+ if (!MoveTo (Table.FieldPtr, fields_range.Start)) {
+ if (!MoveTo (Table.Field, fields_range.Start))
+ return fields;
+
+ for (uint i = 0; i < fields_range.Length; i++)
+ ReadField (fields_range.Start + i, fields);
+ } else
+ ReadPointers (Table.FieldPtr, Table.Field, fields_range, fields, ReadField);
return fields;
}
- FieldDefinition ReadField (uint field_rid)
+ void ReadField (uint field_rid, Collection<FieldDefinition> fields)
{
var attributes = (FieldAttributes) ReadUInt16 ();
var name = ReadString ();
field.token = new MetadataToken (TokenType.Field, field_rid);
metadata.AddFieldDefinition (field);
- return field;
+ if (IsDeleted (field))
+ return;
+
+ fields.Add (field);
}
void InitializeFields ()
metadata.RemoveEventsRange (type);
- if (range.Length == 0 || !MoveTo (Table.Event, range.Start))
+ if (range.Length == 0)
return events;
this.context = type;
- for (uint i = 0; i < range.Length; i++)
- events.Add (ReadEvent (range.Start + i));
+ if (!MoveTo (Table.EventPtr, range.Start)) {
+ if (!MoveTo (Table.Event, range.Start))
+ return events;
+
+ for (uint i = 0; i < range.Length; i++)
+ ReadEvent (range.Start + i, events);
+ } else
+ ReadPointers (Table.EventPtr, Table.Event, range, events, ReadEvent);
return events;
}
- EventDefinition ReadEvent (uint event_rid)
+ void ReadEvent (uint event_rid, Collection<EventDefinition> events)
{
var attributes = (EventAttributes) ReadUInt16 ();
var name = ReadString ();
var @event = new EventDefinition (name, attributes, event_type);
@event.token = new MetadataToken (TokenType.Event, event_rid);
- return @event;
+
+ if (IsDeleted (@event))
+ return;
+
+ events.Add (@event);
}
void InitializeEvents ()
var properties = new MemberDefinitionCollection<PropertyDefinition> (type, (int) range.Length);
- if (range.Length == 0 || !MoveTo (Table.Property, range.Start))
+ if (range.Length == 0)
return properties;
this.context = type;
- for (uint i = 0; i < range.Length; i++)
- properties.Add (ReadProperty (range.Start + i));
+ if (!MoveTo (Table.PropertyPtr, range.Start)) {
+ if (!MoveTo (Table.Property, range.Start))
+ return properties;
+ for (uint i = 0; i < range.Length; i++)
+ ReadProperty (range.Start + i, properties);
+ } else
+ ReadPointers (Table.PropertyPtr, Table.Property, range, properties, ReadProperty);
return properties;
}
- PropertyDefinition ReadProperty (uint property_rid)
+ void ReadProperty (uint property_rid, Collection<PropertyDefinition> properties)
{
var attributes = (PropertyAttributes) ReadUInt16 ();
var name = ReadString ();
property.HasThis = has_this;
property.token = new MetadataToken (TokenType.Property, property_rid);
- return property;
+ if (IsDeleted (property))
+ return;
+
+ properties.Add (property);
}
void InitializeProperties ()
return new MemberDefinitionCollection<MethodDefinition> (type);
var methods = new MemberDefinitionCollection<MethodDefinition> (type, (int) methods_range.Length);
+ if (!MoveTo (Table.MethodPtr, methods_range.Start)) {
+ if (!MoveTo (Table.Method, methods_range.Start))
+ return methods;
- MoveTo (Table.Method, methods_range.Start);
- for (uint i = 0; i < methods_range.Length; i++)
- ReadMethod (methods_range.Start + i, methods);
+ for (uint i = 0; i < methods_range.Length; i++)
+ ReadMethod (methods_range.Start + i, methods);
+ } else
+ ReadPointers (Table.MethodPtr, Table.Method, methods_range, methods, ReadMethod);
return methods;
}
+ void ReadPointers<TMember> (Table ptr, Table table, Range range, Collection<TMember> members, Action<uint, Collection<TMember>> reader)
+ where TMember : IMemberDefinition
+ {
+ for (uint i = 0; i < range.Length; i++) {
+ MoveTo (ptr, range.Start + i);
+
+ var rid = ReadTableIndex (table);
+ MoveTo (table, rid);
+
+ reader (rid, members);
+ }
+ }
+
+ static bool IsDeleted (IMemberDefinition member)
+ {
+ return member.IsSpecialName && member.Name == "_Deleted";
+ }
+
void InitializeMethods ()
{
if (metadata.Methods != null)
method.Name = ReadString ();
method.token = new MetadataToken (TokenType.Method, method_rid);
+ if (IsDeleted (method))
+ return;
+
methods.Add (method); // attach method
var signature = ReadBlobIndex ();
void ReadParameters (MethodDefinition method, Range param_range)
{
- MoveTo (Table.Param, param_range.Start);
- for (uint i = 0; i < param_range.Length; i++) {
- var attributes = (ParameterAttributes) ReadUInt16 ();
- var sequence = ReadUInt16 ();
- var name = ReadString ();
+ if (!MoveTo (Table.ParamPtr, param_range.Start)) {
+ if (!MoveTo (Table.Param, param_range.Start))
+ return;
+
+ for (uint i = 0; i < param_range.Length; i++)
+ ReadParameter (param_range.Start + i, method);
+ } else
+ ReadParameterPointers (method, param_range);
+ }
+
+ void ReadParameterPointers (MethodDefinition method, Range range)
+ {
+ for (uint i = 0; i < range.Length; i++) {
+ MoveTo (Table.ParamPtr, range.Start + i);
+
+ var rid = ReadTableIndex (Table.Param);
- var parameter = sequence == 0
- ? method.MethodReturnType.Parameter
- : method.Parameters [sequence - 1];
+ MoveTo (Table.Param, rid);
- parameter.token = new MetadataToken (TokenType.Param, param_range.Start + i);
- parameter.Name = name;
- parameter.Attributes = attributes;
+ ReadParameter (rid, method);
}
}
+ void ReadParameter (uint param_rid, MethodDefinition method)
+ {
+ var attributes = (ParameterAttributes) ReadUInt16 ();
+ var sequence = ReadUInt16 ();
+ var name = ReadString ();
+
+ var parameter = sequence == 0
+ ? method.MethodReturnType.Parameter
+ : method.Parameters [sequence - 1];
+
+ parameter.token = new MetadataToken (TokenType.Param, param_rid);
+ parameter.Name = name;
+ parameter.Attributes = attributes;
+ }
+
void ReadMethodSignature (uint signature, IMethodSignature method)
{
var reader = ReadSignature (signature);
range.Length++;
}
- if (owner != MetadataToken.Zero)
+ if (owner != MetadataToken.Zero && !ranges.ContainsKey (owner))
ranges.Add (owner, range);
return ranges;
return;
}
- reader.ReadByte ();
+ reader.position++;
var count = reader.ReadCompressedUInt32 ();
var attributes = new Collection<SecurityAttribute> ((int) count);
break;
}
- var exported_type = new ExportedType (@namespace, name, scope) {
+ var exported_type = new ExportedType (@namespace, name, module, scope) {
Attributes = attributes,
Identifier = (int) identifier,
DeclaringType = declaring_type,
IMetadataScope GetExportedTypeScope (MetadataToken token)
{
+ var position = this.position;
+ IMetadataScope scope;
+
switch (token.TokenType) {
case TokenType.AssemblyRef:
- return module.AssemblyReferences [(int) token.RID - 1];
+ InitializeAssemblyReferences ();
+ scope = metadata.AssemblyReferences [(int) token.RID - 1];
+ break;
case TokenType.File:
- var position = this.position;
- var reference = GetModuleReferenceFromFile (token);
- this.position = position;
-
- if (reference == null)
- throw new NotSupportedException ();
-
- return reference;
+ InitializeModuleReferences ();
+ scope = GetModuleReferenceFromFile (token);
+ break;
default:
throw new NotSupportedException ();
}
+
+ this.position = position;
+ return scope;
}
ModuleReference GetModuleReferenceFromFile (MetadataToken token)
var file_name = ReadString ();
var modules = module.ModuleReferences;
- ModuleReference reference = null;
+ ModuleReference reference;
for (int i = 0; i < modules.Count; i++) {
- var module_reference = modules [i];
- if (module_reference.Name != file_name)
- continue;
-
- reference = module_reference;
- break;
+ reference = modules [i];
+ if (reference.Name == file_name)
+ return reference;
}
+ reference = new ModuleReference (file_name);
+ modules.Add (reference);
return reference;
}
public void ReadMethodSignature (IMethodSignature method)
{
var calling_convention = ReadByte ();
+
+ const byte has_this = 0x20;
+ const byte explicit_this = 0x40;
+
+ if ((calling_convention & has_this) != 0) {
+ method.HasThis = true;
+ calling_convention = (byte) (calling_convention & ~has_this);
+ }
+
+ if ((calling_convention & explicit_this) != 0) {
+ method.ExplicitThis = true;
+ calling_convention = (byte) (calling_convention & ~explicit_this);
+ }
+
method.CallingConvention = (MethodCallingConvention) calling_convention;
- method.HasThis = (calling_convention & 0x20) != 0;
- method.ExplicitThis = (calling_convention & 0x40) != 0;
var generic_context = method as MethodReference;
if (generic_context != null)
CheckGenericContext (generic_context, (int) arity -1 );
}
- // TODO: more call_conv
-
var param_count = ReadCompressedUInt32 ();
method.MethodReturnType.ReturnType = ReadTypeSignature ();
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
SignatureWriter GetSecurityDeclarationSignature (SecurityDeclaration declaration)
{
var signature = CreateSignatureWriter ();
- if (!declaration.resolved) {
- signature.WriteBytes (declaration.GetBlob ());
- return signature;
- }
-
- signature.WriteByte ((byte) '.');
-
- var attributes = declaration.security_attributes;
- if (attributes == null)
- throw new NotSupportedException ();
- signature.WriteCompressedUInt32 ((uint) attributes.Count);
-
- for (int i = 0; i < attributes.Count; i++)
- signature.WriteSecurityAttribute (attributes [i]);
+ if (!declaration.resolved)
+ signature.WriteBytes (declaration.GetBlob ());
+ else if (module.Runtime < TargetRuntime.Net_2_0)
+ signature.WriteXmlSecurityDeclaration (declaration);
+ else
+ signature.WriteSecurityDeclaration (declaration);
return signature;
}
WriteCustomAttributeFixedArgument (argument.Type, argument);
}
- public void WriteSecurityAttribute (SecurityAttribute attribute)
+ void WriteSecurityAttribute (SecurityAttribute attribute)
{
WriteTypeReference (attribute.AttributeType);
WriteBytes (buffer);
}
+ public void WriteSecurityDeclaration (SecurityDeclaration declaration)
+ {
+ WriteByte ((byte) '.');
+
+ var attributes = declaration.security_attributes;
+ if (attributes == null)
+ throw new NotSupportedException ();
+
+ WriteCompressedUInt32 ((uint) attributes.Count);
+
+ for (int i = 0; i < attributes.Count; i++)
+ WriteSecurityAttribute (attributes [i]);
+ }
+
+ public void WriteXmlSecurityDeclaration (SecurityDeclaration declaration)
+ {
+ var xml = GetXmlSecurityDeclaration (declaration);
+ if (xml == null)
+ throw new NotSupportedException ();
+
+ WriteBytes (Encoding.Unicode.GetBytes (xml));
+ }
+
+ static string GetXmlSecurityDeclaration (SecurityDeclaration declaration)
+ {
+ if (declaration.security_attributes == null || declaration.security_attributes.Count != 1)
+ return null;
+
+ var attribute = declaration.security_attributes [0];
+
+ if (!attribute.AttributeType.IsTypeOf ("System.Security.Permissions", "PermissionSetAttribute"))
+ return null;
+
+ if (attribute.properties == null || attribute.properties.Count != 1)
+ return null;
+
+ var property = attribute.properties [0];
+ if (property.Name != "XML")
+ return null;
+
+ return (string) property.Argument.Value;
+ }
+
void WriteTypeReference (TypeReference type)
{
WriteUTF8String (TypeParser.ToParseable (type));
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
}
}
+ public class AssemblyResolutionException : FileNotFoundException {
+
+ readonly AssemblyNameReference reference;
+
+ public AssemblyNameReference AssemblyReference {
+ get { return reference; }
+ }
+
+ public AssemblyResolutionException (AssemblyNameReference reference)
+ : base (string.Format ("Failed to resolve assembly: '{0}'", reference))
+ {
+ this.reference = reference;
+ }
+ }
+
public abstract class BaseAssemblyResolver : IAssemblyResolver {
static readonly bool on_mono = Type.GetType ("Mono.Runtime") != null;
return assembly;
}
- throw new FileNotFoundException ("Could not resolve: " + name);
+ throw new AssemblyResolutionException (name);
}
AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable<string> directories, ReaderParameters parameters)
static string GetAssemblyFile (AssemblyNameReference reference, string prefix, string gac)
{
- var gac_folder = new StringBuilder ();
- gac_folder.Append (prefix);
- gac_folder.Append (reference.Version);
- gac_folder.Append ("__");
+ var gac_folder = new StringBuilder ()
+ .Append (prefix)
+ .Append (reference.Version)
+ .Append ("__");
+
for (int i = 0; i < reference.PublicKeyToken.Length; i++)
gac_folder.Append (reference.PublicKeyToken [i].ToString ("x2"));
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
using System;
using System.Text;
+using Mono.Collections.Generic;
+
namespace Mono.Cecil {
- public sealed class CallSite : MethodReference {
+ public sealed class CallSite : IMethodSignature {
+
+ readonly MethodReference signature;
- public override string FullName {
+ public bool HasThis {
+ get { return signature.HasThis; }
+ set { signature.HasThis = value; }
+ }
+
+ public bool ExplicitThis {
+ get { return signature.ExplicitThis; }
+ set { signature.ExplicitThis = value; }
+ }
+
+ public MethodCallingConvention CallingConvention {
+ get { return signature.CallingConvention; }
+ set { signature.CallingConvention = value; }
+ }
+
+ public bool HasParameters {
+ get { return signature.HasParameters; }
+ }
+
+ public Collection<ParameterDefinition> Parameters {
+ get { return signature.Parameters; }
+ }
+
+ public TypeReference ReturnType {
+ get { return signature.MethodReturnType.ReturnType; }
+ set { signature.MethodReturnType.ReturnType = value; }
+ }
+
+ public MethodReturnType MethodReturnType {
+ get { return signature.MethodReturnType; }
+ }
+
+ public string Name {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public string Namespace {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public ModuleDefinition Module {
+ get { return ReturnType.Module; }
+ }
+
+ public IMetadataScope Scope {
+ get { return signature.ReturnType.Scope; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return signature.token; }
+ set { signature.token = value; }
+ }
+
+ public string FullName {
get {
var signature = new StringBuilder ();
signature.Append (ReturnType.FullName);
}
}
- public override ModuleDefinition Module {
- get { return ReturnType.Module; }
+ internal CallSite ()
+ {
+ this.signature = new MethodReference ();
+ this.signature.token = new MetadataToken (TokenType.Signature, 0);
+ }
+
+ public CallSite (TypeReference returnType)
+ : this ()
+ {
+ if (returnType == null)
+ throw new ArgumentNullException ("returnType");
+
+ this.signature.ReturnType = returnType;
}
- public override MethodDefinition Resolve ()
+ public override string ToString ()
{
- return null;
+ return FullName;
}
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
module.Read (this, (@event, reader) => reader.ReadMethods (@event));
}
+
+ public override EventDefinition Resolve ()
+ {
+ return this;
+ }
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
event_type = eventType;
}
+
+ public abstract EventDefinition Resolve ();
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
string name;
uint attributes;
IMetadataScope scope;
+ ModuleDefinition module;
int identifier;
ExportedType declaring_type;
internal MetadataToken token;
}
}
- public ExportedType (string @namespace, string name, IMetadataScope scope)
+ public ExportedType (string @namespace, string name, ModuleDefinition module, IMetadataScope scope)
{
this.@namespace = @namespace;
this.name = name;
this.scope = scope;
+ this.module = module;
}
public override string ToString ()
{
return FullName;
}
+
+ public TypeDefinition Resolve ()
+ {
+ return module.Resolve (CreateReference ());
+ }
+
+ internal TypeReference CreateReference ()
+ {
+ return new TypeReference (@namespace, name, module, scope) {
+ DeclaringType = declaring_type != null ? declaring_type.CreateReference () : null,
+ };
+ }
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
}
public Collection<TypeReference> GenericArguments {
- get {
- if (arguments == null)
- arguments = new Collection<TypeReference> ();
-
- return arguments;
- }
+ get { return arguments ?? (arguments = new Collection<TypeReference> ()); }
}
public override bool IsGenericInstance {
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
}
public Collection<TypeReference> GenericArguments {
- get {
- if (arguments == null)
- arguments = new Collection<TypeReference> ();
-
- return arguments;
- }
+ get { return arguments ?? (arguments = new Collection<TypeReference> ()); }
}
public override TypeReference DeclaringType {
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); }
}
- internal new bool HasImage {
- get { return Module != null && Module.HasImage; }
- }
-
public override IMetadataScope Scope {
get {
if (owner.GenericParameterType == GenericParameterType.Method)
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
if (assembly == null)
return null;
- return GetType (assembly.MainModule, type);
+ return GetType (resolver, assembly.MainModule, type);
case MetadataScopeType.ModuleDefinition:
- return GetType ((ModuleDefinition) scope, type);
+ return GetType (resolver, (ModuleDefinition) scope, type);
case MetadataScopeType.ModuleReference:
var modules = type.Module.Assembly.Modules;
var module_ref = (ModuleReference) scope;
for (int i = 0; i < modules.Count; i++) {
var netmodule = modules [i];
if (netmodule.Name == module_ref.Name)
- return GetType (netmodule, type);
+ return GetType (resolver, netmodule, type);
}
break;
}
throw new NotSupportedException ();
}
+ static TypeDefinition GetType (IAssemblyResolver resolver, ModuleDefinition module, TypeReference reference)
+ {
+ var type = GetType (module, reference);
+ if (type != null)
+ return type;
+
+ if (!module.HasExportedTypes)
+ return null;
+
+ var exported_types = module.ExportedTypes;
+
+ for (int i = 0; i < exported_types.Count; i++) {
+ var exported_type = exported_types [i];
+ if (exported_type.Name != reference.Name)
+ continue;
+
+ if (exported_type.Namespace != reference.Namespace)
+ continue;
+
+ return exported_type.Resolve ();
+ }
+
+ return null;
+ }
+
static TypeDefinition GetType (ModuleDefinition module, TypeReference type)
{
if (!type.IsNested)
if (method.Name != reference.Name)
continue;
+ if (method.HasGenericParameters != reference.HasGenericParameters)
+ continue;
+
+ if (method.HasGenericParameters && method.GenericParameters.Count != reference.GenericParameters.Count)
+ continue;
+
if (!AreSame (method.ReturnType, reference.ReturnType))
continue;
static bool AreSame (GenericInstanceType a, GenericInstanceType b)
{
- if (!a.HasGenericArguments)
- return !b.HasGenericArguments;
-
- if (!b.HasGenericArguments)
- return false;
-
if (a.GenericArguments.Count != b.GenericArguments.Count)
return false;
static bool AreSame (TypeReference a, TypeReference b)
{
+ if (ReferenceEquals (a, b))
+ return true;
+
+ if (a == null || b == null)
+ return false;
+
if (a.etype != b.etype)
return false;
if (a.IsTypeSpecification ())
return AreSame ((TypeSpecification) a, (TypeSpecification) b);
- return a.FullName == b.FullName;
+ if (a.Name != b.Name || a.Namespace != b.Namespace)
+ return false;
+
+ //TODO: check scope
+
+ return AreSame (a.DeclaringType, b.DeclaringType);
}
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
sealed class MetadataSystem {
+ internal AssemblyNameReference [] AssemblyReferences;
+ internal ModuleReference [] ModuleReferences;
+
internal TypeDefinition [] Types;
internal TypeReference [] TypeReferences;
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
if (!HasImage)
return false;
- return Read (this, (_, reader) => reader.GetTypeReference (scope, fullName) != null);
+ return GetTypeReference (scope, fullName) != null;
}
public bool TryGetTypeReference (string fullName, out TypeReference type)
return false;
}
- return (type = Read (this, (_, reader) => reader.GetTypeReference (scope, fullName))) != null;
+ return (type = GetTypeReference (scope, fullName)) != null;
+ }
+
+ TypeReference GetTypeReference (string scope, string fullname)
+ {
+ return Read (new Row<string, string> (scope, fullname), (row, reader) => reader.GetTypeReference (row.Col1, row.Col2));
}
public IEnumerable<TypeReference> GetTypeReferences ()
return ((TypeDefinitionCollection) this.Types).GetType (@namespace ?? string.Empty, name);
}
+ public IEnumerable<TypeDefinition> GetTypes ()
+ {
+ return GetTypes (Types);
+ }
+
+ static IEnumerable<TypeDefinition> GetTypes (Collection<TypeDefinition> types)
+ {
+ for (int i = 0; i < types.Count; i++) {
+ var type = types [i];
+
+ yield return type;
+
+ if (!type.HasNestedTypes)
+ continue;
+
+ foreach (var nested in GetTypes (type.NestedTypes))
+ yield return nested;
+ }
+ }
+
static void CheckFullName (string fullName)
{
if (fullName == null)
public IMetadataTokenProvider LookupToken (MetadataToken token)
{
- return Read (this, (_, reader) => reader.LookupToken (token));
+ return Read (token, (t, reader) => reader.LookupToken (t));
}
internal TRet Read<TItem, TRet> (TItem item, Func<TItem, MetadataReader, TRet> read)
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
BestFitMask = 0x0030,
BestFitEnabled = 0x0010,
- BestFidDisabled = 0x0020,
+ BestFitDisabled = 0x0020,
ThrowOnUnmappableCharMask = 0x3000,
ThrowOnUnmappableCharEnabled = 0x1000,
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.CallConvMask, (ushort) PInvokeAttributes.CallConvFastcall, value); }
}
- public bool IsBestFistEnabled {
+ public bool IsBestFitEnabled {
get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFitEnabled); }
set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFitEnabled, value); }
}
- public bool IsBestFistDisabled {
- get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFidDisabled); }
- set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFidDisabled, value); }
+ public bool IsBestFitDisabled {
+ get { return attributes.GetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFitDisabled); }
+ set { attributes = attributes.SetMaskedAttributes ((ushort) PInvokeAttributes.BestFitMask, (ushort) PInvokeAttributes.BestFitDisabled, value); }
}
public bool IsThrowOnUnmappableCharEnabled {
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
get { return method; }
}
+ public int Sequence {
+ get {
+ if (method == null)
+ return -1;
+
+ return method.HasThis ? index + 1 : index;
+ }
+ }
+
public bool HasConstant {
get {
ResolveConstant ();
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
public bool HasParameters {
get {
+ InitializeMethods ();
+
if (get_method != null)
return get_method.HasParameters;
module.Read (this, (property, reader) => reader.ReadMethods (property));
}
+
+ public override PropertyDefinition Resolve ()
+ {
+ return this;
+ }
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
property_type = propertyType;
}
+
+ public abstract PropertyDefinition Resolve ();
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
if (!HasImage || signature == 0)
throw new NotSupportedException ();
- return module.Read (this, (declaration, reader) => reader.ReadSecurityDeclarationBlob (declaration.signature)); ;
+ return module.Read (this, (declaration, reader) => reader.ReadSecurityDeclarationBlob (declaration.signature));
}
void Resolve ()
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
}
}
- internal new bool HasImage {
- get { return Module != null && Module.HasImage; }
- }
-
public bool HasMethods {
get {
if (methods != null)
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
SplitFullName (type_info.type_fullname, out @namespace, out name);
var type = new TypeReference (@namespace, name, module, scope);
+ MetadataSystem.TryProcessPrimitiveType (type);
AdjustGenericParameters (type);
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
if (metadata.Types == null)
Initialize (module.Types);
- return module.Read (this, (_, reader) => {
+ return module.Read (new Row<string, string> (@namespace, name), (row, reader) => {
var types = reader.metadata.Types;
for (int i = 0; i < types.Length; i++) {
var type = types [i];
- if (type.Name == name && type.Namespace == @namespace)
+ if (type.Name == row.Col2 && type.Namespace == row.Col1)
return type;
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
public Collection (ICollection<T> items)
{
+ if (items == null)
+ throw new ArgumentNullException ("items");
+
this.items = new T [items.Count];
items.CopyTo (this.items, 0);
this.size = this.items.Length;
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
using System;
using System.Collections;
+using System .Collections.Generic;
namespace Mono.Collections.Generic {
- public sealed class ReadOnlyCollection<T> : Collection<T>, IList {
+ public sealed class ReadOnlyCollection<T> : Collection<T>, ICollection<T>, IList {
static ReadOnlyCollection<T> empty;
get { return empty ?? (empty = new ReadOnlyCollection<T> ()); }
}
+ bool ICollection<T>.IsReadOnly {
+ get { return true; }
+ }
+
+ bool IList.IsFixedSize {
+ get { return true; }
+ }
+
bool IList.IsReadOnly {
get { return true; }
}
if (array == null)
throw new ArgumentNullException ();
- this.items = array;
- this.size = array.Length;
+ Initialize (array, array.Length);
}
public ReadOnlyCollection (Collection<T> collection)
if (collection == null)
throw new ArgumentNullException ();
- this.items = collection.items;
- this.size = collection.size;
+ Initialize (collection.items, collection.size);
+ }
+
+ void Initialize (T [] items, int size)
+ {
+ this.items = new T [size];
+ Array.Copy (items, 0, this.items, 0, size);
+ this.size = size;
}
internal override void Grow (int desired)
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
namespace Mono {
//delegate void Action ();
- //delegate void Action<T1, T2> (T1 arg1, T2 arg2);
+ delegate void Action<T1, T2> (T1 arg1, T2 arg2);
//delegate void Action<T1, T2, T3> (T1 arg1, T2 arg2, T3 arg3);
//delegate void Action<T1, T2, T3, T4> (T1 arg1, T2 arg2, T3 arg3, T4 arg4);
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
-using System.Collections;
-using System.Collections.Generic;
+using Mono.Collections.Generic;
namespace Mono {
return self == null || self.Length == 0;
}
- public static bool IsNullOrEmpty<T> (this ICollection<T> self)
+ public static bool IsNullOrEmpty<T> (this Collection<T> self)
{
- return self == null || self.Count == 0;
+ return self == null || self.size == 0;
}
}
}
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// Author:
// Jb Evain (jbevain@gmail.com)
//
-// Copyright (c) 2008 - 2010 Jb Evain
+// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
-5f427237847cd9acb3bb14317c83f7c67a04ab41
+90e481c594502333d400226b3d4198dfd26964b2