示例#1
0
 private XMLInstruction(ILManager manager, MethodDefinition workingMethod, IList <T> workingInstructionList, Func <IList <T>, Instruction, int> indexFinder)
 {
     this.manager                = manager;
     this.workingMethod          = workingMethod;
     this.workingInstructionList = workingInstructionList;
     this.indexFinder            = indexFinder;
     postinitbrs = new List <PostInitData>();
     initType    = XMLIType.Unknown;
 }
示例#2
0
        public DataStruct()
        {
            PatchActionList  = new List <PatchAction>();
            TargetFinderList = new List <TargetFinder>();
            PatchEntryList   = new List <PatchEntry>();
            ReferenceTable   = new ILManager(this);
            ILNodeManager    = new ILNodeManager(this);
            EntryFactory     = new EntryFactory(this);

            ClearASM();
        }
示例#3
0
 public XMLInstruction(ILManager manager, MethodDefinition workingMethod)
     : this(manager, workingMethod, null, null)
 {
     initType = XMLIType.ReadOnly;
 }
示例#4
0
 public XMLInstruction(ILManager manager, IList <T> workingInstructionList, Func <IList <T>, Instruction, int> indexFinder)
     : this(manager, null, workingInstructionList, indexFinder)
 {
     initType = XMLIType.WriteOnly;
 }
示例#5
0
        /// <summary>Reads an XmlNode and creates an Instruction from the data</summary>
        /// <param name="xOperandNode">The XmlElement containing the operand info, created by Operand2Node</param>
        /// <param name="opcode">The OpCode the new Instruction should have, independently of the XmlElement</param>
        /// <param name="nInstructionNum">The NewInstructionNum the Instruction will have after the patch (InstructionInfo.NewInstructionNum)</param>
        /// <param name="postinitbrs">A reference to the PostInitData list, in order to load branch Instructions correctly</param>
        /// <returns>Returns the new Instruction if succeeded, null otherwise</returns>
        public Instruction Node2Instruction(XmlNode xOperandNode, OpCode opcode, int nInstructionNum)
        {
            if (initType != XMLIType.ReadOnly)
            {
                throw new InvalidOperationException("Wrong XMLI constructor used.");
            }

            switch (opcode.OperandType)
            {
            case OperandType.InlineNone:
                return(ILManager.GenInstruction(opcode, null));

            case OperandType.InlineI:
            case OperandType.InlineI8:
            case OperandType.InlineR:
            case OperandType.InlineString:
            case OperandType.ShortInlineI:
            case OperandType.ShortInlineR:
                string primVal;
                if (xOperandNode.GetAttribute(SST.PrimitiveValue, out primVal))
                {
                    return(ILManager.GenInstruction(opcode, primVal));
                }
                else
                {
                    Log.Write(Log.Level.Error, $"Expected 'PrimitiveValue' with \"{opcode.Name}\", but no matching Attribute was found in \"{xOperandNode.InnerXml}\"");
                }
                break;

            case OperandType.InlineField:
            case OperandType.InlineMethod:
            case OperandType.InlineTok:
            case OperandType.InlineType:
                string opVal = xOperandNode.GetAttribute(SST.Resolve);
                if (!string.IsNullOrEmpty(opVal))
                {
                    return(ILManager.GenInstruction(opcode, manager.Resolve(opVal.ToBaseInt())));
                }
                else
                {
                    Log.Write(Log.Level.Error, $"Expected 'Resolve' with \"{opcode.Name}\", but no matching Attribute was found in \"{xOperandNode.InnerXml}\"");
                }
                break;

            case OperandType.InlineArg:
            case OperandType.ShortInlineArg:
                string[] parArrVal = xOperandNode.GetAttribute(SST.Resolve).Split(' ');
                if (parArrVal.Length != 2)
                {
                    int parIndexVal = int.Parse(parArrVal[0]);
                    //object parTypVal = ILManager.Instance.Resolve(parArrVal[1].ToBaseInt());
                    return(ILManager.GenInstruction(opcode, workingMethod.Parameters[parIndexVal]));
                }
                else
                {
                    Log.Write(Log.Level.Error, $"Expected 'Resolve' with \"{opcode.Name}\", but the Attribute is either missing or incorrect in \"{xOperandNode.InnerXml}\"");
                }
                break;

            case OperandType.InlineVar:
            case OperandType.ShortInlineVar:
                string[] varArrVal = xOperandNode.GetAttribute(SST.Resolve).Split(' ');
                if (varArrVal.Length != 2)
                {
                    int varIndexVal = int.Parse(varArrVal[0]);
                    //object varTypVal = ILManager.Instance.Resolve(varArrVal[1].ToBaseInt());
                    return(ILManager.GenInstruction(opcode, workingMethod.Parameters[varIndexVal]));
                }
                else
                {
                    Log.Write(Log.Level.Error, $"Expected 'Resolve' with \"{opcode.Name}\", but the Attribute is either missing or incorrect in \"{xOperandNode.InnerXml}\"");
                }
                break;

            case OperandType.InlineBrTarget:
            case OperandType.ShortInlineBrTarget:
                string briVal = xOperandNode.GetAttribute(SST.BrTargetIndex);
                if (!string.IsNullOrEmpty(briVal))
                {
                    PostInitData pid = new PostInitData();
                    pid.InstructionNum = nInstructionNum;
                    pid.isArray        = false;
                    pid.targetNum      = int.Parse(briVal);
                    postinitbrs.Add(pid);
                    ILManager.GenInstruction(opcode, Instruction.Create(OpCodes.Nop));
                }
                break;

            case OperandType.InlineSwitch:
                string braVal = xOperandNode.GetAttribute(SST.BrTargetArray);
                if (!string.IsNullOrEmpty(braVal))
                {
                    PostInitData pid = new PostInitData();
                    pid.InstructionNum = nInstructionNum;
                    pid.isArray        = true;
                    pid.targetArray    = Array.ConvertAll(braVal.Trim().Split(new[] { ' ' }), s => int.Parse(s));
                    postinitbrs.Add(pid);
                    ILManager.GenInstruction(opcode, new Instruction[0]);
                }
                break;

            case OperandType.InlineSig:
            case OperandType.InlinePhi:
            default:
                Log.Write(Log.Level.Error, $"Opcode \"{opcode.Name}\" not processed");
                break;
            }
            return(null);
        }