mirror of https://github.com/WerWolv/ImHex.git
feat: Added decompressing support
This commit is contained in:
parent
9066891ce2
commit
e2489151f3
|
@ -1 +1,4 @@
|
|||
lib/external/** linguist-vendored
|
||||
lib/external/** linguist-vendored
|
||||
|
||||
dist/*.sh eol=lf
|
||||
dist/**/*Dockerfile eol=lf
|
|
@ -8,7 +8,7 @@ pkgdesc="A Hex Editor for Reverse Engineers, Programmers and people who value th
|
|||
arch=("x86_64")
|
||||
url="https://github.com/WerWolv/ImHex"
|
||||
license=('GPL2')
|
||||
depends=(glfw mbedtls freetype2 libglvnd dbus gtk3 curl fmt yara nlohmann-json)
|
||||
depends=(glfw mbedtls freetype2 libglvnd dbus gtk3 curl fmt yara nlohmann-json libarchive)
|
||||
makedepends=(git)
|
||||
provides=(imhex)
|
||||
conflicts=(imhex)
|
||||
|
|
|
@ -4,7 +4,7 @@ Section: editors
|
|||
Priority: optional
|
||||
Architecture: amd64
|
||||
License: GNU GPL-2
|
||||
Depends: libglfw3 | libglfw3-wayland, libmagic1, libmbedtls14, libfreetype6, libopengl0, libdbus-1-3, xdg-desktop-portal
|
||||
Depends: libglfw3 | libglfw3-wayland, libmagic1, libmbedtls14, libfreetype6, libopengl0, libdbus-1-3, xdg-desktop-portal, libarchive
|
||||
Maintainer: WerWolv <hey@werwolv.net>
|
||||
Description: ImHex Hex Editor
|
||||
A Hex Editor for Reverse Engineers, Programmers and
|
||||
|
|
|
@ -24,5 +24,6 @@ RDEPEND="${DEPEND}
|
|||
dev-cpp/nlohmann_json
|
||||
dbus
|
||||
xdg-desktop-portal
|
||||
app-arch/libarchive
|
||||
"
|
||||
BDEPEND="${DEPEND}"
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
pacman -S $@ --needed \
|
||||
cmake \
|
||||
gcc \
|
||||
lld \
|
||||
glfw \
|
||||
file \
|
||||
mbedtls \
|
||||
freetype2 \
|
||||
dbus \
|
||||
gtk3 \
|
||||
curl \
|
||||
fmt \
|
||||
yara \
|
||||
cmake \
|
||||
gcc \
|
||||
lld \
|
||||
glfw \
|
||||
file \
|
||||
mbedtls \
|
||||
freetype2 \
|
||||
dbus \
|
||||
gtk3 \
|
||||
curl \
|
||||
fmt \
|
||||
yara \
|
||||
nlohmann-json \
|
||||
ninja
|
||||
ninja \
|
||||
libarchive
|
||||
|
|
|
@ -22,4 +22,5 @@ apt install -y \
|
|||
libdbus-1-dev \
|
||||
libcurl4-gnutls-dev \
|
||||
libgtk-3-dev \
|
||||
ninja-build
|
||||
ninja-build \
|
||||
libarchive-dev
|
||||
|
|
|
@ -12,4 +12,5 @@ dnf install -y \
|
|||
glfw-devel \
|
||||
lld \
|
||||
mbedtls-devel \
|
||||
gtk3-devel
|
||||
gtk3-devel \
|
||||
libarchive-devel
|
|
@ -12,4 +12,5 @@ pacman -S --needed --noconfirm \
|
|||
mingw-w64-x86_64-freetype \
|
||||
mingw-w64-x86_64-dlfcn \
|
||||
mingw-w64-x86_64-ninja \
|
||||
mingw-w64-x86_64-capstone
|
||||
mingw-w64-x86_64-capstone \
|
||||
mingw-w64-x86_64-libarchive
|
||||
|
|
|
@ -52,6 +52,7 @@ vcpkg install --triplet=arm-osx-mytriplet curl
|
|||
vcpkg install --triplet=arm-osx-mytriplet mbedtls
|
||||
vcpkg install --triplet=arm-osx-mytriplet freetype
|
||||
vcpkg install --triplet=arm-osx-mytriplet josuttis-jthread
|
||||
vcpkg install --triplet=arm-osx-mytriplet libarchive
|
||||
EOF
|
||||
|
||||
## Install glfw3 dep
|
||||
|
|
|
@ -16,7 +16,8 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
|
|||
"${MINGW_PACKAGE_PREFIX}-file"
|
||||
"${MINGW_PACKAGE_PREFIX}-mbedtls"
|
||||
"${MINGW_PACKAGE_PREFIX}-polly"
|
||||
"${MINGW_PACKAGE_PREFIX}-freetype")
|
||||
"${MINGW_PACKAGE_PREFIX}-freetype"
|
||||
"${MINGW_PACKAGE_PREFIX}-libarchive")
|
||||
|
||||
source=()
|
||||
sha256sums=()
|
||||
|
|
|
@ -12,49 +12,10 @@ finish-args:
|
|||
- --device=all
|
||||
|
||||
modules:
|
||||
- name: libiconv
|
||||
sources:
|
||||
- type: archive
|
||||
url: https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
|
||||
sha256: e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04
|
||||
|
||||
- name: glfw
|
||||
buildsystem: cmake-ninja
|
||||
builddir: true
|
||||
config-opts:
|
||||
- -DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||
- -DBUILD_SHARED_LIBS:BOOL=ON
|
||||
sources:
|
||||
- type: archive
|
||||
url: https://github.com/glfw/glfw/releases/download/3.3.2/glfw-3.3.2.zip
|
||||
sha256: 08a33a512f29d7dbf78eab39bd7858576adcc95228c9efe8e4bc5f0f3261efc7
|
||||
cleanup:
|
||||
- /include
|
||||
- /lib/pkgconfig
|
||||
|
||||
- name: mbedtls
|
||||
buildsystem: cmake-ninja
|
||||
config-opts:
|
||||
- -DCMAKE_C_FLAGS=-fPIC
|
||||
sources:
|
||||
- type: archive
|
||||
url: https://github.com/ARMmbed/mbedtls/archive/refs/tags/v2.27.0.tar.gz
|
||||
sha256: 2a07856e541f0e5f6eaee4f78018c52f25bd244ed76f9020dea54a8b02cac6ea
|
||||
|
||||
- name: nlohmann-json
|
||||
buildsystem: cmake-ninja
|
||||
builddir: true
|
||||
config-opts:
|
||||
- -DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||
- -DBUILD_TESTING=OFF
|
||||
|
||||
sources:
|
||||
- type: archive
|
||||
url: https://github.com/nlohmann/json/archive/v3.9.1.tar.gz
|
||||
sha256: 4cf0df69731494668bdd6460ed8cb269b68de9c19ad8c27abc24cd72605b2d5b
|
||||
|
||||
- name: imhex
|
||||
buildsystem: cmake
|
||||
config-opts:
|
||||
- -DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||
|
||||
sources:
|
||||
- type: git
|
||||
|
|
|
@ -37,6 +37,7 @@ mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
|
|||
/vcpkg/vcpkg install --triplet=wasm32-emscripten libmagic
|
||||
/vcpkg/vcpkg install --triplet=wasm32-emscripten freetype
|
||||
/vcpkg/vcpkg install --triplet=wasm32-emscripten mbedtls
|
||||
/vcpkg/vcpkg install --triplet=wasm32-emscripten libarchive
|
||||
EOF
|
||||
|
||||
# Build ImHex
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 45382a6a37a4cccbecc0f7fb6e6c5f607b50ffab
|
||||
Subproject commit 0a72f7bb33d87c4fb2709b6b94bf83518ab0022d
|
|
@ -174,7 +174,7 @@ namespace hex {
|
|||
}
|
||||
|
||||
bool Plugin::isValid() const {
|
||||
return m_handle != 0;
|
||||
return m_handle != 0 || m_functions.initializeLibraryFunction != nullptr || m_functions.initializePluginFunction != nullptr;
|
||||
}
|
||||
|
||||
bool Plugin::isLoaded() const {
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include(ImHexPlugin)
|
||||
|
||||
find_package(LibArchive 3.6 REQUIRED)
|
||||
|
||||
add_imhex_plugin(
|
||||
NAME
|
||||
decompress
|
||||
SOURCES
|
||||
source/plugin_decompress.cpp
|
||||
|
||||
source/content/pl_functions.cpp
|
||||
INCLUDES
|
||||
include
|
||||
LIBRARIES
|
||||
ui
|
||||
LibArchive::LibArchive
|
||||
)
|
|
@ -0,0 +1,59 @@
|
|||
#include <hex.hpp>
|
||||
|
||||
#include <hex/api/content_registry.hpp>
|
||||
#include <pl/core/evaluator.hpp>
|
||||
#include <pl/patterns/pattern.hpp>
|
||||
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
namespace hex::plugin::decompress {
|
||||
|
||||
void registerPatternLanguageFunctions() {
|
||||
using namespace pl::core;
|
||||
using FunctionParameterCount = pl::api::FunctionParameterCount;
|
||||
|
||||
const pl::api::Namespace nsHexDec = { "builtin", "hex", "dec" };
|
||||
|
||||
/* decompress() */
|
||||
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
|
||||
const auto inputPattern = params[0].toPattern();
|
||||
auto §ion = evaluator->getSection(params[1].toUnsigned());
|
||||
|
||||
std::vector<u8> compressedData;
|
||||
compressedData.resize(inputPattern->getSize());
|
||||
evaluator->readData(inputPattern->getOffset(), compressedData.data(), compressedData.size(), inputPattern->getSection());
|
||||
|
||||
auto inArchive = archive_read_new();
|
||||
ON_SCOPE_EXIT {
|
||||
archive_read_close(inArchive);
|
||||
archive_read_free(inArchive);
|
||||
};
|
||||
|
||||
archive_read_support_filter_all(inArchive);
|
||||
archive_read_support_format_raw(inArchive);
|
||||
|
||||
archive_read_open_memory(inArchive, compressedData.data(), compressedData.size());
|
||||
|
||||
archive_entry *entry = nullptr;
|
||||
while (archive_read_next_header(inArchive, &entry) == ARCHIVE_OK) {
|
||||
const void *block = nullptr;
|
||||
size_t size = 0x00;
|
||||
i64 offset = 0x00;
|
||||
|
||||
while (archive_read_data_block(inArchive, &block, &size, &offset) == ARCHIVE_OK) {
|
||||
section.resize(section.size() + size);
|
||||
std::memcpy(section.data(), block, size);
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#include <hex/plugin.hpp>
|
||||
|
||||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <romfs/romfs.hpp>
|
||||
|
||||
namespace hex::plugin::decompress {
|
||||
|
||||
void registerPatternLanguageFunctions();
|
||||
|
||||
}
|
||||
|
||||
using namespace hex;
|
||||
using namespace hex::plugin::decompress;
|
||||
|
||||
IMHEX_PLUGIN_SETUP("Decompressing", "WerWolv", "Support for decompressing data") {
|
||||
hex::log::debug("Using romfs: '{}'", romfs::name());
|
||||
|
||||
registerPatternLanguageFunctions();
|
||||
}
|
Loading…
Reference in New Issue