Skip to content

Commit 7bfb296

Browse files
committed
Automatically detect whether APNonce is frozen instead of asking user to pick
1 parent 5354e8d commit 7bfb296

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/main/java/airsquared/blobsaver/app/Controller.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,21 +555,18 @@ public void readInfo() {
555555
}
556556

557557
public void readApnonce() {
558-
Alert alert1 = new Alert(Alert.AlertType.CONFIRMATION, "", ButtonType.CANCEL, new ButtonType("Jailbroken"), new ButtonType("Unjailbroken"));
558+
Alert alert1 = new Alert(Alert.AlertType.CONFIRMATION);
559559
alert1.setHeaderText("Read APNonce from connected device");
560560
alert1.setContentText("blobsaver can read both the APNonce and generator from a connected device.\n\n" +
561-
"Please connect your device and click \"Jailbroken\" if your device has a generator set or \"Unjailbroken\" if you don't. If unsure, select \"Unjailbroken\".\n\nYour device will enter recovery mode while retrieving the APNonce and will automatically reboot to normal mode when complete.");
562-
boolean jailbroken;
563-
if (alert1.showAndWait().isEmpty() || !alert1.getResult().getText().contains("ailbroken")) {
561+
"Your device will enter recovery mode while retrieving the APNonce and will automatically reboot to normal mode when complete.");
562+
if (!ButtonType.OK.equals(alert1.showAndWait().orElse(null))) {
564563
return;
565-
} else {
566-
jailbroken = alert1.getResult().getText().equals("Jailbroken");
567564
}
568565
final Alert alert2 = new Alert(Alert.AlertType.INFORMATION, "[This should not be visible]", ButtonType.FINISH);
569-
alert2.setHeaderText("Reading APNonce from connected device...");
566+
alert2.setHeaderText("Read APNonce from connected device");
570567
Utils.forEachButton(alert2, button -> button.setDisable(true));
571568

572-
var task = new LibimobiledeviceUtil.GetApnonceTask(jailbroken);
569+
var task = new LibimobiledeviceUtil.GetApnonceTask(false);
573570
task.setOnSucceeded(event -> {
574571
apnonceField.setText(task.getApnonceResult());
575572
generatorField.setText(task.getGeneratorResult());

src/main/java/airsquared/blobsaver/app/LibimobiledeviceUtil.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
import java.nio.ByteOrder;
3232
import java.util.Objects;
3333

34-
import static airsquared.blobsaver.app.natives.Libimobiledevice.*;
34+
import static airsquared.blobsaver.app.natives.Libimobiledevice.idevice_free;
35+
import static airsquared.blobsaver.app.natives.Libimobiledevice.idevice_new;
36+
import static airsquared.blobsaver.app.natives.Libimobiledevice.lockdownd_client_free;
37+
import static airsquared.blobsaver.app.natives.Libimobiledevice.lockdownd_client_new_with_handshake;
38+
import static airsquared.blobsaver.app.natives.Libimobiledevice.lockdownd_enter_recovery;
39+
import static airsquared.blobsaver.app.natives.Libimobiledevice.lockdownd_get_value;
3540

3641

3742
public class LibimobiledeviceUtil {
@@ -65,11 +70,12 @@ public static void exitRecovery(Pointer irecvClient) throws LibimobiledeviceExce
6570

6671
public static final class GetApnonceTask extends Task<Void> {
6772
private String apnonceResult, generatorResult;
73+
private boolean tryAgain;
6874
/**
6975
* If the device is jailbroken or has a generator set, no need to try to read the apnonce in normal mode.
7076
* If device doesn't have generator set, need to read the apnonce in normal mode to freeze it.
7177
*/
72-
private final boolean jailbroken;
78+
private final boolean forceNewApnonce;
7379

7480
public String getApnonceResult() {
7581
return apnonceResult;
@@ -79,13 +85,13 @@ public String getGeneratorResult() {
7985
return generatorResult;
8086
}
8187

82-
public GetApnonceTask(boolean jailbroken) {
83-
this.jailbroken = jailbroken;
88+
public GetApnonceTask(boolean forceNewApnonce) {
89+
this.forceNewApnonce = forceNewApnonce;
8490
}
8591

8692
@Override
8793
protected Void call() throws LibimobiledeviceException {
88-
if (!jailbroken) {
94+
if (forceNewApnonce || tryAgain) {
8995
updateMessage("Reading APNonce in normal mode...");
9096
System.out.println("Read in normal mode: " + LibimobiledeviceUtil.getApNonceNormalMode());
9197
}
@@ -104,8 +110,13 @@ protected Void call() throws LibimobiledeviceException {
104110

105111
if (apnonceResult.equals(getApnonce(irecvClient.getValue()))) {
106112
Utils.runSafe(() -> updateMessage("Successfully got APNonce, exiting recovery mode..."));
113+
tryAgain = false;
114+
} else if (tryAgain) { // already tried again
115+
Utils.runSafe(() -> updateMessage("Warning: Got APNonce, but APNonce is not frozen. This could mean the generator wasn't set correctly.\n\nExiting recovery mode..."));
116+
tryAgain = false;
107117
} else {
108-
Utils.runSafe(() -> updateMessage("Warning: Got APNonce, but two successive reads didn't match. This could mean the generator wasn't set correctly.\n\nExiting recovery mode..."));
118+
Utils.runSafe(() -> updateMessage("APNonce is not frozen, trying again.\n\nExiting recovery mode..."));
119+
tryAgain = true;
109120
}
110121

111122
LibimobiledeviceUtil.exitRecovery(irecvClient.getValue());
@@ -153,9 +164,14 @@ protected Void call() throws LibimobiledeviceException {
153164

154165
generatorResult = getGenerator();
155166

167+
if (tryAgain) {
168+
call();
169+
return null;
170+
}
171+
156172
updateMessage("Success");
157173

158-
Analytics.readAPNonce(jailbroken);
174+
Analytics.readAPNonce(!forceNewApnonce && !tryAgain);
159175
return null;
160176
}
161177

0 commit comments

Comments
 (0)