@@ -184,6 +184,20 @@ namespace SourceHook
184
184
*/
185
185
struct PassInfo
186
186
{
187
+ PassInfo ()
188
+ : size(0 )
189
+ , type(0 )
190
+ , flags(0 )
191
+ {
192
+ }
193
+
194
+ PassInfo (size_t typeSize, int typeId, unsigned int typeFlags)
195
+ : size(typeSize)
196
+ , type(typeId)
197
+ , flags(typeFlags)
198
+ {
199
+ }
200
+
187
201
enum PassType
188
202
{
189
203
PassType_Unknown=0 , /* *< Unknown -- no extra info available */
@@ -217,6 +231,22 @@ namespace SourceHook
217
231
218
232
struct V2Info
219
233
{
234
+ V2Info ()
235
+ : pNormalCtor(nullptr )
236
+ , pCopyCtor(nullptr )
237
+ , pDtor(nullptr )
238
+ , pAssignOperator(nullptr )
239
+ {
240
+ }
241
+
242
+ V2Info (void *normalCtor, void *copyCtor, void *dtor, void *assignOperator)
243
+ : pNormalCtor(normalCtor)
244
+ , pCopyCtor(copyCtor)
245
+ , pDtor(dtor)
246
+ , pAssignOperator(assignOperator)
247
+ {
248
+ }
249
+
220
250
void *pNormalCtor;
221
251
void *pCopyCtor;
222
252
void *pDtor;
@@ -252,6 +282,19 @@ namespace SourceHook
252
282
const PassInfo::V2Info *paramsPassInfo2;
253
283
};
254
284
285
+ class IProtoInfo
286
+ {
287
+ public:
288
+ virtual ~IProtoInfo () = default ;
289
+ virtual size_t GetNumOfParams () const = 0;
290
+ virtual const PassInfo &GetRetPassInfo () const = 0;
291
+ virtual const PassInfo *GetParamsPassInfo () const = 0;
292
+ virtual int GetConvention () const = 0;
293
+ virtual int GetVersion () const = 0;
294
+ virtual const PassInfo::V2Info &GetRetPassInfo2 () const = 0;
295
+ virtual const PassInfo::V2Info *GetParamsPassInfo2 () const = 0;
296
+ };
297
+
255
298
struct IHookManagerInfo ;
256
299
257
300
/* *
@@ -409,6 +452,9 @@ namespace SourceHook
409
452
{
410
453
virtual void SetInfo (int hookman_version, int vtbloffs, int vtblidx,
411
454
ProtoInfo *proto, void *hookfunc_vfnptr) = 0;
455
+
456
+ virtual void SetInfo (int hookman_version, int vtbloffs, int vtblidx,
457
+ IProtoInfo *proto, void *hookfunc_vfnptr) = 0;
412
458
};
413
459
414
460
// I'm adding support for functions which return references.
@@ -5130,12 +5176,17 @@ class PassInfoInitializer
5130
5176
InitializePassInfo<sizeof ...(ArgsType), 0 , ArgsType...>();
5131
5177
}
5132
5178
5133
- const PassInfo *ParamsPassInfo () const
5179
+ const PassInfo *GetParamsPassInfo () const
5134
5180
{
5135
5181
return params_;
5136
5182
}
5137
5183
5138
- const size_t ParamsPassInfoSize () const
5184
+ const PassInfo::V2Info *GetParamsPassInfoV2 () const
5185
+ {
5186
+ return paramsV2_;
5187
+ }
5188
+
5189
+ const size_t GetParamsPassInfoSize () const
5139
5190
{
5140
5191
return sizeof ...(ArgsType);
5141
5192
}
@@ -5155,6 +5206,32 @@ class PassInfoInitializer
5155
5206
}
5156
5207
5157
5208
PassInfo params_[sizeof ...(ArgsType)];
5209
+ PassInfo::V2Info paramsV2_[sizeof ...(ArgsType)];
5210
+ };
5211
+
5212
+ // For zero arguments
5213
+ template <>
5214
+ class PassInfoInitializer <>
5215
+ {
5216
+ public:
5217
+ constexpr PassInfoInitializer ()
5218
+ {
5219
+ }
5220
+
5221
+ const PassInfo *GetParamsPassInfo () const
5222
+ {
5223
+ return nullptr ;
5224
+ }
5225
+
5226
+ const PassInfo::V2Info *GetParamsPassInfoV2 () const
5227
+ {
5228
+ return nullptr ;
5229
+ }
5230
+
5231
+ const size_t GetParamsPassInfoSize () const
5232
+ {
5233
+ return 0 ;
5234
+ }
5158
5235
};
5159
5236
5160
5237
template <typename T>
@@ -5181,7 +5258,7 @@ struct ReturnTypeInfo<void>
5181
5258
{
5182
5259
static const size_t size ()
5183
5260
{
5184
- return 0 ; // why isn't it sizeof(void) like in TypeInfo<T>?
5261
+ return 0 ;
5185
5262
}
5186
5263
5187
5264
static const int type ()
@@ -5222,6 +5299,65 @@ class CHookManagerMemberFuncHandler : public IHookManagerMemberFunc
5222
5299
HookManagerMemberFunc func_;
5223
5300
};
5224
5301
5302
+ template <typename ReturnType, class ... Params>
5303
+ class CProtoInfo : public IProtoInfo
5304
+ {
5305
+ public:
5306
+ constexpr CProtoInfo ()
5307
+ : retPassInfo(ReturnTypeInfo<ReturnType>::size(),
5308
+ ReturnTypeInfo<ReturnType>::type(),
5309
+ ReturnTypeInfo<ReturnType>::flags())
5310
+ {
5311
+ }
5312
+
5313
+ virtual ~CProtoInfo () override
5314
+ {
5315
+ }
5316
+
5317
+ virtual size_t GetNumOfParams () const override
5318
+ {
5319
+ return paramsPassInfo.GetParamsPassInfoSize ();
5320
+ }
5321
+
5322
+ virtual const PassInfo &GetRetPassInfo () const override
5323
+ {
5324
+ return retPassInfo;
5325
+ }
5326
+
5327
+ virtual const PassInfo *GetParamsPassInfo () const override
5328
+ {
5329
+ return paramsPassInfo.GetParamsPassInfo ();
5330
+ }
5331
+
5332
+ virtual int GetConvention () const override
5333
+ {
5334
+ return 0 ;
5335
+ }
5336
+
5337
+ // version of the ProtoInfo structure.
5338
+ virtual int GetVersion () const override
5339
+ {
5340
+ // 1 for Version2
5341
+ return 1 ;
5342
+ }
5343
+
5344
+ virtual const PassInfo::V2Info &GetRetPassInfo2 () const override
5345
+ {
5346
+ return retPassInfo2;
5347
+ }
5348
+
5349
+ virtual const PassInfo::V2Info *GetParamsPassInfo2 () const override
5350
+ {
5351
+ return paramsPassInfo.GetParamsPassInfoV2 ();
5352
+ }
5353
+
5354
+ private:
5355
+ int numOfParams; // !< number of parameters
5356
+ PassInfo retPassInfo; // !< PassInfo for the return value. size=0 -> no retval
5357
+ PassInfo::V2Info retPassInfo2; // !< Version2 only
5358
+ PassInfoInitializer<Params...> paramsPassInfo; // !< PassInfos for the parameters
5359
+ };
5360
+
5225
5361
template <typename ReturnType, class ... Params>
5226
5362
class ManualHookHandler : public CHookManagerMemberFuncHandler <ManualHookHandler<ReturnType, Params...>>
5227
5363
{
@@ -5237,40 +5373,18 @@ class ManualHookHandler : public CHookManagerMemberFuncHandler<ManualHookHandler
5237
5373
typedef ReturnType (T::*HookFunc)(Params...);
5238
5374
};
5239
5375
5240
- ManualHookHandler ()
5376
+ constexpr ManualHookHandler ()
5241
5377
: CHookManagerMemberFuncHandler<ThisType>(this , &ThisType::HookManPubFunc)
5242
- , thisPointerOffset_(0 )
5243
- , vTableIndex_(0 )
5244
- , vtableOffset_(0 )
5245
5378
, msMFI_{false , 0 , 0 , 0 }
5246
5379
, msHI_(nullptr )
5247
- , msProto_{sizeof ...(Params),
5248
- {ReturnTypeInfo<ReturnType>::size (), ReturnTypeInfo<ReturnType>::type (), ReturnTypeInfo<ReturnType>::flags ()},
5249
- paramInfosM_.ParamsPassInfo (),
5250
- 0 ,
5251
- __SH_EPI,
5252
- paramInfos2M_}
5253
5380
{
5254
- for (PassInfo::V2Info& paramInfo : paramInfos2M_)
5255
- {
5256
- paramInfo = __SH_EPI;
5257
- }
5258
5381
}
5259
5382
5260
5383
virtual ~ManualHookHandler ()
5261
5384
{
5262
5385
// TODO apply RAII, cleanup all related hooks here
5263
5386
}
5264
5387
5265
- // TODO probably not needed for manual hooks
5266
- void Reconfigure ()
5267
- {
5268
- msMFI_.isVirtual = true ;
5269
- msMFI_.thisptroffs = thisPointerOffset_;
5270
- msMFI_.vtblindex = vTableIndex_;
5271
- msMFI_.vtbloffs = vtableOffset_;
5272
- }
5273
-
5274
5388
void Reconfigure (int vtblindex, int vtbloffs = 0 , int thisptroffs = 0 )
5275
5389
{
5276
5390
g_SHPtr->RemoveHookManager (g_PLID, this );
@@ -5285,7 +5399,7 @@ class ManualHookHandler : public CHookManagerMemberFuncHandler<ManualHookHandler
5285
5399
typename ManualHookHandler::FD handler (callbackInstPtr, callbackFuncPtr);
5286
5400
typename ThisType::CMyDelegateImpl* tmp = new typename ThisType::CMyDelegateImpl (handler); // TODO use unique_ptr here
5287
5401
5288
- return g_SHPtr->AddHook (g_PLID, mode, iface, thisPointerOffset_ , this , tmp, post);
5402
+ return g_SHPtr->AddHook (g_PLID, mode, iface, 0 , this , tmp, post);
5289
5403
}
5290
5404
5291
5405
template <typename T>
@@ -5294,7 +5408,7 @@ class ManualHookHandler : public CHookManagerMemberFuncHandler<ManualHookHandler
5294
5408
typename ManualHookHandler::FD handler (callbackInstPtr, callbackFuncPtr);
5295
5409
typename ThisType::CMyDelegateImpl tmp (handler);
5296
5410
5297
- return g_SHPtr->RemoveHook (g_PLID, iface, thisPointerOffset_ , this , &tmp, post);
5411
+ return g_SHPtr->RemoveHook (g_PLID, iface, 0 , this , &tmp, post);
5298
5412
}
5299
5413
5300
5414
// For void return type only
@@ -5557,16 +5671,10 @@ class ManualHookHandler : public CHookManagerMemberFuncHandler<ManualHookHandler
5557
5671
}
5558
5672
5559
5673
private:
5560
- int thisPointerOffset_; // thisptroffs
5561
- int vTableIndex_; // vtblindex
5562
- int vtableOffset_; // vtbloffs
5563
-
5564
5674
MemFuncInfo msMFI_; // ms_MFI
5565
5675
IHookManagerInfo *msHI_; // ms_HI
5566
5676
5567
- PassInfoInitializer<void , Params...> paramInfosM_; // ParamInfosM
5568
- PassInfo::V2Info paramInfos2M_[sizeof ...(Params) + 1 ]; // ParamInfos2M
5569
- ProtoInfo msProto_; // ms_Proto
5677
+ CProtoInfo<ReturnType, Params...> msProto_; // ms_Proto
5570
5678
};
5571
5679
5572
5680
} // SourceHook
0 commit comments