Advertisement
Guest User

Untitled

a guest
May 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /**
  2. * smb/server-message-block comunication methods/rpc eval methods for GOPHER
  3. */
  4. #
  5. include "include/tlv.h"
  6.  
  7. /*
  8. * smb_extract_tlv() - Parses arbitrary data passed to it. Determines which method
  9. * to eval, and calls it appropriately. Utilizes a rpc-like
  10. * procedure to determine the function call.
  11. */
  12. int smb_extract_tlv(void * phandle) {
  13.  
  14. if (!phandle) {
  15. return -1;
  16. }
  17.  
  18. uint32_t dwlength = 0, total = 0;
  19. struct tlv_header hdr = * (struct tlv_header * ) malloc(sizeof h);
  20. struct tlv_packet * p = tlv_packet_new(TLV_PACKET_TYPE_REQUEST, 0);
  21.  
  22. while (dwlength != 8) {
  23. if (!ReadFile(phandle, (char * ) & h, (DWORD) 8, (PDWORD) & dwlength, NULL)) {
  24. goto err;
  25. };
  26. };
  27.  
  28. *(struct tlv_header * ) p = h;
  29. dwlength = 0;
  30.  
  31. while (total < p - > h.len - TLV_MIN_LENGTH) {
  32. if (!ReadFile(phandle, (char * )(p + sizeof(struct tlv_header) + total),
  33. (DWORD)(p - > h.len - TLV_MIN_LENGTH - total),
  34. (PDWORD) & dwlength, NULL)) {
  35.  
  36. goto err;
  37. }
  38. total += dwlength;
  39. }
  40.  
  41. err:
  42. if ((struct tlv_header * ) & hdr != NULL) {
  43. free(hdr);
  44. };
  45.  
  46. if (p != NULL) {
  47. tlv_packet_free(p);
  48. };
  49. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement