summaryrefslogtreecommitdiff
path: root/curl_test.asm
blob: 159a52008770fb115a77c8fc89c3ce2bf1940ee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
global main

extern curl_easy_init
extern curl_easy_cleanup
extern curl_easy_setopt
extern curl_easy_perform

section .data 
	url db "https://httpbin.org/get", 0

section .text

main:
	sub rsp, 8
	; curl = curl_easy_init()
	call curl_easy_init wrt ..plt  ; puts cURL handle in rax
	test rax, rax  ; if rax == 0 (handle is NULL) it failed
	jz .failed

	mov [rsp], rax

	; curl_easy_setopt(curl, CURLOPT_URL, url)
	mov rdi, [rsp]  ; cURL handle (arg 1)
	mov rsi, 10002  ; CURLOPT_URL
	lea rdx, [rel url]  ; put address of url in rdx
	call curl_easy_setopt wrt ..plt  ; set option CURLOPT_URL to url

	; curl_easy_perform()
	mov rdi, [rsp]  ; cURL handle
	call curl_easy_perform wrt ..plt  ; perform cURL

	; curl_easy_cleanup()
	mov rdi, [rsp]  ; RDI = first function argument, set first argument to rsp (cURL handle)
	call curl_easy_cleanup wrt ..plt  ; call curl_easy_cleanup with argument rdi (cURL handle)

	; return 0
	mov eax, 0  ; eax for return code
	mov qword [rsp], 0  ; zero the cURL pointer just in case because why not
	add rsp, 8
	ret

.failed:
	mov eax, 1  ; eax for return code
	add rsp, 8
	ret