Advertisement
Guest User

Untitled

a guest
May 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <libusb.h>
  5. #include <linux/ip.h>
  6. #include <unistd.h>
  7. #include <sys/stat.h>
  8.  
  9. #include "rndis.h"
  10. #include "ether2.h"
  11. #include "ipv4.h"
  12. #include "udp.h"
  13. #include "bootp.h"
  14. #include "tftp.h"
  15. #include "arp.h"
  16.  
  17. #include "utils.h"
  18.  
  19. int main(int UNUSED argc, const char UNUSED * argv[]) {
  20. int actual;
  21. int result;
  22. int r;
  23.  
  24. ssize_t fullSize = sizeof(bootp_packet) + sizeof(udp_t) +
  25. sizeof(struct iphdr) + sizeof(struct ethhdr) +
  26. sizeof(rndis_hdr);
  27. ssize_t rndisSize = sizeof(rndis_hdr);
  28. ssize_t etherSize = sizeof(struct ethhdr);
  29. ssize_t arpSize = sizeof(arp_hdr);
  30. ssize_t ipSize = sizeof(struct iphdr);
  31. ssize_t udpSize = sizeof(udp_t);
  32. ssize_t bootpSize = sizeof(bootp_packet);
  33. ssize_t tftpSize = sizeof(tftp_data);
  34.  
  35. unsigned char *data = (unsigned char*)calloc(1, 1000);
  36. unsigned char *buffer = (unsigned char*)malloc(450 *
  37. sizeof(unsigned char));
  38.  
  39. FILE *send;
  40.  
  41. libusb_device **devs = NULL;
  42. libusb_device_handle *dev_handle = NULL;
  43. libusb_context *ctx = NULL;
  44.  
  45. r = libusb_init(&ctx);
  46. if (r < 0) {
  47. printf("Init error!\n");
  48. exit(1);
  49. }
  50. libusb_set_debug(ctx, 3);
  51.  
  52. while (dev_handle == NULL) {
  53. r = libusb_get_device_list(ctx, &devs);
  54. if (r < 0) {
  55. printf("Cannot get device list.\n");
  56. }
  57. dev_handle = libusb_open_device_with_vid_pid(ctx,
  58. ROMVID, ROMPID);
  59. libusb_free_device_list(devs, 1);
  60. }
  61.  
  62.  
  63. if (libusb_kernel_driver_active(dev_handle, 0) == 1) {
  64. libusb_detach_kernel_driver(dev_handle, 0);
  65. }
  66.  
  67. r = libusb_claim_interface(dev_handle, 1);
  68. if (r < 0) {
  69. printf("Cannot Claim Interface!\n");
  70. exit(1);
  71. }
  72.  
  73. r = libusb_bulk_transfer(dev_handle, (129 | LIBUSB_ENDPOINT_IN),
  74. buffer, 450, &actual, 0);
  75.  
  76. rndis_hdr *rndis = (rndis_hdr*)calloc(1, rndisSize);
  77. make_rndis(rndis, fullSize - rndisSize);
  78.  
  79. struct ethhdr *ether = (struct ethhdr*)(buffer+rndisSize);
  80. struct ethhdr *eth2 = (struct ethhdr*)calloc(1, etherSize);
  81. make_ether2(eth2, ether->h_source, (unsigned char*)my_hwaddr);
  82.  
  83.  
  84. //test
  85. printf("h_source ");
  86. for(int i=0; i<6; i++){
  87. printf("%d-", ether->h_source[i]);
  88. }
  89. printf("\n h_dest ");
  90. for(int i=0; i<6; i++){
  91. printf("%d-", ether->h_dest[i]);
  92. }
  93. printf("\n h_proto ");
  94. printf("%d \n", ether->h_proto);
  95.  
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement