public static bool SignalProcess(this MiraLib.MiraConnection p_Connection, int p_Signal) { var s_Transport = new RpcTransport { Header = new RpcHeader { Category = RpcCategory.Debug, Error = 0, IsRequest = true, Magic = MiraLib.MiraConnection.c_HeaderMagic, Type = (uint)DebuggerCommands.DbgCmd_SignalProc }, Data = ByteString.CopyFrom ( new DbgSignalProcessRequest { Signal = p_Signal }.ToByteArray() ) }; var s_TransportResponse = p_Connection.SendMessageWithResponse(s_Transport); if (s_TransportResponse == null) { return(false); } return(s_TransportResponse.Header.Error == 0); }
public static void Close(this MiraLib.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 = MiraLib.MiraConnection.c_HeaderMagic, 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 RpcTransport SendMessageWithResponse(RpcTransport p_Message) { if (!SendMessage(p_Message)) { return(null); } byte[] s_Data = null; using (var s_Reader = new BinaryReader(m_Socket.GetStream(), Encoding.ASCII, true)) { var s_MessageSize = s_Reader.ReadUInt64(); if (s_MessageSize > (ulong)MaxBufferSize) { return(null); } s_Data = s_Reader.ReadBytes((int)s_MessageSize); } if (s_Data == null) { return(null); } return(RpcTransport.Parser.ParseFrom(s_Data)); }
/// <summary> /// public method <c>SendMessage</c> attempts to send an <c>RpcTransport</c> message/capsule to the PS4 through the established MiraConnection instance. /// </summary> /// <param name="p_OutgoingMessage">Message to send.</param> /// <returns>True if the message was sent, false otherwise.</returns> public bool SendMessage(RpcTransport p_OutgoingMessage) { if (Mira == null) { return(false); } return(Mira.SendMessage(p_OutgoingMessage)); }
/// <summary> /// public method <c>SendMessageWithResponse</c> sends the given message/capsule to the PS4 and waits for a response, then returns it. /// </summary> /// <param name="p_Message">Message to send.</param> /// <returns>RpcTransport response message, or null if the response was invalid.</returns> public RpcTransport SendMessageWithResponse(RpcTransport p_Message) { if (!SendMessage(p_Message)) { return(null); } return(RecvMessage()); }
/// <summary> /// public method <c>SendMessageWithResponse</c> attempts to send a message to the PS4 and receive a response from the established MiraConnection instance. /// </summary> /// <param name="p_Message">Message to send.</param> /// <returns>Response message. If there is no response message or no connection is established, null is returned.</returns> public RpcTransport SendMessageWithResponse(RpcTransport p_Message) { if (Mira == null) { return(null); } return(Mira.SendMessageWithResponse(p_Message)); }
public static ulong Allocate(this MiraLib.MiraConnection p_Connection, uint p_Size) { if (p_Size == 0) { return(0); } if (p_Connection == null) { return(0); } var s_Transport = new RpcTransport { Header = new RpcHeader { Category = RpcCategory.Debug, Error = 0, IsRequest = true, Magic = MiraLib.MiraConnection.c_HeaderMagic, Type = (uint)DebuggerCommands.DbgCmd_AllocateProcMem }, Data = ByteString.CopyFrom ( new DbgAllocateProcessMemoryRequest { Size = p_Size }.ToByteArray() ) }; var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport); if (s_ResponseTransport == null) { return(0); } if (s_ResponseTransport.Header.Error < 0) { return(0); } var s_Response = DbgAllocateProcessMemoryResponse.Parser.ParseFrom(s_ResponseTransport.Data.ToByteArray()); if (s_Response == null) { return(0); } return(s_Response.Address); }
public static byte[] Read(this MiraLib.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 = MiraLib.MiraConnection.c_HeaderMagic, 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()); }
public static List <FmDent> GetDents(this MiraLib.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 = MiraLib.MiraConnection.c_HeaderMagic, 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()); }
public static bool Protect(this MiraLib.MiraConnection p_Connection, ulong p_Address, uint p_Size, int p_Protection) { if (p_Connection == null) { return(false); } if (p_Address == 0 || p_Size == 0) { return(false); } var s_Transport = new RpcTransport { Header = new RpcHeader { Category = RpcCategory.Debug, Error = 0, IsRequest = true, Magic = MiraLib.MiraConnection.c_HeaderMagic, Type = (uint)DebuggerCommands.DbgCmd_ProtectMem }, Data = ByteString.CopyFrom ( new DbgProtectProcessMemoryRequest { Address = p_Address, Length = p_Size, Protection = p_Protection }.ToByteArray() ) }; var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport); if (s_ResponseTransport == null) { return(false); } return(s_ResponseTransport.Header.Error >= 0); }
public static int Open(this MiraLib.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 = MiraLib.MiraConnection.c_HeaderMagic, 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); }
public static bool Write(this MiraLib.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 = MiraLib.MiraConnection.c_HeaderMagic, 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); }
/// <summary> /// public method <c>SendMessage(category, type, error, data)</c> takes the given information and constructs an RpcTransport capsule and sends it to the PS4. /// </summary> /// <param name="p_Category">Category to send the message to.</param> /// <param name="p_Type">Type of message for that category.</param> /// <param name="p_Error">Error code.</param> /// <param name="p_Data">Endpoint specific data.</param> /// <returns>True if the message was sent, false otherwise.</returns> public bool SendMessage(RpcCategory p_Category, uint p_Type, long p_Error, byte[] p_Data) { // Create a capsule for the entire message var s_Transport = new RpcTransport { // Create the request header Header = new RpcHeader { Category = p_Category, Type = p_Type, Error = p_Error, IsRequest = true, Magic = c_HeaderMagic }, Data = ByteString.CopyFrom(p_Data) }; // Send it off return(SendMessage(s_Transport)); }
/// <summary> /// Sends a message without expecting a response /// NOTE: If you incorrectly use this one instead of SendMessageWithResponse stuff may not work /// </summary> /// <param name="p_OutoingMessage">Outgoing message with all fields set and ready to go</param> /// <returns>True on success, false otherwise</returns> public bool SendMessage(RpcTransport p_OutoingMessage) { // Validate that we are connected if (!IsConnected) { return(false); } var s_MessageData = p_OutoingMessage.ToByteArray(); var s_Buffer = new byte[Marshal.SizeOf <ulong>() + s_MessageData.Length]; Buffer.BlockCopy(BitConverter.GetBytes((ulong)s_MessageData.Length), 0, s_Buffer, 0, 8); Buffer.BlockCopy(s_MessageData, 0, s_Buffer, 8, s_MessageData.Length); // Write this, should call serialize which will have header + payload data using (var s_Writer = new BinaryWriter(m_Socket.GetStream(), Encoding.ASCII, true)) s_Writer.Write(s_Buffer); return(true); }
public static FmStatResponse Stat(this MiraLib.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 = MiraLib.MiraConnection.c_HeaderMagic, 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 DbgGetProcessThreadsResponse GetProcessThreads(this MiraLib.MiraConnection p_Connection, int p_ProcessId) { if (p_Connection == null) { return(null); } var s_Transport = new RpcTransport { Header = new RpcHeader { Category = RpcCategory.Debug, Error = 0, IsRequest = true, Magic = MiraLib.MiraConnection.c_HeaderMagic, Type = (uint)DebuggerCommands.DbgCmd_GetProcThreads }, Data = ByteString.CopyFrom ( new DbgGetProcessInfoRequest { ProcessId = p_ProcessId }.ToByteArray() ) }; var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport); if (s_ResponseTransport == null) { return(null); } if (s_ResponseTransport.Header.Error < 0) { return(null); } return(DbgGetProcessThreadsResponse.Parser.ParseFrom(s_ResponseTransport.Data.ToByteArray())); }
public static bool Echo(this MiraLib.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 = MiraLib.MiraConnection.c_HeaderMagic, Type = (uint)FileExplorerCommands.FileExplorer_Echo }, Data = ByteString.CopyFrom ( new FmEchoRequest { Message = p_Message }.ToByteArray() ) }; return(p_Connection.SendMessage(s_Transport)); }
public static List <DbgProcessLimited> GetProcList(this MiraLib.MiraConnection p_Connection) { var s_ProcessList = new List <DbgProcessLimited>(); if (p_Connection == null) { return(new List <DbgProcessLimited>()); } var s_Transport = new RpcTransport { Header = new RpcHeader { Category = RpcCategory.Debug, Error = 0, IsRequest = true, Magic = MiraLib.MiraConnection.c_HeaderMagic, Type = (uint)DebuggerCommands.DbgCmd_GetProcList }, Data = ByteString.Empty }; var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport); if (s_ResponseTransport == null) { return(new List <DbgProcessLimited>()); } if (s_ResponseTransport.Header.Error < 0) { return(new List <DbgProcessLimited>()); } var s_Response = DbgGetProcessListResponse.Parser.ParseFrom(s_ResponseTransport.Data); return(s_Response.Processes.ToList()); }
/// <summary> /// Sets the default transport mechanism to WebSocket /// </summary> public GeneratedTest UseWS() { _defaultTransport = RpcTransport.WebSocket; return(this); }
/// <summary> /// Sets the default transport mechanism to HTTP /// </summary> public GeneratedTest UseHTTP() { _defaultTransport = RpcTransport.HTTP; return(this); }
public Task <RpcMessage> Call(string method, Object[] parameters, bool expectReturn, RpcTransport rpcTransport) { var json = new JObject(); json["jsonrpc"] = "2.0"; if (expectReturn) { json["id"] = Interlocked.Increment(ref _nextMessageId); } json["method"] = method; json["params"] = JToken.FromObject(parameters); return(_transports[rpcTransport].SendMessage(json)); }