Пример #1
0
        private static bool TryDecodePseudoFieldData(
            ClrFieldDefinition pseudoField,
            IType elementType,
            out IReadOnlyList <Constant> data)
        {
            var init    = pseudoField.Definition.InitialValue;
            var intSpec = elementType.GetIntegerSpecOrNull();

            if (intSpec != null && intSpec.Size % 8 == 0)
            {
                int bytesPerInt = intSpec.Size / 8;
                int intCount    = init.Length / bytesPerInt;
                var results     = new Constant[intCount];
                for (int i = 0; i < intCount; i++)
                {
                    var value = new IntegerConstant(0, intSpec);
                    for (int j = bytesPerInt - 1; j >= 0; j--)
                    {
                        value = value.ShiftLeft(8).Add(new IntegerConstant(init[i * bytesPerInt + j], intSpec));
                    }
                    results[i] = value.Normalized;
                }
                data = results;
                return(true);
            }
            else
            {
                data = null;
                return(false);
            }
        }
Пример #2
0
 private static bool IsArrayInit(NamedInstructionBuilder instruction, out ValueTag array, out ClrFieldDefinition pseudoField)
 {
     if (instruction.Prototype is CallPrototype)
     {
         var call   = (CallPrototype)instruction.Prototype;
         var callee = call.Callee;
         if (callee.IsStatic && callee.Parameters.Count == 2 &&
             callee.FullName.ToString() == "System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray")
         {
             var pseudoFieldRef = instruction.Arguments[1];
             NamedInstructionBuilder pseudoFieldInsn;
             if (instruction.Graph.TryGetInstruction(pseudoFieldRef, out pseudoFieldInsn) &&
                 pseudoFieldInsn.Prototype is ConstantPrototype)
             {
                 var constVal = ((ConstantPrototype)pseudoFieldInsn.Prototype).Value;
                 if (constVal is FieldTokenConstant)
                 {
                     pseudoField = ((FieldTokenConstant)constVal).Field as ClrFieldDefinition;
                     array       = instruction.Arguments[0];
                     return(pseudoField != null);
                 }
             }
         }
     }
     array       = null;
     pseudoField = null;
     return(false);
 }