Exemplo n.º 1
0
        /// <summary>
        /// Create and add an instruction.
        /// 
        /// This seems to be a dangerous overload, since it may hide the one below if operand is null.
        /// We can't remove it without checking all ~170 usages though...
        /// </summary>
        public static Instruction Add(this IRLBuilder builder, ISourceLocation sequencePoint, RCode opcode, params Register[] registers)
        {
            if(registers.Any(r=> r == null))
                throw new InvalidOperationException("Register must not be null. Wrong overload?");

            return builder.Add(sequencePoint, opcode, (object)null, registers);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Default ctor
 /// </summary>
 private BoxInfo(XTypeReferenceKind metadataType, ClassReference boxedClass, PrimitiveType primitiveType,
                 string unboxMethodName, RCode convertAfterCode)
 {
     this.metadataType = metadataType;
     this.boxedClass = boxedClass;
     this.primitiveType = primitiveType;
     this.unboxMethodName = unboxMethodName;
     this.convertAfterCode = convertAfterCode;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Create and add an instruction.
        /// </summary>
        public static Instruction Add(this IRLBuilder builder, ISourceLocation sequencePoint, RCode opcode, object operand, params Register[] registers)
        {
            if(operand is Register)
                throw new InvalidOperationException("Wrong overload. Please fix me..."); // see above.
            if(operand is RegisterSpec || operand is RLRange)
                throw new InvalidOperationException("Wrong kind of argument. Please fix me..."); // see above.

            return builder.Add(sequencePoint, opcode, operand, registers);
        }
Exemplo n.º 4
0
 public Format(ushort id, Flags flags, OpCode opCode, RCode rCode)
 {
     this.id            = id;
     this.queries       = new ArrayList();
     this.answerRRs     = new ArrayList();
     this.authorityRRs  = new ArrayList();
     this.additionalRRs = new ArrayList();
     this.SetFlags(flags);
     this.SetOpCode(opCode);
     this.SetRCode(rCode);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Convert RCode to OpCodes.
        /// </summary>
        public static OpCodes ToDex(this RCode code)
        {
            switch (code)
            {
            // Special cases
            case RCode.Leave:
                return(OpCodes.Goto);

            default:
                return((OpCodes)code);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Is the given code any unconditional branch code?
        /// </summary>
        public static bool IsUnconditionalBranch(this RCode code)
        {
            switch (code)
            {
            case RCode.Goto:
            case RCode.Leave:
            case RCode.Throw:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Is the given code an move_x code?
        /// </summary>
        public static bool IsMove(this RCode code)
        {
            switch (code)
            {
            case RCode.Move:
            case RCode.Move_object:
            case RCode.Move_wide:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 8
0
        private RCode ToIntLit(RCode code, bool use8BitLit)
        {
            switch (code)
            {
            case RCode.Add_int:
            case RCode.Add_int_2addr:
            case RCode.Sub_int:           // value is negatized above
            case RCode.Sub_int_2addr:
                return(use8BitLit ? RCode.Add_int_lit8 : RCode.Add_int_lit);

            case RCode.Mul_int:
            case RCode.Mul_int_2addr:
                return(use8BitLit ? RCode.Mul_int_lit8 : RCode.Mul_int_lit);

            case RCode.Div_int:
            case RCode.Div_int_2addr:
                return(use8BitLit ? RCode.Div_int_lit8 : RCode.Div_int_lit);

            case RCode.Rem_int:
            case RCode.Rem_int_2addr:
                return(use8BitLit ? RCode.Rem_int_lit8 : RCode.Rem_int_lit);

            case RCode.And_int:
            case RCode.And_int_2addr:
                return(use8BitLit ? RCode.And_int_lit8 : RCode.And_int_lit);

            case RCode.Or_int:
            case RCode.Or_int_2addr:
                return(use8BitLit ? RCode.Or_int_lit8 : RCode.Or_int_lit);

            case RCode.Xor_int:
            case RCode.Xor_int_2addr:
                return(use8BitLit ? RCode.Xor_int_lit8 : RCode.Xor_int_lit);

            case RCode.Shl_int:
            case RCode.Shl_int_2addr:
                return(RCode.Shl_int_lit8);

            case RCode.Shr_int:
            case RCode.Shr_int_2addr:
                return(RCode.Shr_int_lit8);

            case RCode.Ushr_int:
            case RCode.Ushr_int_2addr:
                return(RCode.Ushr_int_lit8);

            default:
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 9
0
 protected Message(
     ushort transactionId,
     ushort flags,
     QueryResponse queryResponse,
     OpCode opCode, NsFlags nsFlags,
     RCode rCode, ushort questions,
     ushort answerRRs,
     ushort authorityRRs,
     string name,
     NsType nsType,
     NsClass nsClass,
     List <Record> additionalRecords)
 {
 }
Exemplo n.º 10
0
        /// <summary>
        /// Is the given code any return code?
        /// </summary>
        public static bool IsReturn(this RCode code)
        {
            switch (code)
            {
            case RCode.Return:
            case RCode.Return_object:
            case RCode.Return_void:
            case RCode.Return_wide:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Is the given code an const_x code?
        /// </summary>
        public static bool IsConst(this RCode code)
        {
            switch (code)
            {
            case RCode.Const:
            case RCode.Const_class:
            case RCode.Const_wide:
            case RCode.Const_string:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Is the given code an invoke_x code?
        /// </summary>
        public static bool IsInvoke(this RCode code)
        {
            switch (code)
            {
            case RCode.Invoke_direct:
            case RCode.Invoke_interface:
            case RCode.Invoke_static:
            case RCode.Invoke_super:
            case RCode.Invoke_virtual:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 13
0
 public RecordEntity(
     int?id,
     DomainEntity domain,
     RecordInfo recordInfo,
     RCode responseCode,
     int failureCount,
     DateTime?endDate = null)
 {
     Id           = id;
     Domain       = domain;
     RecordInfo   = recordInfo;
     ResponseCode = responseCode;
     FailureCount = failureCount;
     EndDate      = endDate;
 }
Exemplo n.º 14
0
        protected Message(
            ushort transactionId, 
            ushort flags, 
            QueryResponse queryResponse, 
            OpCode opCode, NsFlags nsFlags, 
            RCode rCode, ushort questions, 
            ushort answerRRs, 
            ushort authorityRRs, 
            string name, 
            NsType nsType, 
            NsClass nsClass,
            List<Record> additionalRecords)
        {

        }
        public static bool IsComparisonWithZero(RCode code)
        {
            switch (code)
            {
            case RCode.If_eqz:
            case RCode.If_gez:
            case RCode.If_gtz:
            case RCode.If_lez:
            case RCode.If_ltz:
            case RCode.If_nez:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 16
0
        public TSigRecord(string name, string algorithmName, RCode error, ushort fudge, ushort originalId, byte[] otherData, byte[] mac, DateTime timeSigned)
        {
            DnsHeader = new RecordHeader(name, NsType.TSIG, NsClass.ANY, 0);

            _algorithmName = algorithmName;
            _error = error;
            _fudge = fudge;
            _originalId = originalId;
            _otherData = otherData;
            _mac = mac;
            _timeSigned = timeSigned;

            if(otherData == null)
            {
                _otherData = new byte[]{};
            }
        }
Exemplo n.º 17
0
        public TSigRecord(string name, string algorithmName, RCode error, ushort fudge, ushort originalId, byte[] otherData, byte[] mac, DateTime timeSigned)
        {
            DnsHeader = new RecordHeader(name, NsType.TSIG, NsClass.ANY, 0);

            _algorithmName = algorithmName;
            _error         = error;
            _fudge         = fudge;
            _originalId    = originalId;
            _otherData     = otherData;
            _mac           = mac;
            _timeSigned    = timeSigned;

            if (otherData == null)
            {
                _otherData = new byte[] {};
            }
        }
Exemplo n.º 18
0
        public override void ParseRecord(ref MemoryStream memoryStream)
        {
            Byte[] dataUInt16 = new byte[2];
            Byte[] dataUInt32 = new byte[4];

            _algorithmName = ParseName(ref memoryStream);

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            long timeHigh = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt32, 0, dataUInt32.Length);
            long timeLow = (uint)IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(dataUInt32, 0));

            _timeSigned = DnsHelpers.ConvertFromDnsTime(timeLow, timeHigh);

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            _fudge = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            Int32 macLen = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            _mac = new byte[macLen];
            memoryStream.Read(_mac, 0, macLen);

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            _originalId = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            _error = (RCode)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            Int32 otherLen = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            if (otherLen > 0)
            {
                _otherData = new byte[otherLen];
                memoryStream.Read(_otherData, 0, otherLen);
            }
            else
            {
                _otherData = null;
            }

            _answer = ToString();
        }
        private static RCode ReverseComparison(RCode code)
        {
            switch (code)
            {
            case RCode.If_eqz:
                return(RCode.If_nez);

            case RCode.If_nez:
                return(RCode.If_eqz);

            case RCode.If_gez:
                return(RCode.If_ltz);

            case RCode.If_gtz:
                return(RCode.If_lez);

            case RCode.If_lez:
                return(RCode.If_gtz);

            case RCode.If_ltz:
                return(RCode.If_gez);

            case RCode.If_eq:
                return(RCode.If_ne);

            case RCode.If_ne:
                return(RCode.If_eq);

            case RCode.If_ge:
                return(RCode.If_lt);

            case RCode.If_gt:
                return(RCode.If_le);

            case RCode.If_le:
                return(RCode.If_gt);

            case RCode.If_lt:
                return(RCode.If_ge);

            default:
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 20
0
        private bool IsOptimizableBinOp(RCode code, out int minValue, out int maxValue)
        {
            switch (code)
            {
            case RCode.Add_int:
            case RCode.Add_int_2addr:
            case RCode.Mul_int:
            case RCode.Mul_int_2addr:
            case RCode.Div_int:
            case RCode.Div_int_2addr:
            case RCode.Rem_int:
            case RCode.Rem_int_2addr:
            case RCode.And_int:
            case RCode.And_int_2addr:
            case RCode.Or_int:
            case RCode.Or_int_2addr:
            case RCode.Xor_int:
            case RCode.Xor_int_2addr:
                minValue = short.MinValue;
                maxValue = short.MaxValue;
                return(true);

            case RCode.Shl_int:
            case RCode.Shl_int_2addr:
            case RCode.Shr_int:
            case RCode.Shr_int_2addr:
            case RCode.Ushr_int:
            case RCode.Ushr_int_2addr:
                minValue = sbyte.MinValue;
                maxValue = sbyte.MaxValue;
                return(true);

            case RCode.Sub_int:      // converted to an add
            case RCode.Sub_int_2addr:
                minValue = -short.MaxValue;
                maxValue = -short.MinValue;
                return(true);

            default:
                minValue = int.MaxValue;
                maxValue = int.MinValue;
                return(false);
            }
        }
Exemplo n.º 21
0
        private Response CreateRecord(string domainName, string[][] records, RCode responseCode = RCode.NoError)
        {
            Response response = new Response {
                header = { RCODE = responseCode }
            };

            foreach (var record in records)
            {
                QType dnsEntryType = QType.TXT;
                Class dnsClass     = Class.IN;

                byte nameTerminator = 0;

                byte[]   domainNameBytes   = Encoding.UTF8.GetBytes(domainName);
                byte[]   dnsEntryTypeBytes = BitConverter.GetBytes((UInt16)dnsEntryType).Reverse().ToArray();
                byte[]   dnsClassBytes     = BitConverter.GetBytes((UInt16)dnsClass).Reverse().ToArray();
                byte[]   ttlBytes          = BitConverter.GetBytes(3600).Reverse().ToArray();
                byte[][] recordsBytes      = record.Select(_ => Encoding.UTF8.GetBytes(_)).ToArray();
                byte[]   lengthBytes       =
                    BitConverter.GetBytes((UInt16)recordsBytes.Sum(_ => _.Length)).Reverse().ToArray();


                using (MemoryStream memoryStream = new MemoryStream())
                {
                    memoryStream.WriteByte((byte)domainNameBytes.Length);
                    memoryStream.Write(domainNameBytes, 0, domainNameBytes.Length);
                    memoryStream.WriteByte(nameTerminator);
                    memoryStream.Write(dnsEntryTypeBytes, 0, dnsEntryTypeBytes.Length);
                    memoryStream.Write(dnsClassBytes, 0, dnsClassBytes.Length);
                    memoryStream.Write(ttlBytes, 0, ttlBytes.Length);
                    memoryStream.Write(lengthBytes, 0, lengthBytes.Length);

                    foreach (var bytes in recordsBytes)
                    {
                        memoryStream.WriteByte((byte)bytes.Length);
                        memoryStream.Write(bytes, 0, bytes.Length);
                    }

                    response.Answers.Add(new AnswerRR(new RecordReader(memoryStream.ToArray())));
                }
            }

            return(response);
        }
        /// <summary>
        /// Gets the move code that matches the given const predecessor code.
        /// </summary>
        private static RCode ConstToMove(RCode code)
        {
            switch (code)
            {
            case RCode.Const:
                return(RCode.Move);

            case RCode.Const_class:
                return(RCode.Move_object);

            case RCode.Const_wide:
                return(RCode.Move_wide);

            case RCode.Const_string:
                return(RCode.Move_object);

            default:
                throw new ArgumentException("Invalid code");
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Represents a DNS message
        /// </summary>
        /// <param name="Data">Binary representation of a DNS message.</param>
        public DnsMessage(byte[] Data)
        {
            this.binary = Data;

            using (MemoryStream ms = new MemoryStream(Data))
            {
                this.id = DnsClient.ReadUInt16(ms);

                byte b = (byte)ms.ReadByte();
                this.response            = (b & 0x80) != 0;
                this.opCode              = (OpCode)((b >> 3) & 15);
                this.authoritativeAnswer = (b & 4) != 0;
                this.truncation          = (b & 2) != 0;
                this.recursionDesired    = (b & 1) != 0;

                b = (byte)ms.ReadByte();
                this.recursionAvailable = (b & 128) != 0;
                this.rCode = (RCode)(b & 31);

                ushort QDCOUNT = DnsClient.ReadUInt16(ms);
                ushort ANCOUNT = DnsClient.ReadUInt16(ms);
                ushort NSCOUNT = DnsClient.ReadUInt16(ms);
                ushort ARCOUNT = DnsClient.ReadUInt16(ms);

                this.questions = new Question[QDCOUNT];
                ushort i;

                for (i = 0; i < QDCOUNT; i++)
                {
                    string QNAME  = DnsClient.ReadName(ms);
                    QTYPE  QTYPE  = (QTYPE)DnsClient.ReadUInt16(ms);
                    QCLASS QCLASS = (QCLASS)DnsClient.ReadUInt16(ms);

                    this.questions[i] = new Question(QNAME, QTYPE, QCLASS);
                }

                this.answer     = DnsClient.ReadResourceRecords(ms, ANCOUNT);
                this.authority  = DnsClient.ReadResourceRecords(ms, NSCOUNT);
                this.additional = DnsClient.ReadResourceRecords(ms, ARCOUNT);
            }
        }
Exemplo n.º 24
0
        public static bool IsComparisonBranch(this RCode code)
        {
            switch (code)
            {
            case RCode.If_eq:
            case RCode.If_eqz:
            case RCode.If_ge:
            case RCode.If_gez:
            case RCode.If_gt:
            case RCode.If_gtz:
            case RCode.If_le:
            case RCode.If_lez:
            case RCode.If_lt:
            case RCode.If_ltz:
            case RCode.If_ne:
            case RCode.If_nez:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 25
0
        public bool IsSimpleBranch(RCode code)
        {
            switch (code)
            {
            case RCode.Goto:
            case RCode.Leave:
            case RCode.If_eq:
            case RCode.If_eqz:
            case RCode.If_ge:
            case RCode.If_gez:
            case RCode.If_gt:
            case RCode.If_gtz:
            case RCode.If_le:
            case RCode.If_lez:
            case RCode.If_lt:
            case RCode.If_ltz:
            case RCode.If_ne:
            case RCode.If_nez:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 26
0
 public Response(
     ushort transactionId,
     ushort flags,
     QueryResponse queryResponse,
     OpCode opCode,
     NsFlags nsFlags,
     RCode rCode,
     ushort questions,
     ushort answerRRs,
     ushort authorityRRs,
     string name,
     NsType nsType,
     NsClass nsClass,
     List <Record> additionalRecords,
     int bytesReceived,
     Record[] answers,
     Record[] authoritiveNameServers
     )
 {
     _bytesReceived          = bytesReceived;
     _answers                = answers;
     _authoritiveNameServers = authoritiveNameServers;
     _transactionId          = transactionId;
     _flags             = flags;
     _queryResponse     = queryResponse;
     _opCode            = opCode;
     _nsFlags           = nsFlags;
     _rCode             = rCode;
     _questions         = questions;
     _answerRRs         = answerRRs;
     _authorityRRs      = authorityRRs;
     _name              = name;
     _nsType            = nsType;
     _nsClass           = nsClass;
     _additionalRecords = additionalRecords;
 }
Exemplo n.º 27
0
        public DnsHeader(byte[] byIpData, int start, int bytesReceived)
        {
            NetBinaryReader nbr = new NetBinaryReader(byIpData, start);

            Indentifier = nbr.ReadUInt16();

            QueryOrResponseFlag = nbr.ReadBit();
            OperationCode = (OpCode)nbr.ReadNible();
            AuthoritativeAnswer = nbr.ReadBit();
            Turncation = nbr.ReadBit();
            RecursionDesired = nbr.ReadBit();

            RecursionAvailable = nbr.ReadBit();
            nbr.ReadCustomAmount(3);
            ResponseCode = (RCode)nbr.ReadNible();

            QuestionCount = nbr.ReadUInt16();
            AnswerCount = nbr.ReadUInt16();
            AuthorityCount = nbr.ReadUInt16();
            AdditionalCount = nbr.ReadUInt16();

            data = new byte[bytesReceived - start - OCTET_COUNT];
            Array.Copy(byIpData, start + OCTET_COUNT, data, 0, data.Length);
        }
Exemplo n.º 28
0
 public Instruction(RCode code, object operand, Register[] registers)
 {
     Code           = code;
     Operand        = operand;
     this.registers = new RegisterList(registers);
 }
Exemplo n.º 29
0
 public Instruction(RCode code, object operand)
     : this(code, operand, null)
 {
 }
Exemplo n.º 30
0
 public Instruction(RCode code)
     : this(code, null, (Register[])null)
 {
 }
Exemplo n.º 31
0
 private static RCode ReverseComparison(RCode code)
 {
     switch (code)
     {
         case RCode.If_eqz:
             return RCode.If_nez;
         case RCode.If_nez:
             return RCode.If_eqz;
         case RCode.If_gez:
             return RCode.If_ltz;
         case RCode.If_gtz:
             return RCode.If_lez;
         case RCode.If_lez:
             return RCode.If_gtz;
         case RCode.If_ltz:
             return RCode.If_gez;
         case RCode.If_eq:
             return RCode.If_ne;
         case RCode.If_ne:
             return RCode.If_eq;
         case RCode.If_ge:
             return RCode.If_lt;
         case RCode.If_gt:
             return RCode.If_le;
         case RCode.If_le:
             return RCode.If_gt;
         case RCode.If_lt:
             return RCode.If_ge;
         default:
             throw new InvalidOperationException();
     }
 }
Exemplo n.º 32
0
        public static Format Parse(byte [] buffer, ref int offset)
        {
            //
            // First extract enough information to instantiate a Dns.Format
            //
            ushort id = NetworkBitConverter.ToUInt16(buffer, offset);

            offset += 2;

            ushort flagsAndCodes = NetworkBitConverter.ToUInt16(buffer,
                                                                offset);

            offset += 2;

            Flags flags = (Flags)((int)flagsAndCodes & (int)Flags.ALL);

            OpCode opCode =
                (OpCode)(((int)flagsAndCodes >> OpCodeRoll) & OpCodeMask);

            RCode rCode = (RCode)((int)flagsAndCodes & RCodeMask);

            //
            // Instantiate Dns.Format
            //
            Format format = new Format(id, flags, opCode, rCode);

            //
            // Extract query and record counts and then instantiate
            // Query and ResourceRecord objects
            //

            ushort totalQueries = NetworkBitConverter.ToUInt16(buffer,
                                                               offset);

            offset += 2;

            ushort totalAnswerRRs = NetworkBitConverter.ToUInt16(buffer,
                                                                 offset);

            offset += 2;

            ushort totalAuthorityRRs = NetworkBitConverter.ToUInt16(buffer,
                                                                    offset);

            offset += 2;

            ushort totalAdditionalRRs = NetworkBitConverter.ToUInt16(buffer,
                                                                     offset);

            offset += 2;

            for (ushort i = 0; i < totalQueries; i++)
            {
                Query query = Query.Parse(buffer, ref offset);
                format.queries.Add(query);
            }

            // XXX Parsing stops here when a query fails.
            //
            // When a query fails, servers sometimes
            // indicate resource records are present, but the
            // data that we'd expect to be a resource record
            // does not match the format defined in
            // RFC1035. Details may exist in another RFC (???).
            if (rCode != RCode.NoError)
            {
                return(format);
            }

            for (ushort i = 0; i < totalAnswerRRs; i++)
            {
                ResourceRecord rr = ResourceRecord.Parse(buffer, ref offset);
                format.answerRRs.Add(rr);
            }

            for (ushort i = 0; i < totalAuthorityRRs; i++)
            {
                ResourceRecord rr = ResourceRecord.Parse(buffer, ref offset);
                format.authorityRRs.Add(rr);
            }

            for (ushort i = 0; i < totalAdditionalRRs; i++)
            {
                ResourceRecord rr = ResourceRecord.Parse(buffer, ref offset);
                format.additionalRRs.Add(rr);
            }

            return(format);
        }
Exemplo n.º 33
0
 /// <summary>
 /// Gets a unbox method for the given primitive type.
 /// </summary>
 internal static MethodReference GetUnboxValueMethod(this XTypeReference type, AssemblyCompiler compiler, DexTargetPackage targetPackage, out RCode convertAfterCode)
 {
     return BoxInfo.GetUnboxValueMethod(type, compiler, targetPackage, out convertAfterCode);
 }
Exemplo n.º 34
0
 /// <summary>
 /// Generate an Add opcode.
 /// </summary>
 private static RCode OpcodeForType(AstExpression expr, RCode[] opcodes)
 {
     return OpcodeForType(expr.GetResultType(), opcodes);
 }
Exemplo n.º 35
0
 public Response(
     ushort transactionId, 
     ushort flags, 
     QueryResponse queryResponse, 
     OpCode opCode, 
     NsFlags nsFlags, 
     RCode rCode, 
     ushort questions, 
     ushort answerRRs, 
     ushort authorityRRs, 
     string name, 
     NsType nsType, 
     NsClass nsClass,
     List<Record> additionalRecords,
     int bytesReceived,
     Record[] answers,
     Record[] authoritiveNameServers
     )
 {
     _bytesReceived = bytesReceived;
     _answers = answers;
     _authoritiveNameServers = authoritiveNameServers;
     _transactionId = transactionId;
     _flags = flags;
     _queryResponse = queryResponse;
     _opCode = opCode;
     _nsFlags = nsFlags;
     _rCode = rCode;
     _questions = questions;
     _answerRRs = answerRRs;
     _authorityRRs = authorityRRs;
     _name = name;
     _nsType = nsType;
     _nsClass = nsClass;
     _additionalRecords = additionalRecords;
 }
Exemplo n.º 36
0
 public static bool IsComparisonWithZero(RCode code)
 {
     switch (code)
     {
         case RCode.If_eqz:
         case RCode.If_gez:
         case RCode.If_gtz:
         case RCode.If_lez:
         case RCode.If_ltz:
         case RCode.If_nez:
             return true;
         default:
             return false;
     }
 }
Exemplo n.º 37
0
 private RCode ToComparisonWithZero(RCode code)
 {
     switch (code)
     {
         case RCode.If_eq:
             return RCode.If_eqz;
         case RCode.If_ge:
             return RCode.If_gez;
         case RCode.If_gt:
             return RCode.If_gtz;
         case RCode.If_le:
             return RCode.If_lez;
         case RCode.If_lt:
             return RCode.If_ltz;
         case RCode.If_ne:
             return RCode.If_nez;
         default:
             throw new InvalidOperationException();
     }
 }
 /// <summary>
 /// Gets the move code that matches the given const predecessor code.
 /// </summary>
 private static RCode ConstToMove(RCode code)
 {
     switch (code)
     {
         case RCode.Const:
             return RCode.Move;
         case RCode.Const_class:
             return RCode.Move_object;
         case RCode.Const_wide:
             return RCode.Move_wide;
         case RCode.Const_string:
             return RCode.Move_object;
         default:
             throw new ArgumentException("Invalid code");
     }
 }
Exemplo n.º 39
0
 /// <summary>
 /// Create and add an instruction.
 /// 
 /// This seems to be a dangerous overload, since it may hide the one below if operand is null.
 /// We can't remove it without checking all ~170 usages though...
 /// </summary>
 public static Instruction Add(this IRLBuilder builder, ISourceLocation sequencePoint, RCode opcode)
 {
     return builder.Add(sequencePoint, opcode, (object)null, new Register[0]);
 }
Exemplo n.º 40
0
 /// <summary>
 /// Gets a unbox method for the given primitive type.
 /// </summary>
 internal static MethodReference GetUnboxValueMethod(XTypeReference type, AssemblyCompiler compiler, DexTargetPackage targetPackage, out RCode convertAfterCode)
 {
     var info = Get(type);
     convertAfterCode = info.convertAfterCode;
     var boxingClass = compiler.GetDot42InternalType("Boxing").GetClassReference(targetPackage);
     return new MethodReference(boxingClass, info.unboxMethodName, new Prototype(info.primitiveType, new Parameter(FrameworkReferences.Object, "value")));
 }
 private bool IsOptimizableBinOp(RCode code, out int minValue, out int maxValue)
 {
     switch (code)
     {
         case RCode.Add_int:
         case RCode.Add_int_2addr:
         case RCode.Mul_int:
         case RCode.Mul_int_2addr:
         case RCode.Div_int:
         case RCode.Div_int_2addr:
         case RCode.Rem_int:
         case RCode.Rem_int_2addr:
         case RCode.And_int:
         case RCode.And_int_2addr:
         case RCode.Or_int:
         case RCode.Or_int_2addr:
         case RCode.Xor_int:
         case RCode.Xor_int_2addr:
             minValue = short.MinValue;
             maxValue = short.MaxValue;
             return true;
         case RCode.Shl_int:
         case RCode.Shl_int_2addr:
         case RCode.Shr_int:
         case RCode.Shr_int_2addr:
         case RCode.Ushr_int:
         case RCode.Ushr_int_2addr:
             minValue = sbyte.MinValue;
             maxValue = sbyte.MaxValue;
             return true;
         case RCode.Sub_int:  // converted to an add
         case RCode.Sub_int_2addr:
             minValue = -short.MaxValue;
             maxValue = -short.MinValue;
             return true;
         default:
             minValue = int.MaxValue;
             maxValue = int.MinValue;
             return false;
     }
 }
Exemplo n.º 42
0
 /// <summary>
 /// Create and add an instruction.
 /// </summary>
 public static Instruction Add(this IRLBuilder builder, ISourceLocation sequencePoint, RCode opcode, object operand, params Register[] registers)
 {
     if (operand is Register)
     {
         throw new InvalidOperationException("Wrong overload. Please fix me..."); // see above.
     }
     if (operand is RegisterSpec || operand is RLRange)
     {
         throw new InvalidOperationException("Wrong kind of argument. Please fix me..."); // see above.
     }
     return(builder.Add(sequencePoint, opcode, operand, registers));
 }
Exemplo n.º 43
0
        /// <summary>
        /// Generate an Add opcode.
        /// </summary>
        private static RCode OpcodeForType(XTypeReference type, RCode[] opcodes)
        {
            if (type.IsInt32() || type.IsUInt32() || type.IsInt16() || type.IsUInt16() || type.IsChar() || type.IsByte() || type.IsSByte() || type.IsBoolean()) return opcodes[0];
            if (type.IsInt64() || type.IsUInt64()) return opcodes[1];
            if (type.IsFloat()) return opcodes[2];
            if (type.IsDouble()) return opcodes[3];

            XTypeDefinition typeDef;
            if (type.TryResolve(out typeDef))
            {
                if (typeDef.IsEnum)
                {
                    return OpcodeForType(typeDef.GetEnumUnderlyingType(), opcodes);
                }
            }

            throw new ArgumentException("Unsupported type " + type);
        }
Exemplo n.º 44
0
        /// <summary>
        /// 当动作执行中
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // 判断是否检查登陆
            bool allowAnonymous = false;

            if (filterContext.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
            {
                allowAnonymous = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true)
                                 .Any(a => a.GetType().Equals(typeof(AllowAnonymousAttribute)));
            }
            if (!allowAnonymous)
            {
                Robj <bool> robj        = new Robj <bool>();
                HttpContext httpContext = filterContext.HttpContext;
                string      token       = "";
                if (httpContext.Request.Headers.Keys.Select(k => k.ToLower()).Contains(Consts.Sys_TokenKey))
                {
                    token = httpContext.Request.Headers[Consts.Sys_TokenKey];
                }
                if (string.IsNullOrEmpty(token))
                {   //尝试自链接中获取token 以便get请求
                    if (filterContext.HttpContext.Request.Query.Keys.Contains(Consts.Sys_TokenKey))
                    {
                        token = filterContext.HttpContext.Request.Query[Consts.Sys_TokenKey];
                    }
                }
                if (string.IsNullOrEmpty(token))
                {   //尝试自表单数据中获取token
                    if (!string.IsNullOrEmpty(filterContext.HttpContext.Request.ContentType) &&
                        filterContext.HttpContext.Request.ContentType.ToLower() == "application/x-www-form-urlencoded" &&
                        filterContext.HttpContext.Request.Form.Keys.Contains(Consts.Sys_TokenKey))
                    {
                        token = filterContext.HttpContext.Request.Form[Consts.Sys_TokenKey];
                    }
                }

                RCode  rcode      = RCode.Exception;
                string controller = filterContext.RouteData.Values["controller"].ToString();
                string action     = filterContext.RouteData.Values["action"].ToString();
                try
                {
                    if (string.IsNullOrEmpty(token))
                    {                                         //开发使用
                        rcode = RCode.NeedLogin;
                        throw new Exception("你尚未登录系统,请先登录."); //未登录系统抛出异常
                    }
                    else
                    {
                        //UserDto user = CacheHelper.Get<UserDto>(token);
                        //if (user == null)
                        //{
                        //    rcode = RCode.NeedLogin;
                        //    throw new Exception("登录无效或登录已超时,请重新登录.");
                        //}
                    }
                    base.OnActionExecuting(filterContext);
                }
                catch (Exception ex)
                {
                    robj.Code            = rcode;
                    robj.Message         = ex.Message;
                    filterContext.Result = new ContentResult()
                    {
                        Content = JsonHelper.ObjToJson(robj)
                    };
                }
            }
            else
            {
                base.OnActionExecuting(filterContext);
            }
        }
        private RCode ToIntLit(RCode code, bool use8BitLit)
        {
            switch (code)
            {
                case RCode.Add_int:
                case RCode.Add_int_2addr:
                case RCode.Sub_int:       // value is negatized above
                case RCode.Sub_int_2addr:
                    return use8BitLit ? RCode.Add_int_lit8 : RCode.Add_int_lit;
                case RCode.Mul_int:
                case RCode.Mul_int_2addr:
                    return use8BitLit ? RCode.Mul_int_lit8 : RCode.Mul_int_lit;
                case RCode.Div_int:
                case RCode.Div_int_2addr:
                    return use8BitLit ? RCode.Div_int_lit8 : RCode.Div_int_lit;
                case RCode.Rem_int:
                case RCode.Rem_int_2addr:
                    return use8BitLit ? RCode.Rem_int_lit8 : RCode.Rem_int_lit;
                case RCode.And_int:
                case RCode.And_int_2addr:
                    return use8BitLit ? RCode.And_int_lit8 : RCode.And_int_lit;
                case RCode.Or_int:
                case RCode.Or_int_2addr:
                    return use8BitLit ? RCode.Or_int_lit8 : RCode.Or_int_lit;
                case RCode.Xor_int:
                case RCode.Xor_int_2addr:
                    return use8BitLit ? RCode.Xor_int_lit8 : RCode.Xor_int_lit;

                case RCode.Shl_int:
                case RCode.Shl_int_2addr:
                    return RCode.Shl_int_lit8;
                case RCode.Shr_int:
                case RCode.Shr_int_2addr:
                    return RCode.Shr_int_lit8;
                case RCode.Ushr_int:
                case RCode.Ushr_int_2addr:
                    return RCode.Ushr_int_lit8;
                default:
                    throw new InvalidOperationException();
            }
        }
Exemplo n.º 46
0
 /// <summary>
 /// Create a conversion code sequence.
 /// </summary>
 private RLRange ConvX(ISourceLocation sequencePoint,  RCode code, PrimitiveType type, RLRange arg)
 {
     if (code == RCode.Nop)
         return new RLRange(this.Add(sequencePoint, code), arg.Result);
     var r = frame.AllocateTemp(type);
     return new RLRange(this.Add(sequencePoint, code, r, arg.Result), r);
 }
Exemplo n.º 47
0
        public override void ParseRecord(ref MemoryStream memoryStream)
        {
            Byte[] dataUInt16 = new byte[2];
            Byte[] dataUInt32 = new byte[4];

            _algorithmName = ParseName(ref memoryStream);

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            long timeHigh = (ushort) IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));
            memoryStream.Read(dataUInt32, 0, dataUInt32.Length);
            long timeLow = (uint) IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(dataUInt32, 0));
            _timeSigned = DnsHelpers.ConvertFromDnsTime(timeLow, timeHigh);

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            _fudge = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            Int32 macLen = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));
            _mac = new byte[macLen];
            memoryStream.Read(_mac, 0, macLen);

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            _originalId = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            _error = (RCode)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            Int32 otherLen = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            if(otherLen > 0)
            {
                _otherData = new byte[otherLen];
                memoryStream.Read(_otherData, 0, otherLen);
            }
            else
            {
                _otherData = null;
            }

            _answer = ToString();
        }
Exemplo n.º 48
0
 private static RCode SwapComparisonRegisters(RCode code)
 {
     switch (code)
     {
         case RCode.If_eq:
             return RCode.If_eq;
         case RCode.If_ne:
             return RCode.If_ne;
         case RCode.If_ge:
             return RCode.If_le;
         case RCode.If_gt:
             return RCode.If_lt;
         case RCode.If_le:
             return RCode.If_ge;
         case RCode.If_lt:
             return RCode.If_gt;
         default:
             throw new InvalidOperationException();
     }
 }
Exemplo n.º 49
0
 private Response CreateRecord(string domainName, string[] records, RCode responseCode = RCode.NoError)
 {
     return(CreateRecord(domainName, records.Select(_ => new[] { _ }).ToArray(), responseCode));
 }
Exemplo n.º 50
0
 public static bool WillTakeBranch(RCode code, int comparand)
 {
     switch (code)
     {
         case RCode.If_eqz:
             return comparand == 0;
         case RCode.If_gez:
             return comparand >= 0;
         case RCode.If_gtz:
             return comparand > 0;
         case RCode.If_lez:
             return comparand <= 0;
         case RCode.If_ltz:
             return comparand < 0;
         case RCode.If_nez:
             return comparand != 0;
         default:
             throw new InvalidOperationException();
     }
 }
Exemplo n.º 51
0
 /// <summary>
 /// Create and add an instruction.
 /// </summary>
 public static Instruction Add(this IRLBuilder builder, ISourceLocation sequencePoint, RCode opcode, object operand, params Register[] registers)
 {
     return builder.Add(sequencePoint, opcode, operand, registers);
 }
Exemplo n.º 52
0
 public Instruction(RCode code, params Register[] registers)
     : this(code, null, registers)
 {
 }
Exemplo n.º 53
0
 /// <summary>
 /// 수신된 패킷 처리
 /// </summary>
 /// <param name="buffer"></param>
 protected override void ReceivePacket(IoBuffer buffer)
 {
     hResult = RCode.GetCode(buffer);
 }
Exemplo n.º 54
0
 public bool IsComparisonToRegister(RCode code)
 {
     return code.IsComparisonBranch() && !IsComparisonWithZero(code);
 }