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 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);
        }
Пример #3
0
        public static FmStatResponse Stat(this MiraConnection p_Connection, string p_Path)
        {
            if (p_Connection == null)
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(p_Path))
            {
                return(null);
            }

            var s_Handle = p_Connection.Open(p_Path, (int)OpenOnlyFlags.O_RDONLY, 0777);

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

            var s_Stat = p_Connection.Stat(s_Handle);

            p_Connection.Close(s_Handle);

            return(s_Stat);
        }
Пример #4
0
 public FileManagerViewModel(MiraConnection connection) : base("File Manager")
 {
     ContentId    = ToolContentId;
     m_Connection = connection;
     listItems    = new BindableCollection <FileDetails>();
     Initialize();
 }
Пример #5
0
        public static bool Unlink(this MiraConnection p_Connection, string p_Path)
        {
            if (p_Connection == null)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(p_Path))
            {
                return(false);
            }

            if (p_Path.Length > c_MaxPathLength)
            {
                return(false);
            }

            throw new NotImplementedException();
            //var s_Message = new Message(
            //    MessageCategory.File,
            //    (uint)FileExplorerCommands.FileExplorer_Unlink,
            //    true,
            //    new FileExplorerUnlinkRequest(p_Path).Serialize());

            //return p_Connection.SendMessage(s_Message);
        }
Пример #6
0
        public static void Close(this MiraConnection p_Connection, int p_Handle)
        {
            if (p_Connection == null)
            {
                return;
            }

            if (p_Handle < 0)
            {
                return;
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Close
                },
                Data = ByteString.CopyFrom
                       (
                    new FmCloseRequest
                {
                    Handle = p_Handle
                }.ToByteArray()
                       )
            };

            // We don't care about the response
            p_Connection.SendMessageWithResponse(s_Transport);
        }
        public static bool GetHDDKeys(this MiraConnection p_Connection, out DumpHddKeys p_Output)
        {
            p_Output = new DumpHddKeys
            {
                Encrypted = new byte[0x60],
                Key       = new byte[0x20]
            };

            if (!p_Connection.Connected)
            {
                return(false);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Category    = (int)RPC_CATEGORY.RPCCAT_SYSTEM,
                Magic       = MiraConnection.c_Magic,
                ErrorType   = unchecked ((int)UtilityCmds.OrbisUtils_DumpHddKeys),
                Request     = true,
                PayloadSize = (ushort)Marshal.SizeOf <DumpHddKeys>()
            }, p_Connection.SerializeObject(p_Output));

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

            if (s_Result.ErrorType < 0)
            {
                return(false);
            }

            new RpcMessageHeader(p_Connection.ReceiveObject <ulong>());
            p_Output = p_Connection.ReceiveObject <DumpHddKeys>();

            return(true);
        }
        public static DebuggerPtrace Ptrace(this MiraConnection p_Connection, int p_Request, int p_ProcessId, ulong p_Address, int p_Data, bool p_UseInternalBuffer = false, byte[] p_BufferData = null)
        {
            var s_Data = new byte[0x800];

            if (p_BufferData != null && p_BufferData.Length <= s_Data.Length)
            {
                Buffer.BlockCopy(p_BufferData, 0, s_Data, 0, p_BufferData.Length);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Category    = (int)RPC_CATEGORY.RPCCAT_DBG,
                Magic       = MiraConnection.c_Magic,
                ErrorType   = unchecked ((int)DebuggerCmds.Debugger_Ptrace),
                Request     = true,
                PayloadSize = (ushort)Marshal.SizeOf <DebuggerPtrace>()
            }, p_Connection.SerializeObject(new DebuggerPtrace
            {
                Address            = p_Address,
                Buffer             = s_Data,
                Data               = p_Data,
                ProcessId          = p_ProcessId,
                Request            = p_Request,
                SetAddressToBuffer = p_UseInternalBuffer ? 1 : 0
            }));

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

            return(s_Response);
        }
        public static byte[] ReadMemory(this MiraConnection p_Connection, int p_ProcessId, ulong p_Address,
                                        ushort p_Size)
        {
            if (p_Size > 0x1000)
            {
                return(null);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Category    = (int)RPC_CATEGORY.RPCCAT_DBG,
                Magic       = MiraConnection.c_Magic,
                ErrorType   = (int)DebuggerCmds.Debugger_ReadMem,
                Request     = true,
                PayloadSize = (ushort)Marshal.SizeOf <ReadWriteMem>()
            }, new ReadWriteMem
            {
                ProcessId  = p_ProcessId,
                Address    = p_Address,
                DataLength = p_Size,
                Data       = new byte[0x1000]
            });

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

            return(s_Response.Data);
        }
Пример #10
0
        public MiraDevice(string p_Hostname, ushort p_Port)
        {
            Hostname = p_Hostname;
            Port     = p_Port;

            Connection = new MiraConnection(Hostname, Port);

            m_Consoles = new List <MiraConsole>();
        }
        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);
        }
Пример #14
0
        public static byte[] Read(this MiraConnection p_Connection, int p_Handle, ulong p_Offset, int p_Count)
        {
            if (p_Connection == null)
            {
                return(null);
            }

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

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Read
                },
                Data = ByteString.CopyFrom
                       (
                    // TODO: Add offset
                    new FmReadRequest
                {
                    Handle = p_Handle,
                    Size   = (uint)p_Count
                }.ToByteArray()
                       )
            };

            var s_ResponseData = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_ResponseData == null)
            {
                return(null);
            }

            var s_Response = FmReadResponse.Parser.ParseFrom(s_ResponseData.Data);

            if (s_Response == null)
            {
                return(null);
            }

            return(s_Response.Data.ToArray());
        }
Пример #15
0
        public static List <FmDent> GetDents(this MiraConnection p_Connection, string p_Path)
        {
            if (p_Connection == null)
            {
                return(new List <FmDent>());
            }

            if (string.IsNullOrWhiteSpace(p_Path))
            {
                return(new List <FmDent>());
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_GetDents
                },
                Data = ByteString.CopyFrom
                       (
                    new FmGetDentsRequest
                {
                    Path = p_Path
                }.ToByteArray()
                       )
            };

            var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_ResponseTransport == null)
            {
                return(new List <FmDent>());
            }

            var s_Response = FmGetDentsResponse.Parser.ParseFrom(s_ResponseTransport.Data);

            if (s_Response == null)
            {
                return(new List <FmDent>());
            }

            return(s_Response.Dents.ToList());
        }
Пример #16
0
        public static byte[] DecryptSelf(this MiraConnection p_Connection, string p_Path)
        {
            if (p_Connection == null)
            {
                return(null);
            }

            if (p_Path.Length > FileExplorerExtensions.c_MaxPathLength)
            {
                return(null);
            }

            throw new NotImplementedException();
            //var s_Request = new Message(
            //    MessageCategory.File,
            //    (uint)FileExplorerCommands.FileExplorer_DecryptSelf,
            //    true,
            //    new FileExplorerDecryptSelfRequest(p_Path).Serialize());

            //p_Connection.SendMessage(s_Request);

            //var s_ResponseList = new List<FileExplorerDecryptSelfResponse>();
            //do
            //{
            //    var (s_Response, s_Payload) = p_Connection.RecvMessage<FileExplorerDecryptSelfResponse>(s_Request);
            //    if (s_Response == null || s_Response?.Error < 0 || s_Payload == null)
            //        return null;

            //    var s_ChunkIndex = s_Payload.Index;
            //    if (s_ChunkIndex == ulong.MaxValue)
            //        break;

            //    s_ResponseList.Add(s_Payload);
            //}
            //while (true);

            //using (var s_Writer = new BinaryWriter(new MemoryStream()))
            //{
            //    for (var i = 0; i < s_ResponseList.Count; ++i)
            //    {
            //        s_Writer.Seek((int)s_ResponseList[i].Offset, SeekOrigin.Begin);
            //        s_Writer.Write(s_ResponseList[i].Data);
            //    }

            //    return ((MemoryStream)s_Writer.BaseStream).ToArray();
            //}
        }
Пример #17
0
        public static List <byte> DownloadFileToByteArray(this MiraConnection p_Connection, string p_Path)
        {
            List <byte> s_Bytes      = new List <byte>();
            var         s_FileHandle = Open(p_Connection, p_Path, (int)OpenOnlyFlags.O_RDONLY, 0);

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

            var s_Stat = Stat(p_Connection, s_FileHandle);

            if (s_Stat == null)
            {
                return(null);
            }

            var s_ChunkSize = 0x4000;
            var s_Chunks    = s_Stat.StSize / s_ChunkSize;
            var s_Leftover  = (int)s_Stat.StSize % s_ChunkSize;

            ulong s_Offset = 0;

            for (var i = 0; i < s_Chunks; ++i)
            {
                var l_Data = Read(p_Connection, s_FileHandle, s_Offset, s_ChunkSize);
                if (l_Data == null)
                {
                    return(null);
                }
                s_Bytes.AddRange(l_Data);
                // Increment our offset
                s_Offset += (ulong)l_Data.LongLength;
            }

            // Write the leftover data
            var s_Data = Read(p_Connection, s_FileHandle, s_Offset, s_Leftover);

            if (s_Data == null)
            {
                return(null);
            }
            // Write the leftover
            s_Bytes.AddRange(s_Data);
            return(s_Bytes);
        }
        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);
        }
Пример #19
0
        public static bool Reboot(this MiraConnection p_Connection)
        {
            throw new NotImplementedException();
            //if (p_Connection == null)
            //    return false;

            //var s_RequestMessage = new Message(
            //   MessageCategory.File,
            //   (uint)OrbisUtilsCommands.OrbisUtils_ShutdownMira,
            //   true,
            //   new OrbisUtilsShutdownMiraRequest
            //   {
            //       RebootConsole = true,
            //       ShutdownMira = false,
            //   }.Serialize());

            //return p_Connection.SendMessage(s_RequestMessage);
        }
Пример #20
0
        public static bool Write(this MiraConnection p_Connection, int p_Handle, byte[] p_Data)
        {
            if (p_Connection == null)
            {
                return(false);
            }

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

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Write
                },
                Data = ByteString.CopyFrom
                       (
                    // TODO: Add offset
                    new FmWriteRequest
                {
                    Handle = p_Handle,
                    Data   = ByteString.CopyFrom(p_Data)
                }.ToByteArray()
                       )
            };

            var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_ResponseTransport == null)
            {
                return(false);
            }

            return(s_ResponseTransport.Header.Error >= 0);
        }
Пример #21
0
        public static int Open(this MiraConnection p_Connection, string p_Path, int p_Flags, int p_Mode)
        {
            if (p_Connection == null)
            {
                return(-1);
            }

            if (string.IsNullOrWhiteSpace(p_Path))
            {
                return(-1);
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Open
                },
                Data = ByteString.CopyFrom
                       (
                    new FmOpenRequest
                {
                    Path  = p_Path,
                    Flags = p_Flags,
                    Mode  = p_Mode
                }.ToByteArray()
                       )
            };

            var s_Response = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_Response == null)
            {
                return(-1);
            }

            return((int)s_Response.Header.Error);
        }
Пример #22
0
        public static FmStatResponse Stat(this MiraConnection p_Connection, int p_Handle)
        {
            if (p_Connection == null)
            {
                return(null);
            }

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

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Stat
                },
                Data = ByteString.CopyFrom
                       (
                    new FmStatRequest
                {
                    Handle = p_Handle,
                }.ToByteArray()
                       )
            };

            var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_ResponseTransport == null)
            {
                return(null);
            }

            return(FmStatResponse.Parser.ParseFrom(s_ResponseTransport.Data));
        }
        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 int Open(this MiraConnection p_Connection, string p_Path, int p_Flags, int p_Mode)
        {
            if (!p_Connection.Connected)
            {
                return(-1);
            }

            if (p_Path.Length > 255)
            {
                return(-1);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Magic       = MiraConnection.c_Magic,
                Category    = (int)RPC_CATEGORY.RPCCAT_FILE,
                Request     = true,
                ErrorType   = (int)FileTransferCmds.FileTransfer_Open,
                PayloadSize = (ushort)Marshal.SizeOf <FileTransferOpen>()
            }, p_Connection.SerializeObject(new FileTransferOpen
            {
                Flags  = p_Flags,
                Handle = -1,
                Mode   = p_Mode,
                Path   = p_Path
            }));

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

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

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

            return(s_Response.Handle);
        }
        public static bool Delete(this MiraConnection p_Connection, string p_Path)
        {
            if (!p_Connection.Connected)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(p_Path))
            {
                return(false);
            }

            if (p_Path.Length > 255)
            {
                return(false);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Magic       = MiraConnection.c_Magic,
                Category    = (int)RPC_CATEGORY.RPCCAT_FILE,
                Request     = true,
                ErrorType   = unchecked ((int)FileTransferCmds.FileTransfer_Delete),
                PayloadSize = (ushort)Marshal.SizeOf <FileTransferDelete>(),
            }, p_Connection.SerializeObject(new FileTransferDelete
            {
                Path = p_Path
            }));

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

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

            return(true);
        }
Пример #26
0
        public static bool Echo(this MiraConnection p_Connection, string p_Message)
        {
            if (p_Connection == null)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(p_Message))
            {
                return(false);
            }

            if (p_Message.Length > ushort.MaxValue)
            {
                return(false);
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Echo
                },
                Data = ByteString.CopyFrom
                       (
                    new FmEchoRequest
                {
                    Message = p_Message
                }.ToByteArray()
                       )
            };

            return(p_Connection.SendMessage(s_Transport));
        }
        public static bool Stat(this MiraConnection p_Connection, string p_Path, out FileTransferStat p_Stat)
        {
            p_Stat = new FileTransferStat();

            if (!p_Connection.Connected)
            {
                return(false);
            }

            if (p_Path.Length > 255)
            {
                return(false);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Magic       = MiraConnection.c_Magic,
                Category    = (int)RPC_CATEGORY.RPCCAT_FILE,
                Request     = true,
                ErrorType   = unchecked ((int)FileTransferCmds.FileTransfer_Stat),
                PayloadSize = (ushort)Marshal.SizeOf <FileTransferStat>()
            }, p_Connection.SerializeObject(new FileTransferStat
            {
                Path = p_Path
            }));

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

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

            p_Stat = p_Connection.ReceiveObject <FileTransferStat>();

            return(true);
        }
        public static void Close(this MiraConnection p_Connection, int p_Descriptor)
        {
            if (!p_Connection.Connected)
            {
                return;
            }

            if (p_Descriptor < 0)
            {
                return;
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Magic       = MiraConnection.c_Magic,
                Category    = (int)RPC_CATEGORY.RPCCAT_FILE,
                Request     = true,
                ErrorType   = (int)FileTransferCmds.FileTransfer_Close,
                PayloadSize = (ushort)Marshal.SizeOf <FileTransferClose>()
            }, p_Connection.SerializeObject(new FileTransferClose
            {
                Handle = p_Descriptor
            }));
        }
        public static int Kill(this MiraConnection p_Connection, int p_Pid, int p_Signal)
        {
            if (!p_Connection.Connected)
            {
                return(-1);
            }

            p_Connection.SendMessage(new RpcMessageHeader
            {
                Category    = (int)RPC_CATEGORY.RPCCAT_DBG,
                Magic       = MiraConnection.c_Magic,
                ErrorType   = unchecked ((int)DebuggerCmds.Debugger_Kill),
                Request     = true,
                PayloadSize = (ushort)Marshal.SizeOf <DebuggerKill>()
            }, p_Connection.SerializeObject(new DebuggerKill
            {
                Pid    = p_Pid,
                Signal = p_Signal
            }));

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

            return((int)s_Result.ErrorType);
        }
Пример #30
0
 public void TestInitialization()
 {
     m_Connection = new MiraConnection(c_Address, c_Port);
 }