Skip to content

Commit

Permalink
Early work on API, no implementation, just trying to get a feel for a…
Browse files Browse the repository at this point in the history
… nice API
  • Loading branch information
xforce committed Jun 22, 2019
1 parent e24eded commit 7c8222b
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 0 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --cpu=x64_windows --host_cpu=x64_windows --incompatible_windows_native_test_wrapper --shell_executable="cmd" --copt="/D_ITERATOR_DEBUG_LEVEL=0" --cxxopt=-std:c++latest --define internal=1
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[submodule "third_party/spdlog"]
path = third_party/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "third_party/zydis"]
path = third_party/zydis
url = https://github.com/zyantific/zydis.git
[submodule "third_party/asmjit"]
path = third_party/asmjit
url = https://github.com/asmjit/asmjit.git
12 changes: 12 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cc_library(
name = "meow-hook",
srcs = glob(["src/**/*.cc"]) + glob(["src/**/*.h"]),
hdrs = glob(["include/**/*.h"]),
includes = [
"include",
],
deps = [
"//third_party:asmjit",
"//third_party:zydis",
],
)
60 changes: 60 additions & 0 deletions include/meow_hook/detour.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include <cstdint>

namespace meow_hook
{

namespace detail
{
template <class T> class detour;

template <typename Ret, typename... Args> //
class detour<Ret(Args...)>;

class detour_base
{
public:
detour_base(uintptr_t address, void *func)
: address_(address)
, function_(func)
{
//
}
virtual ~detour_base() = default;

private:
void hook();
void unhook();

uintptr_t address_ = 0;
void * function_ = nullptr;

template <class T> friend class detour;
};

template <typename Ret, typename... Args> //
class detour<Ret(Args...)> : public detour_base
{
public:
using function_t = Ret(Args...);

//
detour(uintptr_t address, function_t *fn)
: detour_base(address, fn)
{
// Hook
detour_base::hook();
}

~detour() override
{
// Unhook
detour_base::unhook();
}
};

} // namespace detail

template <typename T> using detour = detail::detour<T>;
} // namespace meow_hook
Empty file.
15 changes: 15 additions & 0 deletions src/detour.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "meow_hook/detour.h"

namespace meow_hook::detail
{
void detour_base::hook()
{
//
}

void detour_base::unhook()
{
//
}

} // namespace meow_hook::detail
18 changes: 18 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <Zydis/Zydis.h>

#include "meow_hook/detour.h"

bool hook(int)
{
return false;
}

int main()
{
ZydisDecoder decoder;
ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_ADDRESS_WIDTH_64);

meow_hook::detour<bool(int)> detour(0x0, hook);

return 0;
}
Empty file added tests/BUILD
Empty file.
58 changes: 58 additions & 0 deletions third_party/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
cc_library(
name = "spdlog",
defines = [
"SPDLOG_WCHAR_FILENAMES"
],
hdrs = glob(["spdlog/include/**/*.h"]),
includes = [
"spdlog/include",
],
visibility = ["//visibility:public"],
)

cc_library(
name = "zycore",
hdrs = glob(["zydis/dependencies/zycore/include/**/*.h"]),
srcs = glob(["zydis/dependencies/zycore/src/**/*.c"]),
defines = [
"ZYCORE_STATIC_DEFINE"
],
includes = [
"zydis/dependencies/zycore/include",
] + select({
"@bazel_tools//src/conditions:windows": ["zydis/msvc"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
)

cc_library(
name = "zydis",
hdrs = glob(["zydis/include/**/*.h"]),
srcs = glob(["zydis/src/**/*.c", "zydis/src/**/*.inc"]),
defines = [
"ZYDIS_STATIC_DEFINE"
],
includes = [
"zydis/include",
] + select({
"@bazel_tools//src/conditions:windows": ["zydis/msvc"],
"//conditions:default": [],
}),
copts = ["-Ithird_party/zydis/src"], # GOD THIS SUCKS SOOOOO MUCH, WHY BAZEL WHY, I LIKE YOU BUT INCLUDE PATHS ARE JUST GARBAGE
visibility = ["//visibility:public"],
deps = [
":zycore"
]
)

cc_library(
name = "asmjit",
defines = [ ],
hdrs = glob(["asmjit/src/**/*.h"]),
srcs = glob(["asmjit/src/**/*.cpp"]),
includes = [
"asmjit/src",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions third_party/asmjit
Submodule asmjit added at 423eb0
1 change: 1 addition & 0 deletions third_party/spdlog
Submodule spdlog added at ea5f07
1 change: 1 addition & 0 deletions third_party/zydis
Submodule zydis added at 93eba1
1 change: 1 addition & 0 deletions tools/lavender
Submodule lavender added at 7c291f

0 comments on commit 7c8222b

Please sign in to comment.