mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Correctly implement RSD handshake
This commit is contained in:
@@ -33,7 +33,8 @@ pub struct RsdHandshake {
|
|||||||
impl RsdHandshake {
|
impl RsdHandshake {
|
||||||
pub async fn new(socket: impl ReadWrite) -> Result<Self, IdeviceError> {
|
pub async fn new(socket: impl ReadWrite) -> Result<Self, IdeviceError> {
|
||||||
let mut xpc_client = RemoteXpcClient::new(socket).await?;
|
let mut xpc_client = RemoteXpcClient::new(socket).await?;
|
||||||
let data = xpc_client.do_handshake().await?;
|
xpc_client.do_handshake().await?;
|
||||||
|
let data = xpc_client.recv_root().await?;
|
||||||
|
|
||||||
let services_dict = match data
|
let services_dict = match data
|
||||||
.as_dictionary()
|
.as_dictionary()
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ impl<R: ReadWrite> RemoteXpcClient<R> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn do_handshake(&mut self) -> Result<plist::Value, IdeviceError> {
|
pub async fn do_handshake(&mut self) -> Result<(), IdeviceError> {
|
||||||
self.h2_client
|
self.h2_client
|
||||||
.set_settings(
|
.set_settings(
|
||||||
vec![
|
vec![
|
||||||
Setting::MaxConcurrentStreams(10),
|
Setting::MaxConcurrentStreams(100),
|
||||||
Setting::InitialWindowSize(1048576),
|
Setting::InitialWindowSize(1048576),
|
||||||
],
|
],
|
||||||
0,
|
0,
|
||||||
@@ -50,9 +50,6 @@ impl<R: ReadWrite> RemoteXpcClient<R> {
|
|||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.recv_root().await?;
|
|
||||||
self.recv_root().await?;
|
|
||||||
|
|
||||||
debug!("Sending weird flags");
|
debug!("Sending weird flags");
|
||||||
self.send_root(XPCMessage::new(Some(XPCFlag::Custom(0x201)), None, None))
|
self.send_root(XPCMessage::new(Some(XPCFlag::Custom(0x201)), None, None))
|
||||||
.await?;
|
.await?;
|
||||||
@@ -66,29 +63,7 @@ impl<R: ReadWrite> RemoteXpcClient<R> {
|
|||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut total_msg = Vec::new();
|
Ok(())
|
||||||
loop {
|
|
||||||
// We receive from the root channel for this message
|
|
||||||
total_msg.extend(self.h2_client.read(ROOT_CHANNEL).await?);
|
|
||||||
let msg = match XPCMessage::decode(&total_msg) {
|
|
||||||
Ok(m) => m,
|
|
||||||
Err(IdeviceError::PacketSizeMismatch) => {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match msg.message {
|
|
||||||
Some(msg) => {
|
|
||||||
return Ok(msg.to_plist());
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
return Err(IdeviceError::UnexpectedResponse);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn recv(&mut self) -> Result<plist::Value, IdeviceError> {
|
pub async fn recv(&mut self) -> Result<plist::Value, IdeviceError> {
|
||||||
@@ -103,16 +78,52 @@ impl<R: ReadWrite> RemoteXpcClient<R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn recv_root(&mut self) -> Result<Option<plist::Value>, IdeviceError> {
|
pub async fn recv_root(&mut self) -> Result<plist::Value, IdeviceError> {
|
||||||
let msg = self.h2_client.read(ROOT_CHANNEL).await?;
|
let mut msg_buffer = Vec::new();
|
||||||
let msg = XPCMessage::decode(&msg)?;
|
loop {
|
||||||
|
msg_buffer.extend(self.h2_client.read(ROOT_CHANNEL).await?);
|
||||||
|
let msg = match XPCMessage::decode(&msg_buffer) {
|
||||||
|
Ok(m) => m,
|
||||||
|
Err(IdeviceError::PacketSizeMismatch) => continue,
|
||||||
|
Err(e) => break Err(e),
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(msg) = msg.message {
|
match msg.message {
|
||||||
Ok(Some(msg.to_plist()))
|
Some(msg) => {
|
||||||
} else {
|
if let Some(d) = msg.as_dictionary() {
|
||||||
Ok(None)
|
if d.is_empty() {
|
||||||
|
msg_buffer.clear();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break Ok(msg.to_plist());
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
// don't care didn't ask
|
||||||
|
msg_buffer.clear();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn send_object(
|
||||||
|
&mut self,
|
||||||
|
msg: plist::Value,
|
||||||
|
expect_reply: bool,
|
||||||
|
) -> Result<(), IdeviceError> {
|
||||||
|
let msg: XPCObject = msg.into();
|
||||||
|
|
||||||
|
let mut flag = XPCFlag::DataFlag | XPCFlag::AlwaysSet;
|
||||||
|
if expect_reply {
|
||||||
|
flag |= XPCFlag::WantingReply;
|
||||||
|
}
|
||||||
|
|
||||||
|
let msg = XPCMessage::new(Some(flag), Some(msg), Some(self.root_id));
|
||||||
|
self.send_root(msg).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn send_root(&mut self, msg: XPCMessage) -> Result<(), IdeviceError> {
|
async fn send_root(&mut self, msg: XPCMessage) -> Result<(), IdeviceError> {
|
||||||
self.h2_client
|
self.h2_client
|
||||||
|
|||||||
Reference in New Issue
Block a user