Advertisement
Guest User

SO 7379553 #2

a guest
Sep 13th, 2011
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .text:0000000000400E63 main            proc near               ; DATA XREF: _start+1Do
  2. .text:0000000000400E63
  3. .text:0000000000400E63 argv            = qword ptr -160h
  4. .text:0000000000400E63 argc            = dword ptr -154h
  5. .text:0000000000400E63 name            = byte ptr -150h
  6. .text:0000000000400E63 addr            = sockaddr_in ptr -50h
  7. .text:0000000000400E63 fd              = dword ptr -3Ch
  8. .text:0000000000400E63 _addr0          = qword ptr -38h
  9. .text:0000000000400E63 _hostent        = qword ptr -30h
  10. .text:0000000000400E63 newbuf          = qword ptr -28h
  11. .text:0000000000400E63 tmp             = qword ptr -20h
  12. .text:0000000000400E63 ip_str          = qword ptr -18h
  13. .text:0000000000400E63
  14. .text:0000000000400E63                 push    rbp
  15. .text:0000000000400E64                 mov     rbp, rsp
  16. .text:0000000000400E67                 push    rbx
  17. .text:0000000000400E68                 sub     rsp, 158h
  18. .text:0000000000400E6F                 mov     [rbp+argc], edi
  19. .text:0000000000400E75                 mov     [rbp+argv], rsi
  20. .text:0000000000400E7C                 cmp     [rbp+argc], 2
  21. .text:0000000000400E83                 jz      short loc_400EB3 ; if ( argc != 2 )
  22. .text:0000000000400E83                                         ; {
  23. .text:0000000000400E83                                         ;   fprintf(stderr, "Usage");
  24. .text:0000000000400E83                                         ;   exit(1);
  25. .text:0000000000400E83                                         ; }
  26. .text:0000000000400E85                 mov     rax, cs:stderr@@GLIBC_2_2_5
  27. .text:0000000000400E8C                 mov     rdx, rax
  28. .text:0000000000400E8F                 mov     eax, offset aUsage ; "Usage"
  29. .text:0000000000400E94                 mov     rcx, rdx        ; s
  30. .text:0000000000400E97                 mov     edx, 5          ; n
  31. .text:0000000000400E9C                 mov     esi, 1          ; size
  32. .text:0000000000400EA1                 mov     rdi, rax        ; ptr
  33. .text:0000000000400EA4                 call    _fwrite
  34. .text:0000000000400EA9                 mov     edi, 1          ; status
  35. .text:0000000000400EAE                 call    _exit
  36. .text:0000000000400EB3 ; ---------------------------------------------------------------------------
  37. .text:0000000000400EB3
  38. .text:0000000000400EB3 loc_400EB3:                             ; CODE XREF: main+20j
  39. .text:0000000000400EB3                 lea     rax, [rbp+name] ; char name[0x100];
  40. .text:0000000000400EBA                 mov     esi, 100h       ; len
  41. .text:0000000000400EBF                 mov     rdi, rax        ; name
  42. .text:0000000000400EC2                 call    _gethostname    ; gethostname(name, 0x100);
  43. .text:0000000000400EC7                 lea     rax, [rbp+name]
  44. .text:0000000000400ECE                 mov     rdi, rax        ; name
  45. .text:0000000000400ED1                 call    _gethostbyname  ; struct hostent* _hostent = gethostbyname(name);
  46. .text:0000000000400ED6                 mov     [rbp+_hostent], rax
  47. .text:0000000000400EDA                 mov     rax, [rbp+_hostent]
  48. .text:0000000000400EDE                 mov     rax, [rax+hostent.h_addr_list]
  49. .text:0000000000400EE2                 mov     rax, [rax]
  50. .text:0000000000400EE5                 mov     [rbp+_addr0], rax ; struct in_addr *_addr0 = (struct in_addr *)(_hostent->h_addr_list[0]);
  51. .text:0000000000400EE9                 mov     [rbp+addr.sin_family], AF_INET ; struct sockaddr_in addr;
  52. .text:0000000000400EE9                                         ; addr.sa_family = AF_INET;
  53. .text:0000000000400EEF                 mov     edi, 0          ; hostshort
  54. .text:0000000000400EF4                 call    _htons
  55. .text:0000000000400EF9                 mov     [rbp+addr.sin_port], ax ; addr.sin_port = htons(0);
  56. .text:0000000000400EFD                 mov     rax, [rbp+_addr0]
  57. .text:0000000000400F01                 mov     eax, [rax+in_addr.s_addr]
  58. .text:0000000000400F03                 mov     [rbp+addr.sin_addr.s_addr], eax ; addr.sin_addr.s_addr = _addr0->s_addr;
  59. .text:0000000000400F06                 mov     edi, 6          ; size
  60. .text:0000000000400F0B                 call    _malloc         ; char *tmp = malloc(6);
  61. .text:0000000000400F10                 mov     [rbp+tmp], rax
  62. .text:0000000000400F14                 movzx   eax, [rbp+addr.sin_port]
  63. .text:0000000000400F18                 movzx   edx, ax
  64. .text:0000000000400F1B                 mov     ecx, offset format ; "%d"
  65. .text:0000000000400F20                 mov     rax, [rbp+tmp]
  66. .text:0000000000400F24                 mov     rsi, rcx        ; format
  67. .text:0000000000400F27                 mov     rdi, rax        ; s
  68. .text:0000000000400F2A                 mov     eax, 0
  69. .text:0000000000400F2F                 call    _sprintf        ; sprintf(tmp, "%d", addr.sin_port);
  70. .text:0000000000400F34                 mov     rax, [rbp+_addr0]
  71. .text:0000000000400F38                 mov     edi, [rax+in_addr.s_addr] ; in
  72. .text:0000000000400F3A                 call    _inet_ntoa      ; char *ip_str = inet_ntoa(in_addr.s_addr);
  73. .text:0000000000400F3F                 mov     [rbp+ip_str], rax
  74. .text:0000000000400F43                 mov     rax, [rbp+argv] ; argv is a char **
  75. .text:0000000000400F4A                 add     rax, 8          ; 8 is the pointer size, so we're advancing one pointer forward
  76. .text:0000000000400F4E                 mov     rax, [rax]      ; dereference the pointer
  77. .text:0000000000400F51                 mov     rdi, rax        ; rdi = argv[1];
  78. .text:0000000000400F54                 call    _strlen         ; rbx = strlen(argv[1]);
  79. .text:0000000000400F59                 mov     rbx, rax
  80. .text:0000000000400F5C                 mov     rax, [rbp+ip_str]
  81. .text:0000000000400F60                 mov     rdi, rax        ; s
  82. .text:0000000000400F63                 call    _strlen         ; rbx += strlen(ip_str);
  83. .text:0000000000400F68                 add     rbx, rax
  84. .text:0000000000400F6B                 mov     rax, [rbp+tmp]
  85. .text:0000000000400F6F                 mov     rdi, rax        ; s
  86. .text:0000000000400F72                 call    _strlen         ; rax = rbx + strlen(tmp);
  87. .text:0000000000400F77                 lea     rax, [rbx+rax]
  88. .text:0000000000400F7B                 add     rax, 5
  89. .text:0000000000400F7F                 mov     rdi, rax        ; size
  90. .text:0000000000400F82                 call    _malloc         ; malloc(rax+5);
  91. .text:0000000000400F82                                         ; i.e.
  92. .text:0000000000400F82                                         ; char *newbuf = malloc(strlen(argv[1])+strlen(ip_str)+strlen(tmp)+5);
  93. .text:0000000000400F87                 mov     [rbp+newbuf], rax
  94. .text:0000000000400F8B                 mov     ecx, offset aR  ; "r"
  95. .text:0000000000400F90                 mov     rax, [rbp+newbuf]
  96. .text:0000000000400F94                 mov     edx, 2          ; n
  97. .text:0000000000400F99                 mov     rsi, rcx        ; src
  98. .text:0000000000400F9C                 mov     rdi, rax        ; dest
  99. .text:0000000000400F9F                 call    _memcpy         ; strcpy(newbuf, "r");
  100. .text:0000000000400FA4                 mov     edx, offset _space ; " "
  101. .text:0000000000400FA9                 mov     rax, [rbp+newbuf]
  102. .text:0000000000400FAD                 mov     rsi, rdx        ; src
  103. .text:0000000000400FB0                 mov     rdi, rax        ; dest
  104. .text:0000000000400FB3                 call    _strcat         ; strcat(newbuf, " ");
  105. .text:0000000000400FB8                 mov     rax, [rbp+argv]
  106. .text:0000000000400FBF                 add     rax, 8
  107. .text:0000000000400FC3                 mov     rax, [rax]
  108. .text:0000000000400FC6                 mov     rdi, rax        ; s
  109. .text:0000000000400FC9                 call    _strlen         ; rdx = strlen(argv[1]);
  110. .text:0000000000400FCE                 mov     rdx, rax        ; n
  111. .text:0000000000400FD1                 mov     rax, [rbp+argv]
  112. .text:0000000000400FD8                 add     rax, 8
  113. .text:0000000000400FDC                 mov     rax, [rax]
  114. .text:0000000000400FDF                 mov     rcx, rax
  115. .text:0000000000400FE2                 mov     rax, [rbp+newbuf]
  116. .text:0000000000400FE6                 mov     rsi, rcx        ; src
  117. .text:0000000000400FE9                 mov     rdi, rax        ; dest
  118. .text:0000000000400FEC                 call    _strncat        ; strncat(newbuf, argv[1], strlen(argv[1]));
  119. .text:0000000000400FEC                                         ; i.e. simply strcat(newbuf, argv[1]);
  120. .text:0000000000400FF1                 mov     edx, offset _space ; " "
  121. .text:0000000000400FF6                 mov     rax, [rbp+newbuf]
  122. .text:0000000000400FFA                 mov     rsi, rdx        ; src
  123. .text:0000000000400FFD                 mov     rdi, rax        ; dest
  124. .text:0000000000401000                 call    _strcat         ; strcat(newbuf, " ");
  125. .text:0000000000401005                 mov     rax, [rbp+ip_str]
  126. .text:0000000000401009                 mov     rdi, rax        ; s
  127. .text:000000000040100C                 call    _strlen
  128. .text:0000000000401011                 mov     rdx, rax        ; n
  129. .text:0000000000401014                 mov     rcx, [rbp+ip_str]
  130. .text:0000000000401018                 mov     rax, [rbp+newbuf]
  131. .text:000000000040101C                 mov     rsi, rcx        ; src
  132. .text:000000000040101F                 mov     rdi, rax        ; dest
  133. .text:0000000000401022                 call    _strncat        ; strcat(newbuf, ip_str);
  134. .text:0000000000401027                 mov     edx, offset _space ; " "
  135. .text:000000000040102C                 mov     rax, [rbp+newbuf]
  136. .text:0000000000401030                 mov     rsi, rdx        ; src
  137. .text:0000000000401033                 mov     rdi, rax        ; dest
  138. .text:0000000000401036                 call    _strcat         ; strcat(newbuf, " ");
  139. .text:000000000040103B                 mov     rax, [rbp+tmp]
  140. .text:000000000040103F                 mov     rdi, rax        ; s
  141. .text:0000000000401042                 call    _strlen
  142. .text:0000000000401047                 mov     rdx, rax        ; n
  143. .text:000000000040104A                 mov     rcx, [rbp+tmp]
  144. .text:000000000040104E                 mov     rax, [rbp+newbuf]
  145. .text:0000000000401052                 mov     rsi, rcx        ; src
  146. .text:0000000000401055                 mov     rdi, rax        ; dest
  147. .text:0000000000401058                 call    _strncat        ; strcat(newbuf, tmp);
  148. .text:000000000040105D                 mov     rax, [rbp+newbuf]
  149. .text:0000000000401061                 mov     rdi, rax
  150. .text:0000000000401064                 call    register_broker ; register_broker(newbuf);
  151. .text:0000000000401069                 mov     edx, 0          ; protocol
  152. .text:000000000040106E                 mov     esi, SOCK_STREAM ; type
  153. .text:0000000000401073                 mov     edi, PF_INET    ; domain
  154. .text:0000000000401078                 call    _socket         ; int fd = socket(PF_INET, SOCK_STREAM, 0);
  155. .text:000000000040107D                 mov     [rbp+fd], eax
  156. .text:0000000000401080                 cmp     [rbp+fd], 0
  157. .text:0000000000401084                 jns     short loc_40109A ; if ( fd < 0 )
  158. .text:0000000000401084                                         ; {
  159. .text:0000000000401084                                         ;   perror("Error creating socket");
  160. .text:0000000000401084                                         ;   exit(1);
  161. .text:0000000000401084                                         ; }
  162. .text:0000000000401086                 mov     edi, offset aErrorCreatingS ; "Error creating socket"
  163. .text:000000000040108B                 call    _perror
  164. .text:0000000000401090                 mov     edi, 1          ; status
  165. .text:0000000000401095                 call    _exit
  166. .text:000000000040109A ; ---------------------------------------------------------------------------
  167. .text:000000000040109A
  168. .text:000000000040109A loc_40109A:                             ; CODE XREF: main+221j
  169. .text:000000000040109A                 lea     rcx, [rbp+addr]
  170. .text:000000000040109E                 mov     eax, [rbp+fd]
  171. .text:00000000004010A1                 mov     edx, size sockaddr_in ; len
  172. .text:00000000004010A6                 mov     rsi, rcx        ; addr
  173. .text:00000000004010A9                 mov     edi, eax        ; fd
  174. .text:00000000004010AB                 call    _bind           ; _eax = bind(fd, addr, sizeof(addr));
  175. .text:00000000004010B0                 test    eax, eax
  176. .text:00000000004010B2                 jz      short loc_4010C8 ; if ( _eax != 0 )
  177. .text:00000000004010B2                                         ; {
  178. .text:00000000004010B2                                         ;   perror("Error binding socket");
  179. .text:00000000004010B2                                         ;   exit(1);
  180. .text:00000000004010B2                                         ; }
  181. .text:00000000004010B4                 mov     edi, offset aErrorBindingSo ; "Error binding socket"
  182. .text:00000000004010B9                 call    _perror
  183. .text:00000000004010BE                 mov     edi, 1          ; status
  184. .text:00000000004010C3                 call    _exit
  185. .text:00000000004010C8 ; ---------------------------------------------------------------------------
  186. .text:00000000004010C8
  187. .text:00000000004010C8 loc_4010C8:                             ; CODE XREF: main+24Fj
  188. .text:00000000004010C8                 mov     eax, [rbp+fd]
  189. .text:00000000004010CB                 mov     esi, 80h        ; n
  190. .text:00000000004010D0                 mov     edi, eax        ; fd
  191. .text:00000000004010D2                 call    _listen         ; _eax = listen(fd, 0x80);
  192. .text:00000000004010D7                 test    eax, eax
  193. .text:00000000004010D9                 jns     short loc_4010EF ; if ( _eax != 0 )
  194. .text:00000000004010D9                                         ; {
  195. .text:00000000004010D9                                         ;   perror("Error listening on socket");
  196. .text:00000000004010D9                                         ;   exit(1);
  197. .text:00000000004010D9                                         ; }
  198. .text:00000000004010DB                 mov     edi, offset aErrorListening ; "Error listening on socket"
  199. .text:00000000004010E0                 call    _perror
  200. .text:00000000004010E5                 mov     edi, 1          ; status
  201. .text:00000000004010EA                 call    _exit
  202. .text:00000000004010EF ; ---------------------------------------------------------------------------
  203. .text:00000000004010EF
  204. .text:00000000004010EF loc_4010EF:                             ; CODE XREF: main+276j
  205. .text:00000000004010EF                 mov     eax, [rbp+fd]
  206. .text:00000000004010F2                 mov     edi, eax
  207. .text:00000000004010F4                 call    handle_requests ; handle_requests(fd);
  208. .text:00000000004010F9                 add     rsp, 158h
  209. .text:0000000000401100                 pop     rbx
  210. .text:0000000000401101                 leave
  211. .text:0000000000401102                 retn
  212. .text:0000000000401102 main            endp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement