From cdcfee48b9720d589a4e2cd43725e8229ca336f9 Mon Sep 17 00:00:00 2001 From: bigbiff bigbiff Date: Wed, 27 Feb 2013 21:11:26 -0500 Subject: use md5.c for computation of md5sums create a framework for computing digests and reading digests in TWRP add space for backwards compatibility with bb md5sum Change-Id: Ia18e3f430eed5eba22e5052d39b9b8d88ecd4536 --- twrp-functions.cpp | 58 ++++++++++++++---------------------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) (limited to 'twrp-functions.cpp') diff --git a/twrp-functions.cpp b/twrp-functions.cpp index a90be5a6d..76ee93a1e 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -49,48 +49,6 @@ int TWFunc::Exec_Cmd(string cmd, string &result) { return ret; } -/* Checks md5 for a path - Return values: - -1 : MD5 does not exist - 0 : Failed - 1 : Success */ -int TWFunc::Check_MD5(string File) { - int ret; - string Command, DirPath, MD5_File, Sline, Filename, MD5_File_Filename, OK; - char line[255]; - size_t pos; - string result; - - MD5_File = File + ".md5"; - if (Path_Exists(MD5_File)) { - DirPath = Get_Path(File); - MD5_File = Get_Filename(MD5_File); - Command = "cd '" + DirPath + "' && /sbin/busybox md5sum -c '" + MD5_File + "'"; - Exec_Cmd(Command, result); - pos = result.find(":"); - if (pos != string::npos) { - Filename = Get_Filename(File); - MD5_File_Filename = result.substr(0, pos); - OK = result.substr(pos + 2, result.size() - pos - 2); - if (Filename == MD5_File_Filename && (OK == "OK" || OK == "OK\n")) { - //MD5 is good, return 1 - ret = 1; - } else { - // MD5 is bad, return 0 - ret = 0; - } - } else { - // MD5 is bad, return 0 - ret = 0; - } - } else { - //No md5 file, return -1 - ret = -1; - } - - return ret; -} - // Returns "file.name" from a full /path/to/file.name string TWFunc::Get_Filename(string Path) { size_t pos = Path.find_last_of("/"); @@ -482,10 +440,24 @@ unsigned int TWFunc::Get_D_Type_From_Stat(string Path) { } int TWFunc::read_file(string fn, string& results) { + ifstream file; + file.open(fn.c_str(), ios::in); + if (file.is_open()) { + file >> results; + file.close(); + return 0; + } + LOGI("Cannot find file %s\n", fn.c_str()); + return -1; +} + +int TWFunc::read_file(string fn, vector& results) { ifstream file; + string line; file.open(fn.c_str(), ios::in); if (file.is_open()) { - file >> results; + while (getline(file, line)) + results.push_back(line); file.close(); return 0; } -- cgit v1.2.3