示例#1
0
        bool CheckBlock(Block block, Dictionary <Local, VMInfo> vmDictonary, out List <Tuple <Tuple <int, int>, Tuple <int, Local> > > loalBlocks)
        {
            loalBlocks = new List <Tuple <Tuple <int, int>, Tuple <int, Local> > >();
            var instr = block.Instructions;

            for (int i = 0; i < instr.Count; i++)
            {
                if (!Utilis.IsLoc(instr[i]))
                {
                    continue;
                }
                var local = instr[i].Instruction.GetLocal(blocks.Locals);
                if (local == null || !vmDictonary.ContainsKey(local))
                {
                    continue;
                }
                var vmInfo = vmDictonary[local];
                if (Utilis.IsStloc(instr[i]))
                {
                    if (vmInfo.Instruction != instr[i])
                    {
                        return(false);
                    }
                }
                else
                {
                    ElementType type;
                    int         ptrIndex, size;
                    if (!isValidLoad(block, i, out type, out ptrIndex, out size))
                    {
                        return(false);
                    }
                    if (vmInfo.Info[ptrIndex] != ElementType.Void && !Utilis.IsValidElementType(vmInfo.Info[ptrIndex], type))
                    {
                        return(false);
                    }
                    vmInfo.Info[ptrIndex] = Utilis.GetBestElementType(type);
                    var tup1 = new Tuple <int, int>()
                    {
                        Item1 = i, Item2 = size
                    };
                    var tup2 = new Tuple <int, Local>()
                    {
                        Item1 = ptrIndex, Item2 = local
                    };
                    loalBlocks.Add(new Tuple <Tuple <int, int>, Tuple <int, Local> >()
                    {
                        Item1 = tup1, Item2 = tup2
                    });
                }
            }
            return(true);
        }
示例#2
0
        bool CheckAlocBlock(Block block, out Dictionary <Local, VMInfo> vmDictonary)
        {
            vmDictonary = new Dictionary <Local, VMInfo>();
            var outLocals = new List <VMInfo>();
            var instr     = block.Instructions;

            for (int i = 3; i < instr.Count; i++)
            {
                if (!Utilis.IsLoc(instr[i]))
                {
                    continue;
                }
                var local = instr[i].Instruction.GetLocal(blocks.Locals);
                if (!Utilis.IsPtrElementType(local.Type, ElementType.U1))
                {
                    continue;
                }
                if (!instr[i].IsStloc())
                {
                    continue;
                }
                if (vmDictonary.ContainsKey(local))
                {
                    outLocals.Remove(vmDictonary[local]);
                    continue;
                }
                if (instr[i - 1].OpCode != OpCodes.Localloc)
                {
                    continue;
                }
                if (instr[i - 2].OpCode != OpCodes.Conv_U)
                {
                    continue;
                }
                if (!instr[i - 3].IsLdcI4())
                {
                    continue;
                }
                var size   = instr[i - 3].GetLdcI4Value();
                var vmInfo = new VMInfo()
                {
                    Size = size, Local = local, Instruction = instr[i], Info = NewEmptyElementTypeArray(size)
                };
                vmDictonary[local] = vmInfo;
                outLocals.Add(vmInfo);
            }
            return(outLocals.Count != 0);
        }