1
0
mirror of synced 2024-09-23 19:18:24 +02:00

feat: Added decompressing support

This commit is contained in:
WerWolv 2023-12-24 13:14:51 +01:00
parent 9066891ce2
commit e2489151f3
17 changed files with 134 additions and 63 deletions

5
.gitattributes vendored
View File

@ -1 +1,4 @@
lib/external/** linguist-vendored lib/external/** linguist-vendored
dist/*.sh eol=lf
dist/**/*Dockerfile eol=lf

2
dist/Arch/PKGBUILD vendored
View File

@ -8,7 +8,7 @@ pkgdesc="A Hex Editor for Reverse Engineers, Programmers and people who value th
arch=("x86_64") arch=("x86_64")
url="https://github.com/WerWolv/ImHex" url="https://github.com/WerWolv/ImHex"
license=('GPL2') 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) makedepends=(git)
provides=(imhex) provides=(imhex)
conflicts=(imhex) conflicts=(imhex)

View File

@ -4,7 +4,7 @@ Section: editors
Priority: optional Priority: optional
Architecture: amd64 Architecture: amd64
License: GNU GPL-2 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> Maintainer: WerWolv <hey@werwolv.net>
Description: ImHex Hex Editor Description: ImHex Hex Editor
A Hex Editor for Reverse Engineers, Programmers and A Hex Editor for Reverse Engineers, Programmers and

View File

@ -24,5 +24,6 @@ RDEPEND="${DEPEND}
dev-cpp/nlohmann_json dev-cpp/nlohmann_json
dbus dbus
xdg-desktop-portal xdg-desktop-portal
app-arch/libarchive
" "
BDEPEND="${DEPEND}" BDEPEND="${DEPEND}"

View File

@ -1,17 +1,18 @@
#!/usr/bin/env sh #!/usr/bin/env sh
pacman -S $@ --needed \ pacman -S $@ --needed \
cmake \ cmake \
gcc \ gcc \
lld \ lld \
glfw \ glfw \
file \ file \
mbedtls \ mbedtls \
freetype2 \ freetype2 \
dbus \ dbus \
gtk3 \ gtk3 \
curl \ curl \
fmt \ fmt \
yara \ yara \
nlohmann-json \ nlohmann-json \
ninja ninja \
libarchive

View File

@ -22,4 +22,5 @@ apt install -y \
libdbus-1-dev \ libdbus-1-dev \
libcurl4-gnutls-dev \ libcurl4-gnutls-dev \
libgtk-3-dev \ libgtk-3-dev \
ninja-build ninja-build \
libarchive-dev

View File

@ -12,4 +12,5 @@ dnf install -y \
glfw-devel \ glfw-devel \
lld \ lld \
mbedtls-devel \ mbedtls-devel \
gtk3-devel gtk3-devel \
libarchive-devel

View File

@ -12,4 +12,5 @@ pacman -S --needed --noconfirm \
mingw-w64-x86_64-freetype \ mingw-w64-x86_64-freetype \
mingw-w64-x86_64-dlfcn \ mingw-w64-x86_64-dlfcn \
mingw-w64-x86_64-ninja \ mingw-w64-x86_64-ninja \
mingw-w64-x86_64-capstone mingw-w64-x86_64-capstone \
mingw-w64-x86_64-libarchive

View File

@ -52,6 +52,7 @@ vcpkg install --triplet=arm-osx-mytriplet curl
vcpkg install --triplet=arm-osx-mytriplet mbedtls vcpkg install --triplet=arm-osx-mytriplet mbedtls
vcpkg install --triplet=arm-osx-mytriplet freetype vcpkg install --triplet=arm-osx-mytriplet freetype
vcpkg install --triplet=arm-osx-mytriplet josuttis-jthread vcpkg install --triplet=arm-osx-mytriplet josuttis-jthread
vcpkg install --triplet=arm-osx-mytriplet libarchive
EOF EOF
## Install glfw3 dep ## Install glfw3 dep

3
dist/msys2/PKGBUILD vendored
View File

@ -16,7 +16,8 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
"${MINGW_PACKAGE_PREFIX}-file" "${MINGW_PACKAGE_PREFIX}-file"
"${MINGW_PACKAGE_PREFIX}-mbedtls" "${MINGW_PACKAGE_PREFIX}-mbedtls"
"${MINGW_PACKAGE_PREFIX}-polly" "${MINGW_PACKAGE_PREFIX}-polly"
"${MINGW_PACKAGE_PREFIX}-freetype") "${MINGW_PACKAGE_PREFIX}-freetype"
"${MINGW_PACKAGE_PREFIX}-libarchive")
source=() source=()
sha256sums=() sha256sums=()

View File

@ -12,49 +12,10 @@ finish-args:
- --device=all - --device=all
modules: 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 - name: imhex
buildsystem: cmake buildsystem: cmake
config-opts:
- -DCMAKE_BUILD_TYPE=RelWithDebInfo
sources: sources:
- type: git - type: git

1
dist/web/Dockerfile vendored
View File

@ -37,6 +37,7 @@ mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
/vcpkg/vcpkg install --triplet=wasm32-emscripten libmagic /vcpkg/vcpkg install --triplet=wasm32-emscripten libmagic
/vcpkg/vcpkg install --triplet=wasm32-emscripten freetype /vcpkg/vcpkg install --triplet=wasm32-emscripten freetype
/vcpkg/vcpkg install --triplet=wasm32-emscripten mbedtls /vcpkg/vcpkg install --triplet=wasm32-emscripten mbedtls
/vcpkg/vcpkg install --triplet=wasm32-emscripten libarchive
EOF EOF
# Build ImHex # Build ImHex

@ -1 +1 @@
Subproject commit 45382a6a37a4cccbecc0f7fb6e6c5f607b50ffab Subproject commit 0a72f7bb33d87c4fb2709b6b94bf83518ab0022d

View File

@ -174,7 +174,7 @@ namespace hex {
} }
bool Plugin::isValid() const { bool Plugin::isValid() const {
return m_handle != 0; return m_handle != 0 || m_functions.initializeLibraryFunction != nullptr || m_functions.initializePluginFunction != nullptr;
} }
bool Plugin::isLoaded() const { bool Plugin::isLoaded() const {

View File

@ -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
)

View File

@ -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 &section = 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;
});
}
}

View File

@ -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();
}