forked from M66B/cm10-fxp-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recovery_check_pin.patch
85 lines (81 loc) · 2.07 KB
/
recovery_check_pin.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
diff --git a/recovery.c b/recovery.c
index 6778ac9..9c4cdd8 100644
--- a/recovery.c
+++ b/recovery.c
@@ -783,6 +783,61 @@ setup_adbd() {
property_set("service.adb.root", "1");
}
+int get_pin() {
+ char code[5] = "";
+ char owner[80] = "";
+ char pin[] = "????";
+
+ // Read pin code
+ FILE* fp = fopen("/cache/pin/code", "r");
+ if (fp != NULL) {
+ if (fgets(code, sizeof(code), fp)) {
+ char *n = strchr(code, '\n');
+ if (n) *n = 0;
+ }
+ fclose(fp);
+ }
+
+ // Read owner
+ FILE* fpo = fopen("/cache/pin/owner", "r");
+ if (fpo != NULL) {
+ fgets(owner, sizeof(owner), fpo);
+ fclose(fpo);
+ }
+
+ if (*code == 0)
+ *pin = 0;
+ else {
+ int i;
+ char item[] = "----";
+ const char* headers[] = { owner, "", "Enter pincode:", "", item, "", NULL };
+ const char* digits[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
+
+ // Get pincode
+ for (i = 0; i < strlen(item); i++) {
+ int digit = get_menu_selection(prepend_title(headers), digits, 0, 0);
+ if (digit == GO_BACK) {
+ i = -1;
+ memset(pin, '?', 4);
+ memset(item, '-', 4);
+ }
+ else {
+ pin[i] = '0' + digit;
+ item[i] = '*';
+ }
+ }
+ }
+
+ // Check pincode
+ if (strcmp(pin, code))
+ return false;
+ else {
+ __system("touch /cache/pin/ok");
+ __system("/sbin/adbd &");
+ return true;
+ }
+}
+
int
main(int argc, char **argv) {
@@ -970,14 +1025,15 @@ main(int argc, char **argv) {
}
}
- setup_adbd();
-
if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) {
ui_set_show_text(1);
ui_set_background(BACKGROUND_ICON_ERROR);
}
if (status != INSTALL_SUCCESS || ui_text_visible()) {
- prompt_and_wait();
+ if (get_pin())
+ prompt_and_wait();
+ else
+ poweroff = 1;
}
verify_root_and_recovery();