Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make md5 calcation base on ppsspp
#1
Hi

I want to port
https://github.com/jixunmoe/mfcDuDownloadCodeGenerator
Project into Android.
(I have ported to Delphi https://github.com/sum2012/DelphiDuDownl...eGenerator but don't work in Android)

It need full file of md5, first 262144 byte of md5
and file size.

Now I can compile ppsspp in Android Studio so that I want to make md5 calcation base on ppsspp

UI::EventReturn GameScreen::OnDoMD5(UI::EventParams& e) {
auto chrs = gamePath_.c_str();
MD5string = md5file(chrs);
...............


std:Confusedtring md5file(const char* filename) {
std::FILE* file = std::fopen(filename, "rb");

std::FILE* file = std::fopen don't work in Andorid.
Anyone can help me?Thanks
Reply
#2
You have to use OpenCFile, because it goes through the Java stuff that is now required for opening files on Android.

https://github.com/hrydgard/ppsspp/blob/...n.cpp#L210

-[Unknown]
Reply
#3
Thanks [Unknown]
Next question:How to calculation first 262144 byte of md5 ?

Now the full file size of md5 calc of code is:
Code:
#include "Common/Crypto/md5.h" static char hb2hex(unsigned char hb) { hb = hb & 0xF; return hb < 10 ? '0' + hb : hb - 10 + 'a'; } std::string MD5FullFile(const Path filename) { FILE* in = File::OpenCFile(filename, "rb"); if (!in) { WARN_LOG(COMMON, "Unable to open %s\n", filename.c_str()); return ""; } unsigned char buff[BUFSIZ]; md5_context c; md5_starts(&c); unsigned char out[16]; size_t len = 0; while ((len = std::fread(buff, sizeof(char), BUFSIZ, in)) > 0) { md5_update(&c, buff, len); } md5_finish(&c, out); std::string res; for (size_t i = 0; i < 16; ++i) { res.push_back(hb2hex(out[i] >> 4)); res.push_back(hb2hex(out[i])); } fclose(in); return res; }
Reply
#4
I found another md5 calc ,so that it is easier to calc 262144 bytes.
Please correct me if I am wrong
Code:
std::string MD5_262144_File(const Path filename) { std::ifstream is(filename.c_str(), std::ifstream::binary); md5_context c; md5_starts(&c); char buf[256]; // 256 * 1024 = 262144 byte for (size_t i = 0; i < 1024; ++i) { is.read(buf, sizeof(buf)); md5_update(&c, (unsigned char*)buf, is.gcount()); } unsigned char out[16]; md5_finish(&c, out); std::string res; for (size_t i = 0; i < 16; ++i) { res.push_back(hb2hex(out[i] >> 4)); res.push_back(hb2hex(out[i])); } return res; }
I want to be a crash fixer
PM me if you want to me look a game
Reply
#5
That should be fine, although I wouldn't recommend handling as a string. There might be a problem if the file is smaller than that many bytes, though.

-[Unknown]
Reply
#6
Unlucky,windows and Android result not same.
(07-31-2022, 11:59 PM)[Unknown] Wrote: That should be fine, although I wouldn't recommend handling as a string. There might be a problem if the file is smaller than that many bytes, though.

-[Unknown]
Reply
#7
I asked in reddit and get solve
I want to be a crash fixer
PM me if you want to me look a game
Reply


Forum Jump: