Example #1
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, SsaRegister regArg, CfgOutboundEdge[] cfgEdgesArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     RegArg = regArg;
     CfgEdgesArg = cfgEdgesArg;
 }
Example #2
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, SsaRegister regArg, SsaRegister regArg2)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     RegArg = regArg;
     RegArg2 = regArg2;
 }
Example #3
0
        public void get_token(string testval, OpcodeEnum result1, string result2)
        {
            var sourceLine = new SourceLine(testval);

            Assert.Equal(result1, sourceLine.OpCode);
            Assert.Equal(result2, sourceLine.Operand);
        }
Example #4
0
 public IntcodeInstruction(OpcodeEnum opcode, ParameterModesEnum firstParameterMode, ParameterModesEnum secondParameterMode, ParameterModesEnum thirdParameterMode)
 {
     Opcode              = opcode;
     FirstParameterMode  = firstParameterMode;
     SecondParameterMode = secondParameterMode;
     ThirdParameterMode  = thirdParameterMode;
 }
Example #5
0
 public ushort?GetOpcode(OpcodeEnum opcode)
 {
     if (!ReverseKnownOpcode.ContainsKey(opcode))
     {
         return(null);
     }
     return(ReverseKnownOpcode[opcode]);
 }
Example #6
0
        public KeyValuePair <long, ParsedMessage>?LastOccurrence(OpcodeEnum opcode)
        {
            if (!IsKnown(opcode))
            {
                return(null);
            }

            return(AllPackets.Where(x => x.Value.OpCode == ReverseKnownOpcode[opcode]).Last());
        }
Example #7
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, SsaRegister regArg, SsaRegister regArg2, string strArg, CLRTypeSpec typeSpecArg, CLRTypeSpec typeSpecArg2)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     RegArg = regArg;
     RegArg2 = regArg2;
     StrArg = strArg;
     TypeSpecArg = typeSpecArg;
     TypeSpecArg2 = typeSpecArg2;
 }
Example #8
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="command">The command.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public bool ExecCommand(OpcodeEnum code, string command)
        {
            if (!IsConnected)
            {
                return(false);
            }

            Client.SendPacket(new Packet(code, PacketTypeEnum.ExecCommand, command));
            return(true);
        }
Example #9
0
        private static int[] TranslateBatchOfIntCode(OpcodeEnum opcode, int index, int[] testInput)
        {
            switch (opcode)
            {
            case OpcodeEnum.Add:
                return(AddBatchOfIntCode(index, testInput));

            case OpcodeEnum.Multiply:
                return(MultiplyBatchOfIntCode(index, testInput));

            default:
                throw new Exception("Invalid opcode upstream");
            }
        }
Example #10
0
        private static int[] ProcessIntCode(int[] testInput)
        {
            for (int i = 0; i < testInput.Length; i += 4)
            {
                OpcodeEnum opcode = GetOpcode(i, testInput);

                if (opcode == OpcodeEnum.EndProgram)
                {
                    return(testInput);
                }

                testInput = TranslateBatchOfIntCode(opcode, i, testInput);
            }
            return(testInput);
        }
Example #11
0
 // Once your module found a new opcode
 public void SetOpcode(OpcodeId opcode, OpcodeEnum opcodeName)
 {
     if (KnownOpcode.ContainsKey(opcode))
     {
         KnownOpcode.TryGetValue(opcode, out var value);
         throw new Exception("opcode: " + opcode + " is already know = " + value + " . You try to add instead = " + Enum.GetName(typeof(OpcodeEnum), opcodeName));
     }
     if (KnownOpcode.Values.Contains(opcodeName))
     {
         throw new Exception("opcodename: " + Enum.GetName(typeof(OpcodeEnum), opcodeName) + " is already know = " + opcode);
     }
     Console.WriteLine(opcode + " => " + opcodeName);
     ReverseKnownOpcode.Add(opcodeName, opcode);
     KnownOpcode.Add(opcode, opcodeName);
     NetworkController.Instance.UiUpdateKnownOpcode.Add(opcode, opcodeName);
 }
Example #12
0
 // NOT TESTED
 public bool PacketSeenInTheLastXms(OpcodeEnum opcode, DateTime now, long ms)
 {
     if (!ReverseKnownOpcode.ContainsKey(opcode))
     {
         return(false);
     }
     for (var i = PacketCount; i > 0; --i)
     {
         var packet = AllPackets[i];
         if (packet.Time.Ticks < now.Ticks - TimeSpan.TicksPerMillisecond * ms)
         {
             return(false);
         }
         if (packet.OpCode == ReverseKnownOpcode[opcode])
         {
             return(true);
         }
     }
     return(false);
 }
Example #13
0
        internal Opcode(byte code, OpcodeEnum @enum, AddressingMode mode, byte cycles)
        {
            Code   = code;
            Enum   = @enum;
            Mode   = mode;
            Cycles = cycles;

            if (Mode == AddressingMode.Implied)
            {
                Length = 0;
            }
            else if (Mode == AddressingMode.Absolute || Mode == AddressingMode.AbsoluteX ||
                     Mode == AddressingMode.AbsoluteY || Mode == AddressingMode.Indirect)
            {
                Length = 2;
            }
            else
            {
                Length = 1;
            }
        }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Packet"/> class.
 /// </summary>
 /// <param name="opcode">The opcode.</param>
 /// <param name="type">The type.</param>
 /// <param name="data">The data.</param>
 public Packet(OpcodeEnum opcode, PacketTypeEnum type, int data) : this(opcode, type, data.ToString())
 {
 }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Packet"/> class.
 /// </summary>
 /// <param name="opcode">The opcode.</param>
 /// <param name="type">The type.</param>
 /// <param name="data">The data.</param>
 public Packet(OpcodeEnum opcode, PacketTypeEnum type, string data) : this(opcode, type, Encoding.Default.GetBytes(data + "\0"))
 {
 }
Example #16
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, CfgOutboundEdge cfgEdgeArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     CfgEdgeArg = cfgEdgeArg;
 }
Example #17
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, VReg vRegArg, SsaRegister regArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     VRegArg = vRegArg;
     RegArg = regArg;
 }
Example #18
0
 public bool IsKnown(OpcodeEnum opcode) => ReverseKnownOpcode.ContainsKey(opcode);
Example #19
0
		static async public Task<WebSocketPacket> ReadPacketFromStreamAsync(int Version, NodeBufferedStream Stream)
		{
			var Packet = default(WebSocketPacket);

			if (Version <= 0)
			{
				var PayloadBegin = await Stream.ReadBytesAsync(1);
				if (PayloadBegin[0] != 0x00) throw(new Exception("Invalid Packet"));
				Packet.Opcode = OpcodeEnum.TextFrame;
				Packet.Payload = await Stream.ReadBytesUntilByteAsync(0xFF);
			}
			else
			{
				var Header = new byte[2];
				var Size = new byte[8];
				var SizeSize = 0;
				var Mask = new byte[4];
				var Data = new MemoryStream();
				var Temp = new byte[128];
				WebSocketPacket.OpcodeEnum Opcode;
				bool IsFinal;
				bool IsMasked;
				int PayloadLength;

				do
				{
					await Stream.ReadAsync(Header, 0, 2);
					IsFinal = (((Header[0] >> 7) & 0x1) != 0);
					Opcode = (WebSocketPacket.OpcodeEnum)((Header[0] >> 0) & 0x7);
					PayloadLength = (Header[1] >> 0) & 0x7F;
					IsMasked = ((Header[1] >> 7) & 0x1) != 0;

					if (Opcode != OpcodeEnum.ContinuationFrame)
					{
						Packet.Opcode = Opcode;
					}

					// EXTENDED PayloadLength
					if (PayloadLength >= 0x7E)
					{
						if (PayloadLength == 0x7E)
						{
							SizeSize = 2;
						}
						else if (PayloadLength == 0x7F)
						{
							SizeSize = 8;
						}
						await Stream.ReadAsync(Size, 0, SizeSize);
						PayloadLength = 0;
						for (int n = 0; n < SizeSize; n++)
						{
							PayloadLength <<= 8;
							PayloadLength |= Size[n];
						}
					}

					// MASK
					if (IsMasked)
					{
						await Stream.ReadAsync(Mask, 0, 4);
					}

					// Read Payload
					await Stream.ReadAsync(Temp, 0, PayloadLength);

					// Perform unmasking
					if (IsMasked)
					{
						for (int n = 0; n < PayloadLength; n++) Temp[n] ^= Mask[n % 4];
					}

					Data.Write(Temp, 0, PayloadLength);
				} while (!IsFinal);

				Packet.Payload = Data.ToArray();
			}

			return Packet;
		}
Example #20
0
 public OpcodeDTO(OpcodeEnum type, ushort opcode, uint length, uint[] data) : this((ushort)type, opcode, length, data)
 {
 }
Example #21
0
 public MessageEventArgs(OpcodeEnum opcode, byte[] payload, bool more)
 {
     Opcode = opcode;
     Payload = payload;
     More = more;
 }
Example #22
0
        void Process(byte b)
        {
            switch (m_state)
            {
            case State.NewMessage:
                m_final  = (b & FinalBit) != 0;
                m_opcode = (OpcodeEnum)(b & 0xF);
                m_state  = State.SecondByte;
                break;

            case State.SecondByte:
                m_isMaksed = (b & MaskedBit) != 0;
                byte length = (byte)(b & 0x7F);

                if (length < 126)
                {
                    m_payloadLength = length;
                    m_state         = NextState();
                }
                else if (length == 126)
                {
                    m_state = State.ShortSize;
                }
                else
                {
                    m_state = State.LongSize;
                }
                break;

            case State.Mask:
                m_mask[0] = b;
                m_state   = State.Mask2;
                break;

            case State.Mask2:
                m_mask[1] = b;
                m_state   = State.Mask3;
                break;

            case State.Mask3:
                m_mask[2] = b;
                m_state   = State.Mask4;
                break;

            case State.Mask4:
                m_mask[3] = b;
                m_state   = NextState();
                break;

            case State.ShortSize:
                m_payloadLength = b << 8;
                m_state         = State.ShortSize2;
                break;

            case State.ShortSize2:
                m_payloadLength |= b;
                m_state          = NextState();
                break;

            case State.LongSize:
                m_payloadLength = 0;

                // must be zero, max message size is MaxInt
                Debug.Assert(b == 0);
                m_state = State.LongSize2;
                break;

            case State.LongSize2:
                // must be zero, max message size is MaxInt
                Debug.Assert(b == 0);
                m_state = State.LongSize3;
                break;

            case State.LongSize3:
                // must be zero, max message size is MaxInt
                Debug.Assert(b == 0);
                m_state = State.LongSize4;
                break;

            case State.LongSize4:
                // must be zero, max message size is MaxInt
                Debug.Assert(b == 0);
                m_state = State.LongSize5;
                break;

            case State.LongSize5:
                m_payloadLength |= b << 24;
                m_state          = State.LongSize6;
                break;

            case State.LongSize6:
                m_payloadLength |= b << 16;
                m_state          = State.LongSize7;
                break;

            case State.LongSize7:
                m_payloadLength |= b << 8;
                m_state          = State.LongSize8;
                break;

            case State.LongSize8:
                m_payloadLength |= b;
                m_state          = NextState();
                break;

            case State.MoreByte:
                // The first byte of the payload is the more bit

                if (m_isMaksed)
                {
                    m_more = (b ^ m_mask[0]) == 1;
                }
                else
                {
                    m_more = b == 1;
                }

                m_payloadLength--;

                m_state = State.Payload;
                break;
            }
        }
Example #23
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, bool flagArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     FlagArg = flagArg;
 }
Example #24
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, SsaRegister regArg, uint uintArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     RegArg = regArg;
     UIntArg = uintArg;
 }
Example #25
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, SsaRegister regArg, SsaRegister regArg2, SsaRegister regArg3, bool flagArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     RegArg = regArg;
     RegArg2 = regArg2;
     RegArg3 = regArg3;
     FlagArg = FlagArg;
 }
Example #26
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, SsaRegister regArg, SsaRegister regArg2, ArithEnum arithArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     RegArg = regArg;
     RegArg2 = regArg2;
     ArithArg = arithArg;
 }
Example #27
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, uint uintArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     UIntArg = uintArg;
 }
Example #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Packet"/> class.
 /// </summary>
 /// <param name="opcode">The opcode.</param>
 /// <param name="type">The type.</param>
 public Packet(OpcodeEnum opcode, PacketTypeEnum type) : this(opcode, type, "")
 {
 }
Example #29
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, SsaRegister regArg, CLRTypeSpec typeSpec, string strArg, bool flagArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     RegArg = regArg;
     TypeSpecArg = typeSpec;
     StrArg = strArg;
     FlagArg = flagArg;
 }
Example #30
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, SsaRegister regArg, SsaRegister regArg2, CfgOutboundEdge cfgEdgeArg, bool flagArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     RegArg = regArg;
     RegArg2 = regArg2;
     CfgEdgeArg = cfgEdgeArg;
     FlagArg = flagArg;
 }
Example #31
0
 public void Send(OpcodeEnum type, ushort opcode, uint length, uint[] data)
 {
     Send(new OpcodeDTO(type, opcode, length, data));
 }
Example #32
0
 public void Execute(OpcodeEnum opcodeEnum, AddressingMode mode, ushort parameter = 0)
 {
     InnerExecute(_opcodes.Get(opcodeEnum, mode), parameter, 0, 0);
 }
Example #33
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
 }
Example #34
0
 public void Execute(OpcodeEnum opcodeEnum, ushort parameter = 0)
 {
     InnerExecute(_opcodes.Get(opcodeEnum), parameter, 0, 0);
 }
Example #35
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, SsaRegister regArg, CLRTypeSpec typeSpec)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     RegArg = regArg;
     TypeSpecArg = typeSpec;
 }
Example #36
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, CppMethodSpec methodSpecArg, CLRTypeSpec typeSpecArg, SsaRegister regArg, SsaRegister regArg2, SsaRegister[] regArgs)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     TypeSpecArg = typeSpecArg;
     MethodSpecArg = methodSpecArg;
     RegArg = regArg;
     RegArg2 = regArg2;
     RegArgs = regArgs;
 }
Example #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Packet"/> class.
 /// </summary>
 /// <param name="opcode">The opcode.</param>
 /// <param name="type">The type.</param>
 /// <param name="data">The data.</param>
 public Packet(OpcodeEnum opcode, PacketTypeEnum type, byte[] data) : this()
 {
     Opcode = opcode;
     Type   = type;
     Data   = data;
 }
Example #38
0
 public MidInstruction(OpcodeEnum opcode, CodeLocationTag codeLocation, ExceptionHandlingCluster ehClusterArg)
 {
     Opcode = opcode;
     CodeLocation = codeLocation;
     EhClusterArg = ehClusterArg;
 }
Example #39
0
 public MessageEventArgs(OpcodeEnum opcode, byte[] payload, bool more)
 {
     Opcode  = opcode;
     Payload = payload;
     More    = more;
 }
Example #40
0
        void Process(byte b)
        {
            switch (m_state)
            {
                case State.NewMessage:
                    m_final = (b & FinalBit) != 0;
                    m_opcode = (OpcodeEnum)(b & 0xF);
                    m_state = State.SecondByte;                   
                    break;
                case State.SecondByte:
                    m_isMaksed = (b & MaskedBit) != 0;
                    byte length = (byte)(b & 0x7F);

                    if (length < 126)
                    {
                        m_payloadLength = length;
                        m_state = NextState();
                    }
                    else if (length == 126)
                    {
                        m_state = State.ShortSize;
                    }
                    else
                    {
                        m_state = State.LongSize;
                    }
                    break;
                case State.Mask:
                    m_mask[0] = b;
                    m_state = State.Mask2;
                    break;
                case State.Mask2:
                    m_mask[1] = b;
                    m_state = State.Mask3;
                    break;
                case State.Mask3:
                    m_mask[2] = b;
                    m_state = State.Mask4;
                    break;
                case State.Mask4:
                    m_mask[3] = b;
                    m_state = NextState();
                    break;
                case State.ShortSize:
                    m_payloadLength = b << 8;
                    m_state = State.ShortSize2;
                    break;
                case State.ShortSize2:
                    m_payloadLength |= b;
                    m_state = NextState();
                    break;
                case State.LongSize:
                    m_payloadLength = 0;

                    // must be zero, max message size is MaxInt
                    Debug.Assert(b == 0);
                    m_state = State.LongSize2;
                    break;
                case State.LongSize2:
                    // must be zero, max message size is MaxInt
                    Debug.Assert(b == 0);
                    m_state = State.LongSize3;
                    break;
                case State.LongSize3:
                    // must be zero, max message size is MaxInt
                    Debug.Assert(b == 0);
                    m_state = State.LongSize4;
                    break;
                case State.LongSize4:
                    // must be zero, max message size is MaxInt
                    Debug.Assert(b == 0);
                    m_state = State.LongSize5;
                    break;
                case State.LongSize5:
                    m_payloadLength |= b << 24;
                    m_state = State.LongSize6;
                    break;
                case State.LongSize6:
                    m_payloadLength |= b << 16;
                    m_state = State.LongSize7;
                    break;
                case State.LongSize7:
                    m_payloadLength |= b << 8;
                    m_state = State.LongSize8;
                    break;
                case State.LongSize8:
                    m_payloadLength |= b;
                    m_state = NextState();
                    break;
                case State.MoreByte:
                    // The first byte of the payload is the more bit                  

                    if (m_isMaksed)
                    {
                        m_more = (b ^ m_mask[0]) == 1;
                    }
                    else
                    {
                        m_more = b == 1;
                    }

                    m_payloadLength--;

                    m_state = State.Payload;
                    break;
            }
        }