想在暴风影音放电影时在上面写字,思路是先HOOK它的里面的CreateSurface,结果怎么HOOK也出错,后来用自己写的一个简单的DIRECTX的程序来调,发现如果我自己的HOOK函数如果不Const,Out这些东西还可以进去,但在真正调用原函数时会出错,要是加了进都进不去就出错,请看代码:
//这个函数定义时如果不加关键字:const 和out可以进去,
//但调用原函数时会出错,如果加了就进不去就会出错即:
//function MyCreateSurfaceEx(lpDDSurfaceDesc: TDDSurfaceDesc2;
// lplpDDSurface: IDirectDrawSurface7;
// pUnkOuter: IUnknown): HResult; stdcall;
function MyCreateSurfaceEx(const lpDDSurfaceDesc: TDDSurfaceDesc2;
out lplpDDSurface: IDirectDrawSurface7;
pUnkOuter: IUnknown): HResult; stdcall;
type
TNewCreateSurfaceEx=function(const lpDDSurfaceDesc: TDDSurfaceDesc2;
out lplpDDSurface: IDirectDrawSurface7;
pUnkOuter: IUnknown): HResult; stdcall;
begin
asm
pushad
pushfd
end;
showmessage('MyCreateSurfaceEx Enter');
asm
popad
popfd
end;
Result:=TNewCreateSurfaceEx(OldCreateSurfaceEx)(lpDDSurfaceDesc,lplpDDSurface,pUnkOuter
showmessage('MyCreateSurfaceEx Exit');
end;
//
function MyDirectDrawCreateEx(lpGUID: PGUID; out lplpDD: IDirectDraw7;
const iid: TGUID; pUnkOuter: IUnknown): HResult; stdcall;
type
TNewDirectDrawCreateEx=function(lpGUID: PGUID; out lplpDD: IDirectDraw7;
const iid: TGUID; pUnkOuter: IUnknown): HResult; stdcall;
begin
//showmessage('MyDirectDrawCreateEx');
Hook[2].UnHook;
MylpDD:=THookIDirectDraw7.Create(lpGUID,iid,pUnkOuter);
Result := TNewDirectDrawCreateEx(Hook[2].BaseAddr)(lpGUID, lplpDD, iid, pUnkOuter);
Hook[2].Hook;
if Result<>DD_OK then Exit;
HookVirtualTable(Pointer(lplpDD),6,@MyCreateSurfaceEx,OldCreateSurfaceEx);
//showmessage('lplpDD:='+inttostr(dword(lplpDD)));
end;
procedure HookVirtualTable(lpDD:Pointer;Index:Byte;NewFunc:Pointer;var OldFunc:Dword);
begin
OldFunc:=PWord(Dword(lpDD^)+Index*4)^;
PDword(Dword(lpDD^)+Index*4)^:=Dword(NewFunc);
end;
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!