コード例 #1
0
        public override void VisitVariableDefinitionCollection(VariableDefinitionCollection variables)
        {
            MethodBody body = variables.Container as MethodBody;

            if (body == null || body.LocalVarToken == 0)
            {
                return;
            }

            StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable();
            StandAloneSigRow   sasRow   = sasTable [(int)GetRid(body.LocalVarToken) - 1];
            LocalVarSig        sig      = m_reflectReader.SigReader.GetLocalVarSig(sasRow.Signature);

            for (int i = 0; i < sig.Count; i++)
            {
                LocalVarSig.LocalVariable lv      = sig.LocalVariables [i];
                TypeReference             varType = m_reflectReader.GetTypeRefFromSig(
                    lv.Type, new GenericContext(body.Method));

                if (lv.ByRef)
                {
                    varType = new ReferenceType(varType);
                }
                if ((lv.Constraint & Constraint.Pinned) != 0)
                {
                    varType = new PinnedType(varType);
                }

                varType = m_reflectReader.GetModifierType(lv.CustomMods, varType);

                body.Variables.Add(new VariableDefinition(
                                       string.Concat("V_", i), i, body.Method, varType));
            }
        }
コード例 #2
0
ファイル: CodeWriter.cs プロジェクト: mbonacci/DeConfuser
        LocalVarSig GetLocalVarSig(VariableDefinitionCollection vars)
        {
            LocalVarSig lvs = new LocalVarSig();

            lvs.CallingConvention |= 0x7;
            lvs.Count              = vars.Count;
            lvs.LocalVariables     = new LocalVarSig.LocalVariable [lvs.Count];
            for (int i = 0; i < lvs.Count; i++)
            {
                LocalVarSig.LocalVariable lv   = new LocalVarSig.LocalVariable();
                TypeReference             type = vars [i].VariableType;

                lv.CustomMods = m_reflectWriter.GetCustomMods(type);

                if (type is PinnedType)
                {
                    lv.Constraint |= Constraint.Pinned;
                    type           = (type as PinnedType).ElementType;
                }

                if (type is ReferenceType)
                {
                    lv.ByRef = true;
                    type     = (type as ReferenceType).ElementType;
                }

                lv.Type = m_reflectWriter.GetSigType(type);

                lvs.LocalVariables [i] = lv;
            }
            return(lvs);
        }
コード例 #3
0
        private List <DebugLocalVariableInfo> GetLocalVariablesInScope(ISymUnmanagedScope symScope)
        {
            List <DebugLocalVariableInfo> vars = new List <DebugLocalVariableInfo>();

            foreach (ISymUnmanagedVariable symVar in symScope.GetLocals())
            {
                ISymUnmanagedVariable symVarCopy = symVar;
                int                       start;
                SignatureReader           sigReader  = new SignatureReader(symVar.GetSignature());
                LocalVarSig.LocalVariable locVarSig  = sigReader.ReadLocalVariable(sigReader.Blob, 0, out start);
                DebugType                 locVarType = DebugType.CreateFromSignature(this.DebugModule, locVarSig.Type, declaringType);
                // Compiler generated?
                // NB: Display class does not have the compiler-generated flag
                if ((symVar.GetAttributes() & 1) == 1 || symVar.GetName().StartsWith("CS$"))
                {
                    // Get display class from local variable
                    if (locVarType.IsDisplayClass)
                    {
                        AddCapturedLocalVariables(
                            vars,
                            (int)symScope.GetStartOffset(),
                            (int)symScope.GetEndOffset(),
                            delegate(StackFrame context)
                        {
                            return(GetLocalVariableValue(context, symVarCopy));
                        },
                            locVarType
                            );
                    }
                }
                else
                {
                    DebugLocalVariableInfo locVar = new DebugLocalVariableInfo(
                        symVar.GetName(),
                        (int)symVar.GetAddressField1(),
                        // symVar also has Get*Offset methods, but the are not implemented
                        (int)symScope.GetStartOffset(),
                        (int)symScope.GetEndOffset(),
                        locVarType,
                        delegate(StackFrame context)
                    {
                        return(GetLocalVariableValue(context, symVarCopy));
                    }
                        );
                    vars.Add(locVar);
                }
            }
            foreach (ISymUnmanagedScope childScope in symScope.GetChildren())
            {
                vars.AddRange(GetLocalVariablesInScope(childScope));
            }

            return(vars);
        }
コード例 #4
0
        public LocalVarSig.LocalVariable GetLocalVariableSig(VariableDefinition var)
        {
            LocalVarSig.LocalVariable lv   = new LocalVarSig.LocalVariable();
            TypeReference             type = var.VariableType;

            lv.CustomMods = m_reflectWriter.GetCustomMods(type);

            if (type is PinnedType)
            {
                lv.Constraint |= Constraint.Pinned;
                type           = (type as PinnedType).ElementType;
            }

            if (type is ReferenceType)
            {
                lv.ByRef = true;
                type     = (type as ReferenceType).ElementType;
            }

            lv.Type = m_reflectWriter.GetSigType(type);

            return(lv);
        }