Пример #1
0
        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);
        }
 public void AddRange(VariableDefinitionCollection value)
 {
     for (int i = 0; i < value.Count; i++)
     {
         List.Add(value[i]);
     }
 }
Пример #3
0
 public MethodBody(MethodDefinition meth)
 {
     m_method = meth;
     m_instructions = new InstructionCollection (this);
     m_exceptions = new ExceptionHandlerCollection (this);
     m_variables = new VariableDefinitionCollection (this);
 }
Пример #4
0
 public MethodBody(MethodDefinition meth)
 {
     m_method       = meth;
     m_instructions = new InstructionCollection(this);
     m_exceptions   = new ExceptionHandlerCollection(this);
     m_variables    = new VariableDefinitionCollection(this);
 }
Пример #5
0
        public override void VisitVariableDefinitionCollection(VariableDefinitionCollection variables)
        {
            MethodBody body = variables.Container as MethodBody;

            if (body == null || stripped)
            {
                return;
            }

            uint sig = m_reflectWriter.SignatureWriter.AddLocalVarSig(
                GetLocalVarSig(variables));

            if (m_localSigCache.Contains(sig))
            {
                body.LocalVarToken = (int)m_localSigCache [sig];
                return;
            }

            StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable();
            StandAloneSigRow   sasRow   = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow(
                sig);

            sasTable.Rows.Add(sasRow);
            body.LocalVarToken    = sasTable.Rows.Count;
            m_localSigCache [sig] = body.LocalVarToken;
        }
Пример #6
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));
            }
        }
		internal DecompilationContext (MethodBody body, ControlFlowGraph cfg)
		{
			this.body = body;
			this.method = body.Method;
			this.variables = CloneCollection (body.Variables);
			this.cfg = cfg;
		}
Пример #8
0
        public VariableDefinitionCollection ReadVariables(MetadataToken local_var_token)
        {
            int position = reader.position;
            VariableDefinitionCollection result = reader.ReadVariables(local_var_token);

            reader.position = position;
            return(result);
        }
Пример #9
0
        public VariableDefinitionCollection ReadVariables(MetadataToken local_var_token)
        {
            int position = this.reader.position;
            VariableDefinitionCollection definitions = this.reader.ReadVariables(local_var_token);

            this.reader.position = position;
            return(definitions);
        }
		static VariableDefinitionCollection CloneCollection (VariableDefinitionCollection variables)
		{
			var collection = new VariableDefinitionCollection (variables.Container);

			foreach (VariableDefinition variable in variables)
				collection.Add (variable);

			return collection;
		}
Пример #11
0
 public override void VisitVariableDefinitionCollection(VariableDefinitionCollection variables)
 {
   /*
   foreach (VariableDefinition variable in variables)
   {
     _modelCreator.UseType(variable.ToTypeKey());
   }
   */
 }
Пример #12
0
        private void DeclareLocals(VariableDefinitionCollection variableDefinitions)
        {
            foreach (VariableDefinition variableDefinition in variableDefinitions)
            {
                Type type = outer.ResolveType(variableDefinition.VariableType);
                LocalBuilder localBuilder = generator.DeclareLocal(type);

                locals.Add(variableDefinition, localBuilder);
            }
        }
Пример #13
0
        public 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++)
            {
                lvs.LocalVariables [i] = GetLocalVariableSig(vars [i]);
            }

            return(lvs);
        }
Пример #14
0
		public BlockStatement Process (DecompilationContext context, BlockStatement body)
		{
			this.cfg = context.ControlFlowGraph;
			this.annotations = AnnotationStore.CreateStore (cfg, optimization);
			this.body = context.Body;
			this.variables = context.Variables;

			this.expression_decompiler = new ExpressionDecompiler (context.Method, annotations);
			this.statements = new List<Statement> [cfg.Blocks.Length];
			this.processed = new HashSet<InstructionBlock> ();
			this.assignments = new Dictionary<VariableReference, Expression> ();

			Run ();

			PopulateBodyBlock (body);

			return body;
		}
Пример #15
0
        private void PatchRawFatMethod(ByteBuffer buffer, MethodSymbols symbols, CodeWriter writer, out MetadataToken local_var_token)
        {
            uint   num;
            ushort num1 = base.ReadUInt16();

            buffer.WriteUInt16(num1);
            buffer.WriteUInt16(base.ReadUInt16());
            symbols.code_size = base.ReadInt32();
            buffer.WriteInt32(symbols.code_size);
            local_var_token = this.ReadToken();
            if (local_var_token.RID <= 0)
            {
                buffer.WriteUInt32(0);
            }
            else
            {
                VariableDefinitionCollection    variableDefinitionCollection = this.ReadVariables(local_var_token);
                Collection <VariableDefinition> variableDefinitions          = variableDefinitionCollection;
                symbols.variables = variableDefinitionCollection;
                Collection <VariableDefinition> variableDefinitions1 = variableDefinitions;
                ByteBuffer byteBuffer = buffer;
                if (variableDefinitions1 != null)
                {
                    num = writer.GetStandAloneSignature(symbols.variables).ToUInt32();
                }
                else
                {
                    num = 0;
                }
                byteBuffer.WriteUInt32(num);
            }
            this.PatchRawCode(buffer, symbols.code_size, writer);
            if ((num1 & 8) != 0)
            {
                this.PatchRawSection(buffer, writer.metadata);
            }
        }
Пример #16
0
        private void PatchRawFatMethod(ByteBuffer buffer, CodeWriter writer, out int code_size, out MetadataToken local_var_token)
        {
            ushort num = ReadUInt16();

            buffer.WriteUInt16(num);
            buffer.WriteUInt16(ReadUInt16());
            code_size = ReadInt32();
            buffer.WriteInt32(code_size);
            local_var_token = ReadToken();
            if (local_var_token.RID != 0)
            {
                VariableDefinitionCollection variableDefinitionCollection = ReadVariables(local_var_token);
                buffer.WriteUInt32((variableDefinitionCollection != null) ? writer.GetStandAloneSignature(variableDefinitionCollection).ToUInt32() : 0);
            }
            else
            {
                buffer.WriteUInt32(0u);
            }
            PatchRawCode(buffer, code_size, writer);
            if ((num & 8) != 0)
            {
                PatchRawSection(buffer, writer.metadata);
            }
        }
		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));
			}
		}
Пример #18
0
		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;
		}
Пример #19
0
		public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
		{
			MethodBody body = variables.Container;
			uint sig = m_reflectWriter.SignatureWriter.AddLocalVarSig (
					GetLocalVarSig (variables));

			if (m_localSigCache.Contains (sig)) {
				body.LocalVarToken = (int) m_localSigCache [sig];
				return;
			}

			StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable ();
			StandAloneSigRow sasRow = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow (
				sig);

			sasTable.Rows.Add (sasRow);
			body.LocalVarToken = sasTable.Rows.Count;
			m_localSigCache [sig] = body.LocalVarToken;
		}
Пример #20
0
 public override void VisitVariableDefinitionCollection(VariableDefinitionCollection variables)
 {
     this._activeBody.InitLocals = true;
     this._localTypes = variables;
     this._locals = new object[variables.Count];
 }
Пример #21
0
        public 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++) {
                lvs.LocalVariables [i] = GetLocalVariableSig (vars [i]);
            }

            return lvs;
        }
		public void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
		{
			foreach (VariableDefinition vd in variables)
				vd.Accept (this);
		}
 public void VisitVariableDefinitionCollection(VariableDefinitionCollection variables)
 {
     foreach (VariableDefinition definition in variables)
     {
         VisitVariableDefinition(definition);
     }
 }
Пример #24
0
		public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
		{
			if (variables.Count == 0)
				return;

			//FIXME: check for 'init' from method header
			m_writer.WriteLine (".locals init (");
			m_writer.Indent ();
			for (int i = 0; i < variables.Count; i++) {
				VisitVariableDefinition (variables [i]);
				m_writer.WriteLine (i < variables.Count - 1 ? "," : String.Empty);
			}
			m_writer.Unindent ();
			m_writer.WriteLine (")");
		}