<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Узнать адрес памяти Dll файла]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=8735&amp;type=atom" />
	<updated>2013-10-06T13:02:32Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=8735</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Узнать адрес памяти Dll файла]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=75798#p75798" />
			<content type="html"><![CDATA[<p>Внёс небольшие исправления: размер структуры нужно писать в неё как &quot;uint&quot;. Также указал тип возвращаемого значения для CreateToolhelp32Snapshot как &quot;ptr&quot;, поскольку справка наводит на подозрения, что даже под x64 тип по умолчанию 32-битный.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-10-06T13:02:32Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=75798#p75798</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Узнать адрес памяти Dll файла]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=75795#p75795" />
			<content type="html"><![CDATA[<p>Спасибо, работает.</p>]]></content>
			<author>
				<name><![CDATA[Dworkin]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27052</uri>
			</author>
			<updated>2013-10-06T12:14:05Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=75795#p75795</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Узнать адрес памяти Dll файла]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=75789#p75789" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-10-06T07:53:01Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=75789#p75789</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Узнать адрес памяти Dll файла]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=75788#p75788" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Dworkin]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27052</uri>
			</author>
			<updated>2013-10-06T01:08:42Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=75788#p75788</id>
		</entry>
</feed>
