Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. SECTION .text
  3.     global  main
  4.     extern  exit
  5.     extern  printf
  6.     extern  snprintf
  7.     extern  strlen
  8.     extern  strpos
  9.     extern  strstr
  10. main:
  11.     mov     dword[init_ebp],ebp
  12.     mov     dword[init_esp],esp
  13.     push    ebp
  14.     mov     ebp,esp
  15.     ;Count the args
  16.     ;==============
  17.     mov     ecx,dword[ebp+8]
  18.     cmp     ecx,1
  19.     jl      .usage
  20.  
  21.     mov     ebx,dword[ebp+12]
  22.     ;call    exit
  23.  
  24.     mov     ecx,dword[ebx+4]
  25.     mov     dword[target_host],ecx
  26.  
  27.     ;look for the scheme delimiter
  28.     ;=============================
  29.     push    scheme_delimiter
  30.     push    dword[target_host]
  31.     call    strstr
  32.     cmp     eax,0
  33.     je      .no_scheme_delimter
  34.     add     eax,3               ;Point past the delimiter
  35.     mov     dword[target_host_ptr],eax  ;save the pointer
  36.     add     esp,8               ;restore the stack pointer
  37.     ;check for www.
  38.     ;==============
  39.     push    dub_dot
  40.     push    dword[target_host_ptr]
  41.     call    strstr
  42.     cmp     eax,0
  43.     je      .no_dub_dot
  44.     ;if(strstr(target_host_ptr,"www.") == target_host_ptr){
  45.     cmp     eax,dword[target_host_ptr]      
  46.     je      .dub_dot_found
  47.     ;}else{
  48.     jmp     .no_dub_dot
  49.  
  50. .no_scheme_delimter:
  51.     push    msg_no_scheme
  52.     push    printf_format_string
  53.     call    printf
  54.     add     esp,8
  55.     mov     eax,-1
  56.     jmp     .leaveMain
  57. .dub_dot_found:
  58.     add     dword[target_host_ptr],4    ;point past the www.
  59.     add     esp,8
  60.  
  61. .no_dub_dot:
  62.     ;save everything until / or end of string is reached
  63.     ;===================================================
  64.     push    dword[target_host]
  65.     call    strlen
  66.     add     esp,4
  67.     mov     ecx,0
  68.     mov     esi,dword[target_host_ptr]
  69.     mov     dword[host_name],esi
  70.  
  71. .save_loop:
  72.     cmp     byte[esi+ecx],0
  73.     je      .stop_saving
  74.     cmp     byte[esi+ecx],'/'
  75.     je      .save_uri
  76.     cmp     byte[esi+ecx],':'
  77.     je      .save_port
  78. .resume_port:
  79.     inc     ecx
  80.     jmp     .save_loop
  81. .stop_saving:
  82.     mov     dword[host_name_end],esi
  83.     add     dword[host_name_end],ecx
  84.     push    dword[host_name]
  85.     push    printf_format_string
  86.     call    printf
  87.     add     esp,8
  88.     jmp     .leaveMain
  89. .save_uri:
  90.     mov     dword[host_name_end],esi
  91.     add     dword[host_name_end],ecx
  92.     dec     dword[host_name_end]
  93.     mov     dword[target_uri],esi
  94.     add     dword[target_uri],ecx
  95.     push    dword[target_uri]
  96.     push    printf_format_string
  97.     call    printf
  98.     add     esp,8
  99.     jmp     .leaveMain
  100. .save_port:
  101.     mov     dword[port_start],esi
  102.     add     dword[port_start],ecx
  103.     inc     dword[port_start]
  104. .save_port_loop:
  105.     inc     ecx
  106.     cmp     byte[esi+ecx],0
  107.     je      .end_save_port_loop
  108.     cmp     byte[esi+ecx],'/'
  109.     je      .end_save_port_loop
  110.     jmp     .save_port_loop
  111. .end_save_port_loop:
  112.     mov     dword[port_end],esi
  113.     add     dword[port_end],ecx
  114.     cmp     byte[esi+ecx],0
  115.     je      .stop_saving
  116.     dec     ecx
  117.     jmp     .resume_port
  118.  
  119. .usage:
  120.     push    usage
  121.     push    printf_format_string
  122.     call    printf
  123.     jmp     .leaveMain
  124. .leaveMain:
  125.     mov     ebp,[init_ebp]
  126.     mov     esp,[init_esp]
  127.     ret
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. SECTION .data
  136. dub_dot: dd 'www.',0
  137. host_name: dd 0
  138. host_name_end: dd 0
  139. init_ebp: dd 0
  140. init_esp: dd 0
  141. msg_dub_dot_found: dd "www. found",0
  142. msg_no_dub_dot: dd "No www. found",0
  143. msg_no_scheme: dd "No scheme delimiter found",0
  144. port_found: dd 0
  145. port_end: dd 0
  146. port_start: dd 0
  147. printf_format_string: dd '%s',0xa,0xd,0
  148. scheme_delimiter: dd '://',0
  149. target_host: dd 0
  150. target_host_ptr: dd 0
  151. target_host_ptr_end: dd 0
  152. target_port: dw 80
  153. target_uri: dd 0
  154. usage: db 'Usage: ./a.out <URL>',0xa,0xd,
  155.        db 'Example: ./a.out http://www.google.com/index.html',0
  156.  
  157. SECTION .bss
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement