1
0
mirror of synced 2024-11-12 02:00:52 +01:00

feat: Move hashes into plugin, merged in extra hashes plugin

This commit is contained in:
WerWolv 2023-12-23 22:01:47 +01:00
parent 61bfe10bc2
commit fe24db7c57
40 changed files with 982 additions and 487 deletions

3
.gitmodules vendored
View File

@ -33,3 +33,6 @@
path = lib/external/libwolv
url = https://github.com/WerWolv/libwolv
[submodule "lib/third_party/HashLibPlus"]
path = lib/third_party/HashLibPlus
url = https://github.com/WerWolv/HashLibPlus

View File

@ -40,6 +40,7 @@ set(LIBIMHEX_SOURCES
source/helpers/debugging.cpp
source/providers/provider.cpp
source/providers/memory_provider.cpp
source/providers/undo/stack.cpp
source/ui/imgui_imhex_extensions.cpp

View File

@ -0,0 +1,47 @@
#pragma once
#include <hex/providers/provider.hpp>
namespace hex::prv {
/**
* This is a simple mock provider that can be used to pass in-memory data to APIs that require a provider.
* It's NOT a provider that can be loaded by the user.
*/
class MemoryProvider : public hex::prv::Provider {
public:
MemoryProvider() = default;
explicit MemoryProvider(std::vector<u8> data) : m_data(std::move(data)) { }
~MemoryProvider() override = default;
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool isReadable() const override { return true; }
[[nodiscard]] bool isWritable() const override { return true; }
[[nodiscard]] bool isResizable() const override { return true; }
[[nodiscard]] bool isSavable() const override { return m_name.empty(); }
[[nodiscard]] bool isSavableAsRecent() const override { return false; }
[[nodiscard]] bool open() override;
void close() override { }
void readRaw(u64 offset, void *buffer, size_t size) override;
void writeRaw(u64 offset, const void *buffer, size_t size) override;
[[nodiscard]] u64 getActualSize() const override { return m_data.size(); }
void resizeRaw(u64 newSize) override;
void insertRaw(u64 offset, u64 size) override;
void removeRaw(u64 offset, u64 size) override;
[[nodiscard]] std::string getName() const override { return ""; }
[[nodiscard]] std::string getTypeName() const override { return "MemoryProvider"; }
private:
void renameFile();
private:
std::vector<u8> m_data;
std::string m_name;
};
}

View File

@ -0,0 +1,71 @@
#include <hex/providers/memory_provider.hpp>
#include <cstring>
namespace hex::prv {
bool MemoryProvider::open() {
if (m_data.empty()) {
m_data.resize(1);
}
return true;
}
void MemoryProvider::readRaw(u64 offset, void *buffer, size_t size) {
auto actualSize = this->getActualSize();
if (actualSize == 0 || (offset + size) > actualSize || buffer == nullptr || size == 0)
return;
std::memcpy(buffer, &m_data.front() + offset, size);
}
void MemoryProvider::writeRaw(u64 offset, const void *buffer, size_t size) {
if ((offset + size) > this->getActualSize() || buffer == nullptr || size == 0)
return;
std::memcpy(&m_data.front() + offset, buffer, size);
}
void MemoryProvider::resizeRaw(u64 newSize) {
m_data.resize(newSize);
}
void MemoryProvider::insertRaw(u64 offset, u64 size) {
auto oldSize = this->getActualSize();
this->resizeRaw(oldSize + size);
std::vector<u8> buffer(0x1000);
const std::vector<u8> zeroBuffer(0x1000);
auto position = oldSize;
while (position > offset) {
const auto readSize = std::min<size_t>(position - offset, buffer.size());
position -= readSize;
this->readRaw(position, buffer.data(), readSize);
this->writeRaw(position, zeroBuffer.data(), readSize);
this->writeRaw(position + size, buffer.data(), readSize);
}
}
void MemoryProvider::removeRaw(u64 offset, u64 size) {
auto oldSize = this->getActualSize();
std::vector<u8> buffer(0x1000);
const auto newSize = oldSize - size;
auto position = offset;
while (position < newSize) {
const auto readSize = std::min<size_t>(newSize - position, buffer.size());
this->readRaw(position + size, buffer.data(), readSize);
this->writeRaw(position, buffer.data(), readSize);
position += readSize;
}
this->resizeRaw(oldSize - size);
}
}

1
lib/third_party/HashLibPlus vendored Submodule

@ -0,0 +1 @@
Subproject commit f9d85855ed5caa1d024634fa24dbfe81f3e00f3e

View File

@ -32,7 +32,6 @@ add_imhex_plugin(
source/content/welcome_screen.cpp
source/content/data_visualizers.cpp
source/content/events.cpp
source/content/hashes.cpp
source/content/global_actions.cpp
source/content/themes.cpp
source/content/recent.cpp
@ -90,7 +89,6 @@ add_imhex_plugin(
source/content/views/view_hex_editor.cpp
source/content/views/view_pattern_editor.cpp
source/content/views/view_pattern_data.cpp
source/content/views/view_hashes.cpp
source/content/views/view_information.cpp
source/content/views/view_about.cpp
source/content/views/view_tools.cpp

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -56,30 +56,11 @@
"hex.builtin.achievement.misc.analyze_file.desc": "",
"hex.builtin.achievement.misc.download_from_store.name": "",
"hex.builtin.achievement.misc.download_from_store.desc": "",
"hex.builtin.achievement.misc.create_hash.name": "",
"hex.builtin.achievement.misc.create_hash.desc": "",
"hex.builtin.command.calc.desc": "Rechner",
"hex.builtin.command.cmd.desc": "Befehl",
"hex.builtin.command.cmd.result": "Befehl '{0}' ausführen",
"hex.builtin.command.web.desc": "Webseite nachschlagen",
"hex.builtin.command.web.result": "'{0}' nachschlagen",
"hex.builtin.hash.crc.iv": "Initialwert",
"hex.builtin.hash.crc.poly": "Polynom",
"hex.builtin.hash.crc.refl_in": "Reflect In",
"hex.builtin.hash.crc.refl_out": "Reflect Out",
"hex.builtin.hash.crc.xor_out": "XOR Out",
"hex.builtin.hash.crc16": "CRC-16",
"hex.builtin.hash.crc32": "CRC-32",
"hex.builtin.hash.crc32c": "CRC-32C",
"hex.builtin.hash.crc32mpeg": "CRC-32/MPEG",
"hex.builtin.hash.crc32posix": "CRC-32/POSIX",
"hex.builtin.hash.crc8": "CRC-8",
"hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224",
"hex.builtin.hash.sha256": "SHA256",
"hex.builtin.hash.sha384": "SHA384",
"hex.builtin.hash.sha512": "SHA512",
"hex.builtin.inspector.ascii": "ASCII Zeichen",
"hex.builtin.inspector.binary": "Binär (8 bit)",
"hex.builtin.inspector.bool": "bool",
@ -628,15 +609,6 @@
"hex.builtin.view.find.value.max": "Maximalwert",
"hex.builtin.view.find.value.min": "Minimalwert",
"hex.builtin.view.find.value.range": "",
"hex.builtin.view.hashes.function": "Hashfunktion",
"hex.builtin.view.hashes.hash": "Hash",
"hex.builtin.view.hashes.hover_info": "Bewege die Maus über die ausgewählten Bytes im Hex Editor und halte SHIFT gedrückt, um die Hashes dieser Region anzuzeigen.",
"hex.builtin.view.hashes.name": "Hashes",
"hex.builtin.view.hashes.no_settings": "Keine Einstellungen verfügbar",
"hex.builtin.view.hashes.remove": "Hash entfernen",
"hex.builtin.view.hashes.table.name": "Name",
"hex.builtin.view.hashes.table.result": "Resultat",
"hex.builtin.view.hashes.table.type": "Typ",
"hex.builtin.view.help.about.contributor": "Mitwirkende",
"hex.builtin.view.help.about.donations": "Spenden",
"hex.builtin.view.help.about.libs": "Benutzte Libraries",

View File

@ -58,8 +58,6 @@
"hex.builtin.achievement.misc.analyze_file.desc": "Analyze the bytes of your data by using the 'Analyze' option in the Data Information view.",
"hex.builtin.achievement.misc.download_from_store.name": "There's an app for that",
"hex.builtin.achievement.misc.download_from_store.desc": "Download any item from the Content Store",
"hex.builtin.achievement.misc.create_hash.name": "Hash browns",
"hex.builtin.achievement.misc.create_hash.desc": "Create a new hash function in the Hash view by selecting the type, giving it a name and clicking on the Plus button next to it.",
"hex.builtin.command.calc.desc": "Calculator",
"hex.builtin.command.convert.desc": "Unit conversion",
"hex.builtin.command.convert.hexadecimal": "hexadecimal",
@ -75,23 +73,6 @@
"hex.builtin.command.cmd.result": "Run command '{0}'",
"hex.builtin.command.web.desc": "Website lookup",
"hex.builtin.command.web.result": "Navigate to '{0}'",
"hex.builtin.hash.crc.iv": "Initial Value",
"hex.builtin.hash.crc.poly": "Polynomial",
"hex.builtin.hash.crc.refl_in": "Reflect In",
"hex.builtin.hash.crc.refl_out": "Reflect Out",
"hex.builtin.hash.crc.xor_out": "XOR Out",
"hex.builtin.hash.crc16": "CRC-16",
"hex.builtin.hash.crc32": "CRC-32",
"hex.builtin.hash.crc32c": "CRC-32C",
"hex.builtin.hash.crc32mpeg": "CRC-32/MPEG",
"hex.builtin.hash.crc32posix": "CRC-32/POSIX",
"hex.builtin.hash.crc8": "CRC-8",
"hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224",
"hex.builtin.hash.sha256": "SHA256",
"hex.builtin.hash.sha384": "SHA384",
"hex.builtin.hash.sha512": "SHA512",
"hex.builtin.inspector.ascii": "ASCII Character",
"hex.builtin.inspector.binary": "Binary (8 bit)",
"hex.builtin.inspector.bool": "bool",
@ -725,15 +706,6 @@
"hex.builtin.view.find.value.max": "Maximum Value",
"hex.builtin.view.find.value.min": "Minimum Value",
"hex.builtin.view.find.value.range": "Ranged Search",
"hex.builtin.view.hashes.function": "Hash function",
"hex.builtin.view.hashes.hash": "Hash",
"hex.builtin.view.hashes.hover_info": "Hover over the Hex Editor selection and hold down SHIFT to view the hashes of that region.",
"hex.builtin.view.hashes.name": "Hashes",
"hex.builtin.view.hashes.no_settings": "No settings available",
"hex.builtin.view.hashes.remove": "Remove hash",
"hex.builtin.view.hashes.table.name": "Name",
"hex.builtin.view.hashes.table.result": "Result",
"hex.builtin.view.hashes.table.type": "Type",
"hex.builtin.view.help.about.commits": "Commit History",
"hex.builtin.view.help.about.contributor": "Contributors",
"hex.builtin.view.help.about.donations": "Donations",

View File

@ -56,30 +56,11 @@
"hex.builtin.achievement.misc.analyze_file.desc": "",
"hex.builtin.achievement.misc.download_from_store.name": "",
"hex.builtin.achievement.misc.download_from_store.desc": "",
"hex.builtin.achievement.misc.create_hash.name": "",
"hex.builtin.achievement.misc.create_hash.desc": "",
"hex.builtin.command.calc.desc": "Calculadora",
"hex.builtin.command.cmd.desc": "Comando",
"hex.builtin.command.cmd.result": "Ejecutar comando '{0}'",
"hex.builtin.command.web.desc": "Búsqueda (de) web",
"hex.builtin.command.web.result": "Navegar a '{0}'",
"hex.builtin.hash.crc.iv": "Valor Inicial",
"hex.builtin.hash.crc.poly": "Polinomio",
"hex.builtin.hash.crc.refl_in": "Reflect In",
"hex.builtin.hash.crc.refl_out": "Reflect Out",
"hex.builtin.hash.crc.xor_out": "XOR Out",
"hex.builtin.hash.crc16": "CRC-16",
"hex.builtin.hash.crc32": "CRC-32",
"hex.builtin.hash.crc32c": "CRC-32Cç",
"hex.builtin.hash.crc32mpeg": "CRC-32/MPEG",
"hex.builtin.hash.crc32posix": "CRC-32/POSIX",
"hex.builtin.hash.crc8": "CRC-8",
"hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224",
"hex.builtin.hash.sha256": "SHA256",
"hex.builtin.hash.sha384": "SHA384",
"hex.builtin.hash.sha512": "SHA512",
"hex.builtin.inspector.ascii": "Carácter ASCII",
"hex.builtin.inspector.binary": "Binario (8 bit)",
"hex.builtin.inspector.bool": "bool",
@ -627,15 +608,6 @@
"hex.builtin.view.find.value.max": "Valor máximo",
"hex.builtin.view.find.value.min": "Valor Mínimo",
"hex.builtin.view.find.value.range": "Búsqueda en Rango",
"hex.builtin.view.hashes.function": "Función de Hash",
"hex.builtin.view.hashes.hash": "Hash",
"hex.builtin.view.hashes.hover_info": "Sitúe el ratón sobre la selección del Editor Hexadecimal y mantenga SHIFT para ver los hashes de esa región.",
"hex.builtin.view.hashes.name": "Hashes",
"hex.builtin.view.hashes.no_settings": "No hay ajustes disponibles",
"hex.builtin.view.hashes.remove": "Eliminar hash",
"hex.builtin.view.hashes.table.name": "Nombre",
"hex.builtin.view.hashes.table.result": "Resultado",
"hex.builtin.view.hashes.table.type": "Tipo",
"hex.builtin.view.help.about.contributor": "Contribuidores",
"hex.builtin.view.help.about.donations": "Donaciones",
"hex.builtin.view.help.about.libs": "Librerías utilizadas",

View File

@ -56,30 +56,11 @@
"hex.builtin.achievement.misc.analyze_file.desc": "",
"hex.builtin.achievement.misc.download_from_store.name": "",
"hex.builtin.achievement.misc.download_from_store.desc": "",
"hex.builtin.achievement.misc.create_hash.name": "",
"hex.builtin.achievement.misc.create_hash.desc": "",
"hex.builtin.command.calc.desc": "Calcolatrice",
"hex.builtin.command.cmd.desc": "Comando",
"hex.builtin.command.cmd.result": "Esegui comando '{0}'",
"hex.builtin.command.web.desc": "Consulta il Web",
"hex.builtin.command.web.result": "Naviga a '{0}'",
"hex.builtin.hash.crc.iv": "Valore Iniziale",
"hex.builtin.hash.crc.poly": "Polinomio",
"hex.builtin.hash.crc.refl_in": "",
"hex.builtin.hash.crc.refl_out": "",
"hex.builtin.hash.crc.xor_out": "",
"hex.builtin.hash.crc16": "CRC16",
"hex.builtin.hash.crc32": "CRC32",
"hex.builtin.hash.crc32c": "",
"hex.builtin.hash.crc32mpeg": "",
"hex.builtin.hash.crc32posix": "",
"hex.builtin.hash.crc8": "CRC8",
"hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224",
"hex.builtin.hash.sha256": "SHA256",
"hex.builtin.hash.sha384": "SHA384",
"hex.builtin.hash.sha512": "SHA512",
"hex.builtin.inspector.ascii": "ASCII Character",
"hex.builtin.inspector.binary": "Binary (8 bit)",
"hex.builtin.inspector.bool": "bool",
@ -627,15 +608,6 @@
"hex.builtin.view.find.value.max": "",
"hex.builtin.view.find.value.min": "",
"hex.builtin.view.find.value.range": "",
"hex.builtin.view.hashes.function": "Funzioni di Hash",
"hex.builtin.view.hashes.hash": "Hash",
"hex.builtin.view.hashes.hover_info": "",
"hex.builtin.view.hashes.name": "Hash",
"hex.builtin.view.hashes.no_settings": "",
"hex.builtin.view.hashes.remove": "",
"hex.builtin.view.hashes.table.name": "",
"hex.builtin.view.hashes.table.result": "Risultato",
"hex.builtin.view.hashes.table.type": "",
"hex.builtin.view.help.about.contributor": "Collaboratori",
"hex.builtin.view.help.about.donations": "Donazioni",
"hex.builtin.view.help.about.libs": "Librerie usate",

View File

@ -56,30 +56,11 @@
"hex.builtin.achievement.misc.analyze_file.desc": "",
"hex.builtin.achievement.misc.download_from_store.name": "",
"hex.builtin.achievement.misc.download_from_store.desc": "",
"hex.builtin.achievement.misc.create_hash.name": "",
"hex.builtin.achievement.misc.create_hash.desc": "",
"hex.builtin.command.calc.desc": "電卓",
"hex.builtin.command.cmd.desc": "コマンド",
"hex.builtin.command.cmd.result": "コマンド '{0}' を実行",
"hex.builtin.command.web.desc": "ウェブサイト参照",
"hex.builtin.command.web.result": "'{0}' を開く",
"hex.builtin.hash.crc.iv": "初期値",
"hex.builtin.hash.crc.poly": "多項式",
"hex.builtin.hash.crc.refl_in": "入力を反映",
"hex.builtin.hash.crc.refl_out": "出力を反映",
"hex.builtin.hash.crc.xor_out": "最終XOR値",
"hex.builtin.hash.crc16": "CRC16",
"hex.builtin.hash.crc32": "CRC32",
"hex.builtin.hash.crc32c": "",
"hex.builtin.hash.crc32mpeg": "",
"hex.builtin.hash.crc32posix": "",
"hex.builtin.hash.crc8": "CRC8",
"hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224",
"hex.builtin.hash.sha256": "SHA256",
"hex.builtin.hash.sha384": "SHA384",
"hex.builtin.hash.sha512": "SHA512",
"hex.builtin.inspector.ascii": "ASCII",
"hex.builtin.inspector.binary": "バイナリ (8 bit)",
"hex.builtin.inspector.bool": "bool",
@ -627,15 +608,6 @@
"hex.builtin.view.find.value.max": "最大値",
"hex.builtin.view.find.value.min": "最小値",
"hex.builtin.view.find.value.range": "",
"hex.builtin.view.hashes.function": "ハッシュ関数",
"hex.builtin.view.hashes.hash": "",
"hex.builtin.view.hashes.hover_info": "",
"hex.builtin.view.hashes.name": "ハッシュ",
"hex.builtin.view.hashes.no_settings": "",
"hex.builtin.view.hashes.remove": "",
"hex.builtin.view.hashes.table.name": "",
"hex.builtin.view.hashes.table.result": "結果",
"hex.builtin.view.hashes.table.type": "",
"hex.builtin.view.help.about.contributor": "ご協力頂いた方々",
"hex.builtin.view.help.about.donations": "寄付",
"hex.builtin.view.help.about.libs": "使用しているライブラリ",

View File

@ -56,30 +56,11 @@
"hex.builtin.achievement.misc.analyze_file.desc": "데이터 정보 보기의 '분석' 옵션을 사용하여 데이터의 바이트를 분석합니다.",
"hex.builtin.achievement.misc.download_from_store.name": "그걸 위한 앱이 있죠",
"hex.builtin.achievement.misc.download_from_store.desc": "콘텐츠 스토어에서 아무 항목이나 다운로드합니다.",
"hex.builtin.achievement.misc.create_hash.name": "해시 브라운",
"hex.builtin.achievement.misc.create_hash.desc": "해시 보기에서 유형을 선택하고 이름을 지정한 다음 옆에 있는 더하기 버튼을 클릭하여 새 해시 함수를 만듭니다.",
"hex.builtin.command.calc.desc": "계산기",
"hex.builtin.command.cmd.desc": "명령",
"hex.builtin.command.cmd.result": "'{0}' 명령 실행",
"hex.builtin.command.web.desc": "웹사이트 탐색",
"hex.builtin.command.web.result": "'{0}'(으)로 이동",
"hex.builtin.hash.crc.iv": "초기 값",
"hex.builtin.hash.crc.poly": "다항식",
"hex.builtin.hash.crc.refl_in": "입력에 반영",
"hex.builtin.hash.crc.refl_out": "출력에 반영",
"hex.builtin.hash.crc.xor_out": "XOR 출력",
"hex.builtin.hash.crc16": "CRC-16",
"hex.builtin.hash.crc32": "CRC-32",
"hex.builtin.hash.crc32c": "CRC-32C",
"hex.builtin.hash.crc32mpeg": "CRC-32/MPEG",
"hex.builtin.hash.crc32posix": "CRC-32/POSIX",
"hex.builtin.hash.crc8": "CRC-8",
"hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224",
"hex.builtin.hash.sha256": "SHA256",
"hex.builtin.hash.sha384": "SHA384",
"hex.builtin.hash.sha512": "SHA512",
"hex.builtin.inspector.ascii": "ASCII 문자",
"hex.builtin.inspector.binary": "2진수 (8비트)",
"hex.builtin.inspector.bool": "부울",
@ -648,15 +629,6 @@
"hex.builtin.view.find.value.max": "최댓값",
"hex.builtin.view.find.value.min": "최솟값",
"hex.builtin.view.find.value.range": "범위 검색",
"hex.builtin.view.hashes.function": "해시 함수",
"hex.builtin.view.hashes.hash": "해시",
"hex.builtin.view.hashes.hover_info": "헥스 에디터 선택 영역 위로 마우스를 가져간 상태에서 Shift를 길게 누르면 해당 영역의 해시를 볼 수 있습니다.",
"hex.builtin.view.hashes.name": "해시",
"hex.builtin.view.hashes.no_settings": "설정이 없습니다",
"hex.builtin.view.hashes.remove": "해시 제거",
"hex.builtin.view.hashes.table.name": "이름",
"hex.builtin.view.hashes.table.result": "결과",
"hex.builtin.view.hashes.table.type": "유형",
"hex.builtin.view.help.about.contributor": "기여자",
"hex.builtin.view.help.about.donations": "후원",
"hex.builtin.view.help.about.libs": "사용한 라이브러리",

View File

@ -56,30 +56,11 @@
"hex.builtin.achievement.misc.analyze_file.desc": "",
"hex.builtin.achievement.misc.download_from_store.name": "",
"hex.builtin.achievement.misc.download_from_store.desc": "",
"hex.builtin.achievement.misc.create_hash.name": "",
"hex.builtin.achievement.misc.create_hash.desc": "",
"hex.builtin.command.calc.desc": "Calculadora",
"hex.builtin.command.cmd.desc": "Comando",
"hex.builtin.command.cmd.result": "Iniciar Comando '{0}'",
"hex.builtin.command.web.desc": "Website lookup",
"hex.builtin.command.web.result": "Navegar para '{0}'",
"hex.builtin.hash.crc.iv": "Initial Value",
"hex.builtin.hash.crc.poly": "Polynomial",
"hex.builtin.hash.crc.refl_in": "Reflect In",
"hex.builtin.hash.crc.refl_out": "Reflect Out",
"hex.builtin.hash.crc.xor_out": "XOR Out",
"hex.builtin.hash.crc16": "CRC16",
"hex.builtin.hash.crc32": "CRC32",
"hex.builtin.hash.crc32c": "",
"hex.builtin.hash.crc32mpeg": "",
"hex.builtin.hash.crc32posix": "",
"hex.builtin.hash.crc8": "CRC8",
"hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224",
"hex.builtin.hash.sha256": "SHA256",
"hex.builtin.hash.sha384": "SHA384",
"hex.builtin.hash.sha512": "SHA512",
"hex.builtin.inspector.ascii": "ASCII Character",
"hex.builtin.inspector.binary": "Binary (8 bit)",
"hex.builtin.inspector.bool": "bool",
@ -627,15 +608,6 @@
"hex.builtin.view.find.value.max": "",
"hex.builtin.view.find.value.min": "",
"hex.builtin.view.find.value.range": "",
"hex.builtin.view.hashes.function": "Função Hash",
"hex.builtin.view.hashes.hash": "Hash",
"hex.builtin.view.hashes.hover_info": "Passe o mouse sobre a seleção Hex Editor e mantenha pressionada a tecla SHIFT para visualizar os hashes dessa região.",
"hex.builtin.view.hashes.name": "Hashes",
"hex.builtin.view.hashes.no_settings": "Nenhuma configuração disponivel",
"hex.builtin.view.hashes.remove": "Remover hash",
"hex.builtin.view.hashes.table.name": "Nome",
"hex.builtin.view.hashes.table.result": "Resultado",
"hex.builtin.view.hashes.table.type": "Tipo",
"hex.builtin.view.help.about.contributor": "Contribuidores",
"hex.builtin.view.help.about.donations": "Doações",
"hex.builtin.view.help.about.libs": "Bibliotecas usadas",

View File

@ -56,30 +56,11 @@
"hex.builtin.achievement.misc.analyze_file.desc": "使用数据信息视图中的“分析”选项来分析数据。",
"hex.builtin.achievement.misc.download_from_store.name": "就是这样用的",
"hex.builtin.achievement.misc.download_from_store.desc": "从内容商店下载任何内容",
"hex.builtin.achievement.misc.create_hash.name": "Hash",
"hex.builtin.achievement.misc.create_hash.desc": "通过选择类型、为其命名并单击旁边的加号按钮,在“哈希”视图中创建新的哈希函数。",
"hex.builtin.command.calc.desc": "计算器",
"hex.builtin.command.cmd.desc": "指令",
"hex.builtin.command.cmd.result": "运行指令 '{0}'",
"hex.builtin.command.web.desc": "网站解析",
"hex.builtin.command.web.result": "导航到 '{0}'",
"hex.builtin.hash.crc.iv": "初始值",
"hex.builtin.hash.crc.poly": "多项式",
"hex.builtin.hash.crc.refl_in": "输入值取反",
"hex.builtin.hash.crc.refl_out": "输出值取反",
"hex.builtin.hash.crc.xor_out": "结果异或值",
"hex.builtin.hash.crc16": "CRC-16",
"hex.builtin.hash.crc32": "CRC-32",
"hex.builtin.hash.crc32c": "CRC-32C",
"hex.builtin.hash.crc32mpeg": "CRC-32/MPEG",
"hex.builtin.hash.crc32posix": "CRC-32/POSIX",
"hex.builtin.hash.crc8": "CRC-8",
"hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224",
"hex.builtin.hash.sha256": "SHA256",
"hex.builtin.hash.sha384": "SHA384",
"hex.builtin.hash.sha512": "SHA512",
"hex.builtin.inspector.ascii": "ASCII 字符",
"hex.builtin.inspector.binary": "二进制8 位)",
"hex.builtin.inspector.bool": "bool",
@ -641,15 +622,6 @@
"hex.builtin.view.find.value.max": "最大值",
"hex.builtin.view.find.value.min": "最小值",
"hex.builtin.view.find.value.range": "范围搜索",
"hex.builtin.view.hashes.function": "哈希函数",
"hex.builtin.view.hashes.hash": "哈希",
"hex.builtin.view.hashes.hover_info": "将鼠标放在 Hex 编辑器的选区上,按住 SHIFT 来查看其哈希。",
"hex.builtin.view.hashes.name": "哈希",
"hex.builtin.view.hashes.no_settings": "没有可用哈希设置",
"hex.builtin.view.hashes.remove": "移除哈希",
"hex.builtin.view.hashes.table.name": "名称",
"hex.builtin.view.hashes.table.result": "结果",
"hex.builtin.view.hashes.table.type": "类型",
"hex.builtin.view.help.about.contributor": "贡献者",
"hex.builtin.view.help.about.donations": "赞助",
"hex.builtin.view.help.about.libs": "使用的库",

View File

@ -56,30 +56,11 @@
"hex.builtin.achievement.misc.analyze_file.desc": "使用資料資訊檢視的 '分析' 選項來分析您資料中的位元組。",
"hex.builtin.achievement.misc.download_from_store.name": "There's an app for that",
"hex.builtin.achievement.misc.download_from_store.desc": "從內容商店下載任何東西",
"hex.builtin.achievement.misc.create_hash.name": "Hash browns",
"hex.builtin.achievement.misc.create_hash.desc": "Create a new hash function in the Hash view by selecting the type, giving it a name and clicking on the Plus button next to it.",
"hex.builtin.command.calc.desc": "計算機",
"hex.builtin.command.cmd.desc": "命令",
"hex.builtin.command.cmd.result": "執行命令 '{0}'",
"hex.builtin.command.web.desc": "網站查詢",
"hex.builtin.command.web.result": "前往 '{0}'",
"hex.builtin.hash.crc.iv": "初始數值",
"hex.builtin.hash.crc.poly": "多項式",
"hex.builtin.hash.crc.refl_in": "Reflect In",
"hex.builtin.hash.crc.refl_out": "Reflect Out",
"hex.builtin.hash.crc.xor_out": "XOR Out",
"hex.builtin.hash.crc16": "CRC16",
"hex.builtin.hash.crc32": "CRC32",
"hex.builtin.hash.crc32c": "CRC-32C",
"hex.builtin.hash.crc32mpeg": "CRC-32/MPEG",
"hex.builtin.hash.crc32posix": "CRC-32/POSIX",
"hex.builtin.hash.crc8": "CRC8",
"hex.builtin.hash.md5": "MD5",
"hex.builtin.hash.sha1": "SHA1",
"hex.builtin.hash.sha224": "SHA224",
"hex.builtin.hash.sha256": "SHA256",
"hex.builtin.hash.sha384": "SHA384",
"hex.builtin.hash.sha512": "SHA512",
"hex.builtin.inspector.ascii": "ASCII 字元",
"hex.builtin.inspector.binary": "二進位 (8 位元)",
"hex.builtin.inspector.bool": "bool",
@ -641,15 +622,6 @@
"hex.builtin.view.find.value.max": "最大值",
"hex.builtin.view.find.value.min": "最小值",
"hex.builtin.view.find.value.range": "",
"hex.builtin.view.hashes.function": "雜湊函式",
"hex.builtin.view.hashes.hash": "雜湊",
"hex.builtin.view.hashes.hover_info": "懸停在十六進位編輯器的選取範圍上,並按住 Shift 以查看該區域的雜湊。",
"hex.builtin.view.hashes.name": "雜湊",
"hex.builtin.view.hashes.no_settings": "無可用設定",
"hex.builtin.view.hashes.remove": "移除雜湊",
"hex.builtin.view.hashes.table.name": "名稱",
"hex.builtin.view.hashes.table.result": "結果",
"hex.builtin.view.hashes.table.type": "類型",
"hex.builtin.view.help.about.contributor": "貢獻者",
"hex.builtin.view.help.about.donations": "贊助",
"hex.builtin.view.help.about.libs": "使用的程式庫",

View File

@ -32,7 +32,7 @@ Size=863,1427
Collapsed=0
DockId=0x00000004,0
[Window][###hex.builtin.view.hashes.name]
[Window][###hex.hashes.view.hashes.name]
Pos=1697,76
Size=863,1427
Collapsed=0
@ -152,7 +152,7 @@ hex.builtin.view.data_processor.name=0
hex.builtin.view.diff.name=0
hex.disassembler.view.disassembler.name=0
hex.builtin.view.find.name=0
hex.builtin.view.hashes.name=0
hex.hashes.view.hashes.name=0
hex.builtin.view.help.about.name=0
hex.builtin.view.hex_editor.name=1
hex.builtin.view.information.name=0

View File

@ -32,7 +32,7 @@ Size=863,1427
Collapsed=0
DockId=0x00000004,0
[Window][###hex.builtin.view.hashes.name]
[Window][###hex.hashes.view.hashes.name]
Pos=1697,76
Size=863,1427
Collapsed=0
@ -153,7 +153,7 @@ hex.builtin.view.data_processor.name=0
hex.builtin.view.diff.name=0
hex.disassembler.view.disassembler.name=0
hex.builtin.view.find.name=0
hex.builtin.view.hashes.name=0
hex.hashes.view.hashes.name=0
hex.builtin.view.help.about.name=0
hex.builtin.view.hex_editor.name=1
hex.builtin.view.highlight_rules.name=0

View File

@ -178,11 +178,6 @@ namespace hex::plugin::builtin {
.setDescription("hex.builtin.achievement.misc.download_from_store.desc")
.setIcon(romfs::get("assets/achievements/package.png").span())
.addRequirement("hex.builtin.achievement.starting_out.open_file.name");
AchievementManager::addAchievement<AchievementMisc>("hex.builtin.achievement.misc.create_hash.name")
.setDescription("hex.builtin.achievement.misc.create_hash.desc")
.setIcon(romfs::get("assets/achievements/fortune-cookie.png").span())
.addRequirement("hex.builtin.achievement.starting_out.open_file.name");
}

View File

@ -1,187 +0,0 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/localization_manager.hpp>
#include <hex/helpers/crypto.hpp>
#include <hex/ui/imgui_imhex_extensions.h>
#include <nlohmann/json.hpp>
namespace hex::plugin::builtin {
class HashMD5 : public ContentRegistry::Hashes::Hash {
public:
HashMD5() : Hash("hex.builtin.hash.md5") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::md5(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA1 : public ContentRegistry::Hashes::Hash {
public:
HashSHA1() : Hash("hex.builtin.hash.sha1") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha1(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA224 : public ContentRegistry::Hashes::Hash {
public:
HashSHA224() : Hash("hex.builtin.hash.sha224") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha224(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA256 : public ContentRegistry::Hashes::Hash {
public:
HashSHA256() : Hash("hex.builtin.hash.sha256") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha256(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA384 : public ContentRegistry::Hashes::Hash {
public:
HashSHA384() : Hash("hex.builtin.hash.sha384") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha384(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA512 : public ContentRegistry::Hashes::Hash {
public:
HashSHA512() : Hash("hex.builtin.hash.sha512") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha512(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
template<typename T>
class HashCRC : public ContentRegistry::Hashes::Hash {
public:
using CRCFunction = T(*)(prv::Provider*&, u64, size_t, u32, u32, u32, bool, bool);
HashCRC(const std::string &name, const CRCFunction &crcFunction, u32 polynomial, u32 initialValue, u32 xorOut, bool reflectIn = false, bool reflectOut = false)
: Hash(name), m_crcFunction(crcFunction), m_polynomial(polynomial), m_initialValue(initialValue), m_xorOut(xorOut), m_reflectIn(reflectIn), m_reflectOut(reflectOut) {}
void draw() override {
ImGuiExt::InputHexadecimal("hex.builtin.hash.crc.poly"_lang, &m_polynomial);
ImGuiExt::InputHexadecimal("hex.builtin.hash.crc.iv"_lang, &m_initialValue);
ImGuiExt::InputHexadecimal("hex.builtin.hash.crc.xor_out"_lang, &m_xorOut);
ImGui::NewLine();
ImGui::Checkbox("hex.builtin.hash.crc.refl_in"_lang, &m_reflectIn);
ImGui::Checkbox("hex.builtin.hash.crc.refl_out"_lang, &m_reflectOut);
}
Function create(std::string name) override {
return Hash::create(name, [hash = *this](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto result = hash.m_crcFunction(provider, region.address, region.size, hash.m_polynomial, hash.m_initialValue, hash.m_xorOut, hash.m_reflectIn, hash.m_reflectOut);
std::vector<u8> bytes(sizeof(result), 0x00);
std::memcpy(bytes.data(), &result, bytes.size());
if constexpr (std::endian::native == std::endian::little)
std::reverse(bytes.begin(), bytes.end());
return bytes;
});
}
[[nodiscard]] nlohmann::json store() const override {
nlohmann::json result;
result["polynomial"] = m_polynomial;
result["initialValue"] = m_initialValue;
result["xorOut"] = m_xorOut;
result["reflectIn"] = m_reflectIn;
result["reflectOut"] = m_reflectOut;
return result;
}
void load(const nlohmann::json &json) override {
try {
m_polynomial = json.at("polynomial");
m_initialValue = json.at("initialValue");
m_xorOut = json.at("xorOut");
m_reflectIn = json.at("reflectIn");
m_reflectOut = json.at("reflectOut");
} catch (std::exception&) { }
}
private:
CRCFunction m_crcFunction;
u32 m_polynomial;
u32 m_initialValue;
u32 m_xorOut;
bool m_reflectIn = false, m_reflectOut = false;
};
void registerHashes() {
ContentRegistry::Hashes::add<HashMD5>();
ContentRegistry::Hashes::add<HashSHA1>();
ContentRegistry::Hashes::add<HashSHA224>();
ContentRegistry::Hashes::add<HashSHA256>();
ContentRegistry::Hashes::add<HashSHA384>();
ContentRegistry::Hashes::add<HashSHA512>();
ContentRegistry::Hashes::add<HashCRC<u8>>("hex.builtin.hash.crc8", crypt::crc8, 0x07, 0x0000, 0x0000);
ContentRegistry::Hashes::add<HashCRC<u16>>("hex.builtin.hash.crc16", crypt::crc16, 0x8005, 0x0000, 0x0000);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.builtin.hash.crc32", crypt::crc32, 0x04C1'1DB7, 0xFFFF'FFFF, 0xFFFF'FFFF, true, true);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.builtin.hash.crc32mpeg", crypt::crc32, 0x04C1'1DB7, 0xFFFF'FFFF, 0x0000'0000, false, false);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.builtin.hash.crc32posix", crypt::crc32, 0x04C1'1DB7, 0x0000'0000, 0xFFFF'FFFF, false, false);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.builtin.hash.crc32c", crypt::crc32, 0x1EDC'6F41, 0xFFFF'FFFF, 0xFFFF'FFFF, true, true);
}
}

View File

@ -1,5 +1,7 @@
#include <hex/helpers/utils.hpp>
#include <hex/providers/memory_provider.hpp>
#include <imgui.h>
#include <pl/pattern_language.hpp>
@ -7,31 +9,28 @@
#include <hex/ui/imgui_imhex_extensions.h>
#include <ui/hex_editor.hpp>
#include <content/providers/memory_file_provider.hpp>
namespace hex::plugin::builtin {
void drawHexVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
static ui::HexEditor editor;
static std::unique_ptr<MemoryFileProvider> dataProvider;
static prv::MemoryProvider dataProvider;
if (shouldReset) {
auto pattern = arguments[0].toPattern();
std::vector<u8> data;
dataProvider = std::make_unique<MemoryFileProvider>();
try {
data = pattern->getBytes();
} catch (const std::exception &) {
dataProvider->resize(0);
dataProvider.resize(0);
throw;
}
dataProvider->resize(data.size());
dataProvider->writeRaw(0x00, data.data(), data.size());
dataProvider->setReadOnly(true);
dataProvider.resize(data.size());
dataProvider.writeRaw(0x00, data.data(), data.size());
editor.setProvider(dataProvider.get());
editor.setProvider(&dataProvider);
}
if (ImGui::BeginChild("##editor", scaled(ImVec2(600, 400)), false, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {

View File

@ -1,7 +1,6 @@
#include "content/views/view_hex_editor.hpp"
#include "content/views/view_pattern_editor.hpp"
#include "content/views/view_pattern_data.hpp"
#include "content/views/view_hashes.hpp"
#include "content/views/view_information.hpp"
#include "content/views/view_about.hpp"
#include "content/views/view_tools.hpp"
@ -29,7 +28,6 @@ namespace hex::plugin::builtin {
ContentRegistry::Views::add<ViewPatternEditor>();
ContentRegistry::Views::add<ViewPatternData>();
ContentRegistry::Views::add<ViewDataInspector>();
ContentRegistry::Views::add<ViewHashes>();
ContentRegistry::Views::add<ViewInformation>();
ContentRegistry::Views::add<ViewBookmarks>();
ContentRegistry::Views::add<ViewPatches>();

View File

@ -16,6 +16,8 @@
#include <hex/helpers/magic.hpp>
#include <hex/helpers/binary_pattern.hpp>
#include <hex/providers/memory_provider.hpp>
#include <hex/helpers/fmt.hpp>
#include <fmt/chrono.h>
@ -588,11 +590,7 @@ namespace hex::plugin::builtin {
ImGuiExt::TextFormatted("{} | 0x{:02X}", hex::toByteString(section.data.size()), section.data.size());
ImGui::TableNextColumn();
if (ImGuiExt::IconButton(ICON_VS_OPEN_PREVIEW, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
auto dataProvider = std::make_shared<MemoryFileProvider>();
dataProvider->resize(section.data.size());
dataProvider->writeRaw(0x00, section.data.data(), section.data.size());
dataProvider->setReadOnly(true);
auto dataProvider = std::make_shared<prv::MemoryProvider>(section.data);
auto hexEditor = auto(m_sectionHexEditor);
hexEditor.setBackgroundHighlightCallback([this, id, &runtime](u64 address, const u8 *, size_t) -> std::optional<color_t> {

View File

@ -23,7 +23,6 @@ namespace hex::plugin::builtin {
void registerSettings();
void loadSettings();
void registerDataProcessorNodes();
void registerHashes();
void registerProviders();
void registerDataFormatters();
void registerMainMenuEntries();
@ -95,7 +94,6 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
registerSettings();
loadSettings();
registerDataProcessorNodes();
registerHashes();
registerProviders();
registerDataFormatters();
createWelcomeScreen();

View File

@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.16)
include(ImHexPlugin)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/HashLibPlus ${CMAKE_CURRENT_BINARY_DIR}/HashLibPlus)
add_imhex_plugin(
NAME
hashes
SOURCES
source/plugin_hashes.cpp
source/content/hashes.cpp
source/content/views/view_hashes.cpp
INCLUDES
include
LIBRARIES
hashplus
)

View File

@ -4,7 +4,7 @@
#include <hex/ui/view.hpp>
namespace hex::plugin::builtin {
namespace hex::plugin::hashes {
class ViewHashes : public View::Window {
public:

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,36 @@
{
"code": "de-DE",
"language": "German",
"country": "Germany",
"fallback": false,
"translations": {
"hex.hashes.achievement.misc.create_hash.name": "",
"hex.hashes.achievement.misc.create_hash.desc": "",
"hex.hashes.view.hashes.function": "Hashfunktion",
"hex.hashes.view.hashes.hash": "Hash",
"hex.hashes.view.hashes.hover_info": "Bewege die Maus über die ausgewählten Bytes im Hex Editor und halte SHIFT gedrückt, um die Hashes dieser Region anzuzeigen.",
"hex.hashes.view.hashes.name": "Hashes",
"hex.hashes.view.hashes.no_settings": "Keine Einstellungen verfügbar",
"hex.hashes.view.hashes.remove": "Hash entfernen",
"hex.hashes.view.hashes.table.name": "Name",
"hex.hashes.view.hashes.table.result": "Resultat",
"hex.hashes.view.hashes.table.type": "Typ",
"hex.hashes.hash.common.iv": "Initialwert",
"hex.hashes.hash.common.poly": "Polynom",
"hex.hashes.hash.common.refl_in": "Reflect In",
"hex.hashes.hash.common.refl_out": "Reflect Out",
"hex.hashes.hash.common.xor_out": "XOR Out",
"hex.hashes.hash.crc16": "CRC-16",
"hex.hashes.hash.crc32": "CRC-32",
"hex.hashes.hash.crc32c": "CRC-32C",
"hex.hashes.hash.crc32mpeg": "CRC-32/MPEG",
"hex.hashes.hash.crc32posix": "CRC-32/POSIX",
"hex.hashes.hash.crc8": "CRC-8",
"hex.hashes.hash.md5": "MD5",
"hex.hashes.hash.sha1": "SHA1",
"hex.hashes.hash.sha224": "SHA224",
"hex.hashes.hash.sha256": "SHA256",
"hex.hashes.hash.sha384": "SHA384",
"hex.hashes.hash.sha512": "SHA512"
}
}

View File

@ -0,0 +1,46 @@
{
"code": "en-US",
"language": "English",
"country": "United States",
"fallback": true,
"translations": {
"hex.hashes.achievement.misc.create_hash.name": "Hash browns",
"hex.hashes.achievement.misc.create_hash.desc": "Create a new hash function in the Hash view by selecting the type, giving it a name and clicking on the Plus button next to it.",
"hex.hashes.view.hashes.function": "Hash function",
"hex.hashes.view.hashes.hash": "Hash",
"hex.hashes.view.hashes.hover_info": "Hover over the Hex Editor selection and hold down SHIFT to view the hashes of that region.",
"hex.hashes.view.hashes.name": "Hashes",
"hex.hashes.view.hashes.no_settings": "No settings available",
"hex.hashes.view.hashes.remove": "Remove hash",
"hex.hashes.view.hashes.table.name": "Name",
"hex.hashes.view.hashes.table.result": "Result",
"hex.hashes.view.hashes.table.type": "Type",
"hex.hashes.hash.common.iv": "Initial Value",
"hex.hashes.hash.common.poly": "Polynomial",
"hex.hashes.hash.common.key": "Key",
"hex.hashes.hash.common.size": "Hash Size",
"hex.hashes.hash.common.rounds": "Hash Rounds",
"hex.hashes.hash.common.salt": "Salt",
"hex.hashes.hash.common.personalization": "Personalization",
"hex.hashes.hash.common.refl_in": "Reflect In",
"hex.hashes.hash.common.refl_out": "Reflect Out",
"hex.hashes.hash.common.xor_out": "XOR Out",
"hex.hashes.hash.crc16": "CRC-16",
"hex.hashes.hash.crc32": "CRC-32",
"hex.hashes.hash.crc32c": "CRC-32C",
"hex.hashes.hash.crc32mpeg": "CRC-32/MPEG",
"hex.hashes.hash.crc32posix": "CRC-32/POSIX",
"hex.hashes.hash.crc8": "CRC-8",
"hex.hashes.hash.md5": "MD5",
"hex.hashes.hash.sha1": "SHA1",
"hex.hashes.hash.sha224": "SHA224",
"hex.hashes.hash.sha256": "SHA256",
"hex.hashes.hash.sha384": "SHA384",
"hex.hashes.hash.sha512": "SHA512",
"hex.hashes.hash.tiger": "Tiger",
"hex.hashes.hash.tiger2": "Tiger2",
"hex.hashes.hash.blake2b": "Blake2B",
"hex.hashes.hash.blake2s": "Blake2S"
}
}

View File

@ -0,0 +1,36 @@
{
"code": "es_ES",
"language": "Spanish",
"country": "Spain",
"fallback": false,
"translations": {
"hex.hashes.achievement.misc.create_hash.name": "",
"hex.hashes.achievement.misc.create_hash.desc": "",
"hex.hashes.view.hashes.function": "Función de Hash",
"hex.hashes.view.hashes.hash": "Hash",
"hex.hashes.view.hashes.hover_info": "Sitúe el ratón sobre la selección del Editor Hexadecimal y mantenga SHIFT para ver los hashes de esa región.",
"hex.hashes.view.hashes.name": "Hashes",
"hex.hashes.view.hashes.no_settings": "No hay ajustes disponibles",
"hex.hashes.view.hashes.remove": "Eliminar hash",
"hex.hashes.view.hashes.table.name": "Nombre",
"hex.hashes.view.hashes.table.result": "Resultado",
"hex.hashes.view.hashes.table.type": "Tipo",
"hex.hashes.hash.common.iv": "Valor Inicial",
"hex.hashes.hash.common.poly": "Polinomio",
"hex.hashes.hash.common.refl_in": "Reflect In",
"hex.hashes.hash.common.refl_out": "Reflect Out",
"hex.hashes.hash.common.xor_out": "XOR Out",
"hex.hashes.hash.crc16": "CRC-16",
"hex.hashes.hash.crc32": "CRC-32",
"hex.hashes.hash.crc32c": "CRC-32C",
"hex.hashes.hash.crc32mpeg": "CRC-32/MPEG",
"hex.hashes.hash.crc32posix": "CRC-32/POSIX",
"hex.hashes.hash.crc8": "CRC-8",
"hex.hashes.hash.md5": "MD5",
"hex.hashes.hash.sha1": "SHA1",
"hex.hashes.hash.sha224": "SHA224",
"hex.hashes.hash.sha256": "SHA256",
"hex.hashes.hash.sha384": "SHA384",
"hex.hashes.hash.sha512": "SHA512"
}
}

View File

@ -0,0 +1,36 @@
{
"code": "it-IT",
"language": "Italian",
"country": "Italy",
"fallback": false,
"translations": {
"hex.hashes.achievement.misc.create_hash.name": "",
"hex.hashes.achievement.misc.create_hash.desc": "",
"hex.hashes.view.hashes.function": "Funzioni di Hash",
"hex.hashes.view.hashes.hash": "Hash",
"hex.hashes.view.hashes.hover_info": "",
"hex.hashes.view.hashes.name": "Hash",
"hex.hashes.view.hashes.no_settings": "",
"hex.hashes.view.hashes.remove": "",
"hex.hashes.view.hashes.table.name": "",
"hex.hashes.view.hashes.table.result": "Risultato",
"hex.hashes.view.hashes.table.type": "",
"hex.hashes.hash.common.iv": "Valore Iniziale",
"hex.hashes.hash.common.poly": "Polinomio",
"hex.hashes.hash.common.refl_in": "",
"hex.hashes.hash.common.refl_out": "",
"hex.hashes.hash.common.xor_out": "",
"hex.hashes.hash.crc16": "CRC16",
"hex.hashes.hash.crc32": "CRC32",
"hex.hashes.hash.crc32c": "",
"hex.hashes.hash.crc32mpeg": "",
"hex.hashes.hash.crc32posix": "",
"hex.hashes.hash.crc8": "CRC8",
"hex.hashes.hash.md5": "MD5",
"hex.hashes.hash.sha1": "SHA1",
"hex.hashes.hash.sha224": "SHA224",
"hex.hashes.hash.sha256": "SHA256",
"hex.hashes.hash.sha384": "SHA384",
"hex.hashes.hash.sha512": "SHA512"
}
}

View File

@ -0,0 +1,36 @@
{
"code": "ja-JP",
"language": "Japanese",
"country": "Japan",
"fallback": false,
"translations": {
"hex.hashes.achievement.misc.create_hash.name": "",
"hex.hashes.achievement.misc.create_hash.desc": "",
"hex.hashes.view.hashes.function": "ハッシュ関数",
"hex.hashes.view.hashes.hash": "",
"hex.hashes.view.hashes.hover_info": "",
"hex.hashes.view.hashes.name": "ハッシュ",
"hex.hashes.view.hashes.no_settings": "",
"hex.hashes.view.hashes.remove": "",
"hex.hashes.view.hashes.table.name": "",
"hex.hashes.view.hashes.table.result": "結果",
"hex.hashes.view.hashes.table.type": "",
"hex.hashes.hash.common.iv": "初期値",
"hex.hashes.hash.common.poly": "多項式",
"hex.hashes.hash.common.refl_in": "入力を反映",
"hex.hashes.hash.common.refl_out": "出力を反映",
"hex.hashes.hash.common.xor_out": "最終XOR値",
"hex.hashes.hash.crc16": "CRC16",
"hex.hashes.hash.crc32": "CRC32",
"hex.hashes.hash.crc32c": "",
"hex.hashes.hash.crc32mpeg": "",
"hex.hashes.hash.crc32posix": "",
"hex.hashes.hash.crc8": "CRC8",
"hex.hashes.hash.md5": "MD5",
"hex.hashes.hash.sha1": "SHA1",
"hex.hashes.hash.sha224": "SHA224",
"hex.hashes.hash.sha256": "SHA256",
"hex.hashes.hash.sha384": "SHA384",
"hex.hashes.hash.sha512": "SHA512"
}
}

View File

@ -0,0 +1,36 @@
{
"code": "ko-KR",
"language": "Korean",
"country": "Korea",
"fallback": false,
"translations": {
"hex.hashes.achievement.misc.create_hash.name": "해시 브라운",
"hex.hashes.achievement.misc.create_hash.desc": "해시 보기에서 유형을 선택하고 이름을 지정한 다음 옆에 있는 더하기 버튼을 클릭하여 새 해시 함수를 만듭니다.",
"hex.hashes.view.hashes.function": "해시 함수",
"hex.hashes.view.hashes.hash": "해시",
"hex.hashes.view.hashes.hover_info": "헥스 에디터 선택 영역 위로 마우스를 가져간 상태에서 Shift를 길게 누르면 해당 영역의 해시를 볼 수 있습니다.",
"hex.hashes.view.hashes.name": "해시",
"hex.hashes.view.hashes.no_settings": "설정이 없습니다",
"hex.hashes.view.hashes.remove": "해시 제거",
"hex.hashes.view.hashes.table.name": "이름",
"hex.hashes.view.hashes.table.result": "결과",
"hex.hashes.view.hashes.table.type": "유형",
"hex.hashes.hash.common.iv": "초기 값",
"hex.hashes.hash.common.poly": "다항식",
"hex.hashes.hash.common.refl_in": "입력에 반영",
"hex.hashes.hash.common.refl_out": "출력에 반영",
"hex.hashes.hash.common.xor_out": "XOR 출력",
"hex.hashes.hash.crc16": "CRC-16",
"hex.hashes.hash.crc32": "CRC-32",
"hex.hashes.hash.crc32c": "CRC-32C",
"hex.hashes.hash.crc32mpeg": "CRC-32/MPEG",
"hex.hashes.hash.crc32posix": "CRC-32/POSIX",
"hex.hashes.hash.crc8": "CRC-8",
"hex.hashes.hash.md5": "MD5",
"hex.hashes.hash.sha1": "SHA1",
"hex.hashes.hash.sha224": "SHA224",
"hex.hashes.hash.sha256": "SHA256",
"hex.hashes.hash.sha384": "SHA384",
"hex.hashes.hash.sha512": "SHA512"
}
}

View File

@ -0,0 +1,36 @@
{
"code": "pt-BR",
"language": "Portuguese",
"country": "Brazil",
"fallback": false,
"translations": {
"hex.hashes.achievement.misc.create_hash.name": "",
"hex.hashes.achievement.misc.create_hash.desc": "",
"hex.hashes.view.hashes.function": "Função Hash",
"hex.hashes.view.hashes.hash": "Hash",
"hex.hashes.view.hashes.hover_info": "Passe o mouse sobre a seleção Hex Editor e mantenha pressionada a tecla SHIFT para visualizar os hashes dessa região.",
"hex.hashes.view.hashes.name": "Hashes",
"hex.hashes.view.hashes.no_settings": "Nenhuma configuração disponivel",
"hex.hashes.view.hashes.remove": "Remover hash",
"hex.hashes.view.hashes.table.name": "Nome",
"hex.hashes.view.hashes.table.result": "Resultado",
"hex.hashes.view.hashes.table.type": "Tipo",
"hex.hashes.hash.common.iv": "Initial Value",
"hex.hashes.hash.common.poly": "Polynomial",
"hex.hashes.hash.common.refl_in": "Reflect In",
"hex.hashes.hash.common.refl_out": "Reflect Out",
"hex.hashes.hash.common.xor_out": "XOR Out",
"hex.hashes.hash.crc16": "CRC16",
"hex.hashes.hash.crc32": "CRC32",
"hex.hashes.hash.crc32c": "",
"hex.hashes.hash.crc32mpeg": "",
"hex.hashes.hash.crc32posix": "",
"hex.hashes.hash.crc8": "CRC8",
"hex.hashes.hash.md5": "MD5",
"hex.hashes.hash.sha1": "SHA1",
"hex.hashes.hash.sha224": "SHA224",
"hex.hashes.hash.sha256": "SHA256",
"hex.hashes.hash.sha384": "SHA384",
"hex.hashes.hash.sha512": "SHA512"
}
}

View File

@ -0,0 +1,36 @@
{
"code": "zh-CN",
"language": "Chinese (Simplified)",
"country": "China",
"fallback": false,
"translations": {
"hex.hashes.achievement.misc.create_hash.name": "Hash",
"hex.hashes.achievement.misc.create_hash.desc": "通过选择类型、为其命名并单击旁边的加号按钮,在“哈希”视图中创建新的哈希函数。",
"hex.hashes.view.hashes.function": "哈希函数",
"hex.hashes.view.hashes.hash": "哈希",
"hex.hashes.view.hashes.hover_info": "将鼠标放在 Hex 编辑器的选区上,按住 SHIFT 来查看其哈希。",
"hex.hashes.view.hashes.name": "哈希",
"hex.hashes.view.hashes.no_settings": "没有可用哈希设置",
"hex.hashes.view.hashes.remove": "移除哈希",
"hex.hashes.view.hashes.table.name": "名称",
"hex.hashes.view.hashes.table.result": "结果",
"hex.hashes.view.hashes.table.type": "类型",
"hex.hashes.hash.common.iv": "初始值",
"hex.hashes.hash.common.poly": "多项式",
"hex.hashes.hash.common.refl_in": "输入值取反",
"hex.hashes.hash.common.refl_out": "输出值取反",
"hex.hashes.hash.common.xor_out": "结果异或值",
"hex.hashes.hash.crc16": "CRC-16",
"hex.hashes.hash.crc32": "CRC-32",
"hex.hashes.hash.crc32c": "CRC-32C",
"hex.hashes.hash.crc32mpeg": "CRC-32/MPEG",
"hex.hashes.hash.crc32posix": "CRC-32/POSIX",
"hex.hashes.hash.crc8": "CRC-8",
"hex.hashes.hash.md5": "MD5",
"hex.hashes.hash.sha1": "SHA1",
"hex.hashes.hash.sha224": "SHA224",
"hex.hashes.hash.sha256": "SHA256",
"hex.hashes.hash.sha384": "SHA384",
"hex.hashes.hash.sha512": "SHA512"
}
}

View File

@ -0,0 +1,36 @@
{
"code": "zh-TW",
"language": "Chinese (Traditional)",
"country": "Taiwan",
"fallback": false,
"translations": {
"hex.hashes.achievement.misc.create_hash.name": "Hash browns",
"hex.hashes.achievement.misc.create_hash.desc": "Create a new hash function in the Hash view by selecting the type, giving it a name and clicking on the Plus button next to it.",
"hex.hashes.view.hashes.function": "雜湊函式",
"hex.hashes.view.hashes.hash": "雜湊",
"hex.hashes.view.hashes.hover_info": "懸停在十六進位編輯器的選取範圍上,並按住 Shift 以查看該區域的雜湊。",
"hex.hashes.view.hashes.name": "雜湊",
"hex.hashes.view.hashes.no_settings": "無可用設定",
"hex.hashes.view.hashes.remove": "移除雜湊",
"hex.hashes.view.hashes.table.name": "名稱",
"hex.hashes.view.hashes.table.result": "結果",
"hex.hashes.view.hashes.table.type": "類型",
"hex.hashes.hash.common.iv": "初始數值",
"hex.hashes.hash.common.poly": "多項式",
"hex.hashes.hash.common.refl_in": "Reflect In",
"hex.hashes.hash.common.refl_out": "Reflect Out",
"hex.hashes.hash.common.xor_out": "XOR Out",
"hex.hashes.hash.crc16": "CRC16",
"hex.hashes.hash.crc32": "CRC32",
"hex.hashes.hash.crc32c": "CRC-32C",
"hex.hashes.hash.crc32mpeg": "CRC-32/MPEG",
"hex.hashes.hash.crc32posix": "CRC-32/POSIX",
"hex.hashes.hash.crc8": "CRC8",
"hex.hashes.hash.md5": "MD5",
"hex.hashes.hash.sha1": "SHA1",
"hex.hashes.hash.sha224": "SHA224",
"hex.hashes.hash.sha256": "SHA256",
"hex.hashes.hash.sha384": "SHA384",
"hex.hashes.hash.sha512": "SHA512"
}
}

View File

@ -0,0 +1,440 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/localization_manager.hpp>
#include <hex/helpers/crypto.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/providers/buffered_reader.hpp>
#include <hex/ui/imgui_imhex_extensions.h>
#include <nlohmann/json.hpp>
#include <wolv/literals.hpp>
#include <HashFactory.h>
namespace hex::plugin::hashes {
namespace {
using namespace wolv::literals;
std::vector<u8> hashProviderRegion(const Region& region, prv::Provider *provider, auto &hashFunction) {
auto reader = prv::ProviderReader(provider);
reader.seek(region.getStartAddress());
reader.setEndAddress(region.getEndAddress());
for (u64 address = region.getStartAddress(); address < region.getEndAddress(); address += 1_MiB) {
u64 readSize = std::min<u64>(1_MiB, (region.getEndAddress() - address) + 1);
auto data = reader.read(address, readSize);
hashFunction->TransformBytes({ data.begin(), data.end() }, address - region.getStartAddress(), data.size());
}
auto result = hashFunction->TransformFinal();
auto bytes = result->GetBytes();
return { bytes.begin(), bytes.end() };
}
}
class HashMD5 : public ContentRegistry::Hashes::Hash {
public:
HashMD5() : Hash("hex.hashes.hash.md5") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::md5(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA1 : public ContentRegistry::Hashes::Hash {
public:
HashSHA1() : Hash("hex.hashes.hash.sha1") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha1(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA224 : public ContentRegistry::Hashes::Hash {
public:
HashSHA224() : Hash("hex.hashes.hash.sha224") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha224(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA256 : public ContentRegistry::Hashes::Hash {
public:
HashSHA256() : Hash("hex.hashes.hash.sha256") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha256(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA384 : public ContentRegistry::Hashes::Hash {
public:
HashSHA384() : Hash("hex.hashes.hash.sha384") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha384(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
class HashSHA512 : public ContentRegistry::Hashes::Hash {
public:
HashSHA512() : Hash("hex.hashes.hash.sha512") {}
Function create(std::string name) override {
return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto array = crypt::sha512(provider, region.address, region.size);
return { array.begin(), array.end() };
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
};
template<typename T>
class HashCRC : public ContentRegistry::Hashes::Hash {
public:
using CRCFunction = T(*)(prv::Provider*&, u64, size_t, u32, u32, u32, bool, bool);
HashCRC(const std::string &name, const CRCFunction &crcFunction, u32 polynomial, u32 initialValue, u32 xorOut, bool reflectIn = false, bool reflectOut = false)
: Hash(name), m_crcFunction(crcFunction), m_polynomial(polynomial), m_initialValue(initialValue), m_xorOut(xorOut), m_reflectIn(reflectIn), m_reflectOut(reflectOut) {}
void draw() override {
ImGuiExt::InputHexadecimal("hex.hashes.hash.common.poly"_lang, &this->m_polynomial);
ImGuiExt::InputHexadecimal("hex.hashes.hash.common.iv"_lang, &this->m_initialValue);
ImGuiExt::InputHexadecimal("hex.hashes.hash.common.xor_out"_lang, &this->m_xorOut);
ImGui::NewLine();
ImGui::Checkbox("hex.hashes.hash.common.refl_in"_lang, &this->m_reflectIn);
ImGui::Checkbox("hex.hashes.hash.common.refl_out"_lang, &this->m_reflectOut);
}
Function create(std::string name) override {
return Hash::create(name, [hash = *this](const Region& region, prv::Provider *provider) -> std::vector<u8> {
auto result = hash.m_crcFunction(provider, region.address, region.size, hash.m_polynomial, hash.m_initialValue, hash.m_xorOut, hash.m_reflectIn, hash.m_reflectOut);
std::vector<u8> bytes(sizeof(result), 0x00);
std::memcpy(bytes.data(), &result, bytes.size());
if constexpr (std::endian::native == std::endian::little)
std::reverse(bytes.begin(), bytes.end());
return bytes;
});
}
[[nodiscard]] nlohmann::json store() const override {
nlohmann::json result;
result["polynomial"] = this->m_polynomial;
result["initialValue"] = this->m_initialValue;
result["xorOut"] = this->m_xorOut;
result["reflectIn"] = this->m_reflectIn;
result["reflectOut"] = this->m_reflectOut;
return result;
}
void load(const nlohmann::json &json) override {
try {
this->m_polynomial = json.at("polynomial");
this->m_initialValue = json.at("initialValue");
this->m_xorOut = json.at("xorOut");
this->m_reflectIn = json.at("reflectIn");
this->m_reflectOut = json.at("reflectOut");
} catch (std::exception&) { }
}
private:
CRCFunction m_crcFunction;
u32 m_polynomial;
u32 m_initialValue;
u32 m_xorOut;
bool m_reflectIn = false, m_reflectOut = false;
};
class HashBasic : public ContentRegistry::Hashes::Hash {
public:
using FactoryFunction = IHash(*)();
explicit HashBasic(FactoryFunction function) : Hash(function()->GetName()), m_factoryFunction(function) {}
Function create(std::string name) override {
return Hash::create(name, [hash = *this](const Region& region, prv::Provider *provider) -> std::vector<u8> {
IHash hashFunction = hash.m_factoryFunction();
hashFunction->Initialize();
return hashProviderRegion(region, provider, hashFunction);
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
private:
FactoryFunction m_factoryFunction;
};
class HashWithKey : public ContentRegistry::Hashes::Hash {
public:
using FactoryFunction = IHashWithKey(*)();
explicit HashWithKey(FactoryFunction function) : Hash(function()->GetName()), m_factoryFunction(function) {}
void draw() override {
ImGui::InputText("hex.hashes.hash.common.key"_lang, this->m_key, ImGuiInputTextFlags_CharsHexadecimal);
}
Function create(std::string name) override {
return Hash::create(name, [hash = *this, key = hex::parseByteString(this->m_key)](const Region& region, prv::Provider *provider) -> std::vector<u8> {
IHashWithKey hashFunction = hash.m_factoryFunction();
hashFunction->Initialize();
hashFunction->SetKey(key);
return hashProviderRegion(region, provider, hashFunction);
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
private:
FactoryFunction m_factoryFunction;
std::string m_key;
};
class HashInitialValue : public ContentRegistry::Hashes::Hash {
public:
using FactoryFunction = IHash(*)(const Int32);
explicit HashInitialValue(FactoryFunction function) : Hash(function(0)->GetName()), m_factoryFunction(function) {}
void draw() override {
ImGuiExt::InputHexadecimal("hex.hashes.hash.common.iv"_lang, &this->m_initialValue);
}
Function create(std::string name) override {
return Hash::create(name, [hash = *this](const Region& region, prv::Provider *provider) -> std::vector<u8> {
IHash hashFunction = hash.m_factoryFunction(Int32(hash.m_initialValue));
hashFunction->Initialize();
return hashProviderRegion(region, provider, hashFunction);
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
private:
FactoryFunction m_factoryFunction;
u32 m_initialValue = 0x00;
};
class HashTiger : public ContentRegistry::Hashes::Hash {
public:
using FactoryFunction = IHash(*)(const Int32, const HashRounds&);
explicit HashTiger(std::string name, FactoryFunction function) : Hash(std::move(name)), m_factoryFunction(function) {}
void draw() override {
ImGui::Combo("hex.hashes.hash.common.size"_lang, &this->m_hashSize, "128 Bits\0" "160 Bits\0" "192 Bits\0");
ImGui::Combo("hex.hashes.hash.common.rounds"_lang, &this->m_hashRounds, "3 Rounds\0" "4 Rounds\0" "5 Rounds\0" "8 Rounds\0");
}
Function create(std::string name) override {
return Hash::create(name, [hash = *this](const Region& region, prv::Provider *provider) -> std::vector<u8> {
Int32 hashSize = 16;
switch (hash.m_hashSize) {
case 0: hashSize = 16; break;
case 1: hashSize = 20; break;
case 2: hashSize = 24; break;
}
HashRounds hashRounds = HashRounds::Rounds3;
switch (hash.m_hashRounds) {
case 0: hashRounds = HashRounds::Rounds3; break;
case 1: hashRounds = HashRounds::Rounds4; break;
case 2: hashRounds = HashRounds::Rounds5; break;
case 3: hashRounds = HashRounds::Rounds8; break;
}
IHash hashFunction = hash.m_factoryFunction(hashSize, hashRounds);
hashFunction->Initialize();
return hashProviderRegion(region, provider, hashFunction);
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
private:
FactoryFunction m_factoryFunction;
int m_hashSize = 0, m_hashRounds = 0;
};
template<typename Config, typename T1, typename T2>
class HashBlake2 : public ContentRegistry::Hashes::Hash {
public:
using FactoryFunction = IHash(*)(T1 a_Config, T2 a_TreeConfig);
explicit HashBlake2(std::string name, FactoryFunction function) : Hash(std::move(name)), m_factoryFunction(function) {}
void draw() override {
ImGui::InputText("hex.hashes.hash.common.salt"_lang, this->m_salt, ImGuiInputTextFlags_CharsHexadecimal);
ImGui::InputText("hex.hashes.hash.common.key"_lang, this->m_key, ImGuiInputTextFlags_CharsHexadecimal);
ImGui::InputText("hex.hashes.hash.common.personalization"_lang, this->m_personalization, ImGuiInputTextFlags_CharsHexadecimal);
ImGui::Combo("hex.hashes.hash.common.size"_lang, &this->m_hashSize, "128 Bits\0" "160 Bits\0" "192 Bits\0" "224 Bits\0" "256 Bits\0" "288 Bits\0" "384 Bits\0" "512 Bits\0");
}
Function create(std::string name) override {
return Hash::create(name, [hash = *this, key = hex::parseByteString(this->m_key), salt = hex::parseByteString(this->m_salt), personalization = hex::parseByteString(this->m_personalization)](const Region& region, prv::Provider *provider) -> std::vector<u8> {
u32 hashSize = 16;
switch (hash.m_hashSize) {
case 0: hashSize = 16; break;
case 1: hashSize = 20; break;
case 2: hashSize = 24; break;
case 3: hashSize = 28; break;
case 4: hashSize = 32; break;
case 5: hashSize = 36; break;
case 6: hashSize = 48; break;
case 7: hashSize = 64; break;
}
auto config = Config::GetDefaultConfig();
config->SetKey(key);
config->SetSalt(salt);
config->SetPersonalization(personalization);
config->SetHashSize(hashSize);
IHash hashFunction = hash.m_factoryFunction(config, nullptr);
hashFunction->Initialize();
return hashProviderRegion(region, provider, hashFunction);
});
}
[[nodiscard]] nlohmann::json store() const override { return { }; }
void load(const nlohmann::json &) override {}
private:
FactoryFunction m_factoryFunction;
std::string m_salt, m_key, m_personalization;
int m_hashSize = 0;
};
void registerHashes() {
ContentRegistry::Hashes::add<HashMD5>();
ContentRegistry::Hashes::add<HashSHA1>();
ContentRegistry::Hashes::add<HashSHA224>();
ContentRegistry::Hashes::add<HashSHA256>();
ContentRegistry::Hashes::add<HashSHA384>();
ContentRegistry::Hashes::add<HashSHA512>();
ContentRegistry::Hashes::add<HashCRC<u8>>("hex.hashes.hash.crc8", crypt::crc8, 0x07, 0x0000, 0x0000);
ContentRegistry::Hashes::add<HashCRC<u16>>("hex.hashes.hash.crc16", crypt::crc16, 0x8005, 0x0000, 0x0000);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.hashes.hash.crc32", crypt::crc32, 0x04C1'1DB7, 0xFFFF'FFFF, 0xFFFF'FFFF, true, true);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.hashes.hash.crc32mpeg", crypt::crc32, 0x04C1'1DB7, 0xFFFF'FFFF, 0x0000'0000, false, false);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.hashes.hash.crc32posix", crypt::crc32, 0x04C1'1DB7, 0x0000'0000, 0xFFFF'FFFF, false, false);
ContentRegistry::Hashes::add<HashCRC<u32>>("hex.hashes.hash.crc32c", crypt::crc32, 0x1EDC'6F41, 0xFFFF'FFFF, 0xFFFF'FFFF, true, true);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Checksum::CreateAdler32);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateAP);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateBKDR);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateBernstein);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateBernstein1);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateDEK);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateDJB);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateELF);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateFNV1a_32);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateFNV32);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateJS);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateOneAtTime);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreatePJW);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateRotating);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateRS);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateSDBM);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateShiftAndXor);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash32::CreateSuperFast);
hex::ContentRegistry::Hashes::add<HashWithKey>(HashFactory::Hash32::CreateMurmur2_32);
hex::ContentRegistry::Hashes::add<HashWithKey>(HashFactory::Hash32::CreateMurmurHash3_x86_32);
hex::ContentRegistry::Hashes::add<HashWithKey>(HashFactory::Hash32::CreateXXHash32);
hex::ContentRegistry::Hashes::add<HashInitialValue>(HashFactory::Hash32::CreateJenkins3);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash64::CreateFNV64);
hex::ContentRegistry::Hashes::add<HashBasic>(HashFactory::Hash64::CreateFNV1a_64);
hex::ContentRegistry::Hashes::add<HashWithKey>(HashFactory::Hash64::CreateMurmur2_64);
hex::ContentRegistry::Hashes::add<HashWithKey>(HashFactory::Hash64::CreateSipHash64_2_4);
hex::ContentRegistry::Hashes::add<HashWithKey>(HashFactory::Hash64::CreateXXHash64);
hex::ContentRegistry::Hashes::add<HashWithKey>(HashFactory::Hash128::CreateSipHash128_2_4);
hex::ContentRegistry::Hashes::add<HashWithKey>(HashFactory::Hash128::CreateMurmurHash3_x86_128);
hex::ContentRegistry::Hashes::add<HashWithKey>(HashFactory::Hash128::CreateMurmurHash3_x64_128);
hex::ContentRegistry::Hashes::add<HashTiger>("hex.hashes.hash.tiger", HashFactory::Crypto::CreateTiger);
hex::ContentRegistry::Hashes::add<HashTiger>("hex.hashes.hash.tiger2", HashFactory::Crypto::CreateTiger2);
hex::ContentRegistry::Hashes::add<HashBlake2<Blake2BConfig, IBlake2BConfig, IBlake2BTreeConfig>>("hex.hashes.hash.blake2b", HashFactory::Crypto::CreateBlake2B);
hex::ContentRegistry::Hashes::add<HashBlake2<Blake2SConfig, IBlake2SConfig, IBlake2STreeConfig>>("hex.hashes.hash.blake2s", HashFactory::Crypto::CreateBlake2S);
}
}

View File

@ -1,16 +1,15 @@
#include "content/views/view_hashes.hpp"
#include "content/providers/memory_file_provider.hpp"
#include <hex/api/project_file_manager.hpp>
#include <hex/api/achievement_manager.hpp>
#include <hex/providers/memory_provider.hpp>
#include <hex/ui/popup.hpp>
#include <hex/helpers/crypto.hpp>
#include <vector>
namespace hex::plugin::builtin {
namespace hex::plugin::hashes {
class PopupTextHash : public Popup<PopupTextHash> {
public:
@ -23,12 +22,10 @@ namespace hex::plugin::builtin {
ImGui::PushItemWidth(-1);
if (ImGui::InputTextMultiline("##input", m_input)) {
auto provider = std::make_unique<MemoryFileProvider>();
provider->resize(m_input.size());
provider->writeRaw(0x00, m_input.data(), m_input.size());
prv::MemoryProvider provider({ m_input.begin(), m_input.end() });
m_hash.reset();
auto bytes = m_hash.get(Region { 0x00, provider->getActualSize() }, provider.get());
auto bytes = m_hash.get(Region { 0x00, provider.getActualSize() }, &provider);
m_result = crypt::encode16(bytes);
}
@ -57,7 +54,7 @@ namespace hex::plugin::builtin {
ContentRegistry::Hashes::Hash::Function m_hash;
};
ViewHashes::ViewHashes() : View::Window("hex.builtin.view.hashes.name") {
ViewHashes::ViewHashes() : View::Window("hex.hashes.view.hashes.name") {
EventRegionSelected::subscribe(this, [this](const auto &providerRegion) {
for (auto &function : m_hashFunctions.get(providerRegion.getProvider()))
function.reset();
@ -77,7 +74,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextUnformatted("hex.builtin.view.hashes.name"_lang);
ImGui::TextUnformatted("hex.hashes.view.hashes.name"_lang);
ImGui::Separator();
ImGui::Indent();
@ -144,7 +141,7 @@ namespace hex::plugin::builtin {
m_selectedHash = hashes.front().get();
}
if (ImGui::BeginCombo("hex.builtin.view.hashes.function"_lang, m_selectedHash != nullptr ? Lang(m_selectedHash->getUnlocalizedName()) : "")) {
if (ImGui::BeginCombo("hex.hashes.view.hashes.function"_lang, m_selectedHash != nullptr ? Lang(m_selectedHash->getUnlocalizedName()) : "")) {
for (const auto &hash : hashes) {
if (ImGui::Selectable(Lang(hash->getUnlocalizedName()), m_selectedHash == hash.get())) {
@ -157,7 +154,7 @@ namespace hex::plugin::builtin {
}
if (m_newHashName.empty() && m_selectedHash != nullptr)
m_newHashName = hex::format("{} {}", Lang(m_selectedHash->getUnlocalizedName()), static_cast<const char *>("hex.builtin.view.hashes.hash"_lang));
m_newHashName = hex::format("{} {}", Lang(m_selectedHash->getUnlocalizedName()), static_cast<const char *>("hex.hashes.view.hashes.hash"_lang));
if (ImGui::BeginChild("##settings", ImVec2(ImGui::GetContentRegionAvail().x, 200_scaled), true)) {
if (m_selectedHash != nullptr) {
@ -166,7 +163,7 @@ namespace hex::plugin::builtin {
// Check if no elements have been added
if (startPos == ImGui::GetCursorPosY()) {
ImGuiExt::TextFormattedCentered("hex.builtin.view.hashes.no_settings"_lang);
ImGuiExt::TextFormattedCentered("hex.hashes.view.hashes.no_settings"_lang);
}
}
}
@ -180,18 +177,18 @@ namespace hex::plugin::builtin {
if (ImGuiExt::IconButton(ICON_VS_ADD, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
if (m_selectedHash != nullptr) {
m_hashFunctions->push_back(m_selectedHash->create(m_newHashName));
AchievementManager::unlockAchievement("hex.builtin.achievement.misc", "hex.builtin.achievement.misc.create_hash.name");
AchievementManager::unlockAchievement("hex.builtin.achievement.misc", "hex.hashes.achievement.misc.create_hash.name");
}
}
ImGui::EndDisabled();
ImGui::SameLine();
ImGuiExt::HelpHover("hex.builtin.view.hashes.hover_info"_lang);
ImGuiExt::HelpHover("hex.hashes.view.hashes.hover_info"_lang);
if (ImGui::BeginTable("##hashes", 4, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollY)) {
ImGui::TableSetupColumn("hex.builtin.view.hashes.table.name"_lang);
ImGui::TableSetupColumn("hex.builtin.view.hashes.table.type"_lang);
ImGui::TableSetupColumn("hex.builtin.view.hashes.table.result"_lang, ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("hex.hashes.view.hashes.table.name"_lang);
ImGui::TableSetupColumn("hex.hashes.view.hashes.table.type"_lang);
ImGui::TableSetupColumn("hex.hashes.view.hashes.table.result"_lang, ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##buttons", ImGuiTableColumnFlags_WidthFixed, 50_scaled);
ImGui::TableHeadersRow();

View File

@ -0,0 +1,33 @@
#include <hex/plugin.hpp>
#include <hex/api/achievement_manager.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/helpers/logger.hpp>
#include <romfs/romfs.hpp>
#include <content/views/view_hashes.hpp>
namespace hex::plugin::hashes {
void registerHashes();
}
using namespace hex;
using namespace hex::plugin::hashes;
IMHEX_PLUGIN_SETUP("Hashes", "WerWolv", "Hashing algorithms") {
hex::log::debug("Using romfs: '{}'", romfs::name());
for (auto &path : romfs::list("lang"))
hex::ContentRegistry::Language::addLocalization(nlohmann::json::parse(romfs::get(path).string()));
registerHashes();
ContentRegistry::Views::add<ViewHashes>();
AchievementManager::addAchievement<Achievement>("hex.builtin.achievement.misc", "hex.hashes.achievement.misc.create_hash.name")
.setDescription("hex.hashes.achievement.misc.create_hash.desc")
.setIcon(romfs::get("assets/achievements/fortune-cookie.png").span())
.addRequirement("hex.builtin.achievement.starting_out.open_file.name");
}