<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Перехват com интерфейса процесса]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=14526&amp;type=atom" />
	<updated>2019-02-01T11:41:35Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=14526</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перехват com интерфейса процесса]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=131861#p131861" />
			<content type="html"><![CDATA[<p>Хорошая информация по теме:<br /><a href="https://vedmysh.livejournal.com/8984.html">https://vedmysh.livejournal.com/8984.html</a><br />Непонято, Minhook.dll криво работает или autohotkey.dll его криво инжектит?</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-02-01T11:41:35Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=131861#p131861</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Перехват com интерфейса процесса]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=131771#p131771" />
			<content type="html"><![CDATA[<p>Есть програмка, хочу научиться перехватывать метод EndScene в directx9.<br />Делал вроде бы по этому алгоритму:<br /><a href="http://spazzarama.com/2010/03/29/screen-capture-with-direct3d-api-hooks">http://spazzarama.com/2010/03/29/screen … -api-hooks</a><br />Но при первом же перехвате, перехват происходит, но программа намертво виснет.<br />В чем может быть ошибка?<br />Программа 32 бит тут:<br /><a href="https://ru.files.fm/u/xast7cz4">https://ru.files.fm/u/xast7cz4</a><br />Нужна библиотека MinHook.dll:<br /><a href="https://github.com/tmplinshi/MinHook-AHK/blob/master/MinHook/x32/MinHook.dll">https://github.com/tmplinshi/MinHook-AH … inHook.dll</a><br />Инжектю через autohotkey.dll так:<br /></p><div class="codebox"><pre><code>f11::
WinGet, PID, PID, A
FileRead,HookScript,minhook.ahk
rThread:=&quot;&quot;
rThread:=InjectAhkDll(PID,A_ScriptDir &quot;\AutoHotkey.dll&quot;, HookScript)
return</code></pre></div><p>Сам хук:<br /></p><div class="codebox"><pre><code>#Persistent
SetWorkingDir %A_ScriptDir%
d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0) 
NumPut(1, D3DPRESENT_PARAMETERS, 0)   ; BackBufferWidth
NumPut(1, D3DPRESENT_PARAMETERS, 4)   ; BackBufferHeight
NumPut(1, D3DPRESENT_PARAMETERS, 24)   ; D3DSWAPEFFECT_DISCARD
NumPut(1, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)   ; Windowed
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_HARDWARE_VERTEXPROCESSING := 0x00000040, &amp;D3DPRESENT_PARAMETERS, device)
EndScene := NumGet(NumGet(device+0)+42*A_PtrSize) 
Release(device)
Release(d3d)

MinhookDll := &quot;MinHook.dll&quot;
MinHook_Init(MinhookDll)
MH_CreateHook(EndScene, cbAddr := RegisterCallback(&quot;EndScene_Hook&quot;, &quot;F&quot;))
MH_EnableHook()
return

EndScene_Hook(device)
{
   msgbox hook
}


Direct3DCreate9(SDKVersion)
{
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;d3d9&quot;, &quot;PTR&quot;)
   {
      MsgBox, 16, Error, d3d9 failed.
      ExitApp
   }
   return DllCall(&quot;d3d9\Direct3DCreate9&quot;, &quot;uint&quot;, SDKVersion)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),&quot;ptr&quot;,this,&quot;uint&quot;,Adapter,&quot;uint&quot;,DeviceType,&quot;ptr&quot;,hFocusWindow,&quot;uint&quot;,BehaviorFlags,&quot;ptr&quot;,pPresentationParameters,&quot;ptr*&quot;,ppReturnedDeviceInterface)
   if hr
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

Release(this)
{
   return DllCall(NumGet(NumGet(this+0)+2*A_PtrSize), &quot;ptr&quot;, this)
}

_Error(val)
{
   msgbox % val
   ExitApp
}


MinHook_Init(MinhookDll)
{
   Static h
   If Not h
   {
      h:=DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;,MinhookDll, &quot;Ptr&quot;)
      MH_Initialize()
   }
}

; Creates a Hook for the specified target function, in disabled state.
; Parameters:
;   pTarget    [in]  A pointer to the target function, which will be
;                    overridden by the detour function.
;   pDetour    [in]  A pointer to the detour function, which will override
;                    the target function.
;   ppOriginal [out] A pointer to the trampoline function, which will be
;                    used to call the original target function.
;                    This parameter can be NULL.
MH_CreateHook(pTarget, pDetour, ByRef ppOriginal := 0) {
	return DllCall(&quot;MinHook\MH_CreateHook&quot;
	               , &quot;ptr&quot;, pTarget
	               , &quot;ptr&quot;, pDetour
	               , &quot;uptr*&quot;, ppOriginal )
}

; Initialize the MinHook library. You must call this function EXACTLY ONCE
; at the beginning of your program.
MH_Initialize() {
	return DllCall(&quot;MinHook\MH_Initialize&quot;)
}

; Uninitialize the MinHook library. You must call this function EXACTLY
; ONCE at the end of your program.
MH_Uninitialize() {
	return DllCall(&quot;MinHook\MH_Uninitialize&quot;)
}

; Removes an already created hook.
; Parameters:
;   pTarget [in] A pointer to the target function.
MH_RemoveHook(pTarget) {
	return DllCall(&quot;MinHook\MH_RemoveHook&quot;, &quot;ptr&quot;, pTarget)
}

/*
	#define MH_ALL_HOOKS NULL
*/

; Enables an already created hook.
; Parameters:
;   pTarget [in] A pointer to the target function.
;                If this parameter is MH_ALL_HOOKS, all created hooks are
;                enabled in one go.
MH_EnableHook(pTarget := 0) {
	return DllCall(&quot;MinHook\MH_EnableHook&quot;, &quot;ptr&quot;, pTarget)
}

; Disables an already created hook.
; Parameters:
;   pTarget [in] A pointer to the target function.
;                If this parameter is MH_ALL_HOOKS, all created hooks are
;                disabled in one go.
MH_DisableHook(pTarget := 0) {
	return DllCall(&quot;MinHook\MH_DisableHook&quot;, &quot;ptr&quot;, pTarget)
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-01-30T02:59:36Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=131771#p131771</id>
		</entry>
</feed>
