Skip to content

Instantly share code, notes, and snippets.

@mauronofrio
Last active October 1, 2021 15:04
Show Gist options
  • Save mauronofrio/af29bad34ad87a1a957d193794f0bf5f to your computer and use it in GitHub Desktop.
Save mauronofrio/af29bad34ad87a1a957d193794f0bf5f to your computer and use it in GitHub Desktop.
Patch to make decryption works on OnePlus fajita
# To Compile Fajita TWRP and make decryption working
--- hardware/interfaces/keymaster/4.0/support/Keymaster.cpp
+++ hardware/interfaces/keymaster/4.0/support/Keymaster.cpp
@@ -111,11 +111,10 @@
CHECK(serviceManager) << "Could not retrieve ServiceManager";
auto km4s = enumerateDevices<Keymaster4>(serviceManager);
- auto km3s = enumerateDevices<Keymaster3>(serviceManager);
auto result = std::move(km4s);
- result.insert(result.end(), std::make_move_iterator(km3s.begin()),
- std::make_move_iterator(km3s.end()));
+ result.insert(result.end(), std::make_move_iterator(km4s.begin()),
+ std::make_move_iterator(km4s.end()));
std::sort(result.begin(), result.end(),
[](auto& a, auto& b) { return a->halVersion() > b->halVersion(); });
--- bootable/recovery/crypto/ext4crypt/Decrypt.cpp
+++ bootable/recovery/crypto/ext4crypt/Decrypt.cpp
@@ -1319,11 +1319,11 @@
ret = gk_device->verify(gk_device, user_id, 0, (const uint8_t *)handle.c_str(), st.st_size,
(const uint8_t *)Password.c_str(), (uint32_t)Password.size(), &auth_token, &auth_token_len,
&should_reenroll);
+#endif
if (ret !=0) {
- printf("failed to verify\n");
+ printf("failed to verify, ret=%d\n", ret);
return false;
}
-#endif
char token_hex[(auth_token_len*2)+1];
token_hex[(auth_token_len*2)] = 0;
uint32_t i;
@@ -1336,7 +1336,7 @@
printf("e4crypt_unlock_user_key returned fail\n");
return false;
}
- if (!e4crypt_prepare_user_storage(nullptr, user_id, 0, flags)) {
+ if (!e4crypt_prepare_user_storage("", user_id, 0, flags)) {
printf("failed to e4crypt_prepare_user_storage\n");
return false;
}
+++ b/minuitwrp/graphics_fbdev.cpp
@@ -288,7 +288,7 @@ static GRSurface* fbdev_flip(minui_backend* backend __unused) {
- unsigned int idx;
+ int idx;
unsigned char tmp;
unsigned char* ucfb_vaddr = (unsigned char*)gr_draw->data;
for (idx = 0 ; idx < (gr_draw->height * gr_draw->row_bytes);
idx += 4) {
tmp = ucfb_vaddr[idx];
ucfb_vaddr[idx ] = ucfb_vaddr[idx + 2];
@hacker1024
Copy link

hacker1024 commented Oct 1, 2021

Hi, we're trying to build TWRP for the TicWatch Pro 3. It has a Snapdragon Wear 4100, which is a modified version of the Snapdragon 430. While the SoC is 64 bit, the bootloader, firmware and OS are all 32 bit.

We're getting the following error when trying to decrypt the data partition (F2FS, ice file based encryption):

10-01 14:13:26.824   691   691 E ServiceManagement: getService: defaultServiceManager()->getTransport returns Status(EX_TRANSACTION_FAILED): '-9 Bad file descriptor: '
10-01 14:13:26.824   691   691 F /sbin/recovery: Keymaster.cpp:111] Check failed: serviceManager Could not retrieve ServiceManager
10-01 14:13:26.825   691   691 F libc    : Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 691 (recovery), pid 691 (recovery)
10-01 14:13:26.825   703   703 F libc    : FORTIFY: pthread_mutex_lock called on a destroyed mutex (0xb340c0c0)
10-01 14:13:26.826   703   703 F libc    : Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 703 (hwservicemanage), pid 703 (hwservicemanage)

As your patch touches this code, I'm wondering if it solves a similar issue? Do you have any advice on how to fix this sort of thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment