feat: Added decompressing support
This commit is contained in:
parent
9066891ce2
commit
e2489151f3
5
.gitattributes
vendored
5
.gitattributes
vendored
@ -1 +1,4 @@
|
||||
lib/external/** linguist-vendored
|
||||
lib/external/** linguist-vendored
|
||||
|
||||
dist/*.sh eol=lf
|
||||
dist/**/*Dockerfile eol=lf
|
2
dist/Arch/PKGBUILD
vendored
2
dist/Arch/PKGBUILD
vendored
@ -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)
|
||||
|
2
dist/DEBIAN/control.in
vendored
2
dist/DEBIAN/control.in
vendored
@ -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
|
||||
|
1
dist/ImHex-9999.ebuild
vendored
1
dist/ImHex-9999.ebuild
vendored
@ -24,5 +24,6 @@ RDEPEND="${DEPEND}
|
||||
dev-cpp/nlohmann_json
|
||||
dbus
|
||||
xdg-desktop-portal
|
||||
app-arch/libarchive
|
||||
"
|
||||
BDEPEND="${DEPEND}"
|
||||
|
27
dist/get_deps_archlinux.sh
vendored
27
dist/get_deps_archlinux.sh
vendored
@ -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
|
||||
|
3
dist/get_deps_debian.sh
vendored
3
dist/get_deps_debian.sh
vendored
@ -22,4 +22,5 @@ apt install -y \
|
||||
libdbus-1-dev \
|
||||
libcurl4-gnutls-dev \
|
||||
libgtk-3-dev \
|
||||
ninja-build
|
||||
ninja-build \
|
||||
libarchive-dev
|
||||
|
3
dist/get_deps_fedora.sh
vendored
3
dist/get_deps_fedora.sh
vendored
@ -12,4 +12,5 @@ dnf install -y \
|
||||
glfw-devel \
|
||||
lld \
|
||||
mbedtls-devel \
|
||||
gtk3-devel
|
||||
gtk3-devel \
|
||||
libarchive-devel
|
3
dist/get_deps_msys2.sh
vendored
3
dist/get_deps_msys2.sh
vendored
@ -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
|
||||
|
1
dist/macOS/arm64.Dockerfile
vendored
1
dist/macOS/arm64.Dockerfile
vendored
@ -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
|
||||
|
3
dist/msys2/PKGBUILD
vendored
3
dist/msys2/PKGBUILD
vendored
@ -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=()
|
||||
|
43
dist/net.werwolv.ImHex.yaml
vendored
43
dist/net.werwolv.ImHex.yaml
vendored
@ -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
|
||||
|
1
dist/web/Dockerfile
vendored
1
dist/web/Dockerfile
vendored
@ -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
|
||||
|
2
lib/external/libromfs
vendored
2
lib/external/libromfs
vendored
@ -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 {
|
||||
|
19
plugins/decompress/CMakeLists.txt
Normal file
19
plugins/decompress/CMakeLists.txt
Normal 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
|
||||
)
|
59
plugins/decompress/source/content/pl_functions.cpp
Normal file
59
plugins/decompress/source/content/pl_functions.cpp
Normal 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 §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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
21
plugins/decompress/source/plugin_decompress.cpp
Normal file
21
plugins/decompress/source/plugin_decompress.cpp
Normal 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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user