<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Узнать адрес памяти Dll файла]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=8735</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=8735&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Узнать адрес памяти Dll файла».]]></description>
		<lastBuildDate>Sun, 06 Oct 2013 13:02:32 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Узнать адрес памяти Dll файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=75798#p75798</link>
			<description><![CDATA[<p>Внёс небольшие исправления: размер структуры нужно писать в неё как &quot;uint&quot;. Также указал тип возвращаемого значения для CreateToolhelp32Snapshot как &quot;ptr&quot;, поскольку справка наводит на подозрения, что даже под x64 тип по умолчанию 32-битный.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 06 Oct 2013 13:02:32 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=75798#p75798</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Узнать адрес памяти Dll файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=75795#p75795</link>
			<description><![CDATA[<p>Спасибо, работает.</p>]]></description>
			<author><![CDATA[null@example.com (Dworkin)]]></author>
			<pubDate>Sun, 06 Oct 2013 12:14:05 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=75795#p75795</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Узнать адрес памяти Dll файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=75789#p75789</link>
			<description><![CDATA[<p>Попробуйте так. Чтобы работало с 32- и 64-битными процессами, запускать скрипт в АНК x64.<br /></p><div class="codebox"><pre><code>
Process = program.exe
DllName = kernel32.dll

SetFormat, Integer, Hex
Addr := GetDllAddr(DllName, Process)

If (Addr != 0) {
    MsgBox, %Addr%
}
Else {
    MsgBox, Ошибка
}

GetDllAddr(DllName, ProcessName)
{
    static StructSize, AddrOffset, NameOffset
    If (A_PtrSize = 4) {
        StructSize := 1064
        AddrOffset := 20
        NameOffset := 32
    }
    Else {
        StructSize := 1080
        AddrOffset := 24
        NameOffset := 48
    }
    static FLAGS := 0x18        ; TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32
    static INVALID_HANDLE_VALUE := -1
    static MODULEENTRY32
    VarSetCapacity(MODULEENTRY32, StructSize, 0)
    NumPut(StructSize, MODULEENTRY32, 0, &quot;uint&quot;)

    Process, Exist, %ProcessName%
    If (ErrorLevel = 0)
        Return 0

    snapMod := DllCall(&quot;CreateToolhelp32Snapshot&quot;, &quot;uint&quot;, FLAGS
                                                 , &quot;uint&quot;, ErrorLevel
                                                 , &quot;ptr&quot;)
    If (snapMod = INVALID_HANDLE_VALUE) {
        Return 0
    }

    If DllCall(&quot;Module32FirstW&quot;, &quot;ptr&quot;, snapMod, &quot;ptr&quot;, &amp;MODULEENTRY32)
    {
        pszModule := &amp;MODULEENTRY32 + NameOffset
        If DllCall(&quot;lstrcmpiW&quot;, &quot;wstr&quot;, DllName, &quot;ptr&quot;, pszModule) = 0
        {
            DllCall(&quot;CloseHandle&quot;, &quot;ptr&quot;, snapMod)
            Return NumGet(MODULEENTRY32, AddrOffset, &quot;ptr&quot;)
        }

        While DllCall(&quot;Module32NextW&quot;, &quot;ptr&quot;, snapMod, &quot;ptr&quot;, &amp;MODULEENTRY32)
        {
            If DllCall(&quot;lstrcmpiW&quot;, &quot;wstr&quot;, DllName, &quot;ptr&quot;, pszModule) = 0
            {
                DllCall(&quot;CloseHandle&quot;, &quot;ptr&quot;, snapMod)
                Return NumGet(MODULEENTRY32, AddrOffset, &quot;ptr&quot;)
            }
        }
    }
    DllCall(&quot;CloseHandle&quot;, &quot;ptr&quot;, snapMod)
    Return 0
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 06 Oct 2013 07:53:01 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=75789#p75789</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Узнать адрес памяти Dll файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=75788#p75788</link>
			<description><![CDATA[<p>Помогите пожалуйста. Программа в свой процесс загружает свои Dll. Как можно узнать адрес в памяти программы Dll файла?</p><p>То есть например типо такого:<br /></p><div class="codebox"><pre><code>
processName := igra.exe
adres1 := kakoito.dll
adres2 := 0x123
adres3 := adres1 + adres2
ProcessReadMemory(adres3, processName)
</code></pre></div><p>Для чтения и записи в память я использую это:<br /></p><div class="codebox"><pre><code>ProcessReadMemory(address, processIDorName, type := &quot;Int&quot;, numBytes := 4) {
    VarSetCapacity(buf, numBytes, 0)
    VarSetCapacity(numBytesRead, A_PtrSize, 0)

    Process Exist, %processIDorName%
    if !processID := ErrorLevel
        throw Exception(&quot;Invalid process name or process ID:`n`n&quot;&quot;&quot; . processIDorName . &quot;&quot;&quot;&quot;)

    if !processHandle := DllCall(&quot;OpenProcess&quot;, &quot;Int&quot;, 24, &quot;UInt&quot;, 0, &quot;UInt&quot;, processID, &quot;Ptr&quot;)
        throw Exception(&quot;Failed to open process.`n`nError code:`t&quot; . A_LastError)

    result := DllCall(&quot;ReadProcessMemory&quot;, &quot;Ptr&quot;, processHandle, &quot;Ptr&quot;, address, &quot;Ptr&quot;, &amp;buf, &quot;Ptr&quot;, numBytes, &quot;PtrP&quot;, numBytesRead, &quot;UInt&quot;)

    if !DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, processHandle, &quot;UInt&quot;) &amp;&amp; !result
        throw Exception(&quot;Failed to close process handle.`n`nError code:`t&quot; . A_LastError)

    if !result
        throw Exception(&quot;Failed to read process memory.`n`nError code:`t&quot; . A_LastError)

    if !numBytesRead
        throw Exception(&quot;Read 0 bytes from the`n`nprocess:`t&quot; . processIDorName . &quot;`naddress:`t&quot; . address)

    return NumGet(buf, 0, type)
}

ProcessWriteMemory(data, address, processIDorName, type := &quot;Int&quot;, numBytes := 4) {
    VarSetCapacity(buf, numBytes, 0)
    NumPut(data, buf, 0, type)

    Process Exist, %processIDorName%
    if !processID := ErrorLevel
        throw Exception(&quot;Invalid process name or process ID:`n`n&quot;&quot;&quot; . processIDorName . &quot;&quot;&quot;&quot;)

    if !processHandle := DllCall(&quot;OpenProcess&quot;, &quot;Int&quot;, 40, &quot;UInt&quot;, 0, &quot;UInt&quot;, processID, &quot;Ptr&quot;)
        throw Exception(&quot;Failed to open process.`n`nError code:`t&quot; . A_LastError)

    result := DllCall(&quot;WriteProcessMemory&quot;, &quot;Ptr&quot;, processHandle, &quot;Ptr&quot;, address, &quot;Ptr&quot;, &amp;buf, &quot;Ptr&quot;, numBytes, &quot;UInt&quot;, 0, &quot;UInt&quot;)

    if !DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, processHandle, &quot;UInt&quot;) &amp;&amp; !result
        throw Exception(&quot;Failed to close process handle.`n`nError code:`t&quot; . A_LastError)

    if !result
        throw Exception(&quot;Failed to write process memory.`n`nError code:`t&quot; . A_LastError)

    return result
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Dworkin)]]></author>
			<pubDate>Sun, 06 Oct 2013 01:08:42 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=75788#p75788</guid>
		</item>
	</channel>
</rss>
