MCPcopy Create free account
hub / github.com/TheAssassin/AppImageLauncher / getAppImageDigestMd5

Function getAppImageDigestMd5

src/shared/shared.cpp:948–1009  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

946}
947
948QString getAppImageDigestMd5(const QString& path) {
949 // try to read embedded MD5 digest
950 unsigned long offset = 0, length = 0;
951
952 // first of all, digest calculation is supported only for type 2
953 if (appimage_get_type(path.toStdString().c_str(), false) != 2)
954 return "";
955
956 auto rv = appimage_get_elf_section_offset_and_length(path.toStdString().c_str(), ".digest_md5", &offset, &length);
957
958 QByteArray buffer(16, '\0');
959
960 if (rv && offset != 0 && length != 0) {
961 // open file and read digest from ELF header section
962 QFile file(path);
963
964 if (!file.open(QFile::ReadOnly))
965 return "";
966
967 if (!file.seek(static_cast<qint64>(offset)))
968 return "";
969
970 if (!file.read(buffer.data(), buffer.size()))
971 return "";
972
973 file.close();
974 }
975
976 bool needToCalculateDigest;
977
978 // there seem to be some AppImages out there who actually have the required section embedded, but it's empty
979 // therefore we make the assumption that a hash value of zeroes is probably incorrect and recalculate
980 // in the extremely rare case in which the AppImage's digest would *really* be that value, we'd waste a bit of
981 // computation time, but the chances are so low... who cares, right?
982 {
983 auto nonZeroCharacterFound = false;
984
985 for (const char i : buffer) {
986 if (i != '\0') {
987 nonZeroCharacterFound = true;
988 break;
989 }
990 }
991
992 needToCalculateDigest = !nonZeroCharacterFound;
993 }
994
995 if (needToCalculateDigest) {
996 // calculate digest
997 if (!appimage_type2_digest_md5(path.toStdString().c_str(), buffer.data()))
998 return "";
999 }
1000
1001 // create hexadecimal representation
1002 auto hexDigest = appimage_hexlify(buffer, static_cast<size_t>(buffer.size()));
1003
1004 QString hexDigestStr(hexDigest);
1005

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected