mirror of https://github.com/WerWolv/ImHex.git
sys: Replaced many helper functions with libwolv
This commit is contained in:
parent
e958934a22
commit
0dafb3d230
|
@ -29,3 +29,6 @@
|
|||
[submodule "lib/external/pattern_language"]
|
||||
path = lib/external/pattern_language
|
||||
url = https://github.com/WerWolv/PatternLanguage
|
||||
[submodule "lib/external/libwolv"]
|
||||
path = lib/external/libwolv
|
||||
url = https://github.com/WerWolv/libwolv
|
||||
|
|
|
@ -419,6 +419,8 @@ macro(addBundledLibraries)
|
|||
add_subdirectory(${EXTERN_LIBS_FOLDER}/intervaltree EXCLUDE_FROM_ALL)
|
||||
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(CURL_USE_MBEDTLS ON)
|
||||
set(BUILD_CURL_EXE OFF)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 6742cbb5c464ae4dcd7c1d5d1a573403258000bd
|
|
@ -1 +1 @@
|
|||
Subproject commit 572a481803aa19c5bd0c3ccce08d63666d01499c
|
||||
Subproject commit 714fb62cf47b171dae58bf2c5a95e82d4d8310a7
|
|
@ -25,8 +25,6 @@ set(LIBIMHEX_SOURCES
|
|||
source/helpers/crypto.cpp
|
||||
source/helpers/net.cpp
|
||||
source/helpers/opengl.cpp
|
||||
source/helpers/file.cpp
|
||||
source/helpers/socket.cpp
|
||||
source/helpers/patches.cpp
|
||||
source/helpers/encoding_file.cpp
|
||||
source/helpers/logger.cpp
|
||||
|
@ -72,4 +70,4 @@ elseif (APPLE)
|
|||
endif ()
|
||||
|
||||
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)
|
|
@ -5,6 +5,7 @@
|
|||
#include <hex/data_processor/attribute.hpp>
|
||||
|
||||
#include <set>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
|
@ -77,7 +78,7 @@ namespace hex::dp {
|
|||
const i128& getIntegerOnInput(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 setFloatOnOutput(u32 index, long double floatingPoint);
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
#include <span>
|
||||
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
|
@ -28,7 +29,7 @@ namespace hex {
|
|||
[[nodiscard]] bool valid() const { return this->m_valid; }
|
||||
|
||||
private:
|
||||
void parseThingyFile(fs::File &file);
|
||||
void parseThingyFile(wolv::io::File &file);
|
||||
|
||||
bool m_valid = false;
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
|
@ -10,73 +10,10 @@
|
|||
|
||||
#include <nfd.hpp>
|
||||
|
||||
namespace std::fs {
|
||||
using namespace std::filesystem;
|
||||
}
|
||||
#include <wolv/io/fs.hpp>
|
||||
|
||||
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 {
|
||||
Open,
|
||||
Save,
|
||||
|
@ -107,7 +44,7 @@ namespace hex::fs {
|
|||
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);
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
}
|
|
@ -19,10 +19,6 @@
|
|||
#include <variant>
|
||||
#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;
|
||||
|
||||
namespace hex {
|
||||
|
@ -116,11 +112,6 @@ namespace hex {
|
|||
return i;
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
struct overloaded : Ts... { using Ts::operator()...; };
|
||||
template<class... Ts>
|
||||
overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
template<size_t Size>
|
||||
struct SizeTypeImpl { };
|
||||
|
||||
|
@ -220,14 +211,6 @@ namespace hex {
|
|||
|
||||
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) {
|
||||
auto byteString = std::string(string);
|
||||
byteString.erase(std::remove(byteString.begin(), byteString.end(), ' '), byteString.end());
|
||||
|
@ -327,89 +310,4 @@ namespace hex {
|
|||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,282 +6,21 @@
|
|||
#include <hex/providers/provider.hpp>
|
||||
#include <hex/helpers/literals.hpp>
|
||||
|
||||
#include <wolv/io/buffered_reader.hpp>
|
||||
|
||||
namespace hex::prv {
|
||||
|
||||
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:
|
||||
explicit BufferedReader(Provider *provider, size_t bufferSize = 16_MiB)
|
||||
: m_provider(provider), m_bufferAddress(provider->getBaseAddress()), m_maxBufferSize(bufferSize),
|
||||
m_startAddress(provider->getBaseAddress()), m_endAddress(provider->getBaseAddress() + provider->getActualSize() - 1LLU),
|
||||
m_buffer(bufferSize) {
|
||||
using BufferedReader::BufferedReader;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
ProviderReader(Provider *provider, size_t bufferSize = 0x100000) : BufferedReader(provider, provider->getActualSize(), bufferSize) { }
|
||||
};
|
||||
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <hex/ui/view.hpp>
|
||||
#include <hex/data_processor/node.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <hex/data_processor/node.hpp>
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace hex {
|
|||
void load() {
|
||||
bool loaded = false;
|
||||
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()) {
|
||||
getSettingsData() = nlohmann::json::parse(file.readString());
|
||||
|
@ -37,7 +37,7 @@ namespace hex {
|
|||
|
||||
void store() {
|
||||
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()) {
|
||||
file.write(getSettingsData().dump(4));
|
||||
|
@ -48,7 +48,7 @@ namespace hex {
|
|||
|
||||
void clear() {
|
||||
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
|
||||
hex::fs::remove(dir / SettingsFile);
|
||||
wolv::io::fs::remove(dir / SettingsFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ namespace hex {
|
|||
std::vector<Plugin> PluginManager::s_plugins;
|
||||
|
||||
bool PluginManager::load(const std::fs::path &pluginFolder) {
|
||||
if (!fs::exists(pluginFolder))
|
||||
if (!wolv::io::fs::exists(pluginFolder))
|
||||
return false;
|
||||
|
||||
PluginManager::s_pluginFolder = pluginFolder;
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
#include <hex/providers/provider.hpp>
|
||||
|
||||
#include <wolv/utils/guards.hpp>
|
||||
#include <wolv/io/fs.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
constexpr static auto MetadataHeaderMagic = "HEX";
|
||||
|
@ -24,7 +27,7 @@ namespace hex {
|
|||
ProjectFile::s_currProjectPath = originalPath;
|
||||
};
|
||||
|
||||
if (!fs::exists(filePath) || !fs::isRegularFile(filePath))
|
||||
if (!wolv::io::fs::exists(filePath) || !wolv::io::fs::isRegularFile(filePath))
|
||||
return false;
|
||||
if (filePath.extension() != ".hexproj")
|
||||
return false;
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace hex::dp {
|
|||
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())
|
||||
throwNodeError("Attribute index out of bounds!");
|
||||
|
||||
|
@ -95,7 +95,7 @@ namespace hex::dp {
|
|||
if (attribute.getIOType() != Attribute::IOType::Out)
|
||||
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) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <hex/helpers/crypto.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/base64.h>
|
||||
|
@ -11,13 +11,10 @@
|
|||
#include <mbedtls/sha1.h>
|
||||
#include <mbedtls/sha256.h>
|
||||
#include <mbedtls/sha512.h>
|
||||
#include <mbedtls/aes.h>
|
||||
#include <mbedtls/cipher.h>
|
||||
|
||||
#include <array>
|
||||
#include <span>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <bit>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include <hex/helpers/encoding_file.hpp>
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
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) {
|
||||
case Type::Thingy:
|
||||
parseThingyFile(file);
|
||||
|
@ -31,7 +32,7 @@ namespace hex {
|
|||
return { ".", 1 };
|
||||
}
|
||||
|
||||
void EncodingFile::parseThingyFile(fs::File &file) {
|
||||
void EncodingFile::parseThingyFile(wolv::io::File &file) {
|
||||
for (const auto &line : splitString(file.readString(), "\n")) {
|
||||
|
||||
std::string from, to;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,11 +3,6 @@
|
|||
#include <hex/api/content_registry.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>
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
|
@ -21,61 +16,10 @@
|
|||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
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;
|
||||
void setFileBrowserErrorCallback(const std::function<void()> &callback) {
|
||||
s_fileBrowserErrorCallback = callback;
|
||||
|
@ -171,7 +115,7 @@ namespace hex::fs {
|
|||
|
||||
#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());
|
||||
|
||||
#endif
|
||||
|
@ -281,13 +225,31 @@ namespace hex::fs {
|
|||
|
||||
if (!listNonExisting) {
|
||||
result.erase(std::remove_if(result.begin(), result.end(), [](const auto &path) {
|
||||
return !fs::isDirectory(path);
|
||||
return !wolv::io::fs::isDirectory(path);
|
||||
}), result.end());
|
||||
}
|
||||
|
||||
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) {
|
||||
#if defined(OS_WINDOWS)
|
||||
size_t size = GetShortPathNameW(path.c_str(), nullptr, 0);
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex::log {
|
||||
|
||||
static fs::File g_loggerFile;
|
||||
static wolv::io::File g_loggerFile;
|
||||
|
||||
FILE *getDestination() {
|
||||
if (g_loggerFile.isValid())
|
||||
|
@ -24,8 +23,8 @@ namespace hex::log {
|
|||
if (g_loggerFile.isValid()) return;
|
||||
|
||||
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Logs, true)) {
|
||||
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);
|
||||
wolv::io::fs::createDirectories(path);
|
||||
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();
|
||||
|
||||
if (g_loggerFile.isValid()) break;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
#include <hex/providers/provider.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
|
@ -27,7 +29,7 @@ namespace hex::magic {
|
|||
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Magic)) {
|
||||
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"))) {
|
||||
magicFiles += hex::toUTF8String(fs::toShortPath(entry.path())) + MAGIC_PATH_SEPARATOR;
|
||||
magicFiles += hex::toUTF8String(wolv::io::fs::toShortPath(entry.path())) + MAGIC_PATH_SEPARATOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include <hex/helpers/net.hpp>
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
@ -11,15 +10,18 @@
|
|||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
Net::Net() {
|
||||
FIRST_TIME {
|
||||
AT_FIRST_TIME {
|
||||
curl_global_sslset(CURLSSLBACKEND_MBEDTLS, nullptr, nullptr);
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
};
|
||||
|
||||
FINAL_CLEANUP {
|
||||
AT_FINAL_CLEANUP {
|
||||
curl_global_cleanup();
|
||||
};
|
||||
|
||||
|
@ -202,7 +204,7 @@ namespace hex {
|
|||
|
||||
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())
|
||||
return Response<std::string> { 400, {} };
|
||||
|
||||
|
@ -251,7 +253,7 @@ namespace hex {
|
|||
|
||||
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())
|
||||
return Response<void> { 400 };
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::gl {
|
||||
|
||||
Shader::Shader(std::string_view vertexSource, std::string_view fragmentSource) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
#include <hex/helpers/tar.hpp>
|
||||
#include <hex/helpers/literals.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
using namespace hex::literals;
|
||||
|
@ -12,11 +13,11 @@ namespace hex {
|
|||
|
||||
// Explicitly create file so a short path gets generated
|
||||
if (mode == Mode::Create) {
|
||||
fs::File file(path, fs::File::Mode::Create);
|
||||
wolv::io::File file(path, wolv::io::File::Mode::Create);
|
||||
file.flush();
|
||||
}
|
||||
|
||||
auto shortPath = hex::fs::toShortPath(path);
|
||||
auto shortPath = wolv::io::fs::toShortPath(path);
|
||||
if (mode == Tar::Mode::Read)
|
||||
error = mtar_open(&this->m_ctx, shortPath.string().c_str(), "r");
|
||||
else if (mode == Tar::Mode::Write)
|
||||
|
@ -58,7 +59,7 @@ namespace hex {
|
|||
mtar_header_t header;
|
||||
while (mtar_read_header(&this->m_ctx, &header) != MTAR_ENULLRECORD) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -132,7 +133,7 @@ namespace hex {
|
|||
static void writeFile(mtar_t *ctx, mtar_header_t *header, const std::fs::path &path) {
|
||||
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;
|
||||
for (u64 offset = 0; offset < header->size; offset += BufferSize) {
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include <fonts/fontawesome_font.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <hex/helpers/net.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
#include <fonts/fontawesome_font.h>
|
||||
#include <fonts/codicons_font.h>
|
||||
|
@ -23,6 +22,9 @@
|
|||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <wolv/io/fs.hpp>
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex::init {
|
||||
|
||||
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 (!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
|
||||
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 (auto &folder : fs::getDefaultPaths(static_cast<fs::ImHexPath>(path), true)) {
|
||||
try {
|
||||
fs::createDirectories(folder);
|
||||
wolv::io::fs::createDirectories(folder);
|
||||
} catch (...) {
|
||||
log::error("Failed to create folder {}!", hex::toUTF8String(folder));
|
||||
result = false;
|
||||
|
@ -300,7 +302,7 @@ namespace hex::init {
|
|||
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
|
||||
#if !defined(DEBUG)
|
||||
return true;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <hex.hpp>
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include "window.hpp"
|
||||
|
@ -10,16 +9,19 @@
|
|||
|
||||
#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) {
|
||||
using namespace hex;
|
||||
ImHexApi::System::impl::setProgramArguments(argc, argv, envp);
|
||||
|
||||
// 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";
|
||||
|
||||
if (fs::exists(flagFile) && fs::isRegularFile(flagFile))
|
||||
if (wolv::io::fs::exists(flagFile) && wolv::io::fs::isRegularFile(flagFile))
|
||||
ImHexApi::System::impl::setPortableVersion(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -443,7 +443,7 @@ namespace hex {
|
|||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(hex::toUTF8String(filePath).c_str());
|
||||
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();
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ namespace hex {
|
|||
this->m_fileSize = provider->getSize();
|
||||
|
||||
// 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);
|
||||
|
||||
this->processImpl(bytes);
|
||||
|
@ -572,7 +572,7 @@ namespace hex {
|
|||
this->m_endAddress = endAddress;
|
||||
|
||||
// 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);
|
||||
|
||||
this->processImpl(bytes);
|
||||
|
@ -685,7 +685,7 @@ namespace hex {
|
|||
this->m_fileSize = provider->getSize();
|
||||
|
||||
// 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);
|
||||
|
||||
this->processImpl(bytes);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <hex/providers/provider.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
|
@ -56,7 +57,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
protected:
|
||||
std::fs::path m_path;
|
||||
fs::File m_file;
|
||||
wolv::io::File m_file;
|
||||
size_t m_fileSize = 0;
|
||||
|
||||
std::optional<struct stat> m_fileStats;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <hex/helpers/socket.hpp>
|
||||
#include <hex/providers/provider.hpp>
|
||||
|
||||
#include <wolv/utils/socket.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
#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;
|
||||
|
||||
protected:
|
||||
hex::Socket m_socket;
|
||||
wolv::util::Socket m_socket;
|
||||
|
||||
std::string m_ipAddress;
|
||||
int m_port = 0;
|
||||
|
||||
u64 m_size = 0;
|
||||
|
||||
constexpr static size_t CacheLineSize = 0x1000;
|
||||
constexpr static size_t CacheLineSize = 0x10;
|
||||
|
||||
struct CacheLine {
|
||||
u64 address;
|
||||
|
@ -69,6 +70,7 @@ namespace hex::plugin::builtin {
|
|||
};
|
||||
|
||||
std::list<CacheLine> m_cache;
|
||||
std::atomic<bool> m_resetCache = false;
|
||||
|
||||
std::thread m_cacheUpdateThread;
|
||||
std::mutex m_cacheLock;
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
result += start;
|
||||
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
auto reader = prv::ProviderReader(provider);
|
||||
reader.seek(offset);
|
||||
reader.setEndAddress(offset + size - 1);
|
||||
|
||||
|
@ -107,7 +107,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
result += HeaderLine;
|
||||
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
auto reader = prv::ProviderReader(provider);
|
||||
reader.seek(offset);
|
||||
reader.setEndAddress((offset + size) - 1);
|
||||
|
||||
|
@ -158,7 +158,7 @@ namespace hex::plugin::builtin {
|
|||
" <code>\n"
|
||||
" <span class=\"offsetheader\">Hex View  00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F</span>";
|
||||
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
auto reader = prv::ProviderReader(provider);
|
||||
reader.seek(offset);
|
||||
reader.setEndAddress((offset + size) - 1);
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
#include <implot.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
#include <wolv/utils/core.hpp>
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
class NodeNullptr : public dp::Node {
|
||||
|
@ -167,10 +170,10 @@ namespace hex::plugin::builtin {
|
|||
}
|
||||
|
||||
void process() override {
|
||||
this->setBufferOnOutput(0, hex::toBytes<u8>(u8(this->m_color.Value.x * 0xFF)));
|
||||
this->setBufferOnOutput(1, hex::toBytes<u8>(u8(this->m_color.Value.y * 0xFF)));
|
||||
this->setBufferOnOutput(2, hex::toBytes<u8>(u8(this->m_color.Value.z * 0xFF)));
|
||||
this->setBufferOnOutput(3, hex::toBytes<u8>(u8(this->m_color.Value.w * 0xFF)));
|
||||
this->setBufferOnOutput(0, wolv::util::toBytes<u8>(u8(this->m_color.Value.x * 0xFF)));
|
||||
this->setBufferOnOutput(1, wolv::util::toBytes<u8>(u8(this->m_color.Value.y * 0xFF)));
|
||||
this->setBufferOnOutput(2, wolv::util::toBytes<u8>(u8(this->m_color.Value.z * 0xFF)));
|
||||
this->setBufferOnOutput(3, wolv::util::toBytes<u8>(u8(this->m_color.Value.w * 0xFF)));
|
||||
}
|
||||
|
||||
void store(nlohmann::json &j) const override {
|
||||
|
@ -1169,7 +1172,7 @@ namespace hex::plugin::builtin {
|
|||
const auto &outVars = pl.runtime->getOutVariables();
|
||||
|
||||
if (outVars.contains(this->m_name)) {
|
||||
std::visit(overloaded {
|
||||
std::visit(wolv::util::overloaded {
|
||||
[](const std::string &) {},
|
||||
[](pl::ptrn::Pattern *) {},
|
||||
[this](auto &&value) {
|
||||
|
@ -1231,7 +1234,7 @@ namespace hex::plugin::builtin {
|
|||
}
|
||||
|
||||
void process() override {
|
||||
std::visit(overloaded {
|
||||
std::visit(wolv::util::overloaded {
|
||||
[this](i128 value) { this->setIntegerOnOutput(0, value); },
|
||||
[this](long double value) { this->setFloatOnOutput(0, value); },
|
||||
[this](const std::vector<u8> &value) { this->setBufferOnOutput(0, value); }
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
#include <hex/api/event.hpp>
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <hex/providers/provider.hpp>
|
||||
#include <hex/ui/view.hpp>
|
||||
#include <hex/api/localization.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/api/project_file_manager.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <content/helpers/provider_extra_data.hpp>
|
||||
|
||||
#include <content/providers/file_provider.hpp>
|
||||
|
||||
#include <wolv/io/fs.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
static void openFile(const std::fs::path &path) {
|
||||
|
|
|
@ -6,11 +6,14 @@
|
|||
#include <hex/ui/view.hpp>
|
||||
#include <hex/api/keybinding.hpp>
|
||||
#include <hex/api/project_file_manager.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
#include <hex/helpers/crypto.hpp>
|
||||
#include <hex/helpers/patches.hpp>
|
||||
|
||||
#include "content/global_actions.hpp"
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
@ -122,7 +125,7 @@ namespace hex::plugin::builtin {
|
|||
if (ImGui::MenuItem("hex.builtin.menu.file.import.base64"_lang)) {
|
||||
|
||||
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()) {
|
||||
View::showErrorPopup("hex.builtin.menu.file.import.base64.popup.open_error"_lang);
|
||||
return;
|
||||
|
@ -137,7 +140,7 @@ namespace hex::plugin::builtin {
|
|||
View::showErrorPopup("hex.builtin.menu.file.import.base64.popup.import_error"_lang);
|
||||
else {
|
||||
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())
|
||||
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) {
|
||||
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);
|
||||
if (!patch.has_value()) {
|
||||
handleIPSError(patch.error());
|
||||
|
@ -183,7 +186,7 @@ namespace hex::plugin::builtin {
|
|||
if (ImGui::MenuItem("hex.builtin.menu.file.import.ips32"_lang, nullptr, false)) {
|
||||
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
|
||||
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);
|
||||
if (!patch.has_value()) {
|
||||
handleIPSError(patch.error());
|
||||
|
@ -212,7 +215,7 @@ namespace hex::plugin::builtin {
|
|||
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
|
||||
TaskManager::createTask("hex.builtin.common.processing", TaskManager::NoProgress, [path](auto &task) {
|
||||
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()) {
|
||||
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) {
|
||||
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()) {
|
||||
TaskManager::doLater([] {
|
||||
View::showErrorPopup("hex.builtin.menu.file.export.base64.popup.export_error"_lang);
|
||||
|
@ -291,7 +294,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
TaskManager::doLater([data] {
|
||||
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()) {
|
||||
View::showErrorPopup("hex.builtin.menu.file.export.ips.popup.export_error"_lang);
|
||||
return;
|
||||
|
@ -322,7 +325,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
TaskManager::doLater([data] {
|
||||
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()) {
|
||||
View::showErrorPopup("hex.builtin.menu.file.export.ips.popup.export_error"_lang);
|
||||
return;
|
||||
|
|
|
@ -10,9 +10,12 @@
|
|||
#include "content/providers/view_provider.hpp"
|
||||
|
||||
#include <hex/api/project_file_manager.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
void registerProviders() {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <hex/api/project_file_manager.hpp>
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
@ -77,7 +76,7 @@ namespace hex::plugin::builtin {
|
|||
return;
|
||||
|
||||
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())
|
||||
return;
|
||||
|
||||
|
@ -91,7 +90,7 @@ namespace hex::plugin::builtin {
|
|||
}
|
||||
|
||||
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()) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
@ -113,7 +112,7 @@ namespace hex::plugin::builtin {
|
|||
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);
|
||||
}
|
||||
|
@ -221,7 +220,7 @@ namespace hex::plugin::builtin {
|
|||
this->m_readable = 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()) {
|
||||
this->m_writable = false;
|
||||
this->m_readable = false;
|
||||
|
|
|
@ -56,11 +56,15 @@ namespace hex::plugin::builtin {
|
|||
|
||||
}
|
||||
|
||||
void sendAck(Socket &socket) {
|
||||
void sendAck(wolv::util::Socket &socket) {
|
||||
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));
|
||||
|
||||
socket.writeString(packet);
|
||||
|
@ -84,7 +88,7 @@ namespace hex::plugin::builtin {
|
|||
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::memcpy(bytes.data(), buffer, size);
|
||||
|
||||
|
@ -94,10 +98,10 @@ namespace hex::plugin::builtin {
|
|||
|
||||
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"));
|
||||
|
||||
auto ack = socket.readString(1);
|
||||
|
@ -131,7 +135,7 @@ namespace hex::plugin::builtin {
|
|||
}
|
||||
|
||||
bool GDBProvider::isWritable() const {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GDBProvider::isResizable() const {
|
||||
|
@ -168,7 +172,7 @@ namespace hex::plugin::builtin {
|
|||
}
|
||||
|
||||
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 {
|
||||
while (size > 0) {
|
||||
size_t readSize = std::min(size, CacheLineSize);
|
||||
|
@ -251,22 +255,24 @@ namespace hex::plugin::builtin {
|
|||
}
|
||||
|
||||
if (this->m_socket.isConnected()) {
|
||||
gdb::continueExecution(this->m_socket);
|
||||
|
||||
this->m_cacheUpdateThread = std::thread([this]() {
|
||||
auto cacheLine = this->m_cache.begin();
|
||||
while (this->isConnected()) {
|
||||
{
|
||||
std::scoped_lock lock(this->m_cacheLock);
|
||||
|
||||
if (cacheLine != this->m_cache.end()) {
|
||||
auto data = gdb::readMemory(this->m_socket, cacheLine->address, 0x1000);
|
||||
|
||||
if (data.empty()) {
|
||||
this->m_cache.erase(cacheLine);
|
||||
if (this->m_resetCache) {
|
||||
this->m_cache.clear();
|
||||
this->m_resetCache = false;
|
||||
cacheLine = this->m_cache.begin();
|
||||
continue;
|
||||
}
|
||||
|
||||
while (this->m_cache.size() > 5) {
|
||||
if (cacheLine != this->m_cache.end()) {
|
||||
std::vector<u8> data = gdb::readMemory(this->m_socket, cacheLine->address, CacheLineSize);
|
||||
|
||||
while (std::count_if(this->m_cache.begin(), this->m_cache.end(), [&](auto &line) { return !line.data.empty(); }) > 100) {
|
||||
this->m_cache.pop_front();
|
||||
cacheLine = this->m_cache.begin();
|
||||
}
|
||||
|
@ -279,7 +285,7 @@ namespace hex::plugin::builtin {
|
|||
else
|
||||
cacheLine++;
|
||||
}
|
||||
std::this_thread::sleep_for(100ms);
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
#include <hex/api/imhex_api.hpp>
|
||||
#include <hex/api/localization.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
namespace intel_hex {
|
||||
|
@ -192,7 +193,7 @@ namespace hex::plugin::builtin {
|
|||
}
|
||||
|
||||
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())
|
||||
return false;
|
||||
|
||||
|
@ -245,7 +246,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
if (!picked)
|
||||
return false;
|
||||
if (!fs::isRegularFile(this->m_sourceFilePath))
|
||||
if (!wolv::io::fs::isRegularFile(this->m_sourceFilePath))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
#include <hex/api/imhex_api.hpp>
|
||||
#include <hex/api/localization.hpp>
|
||||
#include <hex/api/event.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
|
@ -50,7 +51,7 @@ namespace hex::plugin::builtin {
|
|||
}
|
||||
|
||||
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()) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
#include <hex/api/localization.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <wolv/io/fs.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
namespace motorola_srec {
|
||||
|
@ -168,7 +170,7 @@ namespace hex::plugin::builtin {
|
|||
}
|
||||
|
||||
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())
|
||||
return false;
|
||||
|
||||
|
@ -222,7 +224,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
if (!picked)
|
||||
return false;
|
||||
if (!fs::isRegularFile(this->m_sourceFilePath))
|
||||
if (!wolv::io::fs::isRegularFile(this->m_sourceFilePath))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include <ui/pattern_drawer.hpp>
|
||||
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<std::fs::path> userFolders;
|
||||
|
@ -566,14 +568,14 @@ namespace hex::plugin::builtin {
|
|||
|
||||
static void loadFontSettings() {
|
||||
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();
|
||||
|
||||
// If no custom font has been specified, search for a file called "font.ttf" in one of the resource folders
|
||||
if (fontFile.empty()) {
|
||||
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Resources)) {
|
||||
auto path = dir / "font.ttf";
|
||||
if (fs::exists(path)) {
|
||||
if (wolv::io::fs::exists(path)) {
|
||||
log::info("Loading custom front from {}", hex::toUTF8String(path));
|
||||
|
||||
fontFile = path;
|
||||
|
|
|
@ -10,10 +10,11 @@
|
|||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
#include <hex/api/event.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
void registerThemeHandlers() {
|
||||
|
@ -334,7 +335,7 @@ namespace hex::plugin::builtin {
|
|||
for (const auto &themeFolder : fs::getDefaultPaths(fs::ImHexPath::Themes)) {
|
||||
for (const auto &theme : std::fs::directory_iterator(themeFolder)) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <hex/helpers/net.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/literals.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/api/localization.hpp>
|
||||
|
@ -27,6 +26,9 @@
|
|||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
namespace {
|
||||
|
@ -747,7 +749,7 @@ namespace hex::plugin::builtin {
|
|||
ON_SCOPE_EXIT {
|
||||
selectedFile.clear();
|
||||
};
|
||||
fs::File file(selectedFile, fs::File::Mode::Write);
|
||||
wolv::io::File file(selectedFile, wolv::io::File::Mode::Write);
|
||||
|
||||
if (!file.isValid()) {
|
||||
View::showErrorPopup("hex.builtin.tools.file_tools.shredder.error.open"_lang);
|
||||
|
@ -912,7 +914,7 @@ namespace hex::plugin::builtin {
|
|||
baseOutputPath.clear();
|
||||
};
|
||||
|
||||
fs::File file(selectedFile, fs::File::Mode::Read);
|
||||
wolv::io::File file(selectedFile, wolv::io::File::Mode::Read);
|
||||
|
||||
if (!file.isValid()) {
|
||||
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;
|
||||
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()) {
|
||||
View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.splitter.picker.error.create"_lang, index));
|
||||
|
@ -1046,7 +1048,7 @@ namespace hex::plugin::builtin {
|
|||
else {
|
||||
if (ImGui::Button("hex.builtin.tools.file_tools.combiner.combine"_lang)) {
|
||||
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()) {
|
||||
View::showErrorPopup("hex.builtin.tools.file_tools.combiner.error.open_output"_lang);
|
||||
|
@ -1060,7 +1062,7 @@ namespace hex::plugin::builtin {
|
|||
task.update(fileIndex);
|
||||
fileIndex++;
|
||||
|
||||
fs::File input(file, fs::File::Mode::Read);
|
||||
wolv::io::File input(file, wolv::io::File::Mode::Read);
|
||||
if (!input.isValid()) {
|
||||
View::showErrorPopup(hex::format("hex.builtin.tools.file_tools.combiner.open_input"_lang, hex::toUTF8String(file)));
|
||||
return;
|
||||
|
|
|
@ -171,7 +171,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
ImGui::TableNextColumn();
|
||||
for (auto &path : fs::getDefaultPaths(type, true)){
|
||||
if(fs::isDirectory(path)){
|
||||
if(wolv::io::fs::isDirectory(path)){
|
||||
ImGui::TextUnformatted(hex::toUTF8String(path).c_str());
|
||||
}else{
|
||||
ImGui::TextFormattedColored(ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed), hex::toUTF8String(path).c_str());
|
||||
|
|
|
@ -4,13 +4,15 @@
|
|||
#include <hex/api/project_file_manager.hpp>
|
||||
#include <hex/providers/provider.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <cstring>
|
||||
|
||||
#include <content/helpers/provider_extra_data.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
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)) {
|
||||
fs::openFileBrowser(fs::DialogMode::Open, { { "Bookmarks File", "hexbm"} }, [&](const std::fs::path &path) {
|
||||
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 (...) { }
|
||||
});
|
||||
}
|
||||
|
@ -397,7 +399,7 @@ namespace hex::plugin::builtin {
|
|||
nlohmann::json 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));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace hex::plugin::builtin {
|
|||
this->m_filterIndices.clear();
|
||||
|
||||
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;
|
||||
for (auto &file : std::fs::directory_iterator(path, error)) {
|
||||
|
|
|
@ -7,12 +7,13 @@
|
|||
#include <cstring>
|
||||
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
#include <pl/pattern_language.hpp>
|
||||
#include <pl/core/evaluator.hpp>
|
||||
#include <pl/patterns/pattern.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
using NumberDisplayStyle = ContentRegistry::DataInspector::NumberDisplayStyle;
|
||||
|
@ -106,7 +107,7 @@ namespace hex::plugin::builtin {
|
|||
if (!filePath.exists() || !filePath.is_regular_file() || filePath.path().extension() != ".hexpat")
|
||||
continue;
|
||||
|
||||
fs::File file(filePath, fs::File::Mode::Read);
|
||||
wolv::io::File file(filePath, wolv::io::File::Mode::Read);
|
||||
if (file.isValid()) {
|
||||
auto inspectorCode = file.readString();
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <hex/providers/provider.hpp>
|
||||
|
@ -14,6 +13,8 @@
|
|||
|
||||
#include <content/helpers/provider_extra_data.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
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)) {
|
||||
fs::openFileBrowser(fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } },
|
||||
[&](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()) {
|
||||
ViewDataProcessor::loadNodes(data.mainWorkspace, file.readString());
|
||||
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)) {
|
||||
fs::openFileBrowser(fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } },
|
||||
[&](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())
|
||||
file.write(ViewDataProcessor::saveNodes(data.mainWorkspace).dump(4));
|
||||
});
|
||||
|
@ -92,7 +93,7 @@ namespace hex::plugin::builtin {
|
|||
});
|
||||
|
||||
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;
|
||||
|
||||
auto &data = ProviderExtraData::getCurrent().dataProcessor;
|
||||
|
@ -204,7 +205,7 @@ namespace hex::plugin::builtin {
|
|||
for (const auto &entry : std::fs::recursive_directory_iterator(basePath)) {
|
||||
if (entry.path().extension() == ".hexnode") {
|
||||
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 });
|
||||
} catch (nlohmann::json::exception &e) {
|
||||
|
@ -320,7 +321,7 @@ namespace hex::plugin::builtin {
|
|||
if (it != workspace.nodes.end()) {
|
||||
auto &node = *it;
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -141,8 +141,8 @@ namespace hex::plugin::builtin {
|
|||
this->m_diffTask = TaskManager::createTask("Diffing...", commonSize, [this, providerA, providerB](Task &task) {
|
||||
std::vector<Diff> differences;
|
||||
|
||||
auto readerA = prv::BufferedReader(providerA);
|
||||
auto readerB = prv::BufferedReader(providerB);
|
||||
auto readerA = prv::ProviderReader(providerA);
|
||||
auto readerB = prv::ProviderReader(providerB);
|
||||
|
||||
for (auto itA = readerA.begin(), itB = readerB.begin(); itA < readerA.end() && itB < readerB.end(); itA++, itB++) {
|
||||
if (task.wasInterrupted())
|
||||
|
|
|
@ -236,7 +236,7 @@ namespace hex::plugin::builtin {
|
|||
return results;
|
||||
}
|
||||
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
auto reader = prv::ProviderReader(provider);
|
||||
reader.seek(searchRegion.getStartAddress());
|
||||
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<Occurrence> results;
|
||||
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
auto reader = prv::ProviderReader(provider);
|
||||
reader.seek(searchRegion.getStartAddress());
|
||||
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<Occurrence> results;
|
||||
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
auto reader = prv::ProviderReader(provider);
|
||||
reader.seek(searchRegion.getStartAddress());
|
||||
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<Occurrence> results;
|
||||
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
auto reader = prv::ProviderReader(provider);
|
||||
reader.seek(searchRegion.getStartAddress());
|
||||
reader.setEndAddress(searchRegion.getEndAddress());
|
||||
|
||||
|
|
|
@ -292,7 +292,7 @@ namespace hex::plugin::builtin {
|
|||
std::optional<Region> findSequence(const std::vector<u8> &sequence, bool backwards) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
hex::prv::BufferedReader reader(provider);
|
||||
prv::ProviderReader reader(provider);
|
||||
|
||||
reader.seek(this->m_searchPosition.value_or(provider->getBaseAddress()));
|
||||
|
||||
|
@ -605,7 +605,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
auto reader = prv::ProviderReader (provider);
|
||||
reader.seek(selection.getStartAddress());
|
||||
reader.setEndAddress(selection.getEndAddress());
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
ContentRegistry::FileHandler::add({ ".mgc" }, [](const auto &path) {
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ namespace hex::plugin::builtin {
|
|||
provider->getBaseAddress(), provider->getSize());
|
||||
|
||||
// Create a handle to the file
|
||||
auto reader = prv::BufferedReader(provider);
|
||||
auto reader = prv::ProviderReader(provider);
|
||||
reader.seek(provider->getBaseAddress() + this->m_inputStartAddress);
|
||||
reader.setEndAddress(provider->getBaseAddress() + this->m_inputEndAddress);
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/api/project_file_manager.hpp>
|
||||
#include <hex/helpers/magic.hpp>
|
||||
|
||||
|
@ -20,6 +19,10 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
#include <chrono>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <wolv/io/fs.hpp>
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
using namespace hex::literals;
|
||||
|
@ -633,7 +636,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
|
||||
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()) {
|
||||
auto code = file.readString();
|
||||
|
||||
|
@ -808,7 +811,7 @@ namespace hex::plugin::builtin {
|
|||
if (!entry.is_regular_file())
|
||||
continue;
|
||||
|
||||
fs::File file(entry.path(), fs::File::Mode::Read);
|
||||
wolv::io::File file(entry.path(), wolv::io::File::Mode::Read);
|
||||
if (!file.isValid())
|
||||
continue;
|
||||
|
||||
|
@ -871,7 +874,7 @@ namespace hex::plugin::builtin {
|
|||
std::vector<std::fs::path> paths;
|
||||
|
||||
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;
|
||||
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)) {
|
||||
fs::openFileBrowser(fs::DialogMode::Save, { {"Pattern", "hexpat"} },
|
||||
[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());
|
||||
});
|
||||
|
@ -969,7 +972,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
void ViewPatternEditor::registerHandlers() {
|
||||
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()) {
|
||||
EventManager::post<RequestSetPatternLanguageCode>(file.readString());
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <hex/helpers/crypto.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/magic.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/tar.hpp>
|
||||
|
||||
|
@ -19,6 +18,8 @@
|
|||
#include <functional>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
|
@ -166,11 +167,11 @@ namespace hex::plugin::builtin {
|
|||
|
||||
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;
|
||||
|
||||
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());
|
||||
|
||||
auto fileHash = crypt::sha256(data);
|
||||
|
@ -227,7 +228,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
auto fullPath = path / std::fs::path(fileName);
|
||||
|
||||
if (!update || fs::exists(fullPath)) {
|
||||
if (!update || wolv::io::fs::exists(fullPath)) {
|
||||
downloading = true;
|
||||
this->m_downloadPath = fullPath;
|
||||
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 folderPath = (path / std::fs::path(fileName).stem());
|
||||
|
||||
fs::remove(filePath);
|
||||
fs::removeAll(folderPath);
|
||||
wolv::io::fs::remove(filePath);
|
||||
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;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <hex/api/theme_manager.hpp>
|
||||
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <wolv/io/file.hpp>
|
||||
|
||||
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){
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <hex/api/project_file_manager.hpp>
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
|
||||
#include "content/helpers/provider_extra_data.hpp"
|
||||
|
@ -18,6 +17,10 @@
|
|||
#include <filesystem>
|
||||
#include <thread>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <wolv/io/fs.hpp>
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
ViewYara::ViewYara() : View("hex.builtin.view.yara.name") {
|
||||
|
@ -25,7 +28,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
ContentRegistry::FileHandler::add({ ".yar", ".yara" }, [](const auto &path) {
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
@ -261,12 +264,12 @@ namespace hex::plugin::builtin {
|
|||
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(
|
||||
compiler,
|
||||
[](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())
|
||||
return nullptr;
|
||||
|
||||
|
@ -285,7 +288,7 @@ namespace hex::plugin::builtin {
|
|||
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 (yr_compiler_add_file(compiler, file.getHandle(), nullptr, nullptr) != 0) {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <hex/ui/view.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
#include <hex/api/project_file_manager.hpp>
|
||||
|
||||
|
@ -18,6 +17,10 @@
|
|||
#include <nlohmann/json.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 <string>
|
||||
|
@ -85,7 +88,7 @@ namespace hex::plugin::builtin {
|
|||
for (u32 i = 0; i < recentFilePaths.size() && uniqueProviders.size() < 5; i++) {
|
||||
auto &path = recentFilePaths[i];
|
||||
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 {
|
||||
.displayName = jsonData["displayName"],
|
||||
.type = jsonData["type"],
|
||||
|
@ -179,14 +182,14 @@ namespace hex::plugin::builtin {
|
|||
for (const auto &provider : ImHexApi::Provider::getProviders())
|
||||
provider->markDirty();
|
||||
|
||||
fs::remove(s_safetyBackupPath);
|
||||
wolv::io::fs::remove(s_safetyBackupPath);
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::SetCursorPosX(width / 9 * 5);
|
||||
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();
|
||||
}
|
||||
|
@ -476,7 +479,7 @@ namespace hex::plugin::builtin {
|
|||
{
|
||||
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()));
|
||||
fs::File recentFile(recentPath / fileName, fs::File::Mode::Create);
|
||||
wolv::io::File recentFile(recentPath / fileName, wolv::io::File::Mode::Create);
|
||||
if (!recentFile.isValid())
|
||||
continue;
|
||||
|
||||
|
@ -550,7 +553,7 @@ namespace hex::plugin::builtin {
|
|||
|
||||
constexpr static auto CrashBackupFileName = "crash_backup.hexproj";
|
||||
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;
|
||||
TaskManager::doLater([] { ImGui::OpenPopup("hex.builtin.welcome.safety_backup.title"_lang); });
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
#include <hex/helpers/fmt.hpp>
|
||||
#include <hex/ui/view.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::plugin::windows {
|
||||
|
||||
bool ProcessMemoryProvider::open() {
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
#include <wolv/utils/guards.hpp>
|
||||
|
||||
namespace hex::plugin::windows {
|
||||
|
||||
ViewTTYConsole::ViewTTYConsole() : View("hex.windows.view.tty_console.name") {
|
||||
|
|
Loading…
Reference in New Issue