Skip to content

Commit

Permalink
Remove libhybris dependency, and start implementing it from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadoum committed Mar 25, 2023
1 parent 28a6b94 commit 68e79f9
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 225 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ endif()
# set_source_files_properties(lib/provision/c.d PROPERTIES COMPILE_FLAGS "-HC -HCf=${CMAKE_BINARY_DIR}/include-provision/provision.h")
# target_include_directories(provision PUBLIC ${CMAKE_BINARY_DIR}/include-provision)

target_link_libraries(provision PUBLIC plist hybris stdc++ pthread rt)
target_link_libraries(provision PUBLIC plist)

set(RETRIEVE_HEADERS_SOURCE_DIR "retrieve_headers/")
file(GLOB_RECURSE RETRIEVE_HEADERS_D_SOURCES "${RETRIEVE_HEADERS_SOURCE_DIR}*.d")
Expand Down
8 changes: 7 additions & 1 deletion anisette_server/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ void main(string[] args) {
}

auto s = new HttpServer(simpleHandler((ref req, ref res) {
if (req.url == "/reprovision") {
if (req.url == "/version") {
import constants;
writeln("[<<] GET /version");
res.writeBody(anisetteServerVersion);
writeln("[>>] 200 OK");
res.setStatus(200);
} else if (req.url == "/reprovision") {
writeln("[<<] GET /reprovision");
adi.provisionDevice(rinfo);
writeln("[>>] 200 OK");
Expand Down
3 changes: 3 additions & 0 deletions anisette_server/constants.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module constants;

enum anisetteServerVersion = "1.1.2";
12 changes: 1 addition & 11 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# ==============================================================================
# Fetching external libraries

include(FetchContent)

FetchContent_Declare(
libhybris
GIT_REPOSITORY https://github.com/Dadoum/libhybris
GIT_TAG master
)
FetchContent_MakeAvailable(libhybris)
target_compile_definitions(hybris PUBLIC BROKEN_MODE)

if(build_sideloadipa OR build_anisetteserver)
include(UseDub)

Expand All @@ -24,6 +14,6 @@ if(build_sideloadipa OR build_anisetteserver)
endif()

if(build_anisetteserver)
DubProject_Add(handy-httpd ~3.3.0)
DubProject_Add(handy-httpd ~5.1.0)
endif()
endif()
43 changes: 43 additions & 0 deletions dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name "provision"
description "Set of tools interracting with Apple servers."
authors "Dadoum"
copyright "Copyright © 2023, Dadoum"

targetType "library"
targetPath "bin"

sourcePaths "lib"
importPaths "lib"

configuration "plist-d" {
dependency "plist" version="~master"
}

configuration "libplist" {
version "LibPlist"
}

subPackage {
name "retrieve-headers"
targetType "executable"
targetPath "bin"

workingDirectory "bin"

sourcePaths "retrieve_headers"

dependency "provision" version="*"
}

subPackage {
name "anisette-server"
targetType "executable"
targetPath "bin"

workingDirectory "bin"

sourcePaths "anisette_server"

dependency "provision" version="*"
dependency "handy-httpd" version="~>5.1.0"
}
7 changes: 7 additions & 0 deletions dub.selections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"fileVersion": 1,
"versions": {
"dxml": "0.4.3",
"plist": "~master"
}
}
112 changes: 51 additions & 61 deletions lib/provision/adi.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,98 +33,90 @@ alias ADIOTPRequest_t = extern(C) int function(ulong, ubyte**, uint*, ubyte**, u
alias ADISetIDMSRouting_t = extern(C) int function(ulong, ulong);
alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);

@nogc public shared struct ADI {
private shared string path;
private shared ulong dsId;

private shared string __identifier;
private shared string[string] urlBag;

shared AndroidLibrary* libcoreadi;
shared AndroidLibrary* libstoreservicescore;

__gshared ADILoadLibraryWithPath_t pADILoadLibraryWithPath;
__gshared ADISetAndroidID_t pADISetAndroidID;
__gshared ADISetProvisioningPath_t pADISetProvisioningPath;

__gshared ADIProvisioningErase_t pADIProvisioningErase;
__gshared ADISynchronize_t pADISynchronize;
__gshared ADIProvisioningDestroy_t pADIProvisioningDestroy;
__gshared ADIProvisioningEnd_t pADIProvisioningEnd;
__gshared ADIProvisioningStart_t pADIProvisioningStart;
__gshared ADIGetLoginCode_t pADIGetLoginCode;
__gshared ADIDispose_t pADIDispose;
__gshared ADIOTPRequest_t pADIOTPRequest;
__gshared ADISetIDMSRouting_t pADISetIDMSRouting;
__gshared ADIGetIDMSRouting_t pADIGetIDMSRouting;
@nogc public struct ADI {
private string path;
private ulong dsId;

private string __identifier;
private string[string] urlBag;

AndroidLibrary* libstoreservicescore;

ADILoadLibraryWithPath_t pADILoadLibraryWithPath;
ADISetAndroidID_t pADISetAndroidID;
ADISetProvisioningPath_t pADISetProvisioningPath;

ADIProvisioningErase_t pADIProvisioningErase;
ADISynchronize_t pADISynchronize;
ADIProvisioningDestroy_t pADIProvisioningDestroy;
ADIProvisioningEnd_t pADIProvisioningEnd;
ADIProvisioningStart_t pADIProvisioningStart;
ADIGetLoginCode_t pADIGetLoginCode;
ADIDispose_t pADIDispose;
ADIOTPRequest_t pADIOTPRequest;
ADISetIDMSRouting_t pADISetIDMSRouting;
ADIGetIDMSRouting_t pADIGetIDMSRouting;

string __clientInfo = "<MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)>";
public @property string clientInfo() shared {
return __clientInfo;
}

public @property void clientInfo(string value) shared {
public @property void clientInfo(string value) {
__clientInfo = value;
}

shared string __serialNo = "0";
public @property string serialNo() shared {
string __serialNo = "0";
public @property string serialNo() {
return __serialNo;
}

public @property void serialNo(string value) shared {
public @property void serialNo(string value) {
__serialNo = value;
}

public @property string provisionPath() shared {
public @property string provisionPath() {
return this.path;
}

public void identifier(string value) shared {
public void identifier(string value) {
pADISetAndroidID(/+identifierStr+/ value.toStringz, /+length+/ cast(uint) value.length);
__identifier = value;
}

public string identifier() shared {
public string identifier() {
return __identifier;
}

public @property string deviceId() shared {
public @property string deviceId() {
return sha1Of(this.identifier).toHexString().toUpper().dup();
}

public @property string localUserUUID() shared {
public @property string localUserUUID() {
return sha256Of(this.identifier).toHexString().toUpper().dup();
}

@disable this();

public shared this(string provisioningPath, char[] identifier = null) {
public this(string provisioningPath, char[] identifier = null) {
version (X86_64) {
enum string architectureIdentifier = "x86_64";
} else version (X86) {
enum string architectureIdentifier = "x86";
} else version (AArch64) {
enum string architectureIdentifier = "arm64-v8a";
} else version (ARM) {
enum string architectureIdentifier = "armeabi-v7a";
} else {
static assert(false, "Architecture not supported :(");
}
enum string architectureIdentifier = "arm64-v8a";
} else version (ARM) {
enum string architectureIdentifier = "armeabi-v7a";
} else {
static assert(false, "Architecture not supported :(");
}

enum string libraryPath = "lib/" ~ architectureIdentifier ~ "/";

initHybris();

if (!exists(libraryPath ~ "libCoreADI.so")) {
throw new FileException(libraryPath ~ "libCoreADI.so", "Apple libraries are not installed correctly. Refer to README for instructions. ");
}

if (!exists(libraryPath ~ "libstoreservicescore.so")) {
throw new FileException(libraryPath ~ "libstoreservicescore.so", "Apple libraries are not installed correctly. Refer to README for instructions. ");
}

this.libcoreadi = new AndroidLibrary(libraryPath ~ "libCoreADI.so");
this.libstoreservicescore = new AndroidLibrary(libraryPath ~ "libstoreservicescore.so");

debug {
Expand Down Expand Up @@ -165,8 +157,8 @@ alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);
this.identifier = cast(string) genAndroidId();
else
this.identifier = cast(string) identifier;
// pADILoadLibraryWithPath(/+path+/ applePrefix.toStringz);
// pADISetAndroidID(/+identifierStr+/ identifier.toStringz, /+length+/ cast(uint) identifier.length);

pADILoadLibraryWithPath(/+path+/ libraryPath.toStringz);

debug {
stderr.writeln("Setting fields...");
Expand All @@ -179,7 +171,7 @@ alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);
}
}

private HTTP makeHttpClient() shared {
private HTTP makeHttpClient() {
auto client = HTTP();

client.setUserAgent("iCloud.exe (unknown version) CFNetwork/520.44.6");
Expand All @@ -204,7 +196,7 @@ alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);
return client;
}

private void populateUrlBag(HTTP client) shared {
private void populateUrlBag(HTTP client) {
auto content = cast(string) std.net.curl.get("https://gsa.apple.com/grandslam/GsService2/lookup", client);

version (LibPlist) {
Expand All @@ -227,7 +219,7 @@ alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);
}
}

private ubyte[] downloadSPIM(HTTP client) shared {
private ubyte[] downloadSPIM(HTTP client) {
import std.datetime.systime;
auto time = Clock.currTime();

Expand Down Expand Up @@ -262,7 +254,7 @@ alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);
return Base64.decode(spimStr);
}

auto sendCPIM(HTTP client, ubyte[] cpim) shared {
auto sendCPIM(HTTP client, ubyte[] cpim) {
string body_ = format!"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
Expand Down Expand Up @@ -314,7 +306,7 @@ alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);
return secondStepAnswers;
}

public bool isMachineProvisioned() shared {
public bool isMachineProvisioned() {
debug {
stderr.writeln("isMachineProvisioned called !");
}
Expand All @@ -328,7 +320,7 @@ alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);
return i == 0;
}

public void provisionDevice(out ulong routingInformation) shared {
public void provisionDevice(out ulong routingInformation) {
debug {
stderr.writeln("provisionDevice called !");
}
Expand Down Expand Up @@ -425,7 +417,7 @@ alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);
throw new AnisetteException(ret);
}

public void getOneTimePassword(out ubyte[] machineId, out ubyte[] oneTimePassword) shared {
public void getOneTimePassword(out ubyte[] machineId, out ubyte[] oneTimePassword) {
debug {
stderr.writeln("getOneTimePassword called !");
}
Expand Down Expand Up @@ -468,21 +460,19 @@ alias ADIGetIDMSRouting_t = extern(C) int function(ulong*, ulong);
throw new AnisetteException(ret);
}

public void getRoutingInformation(out ulong routingInfo) shared {
public void getRoutingInformation(out ulong routingInfo) {
debug {
stderr.writeln("getRoutingInformation ignored");
}

return;

debug {
stderr.writeln("getRoutingInformation called !");
}

auto ret = pADIGetIDMSRouting(
auto ret = 0 /+ pADIGetIDMSRouting(
/+(out) routingInfo+/ &routingInfo,
/+accountID+/ dsId,
);
) +/;

debug {
stderr.writefln("getRoutingInformation -> %d", ret);
Expand Down
Loading

0 comments on commit 68e79f9

Please sign in to comment.