b751f98e91
* ui/ux: Initial recreation of the hex editor view * ui/ux: Added back support for editing cells * ux: Make scrolling and selecting bytes feel nice again * ui/ux: Improved byte selecting, added footer * sys: Make math evaluator more generic to support integer only calculations * patterns: Moved value formatting into pattern language * ui/ux: Added Goto and Search popups, improved selection * ui: Added better tooltips for bookmarks and patterns * sys: Use worse hex search algorithm on macOS Sadly it still doesn't support `std::boyer_moore_horsepool_searcher` * ui: Added back missing events, menu items and shortcuts * fix: Bookmark highlighting being rendered off by one * fix: Various macOS build errors * fix: size_t is not u64 on macos * fix: std::fmod and std::pow not working with integer types on macos * fix: Missing semicolons * sys: Added proper integer pow function * ui: Added back support for custom encodings * fix: Editor not jumping to selection when selection gets changed * ui: Turn Hexii setting into a data visualizer * sys: Added back remaining shortcuts * sys: Remove old hex editor files * sys: Moved more legacy things away from the hex editor view, updated localization * fix: Hex editor scrolling behaving weirdly and inconsistently * sys: Cleaned up Hex editor code * sys: Added selection color setting, localized all new settings * fix: Search feature not working correctly * ui: Replace custom ImGui::Disabled function with native ImGui ones * ui: Fix bookmark tooltip rendering issues * fix: Another size_t not being 64 bit issue on MacOS
64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
#include <hex/helpers/encoding_file.hpp>
|
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
namespace hex {
|
|
|
|
EncodingFile::EncodingFile(Type type, const std::fs::path &path) {
|
|
auto file = fs::File(path, fs::File::Mode::Read);
|
|
switch (type) {
|
|
case Type::Thingy:
|
|
parseThingyFile(file);
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
|
|
this->m_valid = true;
|
|
}
|
|
|
|
std::pair<std::string_view, size_t> EncodingFile::getEncodingFor(const std::vector<u8> &buffer) const {
|
|
for (auto riter = this->m_mapping.crbegin(); riter != this->m_mapping.crend(); ++riter) {
|
|
const auto &[size, mapping] = *riter;
|
|
|
|
if (size > buffer.size()) continue;
|
|
|
|
auto key = std::vector<u8>(buffer.begin(), buffer.begin() + size);
|
|
if (mapping.contains(key))
|
|
return { mapping.at(key), size };
|
|
}
|
|
|
|
return { ".", 1 };
|
|
}
|
|
|
|
void EncodingFile::parseThingyFile(fs::File &file) {
|
|
for (const auto &line : splitString(file.readString(), "\n")) {
|
|
|
|
std::string from, to;
|
|
{
|
|
auto delimiterPos = line.find('=');
|
|
|
|
if (delimiterPos == std::string::npos)
|
|
continue;
|
|
if (delimiterPos >= line.length())
|
|
continue;
|
|
|
|
from = line.substr(0, delimiterPos);
|
|
to = line.substr(delimiterPos + 1);
|
|
|
|
if (from.empty()) continue;
|
|
if (to.empty()) to = " ";
|
|
}
|
|
|
|
auto fromBytes = hex::parseByteString(from);
|
|
if (fromBytes.empty()) continue;
|
|
|
|
if (!this->m_mapping.contains(fromBytes.size()))
|
|
this->m_mapping.insert({ fromBytes.size(), {} });
|
|
this->m_mapping[fromBytes.size()].insert({ fromBytes, to });
|
|
|
|
this->m_longestSequence = std::max(this->m_longestSequence, fromBytes.size());
|
|
}
|
|
}
|
|
|
|
} |