mirror of
https://github.com/nab138/isideload.git
synced 2026-03-02 22:46:15 +01:00
Improve error handling and fix issues
This commit is contained in:
@@ -10,12 +10,12 @@ default = ["remote-anisette", "dep:remove-async-await"]
|
||||
remote-anisette-v3 = ["async", "dep:serde", "dep:serde_json", "dep:tokio-tungstenite", "dep:futures-util", "dep:chrono"]
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.21"
|
||||
hex = "0.4.3"
|
||||
base64 = "0.22"
|
||||
hex = "0.4"
|
||||
plist = "1.4"
|
||||
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "rustls-tls", "gzip"] }
|
||||
rand = "0.8"
|
||||
sha2 = "0.10.8"
|
||||
rand = "0.9"
|
||||
sha2 = "0.10"
|
||||
uuid = { version = "1.3", features = [ "v4", "fast-rng", "macro-diagnostics" ] }
|
||||
android-loader = { git = "https://github.com/Dadoum/android-loader", branch = "bigger_pages" }
|
||||
libc = "0.2"
|
||||
@@ -23,11 +23,11 @@ log = "0.4"
|
||||
async-trait = { version = "0.1", optional = true }
|
||||
remove-async-await = { version = "1.0", optional = true }
|
||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||
serde_json = { version = "1.0.142", optional = true }
|
||||
tokio-tungstenite = { version = "0.20.1", optional = true, features = ["rustls-tls-webpki-roots"] }
|
||||
serde_json = { version = "1.0.115", optional = true }
|
||||
tokio-tungstenite = { version = "0.27.0", optional = true, features = ["rustls-tls-webpki-roots"] }
|
||||
futures-util = { version = "0.3.28", optional = true }
|
||||
chrono = { version = "0.4.37", optional = true }
|
||||
thiserror = "1.0.58"
|
||||
thiserror = "2"
|
||||
anyhow = "1.0.81"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
|
||||
@@ -46,7 +46,7 @@ pub enum ADIError {
|
||||
ReqwestError(#[from] reqwest::Error),
|
||||
Base64Error(#[from] base64::DecodeError),
|
||||
InvalidHeaderValue(#[from] InvalidHeaderValue),
|
||||
IOError(#[from] io::Error)
|
||||
IOError(#[from] io::Error),
|
||||
}
|
||||
|
||||
impl ADIError {
|
||||
@@ -95,7 +95,7 @@ pub struct RequestOTPData {
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "async", async_trait::async_trait(?Send))]
|
||||
pub trait ADIProxy: Send + Sync {
|
||||
pub trait ADIProxy: Send + Sync {
|
||||
fn erase_provisioning(&mut self, ds_id: i64) -> Result<(), ADIError>;
|
||||
fn synchronize(&mut self, ds_id: i64, sim: &[u8]) -> Result<SynchronizeData, ADIError>;
|
||||
fn destroy_provisioning_session(&mut self, session: u32) -> Result<(), ADIError>;
|
||||
@@ -291,7 +291,9 @@ pub struct ADIProxyAnisetteProvider<ProxyType: ADIProxy + 'static> {
|
||||
|
||||
impl<ProxyType: ADIProxy + 'static> ADIProxyAnisetteProvider<ProxyType> {
|
||||
/// If you use this method, you are expected to set the identifier yourself.
|
||||
pub fn without_identifier(adi_proxy: ProxyType) -> Result<ADIProxyAnisetteProvider<ProxyType>, ADIError> {
|
||||
pub fn without_identifier(
|
||||
adi_proxy: ProxyType,
|
||||
) -> Result<ADIProxyAnisetteProvider<ProxyType>, ADIError> {
|
||||
Ok(ADIProxyAnisetteProvider { adi_proxy })
|
||||
}
|
||||
|
||||
@@ -309,7 +311,7 @@ impl<ProxyType: ADIProxy + 'static> ADIProxyAnisetteProvider<ProxyType> {
|
||||
if identifier_file.metadata()?.len() == IDENTIFIER_LENGTH as u64 {
|
||||
identifier_file.read_exact(&mut identifier)?;
|
||||
} else {
|
||||
rand::thread_rng().fill_bytes(&mut identifier);
|
||||
rand::rng().fill_bytes(&mut identifier);
|
||||
identifier_file.write_all(&identifier)?;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
use crate::adi_proxy::{ADIProxyAnisetteProvider, ConfigurableADIProxy};
|
||||
use crate::anisette_headers_provider::AnisetteHeadersProvider;
|
||||
use adi_proxy::ADIError;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use adi_proxy::ADIError;
|
||||
use thiserror::Error;
|
||||
|
||||
pub mod adi_proxy;
|
||||
@@ -58,7 +58,7 @@ pub enum AnisetteError {
|
||||
#[error("Missing Libraries")]
|
||||
MissingLibraries,
|
||||
#[error("{0}")]
|
||||
Anyhow(#[from] anyhow::Error),
|
||||
Anyhow(#[from] anyhow::Error)
|
||||
}
|
||||
|
||||
pub const DEFAULT_ANISETTE_URL: &str = "https://ani.f1sh.me/";
|
||||
@@ -85,7 +85,7 @@ impl AnisetteConfiguration {
|
||||
anisette_url: DEFAULT_ANISETTE_URL.to_string(),
|
||||
anisette_url_v3: DEFAULT_ANISETTE_URL_V3.to_string(),
|
||||
configuration_path: PathBuf::new(),
|
||||
macos_serial: "0".to_string(),
|
||||
macos_serial: "0".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,15 +157,10 @@ impl AnisetteHeaders {
|
||||
|
||||
#[cfg(feature = "remote-anisette-v3")]
|
||||
return Ok(AnisetteHeadersProviderRes::remote(Box::new(
|
||||
remote_anisette_v3::RemoteAnisetteProviderV3::new(
|
||||
configuration.anisette_url_v3,
|
||||
configuration.configuration_path.clone(),
|
||||
configuration.macos_serial.clone(),
|
||||
),
|
||||
remote_anisette_v3::RemoteAnisetteProviderV3::new(configuration.anisette_url_v3, configuration.configuration_path.clone(), configuration.macos_serial.clone()),
|
||||
)));
|
||||
|
||||
#[cfg(feature = "remote-anisette")]
|
||||
#[allow(unreachable_code)]
|
||||
return Ok(AnisetteHeadersProviderRes::remote(Box::new(
|
||||
remote_anisette::RemoteAnisetteProvider::new(configuration.anisette_url),
|
||||
)));
|
||||
|
||||
@@ -99,7 +99,7 @@ pub struct AnisetteState {
|
||||
impl Default for AnisetteState {
|
||||
fn default() -> Self {
|
||||
AnisetteState {
|
||||
keychain_identifier: rand::thread_rng().gen::<[u8; 16]>(),
|
||||
keychain_identifier: rand::rng().random::<[u8; 16]>(),
|
||||
adi_pb: None,
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ impl AnisetteClient {
|
||||
.header("X-Apple-I-MD-LU", encode_hex(&state.md_lu()))
|
||||
.header("X-Mme-Device-Id", state.device_id())
|
||||
.header("X-Apple-I-Client-Time", dt.format("%+").to_string())
|
||||
.header("X-Apple-I-TimeZone", "EDT")
|
||||
.header("X-Apple-I-TimeZone", "UTC")
|
||||
.header("X-Apple-Locale", "en_US")
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ impl AnisetteClient {
|
||||
identifier: base64_encode(&state.keychain_identifier),
|
||||
};
|
||||
connection
|
||||
.send(Message::Text(serde_json::to_string(&identifier)?))
|
||||
.send(Message::Text(serde_json::to_string(&identifier)?.into()))
|
||||
.await?;
|
||||
}
|
||||
ProvisionInput::GiveStartProvisioningData => {
|
||||
@@ -390,7 +390,7 @@ impl AnisetteClient {
|
||||
spim: spim.to_string(),
|
||||
};
|
||||
connection
|
||||
.send(Message::Text(serde_json::to_string(&spim)?))
|
||||
.send(Message::Text(serde_json::to_string(&spim)?.into()))
|
||||
.await?;
|
||||
}
|
||||
ProvisionInput::GiveEndProvisioningData { cpim } => {
|
||||
@@ -427,7 +427,9 @@ impl AnisetteClient {
|
||||
tk: response.get("tk").unwrap().as_string().unwrap(),
|
||||
};
|
||||
connection
|
||||
.send(Message::Text(serde_json::to_string(&end_provisioning)?))
|
||||
.send(Message::Text(
|
||||
serde_json::to_string(&end_provisioning)?.into(),
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
ProvisionInput::ProvisioningSuccess { adi_pb } => {
|
||||
|
||||
@@ -66,11 +66,16 @@ pub struct StoreServicesCoreADIProxy<'lt> {
|
||||
}
|
||||
|
||||
impl StoreServicesCoreADIProxy<'_> {
|
||||
pub fn new<'lt>(library_path: &PathBuf) -> Result<StoreServicesCoreADIProxy<'lt>, AnisetteError> {
|
||||
pub fn new<'lt>(
|
||||
library_path: &PathBuf,
|
||||
) -> Result<StoreServicesCoreADIProxy<'lt>, AnisetteError> {
|
||||
Self::with_custom_provisioning_path(library_path, library_path)
|
||||
}
|
||||
|
||||
pub fn with_custom_provisioning_path<'lt>(library_path: &PathBuf, provisioning_path: &PathBuf) -> Result<StoreServicesCoreADIProxy<'lt>, AnisetteError> {
|
||||
pub fn with_custom_provisioning_path<'lt>(
|
||||
library_path: &PathBuf,
|
||||
provisioning_path: &PathBuf,
|
||||
) -> Result<StoreServicesCoreADIProxy<'lt>, AnisetteError> {
|
||||
// Should be safe if the library is correct.
|
||||
unsafe {
|
||||
LoaderHelpers::setup_hooks();
|
||||
@@ -104,12 +109,8 @@ impl StoreServicesCoreADIProxy<'_> {
|
||||
.ok_or(AnisetteError::InvalidLibraryFormat)?,
|
||||
);
|
||||
|
||||
let path = CString::new(
|
||||
native_library_path
|
||||
.to_str()
|
||||
.ok_or(AnisetteError::Misc)?,
|
||||
)
|
||||
.unwrap();
|
||||
let path =
|
||||
CString::new(native_library_path.to_str().ok_or(AnisetteError::Misc)?).unwrap();
|
||||
assert_eq!((adi_load_library_with_path)(path.as_ptr() as *const u8), 0);
|
||||
|
||||
let adi_set_android_id = store_services_core
|
||||
@@ -163,9 +164,7 @@ impl StoreServicesCoreADIProxy<'_> {
|
||||
adi_otp_request: std::mem::transmute(adi_otp_request),
|
||||
};
|
||||
|
||||
proxy.set_provisioning_path(
|
||||
provisioning_path.to_str().ok_or(AnisetteError::Misc)?,
|
||||
)?;
|
||||
proxy.set_provisioning_path(provisioning_path.to_str().ok_or(AnisetteError::Misc)?)?;
|
||||
|
||||
Ok(proxy)
|
||||
}
|
||||
@@ -370,7 +369,7 @@ unsafe fn __errno_location() -> *mut i32 {
|
||||
|
||||
#[sysv64]
|
||||
fn arc4random() -> u32 {
|
||||
rand::thread_rng().gen()
|
||||
rand::rng().random()
|
||||
}
|
||||
|
||||
#[sysv64]
|
||||
@@ -412,10 +411,10 @@ impl LoaderHelpers {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::AnisetteError;
|
||||
use crate::{AnisetteConfiguration, AnisetteHeaders};
|
||||
use log::info;
|
||||
use std::path::PathBuf;
|
||||
use crate::AnisetteError;
|
||||
|
||||
#[cfg(not(feature = "async"))]
|
||||
#[test]
|
||||
@@ -436,7 +435,6 @@ mod tests {
|
||||
#[cfg(feature = "async")]
|
||||
#[tokio::test]
|
||||
async fn fetch_anisette_ssc_async() -> Result<(), AnisetteError> {
|
||||
|
||||
crate::tests::init_logger();
|
||||
|
||||
let mut provider = AnisetteHeaders::get_ssc_anisette_headers_provider(
|
||||
|
||||
Reference in New Issue
Block a user