Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
momo5502 committed Sep 21, 2024
1 parent d2a5f94 commit ba386a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
22 changes: 17 additions & 5 deletions src/common/utils/nt_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@

namespace utils::nt
{
template <HANDLE InvalidHandle = nullptr>
using HandleFunction = HANDLE();

inline HANDLE null_handle()
{
return nullptr;
}

inline HANDLE invalid_handle()
{
return INVALID_HANDLE_VALUE;
}

template <HandleFunction InvalidHandleFunction = null_handle>
class handle
{
public:
Expand All @@ -24,7 +36,7 @@ namespace utils::nt
if (*this)
{
CloseHandle(this->handle_);
this->handle_ = InvalidHandle;
this->handle_ = InvalidHandleFunction();
}
}

Expand All @@ -43,7 +55,7 @@ namespace utils::nt
{
this->~handle();
this->handle_ = obj.handle_;
obj.handle_ = InvalidHandle;
obj.handle_ = InvalidHandleFunction();
}

return *this;
Expand All @@ -59,7 +71,7 @@ namespace utils::nt

[[nodiscard]] operator bool() const
{
return this->handle_ != InvalidHandle;
return this->handle_ != InvalidHandleFunction();
}

[[nodiscard]] operator HANDLE() const
Expand All @@ -68,6 +80,6 @@ namespace utils::nt
}

private:
HANDLE handle_{InvalidHandle};
HANDLE handle_{InvalidHandleFunction()};
};
}
10 changes: 6 additions & 4 deletions src/windows_emulator/handles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ namespace handle_detail

template <typename T>
struct has_deleter_function<T, std::void_t<decltype(T::deleter(std::declval<T&>()))>>
: std::is_same<decltype(T::deleter(std::declval<T&>())), bool> {};
: std::is_same<decltype(T::deleter(std::declval<T&>())), bool>
{
};
}

template <handle_types::type Type, typename T>
Expand Down Expand Up @@ -145,7 +147,7 @@ class handle_store
return false;
}
}

this->store_.erase(entry);
return true;
}
Expand Down Expand Up @@ -173,7 +175,8 @@ class handle_store
buffer.read_map(this->store_);
}

value_map::iterator begin() {
value_map::iterator begin()
{
return this->store_.begin();
}

Expand All @@ -193,7 +196,6 @@ class handle_store
}

private:

typename value_map::iterator get_iterator(const handle_value h)
{
if (h.type != Type || h.is_pseudo)
Expand Down
10 changes: 5 additions & 5 deletions src/windows_emulator/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ class logger
public:
void print(color c, const char* message, ...) const;

template<typename... Args>
template <typename... Args>
void info(const char* message, Args... args)
{
this->print(color::cyan, message, args...);
}

template<typename... Args>
template <typename... Args>
void warn(const char* message, Args... args)
{
this->print(color::yellow, message, args...);
}

template<typename... Args>
template <typename... Args>
void error(const char* message, Args... args)
{
this->print(color::red, message, args...);
}

template<typename... Args>
template <typename... Args>
void success(const char* message, Args... args)
{
this->print(color::green, message, args...);
}

template<typename... Args>
template <typename... Args>
void log(const char* message, Args... args)
{
this->print(color::gray, message, args...);
Expand Down
2 changes: 1 addition & 1 deletion src/windows_emulator/process_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct event

struct file
{
utils::nt::handle<INVALID_HANDLE_VALUE> handle{};
utils::nt::handle<utils::nt::invalid_handle> handle{};
std::wstring name{};

void serialize(utils::buffer_serializer& buffer) const
Expand Down

0 comments on commit ba386a7

Please sign in to comment.