예제 #1
0
 public Opcode(string name, object paramval)
 {
     Name = name;
     ParamVal = paramval;
     Prefix = null;
     IsPrefix = false;
     NeedsLabel = false;
 }
예제 #2
0
 Opcode OpcodeNoParamVal(string s)
 {
     var NewOp =  new Opcode(s);
     MakeLabel(NewOp);
     return NewOp;
 }
예제 #3
0
 public Opcode(string name)
 {
     Name = name;
     Prefix = null;
     IsPrefix = false;
     NeedsLabel = false;
 }
예제 #4
0
        Opcode OpcodeFourByte(string s)
        {
            // This gets the parameter (stored as b) from the byte[]
            byte[] b = new byte[4];
            for (int k = 0; k < 4; k++)
            {
                b[k] = IL[pos];
                pos++;
            }
            int i = BitConverter.ToInt32(b,0);

            var NewOp =  new Opcode(s,i);
            MakeLabel(NewOp);
            return NewOp;
        }
예제 #5
0
        Opcode OpcodeIndx(string s)
        {
            // This gets the parameter (stored as b) from the byte[]
            byte[] b = new byte[2];
            for (int k = 0; k < 2; k++)
            {
                b[k] = IL[pos];
                pos++;
            }
            short i = BitConverter.ToInt16(b,0);
            var ind = new Index("V_" + i);

            var NewOp =  new Opcode(s,i);
            MakeLabel(NewOp);
            return NewOp;
        }
예제 #6
0
 void MakeLabel(Opcode op)
 {
     op.Label = string.Format("IL_{0:x4}", pos1);
 }
예제 #7
0
        Opcode OpcodeEightByte(string s)
        {
            // This gets the parameter (stored as b) from the byte[]
            byte[] b = new byte[8];
            for (int k = 0; k < 8; k++)
            {
                b[k] = IL[pos];
                pos++;
            }
            long i = BitConverter.ToInt64(b,0);

            var NewOp =  new Opcode(s,i);
            MakeLabel(NewOp);
            return NewOp;
        }
예제 #8
0
 Opcode OpcodeTok(string s)
 {
     // This gets the parameter (stored as b) from the byte[]
     byte[] b = new byte[4];
     for (int k = 0; k < 4; k++)
     {
         b[k] = IL[pos];
         pos++;
     }
     // This calls the appropriate Opcode method depending on what sort of parameter we're dealing with.
     // This is determined by the least byte of the byte[]
     if (b[3] == 4)
     {
         pos -=4;
         return OpcodeFld(s);
     }
     if ((b[3] == 6)||(b[3] == 10))
     {
         pos -=4;
         return OpcodeMeth(s);
     }
     if ((b[3] == 1)||(b[3]==2) || (b[3]==0x1b)) //0x1b is testspec.
     {
         pos -=4;
         return OpcodeType(s);
     }
     Opcode NewOp =  new Opcode(s,b);
     MakeLabel(NewOp);
     return NewOp;
 }
예제 #9
0
        Opcode OpcodeTwoByte(string s)
        {
            // This gets the parameter (stored as b) from the byte[]
            byte[] b = new byte[2];
            for (int k = 0; k < 2; k++)
            {
                b[k] = IL[pos];
                pos++;
            }
            ushort i = BitConverter.ToUInt16(b,0);

            var NewOp =  new Opcode(s,i);
            MakeLabel(NewOp);								// This labels the Opcode
            return NewOp;
        }
예제 #10
0
 Opcode OpcodeTarget(string s)
 {
     // This gets the parameter (stored as b) from the byte[]
     byte[] b  = new byte[4];
     for (int k = 0; k < 4; k++)
     {
         b[k] = IL[pos];
         pos++;
     }
     int l = BitConverter.ToInt32(b,0);
     int TPos = l + pos;
     string s1 =string.Format("IL_{0:x4}", TPos);
     var NewOp =  new Opcode(s,new Target(s1));
     MakeLabel(NewOp);
     return NewOp;
 }
예제 #11
0
 Opcode OpcodeTargetS(string s)
 {
     // This gets the parameter (stored as b) from the byte[]
     sbyte k = (sbyte)IL[pos];
     pos++;
     int b = (int)((sbyte)k + (int)pos);
     string s1 =string.Format("IL_{0:x4}", b);
     var NewOp =  new Opcode(s,new Target(s1));
     MakeLabel(NewOp);
     return NewOp;
 }
예제 #12
0
 Opcode OpcodeSwitch(string s)
 {
     // This gets the number of parameters (stored as b) from the byte[]
     // Each parameter is then added to the ArrayList T
     var T = new ArrayList();
     byte[] b = new byte[4];
     for (int k = 0; k < 4; k++)
     {
         b[k] = IL[pos];
         pos++;
     }
     int i = BitConverter.ToInt32(b,0);				// This tells us how many parameters to expect.
     for (int k = 0; k < i; k++)						// Each parameter will be a four-byte offset
     {
         for (int k1 = 0; k1 < 4; k1++)
         {
             b[k1] = IL[pos];
             pos++;
         }
         int j = BitConverter.ToInt32(b,0);
         string s1 =string.Format("IL_{0:x4}", pos1 + j + 4*i + 5);
         T.Add(new Target(s1));
     }
     var NewOp =  new Opcode(s,T);
     MakeLabel(NewOp);
     return NewOp;
 }
예제 #13
0
 Opcode OpcodeSig(string s)
 {
     // TODO : Resolve this token!
     // This gets the parameter (stored as b) from the byte[]
     byte[] b = new byte[4];
     for (int k = 0; k < 4; k++)
     {
         b[k] = IL[pos];
         pos++;
     }
     var NewOp =  new Opcode(s,b);
     MakeLabel(NewOp);
     return NewOp;
 }
예제 #14
0
 Opcode OpcodeOneByte(string s)
 {
     // This gets the parameter (stored as b) from the byte[]
     byte b = IL[pos];
     pos++;
     var NewOp =  new Opcode(s,b);
     MakeLabel(NewOp);
     return NewOp;
 }
예제 #15
0
 public Opcode(string name, ArrayList paramlist)
 {
     Name = name;
     ParamVal = paramlist;
     Prefix = null;
     IsPrefix = false;
     NeedsLabel = false;
 }
예제 #16
0
        Opcode OpcodeType(string s)
        {
            // This gets the parameter (stored as b) from the byte[]
            byte[] b = new byte[4];
            for (int k = 0; k < 4; k++)
            {
                b[k] = IL[pos];
                pos++;
            }
            Type RetType = (Type)curModule.ResolveMember(BitConverter.ToInt32(b,0));

            var NewOp =  new Opcode(s,RetType);
            MakeLabel(NewOp);
            return NewOp;
        }
예제 #17
0
 public Label ToLabel(ArrayList Opcodes)
 {
     Opcode Op1 = new Opcode();
     foreach(Opcode OP in Opcodes)
     {
         if (Name == OP.Label) return OP.ILLabel;
     }
     return Op1.ILLabel;
 }
예제 #18
0
 Opcode Prefix(string s)
 {
     var OpPre = new Opcode(s);
     MakeLabel(OpPre);							// This labels the Opcode
     OpPre.IsPrefix = true;							// Here we designate the Opcode as a prefix
     Opcode Next = GetOpcode();
     Next.Label = "";
     Next.Prefix = OpPre;
     return Next;
 }
예제 #19
0
 void MakeLabel(Opcode op, bool label)
 {
     if (!label)
         op.Label = "IL_XXXX";
     else MakeLabel(op);
 }
예제 #20
0
 Opcode PrefixParamVal(string s)
 {
     // This gets the parameter (stored as b) from the byte[]
     byte b = IL[pos];
     pos++;
     var OpPre = new Opcode(s,b);
     MakeLabel(OpPre);							// This labels the Opcode
     OpPre.IsPrefix = true;							// Here we designate the Opcode as a prefix
     Opcode Next = GetOpcode();
     Next.Label = "";
     Next.Prefix = OpPre;
     return Next;
 }
예제 #21
0
 Opcode OpcodeFld(string s)
 {
     // This gets the parameter (stored as b) from the byte[]
     byte[] b = new byte[4];
     for (int k = 0; k < 4; k++)
     {
         b[k] = IL[pos];
         pos++;
     }
     // We have to temporarily take out stfld field here.
     // the stfld's order must be fixed up
     FieldInfo ReturnField = (FieldInfo)curModule.ResolveMember(BitConverter.ToInt32(b,0));
     var NewOp =  new Opcode(s,ReturnField);
     if (s.Equals("stfld"))
     {
         StfldList.Add(NewOp.ParamVal);
         return NewOp;
     }
     else
     {
         MakeLabel(NewOp);
         return NewOp;
     }
 }
예제 #22
0
        public ILReader(MethodBase InputMethod, FieldInfo[] FieldsInModule, MethodBase[] MethodsInModule, Assembly currentAssm)
        {
            workingAssm = currentAssm;
            MethodOpcodes = new ArrayList();
            InputMeth = InputMethod;
            ExceptionHandlers = new ArrayList();

            if (InputMethod == null)
            {
                Console.WriteLine("Error, input method is not specified, can not continue");
                return;
            }
            methodBody = InputMethod.GetMethodBody();
            curModule = InputMethod.DeclaringType.Module;

            pos = 0;
            pos1 = 0;

            IL = methodBody.GetILAsByteArray();

            IList<ExceptionHandlingClause>  ehClauses = methodBody.ExceptionHandlingClauses;
            foreach( ExceptionHandlingClause ehclause in ehClauses )
            {
                ExceptionHandlers.Add(new ExceptionInstruction(ehclause.TryOffset,ExceptionHandler.Try,null));
                switch (ehclause.Flags)
                {
                    //case 0:
                    case ExceptionHandlingClauseOptions.Clause:
                        ExceptionHandlers.Add(new ExceptionInstruction(ehclause.HandlerOffset,ExceptionHandler.Catch,ehclause.CatchType));
                        ExceptionHandlers.Add(new ExceptionInstruction(ehclause.HandlerOffset+ehclause.HandlerLength,ExceptionHandler.EndException,null));
                    break;
                    //case 1:
                case ExceptionHandlingClauseOptions.Filter:
                    ExceptionHandlers.Add(new ExceptionInstruction(ehclause.FilterOffset,ExceptionHandler.Filter,null));
                        ExceptionHandlers.Add(new ExceptionInstruction(ehclause.HandlerOffset,ExceptionHandler.EndFilter,null));
                        ExceptionHandlers.Add(new ExceptionInstruction(ehclause.HandlerOffset+ehclause.HandlerLength,ExceptionHandler.EndException,null));
                        break;
                    //case 2:
                    case ExceptionHandlingClauseOptions.Finally:
                        ExceptionHandlers.Add(new ExceptionInstruction(ehclause.HandlerOffset,ExceptionHandler.Finally,null));
                        ExceptionHandlers.Add(new ExceptionInstruction(ehclause.HandlerOffset+ehclause.HandlerLength,ExceptionHandler.EndException,null));
                        break;
                    //case 4:
                    case ExceptionHandlingClauseOptions.Fault:
                        ExceptionHandlers.Add(new ExceptionInstruction(ehclause.HandlerOffset,ExceptionHandler.Fault,null));
                        ExceptionHandlers.Add(new ExceptionInstruction(ehclause.HandlerOffset+ehclause.HandlerLength,ExceptionHandler.EndException,null));
                        break;
                }
            }
            // populate opcode
            Opcode Op = GetOpcode();
            while (Op.Name != "")												// This cycles through all the Opcodes
            {
                if (Op.Name != "stfld")
                    MethodOpcodes.Add(Op);
                Op = GetOpcode();
            }
            // sort the stfld opcodes and output
            // this will make the opcode invalid for run.
            // but out purpose is simply compare the assemblies.
            StfldList.Sort(new StringCompare());
            foreach (object i in StfldList)
            {
                Opcode temp = new Opcode("stfld", i);
                MakeLabel(temp, false);
                MethodOpcodes.Add(temp);
            }
        }
예제 #23
0
        Opcode OpcodeFourByteF(string s)
        {
            // This gets the parameter (stored as b) from the byte[]
            byte[] b = new byte[8];
            for (int k = 0; k < 4; k++)
            {
                b[k] = IL[pos];
                pos++;
            }

            var NewOp =  new Opcode(s,BitConverter.ToDouble(b,0));
            MakeLabel(NewOp);								// This labels the Opcode
            return NewOp;
        }
예제 #24
0
 public Opcode()
 {
     ParamVal = null;
     Prefix = null;
     IsPrefix = false;
     NeedsLabel = false;
 }
예제 #25
0
 Opcode OpcodeIndxS(string s)
 {
     // This gets the parameter (stored as b) from the byte[]
     byte b = IL[pos];
     pos++;
     var ind = new Index("V_" + b);
     var NewOp =  new Opcode(s,b);
     MakeLabel(NewOp);
     return NewOp;
 }
예제 #26
0
 Opcode OpcodeMeth(string s)
 {
     // This gets the parameter (stored as b) from the byte[]
     byte[] b = new byte[4];
     Array.Copy(IL, pos, b, 0, 4);
     pos+=4;
     MethodBase mbase = (MethodBase)curModule.ResolveMember(BitConverter.ToInt32(b,0));
     var NewOp = new Opcode(s, mbase);
     NewOp.workingAssm = this.workingAssm;
     NewOp.workingType = this.InputMeth.DeclaringType;
     MakeLabel(NewOp);															// This labels the Opcode
     return NewOp;
 }