Небольшая библиотека, всего две функции для отправки фото или текста в чат или канал. Библиотека была рабочей в 2016г, сейчас не проверял. Код (Text): ; 06.05.2016 ;********************************************************************************************************************************************************** include \masm32\include\masm32rt.inc include \masm32\include\wininet.inc includelib \masm32\lib\wininet.lib include \masm32\include\urlmon.inc includelib \masm32\lib\urlmon.lib TelegramSendPhoto proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD TelegramSendMessage proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD TelegramSendPhoto_thread proto :DWORD TelegramSendMessage_thread proto :DWORD UnicodeToUTF8 proto :DWORD Set_hWnd proto :DWORD ;macro xparam MACRO n_const, ident mov ebx, ident mov ecx, n_const shl ecx, 16 or ecx, ebx EXITM <ecx> ENDM .data align 4 szContentHeader db "Content-Type: multipart/form-data",03bh," boundary=----------E1jIDWEkDVeOLS0pj8Qh5U",0 align 4 szFormChatID db "------------E1jIDWEkDVeOLS0pj8Qh5U",13,10 db "Content-Disposition: form-data",03bh," name=",022h,"chat_id",022h,13,10,13,10 db "%s",13,10,0 align 4 szFormCaption db "------------E1jIDWEkDVeOLS0pj8Qh5U",13,10 db "Content-Disposition: form-data",03bh," name=",022h,"caption",022h,13,10,13,10,0 ;+caption+13,10 align 4 szFormText db "------------E1jIDWEkDVeOLS0pj8Qh5U",13,10 db "Content-Disposition: form-data",03bh," name=",022h,"parse_mode",022h,13,10,13,10 db "html",13,10 szFormTex2 db "------------E1jIDWEkDVeOLS0pj8Qh5U",13,10 db "Content-Disposition: form-data",03bh," name=",022h,"text",022h,13,10,13,10,0 ;+text+13,10 align 4 szFormPhoto db "------------E1jIDWEkDVeOLS0pj8Qh5U",13,10 db "Content-Disposition: form-data",03bh," name=",022h,"photo",022h,03bh," filename=",022h,"%s",022h,13,10 db "Content-Type: image/jpeg",13,10,13,10,0 align 4 szFinalBoundary db 13,10,"------------E1jIDWEkDVeOLS0pj8Qh5U--",13,10,0 align 4 .data? hWindow dd ? .code ;********************************************************************************************************************************************************** Set_hWnd proc uses ebx hWnd:DWORD mrm hWindow, hWnd ret Set_hWnd endp ;********************************************************************************************************************************************************** TelegramSendPhoto proc uses ebx szClient:DWORD, szServer:DWORD, szBOT:DWORD, szChatID:DWORD, szMsg:DWORD, szPhoto:DWORD invoke VirtualAlloc, 0, 4096, MEM_COMMIT, PAGE_READWRITE mov ebx, eax mrm dword ptr[ebx+4], szClient mrm dword ptr[ebx+8], szServer mrm dword ptr[ebx+12], szBOT mrm dword ptr[ebx+16], szChatID mrm dword ptr[ebx+20], szMsg mrm dword ptr[ebx+24], szPhoto mrm dword ptr[ebx+28], 0 invoke CreateThread, 0, 0, addr TelegramSendPhoto_thread, ebx, 0, ebx cmp eax, 0 je @F mrm dword ptr[ebx+28], eax return 1 @@: invoke VirtualFree, ebx, 0, MEM_RELEASE return 0 TelegramSendPhoto endp ;********************************************************************************************************************************************************** TelegramSendMessage proc uses ebx szClient:DWORD, szServer:DWORD, szBOT:DWORD, szChatID:DWORD, szMsg:DWORD invoke VirtualAlloc, 0, 4096, MEM_COMMIT, PAGE_READWRITE mov ebx, eax mrm dword ptr[ebx+4], szClient mrm dword ptr[ebx+8], szServer mrm dword ptr[ebx+12], szBOT mrm dword ptr[ebx+16], szChatID mrm dword ptr[ebx+20], szMsg mrm dword ptr[ebx+24], 0;no use mrm dword ptr[ebx+28], 0 invoke CreateThread, 0, 0, addr TelegramSendMessage_thread, ebx, 0, ebx cmp eax, 0 je @F mrm dword ptr[ebx+28], eax return 1 @@: invoke VirtualFree, ebx, 0, MEM_RELEASE return 0 TelegramSendMessage endp ;********************************************************************************************************************************************************** TelegramSendPhoto_thread proc vMemory:DWORD LOCAL szClient:DWORD, szServer:DWORD, szBOT:DWORD, szChatID:DWORD, szMsg:DWORD, szPhoto:DWORD LOCAL hSession:DWORD, hConnect:DWORD, hRequest:DWORD, dwContentLength:DWORD, rzv:DWORD, headSize:DWORD, boundarySize:DWORD LOCAL dwFileSize:DWORD, hFile:DWORD, pBuf:DWORD, bwr:DWORD, zzxxcc:DWORD, temp_str1:DWORD, temp_str2:DWORD, temp_str3:DWORD, temp_str4:DWORD LOCAL loc_str[1024]:TCHAR LOCAL loc_BOT[512]:TCHAR mov ebx, vMemory mrm szClient, dword ptr[ebx+4] mrm szServer, dword ptr[ebx+8] mrm szBOT, dword ptr[ebx+12] mrm szChatID, dword ptr[ebx+16] mrm szMsg, dword ptr[ebx+20] mrm szPhoto, dword ptr[ebx+24] invoke lstrcpy, addr loc_BOT, SADD("bot") invoke lstrcat, addr loc_BOT, szBOT invoke lstrcat, addr loc_BOT, SADD("/sendPhoto") mov zzxxcc, 0 mov hFile, 0 mov hSession, 0 mov hConnect, 0 mov hRequest, 0 mov pBuf, 0 add ebx, 128 mov temp_str4, ebx add ebx, 256 mov temp_str3, ebx add ebx, 256 mov temp_str2, ebx add ebx, 512 mov temp_str1, ebx invoke wsprintf, temp_str1, addr szFormChatID, szChatID invoke lstrcpy, temp_str2, addr szFormCaption invoke wsprintf, temp_str3, addr szFormPhoto, szPhoto invoke lstrcpyW, addr loc_str, szMsg invoke UnicodeToUTF8, addr loc_str invoke lstrlen, temp_str2 mov ebx, eax invoke lstrlen, addr loc_str mov ecx, eax mov eax, temp_str2 add eax, ebx add ebx, ecx ;summ len lea esi, loc_str mov edi, eax rep movsb mov eax, temp_str2 mov word ptr[eax+ebx], 0a0dh add ebx, 2 invoke lstrlen, temp_str1 mov edx, eax mov eax, temp_str1 add eax, edx mov esi, temp_str2 mov edi, eax mov ecx, ebx rep movsb add ebx, edx invoke lstrlen, temp_str3 mov edx, eax mov eax, temp_str1 add eax, ebx mov esi, temp_str3 mov edi, eax mov ecx, edx rep movsb add ebx, edx mov headSize, ebx invoke lstrlen, addr szFinalBoundary mov boundarySize, eax ;------------------------------------------------------------------------------------------------------------------------------ invoke CreateFile, szPhoto, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0 cmp eax, INVALID_HANDLE_VALUE je @F mov hFile, eax invoke GetFileSize, hFile, 0 mov dwFileSize, eax mov ebx, headSize add ebx, boundarySize add ebx, dwFileSize mov dwContentLength, ebx add ebx, 2048 invoke VirtualAlloc, 0, ebx, MEM_COMMIT, PAGE_READWRITE mov pBuf, eax mov esi, temp_str1 mov edi, pBuf mov ecx, headSize rep movsb mov ebx, headSize mov edx, pBuf add edx, ebx invoke ReadFile, hFile, edx, dwFileSize, addr rzv, 0 add ebx, dwFileSize lea esi, szFinalBoundary mov edi, pBuf add edi, ebx mov ecx, boundarySize rep movsb invoke CloseHandle, hFile mov hFile, 0 ;------------------------------------------------------------------------------------------------------------------------------ invoke InternetOpen, szClient, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0 cmp eax, 0 je @F mov hSession, eax invoke InternetConnect, hSession, szServer, INTERNET_DEFAULT_HTTPS_PORT, 0, 0, INTERNET_SERVICE_HTTP, 0, 0 cmp eax, 0 je @F mov hConnect, eax invoke HttpOpenRequest, hConnect, SADD("POST"), addr loc_BOT, 0, 0, 0, INTERNET_FLAG_NO_UI or INTERNET_FLAG_SECURE or INTERNET_FLAG_IGNORE_CERT_CN_INVALID or INTERNET_FLAG_IGNORE_CERT_DATE_INVALID, 0 cmp eax, 0 je @F mov hRequest, eax invoke HttpAddRequestHeaders, hRequest, addr szContentHeader, -1, HTTP_ADDREQ_FLAG_ADD cmp eax, 0 je @F invoke wsprintf, temp_str4, SADD("Content-Length: %d"), dwContentLength invoke HttpSendRequest, hRequest, temp_str4, -1, pBuf, dwContentLength cmp eax, 0 je @F ;invoke InternetReadFile, hRequest, temp_str4, 200, addr bwr ;cmp eax, 0 ;je @F ;invoke MessageBox, hWindow, temp_str4, 0, MB_OK mov zzxxcc, 1 @@: cmp pBuf, 0 je @F invoke VirtualFree, pBuf, 0, MEM_RELEASE @@: cmp hRequest, 0 je @F invoke InternetCloseHandle, hRequest @@: cmp hConnect, 0 je @F invoke InternetCloseHandle, hConnect @@: cmp hSession, 0 je @F invoke InternetCloseHandle, hSession @@: cmp hFile, 0 je @F invoke CloseHandle, hFile @@: ;************************************************** mov ebx, vMemory @@: invoke Sleep, 1 cmp dword ptr[ebx+28], 0 je @B mov edx, dword ptr[ebx+28] invoke CloseHandle, edx invoke VirtualFree, vMemory, 0, MEM_RELEASE ;************************************************** cmp zzxxcc, 0 je @F return 1 @@: invoke PostMessage, hWindow, WM_COMMAND, xparam(BN_CLICKED, 2202), 0 return 0 ;error TelegramSendPhoto_thread endp ;######################################################################################################################################################## ;######################################################################################################################################################## TelegramSendMessage_thread proc vMemory:DWORD LOCAL szClient:DWORD, szServer:DWORD, szBOT:DWORD, szChatID:DWORD, szMsg:DWORD LOCAL hSession:DWORD, hConnect:DWORD, hRequest:DWORD, headSize:DWORD LOCAL bwr:DWORD, zzxxcc:DWORD, temp_str1:DWORD, temp_str2:DWORD, temp_str3:DWORD, temp_str4:DWORD LOCAL loc_str[1024]:TCHAR LOCAL loc_BOT[512]:TCHAR mov ebx, vMemory mrm szClient, dword ptr[ebx+4] mrm szServer, dword ptr[ebx+8] mrm szBOT, dword ptr[ebx+12] mrm szChatID, dword ptr[ebx+16] mrm szMsg, dword ptr[ebx+20] invoke lstrcpy, addr loc_BOT, SADD("bot") invoke lstrcat, addr loc_BOT, szBOT invoke lstrcat, addr loc_BOT, SADD("/sendMessage") mov zzxxcc, 0 mov hSession, 0 mov hConnect, 0 mov hRequest, 0 add ebx, 128 mov temp_str4, ebx add ebx, 256 mov temp_str3, ebx add ebx, 256 mov temp_str2, ebx add ebx, 1280 mov temp_str1, ebx invoke wsprintf, temp_str1, addr szFormChatID, szChatID invoke lstrcpy, temp_str2, addr szFormText invoke lstrcpyW, addr loc_str, szMsg invoke UnicodeToUTF8, addr loc_str invoke lstrlen, temp_str2 mov ebx, eax invoke lstrlen, addr loc_str mov ecx, eax mov eax, temp_str2 add eax, ebx add ebx, ecx ;summ len lea esi, loc_str mov edi, eax rep movsb mov eax, temp_str2 mov word ptr[eax+ebx], 0a0dh add ebx, 2 invoke lstrlen, temp_str1 mov edx, eax mov eax, temp_str1 add eax, edx mov esi, temp_str2 mov edi, eax mov ecx, ebx rep movsb add ebx, edx invoke lstrlen, addr szFinalBoundary lea esi, szFinalBoundary mov edi, temp_str1 add edi, ebx mov ecx, eax rep movsb add ebx, eax mov headSize, ebx ;invoke MessageBox, hWindow, ustr$(headSize), 0, MB_OK ;------------------------------------------------------------------------------------------------------------------------------ invoke InternetOpen, szClient, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0 cmp eax, 0 je @F mov hSession, eax invoke InternetConnect, hSession, szServer, INTERNET_DEFAULT_HTTPS_PORT, 0, 0, INTERNET_SERVICE_HTTP, 0, 0 cmp eax, 0 je @F mov hConnect, eax invoke HttpOpenRequest, hConnect, SADD("POST"), addr loc_BOT, 0, 0, 0, INTERNET_FLAG_NO_UI or INTERNET_FLAG_SECURE or INTERNET_FLAG_IGNORE_CERT_CN_INVALID or INTERNET_FLAG_IGNORE_CERT_DATE_INVALID, 0 cmp eax, 0 je @F mov hRequest, eax invoke HttpAddRequestHeaders, hRequest, addr szContentHeader, -1, HTTP_ADDREQ_FLAG_ADD cmp eax, 0 je @F ;------------------------------ invoke wsprintf, temp_str4, SADD("Content-Length: %d"), headSize invoke HttpSendRequest, hRequest, temp_str4, -1, temp_str1, headSize cmp eax, 0 je @F ;invoke InternetReadFile, hRequest, temp_str4, 200, addr bwr ;cmp eax, 0 ;je @F ;invoke MessageBox, hWindow, temp_str4, 0, MB_OK mov zzxxcc, 1 @@: cmp hRequest, 0 je @F invoke InternetCloseHandle, hRequest @@: cmp hConnect, 0 je @F invoke InternetCloseHandle, hConnect @@: cmp hSession, 0 je @F invoke InternetCloseHandle, hSession @@: ;************************************************** mov ebx, vMemory @@: invoke Sleep, 1 cmp dword ptr[ebx+28], 0 je @B mov edx, dword ptr[ebx+28] invoke CloseHandle, edx invoke VirtualFree, vMemory, 0, MEM_RELEASE ;************************************************** cmp zzxxcc, 0 je @F return 1 @@: invoke PostMessage, hWindow, WM_COMMAND, xparam(BN_CLICKED, 2202), 0 return 0 ;error TelegramSendMessage_thread endp ;********************************************************************************************************************************************************** UnicodeToUTF8 proc pBuf:DWORD LOCAL pTempBuf:DWORD, cbTempBuf:DWORD xor ecx, ecx invoke WideCharToMultiByte, CP_UTF8, ecx, pBuf, -1, ecx, ecx, ecx, ecx ;подсчет необходимого количества памяти для UTF8 test eax, eax jz @F mov cbTempBuf, eax invoke VirtualAlloc, 0, eax, MEM_COMMIT, PAGE_READWRITE test eax, eax jz @F mov pTempBuf, eax xor ecx, ecx invoke WideCharToMultiByte, CP_UTF8, ecx, pBuf, -1, pTempBuf, cbTempBuf, ecx, ecx ;перегоняем строчку в UTF8 invoke lstrcpy, pBuf, pTempBuf ;копируем результат в исходный буфер invoke VirtualFree, pTempBuf, 0, MEM_RELEASE @@: ret UnicodeToUTF8 endp ;********************************************************************************************************************************************************** end