@@ -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,26 @@ namespace SourceHook
252
282
const PassInfo::V2Info *paramsPassInfo2;
253
283
};
254
284
285
+ class IProtoInfo
286
+ {
287
+ public:
288
+ enum class ProtoInfoVersion : int
289
+ {
290
+ ProtoInfoVersionInvalid = -1 ,
291
+ ProtoInfoVersion1 = 0 ,
292
+ ProtoInfoVersion2 = 1
293
+ };
294
+
295
+ virtual ~IProtoInfo () = default ;
296
+ virtual size_t GetNumOfParams () const = 0;
297
+ virtual const PassInfo &GetRetPassInfo () const = 0;
298
+ virtual const PassInfo *GetParamsPassInfo () const = 0;
299
+ virtual int GetConvention () const = 0;
300
+ virtual IProtoInfo::ProtoInfoVersion GetVersion () const = 0;
301
+ virtual const PassInfo::V2Info &GetRetPassInfo2 () const = 0;
302
+ virtual const PassInfo::V2Info *GetParamsPassInfo2 () const = 0;
303
+ };
304
+
255
305
struct IHookManagerInfo ;
256
306
257
307
/* *
@@ -409,6 +459,9 @@ namespace SourceHook
409
459
{
410
460
virtual void SetInfo (int hookman_version, int vtbloffs, int vtblidx,
411
461
ProtoInfo *proto, void *hookfunc_vfnptr) = 0;
462
+
463
+ virtual void SetInfo (int hookman_version, int vtbloffs, int vtblidx,
464
+ IProtoInfo *proto, void *hookfunc_vfnptr) = 0;
412
465
};
413
466
414
467
// I'm adding support for functions which return references.
@@ -5130,12 +5183,17 @@ class PassInfoInitializer
5130
5183
InitializePassInfo<sizeof ...(ArgsType), 0 , ArgsType...>();
5131
5184
}
5132
5185
5133
- const PassInfo *ParamsPassInfo () const
5186
+ const PassInfo *GetParamsPassInfo () const
5134
5187
{
5135
5188
return params_;
5136
5189
}
5137
5190
5138
- const size_t ParamsPassInfoSize () const
5191
+ const PassInfo::V2Info *GetParamsPassInfoV2 () const
5192
+ {
5193
+ return paramsV2_;
5194
+ }
5195
+
5196
+ const size_t GetParamsPassInfoSize () const
5139
5197
{
5140
5198
return sizeof ...(ArgsType);
5141
5199
}
@@ -5155,6 +5213,32 @@ class PassInfoInitializer
5155
5213
}
5156
5214
5157
5215
PassInfo params_[sizeof ...(ArgsType)];
5216
+ PassInfo::V2Info paramsV2_[sizeof ...(ArgsType)];
5217
+ };
5218
+
5219
+ // For zero arguments
5220
+ template <>
5221
+ class PassInfoInitializer <>
5222
+ {
5223
+ public:
5224
+ constexpr PassInfoInitializer ()
5225
+ {
5226
+ }
5227
+
5228
+ const PassInfo *GetParamsPassInfo () const
5229
+ {
5230
+ return nullptr ;
5231
+ }
5232
+
5233
+ const PassInfo::V2Info *GetParamsPassInfoV2 () const
5234
+ {
5235
+ return nullptr ;
5236
+ }
5237
+
5238
+ const size_t GetParamsPassInfoSize () const
5239
+ {
5240
+ return 0 ;
5241
+ }
5158
5242
};
5159
5243
5160
5244
template <typename T>
@@ -5181,7 +5265,7 @@ struct ReturnTypeInfo<void>
5181
5265
{
5182
5266
static const size_t size ()
5183
5267
{
5184
- return 0 ; // why isn't it sizeof(void) like in TypeInfo<T>?
5268
+ return 0 ;
5185
5269
}
5186
5270
5187
5271
static const int type ()
@@ -5222,6 +5306,64 @@ class CHookManagerMemberFuncHandler : public IHookManagerMemberFunc
5222
5306
HookManagerMemberFunc func_;
5223
5307
};
5224
5308
5309
+ template <typename ReturnType, class ... Params>
5310
+ class CProtoInfo : public IProtoInfo
5311
+ {
5312
+ public:
5313
+ constexpr CProtoInfo ()
5314
+ : retPassInfo(ReturnTypeInfo<ReturnType>::size(),
5315
+ ReturnTypeInfo<ReturnType>::type(),
5316
+ ReturnTypeInfo<ReturnType>::flags())
5317
+ {
5318
+ }
5319
+
5320
+ virtual ~CProtoInfo () override
5321
+ {
5322
+ }
5323
+
5324
+ virtual size_t GetNumOfParams () const override
5325
+ {
5326
+ return paramsPassInfo.GetParamsPassInfoSize ();
5327
+ }
5328
+
5329
+ virtual const PassInfo &GetRetPassInfo () const override
5330
+ {
5331
+ return retPassInfo;
5332
+ }
5333
+
5334
+ virtual const PassInfo *GetParamsPassInfo () const override
5335
+ {
5336
+ return paramsPassInfo.GetParamsPassInfo ();
5337
+ }
5338
+
5339
+ virtual int GetConvention () const override
5340
+ {
5341
+ return 0 ;
5342
+ }
5343
+
5344
+ // version of the ProtoInfo structure.
5345
+ virtual IProtoInfo::ProtoInfoVersion GetVersion () const override
5346
+ {
5347
+ return ProtoInfoVersion::ProtoInfoVersion2;
5348
+ }
5349
+
5350
+ virtual const PassInfo::V2Info &GetRetPassInfo2 () const override
5351
+ {
5352
+ return retPassInfo2;
5353
+ }
5354
+
5355
+ virtual const PassInfo::V2Info *GetParamsPassInfo2 () const override
5356
+ {
5357
+ return paramsPassInfo.GetParamsPassInfoV2 ();
5358
+ }
5359
+
5360
+ private:
5361
+ int numOfParams; // !< number of parameters
5362
+ PassInfo retPassInfo; // !< PassInfo for the return value. size=0 -> no retval
5363
+ PassInfo::V2Info retPassInfo2; // !< Version2 only
5364
+ PassInfoInitializer<Params...> paramsPassInfo; // !< PassInfos for the parameters
5365
+ };
5366
+
5225
5367
template <typename ReturnType, class ... Params>
5226
5368
class ManualHookHandler : public CHookManagerMemberFuncHandler <ManualHookHandler<ReturnType, Params...>>
5227
5369
{
@@ -5237,40 +5379,26 @@ class ManualHookHandler : public CHookManagerMemberFuncHandler<ManualHookHandler
5237
5379
typedef ReturnType (T::*HookFunc)(Params...);
5238
5380
};
5239
5381
5240
- ManualHookHandler ()
5382
+ constexpr ManualHookHandler ()
5241
5383
: CHookManagerMemberFuncHandler<ThisType>(this , &ThisType::HookManPubFunc)
5242
- , thisPointerOffset_(0 )
5243
- , vTableIndex_(0 )
5244
- , vtableOffset_(0 )
5245
5384
, msMFI_{false , 0 , 0 , 0 }
5246
5385
, 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
5386
{
5254
- for (PassInfo::V2Info& paramInfo : paramInfos2M_)
5255
- {
5256
- paramInfo = __SH_EPI;
5257
- }
5258
5387
}
5259
5388
5389
+ ManualHookHandler (const ManualHookHandler&) = delete ;
5390
+
5391
+ ManualHookHandler (ManualHookHandler&&) = delete ;
5392
+
5393
+ ManualHookHandler& operator =(const ManualHookHandler&) = delete ;
5394
+
5395
+ ManualHookHandler& operator =(ManualHookHandler&&) = delete ;
5396
+
5260
5397
virtual ~ManualHookHandler ()
5261
5398
{
5262
5399
// TODO apply RAII, cleanup all related hooks here
5263
5400
}
5264
5401
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
5402
void Reconfigure (int vtblindex, int vtbloffs = 0 , int thisptroffs = 0 )
5275
5403
{
5276
5404
g_SHPtr->RemoveHookManager (g_PLID, this );
@@ -5285,7 +5413,7 @@ class ManualHookHandler : public CHookManagerMemberFuncHandler<ManualHookHandler
5285
5413
typename ManualHookHandler::FD handler (callbackInstPtr, callbackFuncPtr);
5286
5414
typename ThisType::CMyDelegateImpl* tmp = new typename ThisType::CMyDelegateImpl (handler); // TODO use unique_ptr here
5287
5415
5288
- return g_SHPtr->AddHook (g_PLID, mode, iface, thisPointerOffset_ , this , tmp, post);
5416
+ return g_SHPtr->AddHook (g_PLID, mode, iface, 0 , this , tmp, post);
5289
5417
}
5290
5418
5291
5419
template <typename T>
@@ -5294,7 +5422,7 @@ class ManualHookHandler : public CHookManagerMemberFuncHandler<ManualHookHandler
5294
5422
typename ManualHookHandler::FD handler (callbackInstPtr, callbackFuncPtr);
5295
5423
typename ThisType::CMyDelegateImpl tmp (handler);
5296
5424
5297
- return g_SHPtr->RemoveHook (g_PLID, iface, thisPointerOffset_ , this , &tmp, post);
5425
+ return g_SHPtr->RemoveHook (g_PLID, iface, 0 , this , &tmp, post);
5298
5426
}
5299
5427
5300
5428
// For void return type only
@@ -5557,16 +5685,10 @@ class ManualHookHandler : public CHookManagerMemberFuncHandler<ManualHookHandler
5557
5685
}
5558
5686
5559
5687
private:
5560
- int thisPointerOffset_; // thisptroffs
5561
- int vTableIndex_; // vtblindex
5562
- int vtableOffset_; // vtbloffs
5563
-
5564
5688
MemFuncInfo msMFI_; // ms_MFI
5565
5689
IHookManagerInfo *msHI_; // ms_HI
5566
5690
5567
- PassInfoInitializer<void , Params...> paramInfosM_; // ParamInfosM
5568
- PassInfo::V2Info paramInfos2M_[sizeof ...(Params) + 1 ]; // ParamInfos2M
5569
- ProtoInfo msProto_; // ms_Proto
5691
+ CProtoInfo<ReturnType, Params...> msProto_; // ms_Proto
5570
5692
};
5571
5693
5572
5694
} // SourceHook
0 commit comments