Beispiel #1
0
        private static byte[] getBytes(double s, Class type)
        {
            var l = type.SizeOf();

            switch (l)
            {
            case 1:
                return(new[] { (byte)s });

            case 2:
                return(BitConverter.GetBytes((short)s));

            case 3:
                var bytes = BitConverter.GetBytes((int)s);
                return(new[] { bytes[0], bytes[1], bytes[2] });

            case 4:
                return(BitConverter.GetBytes((int)s));

            case 8:
                return(BitConverter.GetBytes(s));
            }
            return(new byte[l]);
        }
Beispiel #2
0
        internal ConstInfo(Class type, int value, string name = null)
        {
            Return = type;
            Handle = new Operand(value);
            Name   = name;

            var sizeOf = type.SizeOf();

            if (sizeOf <= 4)
            {
                if (type == Assembly.UInt)
                {
                    Value = BitConverter.GetBytes((uint)value);
                }
                else if (type == Assembly.Int)
                {
                    Value = BitConverter.GetBytes(value);
                }
                else if (type == Assembly.Bool)
                {
                    Value = new[] { (byte)(value == 0 ? 0 : 0xff) }
                }
                ;
                else if (type == Assembly.Byte)
                {
                    Value = BitConverter.GetBytes((byte)value);
                }
                else if (type == Assembly.Char)
                {
                    Value = BitConverter.GetBytes((char)value);
                }
                else if (type == Assembly.Float)
                {
                    Value = BitConverter.GetBytes((float)value);
                }
                else if (type == Assembly.Short)
                {
                    Value = BitConverter.GetBytes((short)value);
                }
                else
                {
                    switch (sizeOf)
                    {
                    case 0:
                        Value = new byte[0];
                        break;

                    case 4:
                        Value = BitConverter.GetBytes((uint)value);
                        break;

                    case 2:
                        Value = BitConverter.GetBytes((short)value);
                        break;

                    case 1:
                        Value = BitConverter.GetBytes((byte)value);
                        break;

                    default:
                        Value = BitConverter.GetBytes(value);
                        Value = new[] { Value[0], Value[01], Value[2] };
                        break;
                    }
                }
                Handle = new Operand(value);
            }
            else
            {
                Handle = new Operand(Reg.sip, 0).AsPointer();
            }
        }
Beispiel #3
0
        internal ConstInfo(Class type, byte[] value, string name = null)
        {
            Return = type;
            Value  = value;
            Name   = name;

            if (type.SizeOf() <= 4)
            {
                var val = 0;
                if (type == Assembly.UInt)
                {
                    val = (int)BitConverter.ToUInt32(value, 0);
                }
                else if (type == Assembly.Int)
                {
                    val = BitConverter.ToInt32(value, 0);
                }
                else if (type == Assembly.Bool)
                {
                    val = BitConverter.ToBoolean(value, 0) == false ? 0 : 0xff;
                }
                else if (type == Assembly.Byte)
                {
                    val = value[0];
                }
                else if (type == Assembly.Char)
                {
                    val = BitConverter.ToChar(value, 0);
                }
                else if (type == Assembly.Float)
                {
                    val = Float2Int(BitConverter.ToSingle(value, 0));
                }
                else if (type == Assembly.Short)
                {
                    val = BitConverter.ToInt16(value, 0);
                }
                else
                {
                    switch (value.Length)
                    {
                    case 4:
                        val = BitConverter.ToInt32(value, 0);
                        break;

                    case 2:
                        val = BitConverter.ToInt16(value, 0);
                        break;

                    case 1:
                        val = value[0];
                        break;

                    case 3:
                        val = BitConverter.ToInt32(new byte[] { 0, value[0], value[1], value[2] }, 0);
                        break;
                    }
                }
                Handle = new Operand(val);
            }
            else
            {
                Handle = new Operand(Reg.sip, 0).AsPointer();
            }
        }