예제 #1
0
        public override void Serialize()
        {
            Data.SkipBytes(8);

            Data.ReadIntLE();   // unk
            Data.ReadShortLE(); // unk

            var PosY = Data.ReadShortLE();

            Data.ReadShortLE();            // unk
            var PosX = Data.ReadShortLE(); // CONFIRMED CORRECT

            Data.SkipBytes(15);            // unk stuff

            MoveType moveType = (MoveType)Data.ReadByte();

            Data.ReadIntLE(); // unk zeros

            Data.ResetReaderIndex();
            Logger.Debug($"\n{HexUtils.Dump(Data)}");
            Logger.Debug($"X,Y[{PosX}, {PosY}] MoveType[{moveType.ToString()}]");

            // DEBUG INFO

            /*
             * Logger.Debug(
             *  $"\nPos1: {pos1}\n" +
             *  $"Pos2: {pos2}\n" +
             *  $"Pos3: {pos3}\n" +
             *  $"PossibleZone: {possibleZone}\n" +
             *  $"UnkFloatOrInt: {pos4}\n" +
             *  $"IsMoving: {IsMoving}\n"
             *  );
             */
        }
예제 #2
0
        private async void LoadDump_OnClick(object?sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog {
                Filters = _filters, AllowMultiple = false
            };

            string[]? paths = await dlg.ShowAsync(this);

            if (paths == null || paths.Length < 1)
            {
                return;
            }

            ArrayList data;

            try
            {
                data = new ArrayList(await File.ReadAllBytesAsync(paths[0]));
                _cache.Clear();
                _cache.AddRange((byte[])data.ToArray(typeof(byte)));
                _hexDump.Text = HexUtils.Dump(_cache.ToArray());
            }
            catch (Exception ex)
            {
                await new MessageBox
                {
                    Title       = "Error while reading file",
                    Description = ex.Message
                }.ShowDialog(this);
                return;
            }
            do
            {
                try
                {
                    SPPMessage        msg    = SPPMessage.DecodeMessage((byte[])data.ToArray(typeof(byte)));
                    RecvMsgViewHolder holder = new RecvMsgViewHolder(msg);
                    _vm.MsgTableDataSource?.Add(holder);

                    if (msg.TotalPacketSize >= data.Count)
                    {
                        break;
                    }
                    data.RemoveRange(0, msg.TotalPacketSize);
                }
                catch (InvalidPacketException ex)
                {
                    await new MessageBox
                    {
                        Title       = "Error while parsing file",
                        Description = ex.Message
                    }.ShowDialog(this);
                    _vm.MsgTableDataView.Refresh();
                    return;
                }
            } while (data.Count > 0);

            _vm.MsgTableDataView.Refresh();
        }
예제 #3
0
 public void OnMessageAvailable(ref SPPMessage msg)
 {
     if (msg.Id == SPPMessage.MessageIds.MSG_ID_DEBUG_SKU)
     {
         Log.Information("[Script] DumpSKU: " + HexUtils.Dump(msg.Payload, showAscii: true, showHeader: false, showOffset: false));
         ScriptManager.Instance.UnregisterHook(this);
     }
 }
예제 #4
0
        private void OnNewDataReceived(object?sender, byte[] raw)
        {
            Dispatcher.UIThread.Post(() =>
            {
                try
                {
                    _cache.AddRange(raw);
                    _hexDump.Text = HexUtils.Dump(_cache.ToArray());

                    RecvMsgViewHolder holder = new RecvMsgViewHolder(SPPMessage.DecodeMessage(raw));
                    _vm.MsgTableDataSource?.Add(holder);
                    _vm.MsgTableDataView.Refresh();
                }
                catch (InvalidPacketException) {}
            });
        }
예제 #5
0
        public override Task WriteAsync(IChannelHandlerContext context, object msg)
        {
            if (!(msg is Packet packet))
            {
                return(base.WriteAsync(context, null));
            }

            packet.Deserialize();

            // DEBUG
            Logger.Debug("[S] - {0} - op[0x{1}] - length[{2}] - encrypted[{3}] - compression[{4}]",
                         packet.GetType().Name,
                         packet.OpCode.ToString("X"),
                         packet.Length,
                         packet.IsEncrypted.ToString(),
                         packet.CompressionType.ToString());

            Logger.Debug($"\n{HexUtils.Dump(packet.Data)}");

            if (packet.CompressionType != CompressionType.NONE)
            {
                packet.Compress(); // TODO: LZ4
            }
            if (packet.IsEncrypted)
            {
                packet.Encrypt();
            }

            var header = Unpooled.Buffer();

            packet.Length = (ushort)(packet.Data.ReadableBytes + 6); // current packet size + header length
            //packet.Length = (ushort)(packet.Data.ReadableBytes + 10); // 10 BYTE HEADER FOR RU

            header.WriteUnsignedShortLE((ushort)packet.Length);
            header.WriteUnsignedShortLE(packet.OpCode);
            header.WriteByte((byte)packet.CompressionType); // TODO: LZ4 (Flag: 1)
            header.WriteByte(packet.IsEncrypted ? 1 : 0);   // Crypt Flag

            // RU TEST
            //header.WriteIntLE(0);

            base.WriteAsync(context, header);

            return(base.WriteAsync(context, packet.Data));
        }
        public static BaseMessageParser?BuildParser(SPPMessage msg)
        {
            BaseMessageParser?b = null;

            for (int i = 0; i < RegisteredParsers.Length; i++)
            {
                var act = Activator.CreateInstance(RegisteredParsers[i]);
                if (act?.GetType() == RegisteredParsers[i])
                {
                    BaseMessageParser parser = (BaseMessageParser)act;
                    if (parser.HandledType == msg.Id)
                    {
                        SentrySdk.ConfigureScope(scope =>
                        {
                            scope.SetTag("msg-data-available", "true");
                            scope.SetExtra("msg-type", msg.Type.ToString());
                            scope.SetExtra("msg-id", msg.Id);
                            scope.SetExtra("msg-size", msg.Size);
                            scope.SetExtra("msg-total-size", msg.TotalPacketSize);
                            scope.SetExtra("msg-crc16", msg.Crc16);
                            scope.SetExtra("msg-payload", HexUtils.Dump(msg.Payload, 512, false, false, false));
                        });

                        parser.ParseMessage(msg);
                        b = parser;
                        break;
                    }
                }
            }

            if (b != null)
            {
                foreach (var hook in ScriptManager.Instance.DecoderHooks)
                {
                    hook?.OnDecoderCreated(msg, ref b);
                }
            }

            return(b);
        }
예제 #7
0
 public override void Serialize()
 {
     Logger.Debug("\n" + HexUtils.Dump(Data));
 }
예제 #8
0
 public override void Serialize()
 {
     // contains character name etc etc
     Logger.Debug("\n" + HexUtils.Dump(Data));
 }
예제 #9
0
        private async void LoadDump_OnClick(object?sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog {
                Filters = _filters, AllowMultiple = false
            };

            string[]? paths = await dlg.ShowAsync(this);

            if (paths == null || paths.Length < 1)
            {
                return;
            }

            ArrayList data;

            try
            {
                data = new ArrayList(await File.ReadAllBytesAsync(paths[0]));
                _cache.Clear();
                _cache.AddRange((byte[])data.ToArray(typeof(byte)));
                _hexDump.Text = HexUtils.Dump(_cache.ToArray());
            }
            catch (Exception ex)
            {
                await new MessageBox
                {
                    Title       = "Error while reading file",
                    Description = ex.Message
                }.ShowDialog(this);
                return;
            }

            var msgs      = new List <SPPMessage>();
            int failCount = 0;

            do
            {
                int        msgSize = 0;
                SPPMessage?msg     = null;
                try
                {
                    var raw = data.OfType <byte>().ToArray();

                    msg     = SPPMessage.DecodeMessage(raw);
                    msgSize = msg.TotalPacketSize;

                    msgs.Add(msg);

                    failCount = 0;
                }
                catch (InvalidPacketException)
                {
                    // Attempt to remove broken message, otherwise skip data block
                    var somIndex = 0;
                    for (int i = 1; i < data.Count; i++)
                    {
                        if ((BluetoothImpl.Instance.ActiveModel == Models.Buds &&
                             (byte)(data[i] ?? 0) == (byte)SPPMessage.Constants.SOM) ||
                            (BluetoothImpl.Instance.ActiveModel != Models.Buds &&
                             (byte)(data[i] ?? 0) == (byte)SPPMessage.Constants.SOMPlus))
                        {
                            somIndex = i;
                            break;
                        }
                    }

                    msgSize = somIndex;

                    if (failCount > 5)
                    {
                        // Abandon data block
                        break;
                    }

                    failCount++;
                }

                if (msgSize >= data.Count)
                {
                    data.Clear();
                    break;
                }

                data.RemoveRange(0, msgSize);

                if (ByteArrayUtils.IsBufferZeroedOut(data))
                {
                    /* No more data remaining */
                    break;
                }
            } while (data.Count > 0);

            foreach (var holder in msgs.Select(m => new RecvMsgViewHolder(m)))
            {
                _vm.MsgTableDataSource?.Add(holder);
            }
            _vm.MsgTableDataView.Refresh();
        }
예제 #10
0
    /* Dump incoming byte stream to console */
    public void OnRawDataAvailable(ref byte[] msg)
    {
        var dump = HexUtils.Dump(msg, showHeader: false, showAscii: false, showOffset: false);

        Console.WriteLine(dump);
    }