how can download a file (for example file.text) from an url in assembly language
programing in mac osx or linux
Two main methods:
I can download file with sending command to bash with using execve syscall and call Curl
But I want download file from my program and not use another program or process.
I think I'll be using your second suggestion.
But I don't know how call funcion in another library
I can call printf or puts of c function in my assembly code , but i can not call curl function from libcurl.dylib
How can call it's function?
Edited 2 Years Ago by recher_14263
You have to first declare it as an external function using something like
extern function_name_here (the exact syntax will vary from assembler to assembler). Then, you need to instruct your linker to link against
libcurl.dylib. What assembler/toolchain are you using?
It really is not hard at all to use libcurl. You read the docs pass some parameters and call the functions. The following simple code will get googles robots.txt file and display it in the terminal.
It is 64-bit using NASM tested on Linux
%define CURL_GLOBAL_SSL (1<<0) %define CURL_GLOBAL_WIN32 (1<<1) %define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) %define CURL_GLOBAL_NOTHING 0 %define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL %define CURLOPT_URL 10002 %define CURLOPT_FOLLOWLOCATION 52 %define CURLOPT_WRITEHEADER 10029 %define CURLOPT_WRITEDATA 10001 extern curl_easy_init, curl_easy_cleanup, curl_easy_setopt, curl_easy_perform extern curl_global_init, curl_global_cleanup extern exit, stdout section .data url db "http://www.google.com/robots.txt", 0 global main section .text main: mov rdi, CURL_GLOBAL_ALL call curl_global_init call curl_easy_init mov r15, rax mov rdx, url mov rsi, CURLOPT_URL mov rdi, r15 xor rax, rax call curl_easy_setopt mov rdx, 1 mov rsi, CURLOPT_FOLLOWLOCATION mov rdi, r15 xor rax, rax call curl_easy_setopt mov rdx, [stdout] mov rsi, CURLOPT_WRITEDATA mov rdi, r15 xor rax, rax call curl_easy_setopt mov rdi, r15 call curl_easy_perform mov rdi, r15 call curl_easy_cleanup call curl_global_cleanup mov rdi, 0 call exit
Error handling/checking has been left out.
and the makefile:
APP=download_file all: $(APP) clean $(APP): $(APP).o gcc -g -o $(APP) $(APP).o -lcurl $(APP).o: $(APP).asm nasm -f elf64 $(APP).asm -F dwarf clean: rm $(APP).o
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...