Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. typedef struct{
  5. unsigned char pream;
  6. unsigned char packetType;
  7. unsigned char dataLen;
  8. unsigned char data;
  9. unsigned char hash;
  10. }packet;
  11.  
  12. int main(int argc, char* argv[])
  13. {
  14. if (argc < 2)
  15. return 1;
  16.  
  17. packet pac;
  18. FILE *pFile = fopen(argv[1], "rb");
  19.  
  20. if (!pFile){
  21. printf("Can`t open file\n");
  22. return 1;
  23. }
  24.  
  25.  
  26. unsigned short buf;
  27. fread(&buf, sizeof(unsigned char), sizeof(buf), pFile);
  28. // pream ppppXXXX XXXXXXXX
  29. // type XXXXtttX XXXXXXXX
  30. // len XXXXXXXl llXXXXXX
  31. // 01011101 01NNNNNN NNNNNNNN NNNNNNNN NNNNNNNN NNNNNNNN NNCCCCXX
  32. // 01NNNNNN 01011101
  33. buf = ntohs(buf);
  34. // 01011101 01NNNNNN
  35.  
  36. unsigned long long data = buf & 0x3F; // 0011 1111
  37. buf = buf >> 6;
  38. // 000000 0101110101
  39. unsigned char pream = (buf >> 6) & 0xF;
  40. unsigned char type = (buf >> 3) & 0x7;
  41. unsigned char len = buf & 0x7;
  42. unsigned char databuf[8];
  43.  
  44. fread(databuf, sizeof(unsigned char), len, pFile);
  45. for (unsigned i = 0; i < len - 1; ++i)
  46. data = (data << 8) | databuf[i];
  47. data = (data << 2) | ((databuf[i] >> 6) & 0x3);
  48.  
  49.  
  50.  
  51.  
  52. while (!feof(pFile)){
  53. fread(&pac, sizeof(unsigned char), sizeof(pac), pFile);
  54. }
  55.  
  56. fclose(pFile);
  57. printf("End operations...\n");
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement