Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SECTION .text
- global main
- extern exit
- extern printf
- extern snprintf
- extern strlen
- extern strpos
- extern strstr
- main:
- mov dword[init_ebp],ebp
- mov dword[init_esp],esp
- push ebp
- mov ebp,esp
- ;Count the args
- ;==============
- mov ecx,dword[ebp+8]
- cmp ecx,1
- jl .usage
- mov ebx,dword[ebp+12]
- ;call exit
- mov ecx,dword[ebx+4]
- mov dword[target_host],ecx
- ;look for the scheme delimiter
- ;=============================
- push scheme_delimiter
- push dword[target_host]
- call strstr
- cmp eax,0
- je .no_scheme_delimter
- add eax,3 ;Point past the delimiter
- mov dword[target_host_ptr],eax ;save the pointer
- add esp,8 ;restore the stack pointer
- ;check for www.
- ;==============
- push dub_dot
- push dword[target_host_ptr]
- call strstr
- cmp eax,0
- je .no_dub_dot
- ;if(strstr(target_host_ptr,"www.") == target_host_ptr){
- cmp eax,dword[target_host_ptr]
- je .dub_dot_found
- ;}else{
- jmp .no_dub_dot
- .no_scheme_delimter:
- push msg_no_scheme
- push printf_format_string
- call printf
- add esp,8
- mov eax,-1
- jmp .leaveMain
- .dub_dot_found:
- add dword[target_host_ptr],4 ;point past the www.
- add esp,8
- .no_dub_dot:
- ;save everything until / or end of string is reached
- ;===================================================
- push dword[target_host]
- call strlen
- add esp,4
- mov ecx,0
- mov esi,dword[target_host_ptr]
- mov dword[host_name],esi
- .save_loop:
- cmp byte[esi+ecx],0
- je .stop_saving
- cmp byte[esi+ecx],'/'
- je .save_uri
- cmp byte[esi+ecx],':'
- je .save_port
- .resume_port:
- inc ecx
- jmp .save_loop
- .stop_saving:
- mov dword[host_name_end],esi
- add dword[host_name_end],ecx
- push dword[host_name]
- push printf_format_string
- call printf
- add esp,8
- jmp .leaveMain
- .save_uri:
- mov dword[host_name_end],esi
- add dword[host_name_end],ecx
- dec dword[host_name_end]
- mov dword[target_uri],esi
- add dword[target_uri],ecx
- push dword[target_uri]
- push printf_format_string
- call printf
- add esp,8
- jmp .leaveMain
- .save_port:
- mov dword[port_start],esi
- add dword[port_start],ecx
- inc dword[port_start]
- .save_port_loop:
- inc ecx
- cmp byte[esi+ecx],0
- je .end_save_port_loop
- cmp byte[esi+ecx],'/'
- je .end_save_port_loop
- jmp .save_port_loop
- .end_save_port_loop:
- mov dword[port_end],esi
- add dword[port_end],ecx
- cmp byte[esi+ecx],0
- je .stop_saving
- dec ecx
- jmp .resume_port
- .usage:
- push usage
- push printf_format_string
- call printf
- jmp .leaveMain
- .leaveMain:
- mov ebp,[init_ebp]
- mov esp,[init_esp]
- ret
- SECTION .data
- dub_dot: dd 'www.',0
- host_name: dd 0
- host_name_end: dd 0
- init_ebp: dd 0
- init_esp: dd 0
- msg_dub_dot_found: dd "www. found",0
- msg_no_dub_dot: dd "No www. found",0
- msg_no_scheme: dd "No scheme delimiter found",0
- port_found: dd 0
- port_end: dd 0
- port_start: dd 0
- printf_format_string: dd '%s',0xa,0xd,0
- scheme_delimiter: dd '://',0
- target_host: dd 0
- target_host_ptr: dd 0
- target_host_ptr_end: dd 0
- target_port: dw 80
- target_uri: dd 0
- usage: db 'Usage: ./a.out <URL>',0xa,0xd,
- db 'Example: ./a.out http://www.google.com/index.html',0
- SECTION .bss
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement