Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
123
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 <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. if (argc != 2)
  7. {
  8. printf("Usage: ./recover [Your file].\n");
  9. return 1;
  10. }
  11.  
  12. FILE *file = fopen(argv[1], "r");
  13.  
  14. if (file == NULL)
  15. {
  16. printf("Your file cannot be opened for reading.\n");
  17. return 1;
  18. }
  19.  
  20. unsigned char bytes[512];
  21. char filename[8];
  22.  
  23. int end = 1;
  24.  
  25. int found = 0;
  26. int counter = 0;
  27.  
  28.  
  29. FILE *img;
  30.  
  31. do
  32. {
  33. end = fread(bytes, 512, 1, file);
  34.  
  35. if (bytes[0] == 0xff && bytes[1] == 0xd8 && bytes[2] == 0xff && (bytes[3] & 0xf0) == 0xe0)
  36. {
  37. found = 1;
  38.  
  39. if (counter == 0)
  40. {
  41. sprintf(filename, "%03i.jpg", counter);
  42. img = fopen(filename, "w");
  43. fwrite(bytes, 512, 1, img);
  44. }
  45. else
  46. {
  47. fclose(img);
  48. counter++;
  49. sprintf(filename, "%03i.jpg", counter);
  50. img = fopen(filename, "w");
  51. }
  52. }
  53. else
  54. {
  55. if (found == 1)
  56. {
  57. fwrite(bytes, 512, 1, img);
  58. }
  59. }
  60.  
  61.  
  62. } while (end != 0);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement