Help http_request with cleo.

Batuhan337tr

Active member
Joined
May 8, 2020
Messages
26
Solutions
1
Reaction score
0
Location
Turkey
I am sending a webhook to Discord via http, but some Turkish characters do not appear I need utf8 encode.

1714324863075.png


I'm using this include
PHP:
// 0AB1: call_scm_func @HTTP_GET 4 host 30@ file_path 29@ response_buffer 28@ is_https 27@ _ret_is_success 30@
:HTTP_GET
0AC8: 31@ = allocate_memory_size 4
0AD3: 31@ = format "GET"
059A:  return_false
0AB1: call_scm_func @HTTP_REQUEST 6 host 0@ file_path 1@ type 31@ response_buffer 2@ data 0 is_https 3@ _ret 30@
0AC9: free_allocated_memory 31@
0AB2: ret 1 30@

// 0AB1: call_scm_func @HTTP_POST 5 host 30@ file_path 29@ response_buffer 28@ data 27@ is_https 26@ _ret_is_success 30@
:HTTP_POST
0AC8: 31@ = allocate_memory_size 5
0AD3: 31@ = format "POST"
0AB1: call_scm_func @HTTP_REQUEST 6 url 0@ file_path 1@ type 31@ response_buffer 2@ data 3@ is_https 4@ _ret 30@
0AC9: free_allocated_memory 31@
0AB2: ret 1 30@


:HTTP_REQUEST
{   
Parematers:
    0@ = host       (e.g. http://example.com)
    1@ = file_path  (e.g. index.php)
    2@ = type       (e.g. GET, POST, PUT)
    3@ = response buffer
    4@ = data       (for POST, PUT requests)
}

16@ = false
0AA2: 31@ = load_library "wininet.dll"
0AA4: 30@ = get_proc_address "InternetCloseHandle" library 31@
0AA4: 29@ = get_proc_address "InternetOpenA" library 31@
0AA7: call_function 29@ num_params 5 pop 0 flags 0 proxy_bypass "" proxy "" access_type 0 user_agent "CLEO" _returned 28@
if 28@ <> 0
then
    0AA4: 27@ = get_proc_address "InternetConnectA" library 31@
    
{    void InternetConnectA(
  HINTERNET     hInternet,
  LPCSTR        lpszServerName,
  INTERNET_PORT nServerPort,
  LPCSTR        lpszUserName,
  LPCSTR        lpszPassword,
  DWORD         dwService,
  DWORD         dwFlags,
  DWORD_PTR     dwContext
);
}
    // 3 = INTERNET_SERVICE_HTTP
    if 5@ == true
    then
        // https
        0AA7: call_function 27@ num_params 8 pop 0 0 0 3 "" "" port 443 host 0@ connection_handle 28@ _returned 26@
    else
        // http
        0AA7: call_function 27@ num_params 8 pop 0 0 0 3 "" "" port 80 host 0@ connection_handle 28@ _returned 26@
    end
    
    if 26@ <> 0
    then
        0AA4: 25@ = get_proc_address "HttpOpenRequestA" library 31@
        
        /*  0x80400100 is a set of flags:
            0x80000000 - INTERNET_FLAG_RELOAD
              
              0x800000 - INTERNET_FLAG_SECURE
              0x400000 - INTERNET_FLAG_KEEP_CONNECTION (both these flags result in 12, so "c" in hexadecimal)
              
                 0x100 - INTERNET_FLAG_PRAGMA_NOCACHE
            Reference: https://docs.microsoft.com/en-us/windows/win32/wininet/api-flags   */
        if 5@ == true
        then
            // https
            0AA7: call_function 25@ num_params 8 pop 0 dwContext 0 dwFlags 0x80c00100 accept_types 0 referrer "" version "HTTP/1.1" file_path 1@ request_type 2@ connection_handle 26@ _returned 24@
        else
            0AA7: call_function 25@ num_params 8 pop 0 dwContext 0 dwFlags 0x80400100 accept_types 0 referrer "" version "HTTP/1.1" file_path 1@ request_type 2@ connection_handle 26@ _returned 24@
        end
        
        if 24@ <> 0
        then
            if 4@ == 0
            then
                17@ = 0
            else                       
                0AB1: call_scm_func @http_requests_unique_strlen 1 4@ _returned 17@
            end
 
            0AA4: 22@ = get_proc_address "HttpSendRequestA" library 31@
            
            // content and content_length can be 0 if there's no data to send (e.g. in GET request)
            0AA7: call_function 22@ num_params 5 pop 0  content_length 17@ content 4@ headers_length 47 headers "Content-Type: application/x-www-form-urlencoded" request_handle 24@ _returned 21@


            0AA4: 20@ = get_proc_address "InternetReadFile" library 31@
            
            18@ = 1
            0AC7: 19@ = var 18@ offset
            while 18@ > 0               
                wait 0
                0AA5: call_function 20@ num_params 4 pop 0 ptr_to_number_of_bytes_read 19@ number_of_bytes_to_receive 31 receive_data_buffer 3@ file_handle 24@
                005A: 3@ += 18@
                16@ = true
            end
            0A8C: write_memory 3@ size 1 value 0 virtual_protect 0
            0AA5: call_function 30@ num_params 1 pop 0 24@
        end
 
        0AA5: call_function 30@ num_params 1 pop 0 26@
    end
 
    0AA5: call_function 30@ num_params 1 pop 0 28@
end
 
0AA3: free_library 31@

{ it just doesn't work properly (idk why)
if 16@ == true
then
    0485:  return_true
else
    059A:  return_false
end}
0AB2: ret 1 16@

:http_requests_unique_strlen // called like that to avoid coliding with strlen (if someone has it in their code)
8@ = 0
0A8D: 9@ = read_memory 0@ size 1 virtual_protect 0
while 9@ <> 0
    8@++
    0@++
    0A8D: 9@ = read_memory 0@ size 1 virtual_protect 0   
end
0AB2: ret 1 8@
 

Batuhan337tr

Active member
Joined
May 8, 2020
Messages
26
Solutions
1
Reaction score
0
Location
Turkey
show all code
1714603739869.png

PHP:
{$CLEO .cs}
0000:

REPEAT
WAIT 0                                                   t

UNTIL 0AFA: SAMP_IS_READY

0B34: samp register_client_command "sendwebhook" to_label @sendwebhook

0AC8: $WEBHOOK_HOST = allocate_memory_size 1024
0AD3: $WEBHOOK_HOST = format "discord.com"
0AC8: $WEBHOOK_URL = allocate_memory_size 1024
0AD3: $WEBHOOK_URL = format "api/webhooks/1212123839191314442/Acsdy48w_FODJjYLcfmC_KyRFGAHd4V3iaXlAUp-0U4G4cfaSPgWeszfsxqShm4t7bVH"  
0AC8: $WEBHOOK_BUFFER = allocate_memory_size 1024  
0AC8: $WEBHOOK_DATA = allocate_memory_size 1024

WHILE TRUE
WAIT 0

END

:sendwebhook
0AD3: $WEBHOOK_DATA = format "content=Bu bir test mesajdır."
0AB1: call_scm_func @HTTP_POST 5 host $WEBHOOK_HOST file_path $WEBHOOK_URL response_buffer $WEBHOOK_BUFFER data $WEBHOOK_DATA is_https true _ret_is_success $KONTROL
cmdret

{$INCLUDE includes/http_requests.txt}

@Saam
 
Top