public static List <ProcInfo> GetProcessList(this MiraConnection p_Connection)
        {
            p_Connection.SendMessage(new RpcMessageHeader
            {
                Category    = (int)RPC_CATEGORY.RPCCAT_DBG,
                Magic       = MiraConnection.c_Magic,
                ErrorType   = (int)DebuggerCmds.Debugger_GetProcs,
                Request     = true,
                PayloadSize = 0
            }.ToUInt64());

            var s_Procs = new List <ProcInfo>();

            using (var s_Reader = new BinaryReader(p_Connection.GetStream(), Encoding.ASCII, true))
            {
                while (true)
                {
                    var s_Proc = p_Connection.ReceiveObject <ProcInfo>();
                    // We can check any of the variables for the end finalizer
                    if ((uint)s_Proc.ProcessId == 0xDDDDDDDD)
                    {
                        break;
                    }

                    s_Procs.Add(s_Proc);
                }
            }

            return(s_Procs);
        }
        public static void WriteMemory(this MiraConnection p_Connection, int p_ProcessId, ulong p_Address, byte[] p_Data)
        {
            var s_HeaderData = p_Connection.SerializeObject(new RpcMessageHeader
            {
                Category    = (int)RPC_CATEGORY.RPCCAT_DBG,
                Magic       = MiraConnection.c_Magic,
                ErrorType   = (int)DebuggerCmds.Debugger_WriteMem,
                Request     = true,
                PayloadSize = (ushort)Marshal.SizeOf <ReadWriteMem>()
            }.ToUInt64());

            var s_Payload = new ReadWriteMem
            {
                ProcessId  = p_ProcessId,
                Address    = p_Address,
                DataLength = (ulong)p_Data.LongLength,
                Data       = new byte[0x1000]
            };

            Array.Copy(p_Data, 0, s_Payload.Data, 0, p_Data.Length);

            var s_PayloadData = p_Connection.SerializeObject(s_Payload);

            using (var s_Writer = new BinaryWriter(p_Connection.GetStream(), Encoding.ASCII, true))
            {
                s_Writer.Write(s_HeaderData);
                s_Writer.Write(s_PayloadData);
            }
        }
        public static byte[] Read(this MiraConnection p_Connection, int p_Descriptor, uint p_Offset, ulong p_Size)
        {
            if (!p_Connection.Connected)
            {
                return(null);
            }

            if (p_Descriptor < 0)
            {
                return(null);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Magic       = MiraConnection.c_Magic,
                Category    = (int)RPC_CATEGORY.RPCCAT_FILE,
                Request     = true,
                ErrorType   = (int)FileTransferCmds.FileTransfer_Read,
                PayloadSize = (ushort)Marshal.SizeOf <FileTransferRead>(),
            }, p_Connection.SerializeObject(new FileTransferRead
            {
                Handle = p_Descriptor,
                Offset = p_Offset,
                Size   = p_Size
            }));

            var s_Response = new RpcMessageHeader(p_Connection.ReceiveObject <ulong>());

            if (s_Response.ErrorType != 0)
            {
                return(null);
            }

            var s_Payload = p_Connection.ReceiveObject <FileTransferRead>();

            var s_BlockCount = s_Payload.Size / 0x4000;
            var s_Leftover   = s_Payload.Size % 0x4000;

            byte[] s_Data;
            using (var s_Reader = new BinaryReader(p_Connection.GetStream(), Encoding.ASCII, true))
            {
                using (var s_Writer = new BinaryWriter(new MemoryStream()))
                {
                    for (ulong i = 0; i < s_BlockCount; ++i)
                    {
                        s_Writer.Write(s_Reader.ReadBytes(0x4000));
                    }

                    s_Writer.Write(s_Reader.ReadBytes((int)s_Leftover));
                    s_Data = ((MemoryStream)s_Writer.BaseStream).ToArray();
                }
            }

            return(s_Data);
        }
        public static void ReadFile(this MiraConnection p_Connection, string p_SourcePath, string p_LocalPath)
        {
            if (!p_Connection.Connected)
            {
                return;
            }

            int s_Descriptor = p_Connection.Open(p_SourcePath, 0, 0);

            if (s_Descriptor < 0)
            {
                return;
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Magic       = MiraConnection.c_Magic,
                Category    = (int)RPC_CATEGORY.RPCCAT_FILE,
                Request     = true,
                ErrorType   = (int)FileTransferCmds.FileTransfer_ReadFile,
                PayloadSize = (ushort)Marshal.SizeOf <FileTransferReadFile>()
            }, p_Connection.SerializeObject(new FileTransferReadFile
            {
                Handle = s_Descriptor,
                Size   = 0
            }));

            var s_Result = new RpcMessageHeader(p_Connection.ReceiveObject <ulong>());

            if (s_Result.ErrorType != 0)
            {
                return;
            }

            var s_Response = p_Connection.ReceiveObject <FileTransferReadFile>();

            var s_BlockCount = s_Response.Size / 0x4000;
            var s_Leftover   = s_Response.Size % 0x4000;

            using (var s_Reader = new BinaryReader(p_Connection.GetStream(), Encoding.ASCII, true))
            {
                using (var s_Writer = new BinaryWriter(new FileStream(p_LocalPath, FileMode.Create, FileAccess.ReadWrite)))
                {
                    for (ulong i = 0; i < s_BlockCount; ++i)
                    {
                        s_Writer.Write(s_Reader.ReadBytes(0x4000));
                    }

                    s_Writer.Write(s_Reader.ReadBytes((int)s_Leftover));
                }
            }

            // Close the handle
            p_Connection.Close(s_Descriptor);
        }
        public static bool WriteFile(this MiraConnection p_Connection, string p_Path, byte[] p_Data)
        {
            if (!p_Connection.Connected)
            {
                return(false);
            }

            var s_Descriptor = p_Connection.Open(p_Path, 0x0002 | 0x0200 /* O_RDWR | O_CREAT*/, 0777);

            if (s_Descriptor < 0)
            {
                return(false);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Magic       = MiraConnection.c_Magic,
                Category    = (int)RPC_CATEGORY.RPCCAT_FILE,
                Request     = true,
                ErrorType   = (int)FileTransferCmds.FileTransfer_WriteFile,
                PayloadSize = (ushort)Marshal.SizeOf <FileTransferWriteFile>()
            }, p_Connection.SerializeObject(new FileTransferWriteFile
            {
                Handle = s_Descriptor,
                Size   = (ulong)p_Data.Length
            }));

            var s_BlockCount = p_Data.Length / 0x4000;
            var s_Leftover   = p_Data.Length % 0x4000;

            using (var s_Reader = new BinaryReader(new MemoryStream(p_Data)))
            {
                using (var s_Writer = new BinaryWriter(p_Connection.GetStream(), Encoding.ASCII, true))
                {
                    for (int i = 0; i < s_BlockCount; ++i)
                    {
                        s_Writer.Write(s_Reader.ReadBytes(0x4000));
                    }

                    s_Writer.Write(s_Reader.ReadBytes((int)s_Leftover));
                }
            }

            var s_Result = new RpcMessageHeader(p_Connection.ReceiveObject <ulong>());

            p_Connection.Close(s_Descriptor);

            return(s_Result.ErrorType == 0);
        }
        public static IEnumerable <FileTransferGetdents> GetDents(this MiraConnection p_Connection, string p_Path)
        {
            if (!p_Connection.Connected)
            {
                return(null);
            }

            // Send the request
            p_Connection.SendMessage(new RpcMessageHeader
            {
                Magic       = MiraConnection.c_Magic,
                Category    = (int)RPC_CATEGORY.RPCCAT_FILE,
                Request     = true,
                ErrorType   = (int)FileTransferCmds.FileTransfer_GetDents,
                PayloadSize = (ushort)Marshal.SizeOf <FileTransferGetdents>(),
            }, p_Connection.SerializeObject(new FileTransferGetdents
            {
                Path   = p_Path,
                Handle = -1,
                Type   = 0
            }));

            // Check the result
            var s_Result = new RpcMessageHeader(p_Connection.ReceiveObject <ulong>());

            if (s_Result.ErrorType != 0)
            {
                return(Enumerable.Empty <FileTransferGetdents>());
            }

            // Read the amount of directory entries
            var   s_List      = new List <FileTransferGetdents>();
            ulong s_DentCount = 0;

            using (var s_Reader = new BinaryReader(p_Connection.GetStream(), Encoding.ASCII, true))
                s_DentCount = s_Reader.ReadUInt64();

            Debug.WriteLine($"Dent Count: {s_DentCount}");

            for (ulong i = 0; i < s_DentCount; ++i)
            {
                s_List.Add(p_Connection.ReceiveObject <FileTransferGetdents>());
            }

            return(s_List);
        }
        public static byte[] DecryptExecutableFile(this MiraConnection p_Connection, string p_Path)
        {
            if (p_Path.Length > 255)
            {
                return(null);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Category    = (int)RPC_CATEGORY.RPCCAT_SYSTEM,
                PayloadSize = (ushort)Marshal.SizeOf <DecryptExecutable>(),
                Request     = true,
                Magic       = MiraConnection.c_Magic,
                ErrorType   = unchecked ((int)UtilityCmds.UtilityCmd_DecryptExecutable)
            }, new DecryptExecutable
            {
                Path = p_Path
            });

            byte[] s_Data;
            using (var s_Writer = new BinaryWriter(new MemoryStream()))
            {
                using (var s_Reader = new BinaryReader(p_Connection.GetStream(), Encoding.ASCII, true))
                {
                    var s_Offset = s_Reader.ReadUInt64();
                    var s_Length = s_Reader.ReadUInt64();
                    while (s_Length != 0)
                    {
                        s_Writer.Seek((int)s_Offset, SeekOrigin.Begin);
                        s_Writer.Write(s_Reader.ReadBytes((int)s_Length));
                        s_Offset = s_Reader.ReadUInt64();
                        s_Length = s_Reader.ReadUInt64();
                    }
                }

                s_Data = ((MemoryStream)s_Writer.BaseStream).ToArray();
            }

            return(s_Data);
        }
        public static byte[] ReadFile(this MiraConnection p_Connection, string p_Path)
        {
            if (!p_Connection.Connected)
            {
                return(null);
            }

            int s_Descriptor = p_Connection.Open(p_Path, 0, 0);

            if (s_Descriptor < 0)
            {
                return(null);
            }

            var s_HeaderData = p_Connection.SerializeObject(new RpcMessageHeader
            {
                Magic       = MiraConnection.c_Magic,
                Category    = (int)RPC_CATEGORY.RPCCAT_FILE,
                Request     = true,
                ErrorType   = (int)FileTransferCmds.FileTransfer_ReadFile,
                PayloadSize = (ushort)Marshal.SizeOf <FileTransferReadFile>()
            });

            var s_RequestData = p_Connection.SerializeObject(new FileTransferReadFile
            {
                Handle = s_Descriptor,
                Size   = 0
            });

            using (var s_Writer = new BinaryWriter(p_Connection.GetStream(), Encoding.ASCII, true))
            {
                s_Writer.Write(s_HeaderData);
                s_Writer.Write(s_RequestData);
            }

            var s_Response = p_Connection.ReceiveObject <FileTransferReadFile>();

            var s_BlockCount  = s_Response.Size / 0x4000;
            var s_Leftover    = s_Response.Size % 0x4000;
            var s_CurrentSize = 0;

            byte[] s_Data;
            using (var s_Reader = new BinaryReader(p_Connection.GetStream(), Encoding.ASCII, true))
            {
                using (var s_Writer = new BinaryWriter(new MemoryStream()))
                {
                    for (ulong i = 0; i < s_BlockCount; ++i)
                    {
                        s_CurrentSize += 0x4000;
                        s_Writer.Write(s_Reader.ReadBytes(0x4000));
                    }


                    s_Writer.Write(s_Reader.ReadBytes((int)s_Leftover));

                    s_Data = ((MemoryStream)s_Writer.BaseStream).ToArray();
                }
            }

            // Close the handle
            p_Connection.Close(s_Descriptor);

            return(s_Data);
        }