remotemono
RMonoAPIFunctionRaw_Def.h
1 /*
2  Copyright 2020 David "Alemarius Nexus" Lerch
3 
4  This file is part of RemoteMono.
5 
6  RemoteMono is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  RemoteMono is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with RemoteMono. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include "../config.h"
23 
24 #include <type_traits>
25 #include <BlackBone/Process/Process.h>
26 #include <BlackBone/Process/RPC/RemoteFunction.hpp>
27 #include "RMonoAPIFunctionTypeAdapters.h"
28 #include "RMonoAPIFunctionSimple_Def.h"
29 #include "RMonoAPIFunctionCommon_Def.h"
30 
31 
32 namespace remotemono
33 {
34 
35 
36 
37 // **************************************************************
38 // * *
39 // * BASE CLASS *
40 // * *
41 // **************************************************************
42 
43 
48 template <class CommonT, typename ABI, typename RetT, typename... ArgsT>
50 {
51 public:
52  typedef RetT RawRetType;
53  typedef std::tuple<ArgsT...> RawArgsTuple;
54 
55  typedef RMonoAPIFunctionSimple<RetT, ArgsT...> RawFunc;
56 
57 public:
60 
61  void initRaw(blackbone::ptr_t rawFuncAddr)
62  {
63  this->rawFunc.rebuild(getRemoteMonoAPI()->getProcess(), rawFuncAddr, getRemoteMonoAPI()->getWorkerThread());
64  }
65 
66  RetT invokeRaw(ArgsT... args) { return rawFunc(args...); }
67 
68  blackbone::ptr_t getRawFuncAddress() const { return rawFunc.getAddress(); }
69 
70 private:
71  RMonoAPIBase* getRemoteMonoAPI() { return static_cast<CommonT*>(this)->getRemoteMonoAPI(); }
72 
73 protected:
74  RawFunc rawFunc;
75 };
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 // **************************************************************
86 // * *
87 // * ADAPTER CHAIN *
88 // * *
89 // **************************************************************
90 
91 // Can be used to adapt the definition types into the API types, e.g. by adding, changing or removing arguments.
92 
93 template <typename CommonT, typename ABI, typename RetT, typename... ArgsT>
95  CommonT,
96  ABI,
97  typename RMonoAPIReturnTypeAdapter<ABI, RetT>::RawType,
98  typename RMonoAPIParamTypeAdapter<ABI, ArgsT>::RawType...
99  > {};
100 
101 
102 template <typename Enable, typename CommonT, typename ABI, typename RetT, typename... ArgsT>
103 class RMonoAPIFunctionRawAdapter : public RMonoAPIFunctionRawAdapterFinal<CommonT, ABI, RetT, ArgsT...> {};
104 
105 
106 
107 
108 
109 
110 // **************************************************************
111 // * *
112 // * FRONT CLASS *
113 // * *
114 // **************************************************************
115 
116 
122 template <typename CommonT, typename ABI, typename RetT, typename... ArgsT>
123 class RMonoAPIFunctionRaw : public RMonoAPIFunctionRawAdapter<void, CommonT, ABI, RetT, ArgsT...>
124 {
125 protected:
126  void resetRaw()
127  {
128  rawFunc.reset();
129  }
130 };
131 
132 
133 
134 }
remotemono::RMonoAPIFunctionCommon
Definition: RMonoAPIFunctionCommon_Def.h:32
remotemono::RMonoAPIBase
Definition: RMonoAPIBase_Def.h:43
remotemono::RMonoAPIFunctionRawBase
Definition: RMonoAPIFunctionRaw_Def.h:50
remotemono::RMonoAPIFunctionSimple
Definition: RMonoAPIFunctionSimple_Def.h:39
remotemono::RMonoAPIFunctionRawAdapter
Definition: RMonoAPIFunctionRaw_Def.h:103
remotemono::RMonoAPIFunctionRawAdapterFinal
Definition: RMonoAPIFunctionRaw_Def.h:99
remotemono::RMonoAPIFunctionRaw
Definition: RMonoAPIFunctionRaw_Def.h:124