<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Передать структуру]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15994&amp;type=atom" />
	<updated>2021-07-05T14:14:52Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=15994</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148863#p148863" />
			<content type="html"><![CDATA[<p>Хорошо, спасибо.</p>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2021-07-05T14:14:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148863#p148863</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148861#p148861" />
			<content type="html"><![CDATA[<p>Представьте, что структура - это письменный стол, а члены структуры это ящики в столе в сантиметрах.<br />Ящик может быть пустой или полный, но он всё-равно занимает какое-то место.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2021-07-05T14:12:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148861#p148861</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148860#p148860" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>откуда взялось здесь 1084?</p></blockquote></div><p>Это емкость переменной, если поставить меньше, ничего не заработает. Но я еще не посчитал ее.<br /></p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Если работает, значит смещения указаны правильно</p></blockquote></div><p>Да, смещения такие же, я их просто по-своему записывал. А так, вроде все работает, буду дальше учить структуры.</p>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2021-07-05T13:59:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148860#p148860</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148859#p148859" />
			<content type="html"><![CDATA[<p>Теперь почти всё правильно, но, во-первых, откуда взялось здесь 1084?<br /></p><div class="codebox"><pre><code>VarSetCapacity(ParamStruct, 1084, 0)</code></pre></div><p>Во-вторых, для наглядности лучше так:<br /></p><div class="codebox"><pre><code>StrPut(File, &amp;ParamStruct + 4, &quot;UTF-16&quot;)
NumPut(&amp;str, ParamStruct, 4 + 520*2)
NumPut(id  , ParamStruct, 4 + 520*2 + 4, &quot;Uint&quot;)
NumPut(2   , ParamStruct, 4 + 520*2 + 8, &quot;Uint&quot;)
; NumPut(0   , ParamStruct, 4 + 520*2 + 12, &quot;Uint&quot;)</code></pre></div><p>Ноль передавать не нужно (но можно для наглядности).<br /></p><div class="quotebox"><cite>svoboden пишет:</cite><blockquote><p>мой вариант тоже работает же</p></blockquote></div><p>Если работает, значит смещения указаны правильно (посчитайте, какие в моём, какие в вашем), просто неправильно записаны.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-07-05T13:38:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148859#p148859</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148858#p148858" />
			<content type="html"><![CDATA[<p>Ну да, у меня заработал такой вариант, но и мой вариант тоже работает же, не знаю.<br /></p><div class="codebox"><pre><code>#NoEnv

File := &quot;test_.dll&quot;
str := &quot;test.exe&quot;

WinGet, id, PID, ahk_exe test.exe

hModule := DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;gh_injector.dll&quot;, &quot;Ptr&quot;)
InjectW := DllCall(&quot;GetProcAddress&quot;, &quot;Ptr&quot;, hModule, &quot;Astr&quot;, &quot;InjectW&quot;, &quot;Ptr&quot;)
;msgbox % InjectW

VarSetCapacity(ParamStruct, 1084, 0)

StrPut(File, &amp;ParamStruct + 4, &quot;UTF-16&quot;)
NumPut(&amp;str, ParamStruct + 4 + 520*2)
NumPut(id, ParamStruct, 8 + 520*2, &quot;Uint&quot;)
NumPut(2, ParamStruct, 12 + 520*2, &quot;Uint&quot;)
NumPut(0, ParamStruct, 16 + 520*2, &quot;Uint&quot;)

DllCall(InjectW, &quot;Ptr&quot;, &amp;ParamStruct)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2021-07-05T12:24:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148858#p148858</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148857#p148857" />
			<content type="html"><![CDATA[<p>Так тоже неудобно. Во-первых, для наглядности (и во избежание ошибок) нужно добавлять поля в том порядке, в котором они идут в структуре. Во-вторых, лучше расписывать оффсеты подробно, т. е. вместо<br /></p><div class="codebox"><pre><code>NumPut(&amp;str, &amp;ParamStruct + 1044)</code></pre></div><p>пишем<br /></p><div class="codebox"><pre><code>NumPut(&amp;str, &amp;ParamStruct + 4 + 520*2)</code></pre></div><p>И так же для остальных полей.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-07-05T12:07:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148857#p148857</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148856#p148856" />
			<content type="html"><![CDATA[<p>Так вроде:<br /></p><div class="codebox"><pre><code>#NoEnv

File := &quot;test_.dll&quot;
str := &quot;test.exe&quot;

WinGet, id, PID, ahk_exe test.exe

hModule := DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;gh_injector.dll&quot;, &quot;Ptr&quot;)
InjectW := DllCall(&quot;GetProcAddress&quot;, &quot;Ptr&quot;, hModule, &quot;Astr&quot;, &quot;InjectW&quot;, &quot;Ptr&quot;)
;msgbox % InjectW

VarSetCapacity(ParamStruct, 1084, 0)

NumPut(&amp;str, ParamStruct + 1044)
NumPut(id, ParamStruct, 1048, &quot;Uint&quot;)
NumPut(2, ParamStruct, 1052, &quot;Uint&quot;)
NumPut(0, ParamStruct, 1056, &quot;Uint&quot;) ; 0 - NtCreateThreadEx
StrPut(File, &amp;ParamStruct + 4, &quot;UTF-16&quot;)

DllCall(InjectW, &quot;Ptr&quot;, &amp;ParamStruct)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2021-07-05T11:59:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148856#p148856</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148855#p148855" />
			<content type="html"><![CDATA[<p>Неудобно смотреть в таком виде. Зачем вы всё умножаете на 2? Здесь на 2 умножается только 520, остальное складывается. Перепишите, всё будет понятно.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-07-05T11:47:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148855#p148855</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148854#p148854" />
			<content type="html"><![CDATA[<p>Так проверьте, вот, может не очень правильный скрипт, но смещения работают, три первых поля я не гадал, а дальше да, вопросы уже, но я все-равно подобрал их исходя из файла ошибок.<br /></p><div class="codebox"><pre><code>#NoEnv

File := &quot;test_.dll&quot;
str := &quot;test.exe&quot;

WinGet, id, PID, ahk_exe test.exe

hModule := DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;gh_injector.dll&quot;, &quot;Ptr&quot;)
;msgbox % hModule
InjectW := DllCall(&quot;GetProcAddress&quot;, &quot;Ptr&quot;, hModule, &quot;Astr&quot;, &quot;InjectW&quot;, &quot;Ptr&quot;)
;msgbox % InjectW

VarSetCapacity(ParamStruct, 542 * 2, 0)

NumPut(&amp;str, ParamStruct + 522 * 2)
NumPut(id, ParamStruct, 524 * 2, &quot;Uint&quot;)
NumPut(2, ParamStruct, 526 * 2, &quot;Uint&quot;)
NumPut(0, ParamStruct, 528 * 2, &quot;Uint&quot;) ; 0 - NtCreateThreadEx
StrPut(File, &amp;ParamStruct + 4, &quot;UTF-16&quot;)

DllCall(InjectW, &quot;Ptr&quot;, &amp;ParamStruct)</code></pre></div><p>Я посчитал почему-то по справке, что szTargetProcessExeFileName = 2 байтам. И это оказалось правильным смещением, не знаю.</p>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2021-07-05T11:41:55Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148854#p148854</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148853#p148853" />
			<content type="html"><![CDATA[<p>Это имеет отношение ко второму полю, там указано, сколько занимает один wchar_t, действительно 2 байта, именно поэтому мы умножаем 520 (количество символов в строке) на два.<br />В третьем поле вы видите звёздочку, это значит указатель.<br />То-есть во втором поле мы передаём непосредственно саму строку с помощью StrPut(), а в третьем адрес строки с помощью NumPut().</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-07-05T11:33:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148853#p148853</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148852#p148852" />
			<content type="html"><![CDATA[<p>По вашей ссылке смотрел: <a href="https://docs.microsoft.com/en-us/cpp/cpp/data-type-ranges?view=msvc-160&amp;viewFallbackFrom=vs-2019">https://docs.microsoft.com/en-us/cpp/cp … om=vs-2019</a>. Ориентировался на эту надпись: wchar_t	2	__wchar_t	0 to 65,535</p>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2021-07-05T11:28:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148852#p148852</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148851#p148851" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>struct INJECTIONDATA
{
    DWORD            LastErrorCode;
    wchar_t            szDllPath[MAX_PATH * 2];
    wchar_t*          szTargetProcessExeFileName;
    DWORD            ProcessID;
    INJECTION_MODE    Mode;
    LAUNCH_METHOD    Method;
    DWORD            Flags;
    DWORD            hHandleValue;
    HINSTANCE       hDllOut;
};</code></pre></div><p>А почему третье два? Это указатель (адрес) переменной со строкой. Для 32 битных процессов указатели занимают 4 байта, для 64 битных 8.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-07-05T11:23:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148851#p148851</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148850#p148850" />
			<content type="html"><![CDATA[<p>Тогда:<br />4 байта.<br />520 * 2 байт.<br />2 байта.<br />4 байта.</p>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2021-07-05T11:20:28Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148850#p148850</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148849#p148849" />
			<content type="html"><![CDATA[<p>Вопрос невнимательно прочитали</p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>сколько байтов занимает каждое поле</p></blockquote></div><p>Поле не может занимать 0 байт.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-07-05T11:18:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148849#p148849</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Передать структуру]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148848#p148848" />
			<content type="html"><![CDATA[<p>первое поле 0 байт.<br />второе 520 * 2 (умножить на 2 - это юникод строка, она в два раза больше анси).<br />третье 2 байта.<br />четвертое уже непонятно.</p>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2021-07-05T11:16:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148848#p148848</id>
		</entry>
</feed>
