<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Чтение .txt и выполнение команды]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=12323&amp;type=atom" />
	<updated>2017-01-17T22:08:51Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=12323</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение .txt и выполнение команды]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111199#p111199" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>belyankin12 пишет:</cite><blockquote><p>Кстати, если так подумать, вы прочитаете все содержимое чатлога. Ваш способ мне кажется не самый безопасный...</p></blockquote></div><p> Можно зашифровать содержимое чат-лога, это не сложно.</p><p>Например используя&nbsp; функцию расчёта HASH, ключом будет например EXE-file.</p><p>Функция поддерживает HASH типы(MD2/MD5/SHA - поддержка всеми Windows, SHA256/SHA384/SHA512 - не поддерживается Windows XP/2000).<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;Функция fnHASH</div><div class="fancy_spoiler"><div class="codebox"><pre><code>;-----------------------------------------------------------------------------------------------------------------
;                                  Функция расчёта контрольной суммы файла
; HASH типы: MD2/MD5/SHA - поддержка всеми Windows, SHA256/SHA384/SHA512 - не поддерживается Windows XP/2000
;-----------------------------------------------------------------------------------------------------------------

;НА ВХОД:
; 1-й параметр(STRING): Полный путь к файлу
; 2-й параметр(STRING): HASH-типы из списка MD2/MD5/SHA/SHA256/SHA384/SHA512

;НА ВЫХОД:
; Или контольная сумма файла(STRING)
; Или слово &quot;ERROR&quot;(STRING)

fnHASH(FilePath, str)
{
  CaseSensitive := False ; Не чувствительность к регистру, те Б = б
  if (str = &quot;MD2&quot;)
        vHASH := 1
  Else if (str = &quot;MD5&quot;)
        vHASH := 2
  Else if (str = &quot;SHA&quot;)
        vHASH := 3
  Else if (str = &quot;SHA256&quot;)
        vHASH := 4
  Else if (str = &quot;SHA384&quot;)
        vHASH := 5
  Else if (str = &quot;SHA512&quot;)
        vHASH := 6
          Else
              Return &quot;ERROR&quot;
  CaseSensitive := True ; Чувствительность к регистру, те Б != б
  ret := HashFile(FilePath,vHASH)
Return ret
}

/*
HASH types:
1 - MD2
2 - MD5
3 - SHA
4 - SHA256 - not supported on XP,2000
5 - SHA384 - not supported on XP,2000
6 - SHA512 - not supported on XP,2000
*/

HashFile(filePath,hashType=2)
{
	PROV_RSA_AES := 24
	CRYPT_VERIFYCONTEXT := 0xF0000000
	BUFF_SIZE := 1024 * 1024 ; 1 MB
	HP_HASHVAL := 0x0002
	HP_HASHSIZE := 0x0004
	
	HASH_ALG := hashType = 1 ? (CALG_MD2 := 32769) : HASH_ALG
	HASH_ALG := hashType = 2 ? (CALG_MD5 := 32771) : HASH_ALG
	HASH_ALG := hashType = 3 ? (CALG_SHA := 32772) : HASH_ALG
	HASH_ALG := hashType = 4 ? (CALG_SHA_256 := 32780) : HASH_ALG	;Vista+ only
	HASH_ALG := hashType = 5 ? (CALG_SHA_384 := 32781) : HASH_ALG	;Vista+ only
	HASH_ALG := hashType = 6 ? (CALG_SHA_512 := 32782) : HASH_ALG	;Vista+ only
	
	f := FileOpen(filePath,&quot;r&quot;,&quot;CP0&quot;)
	if !IsObject(f)
		return 0
	if !hModule := DllCall( &quot;GetModuleHandleW&quot;, &quot;str&quot;, &quot;Advapi32.dll&quot;, &quot;Ptr&quot; )
		hModule := DllCall( &quot;LoadLibraryW&quot;, &quot;str&quot;, &quot;Advapi32.dll&quot;, &quot;Ptr&quot; )
	if !dllCall(&quot;Advapi32\CryptAcquireContextW&quot;
				,&quot;Ptr*&quot;,hCryptProv
				,&quot;Uint&quot;,0
				,&quot;Uint&quot;,0
				,&quot;Uint&quot;,PROV_RSA_AES
				,&quot;UInt&quot;,CRYPT_VERIFYCONTEXT )
		Goto,FreeHandles
	
	if !dllCall(&quot;Advapi32\CryptCreateHash&quot;
				,&quot;Ptr&quot;,hCryptProv
				,&quot;Uint&quot;,HASH_ALG
				,&quot;Uint&quot;,0
				,&quot;Uint&quot;,0
				,&quot;Ptr*&quot;,hHash )
		Goto,FreeHandles
	
	VarSetCapacity(read_buf,BUFF_SIZE,0)
	
    hCryptHashData := DllCall(&quot;GetProcAddress&quot;, &quot;Ptr&quot;, hModule, &quot;AStr&quot;, &quot;CryptHashData&quot;, &quot;Ptr&quot;)
	While (cbCount := f.RawRead(read_buf, BUFF_SIZE))
	{
		if (cbCount = 0)
			break
		
		if !dllCall(hCryptHashData
					,&quot;Ptr&quot;,hHash
					,&quot;Ptr&quot;,&amp;read_buf
					,&quot;Uint&quot;,cbCount
					,&quot;Uint&quot;,0 )
			Goto,FreeHandles
	}
	
	if !dllCall(&quot;Advapi32\CryptGetHashParam&quot;
				,&quot;Ptr&quot;,hHash
				,&quot;Uint&quot;,HP_HASHSIZE
				,&quot;Uint*&quot;,HashLen
				,&quot;Uint*&quot;,HashLenSize := 4
				,&quot;UInt&quot;,0 ) 
		Goto,FreeHandles
		
	VarSetCapacity(pbHash,HashLen,0)
	if !dllCall(&quot;Advapi32\CryptGetHashParam&quot;
				,&quot;Ptr&quot;,hHash
				,&quot;Uint&quot;,HP_HASHVAL
				,&quot;Ptr&quot;,&amp;pbHash
				,&quot;Uint*&quot;,HashLen
				,&quot;UInt&quot;,0 )
		Goto,FreeHandles	
	
	SetFormat,integer,Hex
	loop,%HashLen%
	{
		num := numget(pbHash,A_index-1,&quot;UChar&quot;)
		hashval .= substr((num &gt;&gt; 4),0) . substr((num &amp; 0xf),0)
	}
	SetFormat,integer,D
		
FreeHandles:
	f.Close()
	DllCall(&quot;FreeLibrary&quot;, &quot;Ptr&quot;, hModule)
	dllCall(&quot;Advapi32\CryptDestroyHash&quot;,&quot;Ptr&quot;,hHash)
	dllCall(&quot;Advapi32\CryptReleaseContext&quot;,&quot;Ptr&quot;,hCryptProv,&quot;UInt&quot;,0)
	return hashval
}</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[Indomito]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27285</uri>
			</author>
			<updated>2017-01-17T22:08:51Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111199#p111199</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение .txt и выполнение команды]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111195#p111195" />
			<content type="html"><![CDATA[<p><strong>KenzoHK</strong><br />Попробуй разбирать каждую строку,&nbsp; да и &quot;чек&quot; может быть частью слова, желательно использовать ключ, например &quot;%чек&quot;.<br />Хотя, если это единственно слово в строке, то не нужно огород городить, а проще использовать:<br /> — простое чтение строк <strong>Loop, Read, InputFile [, OutputFile]</strong>;<br /> — разбор строки <strong>Loop, Parse, InputVar [, Delimiters, OmitChars]</strong>.</p><br /><p>Пример самого простого разбора. </p><div class="codebox"><pre><code>Haystack  := &quot;C:\AHK Compiler\AHK Compiler.exe&quot;
Needle  := &quot;\&quot;
a := InStr(Haystack, Needle , , 0)
vDir := SubStr(Haystack, 1 , a-1)
vFile := SubStr(Haystack, a+1)
MsgBox %vDir% --- %vFile%</code></pre></div><p>Удачи с чеками. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[Indomito]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27285</uri>
			</author>
			<updated>2017-01-17T21:21:47Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111195#p111195</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение .txt и выполнение команды]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111171#p111171" />
			<content type="html"><![CDATA[<p>Кстати, если так подумать, вы прочитаете все содержимое чатлога. Ваш способ мне кажется не самый безопасный. Так, можно активировать команду любому игроку, что напишет кодовое слово, не так ли?</p>]]></content>
			<author>
				<name><![CDATA[belyankin12]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34408</uri>
			</author>
			<updated>2017-01-17T07:16:17Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111171#p111171</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение .txt и выполнение команды]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111157#p111157" />
			<content type="html"><![CDATA[<p><strong><em>string</em> </strong>- это не часть выражения, а имя переменной. Вам следует на место этого слова подставить <strong><em>sms</em></strong>.</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2017-01-16T15:47:55Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111157#p111157</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение .txt и выполнение команды]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111156#p111156" />
			<content type="html"><![CDATA[<p><strong>ypppu</strong>, это понятно.<br />Вот мой код, но он не в какую не хочет выполнять команды.<br /></p><div class="codebox"><pre><code>login:= &quot;чек&quot; 
FileRead, sms, %A_MyDocuments%\GTA San Andreas User Files\SAMP\chatlog.txt    
If string contains %login%
(Дальше идут сами действия)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[KenzoHK]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34095</uri>
			</author>
			<updated>2017-01-16T15:24:44Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111156#p111156</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Чтение .txt и выполнение команды]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111155#p111155" />
			<content type="html"><![CDATA[<p><a href="http://www.script-coding.com/AutoHotkey/FileRead.html">FileRead</a>.</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2017-01-16T15:20:46Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111155#p111155</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Чтение .txt и выполнение команды]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111154#p111154" />
			<content type="html"><![CDATA[<p>Есть .txt файл в нем определенное слово, как сделать чтобы это слово читало и начало выполнять команду.</p>]]></content>
			<author>
				<name><![CDATA[KenzoHK]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34095</uri>
			</author>
			<updated>2017-01-16T15:17:39Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111154#p111154</id>
		</entry>
</feed>
