summaryrefslogtreecommitdiffstats
path: root/adbbu
diff options
context:
space:
mode:
Diffstat (limited to 'adbbu')
-rw-r--r--adbbu/Android.mk7
-rw-r--r--adbbu/twrpback.cpp38
2 files changed, 18 insertions, 27 deletions
diff --git a/adbbu/Android.mk b/adbbu/Android.mk
index 10faf6f65..33d3ad7d3 100644
--- a/adbbu/Android.mk
+++ b/adbbu/Android.mk
@@ -2,10 +2,9 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
- twrpback.cpp \
- ../twrpDigest.cpp \
- ../digest/md5.c
-LOCAL_SHARED_LIBRARIES += libstdc++ libz libselinux
+ twrpback.cpp
+
+LOCAL_SHARED_LIBRARIES += libstdc++ libz libtwrpdigest
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
LOCAL_C_INCLUDES += external/stlport/stlport
LOCAL_SHARED_LIBRARIES += libstlport
diff --git a/adbbu/twrpback.cpp b/adbbu/twrpback.cpp
index 1c98a1b5c..8652de2ac 100644
--- a/adbbu/twrpback.cpp
+++ b/adbbu/twrpback.cpp
@@ -34,9 +34,8 @@
#include "twadbstream.h"
#include "twrpback.hpp"
-#include "../variables.h"
-#include "../twcommon.h"
-#include "../twrpDigest.hpp"
+#include "../twrpDigest/twrpDigest.hpp"
+#include "../twrpDigest/twrpMD5.hpp"
twrpback::twrpback(void) {
read_fd = 0;
@@ -94,7 +93,7 @@ void twrpback::close_restore_fds() {
}
int twrpback::backup(std::string command) {
- twrpDigest adb_md5;
+ twrpMD5 digest;
bool breakloop = false;
int bytes = 0, errctr = 0;
char result[MAX_ADB_READ];
@@ -215,8 +214,7 @@ int twrpback::backup(std::string command) {
struct twfilehdr twimghdr;
adblogwrite("Writing TWIMG\n");
- adb_md5.initMD5();
-
+ digest.init();
memset(&twimghdr, 0, sizeof(twimghdr));
memcpy(&twimghdr, cmd, sizeof(cmd));
md5fnsize = twimghdr.size;
@@ -234,7 +232,7 @@ int twrpback::backup(std::string command) {
struct twfilehdr twfilehdr;
adblogwrite("Writing TWFN\n");
- adb_md5.initMD5();
+ digest.init();
ADBSTRUCT_STATIC_ASSERT(sizeof(twfilehdr) == MAX_ADB_READ);
@@ -269,8 +267,7 @@ int twrpback::backup(std::string command) {
totalbytes += bytes;
char *writeresult = new char [bytes];
memcpy(writeresult, result, bytes);
- if (adb_md5.updateMD5stream((unsigned char *) writeresult, bytes) == -1)
- adblogwrite("failed to update md5 stream\n");
+ digest.update((unsigned char *) writeresult, bytes);
if (fwrite(writeresult, 1, bytes, adbd_fp) != bytes) {
adblogwrite("Error writing backup data to adbd\n");
close_backup_fds();
@@ -290,8 +287,7 @@ int twrpback::backup(std::string command) {
close_backup_fds();
return -1;
}
- if (adb_md5.updateMD5stream((unsigned char *) padding, sizeof(padding)) == -1)
- adblogwrite("failed to update md5 stream\n");
+ digest.update((unsigned char *) padding, sizeof(padding));
fflush(adbd_fp);
totalbytes = 0;
}
@@ -299,9 +295,8 @@ int twrpback::backup(std::string command) {
AdbBackupFileTrailer md5trailer;
memset(&md5trailer, 0, sizeof(md5trailer));
- adb_md5.finalizeMD5stream();
- std::string md5string = adb_md5.createMD5string();
+ std::string md5string = digest.return_digest_string();
strncpy(md5trailer.start_of_trailer, TWRP, sizeof(md5trailer.start_of_trailer));
strncpy(md5trailer.type, MD5TRAILER, sizeof(md5trailer.type));
@@ -350,8 +345,7 @@ int twrpback::backup(std::string command) {
char *writeresult = new char [bytes];
memcpy(writeresult, result, bytes);
- if (adb_md5.updateMD5stream((unsigned char *) writeresult, bytes) == -1)
- adblogwrite("failed to update md5 stream\n");
+ digest.update((unsigned char *) writeresult, bytes);
totalbytes += bytes;
dataChunkBytes += bytes;
@@ -399,7 +393,8 @@ int twrpback::backup(std::string command) {
}
int twrpback::restore(void) {
- twrpDigest adb_md5;
+ twrpMD5 digest;
+ char cmd[MAX_ADB_READ];
char result[MAX_ADB_READ];
struct AdbBackupControlType structcmd;
int adb_control_twrp_fd, errctr = 0;
@@ -591,8 +586,8 @@ int twrpback::restore(void) {
struct twfilehdr twimghdr;
uint32_t crc, twimghdrcrc;
+ digest.init();
totalbytes -= sizeof(result);
- adb_md5.initMD5();
adblogwrite("Restoring TWIMG\n");
memset(&twimghdr, 0, sizeof(twimghdr));
memcpy(&twimghdr, result, sizeof(result));
@@ -623,9 +618,9 @@ int twrpback::restore(void) {
else if (cmdtype == TWFN) {
struct twfilehdr twfilehdr;
uint32_t crc, twfilehdrcrc;
+ digest.init();
totalbytes -= sizeof(result);
- adb_md5.initMD5();
adblogwrite("Restoring TWFN\n");
memset(&twfilehdr, 0, sizeof(twfilehdr));
memcpy(&twfilehdr, result, sizeof(result));
@@ -703,15 +698,13 @@ int twrpback::restore(void) {
close_restore_fds();
return -1;
}
- adblogwrite("md5 finalize stream\n");
- adb_md5.finalizeMD5stream();
AdbBackupFileTrailer md5;
memset(&md5, 0, sizeof(md5));
strncpy(md5.start_of_trailer, TWRP, sizeof(md5.start_of_trailer));
strncpy(md5.type, TWMD5, sizeof(md5.type));
- std::string md5string = adb_md5.createMD5string();
+ std::string md5string = digest.return_digest_string();
strncpy(md5.md5, md5string.c_str(), sizeof(md5.md5));
adblogwrite("Sending MD5Check\n");
@@ -726,8 +719,7 @@ int twrpback::restore(void) {
break;
}
}
- if (adb_md5.updateMD5stream((unsigned char*)result, sizeof(result)) == -1)
- adblogwrite("failed to update md5 stream\n");
+ digest.update((unsigned char*)result, sizeof(result));
dataChunkBytes += readbytes;
if (write(adb_write_fd, result, sizeof(result)) < 0) {