|
32 | 32 | #include "../trampoline_encmnt/encmnt_defines.h"
|
33 | 33 | #include "../hooks.h"
|
34 | 34 |
|
| 35 | +extern int e4crypt_install_keyring(); |
| 36 | + |
35 | 37 | static char encmnt_cmd_arg[64] = { 0 };
|
36 | 38 | static char *const encmnt_cmd[] = { "/mrom_enc/trampoline_encmnt", encmnt_cmd_arg, NULL };
|
37 | 39 | #ifdef MR_ENCRYPTION_FAKE_PROPERTIES
|
38 |
| -static char *const encmnt_envp[] = { "LD_LIBRARY_PATH=/mrom_enc/", "LD_PRELOAD=/mrom_enc/libmultirom_fake_properties.so /mrom_enc/libmultirom_fake_propertywait.so", NULL }; |
| 40 | +static char *const encmnt_envp[] = { "LD_CONFIG_FILE='/mrom_enc/ld.config.txt'", "LD_LIBRARY_PATH=/mrom_enc/", "LD_PRELOAD=/mrom_enc/libmultirom_fake_properties.so /mrom_enc/libmultirom_fake_propertywait.so", NULL }; |
39 | 41 | #else
|
40 |
| -static char *const encmnt_envp[] = { "LD_LIBRARY_PATH=/mrom_enc/", NULL }; |
| 42 | +static char *const encmnt_envp[] = { "LD_CONFIG_FILE='/mrom_enc/ld.config.txt'", "LD_LIBRARY_PATH=/mrom_enc/", NULL }; |
41 | 43 | #endif
|
42 | 44 | static int g_decrypted = 0;
|
43 | 45 |
|
44 |
| -int encryption_before_mount(struct fstab *fstab) |
| 46 | +int encryption_before_mount(struct fstab *fstab, bool isFbe) |
45 | 47 | {
|
46 | 48 | int exit_code = -1;
|
47 | 49 | char *output = NULL, *itr;
|
@@ -80,52 +82,70 @@ int encryption_before_mount(struct fstab *fstab)
|
80 | 82 |
|
81 | 83 | INFO("Running trampoline_encmnt\n");
|
82 | 84 |
|
83 |
| - strcpy(encmnt_cmd_arg, "decrypt"); |
| 85 | + if (isFbe) { |
| 86 | + //rename("/realdata", "/data"); |
| 87 | + int err = mount("/realdata", "/data", NULL, MS_MOVE, NULL); |
| 88 | + INFO("err %d %s\n", err, strerror(errno)); |
| 89 | + int ret = e4crypt_install_keyring(); |
| 90 | + strcpy(encmnt_cmd_arg, "decryptfbe"); |
| 91 | + } else { |
| 92 | + strcpy(encmnt_cmd_arg, "decrypt"); |
| 93 | + } |
84 | 94 | output = run_get_stdout_with_exit_with_env(encmnt_cmd, &exit_code, encmnt_envp);
|
85 |
| - if(exit_code != 0 || !output) |
| 95 | + if(exit_code != 0 || (!isFbe && !output)) |
86 | 96 | {
|
87 | 97 | ERROR("Failed to run trampoline_encmnt, exit code %d: %s\n", exit_code, output);
|
88 | 98 | goto exit;
|
89 | 99 | }
|
90 | 100 |
|
91 |
| - itr = output + strlen(output) - 1; |
92 |
| - while(itr >= output && isspace(*itr)) |
93 |
| - *itr-- = 0; |
94 |
| - |
95 |
| - if(strcmp(output, ENCMNT_BOOT_INTERNAL_OUTPUT) == 0) |
96 |
| - { |
97 |
| - INFO("trampoline_encmnt requested to boot internal ROM.\n"); |
98 |
| - res = ENC_RES_BOOT_INTERNAL; |
99 |
| - goto exit; |
| 101 | + if (!isFbe || exit_code != 0) { |
| 102 | + itr = output + strlen(output) - 1; |
| 103 | + while(itr >= output && isspace(*itr)) |
| 104 | + *itr-- = 0; |
| 105 | + |
| 106 | + if(strcmp(output, ENCMNT_BOOT_INTERNAL_OUTPUT) == 0) |
| 107 | + { |
| 108 | + INFO("trampoline_encmnt requested to boot internal ROM.\n"); |
| 109 | + res = ENC_RES_BOOT_INTERNAL; |
| 110 | + goto exit; |
| 111 | + } |
| 112 | + |
| 113 | + if(strcmp(output, ENCMNT_BOOT_RECOVERY_OUTPUT) == 0) |
| 114 | + { |
| 115 | + INFO("trampoline_encmnt requested to boot recovery.\n"); |
| 116 | + res = ENC_RES_BOOT_RECOVERY; |
| 117 | + goto exit; |
| 118 | + } |
100 | 119 | }
|
101 | 120 |
|
102 |
| - if(strcmp(output, ENCMNT_BOOT_RECOVERY_OUTPUT) == 0) |
103 |
| - { |
104 |
| - INFO("trampoline_encmnt requested to boot recovery.\n"); |
105 |
| - res = ENC_RES_BOOT_RECOVERY; |
106 |
| - goto exit; |
107 |
| - } |
| 121 | + if (!isFbe) { |
108 | 122 |
|
109 |
| - if(!strstartswith(output, "/dev")) |
110 |
| - { |
111 |
| - ERROR("Invalid trampoline_encmnt output: %s\n", output); |
112 |
| - goto exit; |
113 |
| - } |
| 123 | + if(!strstartswith(output, "/dev")) |
| 124 | + { |
| 125 | + ERROR("Invalid trampoline_encmnt output: %s\n", output); |
| 126 | + goto exit; |
| 127 | + } |
114 | 128 |
|
115 |
| - g_decrypted = 1; |
| 129 | + g_decrypted = 1; |
116 | 130 |
|
117 |
| - struct fstab_part *datap = fstab_find_first_by_path(fstab, "/data"); |
118 |
| - if(!datap) |
119 |
| - { |
120 |
| - ERROR("Failed to find /data in fstab!\n"); |
121 |
| - goto exit; |
122 |
| - } |
| 131 | + struct fstab_part *datap = fstab_find_first_by_path(fstab, "/data"); |
| 132 | + if(!datap) |
| 133 | + { |
| 134 | + ERROR("Failed to find /data in fstab!\n"); |
| 135 | + goto exit; |
| 136 | + } |
123 | 137 |
|
124 |
| - INFO("Updating device %s to %s in fstab due to encryption.\n", datap->device, output); |
125 |
| - fstab_update_device(fstab, datap->device, output); |
| 138 | + INFO("Updating device %s to %s in fstab due to encryption.\n", datap->device, output); |
| 139 | + fstab_update_device(fstab, datap->device, output); |
| 140 | + } |
126 | 141 |
|
127 | 142 | res = ENC_RES_OK;
|
128 | 143 | exit:
|
| 144 | + if (isFbe) { |
| 145 | + //rename("/data", "/realdata"); |
| 146 | + mount("/data", "/realdata", NULL, MS_MOVE, NULL); |
| 147 | + mkdir("/data", 0755); |
| 148 | + } |
129 | 149 | free(output);
|
130 | 150 | return res;
|
131 | 151 | }
|
|
0 commit comments