Пример1
Код
--lua
local ffi = require("ffi")
local inet = ffi.load('Wininet.dll')
local INTERNET_OPEN_TYPE_PRECONFIG = 0
local INTERNET_DEFAULT_HTTPS_PORT = 443
local INTERNET_SERVICE_HTTP = 3
local INTERNET_FLAG_SECURE = 8388608
local INTERNET_FLAG_NO_CACHE_WRITE = 67108864
ffi.cdef[[
int InternetOpenA(const char* lpszAgent, unsigned long dwAccessType, const char* lpszProxy, const char* lpszProxyBypass, unsigned long dwFlags);
bool InternetCloseHandle(int hInternet);
int InternetConnectA(int hInternet, const char* lpszServerName, unsigned short nServerPort, const char* lpszUserName,
const char* lpszPassword, unsigned long dwService, unsigned long dwFlags,unsigned long dwContext);
int HttpOpenRequestA(int hConnect, const char* lpszVerb, const char* lpszObjectName, const char* lpszVersion,
const char* lpszReferrer, const char* lplpszAcceptTypes, unsigned long dwFlags, unsigned long dwContext);
bool HttpSendRequestA(int hRequest, const char* lpszHeaders, unsigned long dwHeadersLength, const char* lpOptional, unsigned long dwOptionalLength);
bool InternetReadFile(int hFile, char* lpBuffer, unsigned long dwNumberOfBytesToRead, unsigned long* lpdwNumberOfBytesRead);
]]
function http(Verb, ServerName, ObjectName)
local buf = ffi.new('char[9999]')
local dwBytesRead = ffi.new('unsigned long[1]')
local hInternet = inet.InternetOpenA("Mozilla", INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
if hInternet then
local hConnect = inet.InternetConnectA(hInternet, ServerName, INTERNET_DEFAULT_HTTPS_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0)
if hConnect then
local hRequest = inet.HttpOpenRequestA(hConnect, Verb, ObjectName, nil, nil, nil, INTERNET_FLAG_SECURE + INTERNET_FLAG_NO_CACHE_WRITE, 0)
if hRequest then
inet.HttpSendRequestA(hRequest, '', 0, '', 0)
local fr=''
while inet.InternetReadFile(hRequest, buf, ffi.sizeof(buf)-1, dwBytesRead) do
if dwBytesRead[0] == 0 then break end
fr = fr .. ffi.string(buf, dwBytesRead[0])
end
inet.InternetCloseHandle(hRequest)
return fr
end
inet.InternetCloseHandle(hConnect)
end
local close = inet.InternetCloseHandle(hInternet)
end
end
log 'clear' log 'mode compact'
local s = http('POST', 'forum.uokit.com', 'index.php') -- отправка запроса
-- в переменной s содержится код страницы forum.uokit.com/index.php
local guest, user, hidden = s:match('%<b%>(%d+)%<%/b%> гостей, %<b%>(%d+)%<%/b%> пользователей %<b%>(%d+)%<%/b%> скрытых пользователей')
log('На форуме сейчас:\r\n', guest, 'гостей, ', user, ' пользователей, ', hidden, ' скрытых пользователей\r\n')
log('Список пользователей:')
for name_user in s:gmatch('title=.%d+:%d+.-([^%>]-)%<%/') do
log(name_user)
end
Пример2
Код
--lua
local ffi = require("ffi")
local inet = ffi.load('Wininet.dll')
local shell = ffi.load('Shell32.dll')
ffi.cdef[[
int InternetOpenA(const char* lpszAgent, unsigned long dwAccessType, const char* lpszProxy, const char* lpszProxyBypass, unsigned long dwFlags);
bool InternetCloseHandle(int hInternet);
int InternetConnectA(int hInternet, const char* lpszServerName, unsigned short nServerPort, const char* lpszUserName,
const char* lpszPassword, unsigned long dwService, unsigned long dwFlags,unsigned long dwContext);
int HttpOpenRequestA(int hConnect, const char* lpszVerb, const char* lpszObjectName, const char* lpszVersion,
const char* lpszReferrer, const char* lplpszAcceptTypes, unsigned long dwFlags, unsigned long dwContext);
bool HttpSendRequestA(int hRequest, const char* lpszHeaders, unsigned long dwHeadersLength, const char* lpOptional, unsigned long dwOptionalLength);
bool InternetReadFile(int hFile, char* lpBuffer, unsigned long dwNumberOfBytesToRead, unsigned long* lpdwNumberOfBytesRead);
]]
local INTERNET_OPEN_TYPE_PRECONFIG = 0
local INTERNET_DEFAULT_HTTPS_PORT = 443
local INTERNET_SERVICE_HTTP = 3
local INTERNET_FLAG_SECURE = 8388608
local INTERNET_FLAG_NO_CACHE_WRITE = 67108864
ffi.cdef[[int ShellExecuteA(int hwnd, const char* lpOperation, const char* lpFile, const char* lpParameters, const char* lpDirectory, int nShowCmd);]]
local SW_SHOW = 5
function http(Verb, ServerName, ObjectName)
local buf = ffi.new('char[9999]')
local dwBytesRead = ffi.new('unsigned long[1]')
local hInternet = inet.InternetOpenA("Mozilla", INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
if hInternet then
local hConnect = inet.InternetConnectA(hInternet, ServerName, INTERNET_DEFAULT_HTTPS_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0)
if hConnect then
local hRequest = inet.HttpOpenRequestA(hConnect, Verb, ObjectName, nil, nil, nil, INTERNET_FLAG_SECURE + INTERNET_FLAG_NO_CACHE_WRITE, 0)
if hRequest then
inet.HttpSendRequestA(hRequest, '', 0, '', 0)
local fr=''
while inet.InternetReadFile(hRequest, buf, ffi.sizeof(buf)-1, dwBytesRead) do
if dwBytesRead[0] == 0 then break end
fr = fr .. ffi.string(buf, dwBytesRead[0])
end
inet.InternetCloseHandle(hRequest)
return fr
end
inet.InternetCloseHandle(hConnect)
end
local close = inet.InternetCloseHandle(hInternet)
end
return nil
end
log 'clear' log 'mode compact'
local name_function = 'CreateWindowExA'
-- получить содержимое страницы https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexa
local s = http('POST', 'docs.microsoft.com', [[en-us/windows/win32/api/winuser/nf-winuser-]] .. name_function)
if s then
local file = io.open([[C:\content.txt]], 'wb')
if file then
file:write(s)
file:close()
shell.ShellExecuteA(0, 'open', [[C:\content.txt]], '', '', SW_SHOW)
end
-- найти текст между <pre><code class="lang-cpp"> и </code></pre>
local parameters = s:match('%<pre%>%<code class%=%"lang%-cpp%"%>(.-)%<%/code%>%<%/pre%>')
if parameters then
log (parameters)
end
end
Пример3
Код
--lua
local ffi = require("ffi")
local inet = ffi.load('Wininet.dll')
local INTERNET_OPEN_TYPE_PRECONFIG = 0
local INTERNET_DEFAULT_HTTPS_PORT = 443
local INTERNET_SERVICE_HTTP = 3
local INTERNET_FLAG_SECURE = 8388608
local INTERNET_FLAG_NO_CACHE_WRITE = 67108864
ffi.cdef[[
int InternetOpenA(const char* lpszAgent, unsigned long dwAccessType, const char* lpszProxy, const char* lpszProxyBypass, unsigned long dwFlags);
bool InternetCloseHandle(int hInternet);
int InternetConnectA(int hInternet, const char* lpszServerName, unsigned short nServerPort, const char* lpszUserName,
const char* lpszPassword, unsigned long dwService, unsigned long dwFlags,unsigned long dwContext);
int HttpOpenRequestA(int hConnect, const char* lpszVerb, const char* lpszObjectName, const char* lpszVersion,
const char* lpszReferrer, const char* lplpszAcceptTypes, unsigned long dwFlags, unsigned long dwContext);
bool HttpSendRequestA(int hRequest, const char* lpszHeaders, unsigned long dwHeadersLength, const char* lpOptional, unsigned long dwOptionalLength);
bool InternetReadFile(int hFile, char* lpBuffer, unsigned long dwNumberOfBytesToRead, unsigned long* lpdwNumberOfBytesRead);
]]
function http(Verb, ServerName, ObjectName)
local buf = ffi.new('char[9999]')
local dwBytesRead = ffi.new('unsigned long[1]')
local hInternet = inet.InternetOpenA("Mozilla", INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
if hInternet then
local hConnect = inet.InternetConnectA(hInternet, ServerName, INTERNET_DEFAULT_HTTPS_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0)
if hConnect then
local hRequest = inet.HttpOpenRequestA(hConnect, Verb, ObjectName, nil, nil, nil, INTERNET_FLAG_SECURE + INTERNET_FLAG_NO_CACHE_WRITE, 0)
if hRequest then
inet.HttpSendRequestA(hRequest, '', 0, '', 0)
local fr=''
while inet.InternetReadFile(hRequest, buf, ffi.sizeof(buf)-1, dwBytesRead) do
if dwBytesRead[0] == 0 then break end
fr = fr .. ffi.string(buf, dwBytesRead[0])
end
inet.InternetCloseHandle(hRequest)
return fr
end
inet.InternetCloseHandle(hConnect)
end
local close = inet.InternetCloseHandle(hInternet)
end
end
log 'clear' log 'mode compact'
local s = http('GET', 'api.ipify.org', '') -- отправка запроса
log (s)
s = http('GET', 'api.ipify.org', '?format=json') -- отправка запроса
log (s)