From ba386a7928f10f755c864331485be3a6f8970984 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 21 Sep 2024 21:30:56 +0200 Subject: [PATCH] Small fixes --- src/common/utils/nt_handle.hpp | 22 +++++++++++++++++----- src/windows_emulator/handles.hpp | 10 ++++++---- src/windows_emulator/logger.hpp | 10 +++++----- src/windows_emulator/process_context.hpp | 2 +- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/common/utils/nt_handle.hpp b/src/common/utils/nt_handle.hpp index 5ed9ceec..0545027e 100644 --- a/src/common/utils/nt_handle.hpp +++ b/src/common/utils/nt_handle.hpp @@ -8,7 +8,19 @@ namespace utils::nt { - template + using HandleFunction = HANDLE(); + + inline HANDLE null_handle() + { + return nullptr; + } + + inline HANDLE invalid_handle() + { + return INVALID_HANDLE_VALUE; + } + + template class handle { public: @@ -24,7 +36,7 @@ namespace utils::nt if (*this) { CloseHandle(this->handle_); - this->handle_ = InvalidHandle; + this->handle_ = InvalidHandleFunction(); } } @@ -43,7 +55,7 @@ namespace utils::nt { this->~handle(); this->handle_ = obj.handle_; - obj.handle_ = InvalidHandle; + obj.handle_ = InvalidHandleFunction(); } return *this; @@ -59,7 +71,7 @@ namespace utils::nt [[nodiscard]] operator bool() const { - return this->handle_ != InvalidHandle; + return this->handle_ != InvalidHandleFunction(); } [[nodiscard]] operator HANDLE() const @@ -68,6 +80,6 @@ namespace utils::nt } private: - HANDLE handle_{InvalidHandle}; + HANDLE handle_{InvalidHandleFunction()}; }; } diff --git a/src/windows_emulator/handles.hpp b/src/windows_emulator/handles.hpp index c557a8cd..97d16683 100644 --- a/src/windows_emulator/handles.hpp +++ b/src/windows_emulator/handles.hpp @@ -77,7 +77,9 @@ namespace handle_detail template struct has_deleter_function()))>> - : std::is_same())), bool> {}; + : std::is_same())), bool> + { + }; } template @@ -145,7 +147,7 @@ public: return false; } } - + this->store_.erase(entry); return true; } @@ -173,7 +175,8 @@ public: buffer.read_map(this->store_); } - value_map::iterator begin() { + value_map::iterator begin() + { return this->store_.begin(); } @@ -193,7 +196,6 @@ public: } private: - typename value_map::iterator get_iterator(const handle_value h) { if (h.type != Type || h.is_pseudo) diff --git a/src/windows_emulator/logger.hpp b/src/windows_emulator/logger.hpp index 9e48d37a..3734b55a 100644 --- a/src/windows_emulator/logger.hpp +++ b/src/windows_emulator/logger.hpp @@ -19,31 +19,31 @@ class logger public: void print(color c, const char* message, ...) const; - template + template void info(const char* message, Args... args) { this->print(color::cyan, message, args...); } - template + template void warn(const char* message, Args... args) { this->print(color::yellow, message, args...); } - template + template void error(const char* message, Args... args) { this->print(color::red, message, args...); } - template + template void success(const char* message, Args... args) { this->print(color::green, message, args...); } - template + template void log(const char* message, Args... args) { this->print(color::gray, message, args...); diff --git a/src/windows_emulator/process_context.hpp b/src/windows_emulator/process_context.hpp index b0dd109c..1de4e4c6 100644 --- a/src/windows_emulator/process_context.hpp +++ b/src/windows_emulator/process_context.hpp @@ -51,7 +51,7 @@ struct event struct file { - utils::nt::handle handle{}; + utils::nt::handle handle{}; std::wstring name{}; void serialize(utils::buffer_serializer& buffer) const