Пример #1
0
        private void ParseNativeVarInfo(byte[] image, int offset)
        {
            // Each Varinfo has a:
            // - native start +End offset. We can use a delta for the end offset.
            // - Il variable number. These are usually small.
            // - VarLoc information. This is a tagged variant.
            // The entries aren't sorted in any particular order.
            NibbleReader reader         = new NibbleReader(image, offset);
            uint         nativeVarCount = reader.ReadUInt();

            for (int i = 0; i < nativeVarCount; ++i)
            {
                var entry = new NativeVarInfo();
                entry.StartOffset    = reader.ReadUInt();
                entry.EndOffset      = entry.StartOffset + reader.ReadUInt();
                entry.VariableNumber = (uint)(reader.ReadUInt() + (int)ImplicitILArguments.Max);

                var varLoc = new VarLoc();
                varLoc.VarLocType = (VarLocType)reader.ReadUInt();
                switch (varLoc.VarLocType)
                {
                case VarLocType.VLT_REG:
                case VarLocType.VLT_REG_FP:
                case VarLocType.VLT_REG_BYREF:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    break;

                case VarLocType.VLT_STK:
                case VarLocType.VLT_STK_BYREF:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    varLoc.Data2 = ReadEncodedStackOffset(reader);
                    break;

                case VarLocType.VLT_REG_REG:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    varLoc.Data2 = (int)reader.ReadUInt();
                    break;

                case VarLocType.VLT_REG_STK:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    varLoc.Data2 = (int)reader.ReadUInt();
                    varLoc.Data3 = ReadEncodedStackOffset(reader);
                    break;

                case VarLocType.VLT_STK_REG:
                    varLoc.Data1 = ReadEncodedStackOffset(reader);
                    varLoc.Data2 = (int)reader.ReadUInt();
                    varLoc.Data3 = (int)reader.ReadUInt();
                    break;

                case VarLocType.VLT_STK2:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    varLoc.Data2 = ReadEncodedStackOffset(reader);
                    break;

                case VarLocType.VLT_FPSTK:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    break;

                case VarLocType.VLT_FIXED_VA:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    break;

                default:
                    throw new BadImageFormatException("Unexpected var loc type");
                }

                entry.VariableLocation = varLoc;
                _variablesList.Add(entry);
            }
        }
Пример #2
0
        private void ParseNativeVarInfo(byte[] image, int offset)
        {
            // Each Varinfo has a:
            // - native start +End offset. We can use a delta for the end offset.
            // - Il variable number. These are usually small.
            // - VarLoc information. This is a tagged variant.
            // The entries aren't sorted in any particular order.
            NibbleReader reader         = new NibbleReader(image, offset);
            uint         nativeVarCount = reader.ReadUInt();

            for (int i = 0; i < nativeVarCount; ++i)
            {
                var entry = new NativeVarInfo();
                entry.StartOffset    = reader.ReadUInt();
                entry.EndOffset      = entry.StartOffset + reader.ReadUInt();
                entry.VariableNumber = (uint)(reader.ReadUInt() + (int)ImplicitILArguments.Max);
                entry.Variable       = new Variable();
                // TODO: This is probably incomplete
                // This does not handle any implicit arguments or var args
                if (entry.VariableNumber < this._runtimeFunction.Method.Signature.ParameterTypes.Length)
                {
                    entry.Variable.Type  = VariableType.Parameter;
                    entry.Variable.Index = (int)entry.VariableNumber;
                }
                else
                {
                    entry.Variable.Type  = VariableType.Local;
                    entry.Variable.Index = (int)entry.VariableNumber - this._runtimeFunction.Method.Signature.ParameterTypes.Length;
                }

                var varLoc = new VarLoc();
                varLoc.VarLocType = (VarLocType)reader.ReadUInt();
                switch (varLoc.VarLocType)
                {
                case VarLocType.VLT_REG:
                case VarLocType.VLT_REG_FP:
                case VarLocType.VLT_REG_BYREF:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    break;

                case VarLocType.VLT_STK:
                case VarLocType.VLT_STK_BYREF:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    varLoc.Data2 = ReadEncodedStackOffset(reader);
                    break;

                case VarLocType.VLT_REG_REG:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    varLoc.Data2 = (int)reader.ReadUInt();
                    break;

                case VarLocType.VLT_REG_STK:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    varLoc.Data2 = (int)reader.ReadUInt();
                    varLoc.Data3 = ReadEncodedStackOffset(reader);
                    break;

                case VarLocType.VLT_STK_REG:
                    varLoc.Data1 = ReadEncodedStackOffset(reader);
                    varLoc.Data2 = (int)reader.ReadUInt();
                    varLoc.Data3 = (int)reader.ReadUInt();
                    break;

                case VarLocType.VLT_STK2:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    varLoc.Data2 = ReadEncodedStackOffset(reader);
                    break;

                case VarLocType.VLT_FPSTK:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    break;

                case VarLocType.VLT_FIXED_VA:
                    varLoc.Data1 = (int)reader.ReadUInt();
                    break;

                default:
                    throw new BadImageFormatException("Unexpected var loc type");
                }

                entry.VariableLocation = varLoc;
                _variablesList.Add(entry);
            }
        }