Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Fix checksums data types and lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
hardronix122 committed Aug 18, 2023
1 parent aeff162 commit 1f1623b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 23)

# ImHexQb #
project(imhexqb VERSION 1.0.5)
project(imhexqb VERSION 1.0.6)

# Include ImHex cmake module #
set(IMHEX_BASE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/ImHex)
Expand Down
14 changes: 7 additions & 7 deletions source/qb/ChecksumDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <hex/helpers/fs.hpp>

ChecksumDictionary::ChecksumDictionary() {
dictionary = std::map<uint32_t, std::string>();
dictionary = std::map<uint64_t, std::string>();
}

std::string ChecksumDictionary::getDictionaryPath() {
Expand Down Expand Up @@ -31,10 +31,10 @@ ChecksumDictionary ChecksumDictionary::load(const std::string& path) {
nlohmann::basic_json json = nlohmann::json::parse(buf.str());

if (!json.contains("checksums")) {
json["checksums"] = std::map<uint32_t, std::string>();
json["checksums"] = std::map<uint64_t, std::string>();
}

std::map<uint32_t, std::string> dict = json["checksums"];
std::map<uint64_t, std::string> dict = json["checksums"];

return ChecksumDictionary(dict);
}
Expand All @@ -49,16 +49,16 @@ void ChecksumDictionary::save(const std::string& path) {
data.close();
}

void ChecksumDictionary::populate(uint32_t value, std::string name) {
void ChecksumDictionary::populate(uint64_t value, const std::string& name) {
dictionary.insert({value, name});
}

bool ChecksumDictionary::contains(uint32_t value) {
bool ChecksumDictionary::contains(uint64_t value) {
return dictionary.contains(value);
}

std::string ChecksumDictionary::resolve(uint32_t checksum) {
std::string ChecksumDictionary::resolve(uint64_t checksum) {
return dictionary[checksum];
}

ChecksumDictionary::ChecksumDictionary(const std::map<uint32_t, std::string> &dictionary) : dictionary(dictionary) {}
ChecksumDictionary::ChecksumDictionary(const std::map<uint64_t, std::string> &dictionary) : dictionary(dictionary) {}
10 changes: 5 additions & 5 deletions source/qb/ChecksumDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
class ChecksumDictionary {
public:
ChecksumDictionary();
explicit ChecksumDictionary(const std::map<uint32_t, std::string> &dictionary);
explicit ChecksumDictionary(const std::map<uint64_t, std::string> &dictionary);

static std::string getDictionaryPath();
static ChecksumDictionary load(const std::string& path);
void save(const std::string& path);

void populate(uint32_t value, std::string name);
bool contains(uint32_t value);
std::string resolve(uint32_t checksum);
void populate(uint64_t value, const std::string& name);
bool contains(uint64_t value);
std::string resolve(uint64_t checksum);
private:
std::map<uint32_t, std::string> dictionary;
std::map<uint64_t, std::string> dictionary;
};


Expand Down
7 changes: 6 additions & 1 deletion source/qb/QbRecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,12 @@ std::vector<u8> QbRecompiler::compile(std::string &source, ChecksumDictionary &s
bytes.push_back(((checksum) >> 16) & 0xFF);
bytes.push_back(((checksum) >> 24) & 0xFF);

symbols.populate(checksum, checksum_name);
unsigned long reversed = ((unsigned long)(checksum & 0xFF) << 24) |
((unsigned long)((checksum >> 8) & 0xFF) << 16) |
((unsigned long)((checksum >> 16) & 0xFF) << 8) |
((unsigned long)((checksum >> 24) & 0xFF));

symbols.populate(reversed, checksum_name);

index++;

Expand Down

0 comments on commit 1f1623b

Please sign in to comment.