mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-19 11:43:56 +00:00
Fix warnings
This commit is contained in:
@@ -1,55 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
#include <utils/object.hpp>
|
||||
|
||||
template <typename T>
|
||||
T resolve_indexed_argument_internal(size_t* args, size_t& index)
|
||||
template <typename T, size_t N>
|
||||
T resolve_indexed_argument_internal(const std::array<size_t, N>& args, size_t& index)
|
||||
{
|
||||
const auto a1 = args[index++];
|
||||
|
||||
if constexpr (sizeof(T) <= sizeof(a1) || sizeof(size_t) > 4)
|
||||
{
|
||||
return (T)(a1);
|
||||
return T(a1);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto a2 = args[index++];
|
||||
|
||||
const auto arg = (a1 | (static_cast<uint64_t>(a2) << 32));
|
||||
return (T)(arg);
|
||||
return T(arg);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T resolve_indexed_argument(size_t* args, size_t& index)
|
||||
template <typename T, size_t N>
|
||||
T resolve_indexed_argument(const std::array<size_t, N>& args, size_t& index)
|
||||
{
|
||||
auto arg = resolve_indexed_argument_internal<T>(args, index);
|
||||
auto arg = resolve_indexed_argument_internal<T, N>(args, index);
|
||||
return arg;
|
||||
}
|
||||
|
||||
template <typename ReturnType, typename... Args>
|
||||
class function_wrapper2 : public utils::object
|
||||
class function_wrapper_tcg : public utils::object
|
||||
{
|
||||
public:
|
||||
using user_data_pointer = void*;
|
||||
using c_function_type = ReturnType(Args..., user_data_pointer);
|
||||
using functor_type = std::function<ReturnType(Args...)>;
|
||||
|
||||
function_wrapper2() = default;
|
||||
function_wrapper_tcg() = default;
|
||||
|
||||
function_wrapper2(functor_type functor)
|
||||
function_wrapper_tcg(functor_type functor)
|
||||
: functor_(std::make_unique<functor_type>(std::move(functor)))
|
||||
{
|
||||
}
|
||||
|
||||
c_function_type* get_c_function() const
|
||||
{
|
||||
return (c_function_type*)(void*)+[](size_t a1, size_t a2, size_t a3, size_t a4, size_t a5, size_t a6, size_t a7,
|
||||
size_t a8, size_t a9, size_t a10, size_t a11, size_t a12) -> uint64_t {
|
||||
size_t real_args[]{a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12};
|
||||
auto* func = +[](const size_t a1, const size_t a2, const size_t a3, const size_t a4, const size_t a5,
|
||||
const size_t a6, const size_t a7, const size_t a8, const size_t a9, const size_t a10,
|
||||
const size_t a11, const size_t a12) -> uint64_t {
|
||||
const std::array arguments = {a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12};
|
||||
|
||||
const auto lambda = +[](Args... args, user_data_pointer user_data) -> ReturnType {
|
||||
return (*static_cast<functor_type*>(user_data))(std::forward<Args>(args)...);
|
||||
@@ -57,19 +59,21 @@ class function_wrapper2 : public utils::object
|
||||
|
||||
size_t index = 0;
|
||||
std::tuple<Args..., user_data_pointer> func_args{
|
||||
resolve_indexed_argument<std::remove_cv_t<std::remove_reference_t<Args>>>(real_args, index)...,
|
||||
resolve_indexed_argument<user_data_pointer>(real_args, index)};
|
||||
resolve_indexed_argument<std::remove_cv_t<std::remove_reference_t<Args>>>(arguments, index)...,
|
||||
resolve_indexed_argument<user_data_pointer>(arguments, index)};
|
||||
|
||||
(void)index;
|
||||
|
||||
if constexpr (!std::is_void_v<ReturnType>)
|
||||
{
|
||||
return (uint64_t)std::apply(lambda, std::move(func_args));
|
||||
return uint64_t(std::apply(lambda, std::move(func_args)));
|
||||
}
|
||||
|
||||
std::apply(lambda, std::move(func_args));
|
||||
return 0;
|
||||
};
|
||||
|
||||
return reinterpret_cast<c_function_type*>(reinterpret_cast<void*>(func));
|
||||
}
|
||||
|
||||
void* get_function() const
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "unicorn_hook.hpp"
|
||||
|
||||
#include "function_wrapper.hpp"
|
||||
#include "function_wrapper2.hpp"
|
||||
#include "function_wrapper_tcg.hpp"
|
||||
#include <ranges>
|
||||
|
||||
namespace unicorn
|
||||
@@ -386,7 +386,6 @@ namespace unicorn
|
||||
|
||||
emulator_hook* hook_instruction(const int instruction_type, instruction_hook_callback callback) override
|
||||
{
|
||||
|
||||
unicorn_hook hook{*this};
|
||||
auto container = std::make_unique<hook_container>();
|
||||
|
||||
@@ -400,19 +399,18 @@ namespace unicorn
|
||||
|
||||
uce(uc_hook_add(*this, hook.make_reference(), UC_HOOK_INSN_INVALID, wrapper.get_function(),
|
||||
wrapper.get_user_data(), 0, std::numeric_limits<pointer_type>::max()));
|
||||
container->add(std::move(wrapper), std::move(hook));
|
||||
}
|
||||
else if(inst_type == x64_hookable_instructions::syscall){
|
||||
function_wrapper<void, uc_engine*> wrapper([c = std::move(callback)](uc_engine*) {
|
||||
c();
|
||||
});
|
||||
container->add(std::move(wrapper), std::move(hook));
|
||||
}
|
||||
else if (inst_type == x64_hookable_instructions::syscall)
|
||||
{
|
||||
function_wrapper<void, uc_engine*> wrapper([c = std::move(callback)](uc_engine*) { c(); });
|
||||
|
||||
const auto uc_instruction = map_hookable_instruction(inst_type);
|
||||
uce(uc_hook_add(*this, hook.make_reference(), UC_HOOK_INSN, wrapper.get_function(),
|
||||
wrapper.get_user_data(), 0, std::numeric_limits<pointer_type>::max(),
|
||||
uc_instruction));
|
||||
|
||||
container->add(std::move(wrapper), std::move(hook));
|
||||
container->add(std::move(wrapper), std::move(hook));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -425,7 +423,7 @@ namespace unicorn
|
||||
wrapper.get_user_data(), 0, std::numeric_limits<pointer_type>::max(),
|
||||
uc_instruction));
|
||||
|
||||
container->add(std::move(wrapper), std::move(hook));
|
||||
container->add(std::move(wrapper), std::move(hook));
|
||||
}
|
||||
|
||||
auto* result = container->as_opaque_hook();
|
||||
@@ -552,7 +550,7 @@ namespace unicorn
|
||||
c(address); //
|
||||
};
|
||||
|
||||
function_wrapper2<void, uc_engine*, uint64_t, uint32_t> wrapper(std::move(exec_wrapper));
|
||||
function_wrapper_tcg<void, uc_engine*, uint64_t, uint32_t> wrapper(std::move(exec_wrapper));
|
||||
|
||||
unicorn_hook hook{*this};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user