sys: Replaced many helper functions with libwolv

This commit is contained in:
WerWolv 2023-03-12 18:27:29 +01:00
parent e958934a22
commit 0dafb3d230
62 changed files with 263 additions and 1091 deletions

3
.gitmodules vendored
View File

@ -29,3 +29,6 @@
[submodule "lib/external/pattern_language"] [submodule "lib/external/pattern_language"]
path = lib/external/pattern_language path = lib/external/pattern_language
url = https://github.com/WerWolv/PatternLanguage url = https://github.com/WerWolv/PatternLanguage
[submodule "lib/external/libwolv"]
path = lib/external/libwolv
url = https://github.com/WerWolv/libwolv

View File

@ -419,6 +419,8 @@ macro(addBundledLibraries)
add_subdirectory(${EXTERN_LIBS_FOLDER}/intervaltree EXCLUDE_FROM_ALL) add_subdirectory(${EXTERN_LIBS_FOLDER}/intervaltree EXCLUDE_FROM_ALL)
set_target_properties(intervaltree PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(intervaltree PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_subdirectory(${EXTERN_LIBS_FOLDER}/libwolv EXCLUDE_FROM_ALL)
set(XDGPP_INCLUDE_DIRS "${EXTERN_LIBS_FOLDER}/xdgpp") set(XDGPP_INCLUDE_DIRS "${EXTERN_LIBS_FOLDER}/xdgpp")
set(CURL_USE_MBEDTLS ON) set(CURL_USE_MBEDTLS ON)
set(BUILD_CURL_EXE OFF) set(BUILD_CURL_EXE OFF)

1
lib/external/libwolv vendored Submodule

@ -0,0 +1 @@
Subproject commit 6742cbb5c464ae4dcd7c1d5d1a573403258000bd

@ -1 +1 @@
Subproject commit 572a481803aa19c5bd0c3ccce08d63666d01499c Subproject commit 714fb62cf47b171dae58bf2c5a95e82d4d8310a7

View File

@ -25,8 +25,6 @@ set(LIBIMHEX_SOURCES
source/helpers/crypto.cpp source/helpers/crypto.cpp
source/helpers/net.cpp source/helpers/net.cpp
source/helpers/opengl.cpp source/helpers/opengl.cpp
source/helpers/file.cpp
source/helpers/socket.cpp
source/helpers/patches.cpp source/helpers/patches.cpp
source/helpers/encoding_file.cpp source/helpers/encoding_file.cpp
source/helpers/logger.cpp source/helpers/logger.cpp
@ -72,4 +70,4 @@ elseif (APPLE)
endif () endif ()
target_link_libraries(libimhex PRIVATE ${FMT_LIBRARIES}) target_link_libraries(libimhex PRIVATE ${FMT_LIBRARIES})
target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} libpl intervaltree ${MINIAUDIO_LIBRARIES}) target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} libpl intervaltree ${MINIAUDIO_LIBRARIES} libwolv-utils libwolv-io libwolv-hash)

View File

@ -5,6 +5,7 @@
#include <hex/data_processor/attribute.hpp> #include <hex/data_processor/attribute.hpp>
#include <set> #include <set>
#include <span>
#include <string_view> #include <string_view>
#include <vector> #include <vector>
@ -77,7 +78,7 @@ namespace hex::dp {
const i128& getIntegerOnInput(u32 index); const i128& getIntegerOnInput(u32 index);
const long double& getFloatOnInput(u32 index); const long double& getFloatOnInput(u32 index);
void setBufferOnOutput(u32 index, const std::vector<u8> &data); void setBufferOnOutput(u32 index, std::span<const u8> data);
void setIntegerOnOutput(u32 index, i128 integer); void setIntegerOnOutput(u32 index, i128 integer);
void setFloatOnOutput(u32 index, long double floatingPoint); void setFloatOnOutput(u32 index, long double floatingPoint);

View File

@ -8,7 +8,8 @@
#include <span> #include <span>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/file.hpp>
#include <wolv/io/file.hpp>
namespace hex { namespace hex {
@ -28,7 +29,7 @@ namespace hex {
[[nodiscard]] bool valid() const { return this->m_valid; } [[nodiscard]] bool valid() const { return this->m_valid; }
private: private:
void parseThingyFile(fs::File &file); void parseThingyFile(wolv::io::File &file);
bool m_valid = false; bool m_valid = false;

View File

@ -1,83 +0,0 @@
#pragma once
#include <hex.hpp>
#include <cstdio>
#include <string>
#include <vector>
#include <hex/helpers/fs.hpp>
#include <sys/stat.h>
#if defined(OS_MACOS)
#include <unistd.h>
#include <sys/fcntl.h>
#define off64_t off_t
#define fopen64 fopen
#define fseeko64 fseek
#define ftello64 ftell
#define ftruncate64 ftruncate
#elif defined(OS_LINUX)
#include <unistd.h>
#include <fcntl.h>
#endif
namespace hex::fs {
class File {
public:
enum class Mode
{
Read,
Write,
Create
};
explicit File(const std::fs::path &path, Mode mode) noexcept;
File() noexcept;
File(const File &) = delete;
File(File &&other) noexcept;
~File();
File &operator=(File &&other) noexcept;
[[nodiscard]] bool isValid() const {
return this->m_file != nullptr && fs::exists(this->m_path) && !fs::isDirectory(this->m_path);
}
void seek(u64 offset);
void close();
size_t readBuffer(u8 *buffer, size_t size);
std::vector<u8> readBytes(size_t numBytes = 0);
std::string readString(size_t numBytes = 0);
std::u8string readU8String(size_t numBytes = 0);
void write(const u8 *buffer, size_t size);
void write(const std::vector<u8> &bytes);
void write(const std::string &string);
void write(const std::u8string &string);
[[nodiscard]] size_t getSize() const;
void setSize(u64 size);
void flush();
bool remove();
auto getHandle() { return this->m_file; }
const std::fs::path &getPath() { return this->m_path; }
void disableBuffering();
std::optional<struct stat> getFileInfo();
private:
FILE *m_file;
std::fs::path m_path;
};
}

View File

@ -10,73 +10,10 @@
#include <nfd.hpp> #include <nfd.hpp>
namespace std::fs { #include <wolv/io/fs.hpp>
using namespace std::filesystem;
}
namespace hex::fs { namespace hex::fs {
[[maybe_unused]]
static inline bool exists(const std::fs::path &path) {
std::error_code error;
return std::filesystem::exists(path, error) && !error;
}
[[maybe_unused]]
static inline bool createDirectories(const std::fs::path &path) {
std::error_code error;
return std::filesystem::create_directories(path, error) && !error;
}
[[maybe_unused]]
static inline bool isRegularFile(const std::fs::path &path) {
std::error_code error;
return std::filesystem::is_regular_file(path, error) && !error;
}
[[maybe_unused]]
static inline bool copyFile(const std::fs::path &from, const std::fs::path &to, std::fs::copy_options = std::fs::copy_options::none) {
std::error_code error;
return std::filesystem::copy_file(from, to, error) && !error;
}
[[maybe_unused]]
static inline bool isDirectory(const std::fs::path &path) {
std::error_code error;
return std::filesystem::is_directory(path, error) && !error;
}
[[maybe_unused]]
static inline bool remove(const std::fs::path &path) {
std::error_code error;
return std::filesystem::remove(path, error) && !error;
}
[[maybe_unused]]
static inline bool removeAll(const std::fs::path &path) {
std::error_code error;
return std::filesystem::remove_all(path, error) && !error;
}
[[maybe_unused]]
static inline uintmax_t getFileSize(const std::fs::path &path) {
std::error_code error;
auto size = std::filesystem::file_size(path, error);
if (error) return 0;
else return size;
}
static inline bool isSubPath(const std::fs::path& base, const std::fs::path& destination) {
const auto relative = std::fs::relative(destination, base).u8string();
return relative.size() == 1 || (relative[0] != '.' && relative[1] != '.');
}
bool isPathWritable(const std::fs::path &path);
std::fs::path toShortPath(const std::fs::path &path);
enum class DialogMode { enum class DialogMode {
Open, Open,
Save, Save,
@ -107,7 +44,7 @@ namespace hex::fs {
END END
}; };
std::optional<std::fs::path> getExecutablePath(); bool isPathWritable(const std::fs::path &path);
std::vector<std::fs::path> getDefaultPaths(ImHexPath path, bool listNonExisting = false); std::vector<std::fs::path> getDefaultPaths(ImHexPath path, bool listNonExisting = false);

View File

@ -1,55 +0,0 @@
#pragma once
#include <hex.hpp>
#include <string>
#include <vector>
#if defined(OS_WINDOWS)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#define SOCKET_NONE INVALID_SOCKET
#else
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#define SOCKET_NONE -1
#endif
namespace hex {
class Socket {
public:
Socket() = default;
Socket(const Socket &) = delete;
Socket(Socket &&other) noexcept;
Socket(const std::string &address, u16 port);
~Socket();
void connect(const std::string &address, u16 port);
void disconnect();
[[nodiscard]] bool isConnected() const;
[[nodiscard]] std::string readString(size_t size = 0x1000) const;
[[nodiscard]] std::vector<u8> readBytes(size_t size = 0x1000) const;
void writeString(const std::string &string) const;
void writeBytes(const std::vector<u8> &bytes) const;
private:
bool m_connected = false;
#if defined(OS_WINDOWS)
SOCKET m_socket = SOCKET_NONE;
#else
int m_socket = SOCKET_NONE;
#endif
};
}

View File

@ -19,10 +19,6 @@
#include <variant> #include <variant>
#include <vector> #include <vector>
#define TOKEN_CONCAT_IMPL(x, y) x##y
#define TOKEN_CONCAT(x, y) TOKEN_CONCAT_IMPL(x, y)
#define ANONYMOUS_VARIABLE(prefix) TOKEN_CONCAT(prefix, __COUNTER__)
struct ImVec2; struct ImVec2;
namespace hex { namespace hex {
@ -116,11 +112,6 @@ namespace hex {
return i; return i;
} }
template<class... Ts>
struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
template<size_t Size> template<size_t Size>
struct SizeTypeImpl { }; struct SizeTypeImpl { };
@ -220,14 +211,6 @@ namespace hex {
std::string toEngineeringString(double value); std::string toEngineeringString(double value);
template<typename T>
std::vector<u8> toBytes(T value) {
std::vector<u8> bytes(sizeof(T));
std::memcpy(bytes.data(), &value, sizeof(T));
return bytes;
}
inline std::vector<u8> parseByteString(const std::string &string) { inline std::vector<u8> parseByteString(const std::string &string) {
auto byteString = std::string(string); auto byteString = std::string(string);
byteString.erase(std::remove(byteString.begin(), byteString.end(), ' '), byteString.end()); byteString.erase(std::remove(byteString.begin(), byteString.end(), ' '), byteString.end());
@ -327,89 +310,4 @@ namespace hex {
return string.substr(0, maxLength - 3) + "..."; return string.substr(0, maxLength - 3) + "...";
} }
namespace scope_guard {
#define SCOPE_GUARD ::hex::scope_guard::ScopeGuardOnExit() + [&]()
#define ON_SCOPE_EXIT [[maybe_unused]] auto ANONYMOUS_VARIABLE(SCOPE_EXIT_) = SCOPE_GUARD
template<class F>
class ScopeGuard {
private:
F m_func;
bool m_active;
public:
explicit constexpr ScopeGuard(F func) : m_func(std::move(func)), m_active(true) { }
~ScopeGuard() {
if (this->m_active) { this->m_func(); }
}
void release() { this->m_active = false; }
ScopeGuard(ScopeGuard &&other) noexcept : m_func(std::move(other.m_func)), m_active(other.m_active) {
other.cancel();
}
ScopeGuard &operator=(ScopeGuard &&) = delete;
};
enum class ScopeGuardOnExit
{
};
template<typename F>
constexpr ScopeGuard<F> operator+(ScopeGuardOnExit, F &&f) {
return ScopeGuard<F>(std::forward<F>(f));
}
}
namespace first_time_exec {
#define FIRST_TIME [[maybe_unused]] static auto ANONYMOUS_VARIABLE(FIRST_TIME_) = ::hex::first_time_exec::FirstTimeExecutor() + [&]()
template<class F>
class FirstTimeExecute {
public:
explicit constexpr FirstTimeExecute(F func) { func(); }
FirstTimeExecute &operator=(FirstTimeExecute &&) = delete;
};
enum class FirstTimeExecutor
{
};
template<typename F>
constexpr FirstTimeExecute<F> operator+(FirstTimeExecutor, F &&f) {
return FirstTimeExecute<F>(std::forward<F>(f));
}
}
namespace final_cleanup {
#define FINAL_CLEANUP [[maybe_unused]] static auto ANONYMOUS_VARIABLE(ON_EXIT_) = ::hex::final_cleanup::FinalCleanupExecutor() + [&]()
template<class F>
class FinalCleanupExecute {
F m_func;
public:
explicit constexpr FinalCleanupExecute(F func) : m_func(func) { }
constexpr ~FinalCleanupExecute() { this->m_func(); }
FinalCleanupExecute &operator=(FinalCleanupExecute &&) = delete;
};
enum class FinalCleanupExecutor
{
};
template<typename F>
constexpr FinalCleanupExecute<F> operator+(FinalCleanupExecutor, F &&f) {
return FinalCleanupExecute<F>(std::forward<F>(f));
}
}
} }

View File

@ -6,282 +6,21 @@
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <hex/helpers/literals.hpp> #include <hex/helpers/literals.hpp>
#include <wolv/io/buffered_reader.hpp>
namespace hex::prv { namespace hex::prv {
using namespace hex::literals; using namespace hex::literals;
class BufferedReader { inline void providerReaderFunction(Provider *provider, void *buffer, u64 address, size_t size) {
provider->read(address, buffer, size);
}
class ProviderReader : public wolv::io::BufferedReader<prv::Provider, providerReaderFunction> {
public: public:
explicit BufferedReader(Provider *provider, size_t bufferSize = 16_MiB) using BufferedReader::BufferedReader;
: m_provider(provider), m_bufferAddress(provider->getBaseAddress()), m_maxBufferSize(bufferSize),
m_startAddress(provider->getBaseAddress()), m_endAddress(provider->getBaseAddress() + provider->getActualSize() - 1LLU),
m_buffer(bufferSize) {
} ProviderReader(Provider *provider, size_t bufferSize = 0x100000) : BufferedReader(provider, provider->getActualSize(), bufferSize) { }
void seek(u64 address) {
this->m_startAddress = address;
}
void setEndAddress(u64 address) {
if (address >= this->m_provider->getActualSize())
address = this->m_provider->getActualSize() - 1;
this->m_endAddress = address;
}
[[nodiscard]] std::vector<u8> read(u64 address, size_t size) {
if (size > this->m_buffer.size()) {
std::vector<u8> result;
result.resize(size);
this->m_provider->read(address, result.data(), result.size());
return result;
}
this->updateBuffer(address, size);
auto result = &this->m_buffer[address - this->m_bufferAddress];
return { result, result + std::min(size, this->m_buffer.size()) };
}
[[nodiscard]] std::vector<u8> readReverse(u64 address, size_t size) {
if (size > this->m_buffer.size()) {
std::vector<u8> result;
result.resize(size);
this->m_provider->read(address, result.data(), result.size());
return result;
}
this->updateBuffer(address - std::min<u64>(address, this->m_buffer.size()), size);
auto result = &this->m_buffer[address - this->m_bufferAddress];
return { result, result + std::min(size, this->m_buffer.size()) };
}
class Iterator {
public:
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = u8;
using pointer = const value_type*;
using reference = const value_type&;
Iterator(BufferedReader *reader, u64 address) : m_reader(reader), m_address(address) {}
Iterator& operator++() {
this->m_address++;
return *this;
}
Iterator operator++(int) {
auto copy = *this;
this->m_address++;
return copy;
}
Iterator& operator--() {
this->m_address--;
return *this;
}
Iterator operator--(int) {
auto copy = *this;
this->m_address--;
return copy;
}
Iterator& operator+=(i64 offset) {
this->m_address += offset;
return *this;
}
Iterator& operator-=(i64 offset) {
this->m_address -= offset;
return *this;
}
value_type operator*() const {
return (*this)[0];
}
[[nodiscard]] u64 getAddress() const {
return this->m_address;
}
void setAddress(u64 address) {
this->m_address = address;
}
difference_type operator-(const Iterator &other) const {
return this->m_address - other.m_address;
}
Iterator operator+(i64 offset) const {
return { this->m_reader, this->m_address + offset };
}
value_type operator[](i64 offset) const {
auto result = this->m_reader->read(this->m_address + offset, 1);
if (result.empty())
return 0x00;
return result[0];
}
friend bool operator== (const Iterator& left, const Iterator& right) { return left.m_address == right.m_address; };
friend bool operator!= (const Iterator& left, const Iterator& right) { return left.m_address != right.m_address; };
friend bool operator> (const Iterator& left, const Iterator& right) { return left.m_address > right.m_address; };
friend bool operator< (const Iterator& left, const Iterator& right) { return left.m_address < right.m_address; };
friend bool operator>= (const Iterator& left, const Iterator& right) { return left.m_address >= right.m_address; };
friend bool operator<= (const Iterator& left, const Iterator& right) { return left.m_address <= right.m_address; };
private:
BufferedReader *m_reader;
u64 m_address;
};
class ReverseIterator {
public:
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = u8;
using pointer = const value_type*;
using reference = const value_type&;
ReverseIterator(BufferedReader *reader, u64 address) : m_reader(reader), m_address(address) {}
ReverseIterator& operator++() {
this->m_address--;
return *this;
}
ReverseIterator operator++(int) {
auto copy = *this;
this->m_address--;
return copy;
}
ReverseIterator& operator--() {
this->m_address++;
return *this;
}
ReverseIterator operator--(int) {
auto copy = *this;
this->m_address++;
return copy;
}
ReverseIterator& operator+=(i64 offset) {
this->m_address -= offset;
return *this;
}
ReverseIterator& operator-=(i64 offset) {
this->m_address += offset;
return *this;
}
value_type operator*() const {
return (*this)[0];
}
[[nodiscard]] u64 getAddress() const {
return this->m_address;
}
void setAddress(u64 address) {
this->m_address = address;
}
difference_type operator-(const ReverseIterator &other) const {
return other.m_address - this->m_address;
}
ReverseIterator operator+(i64 offset) const {
return { this->m_reader, this->m_address - offset };
}
value_type operator[](i64 offset) const {
auto result = this->m_reader->readReverse(this->m_address - offset, 1);
if (result.empty())
return 0x00;
return result[0];
}
friend bool operator== (const ReverseIterator& left, const ReverseIterator& right) { return left.m_address == right.m_address; };
friend bool operator!= (const ReverseIterator& left, const ReverseIterator& right) { return left.m_address != right.m_address; };
friend bool operator> (const ReverseIterator& left, const ReverseIterator& right) { return left.m_address > right.m_address; };
friend bool operator< (const ReverseIterator& left, const ReverseIterator& right) { return left.m_address < right.m_address; };
friend bool operator>= (const ReverseIterator& left, const ReverseIterator& right) { return left.m_address >= right.m_address; };
friend bool operator<= (const ReverseIterator& left, const ReverseIterator& right) { return left.m_address <= right.m_address; };
private:
BufferedReader *m_reader;
u64 m_address = 0x00;
};
Iterator begin() {
return { this, this->m_startAddress };
}
Iterator end() {
return { this, this->m_endAddress + 1 };
}
ReverseIterator rbegin() {
return { this, this->m_startAddress };
}
ReverseIterator rend() {
return { this, 0 };
}
private:
void updateBuffer(u64 address, size_t size) {
if (address > this->m_endAddress)
return;
if (!this->m_bufferValid || address < this->m_bufferAddress || address + size > (this->m_bufferAddress + this->m_buffer.size())) {
const auto remainingBytes = (this->m_endAddress - address) + 1;
if (remainingBytes < this->m_maxBufferSize)
this->m_buffer.resize(remainingBytes);
else
this->m_buffer.resize(this->m_maxBufferSize);
this->m_provider->read(address, this->m_buffer.data(), this->m_buffer.size());
this->m_bufferAddress = address;
this->m_bufferValid = true;
}
}
private:
Provider *m_provider;
u64 m_bufferAddress = 0x00;
size_t m_maxBufferSize;
bool m_bufferValid = false;
u64 m_startAddress = 0x00, m_endAddress;
std::vector<u8> m_buffer;
}; };
} }

View File

@ -1,17 +1,17 @@
#include <hex/api/content_registry.hpp> #include <hex/api/content_registry.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <hex/ui/view.hpp> #include <hex/ui/view.hpp>
#include <hex/data_processor/node.hpp>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <hex/data_processor/node.hpp> #include <wolv/io/file.hpp>
namespace hex { namespace hex {
@ -22,7 +22,7 @@ namespace hex {
void load() { void load() {
bool loaded = false; bool loaded = false;
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) { for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
fs::File file(dir / SettingsFile, fs::File::Mode::Read); wolv::io::File file(dir / SettingsFile, wolv::io::File::Mode::Read);
if (file.isValid()) { if (file.isValid()) {
getSettingsData() = nlohmann::json::parse(file.readString()); getSettingsData() = nlohmann::json::parse(file.readString());
@ -37,7 +37,7 @@ namespace hex {
void store() { void store() {
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) { for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
fs::File file(dir / SettingsFile, fs::File::Mode::Create); wolv::io::File file(dir / SettingsFile, wolv::io::File::Mode::Create);
if (file.isValid()) { if (file.isValid()) {
file.write(getSettingsData().dump(4)); file.write(getSettingsData().dump(4));
@ -48,7 +48,7 @@ namespace hex {
void clear() { void clear() {
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) { for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
hex::fs::remove(dir / SettingsFile); wolv::io::fs::remove(dir / SettingsFile);
} }
} }

View File

@ -145,7 +145,7 @@ namespace hex {
std::vector<Plugin> PluginManager::s_plugins; std::vector<Plugin> PluginManager::s_plugins;
bool PluginManager::load(const std::fs::path &pluginFolder) { bool PluginManager::load(const std::fs::path &pluginFolder) {
if (!fs::exists(pluginFolder)) if (!wolv::io::fs::exists(pluginFolder))
return false; return false;
PluginManager::s_pluginFolder = pluginFolder; PluginManager::s_pluginFolder = pluginFolder;

View File

@ -6,6 +6,9 @@
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <wolv/utils/guards.hpp>
#include <wolv/io/fs.hpp>
namespace hex { namespace hex {
constexpr static auto MetadataHeaderMagic = "HEX"; constexpr static auto MetadataHeaderMagic = "HEX";
@ -24,7 +27,7 @@ namespace hex {
ProjectFile::s_currProjectPath = originalPath; ProjectFile::s_currProjectPath = originalPath;
}; };
if (!fs::exists(filePath) || !fs::isRegularFile(filePath)) if (!wolv::io::fs::exists(filePath) || !wolv::io::fs::isRegularFile(filePath))
return false; return false;
if (filePath.extension() != ".hexproj") if (filePath.extension() != ".hexproj")
return false; return false;

View File

@ -86,7 +86,7 @@ namespace hex::dp {
return *reinterpret_cast<long double *>(outputData.data()); return *reinterpret_cast<long double *>(outputData.data());
} }
void Node::setBufferOnOutput(u32 index, const std::vector<u8> &data) { void Node::setBufferOnOutput(u32 index, std::span<const u8> data) {
if (index >= this->getAttributes().size()) if (index >= this->getAttributes().size())
throwNodeError("Attribute index out of bounds!"); throwNodeError("Attribute index out of bounds!");
@ -95,7 +95,7 @@ namespace hex::dp {
if (attribute.getIOType() != Attribute::IOType::Out) if (attribute.getIOType() != Attribute::IOType::Out)
throwNodeError("Tried to set output data of an input attribute!"); throwNodeError("Tried to set output data of an input attribute!");
attribute.getOutputData() = data; attribute.getOutputData() = { data.begin(), data.end() };
} }
void Node::setIntegerOnOutput(u32 index, i128 integer) { void Node::setIntegerOnOutput(u32 index, i128 integer) {

View File

@ -1,8 +1,8 @@
#include <hex/helpers/crypto.hpp> #include <hex/helpers/crypto.hpp>
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/concepts.hpp> #include <wolv/utils/guards.hpp>
#include <mbedtls/version.h> #include <mbedtls/version.h>
#include <mbedtls/base64.h> #include <mbedtls/base64.h>
@ -11,13 +11,10 @@
#include <mbedtls/sha1.h> #include <mbedtls/sha1.h>
#include <mbedtls/sha256.h> #include <mbedtls/sha256.h>
#include <mbedtls/sha512.h> #include <mbedtls/sha512.h>
#include <mbedtls/aes.h>
#include <mbedtls/cipher.h> #include <mbedtls/cipher.h>
#include <array> #include <array>
#include <span>
#include <functional> #include <functional>
#include <algorithm>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <bit> #include <bit>

View File

@ -1,11 +1,12 @@
#include <hex/helpers/encoding_file.hpp> #include <hex/helpers/encoding_file.hpp>
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <wolv/io/file.hpp>
namespace hex { namespace hex {
EncodingFile::EncodingFile(Type type, const std::fs::path &path) { EncodingFile::EncodingFile(Type type, const std::fs::path &path) {
auto file = fs::File(path, fs::File::Mode::Read); auto file = wolv::io::File(path, wolv::io::File::Mode::Read);
switch (type) { switch (type) {
case Type::Thingy: case Type::Thingy:
parseThingyFile(file); parseThingyFile(file);
@ -31,7 +32,7 @@ namespace hex {
return { ".", 1 }; return { ".", 1 };
} }
void EncodingFile::parseThingyFile(fs::File &file) { void EncodingFile::parseThingyFile(wolv::io::File &file) {
for (const auto &line : splitString(file.readString(), "\n")) { for (const auto &line : splitString(file.readString(), "\n")) {
std::string from, to; std::string from, to;

View File

@ -1,185 +0,0 @@
#include <hex/helpers/file.hpp>
#include <hex/helpers/utils.hpp>
#include <unistd.h>
namespace hex::fs {
File::File(const std::fs::path &path, Mode mode) noexcept : m_path(path) {
#if defined(OS_WINDOWS)
if (mode == File::Mode::Read)
this->m_file = _wfopen(path.c_str(), L"rb");
else if (mode == File::Mode::Write)
this->m_file = _wfopen(path.c_str(), L"r+b");
if (mode == File::Mode::Create || (mode == File::Mode::Write && this->m_file == nullptr))
this->m_file = _wfopen(path.c_str(), L"w+b");
#else
if (mode == File::Mode::Read)
this->m_file = fopen64(hex::toUTF8String(path).c_str(), "rb");
else if (mode == File::Mode::Write)
this->m_file = fopen64(hex::toUTF8String(path).c_str(), "r+b");
if (mode == File::Mode::Create || (mode == File::Mode::Write && this->m_file == nullptr))
this->m_file = fopen64(hex::toUTF8String(path).c_str(), "w+b");
#endif
}
File::File() noexcept {
this->m_file = nullptr;
}
File::File(File &&other) noexcept {
this->m_file = other.m_file;
other.m_file = nullptr;
}
File::~File() {
this->close();
}
File &File::operator=(File &&other) noexcept {
this->m_file = other.m_file;
other.m_file = nullptr;
this->m_path = std::move(other.m_path);
return *this;
}
void File::seek(u64 offset) {
fseeko64(this->m_file, offset, SEEK_SET);
}
void File::close() {
if (isValid()) {
std::fclose(this->m_file);
this->m_file = nullptr;
}
}
size_t File::readBuffer(u8 *buffer, size_t size) {
if (!isValid()) return 0;
return fread(buffer, size, 1, this->m_file);
}
std::vector<u8> File::readBytes(size_t numBytes) {
if (!isValid()) return {};
auto size = numBytes == 0 ? getSize() : numBytes;
if (size == 0) return {};
std::vector<u8> bytes(size);
auto bytesRead = fread(bytes.data(), 1, bytes.size(), this->m_file);
bytes.resize(bytesRead);
return bytes;
}
std::string File::readString(size_t numBytes) {
if (!isValid()) return {};
if (getSize() == 0) return {};
auto bytes = readBytes(numBytes);
if (bytes.empty())
return "";
auto cString = reinterpret_cast<const char *>(bytes.data());
return { cString, hex::strnlen(cString, bytes.size()) };
}
std::u8string File::readU8String(size_t numBytes) {
if (!isValid()) return {};
if (getSize() == 0) return {};
auto bytes = readBytes(numBytes);
if (bytes.empty())
return u8"";
auto cString = reinterpret_cast<const char8_t *>(bytes.data());
return { cString, hex::strnlen(reinterpret_cast<const char*>(bytes.data()), bytes.size()) };
}
void File::write(const u8 *buffer, size_t size) {
if (!isValid()) return;
std::fwrite(buffer, size, 1, this->m_file);
}
void File::write(const std::vector<u8> &bytes) {
if (!isValid()) return;
std::fwrite(bytes.data(), 1, bytes.size(), this->m_file);
}
void File::write(const std::string &string) {
if (!isValid()) return;
std::fwrite(string.data(), string.size(), 1, this->m_file);
}
void File::write(const std::u8string &string) {
if (!isValid()) return;
std::fwrite(string.data(), string.size(), 1, this->m_file);
}
size_t File::getSize() const {
if (!isValid()) return 0;
auto startPos = ftello64(this->m_file);
fseeko64(this->m_file, 0, SEEK_END);
auto size = ftello64(this->m_file);
fseeko64(this->m_file, startPos, SEEK_SET);
if (size < 0)
return 0;
return size;
}
void File::setSize(u64 size) {
if (!isValid()) return;
auto result = ftruncate64(fileno(this->m_file), size);
hex::unused(result);
}
void File::flush() {
std::fflush(this->m_file);
}
bool File::remove() {
this->close();
return std::remove(hex::toUTF8String(this->m_path).c_str()) == 0;
}
void File::disableBuffering() {
if (!isValid()) return;
std::setvbuf(this->m_file, nullptr, _IONBF, 0);
}
std::optional<struct stat> File::getFileInfo() {
struct stat fileInfo = { };
#if defined(OS_WINDOWS)
if (wstat(this->m_path.c_str(), &fileInfo) != 0)
return std::nullopt;
#else
if (stat(hex::toUTF8String(this->m_path).c_str(), &fileInfo) != 0)
return std::nullopt;
#endif
return fileInfo;
}
}

View File

@ -3,11 +3,6 @@
#include <hex/api/content_registry.hpp> #include <hex/api/content_registry.hpp>
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <hex/helpers/fs_macos.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/intrinsics.hpp>
#include <hex/helpers/utils.hpp>
#include <xdg.hpp> #include <xdg.hpp>
#if defined(OS_WINDOWS) #if defined(OS_WINDOWS)
@ -21,61 +16,10 @@
#include <algorithm> #include <algorithm>
#include <filesystem> #include <filesystem>
#include <wolv/io/file.hpp>
namespace hex::fs { namespace hex::fs {
std::optional<std::fs::path> getExecutablePath() {
#if defined(OS_WINDOWS)
std::wstring exePath(MAX_PATH, '\0');
if (GetModuleFileNameW(nullptr, exePath.data(), exePath.length()) == 0)
return std::nullopt;
hex::trim(exePath);
return exePath;
#elif defined(OS_LINUX)
std::string exePath(PATH_MAX, '\0');
if (readlink("/proc/self/exe", exePath.data(), PATH_MAX) < 0)
return std::nullopt;
hex::trim(exePath);
return exePath;
#elif defined(OS_MACOS)
std::string exePath;
{
auto string = getMacExecutableDirectoryPath();
exePath = string;
macFree(string);
}
hex::trim(exePath);
return exePath;
#else
return std::nullopt;
#endif
}
bool isPathWritable(const std::fs::path &path) {
constexpr static auto TestFileName = "__imhex__tmp__";
{
File file(path / TestFileName, File::Mode::Read);
if (file.isValid()) {
if (!file.remove())
return false;
}
}
File file(path / TestFileName, File::Mode::Create);
bool result = file.isValid();
if (!file.remove())
return false;
return result;
}
static std::function<void()> s_fileBrowserErrorCallback; static std::function<void()> s_fileBrowserErrorCallback;
void setFileBrowserErrorCallback(const std::function<void()> &callback) { void setFileBrowserErrorCallback(const std::function<void()> &callback) {
s_fileBrowserErrorCallback = callback; s_fileBrowserErrorCallback = callback;
@ -171,7 +115,7 @@ namespace hex::fs {
#else #else
if (auto executablePath = fs::getExecutablePath(); executablePath.has_value()) if (auto executablePath = wolv::io::fs::getExecutablePath(); executablePath.has_value())
paths.push_back(executablePath->parent_path()); paths.push_back(executablePath->parent_path());
#endif #endif
@ -281,13 +225,31 @@ namespace hex::fs {
if (!listNonExisting) { if (!listNonExisting) {
result.erase(std::remove_if(result.begin(), result.end(), [](const auto &path) { result.erase(std::remove_if(result.begin(), result.end(), [](const auto &path) {
return !fs::isDirectory(path); return !wolv::io::fs::isDirectory(path);
}), result.end()); }), result.end());
} }
return result; return result;
} }
bool isPathWritable(const std::fs::path &path) {
constexpr static auto TestFileName = "__imhex__tmp__";
{
wolv::io::File file(path / TestFileName, wolv::io::File::Mode::Read);
if (file.isValid()) {
if (!file.remove())
return false;
}
}
wolv::io::File file(path / TestFileName, wolv::io::File::Mode::Create);
bool result = file.isValid();
if (!file.remove())
return false;
return result;
}
std::fs::path toShortPath(const std::fs::path &path) { std::fs::path toShortPath(const std::fs::path &path) {
#if defined(OS_WINDOWS) #if defined(OS_WINDOWS)
size_t size = GetShortPathNameW(path.c_str(), nullptr, 0); size_t size = GetShortPathNameW(path.c_str(), nullptr, 0);

View File

@ -1,13 +1,12 @@
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#include <iostream> #include <wolv/io/file.hpp>
namespace hex::log { namespace hex::log {
static fs::File g_loggerFile; static wolv::io::File g_loggerFile;
FILE *getDestination() { FILE *getDestination() {
if (g_loggerFile.isValid()) if (g_loggerFile.isValid())
@ -24,8 +23,8 @@ namespace hex::log {
if (g_loggerFile.isValid()) return; if (g_loggerFile.isValid()) return;
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Logs, true)) { for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Logs, true)) {
fs::createDirectories(path); wolv::io::fs::createDirectories(path);
g_loggerFile = fs::File(path / hex::format("{0:%Y%m%d_%H%M%S}.log", fmt::localtime(std::chrono::system_clock::now())), fs::File::Mode::Create); g_loggerFile = wolv::io::File(path / hex::format("{0:%Y%m%d_%H%M%S}.log", fmt::localtime(std::chrono::system_clock::now())), wolv::io::File::Mode::Create);
g_loggerFile.disableBuffering(); g_loggerFile.disableBuffering();
if (g_loggerFile.isValid()) break; if (g_loggerFile.isValid()) break;

View File

@ -3,6 +3,8 @@
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <wolv/utils/guards.hpp>
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <filesystem> #include <filesystem>
@ -27,7 +29,7 @@ namespace hex::magic {
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Magic)) { for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Magic)) {
for (const auto &entry : std::fs::directory_iterator(dir, error)) { for (const auto &entry : std::fs::directory_iterator(dir, error)) {
if (entry.is_regular_file() && ((sourceFiles && entry.path().extension().empty()) || (!sourceFiles && entry.path().extension() == ".mgc"))) { if (entry.is_regular_file() && ((sourceFiles && entry.path().extension().empty()) || (!sourceFiles && entry.path().extension() == ".mgc"))) {
magicFiles += hex::toUTF8String(fs::toShortPath(entry.path())) + MAGIC_PATH_SEPARATOR; magicFiles += hex::toUTF8String(wolv::io::fs::toShortPath(entry.path())) + MAGIC_PATH_SEPARATOR;
} }
} }
} }

View File

@ -1,7 +1,6 @@
#include <hex/helpers/net.hpp> #include <hex/helpers/net.hpp>
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <hex/api/content_registry.hpp> #include <hex/api/content_registry.hpp>
@ -11,15 +10,18 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <wolv/io/file.hpp>
#include <wolv/utils/guards.hpp>
namespace hex { namespace hex {
Net::Net() { Net::Net() {
FIRST_TIME { AT_FIRST_TIME {
curl_global_sslset(CURLSSLBACKEND_MBEDTLS, nullptr, nullptr); curl_global_sslset(CURLSSLBACKEND_MBEDTLS, nullptr, nullptr);
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
}; };
FINAL_CLEANUP { AT_FINAL_CLEANUP {
curl_global_cleanup(); curl_global_cleanup();
}; };
@ -202,7 +204,7 @@ namespace hex {
ON_SCOPE_EXIT { this->m_transmissionActive.unlock(); }; ON_SCOPE_EXIT { this->m_transmissionActive.unlock(); };
fs::File file(filePath, fs::File::Mode::Read); wolv::io::File file(filePath, wolv::io::File::Mode::Read);
if (!file.isValid()) if (!file.isValid())
return Response<std::string> { 400, {} }; return Response<std::string> { 400, {} };
@ -251,7 +253,7 @@ namespace hex {
ON_SCOPE_EXIT { this->m_transmissionActive.unlock(); }; ON_SCOPE_EXIT { this->m_transmissionActive.unlock(); };
fs::File file(filePath, fs::File::Mode::Create); wolv::io::File file(filePath, wolv::io::File::Mode::Create);
if (!file.isValid()) if (!file.isValid())
return Response<void> { 400 }; return Response<void> { 400 };

View File

@ -3,6 +3,8 @@
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::gl { namespace hex::gl {
Shader::Shader(std::string_view vertexSource, std::string_view fragmentSource) { Shader::Shader(std::string_view vertexSource, std::string_view fragmentSource) {

View File

@ -1,104 +0,0 @@
#include <hex/helpers/socket.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/logger.hpp>
namespace hex {
Socket::Socket(const std::string &address, u16 port) {
#if defined(OS_WINDOWS)
FIRST_TIME {
WSAData wsa;
WSAStartup(MAKEWORD(2, 2), &wsa);
};
FINAL_CLEANUP {
WSACleanup();
};
#endif
this->connect(address, port);
}
Socket::Socket(Socket &&other) noexcept {
this->m_socket = other.m_socket;
this->m_connected = other.m_connected;
other.m_socket = SOCKET_NONE;
}
Socket::~Socket() {
this->disconnect();
}
void Socket::writeBytes(const std::vector<u8> &bytes) const {
if (!this->isConnected()) return;
::send(this->m_socket, reinterpret_cast<const char *>(bytes.data()), bytes.size(), 0);
}
void Socket::writeString(const std::string &string) const {
if (!this->isConnected()) return;
::send(this->m_socket, string.c_str(), string.length(), 0);
}
std::vector<u8> Socket::readBytes(size_t size) const {
std::vector<u8> data;
data.resize(size);
auto receivedSize = ::recv(this->m_socket, reinterpret_cast<char *>(data.data()), size, 0);
if (receivedSize < 0)
return {};
data.resize(receivedSize);
return data;
}
std::string Socket::readString(size_t size) const {
auto bytes = readBytes(size);
std::string result;
std::copy(bytes.begin(), bytes.end(), std::back_inserter(result));
return result;
}
bool Socket::isConnected() const {
return this->m_connected;
}
void Socket::connect(const std::string &address, u16 port) {
this->m_socket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (this->m_socket == SOCKET_NONE)
return;
sockaddr_in client = { };
client.sin_family = AF_INET;
client.sin_port = htons(port);
#if defined(OS_WINDOWS)
client.sin_addr.S_un.S_addr = ::inet_addr(address.c_str());
#else
client.sin_addr.s_addr = ::inet_addr(address.c_str());
#endif
this->m_connected = ::connect(this->m_socket, reinterpret_cast<sockaddr *>(&client), sizeof(client)) == 0;
}
void Socket::disconnect() {
if (this->m_socket != SOCKET_NONE) {
#if defined(OS_WINDOWS)
closesocket(this->m_socket);
#else
close(this->m_socket);
#endif
}
this->m_connected = false;
}
}

View File

@ -1,8 +1,9 @@
#include <hex/helpers/tar.hpp> #include <hex/helpers/tar.hpp>
#include <hex/helpers/literals.hpp> #include <hex/helpers/literals.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <wolv/io/file.hpp>
namespace hex { namespace hex {
using namespace hex::literals; using namespace hex::literals;
@ -12,11 +13,11 @@ namespace hex {
// Explicitly create file so a short path gets generated // Explicitly create file so a short path gets generated
if (mode == Mode::Create) { if (mode == Mode::Create) {
fs::File file(path, fs::File::Mode::Create); wolv::io::File file(path, wolv::io::File::Mode::Create);
file.flush(); file.flush();
} }
auto shortPath = hex::fs::toShortPath(path); auto shortPath = wolv::io::fs::toShortPath(path);
if (mode == Tar::Mode::Read) if (mode == Tar::Mode::Read)
error = mtar_open(&this->m_ctx, shortPath.string().c_str(), "r"); error = mtar_open(&this->m_ctx, shortPath.string().c_str(), "r");
else if (mode == Tar::Mode::Write) else if (mode == Tar::Mode::Write)
@ -58,7 +59,7 @@ namespace hex {
mtar_header_t header; mtar_header_t header;
while (mtar_read_header(&this->m_ctx, &header) != MTAR_ENULLRECORD) { while (mtar_read_header(&this->m_ctx, &header) != MTAR_ENULLRECORD) {
std::fs::path path = header.name; std::fs::path path = header.name;
if (header.name != PaxHeaderName && fs::isSubPath(basePath, path)) { if (header.name != PaxHeaderName && wolv::io::fs::isSubPath(basePath, path)) {
result.emplace_back(header.name); result.emplace_back(header.name);
} }
@ -132,7 +133,7 @@ namespace hex {
static void writeFile(mtar_t *ctx, mtar_header_t *header, const std::fs::path &path) { static void writeFile(mtar_t *ctx, mtar_header_t *header, const std::fs::path &path) {
constexpr static u64 BufferSize = 1_MiB; constexpr static u64 BufferSize = 1_MiB;
fs::File outputFile(path, fs::File::Mode::Create); wolv::io::File outputFile(path, wolv::io::File::Mode::Create);
std::vector<u8> buffer; std::vector<u8> buffer;
for (u64 offset = 0; offset < header->size; offset += BufferSize) { for (u64 offset = 0; offset < header->size; offset += BufferSize) {

View File

@ -17,6 +17,8 @@
#include <fonts/fontawesome_font.h> #include <fonts/fontawesome_font.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <wolv/utils/guards.hpp>
#include <unistd.h> #include <unistd.h>
#include <chrono> #include <chrono>

View File

@ -11,7 +11,6 @@
#include <hex/helpers/net.hpp> #include <hex/helpers/net.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <hex/helpers/file.hpp>
#include <fonts/fontawesome_font.h> #include <fonts/fontawesome_font.h>
#include <fonts/codicons_font.h> #include <fonts/codicons_font.h>
@ -23,6 +22,9 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <wolv/io/fs.hpp>
#include <wolv/io/file.hpp>
namespace hex::init { namespace hex::init {
using namespace std::literals::string_literals; using namespace std::literals::string_literals;
@ -78,7 +80,7 @@ namespace hex::init {
// If a custom certificate was found, use it, otherwise use the one from the romfs // If a custom certificate was found, use it, otherwise use the one from the romfs
if (!caCertPath.empty()) if (!caCertPath.empty())
Net::setCACert(fs::File(caCertPath, fs::File::Mode::Read).readString()); Net::setCACert(wolv::io::File(caCertPath, wolv::io::File::Mode::Read).readString());
else else
Net::setCACert(std::string(romfs::get(CaCertPath).string())); Net::setCACert(std::string(romfs::get(CaCertPath).string()));
@ -94,7 +96,7 @@ namespace hex::init {
for (u32 path = 0; path < u32(fs::ImHexPath::END); path++) { for (u32 path = 0; path < u32(fs::ImHexPath::END); path++) {
for (auto &folder : fs::getDefaultPaths(static_cast<fs::ImHexPath>(path), true)) { for (auto &folder : fs::getDefaultPaths(static_cast<fs::ImHexPath>(path), true)) {
try { try {
fs::createDirectories(folder); wolv::io::fs::createDirectories(folder);
} catch (...) { } catch (...) {
log::error("Failed to create folder {}!", hex::toUTF8String(folder)); log::error("Failed to create folder {}!", hex::toUTF8String(folder));
result = false; result = false;
@ -300,7 +302,7 @@ namespace hex::init {
return false; return false;
} }
const auto shouldLoadPlugin = [executablePath = hex::fs::getExecutablePath()](const Plugin &plugin) { const auto shouldLoadPlugin = [executablePath = wolv::io::fs::getExecutablePath()](const Plugin &plugin) {
// In debug builds, ignore all plugins that are not part of the executable directory // In debug builds, ignore all plugins that are not part of the executable directory
#if !defined(DEBUG) #if !defined(DEBUG)
return true; return true;

View File

@ -1,6 +1,5 @@
#include <hex.hpp> #include <hex.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include "window.hpp" #include "window.hpp"
@ -10,16 +9,19 @@
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <wolv/io/fs.hpp>
#include <wolv/utils/guards.hpp>
int main(int argc, char **argv, char **envp) { int main(int argc, char **argv, char **envp) {
using namespace hex; using namespace hex;
ImHexApi::System::impl::setProgramArguments(argc, argv, envp); ImHexApi::System::impl::setProgramArguments(argc, argv, envp);
// Check if ImHex is installed in portable mode // Check if ImHex is installed in portable mode
{ {
if (const auto executablePath = fs::getExecutablePath(); executablePath.has_value()) { if (const auto executablePath = wolv::io::fs::getExecutablePath(); executablePath.has_value()) {
const auto flagFile = executablePath->parent_path() / "PORTABLE"; const auto flagFile = executablePath->parent_path() / "PORTABLE";
if (fs::exists(flagFile) && fs::isRegularFile(flagFile)) if (wolv::io::fs::exists(flagFile) && wolv::io::fs::isRegularFile(flagFile))
ImHexApi::System::impl::setPortableVersion(true); ImHexApi::System::impl::setPortableVersion(true);
} }
} }

View File

@ -443,7 +443,7 @@ namespace hex {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextUnformatted(hex::toUTF8String(filePath).c_str()); ImGui::TextUnformatted(hex::toUTF8String(filePath).c_str());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextUnformatted(fs::exists(filePath) ? ICON_VS_CHECK : ICON_VS_CLOSE); ImGui::TextUnformatted(wolv::io::fs::exists(filePath) ? ICON_VS_CHECK : ICON_VS_CLOSE);
} }
ImGui::EndTable(); ImGui::EndTable();
} }
@ -867,7 +867,7 @@ namespace hex {
} }
} }
if (!this->m_imguiSettingsPath.empty() && fs::exists(this->m_imguiSettingsPath)) if (!this->m_imguiSettingsPath.empty() && wolv::io::fs::exists(this->m_imguiSettingsPath))
ImGui::LoadIniSettingsFromDisk(hex::toUTF8String(this->m_imguiSettingsPath).c_str()); ImGui::LoadIniSettingsFromDisk(hex::toUTF8String(this->m_imguiSettingsPath).c_str());
} }

View File

@ -338,7 +338,7 @@ namespace hex {
this->m_fileSize = provider->getSize(); this->m_fileSize = provider->getSize();
// Get a file reader // Get a file reader
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
std::vector<u8> bytes = reader.read(this->m_startAddress, this->m_endAddress - this->m_startAddress); std::vector<u8> bytes = reader.read(this->m_startAddress, this->m_endAddress - this->m_startAddress);
this->processImpl(bytes); this->processImpl(bytes);
@ -572,7 +572,7 @@ namespace hex {
this->m_endAddress = endAddress; this->m_endAddress = endAddress;
// Get a file reader // Get a file reader
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
std::vector<u8> bytes = reader.read(this->m_startAddress, this->m_endAddress - this->m_startAddress); std::vector<u8> bytes = reader.read(this->m_startAddress, this->m_endAddress - this->m_startAddress);
this->processImpl(bytes); this->processImpl(bytes);
@ -685,7 +685,7 @@ namespace hex {
this->m_fileSize = provider->getSize(); this->m_fileSize = provider->getSize();
// Get a file reader // Get a file reader
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
std::vector<u8> bytes = reader.read(this->m_startAddress, this->m_endAddress - this->m_startAddress); std::vector<u8> bytes = reader.read(this->m_startAddress, this->m_endAddress - this->m_startAddress);
this->processImpl(bytes); this->processImpl(bytes);

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <hex/helpers/file.hpp>
#include <wolv/io/file.hpp>
#include <string_view> #include <string_view>
@ -56,7 +57,7 @@ namespace hex::plugin::builtin {
protected: protected:
std::fs::path m_path; std::fs::path m_path;
fs::File m_file; wolv::io::File m_file;
size_t m_fileSize = 0; size_t m_fileSize = 0;
std::optional<struct stat> m_fileStats; std::optional<struct stat> m_fileStats;

View File

@ -1,8 +1,9 @@
#pragma once #pragma once
#include <hex/helpers/socket.hpp>
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <wolv/utils/socket.hpp>
#include <array> #include <array>
#include <mutex> #include <mutex>
#include <string_view> #include <string_view>
@ -53,14 +54,14 @@ namespace hex::plugin::builtin {
std::variant<std::string, i128> queryInformation(const std::string &category, const std::string &argument) override; std::variant<std::string, i128> queryInformation(const std::string &category, const std::string &argument) override;
protected: protected:
hex::Socket m_socket; wolv::util::Socket m_socket;
std::string m_ipAddress; std::string m_ipAddress;
int m_port = 0; int m_port = 0;
u64 m_size = 0; u64 m_size = 0;
constexpr static size_t CacheLineSize = 0x1000; constexpr static size_t CacheLineSize = 0x10;
struct CacheLine { struct CacheLine {
u64 address; u64 address;
@ -69,6 +70,7 @@ namespace hex::plugin::builtin {
}; };
std::list<CacheLine> m_cache; std::list<CacheLine> m_cache;
std::atomic<bool> m_resetCache = false;
std::thread m_cacheUpdateThread; std::thread m_cacheUpdateThread;
std::mutex m_cacheLock; std::mutex m_cacheLock;

View File

@ -16,7 +16,7 @@ namespace hex::plugin::builtin {
result += start; result += start;
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
reader.seek(offset); reader.seek(offset);
reader.setEndAddress(offset + size - 1); reader.setEndAddress(offset + size - 1);
@ -107,7 +107,7 @@ namespace hex::plugin::builtin {
result += HeaderLine; result += HeaderLine;
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
reader.seek(offset); reader.seek(offset);
reader.setEndAddress((offset + size) - 1); reader.setEndAddress((offset + size) - 1);
@ -158,7 +158,7 @@ namespace hex::plugin::builtin {
" <code>\n" " <code>\n"
" <span class=\"offsetheader\">Hex View&nbsp&nbsp00 01 02 03 04 05 06 07&nbsp 08 09 0A 0B 0C 0D 0E 0F</span>"; " <span class=\"offsetheader\">Hex View&nbsp&nbsp00 01 02 03 04 05 06 07&nbsp 08 09 0A 0B 0C 0D 0E 0F</span>";
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
reader.seek(offset); reader.seek(offset);
reader.setEndAddress((offset + size) - 1); reader.setEndAddress((offset + size) - 1);

View File

@ -21,6 +21,9 @@
#include <implot.h> #include <implot.h>
#include <hex/ui/imgui_imhex_extensions.h> #include <hex/ui/imgui_imhex_extensions.h>
#include <wolv/utils/core.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
class NodeNullptr : public dp::Node { class NodeNullptr : public dp::Node {
@ -167,10 +170,10 @@ namespace hex::plugin::builtin {
} }
void process() override { void process() override {
this->setBufferOnOutput(0, hex::toBytes<u8>(u8(this->m_color.Value.x * 0xFF))); this->setBufferOnOutput(0, wolv::util::toBytes<u8>(u8(this->m_color.Value.x * 0xFF)));
this->setBufferOnOutput(1, hex::toBytes<u8>(u8(this->m_color.Value.y * 0xFF))); this->setBufferOnOutput(1, wolv::util::toBytes<u8>(u8(this->m_color.Value.y * 0xFF)));
this->setBufferOnOutput(2, hex::toBytes<u8>(u8(this->m_color.Value.z * 0xFF))); this->setBufferOnOutput(2, wolv::util::toBytes<u8>(u8(this->m_color.Value.z * 0xFF)));
this->setBufferOnOutput(3, hex::toBytes<u8>(u8(this->m_color.Value.w * 0xFF))); this->setBufferOnOutput(3, wolv::util::toBytes<u8>(u8(this->m_color.Value.w * 0xFF)));
} }
void store(nlohmann::json &j) const override { void store(nlohmann::json &j) const override {
@ -1169,7 +1172,7 @@ namespace hex::plugin::builtin {
const auto &outVars = pl.runtime->getOutVariables(); const auto &outVars = pl.runtime->getOutVariables();
if (outVars.contains(this->m_name)) { if (outVars.contains(this->m_name)) {
std::visit(overloaded { std::visit(wolv::util::overloaded {
[](const std::string &) {}, [](const std::string &) {},
[](pl::ptrn::Pattern *) {}, [](pl::ptrn::Pattern *) {},
[this](auto &&value) { [this](auto &&value) {
@ -1231,7 +1234,7 @@ namespace hex::plugin::builtin {
} }
void process() override { void process() override {
std::visit(overloaded { std::visit(wolv::util::overloaded {
[this](i128 value) { this->setIntegerOnOutput(0, value); }, [this](i128 value) { this->setIntegerOnOutput(0, value); },
[this](long double value) { this->setFloatOnOutput(0, value); }, [this](long double value) { this->setFloatOnOutput(0, value); },
[this](const std::vector<u8> &value) { this->setBufferOnOutput(0, value); } [this](const std::vector<u8> &value) { this->setBufferOnOutput(0, value); }

View File

@ -1,20 +1,19 @@
#include <hex/api/event.hpp> #include <hex/api/event.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <hex/ui/view.hpp> #include <hex/ui/view.hpp>
#include <hex/api/localization.hpp> #include <hex/api/localization.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <imgui.h> #include <imgui.h>
#include <nlohmann/json.hpp>
#include <content/helpers/provider_extra_data.hpp> #include <content/helpers/provider_extra_data.hpp>
#include <content/providers/file_provider.hpp> #include <content/providers/file_provider.hpp>
#include <wolv/io/fs.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
static void openFile(const std::fs::path &path) { static void openFile(const std::fs::path &path) {

View File

@ -6,11 +6,14 @@
#include <hex/ui/view.hpp> #include <hex/ui/view.hpp>
#include <hex/api/keybinding.hpp> #include <hex/api/keybinding.hpp>
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/crypto.hpp> #include <hex/helpers/crypto.hpp>
#include <hex/helpers/patches.hpp> #include <hex/helpers/patches.hpp>
#include "content/global_actions.hpp" #include "content/global_actions.hpp"
#include <wolv/io/file.hpp>
using namespace std::literals::string_literals; using namespace std::literals::string_literals;
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
@ -122,7 +125,7 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.menu.file.import.base64"_lang)) { if (ImGui::MenuItem("hex.builtin.menu.file.import.base64"_lang)) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
fs::File inputFile(path, fs::File::Mode::Read); wolv::io::File inputFile(path, wolv::io::File::Mode::Read);
if (!inputFile.isValid()) { if (!inputFile.isValid()) {
View::showErrorPopup("hex.builtin.menu.file.import.base64.popup.open_error"_lang); View::showErrorPopup("hex.builtin.menu.file.import.base64.popup.open_error"_lang);
return; return;
@ -137,7 +140,7 @@ namespace hex::plugin::builtin {
View::showErrorPopup("hex.builtin.menu.file.import.base64.popup.import_error"_lang); View::showErrorPopup("hex.builtin.menu.file.import.base64.popup.import_error"_lang);
else { else {
fs::openFileBrowser(fs::DialogMode::Save, {}, [&data](const std::fs::path &path) { fs::openFileBrowser(fs::DialogMode::Save, {}, [&data](const std::fs::path &path) {
fs::File outputFile(path, fs::File::Mode::Create); wolv::io::File outputFile(path, wolv::io::File::Mode::Create);
if (!outputFile.isValid()) if (!outputFile.isValid())
View::showErrorPopup("hex.builtin.menu.file.import.base64.popup.import_error"_lang); View::showErrorPopup("hex.builtin.menu.file.import.base64.popup.import_error"_lang);
@ -157,7 +160,7 @@ namespace hex::plugin::builtin {
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
TaskManager::createTask("hex.builtin.common.processing", TaskManager::NoProgress, [path](auto &task) { TaskManager::createTask("hex.builtin.common.processing", TaskManager::NoProgress, [path](auto &task) {
auto patchData = fs::File(path, fs::File::Mode::Read).readBytes(); auto patchData = wolv::io::File(path, wolv::io::File::Mode::Read).readBytes();
auto patch = hex::loadIPSPatch(patchData); auto patch = hex::loadIPSPatch(patchData);
if (!patch.has_value()) { if (!patch.has_value()) {
handleIPSError(patch.error()); handleIPSError(patch.error());
@ -183,7 +186,7 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.menu.file.import.ips32"_lang, nullptr, false)) { if (ImGui::MenuItem("hex.builtin.menu.file.import.ips32"_lang, nullptr, false)) {
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
TaskManager::createTask("hex.builtin.common.processing", TaskManager::NoProgress, [path](auto &task) { TaskManager::createTask("hex.builtin.common.processing", TaskManager::NoProgress, [path](auto &task) {
auto patchData = fs::File(path, fs::File::Mode::Read).readBytes(); auto patchData = wolv::io::File(path, wolv::io::File::Mode::Read).readBytes();
auto patch = hex::loadIPS32Patch(patchData); auto patch = hex::loadIPS32Patch(patchData);
if (!patch.has_value()) { if (!patch.has_value()) {
handleIPSError(patch.error()); handleIPSError(patch.error());
@ -212,7 +215,7 @@ namespace hex::plugin::builtin {
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
TaskManager::createTask("hex.builtin.common.processing", TaskManager::NoProgress, [path](auto &task) { TaskManager::createTask("hex.builtin.common.processing", TaskManager::NoProgress, [path](auto &task) {
auto provider = ImHexApi::Provider::get(); auto provider = ImHexApi::Provider::get();
auto patchData = fs::File(path, fs::File::Mode::Read).readBytes(); auto patchData = wolv::io::File(path, wolv::io::File::Mode::Read).readBytes();
if (patchData.size() != provider->getActualSize()) { if (patchData.size() != provider->getActualSize()) {
View::showErrorPopup("hex.builtin.menu.file.import.modified_file.popup.invalid_size"_lang); View::showErrorPopup("hex.builtin.menu.file.import.modified_file.popup.invalid_size"_lang);
@ -254,7 +257,7 @@ namespace hex::plugin::builtin {
fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) { fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) {
TaskManager::createTask("hex.builtin.common.processing", TaskManager::NoProgress, [path](auto &) { TaskManager::createTask("hex.builtin.common.processing", TaskManager::NoProgress, [path](auto &) {
fs::File outputFile(path, fs::File::Mode::Create); wolv::io::File outputFile(path, wolv::io::File::Mode::Create);
if (!outputFile.isValid()) { if (!outputFile.isValid()) {
TaskManager::doLater([] { TaskManager::doLater([] {
View::showErrorPopup("hex.builtin.menu.file.export.base64.popup.export_error"_lang); View::showErrorPopup("hex.builtin.menu.file.export.base64.popup.export_error"_lang);
@ -291,7 +294,7 @@ namespace hex::plugin::builtin {
TaskManager::doLater([data] { TaskManager::doLater([data] {
fs::openFileBrowser(fs::DialogMode::Save, {}, [&data](const auto &path) { fs::openFileBrowser(fs::DialogMode::Save, {}, [&data](const auto &path) {
auto file = fs::File(path, fs::File::Mode::Create); auto file = wolv::io::File(path, wolv::io::File::Mode::Create);
if (!file.isValid()) { if (!file.isValid()) {
View::showErrorPopup("hex.builtin.menu.file.export.ips.popup.export_error"_lang); View::showErrorPopup("hex.builtin.menu.file.export.ips.popup.export_error"_lang);
return; return;
@ -322,7 +325,7 @@ namespace hex::plugin::builtin {
TaskManager::doLater([data] { TaskManager::doLater([data] {
fs::openFileBrowser(fs::DialogMode::Save, {}, [&data](const auto &path) { fs::openFileBrowser(fs::DialogMode::Save, {}, [&data](const auto &path) {
auto file = fs::File(path, fs::File::Mode::Create); auto file = wolv::io::File(path, wolv::io::File::Mode::Create);
if (!file.isValid()) { if (!file.isValid()) {
View::showErrorPopup("hex.builtin.menu.file.export.ips.popup.export_error"_lang); View::showErrorPopup("hex.builtin.menu.file.export.ips.popup.export_error"_lang);
return; return;

View File

@ -10,9 +10,12 @@
#include "content/providers/view_provider.hpp" #include "content/providers/view_provider.hpp"
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <nlohmann/json.hpp>
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#include <nlohmann/json.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
void registerProviders() { void registerProviders() {

View File

@ -7,7 +7,6 @@
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@ -77,7 +76,7 @@ namespace hex::plugin::builtin {
return; return;
std::scoped_lock lock(this->m_mutex); std::scoped_lock lock(this->m_mutex);
fs::File writeFile(this->m_path, fs::File::Mode::Write); wolv::io::File writeFile(this->m_path, wolv::io::File::Mode::Write);
if (!writeFile.isValid()) if (!writeFile.isValid())
return; return;
@ -91,7 +90,7 @@ namespace hex::plugin::builtin {
} }
void FileProvider::saveAs(const std::fs::path &path) { void FileProvider::saveAs(const std::fs::path &path) {
fs::File file(path, fs::File::Mode::Create); wolv::io::File file(path, wolv::io::File::Mode::Create);
if (file.isValid()) { if (file.isValid()) {
auto provider = ImHexApi::Provider::get(); auto provider = ImHexApi::Provider::get();
@ -113,7 +112,7 @@ namespace hex::plugin::builtin {
this->close(); this->close();
{ {
fs::File file(this->m_path, fs::File::Mode::Write); wolv::io::File file(this->m_path, wolv::io::File::Mode::Write);
file.setSize(newSize); file.setSize(newSize);
} }
@ -221,7 +220,7 @@ namespace hex::plugin::builtin {
this->m_readable = true; this->m_readable = true;
this->m_writable = true; this->m_writable = true;
fs::File file(this->m_path, fs::File::Mode::Read); wolv::io::File file(this->m_path, wolv::io::File::Mode::Read);
if (!file.isValid()) { if (!file.isValid()) {
this->m_writable = false; this->m_writable = false;
this->m_readable = false; this->m_readable = false;

View File

@ -56,11 +56,15 @@ namespace hex::plugin::builtin {
} }
void sendAck(Socket &socket) { void sendAck(wolv::util::Socket &socket) {
socket.writeString("+"); socket.writeString("+");
} }
std::vector<u8> readMemory(Socket &socket, u64 address, size_t size) { void continueExecution(wolv::util::Socket &socket) {
socket.writeString(createPacket("vCont;c"));
}
std::vector<u8> readMemory(wolv::util::Socket &socket, u64 address, size_t size) {
std::string packet = createPacket(hex::format("m{:X},{:X}", address, size)); std::string packet = createPacket(hex::format("m{:X},{:X}", address, size));
socket.writeString(packet); socket.writeString(packet);
@ -84,7 +88,7 @@ namespace hex::plugin::builtin {
return data; return data;
} }
void writeMemory(Socket &socket, u64 address, const void *buffer, size_t size) { void writeMemory(wolv::util::Socket &socket, u64 address, const void *buffer, size_t size) {
std::vector<u8> bytes(size); std::vector<u8> bytes(size);
std::memcpy(bytes.data(), buffer, size); std::memcpy(bytes.data(), buffer, size);
@ -94,10 +98,10 @@ namespace hex::plugin::builtin {
socket.writeString(packet); socket.writeString(packet);
auto receivedPacket = socket.readString(3); auto receivedPacket = socket.readString(6);
} }
bool enableNoAckMode(Socket &socket) { bool enableNoAckMode(wolv::util::Socket &socket) {
socket.writeString(createPacket("QStartNoAckMode")); socket.writeString(createPacket("QStartNoAckMode"));
auto ack = socket.readString(1); auto ack = socket.readString(1);
@ -131,7 +135,7 @@ namespace hex::plugin::builtin {
} }
bool GDBProvider::isWritable() const { bool GDBProvider::isWritable() const {
return false; return true;
} }
bool GDBProvider::isResizable() const { bool GDBProvider::isResizable() const {
@ -168,7 +172,7 @@ namespace hex::plugin::builtin {
} }
if (cacheLine != this->m_cache.end()) if (cacheLine != this->m_cache.end())
std::memcpy(buffer, &cacheLine->data[0] + (offset % CacheLineSize), size); std::memcpy(buffer, &cacheLine->data[0] + (offset % CacheLineSize), std::min(size, cacheLine->data.size()));
} else { } else {
while (size > 0) { while (size > 0) {
size_t readSize = std::min(size, CacheLineSize); size_t readSize = std::min(size, CacheLineSize);
@ -251,22 +255,24 @@ namespace hex::plugin::builtin {
} }
if (this->m_socket.isConnected()) { if (this->m_socket.isConnected()) {
gdb::continueExecution(this->m_socket);
this->m_cacheUpdateThread = std::thread([this]() { this->m_cacheUpdateThread = std::thread([this]() {
auto cacheLine = this->m_cache.begin(); auto cacheLine = this->m_cache.begin();
while (this->isConnected()) { while (this->isConnected()) {
{ {
std::scoped_lock lock(this->m_cacheLock); std::scoped_lock lock(this->m_cacheLock);
if (this->m_resetCache) {
this->m_cache.clear();
this->m_resetCache = false;
cacheLine = this->m_cache.begin();
}
if (cacheLine != this->m_cache.end()) { if (cacheLine != this->m_cache.end()) {
auto data = gdb::readMemory(this->m_socket, cacheLine->address, 0x1000); std::vector<u8> data = gdb::readMemory(this->m_socket, cacheLine->address, CacheLineSize);
if (data.empty()) { while (std::count_if(this->m_cache.begin(), this->m_cache.end(), [&](auto &line) { return !line.data.empty(); }) > 100) {
this->m_cache.erase(cacheLine);
cacheLine = this->m_cache.begin();
continue;
}
while (this->m_cache.size() > 5) {
this->m_cache.pop_front(); this->m_cache.pop_front();
cacheLine = this->m_cache.begin(); cacheLine = this->m_cache.begin();
} }
@ -279,7 +285,7 @@ namespace hex::plugin::builtin {
else else
cacheLine++; cacheLine++;
} }
std::this_thread::sleep_for(100ms); std::this_thread::sleep_for(10ms);
} }
}); });

View File

@ -5,11 +5,12 @@
#include <hex/api/imhex_api.hpp> #include <hex/api/imhex_api.hpp>
#include <hex/api/localization.hpp> #include <hex/api/localization.hpp>
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <wolv/io/file.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
namespace intel_hex { namespace intel_hex {
@ -192,7 +193,7 @@ namespace hex::plugin::builtin {
} }
bool IntelHexProvider::open() { bool IntelHexProvider::open() {
auto file = fs::File(this->m_sourceFilePath, fs::File::Mode::Read); auto file = wolv::io::File(this->m_sourceFilePath, wolv::io::File::Mode::Read);
if (!file.isValid()) if (!file.isValid())
return false; return false;
@ -245,7 +246,7 @@ namespace hex::plugin::builtin {
if (!picked) if (!picked)
return false; return false;
if (!fs::isRegularFile(this->m_sourceFilePath)) if (!wolv::io::fs::isRegularFile(this->m_sourceFilePath))
return false; return false;
return true; return true;

View File

@ -6,7 +6,8 @@
#include <hex/api/imhex_api.hpp> #include <hex/api/imhex_api.hpp>
#include <hex/api/localization.hpp> #include <hex/api/localization.hpp>
#include <hex/api/event.hpp> #include <hex/api/event.hpp>
#include <hex/helpers/file.hpp>
#include <wolv/io/file.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
@ -50,7 +51,7 @@ namespace hex::plugin::builtin {
} }
void MemoryFileProvider::saveAs(const std::fs::path &path) { void MemoryFileProvider::saveAs(const std::fs::path &path) {
fs::File file(path, fs::File::Mode::Create); wolv::io::File file(path, wolv::io::File::Mode::Create);
if (file.isValid()) { if (file.isValid()) {
auto provider = ImHexApi::Provider::get(); auto provider = ImHexApi::Provider::get();

View File

@ -3,9 +3,11 @@
#include <hex/api/localization.hpp> #include <hex/api/localization.hpp>
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#include <wolv/io/file.hpp>
#include <wolv/io/fs.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
namespace motorola_srec { namespace motorola_srec {
@ -168,7 +170,7 @@ namespace hex::plugin::builtin {
} }
bool MotorolaSRECProvider::open() { bool MotorolaSRECProvider::open() {
auto file = fs::File(this->m_sourceFilePath, fs::File::Mode::Read); auto file = wolv::io::File(this->m_sourceFilePath, wolv::io::File::Mode::Read);
if (!file.isValid()) if (!file.isValid())
return false; return false;
@ -222,7 +224,7 @@ namespace hex::plugin::builtin {
if (!picked) if (!picked)
return false; return false;
if (!fs::isRegularFile(this->m_sourceFilePath)) if (!wolv::io::fs::isRegularFile(this->m_sourceFilePath))
return false; return false;
return true; return true;

View File

@ -16,6 +16,8 @@
#include <ui/pattern_drawer.hpp> #include <ui/pattern_drawer.hpp>
#include <wolv/utils/guards.hpp>
namespace { namespace {
std::vector<std::fs::path> userFolders; std::vector<std::fs::path> userFolders;
@ -566,14 +568,14 @@ namespace hex::plugin::builtin {
static void loadFontSettings() { static void loadFontSettings() {
std::fs::path fontFile = ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.font_path", ""); std::fs::path fontFile = ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.font_path", "");
if (!fs::exists(fontFile) || !fs::isRegularFile(fontFile)) if (!wolv::io::fs::exists(fontFile) || !wolv::io::fs::isRegularFile(fontFile))
fontFile.clear(); fontFile.clear();
// If no custom font has been specified, search for a file called "font.ttf" in one of the resource folders // If no custom font has been specified, search for a file called "font.ttf" in one of the resource folders
if (fontFile.empty()) { if (fontFile.empty()) {
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Resources)) { for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Resources)) {
auto path = dir / "font.ttf"; auto path = dir / "font.ttf";
if (fs::exists(path)) { if (wolv::io::fs::exists(path)) {
log::info("Loading custom front from {}", hex::toUTF8String(path)); log::info("Loading custom front from {}", hex::toUTF8String(path));
fontFile = path; fontFile = path;

View File

@ -10,10 +10,11 @@
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/file.hpp>
#include <hex/api/event.hpp> #include <hex/api/event.hpp>
#include <wolv/io/file.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
void registerThemeHandlers() { void registerThemeHandlers() {
@ -334,7 +335,7 @@ namespace hex::plugin::builtin {
for (const auto &themeFolder : fs::getDefaultPaths(fs::ImHexPath::Themes)) { for (const auto &themeFolder : fs::getDefaultPaths(fs::ImHexPath::Themes)) {
for (const auto &theme : std::fs::directory_iterator(themeFolder)) { for (const auto &theme : std::fs::directory_iterator(themeFolder)) {
if (theme.is_regular_file()) if (theme.is_regular_file())
api::ThemeManager::addTheme(fs::File(theme.path(), fs::File::Mode::Read).readString()); api::ThemeManager::addTheme(wolv::io::File(theme.path(), wolv::io::File::Mode::Read).readString());
} }
} }
} }

View File

@ -4,7 +4,6 @@
#include <hex/helpers/net.hpp> #include <hex/helpers/net.hpp>
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/literals.hpp> #include <hex/helpers/literals.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/api/localization.hpp> #include <hex/api/localization.hpp>
@ -27,6 +26,9 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <wolv/io/file.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
namespace { namespace {
@ -747,7 +749,7 @@ namespace hex::plugin::builtin {
ON_SCOPE_EXIT { ON_SCOPE_EXIT {
selectedFile.clear(); selectedFile.clear();
}; };
fs::File file(selectedFile, fs::File::Mode::Write); wolv::io::File file(selectedFile, wolv::io::File::Mode::Write);
if (!file.isValid()) { if (!file.isValid()) {
View::showErrorPopup("hex.builtin.tools.file_tools.shredder.error.open"_lang); View::showErrorPopup("hex.builtin.tools.file_tools.shredder.error.open"_lang);
@ -912,7 +914,7 @@ namespace hex::plugin::builtin {
baseOutputPath.clear(); baseOutputPath.clear();
}; };
fs::File file(selectedFile, fs::File::Mode::Read); wolv::io::File file(selectedFile, wolv::io::File::Mode::Read);
if (!file.isValid()) { if (!file.isValid()) {
View::showErrorPopup("hex.builtin.tools.file_tools.splitter.picker.error.open"_lang); View::showErrorPopup("hex.builtin.tools.file_tools.splitter.picker.error.open"_lang);
@ -933,7 +935,7 @@ namespace hex::plugin::builtin {
std::fs::path path = baseOutputPath; std::fs::path path = baseOutputPath;
path += hex::format(".{:05}", index); path += hex::format(".{:05}", index);
fs::File partFile(path, fs::File::Mode::Create); wolv::io::File partFile(path, wolv::io::File::Mode::Create);
if (!partFile.isValid()) { if (!partFile.isValid()) {
View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.splitter.picker.error.create"_lang, index)); View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.splitter.picker.error.create"_lang, index));
@ -1046,7 +1048,7 @@ namespace hex::plugin::builtin {
else { else {
if (ImGui::Button("hex.builtin.tools.file_tools.combiner.combine"_lang)) { if (ImGui::Button("hex.builtin.tools.file_tools.combiner.combine"_lang)) {
combinerTask = TaskManager::createTask("hex.builtin.tools.file_tools.combiner.combining", 0, [](auto &task) { combinerTask = TaskManager::createTask("hex.builtin.tools.file_tools.combiner.combining", 0, [](auto &task) {
fs::File output(outputPath, fs::File::Mode::Create); wolv::io::File output(outputPath, wolv::io::File::Mode::Create);
if (!output.isValid()) { if (!output.isValid()) {
View::showErrorPopup("hex.builtin.tools.file_tools.combiner.error.open_output"_lang); View::showErrorPopup("hex.builtin.tools.file_tools.combiner.error.open_output"_lang);
@ -1060,14 +1062,14 @@ namespace hex::plugin::builtin {
task.update(fileIndex); task.update(fileIndex);
fileIndex++; fileIndex++;
fs::File input(file, fs::File::Mode::Read); wolv::io::File input(file, wolv::io::File::Mode::Read);
if (!input.isValid()) { if (!input.isValid()) {
View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.combiner.open_input"_lang, hex::toUTF8String(file))); View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.combiner.open_input"_lang, hex::toUTF8String(file)));
return; return;
} }
constexpr static auto BufferSize = 0xFF'FFFF; constexpr static auto BufferSize = 0xFF'FFFF;
auto inputSize = input.getSize(); auto inputSize = input.getSize();
for (u64 inputOffset = 0; inputOffset < inputSize; inputOffset += BufferSize) { for (u64 inputOffset = 0; inputOffset < inputSize; inputOffset += BufferSize) {
output.write(input.readBytes(std::min<u64>(BufferSize, inputSize - inputOffset))); output.write(input.readBytes(std::min<u64>(BufferSize, inputSize - inputOffset)));
output.flush(); output.flush();

View File

@ -171,7 +171,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
for (auto &path : fs::getDefaultPaths(type, true)){ for (auto &path : fs::getDefaultPaths(type, true)){
if(fs::isDirectory(path)){ if(wolv::io::fs::isDirectory(path)){
ImGui::TextUnformatted(hex::toUTF8String(path).c_str()); ImGui::TextUnformatted(hex::toUTF8String(path).c_str());
}else{ }else{
ImGui::TextFormattedColored(ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed), hex::toUTF8String(path).c_str()); ImGui::TextFormattedColored(ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed), hex::toUTF8String(path).c_str());

View File

@ -4,13 +4,15 @@
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#include <hex/helpers/file.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <cstring> #include <cstring>
#include <content/helpers/provider_extra_data.hpp> #include <content/helpers/provider_extra_data.hpp>
#include <wolv/io/file.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
ViewBookmarks::ViewBookmarks() : View("hex.builtin.view.bookmarks.name") { ViewBookmarks::ViewBookmarks() : View("hex.builtin.view.bookmarks.name") {
@ -388,7 +390,7 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.menu.file.bookmark.import"_lang, nullptr, false, providerValid)) { if (ImGui::MenuItem("hex.builtin.menu.file.bookmark.import"_lang, nullptr, false, providerValid)) {
fs::openFileBrowser(fs::DialogMode::Open, { { "Bookmarks File", "hexbm"} }, [&](const std::fs::path &path) { fs::openFileBrowser(fs::DialogMode::Open, { { "Bookmarks File", "hexbm"} }, [&](const std::fs::path &path) {
try { try {
importBookmarks(ImHexApi::Provider::get(), nlohmann::json::parse(fs::File(path, fs::File::Mode::Read).readString())); importBookmarks(ImHexApi::Provider::get(), nlohmann::json::parse(wolv::io::File(path, wolv::io::File::Mode::Read).readString()));
} catch (...) { } } catch (...) { }
}); });
} }
@ -397,7 +399,7 @@ namespace hex::plugin::builtin {
nlohmann::json json; nlohmann::json json;
exportBookmarks(ImHexApi::Provider::get(), json); exportBookmarks(ImHexApi::Provider::get(), json);
fs::File(path, fs::File::Mode::Create).write(json.dump(4)); wolv::io::File(path, wolv::io::File::Mode::Create).write(json.dump(4));
}); });
} }
}); });

View File

@ -22,7 +22,7 @@ namespace hex::plugin::builtin {
this->m_filterIndices.clear(); this->m_filterIndices.clear();
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Constants)) { for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Constants)) {
if (!fs::exists(path)) continue; if (!wolv::io::fs::exists(path)) continue;
std::error_code error; std::error_code error;
for (auto &file : std::fs::directory_iterator(path, error)) { for (auto &file : std::fs::directory_iterator(path, error)) {

View File

@ -7,12 +7,13 @@
#include <cstring> #include <cstring>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <hex/helpers/file.hpp>
#include <pl/pattern_language.hpp> #include <pl/pattern_language.hpp>
#include <pl/core/evaluator.hpp> #include <pl/core/evaluator.hpp>
#include <pl/patterns/pattern.hpp> #include <pl/patterns/pattern.hpp>
#include <wolv/io/file.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
using NumberDisplayStyle = ContentRegistry::DataInspector::NumberDisplayStyle; using NumberDisplayStyle = ContentRegistry::DataInspector::NumberDisplayStyle;
@ -106,7 +107,7 @@ namespace hex::plugin::builtin {
if (!filePath.exists() || !filePath.is_regular_file() || filePath.path().extension() != ".hexpat") if (!filePath.exists() || !filePath.is_regular_file() || filePath.path().extension() != ".hexpat")
continue; continue;
fs::File file(filePath, fs::File::Mode::Read); wolv::io::File file(filePath, wolv::io::File::Mode::Read);
if (file.isValid()) { if (file.isValid()) {
auto inspectorCode = file.readString(); auto inspectorCode = file.readString();

View File

@ -2,7 +2,6 @@
#include <hex/api/content_registry.hpp> #include <hex/api/content_registry.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <hex/providers/provider.hpp> #include <hex/providers/provider.hpp>
@ -14,6 +13,8 @@
#include <content/helpers/provider_extra_data.hpp> #include <content/helpers/provider_extra_data.hpp>
#include <wolv/io/file.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
ViewDataProcessor::ViewDataProcessor() : View("hex.builtin.view.data_processor.name") { ViewDataProcessor::ViewDataProcessor() : View("hex.builtin.view.data_processor.name") {
@ -73,7 +74,7 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.load_processor"_lang, nullptr, false, providerValid)) { if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.load_processor"_lang, nullptr, false, providerValid)) {
fs::openFileBrowser(fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } }, fs::openFileBrowser(fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } },
[&](const std::fs::path &path) { [&](const std::fs::path &path) {
fs::File file(path, fs::File::Mode::Read); wolv::io::File file(path, wolv::io::File::Mode::Read);
if (file.isValid()) { if (file.isValid()) {
ViewDataProcessor::loadNodes(data.mainWorkspace, file.readString()); ViewDataProcessor::loadNodes(data.mainWorkspace, file.readString());
this->m_updateNodePositions = true; this->m_updateNodePositions = true;
@ -84,7 +85,7 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.save_processor"_lang, nullptr, false, !data.workspaceStack.empty() && !data.workspaceStack.back()->nodes.empty() && providerValid)) { if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.save_processor"_lang, nullptr, false, !data.workspaceStack.empty() && !data.workspaceStack.back()->nodes.empty() && providerValid)) {
fs::openFileBrowser(fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } }, fs::openFileBrowser(fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } },
[&](const std::fs::path &path) { [&](const std::fs::path &path) {
fs::File file(path, fs::File::Mode::Create); wolv::io::File file(path, wolv::io::File::Mode::Create);
if (file.isValid()) if (file.isValid())
file.write(ViewDataProcessor::saveNodes(data.mainWorkspace).dump(4)); file.write(ViewDataProcessor::saveNodes(data.mainWorkspace).dump(4));
}); });
@ -92,7 +93,7 @@ namespace hex::plugin::builtin {
}); });
ContentRegistry::FileHandler::add({ ".hexnode" }, [this](const auto &path) { ContentRegistry::FileHandler::add({ ".hexnode" }, [this](const auto &path) {
fs::File file(path, fs::File::Mode::Read); wolv::io::File file(path, wolv::io::File::Mode::Read);
if (!file.isValid()) return false; if (!file.isValid()) return false;
auto &data = ProviderExtraData::getCurrent().dataProcessor; auto &data = ProviderExtraData::getCurrent().dataProcessor;
@ -204,7 +205,7 @@ namespace hex::plugin::builtin {
for (const auto &entry : std::fs::recursive_directory_iterator(basePath)) { for (const auto &entry : std::fs::recursive_directory_iterator(basePath)) {
if (entry.path().extension() == ".hexnode") { if (entry.path().extension() == ".hexnode") {
try { try {
nlohmann::json nodeJson = nlohmann::json::parse(fs::File(entry.path(), fs::File::Mode::Read).readString()); nlohmann::json nodeJson = nlohmann::json::parse(wolv::io::File(entry.path(), wolv::io::File::Mode::Read).readString());
this->m_customNodes.push_back(CustomNode { LangEntry(nodeJson["name"]), nodeJson }); this->m_customNodes.push_back(CustomNode { LangEntry(nodeJson["name"]), nodeJson });
} catch (nlohmann::json::exception &e) { } catch (nlohmann::json::exception &e) {
@ -320,7 +321,7 @@ namespace hex::plugin::builtin {
if (it != workspace.nodes.end()) { if (it != workspace.nodes.end()) {
auto &node = *it; auto &node = *it;
fs::openFileBrowser(fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } }, [&](const std::fs::path &path){ fs::openFileBrowser(fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } }, [&](const std::fs::path &path){
fs::File outputFile(path, fs::File::Mode::Create); wolv::io::File outputFile(path, wolv::io::File::Mode::Create);
outputFile.write(ViewDataProcessor::saveNode(node.get()).dump(4)); outputFile.write(ViewDataProcessor::saveNode(node.get()).dump(4));
}); });
} }

View File

@ -141,8 +141,8 @@ namespace hex::plugin::builtin {
this->m_diffTask = TaskManager::createTask("Diffing...", commonSize, [this, providerA, providerB](Task &task) { this->m_diffTask = TaskManager::createTask("Diffing...", commonSize, [this, providerA, providerB](Task &task) {
std::vector<Diff> differences; std::vector<Diff> differences;
auto readerA = prv::BufferedReader(providerA); auto readerA = prv::ProviderReader(providerA);
auto readerB = prv::BufferedReader(providerB); auto readerB = prv::ProviderReader(providerB);
for (auto itA = readerA.begin(), itB = readerB.begin(); itA < readerA.end() && itB < readerB.end(); itA++, itB++) { for (auto itA = readerA.begin(), itB = readerB.begin(); itA < readerA.end() && itB < readerB.end(); itA++, itB++) {
if (task.wasInterrupted()) if (task.wasInterrupted())

View File

@ -236,7 +236,7 @@ namespace hex::plugin::builtin {
return results; return results;
} }
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
reader.seek(searchRegion.getStartAddress()); reader.seek(searchRegion.getStartAddress());
reader.setEndAddress(searchRegion.getEndAddress()); reader.setEndAddress(searchRegion.getEndAddress());
@ -295,7 +295,7 @@ namespace hex::plugin::builtin {
std::vector<ViewFind::Occurrence> ViewFind::searchSequence(Task &task, prv::Provider *provider, hex::Region searchRegion, const SearchSettings::Sequence &settings) { std::vector<ViewFind::Occurrence> ViewFind::searchSequence(Task &task, prv::Provider *provider, hex::Region searchRegion, const SearchSettings::Sequence &settings) {
std::vector<Occurrence> results; std::vector<Occurrence> results;
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
reader.seek(searchRegion.getStartAddress()); reader.seek(searchRegion.getStartAddress());
reader.setEndAddress(searchRegion.getEndAddress()); reader.setEndAddress(searchRegion.getEndAddress());
@ -353,7 +353,7 @@ namespace hex::plugin::builtin {
std::vector<ViewFind::Occurrence> ViewFind::searchBinaryPattern(Task &task, prv::Provider *provider, hex::Region searchRegion, const SearchSettings::BinaryPattern &settings) { std::vector<ViewFind::Occurrence> ViewFind::searchBinaryPattern(Task &task, prv::Provider *provider, hex::Region searchRegion, const SearchSettings::BinaryPattern &settings) {
std::vector<Occurrence> results; std::vector<Occurrence> results;
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
reader.seek(searchRegion.getStartAddress()); reader.seek(searchRegion.getStartAddress());
reader.setEndAddress(searchRegion.getEndAddress()); reader.setEndAddress(searchRegion.getEndAddress());
@ -386,7 +386,7 @@ namespace hex::plugin::builtin {
std::vector<ViewFind::Occurrence> ViewFind::searchValue(Task &task, prv::Provider *provider, Region searchRegion, const SearchSettings::Value &settings) { std::vector<ViewFind::Occurrence> ViewFind::searchValue(Task &task, prv::Provider *provider, Region searchRegion, const SearchSettings::Value &settings) {
std::vector<Occurrence> results; std::vector<Occurrence> results;
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
reader.seek(searchRegion.getStartAddress()); reader.seek(searchRegion.getStartAddress());
reader.setEndAddress(searchRegion.getEndAddress()); reader.setEndAddress(searchRegion.getEndAddress());

View File

@ -292,7 +292,7 @@ namespace hex::plugin::builtin {
std::optional<Region> findSequence(const std::vector<u8> &sequence, bool backwards) { std::optional<Region> findSequence(const std::vector<u8> &sequence, bool backwards) {
auto provider = ImHexApi::Provider::get(); auto provider = ImHexApi::Provider::get();
hex::prv::BufferedReader reader(provider); prv::ProviderReader reader(provider);
reader.seek(this->m_searchPosition.value_or(provider->getBaseAddress())); reader.seek(this->m_searchPosition.value_or(provider->getBaseAddress()));
@ -605,7 +605,7 @@ namespace hex::plugin::builtin {
auto provider = ImHexApi::Provider::get(); auto provider = ImHexApi::Provider::get();
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader (provider);
reader.seek(selection.getStartAddress()); reader.seek(selection.getStartAddress());
reader.setEndAddress(selection.getEndAddress()); reader.setEndAddress(selection.getEndAddress());

View File

@ -47,7 +47,7 @@ namespace hex::plugin::builtin {
ContentRegistry::FileHandler::add({ ".mgc" }, [](const auto &path) { ContentRegistry::FileHandler::add({ ".mgc" }, [](const auto &path) {
for (const auto &destPath : fs::getDefaultPaths(fs::ImHexPath::Magic)) { for (const auto &destPath : fs::getDefaultPaths(fs::ImHexPath::Magic)) {
if (fs::copyFile(path, destPath / path.filename(), std::fs::copy_options::overwrite_existing)) { if (wolv::io::fs::copyFile(path, destPath / path.filename(), std::fs::copy_options::overwrite_existing)) {
View::showInfoPopup("hex.builtin.view.information.magic_db_added"_lang); View::showInfoPopup("hex.builtin.view.information.magic_db_added"_lang);
return true; return true;
} }
@ -110,7 +110,7 @@ namespace hex::plugin::builtin {
provider->getBaseAddress(), provider->getSize()); provider->getBaseAddress(), provider->getSize());
// Create a handle to the file // Create a handle to the file
auto reader = prv::BufferedReader(provider); auto reader = prv::ProviderReader(provider);
reader.seek(provider->getBaseAddress() + this->m_inputStartAddress); reader.seek(provider->getBaseAddress() + this->m_inputStartAddress);
reader.setEndAddress(provider->getBaseAddress() + this->m_inputEndAddress); reader.setEndAddress(provider->getBaseAddress() + this->m_inputEndAddress);

View File

@ -11,7 +11,6 @@
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/file.hpp>
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <hex/helpers/magic.hpp> #include <hex/helpers/magic.hpp>
@ -20,6 +19,10 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <chrono> #include <chrono>
#include <wolv/io/file.hpp>
#include <wolv/io/fs.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
using namespace hex::literals; using namespace hex::literals;
@ -633,7 +636,7 @@ namespace hex::plugin::builtin {
void ViewPatternEditor::loadPatternFile(const std::fs::path &path, prv::Provider *provider) { void ViewPatternEditor::loadPatternFile(const std::fs::path &path, prv::Provider *provider) {
fs::File file(path, fs::File::Mode::Read); wolv::io::File file(path, wolv::io::File::Mode::Read);
if (file.isValid()) { if (file.isValid()) {
auto code = file.readString(); auto code = file.readString();
@ -808,7 +811,7 @@ namespace hex::plugin::builtin {
if (!entry.is_regular_file()) if (!entry.is_regular_file())
continue; continue;
fs::File file(entry.path(), fs::File::Mode::Read); wolv::io::File file(entry.path(), wolv::io::File::Mode::Read);
if (!file.isValid()) if (!file.isValid())
continue; continue;
@ -871,7 +874,7 @@ namespace hex::plugin::builtin {
std::vector<std::fs::path> paths; std::vector<std::fs::path> paths;
for (const auto &imhexPath : fs::getDefaultPaths(fs::ImHexPath::Patterns)) { for (const auto &imhexPath : fs::getDefaultPaths(fs::ImHexPath::Patterns)) {
if (!fs::exists(imhexPath)) continue; if (!wolv::io::fs::exists(imhexPath)) continue;
std::error_code error; std::error_code error;
for (auto &entry : std::fs::recursive_directory_iterator(imhexPath, error)) { for (auto &entry : std::fs::recursive_directory_iterator(imhexPath, error)) {
@ -890,7 +893,7 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang, nullptr, false, providerValid)) { if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang, nullptr, false, providerValid)) {
fs::openFileBrowser(fs::DialogMode::Save, { {"Pattern", "hexpat"} }, fs::openFileBrowser(fs::DialogMode::Save, { {"Pattern", "hexpat"} },
[this](const auto &path) { [this](const auto &path) {
fs::File file(path, fs::File::Mode::Create); wolv::io::File file(path, wolv::io::File::Mode::Create);
file.write(this->m_textEditor.GetText()); file.write(this->m_textEditor.GetText());
}); });
@ -969,7 +972,7 @@ namespace hex::plugin::builtin {
void ViewPatternEditor::registerHandlers() { void ViewPatternEditor::registerHandlers() {
ContentRegistry::FileHandler::add({ ".hexpat", ".pat" }, [](const std::fs::path &path) -> bool { ContentRegistry::FileHandler::add({ ".hexpat", ".pat" }, [](const std::fs::path &path) -> bool {
fs::File file(path, fs::File::Mode::Read); wolv::io::File file(path, wolv::io::File::Mode::Read);
if (file.isValid()) { if (file.isValid()) {
EventManager::post<RequestSetPatternLanguageCode>(file.readString()); EventManager::post<RequestSetPatternLanguageCode>(file.readString());

View File

@ -10,7 +10,6 @@
#include <hex/helpers/crypto.hpp> #include <hex/helpers/crypto.hpp>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <hex/helpers/magic.hpp> #include <hex/helpers/magic.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/tar.hpp> #include <hex/helpers/tar.hpp>
@ -19,6 +18,8 @@
#include <functional> #include <functional>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <wolv/io/file.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
using namespace std::literals::string_literals; using namespace std::literals::string_literals;
@ -166,11 +167,11 @@ namespace hex::plugin::builtin {
auto path = folder / std::fs::path(storeEntry.fileName); auto path = folder / std::fs::path(storeEntry.fileName);
if (fs::exists(path) && fs::isPathWritable(folder)) { if (wolv::io::fs::exists(path) && fs::isPathWritable(folder)) {
storeEntry.installed = true; storeEntry.installed = true;
std::ifstream file(path, std::ios::in | std::ios::binary); std::ifstream file(path, std::ios::in | std::ios::binary);
std::vector<u8> data(fs::getFileSize(path), 0x00); std::vector<u8> data(wolv::io::fs::getFileSize(path), 0x00);
file.read(reinterpret_cast<char *>(data.data()), data.size()); file.read(reinterpret_cast<char *>(data.data()), data.size());
auto fileHash = crypt::sha256(data); auto fileHash = crypt::sha256(data);
@ -227,7 +228,7 @@ namespace hex::plugin::builtin {
auto fullPath = path / std::fs::path(fileName); auto fullPath = path / std::fs::path(fileName);
if (!update || fs::exists(fullPath)) { if (!update || wolv::io::fs::exists(fullPath)) {
downloading = true; downloading = true;
this->m_downloadPath = fullPath; this->m_downloadPath = fullPath;
this->m_download = this->m_net.downloadFile(url, fullPath, 30'0000); this->m_download = this->m_net.downloadFile(url, fullPath, 30'0000);
@ -249,10 +250,10 @@ namespace hex::plugin::builtin {
const auto filePath = path / fileName; const auto filePath = path / fileName;
const auto folderPath = (path / std::fs::path(fileName).stem()); const auto folderPath = (path / std::fs::path(fileName).stem());
fs::remove(filePath); wolv::io::fs::remove(filePath);
fs::removeAll(folderPath); wolv::io::fs::removeAll(folderPath);
removed = removed && !fs::exists(filePath) && !fs::exists(folderPath); removed = removed && !wolv::io::fs::exists(filePath) && !wolv::io::fs::exists(folderPath);
} }
return removed; return removed;

View File

@ -2,7 +2,7 @@
#include <hex/api/theme_manager.hpp> #include <hex/api/theme_manager.hpp>
#include <hex/helpers/file.hpp> #include <wolv/io/file.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
@ -59,7 +59,7 @@ namespace hex::plugin::builtin {
fs::openFileBrowser(fs::DialogMode::Save, { { "ImHex Theme", "json" } }, [this](const std::fs::path &path){ fs::openFileBrowser(fs::DialogMode::Save, { { "ImHex Theme", "json" } }, [this](const std::fs::path &path){
auto json = api::ThemeManager::exportCurrentTheme(this->m_themeName); auto json = api::ThemeManager::exportCurrentTheme(this->m_themeName);
fs::File outputFile(path, fs::File::Mode::Create); wolv::io::File outputFile(path, wolv::io::File::Mode::Create);
outputFile.write(json.dump(4)); outputFile.write(json.dump(4));
}); });
} }

View File

@ -4,7 +4,6 @@
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include "content/helpers/provider_extra_data.hpp" #include "content/helpers/provider_extra_data.hpp"
@ -18,6 +17,10 @@
#include <filesystem> #include <filesystem>
#include <thread> #include <thread>
#include <wolv/io/file.hpp>
#include <wolv/io/fs.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
ViewYara::ViewYara() : View("hex.builtin.view.yara.name") { ViewYara::ViewYara() : View("hex.builtin.view.yara.name") {
@ -25,7 +28,7 @@ namespace hex::plugin::builtin {
ContentRegistry::FileHandler::add({ ".yar", ".yara" }, [](const auto &path) { ContentRegistry::FileHandler::add({ ".yar", ".yara" }, [](const auto &path) {
for (const auto &destPath : fs::getDefaultPaths(fs::ImHexPath::Yara)) { for (const auto &destPath : fs::getDefaultPaths(fs::ImHexPath::Yara)) {
if (fs::copyFile(path, destPath / path.filename(), std::fs::copy_options::overwrite_existing)) { if (wolv::io::fs::copyFile(path, destPath / path.filename(), std::fs::copy_options::overwrite_existing)) {
View::showInfoPopup("hex.builtin.view.yara.rule_added"_lang); View::showInfoPopup("hex.builtin.view.yara.rule_added"_lang);
return true; return true;
} }
@ -261,12 +264,12 @@ namespace hex::plugin::builtin {
yr_compiler_destroy(compiler); yr_compiler_destroy(compiler);
}; };
auto currFilePath = hex::toUTF8String(fs::toShortPath(filePath)); auto currFilePath = hex::toUTF8String(wolv::io::fs::toShortPath(filePath));
yr_compiler_set_include_callback( yr_compiler_set_include_callback(
compiler, compiler,
[](const char *includeName, const char *, const char *, void *userData) -> const char * { [](const char *includeName, const char *, const char *, void *userData) -> const char * {
fs::File file(std::fs::path(static_cast<const char *>(userData)).parent_path() / includeName, fs::File::Mode::Read); wolv::io::File file(std::fs::path(static_cast<const char *>(userData)).parent_path() / includeName, wolv::io::File::Mode::Read);
if (!file.isValid()) if (!file.isValid())
return nullptr; return nullptr;
@ -285,7 +288,7 @@ namespace hex::plugin::builtin {
currFilePath.data() currFilePath.data()
); );
fs::File file(rules[this->m_selectedRule].second, fs::File::Mode::Read); wolv::io::File file(rules[this->m_selectedRule].second, wolv::io::File::Mode::Read);
if (!file.isValid()) return; if (!file.isValid()) return;
if (yr_compiler_add_file(compiler, file.getHandle(), nullptr, nullptr) != 0) { if (yr_compiler_add_file(compiler, file.getHandle(), nullptr, nullptr) != 0) {

View File

@ -7,7 +7,6 @@
#include <hex/ui/view.hpp> #include <hex/ui/view.hpp>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp> #include <hex/helpers/logger.hpp>
#include <hex/helpers/file.hpp>
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
@ -18,6 +17,10 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <romfs/romfs.hpp> #include <romfs/romfs.hpp>
#include <wolv/io/file.hpp>
#include <wolv/io/fs.hpp>
#include <wolv/utils/guards.hpp>
#include <fonts/codicons_font.h> #include <fonts/codicons_font.h>
#include <string> #include <string>
@ -85,7 +88,7 @@ namespace hex::plugin::builtin {
for (u32 i = 0; i < recentFilePaths.size() && uniqueProviders.size() < 5; i++) { for (u32 i = 0; i < recentFilePaths.size() && uniqueProviders.size() < 5; i++) {
auto &path = recentFilePaths[i]; auto &path = recentFilePaths[i];
try { try {
auto jsonData = nlohmann::json::parse(fs::File(path, fs::File::Mode::Read).readString()); auto jsonData = nlohmann::json::parse(wolv::io::File(path, wolv::io::File::Mode::Read).readString());
uniqueProviders.insert(RecentProvider { uniqueProviders.insert(RecentProvider {
.displayName = jsonData["displayName"], .displayName = jsonData["displayName"],
.type = jsonData["type"], .type = jsonData["type"],
@ -179,14 +182,14 @@ namespace hex::plugin::builtin {
for (const auto &provider : ImHexApi::Provider::getProviders()) for (const auto &provider : ImHexApi::Provider::getProviders())
provider->markDirty(); provider->markDirty();
fs::remove(s_safetyBackupPath); wolv::io::fs::remove(s_safetyBackupPath);
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
ImGui::SameLine(); ImGui::SameLine();
ImGui::SetCursorPosX(width / 9 * 5); ImGui::SetCursorPosX(width / 9 * 5);
if (ImGui::Button("hex.builtin.welcome.safety_backup.delete"_lang, ImVec2(width / 3, 0))) { if (ImGui::Button("hex.builtin.welcome.safety_backup.delete"_lang, ImVec2(width / 3, 0))) {
fs::remove(s_safetyBackupPath); wolv::io::fs::remove(s_safetyBackupPath);
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
@ -476,7 +479,7 @@ namespace hex::plugin::builtin {
{ {
for (const auto &recentPath : fs::getDefaultPaths(fs::ImHexPath::Recent)) { for (const auto &recentPath : fs::getDefaultPaths(fs::ImHexPath::Recent)) {
auto fileName = hex::format("{:%y%m%d_%H%M%S}.json", fmt::gmtime(std::chrono::system_clock::now())); auto fileName = hex::format("{:%y%m%d_%H%M%S}.json", fmt::gmtime(std::chrono::system_clock::now()));
fs::File recentFile(recentPath / fileName, fs::File::Mode::Create); wolv::io::File recentFile(recentPath / fileName, wolv::io::File::Mode::Create);
if (!recentFile.isValid()) if (!recentFile.isValid())
continue; continue;
@ -550,7 +553,7 @@ namespace hex::plugin::builtin {
constexpr static auto CrashBackupFileName = "crash_backup.hexproj"; constexpr static auto CrashBackupFileName = "crash_backup.hexproj";
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Config)) { for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Config)) {
if (auto filePath = std::fs::path(path) / CrashBackupFileName; fs::exists(filePath)) { if (auto filePath = std::fs::path(path) / CrashBackupFileName; wolv::io::fs::exists(filePath)) {
s_safetyBackupPath = filePath; s_safetyBackupPath = filePath;
TaskManager::doLater([] { ImGui::OpenPopup("hex.builtin.welcome.safety_backup.title"_lang); }); TaskManager::doLater([] { ImGui::OpenPopup("hex.builtin.welcome.safety_backup.title"_lang); });
} }

View File

@ -10,6 +10,9 @@
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#include <hex/ui/view.hpp> #include <hex/ui/view.hpp>
#include <wolv/io/file.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::windows { namespace hex::plugin::windows {
bool ProcessMemoryProvider::open() { bool ProcessMemoryProvider::open() {

View File

@ -4,6 +4,8 @@
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::windows { namespace hex::plugin::windows {
ViewTTYConsole::ViewTTYConsole() : View("hex.windows.view.tty_console.name") { ViewTTYConsole::ViewTTYConsole() : View("hex.windows.view.tty_console.name") {