Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make md5 calcation base on ppsspp
07-30-2022, 09:10 AM
Post: #1
Make md5 calcation base on ppsspp
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::string 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
Find all posts by this user
Quote this message in a reply
07-30-2022, 02:35 PM
Post: #2
RE: Make md5 calcation base on ppsspp
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]
Find all posts by this user
Quote this message in a reply
07-31-2022, 02:02 AM
Post: #3
RE: Make md5 calcation base on ppsspp
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;
}
Find all posts by this user
Quote this message in a reply
07-31-2022, 10:48 AM
Post: #4
RE: Make md5 calcation base on ppsspp
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
Find all posts by this user
Quote this message in a reply
07-31-2022, 11:59 PM
Post: #5
RE: Make md5 calcation base on ppsspp
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]
Find all posts by this user
Quote this message in a reply
08-04-2022, 10:58 AM
Post: #6
RE: Make md5 calcation base on ppsspp
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]
Find all posts by this user
Quote this message in a reply
08-04-2022, 12:40 PM
Post: #7
RE: Make md5 calcation base on ppsspp
I asked in reddit and get solve

I want to be a crash fixer
PM me if you want to me look a game
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: