如何挂钩DirectX11获取Shader的字节码

时间:2018-02-24 10:16:01

标签: directx shader bytecode

【DirectX9获取着色器字节码 - 】 我挂钩DrawIndexedPrimitive

HookCode(PPointer(g_DeviceBaseAddr + $148)^,@NewDrawIndexedPrimitive, @OldDrawIndexedPrimitive);    

function NewDrawIndexedPrimitive(const Device:IDirect3DDevice9;_Type: TD3DPrimitiveType; BaseVertexIndex: Integer; MinVertexIndex, NumVertices, startIndex, primCount: LongWord): HResult; stdcall;
var
    ppShader: IDirect3DVertexShader9;
    _Code:Pointer;
    _CodeLen:Cardinal;
begin
    Device.GetVertexShader(ppShader);//<------1.Get ShaderObject(ppShader)
    ppShader.GetFunction(nil,_CodeLen);
    GetMem(_Code,_CodeLen);
    ppShader.GetFunction(_Code,_CodeLen);//<----2.Get bytecode from ShaderObject(ppShader)
    Result:=OldDrawIndexedPrimitive(Self,_Type,BaseVertexIndex,MinVertexIndex, NumVertices, startIndex, primCount);
end;

【DirectX11如何获取VSShader字节码?】 我挂钩DrawIndexed

pDrawIndexed:=PPointer(PUINT_PTR(UINT_PTR(g_ImmContext)+0)^ + 12 * SizeOf(Pointer))^;
HookCode(pDrawIndexed,@NewDrawIndexed,@OldDrawIndexed);

procedure NewDrawIndexed(g_Real_ImmContext:ID3D11DeviceContext;IndexCount:     UINT;StartIndexLocation: UINT;BaseVertexLocation: Integer); stdcall;
var
    game_pVertexShader: ID3D11VertexShader;
        ppClassInstances: ID3D11ClassInstance;
        NumClassInstances: UINT
begin
    g_Real_ImmContext.VSGetShader(game_pVertexShader,ppClassInstances,NumClassInstances);    //<------1.Get ShaderObject(game_pVertexShader)
    .....//<----【2.Here's how to get bytecode from ShaderObject(game_pVertexShader)?】
    OldDrawIndexed(ImmContext, IndexCount, StartIndexLocation, BaseVertexLocation);
end;

另一种方式:

HOOK CreateVertexShader()

HOOK需要在游戏CreateVertexShader之前创建,如果游戏以后运行,HOOK将不会获得字节码,我需要随时获取字节码,如DirectX9

0 个答案:

没有答案