Guest User

Untitled

a guest
Nov 23rd, 2012
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7.  
  8. #include "../libaos/libaos.h"
  9.  
  10.  
  11. main(int argc, char**argv)
  12. {
  13. int fd,fdo;
  14. unsigned char *buffer;
  15. struct flash_header header;
  16. int sz_unk;
  17. fd = open(argv[1], O_RDONLY);
  18. read(fd, &header, sizeof(header));
  19. // 0xDAE589F0
  20. printf("sizeof(header)=%ld\n", sizeof(header));
  21. printf("magic : 0x%08X\n", header.magic);
  22. printf("bits : 0x%08X\n", header.bits);
  23. printf("filesize : %d\n", header.filesize);
  24. printf("entrypt : 0x%08X\n", header.entrypoint);
  25. printf("cpio : %08X\n", header.cpio);
  26. printf("cpiosz : %d\n", header.cpio_size);
  27.  
  28. fdo = open("unpacked-header", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
  29. write(fdo, &header, sizeof(header));
  30. close(fdo);
  31. fdo = open("unpacked-kernel", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
  32. buffer = malloc(header.cpio);
  33. read(fd, buffer, header.cpio - sizeof(header));
  34. write(fdo, buffer, header.cpio - sizeof(header));
  35. close(fdo);
  36. fdo = open("unpacked-cpio.gz", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
  37. buffer = malloc(header.cpio_size);
  38. read(fd, buffer, header.cpio_size);
  39. write(fdo, buffer, header.cpio_size);
  40. close(fdo);
  41.  
  42. buffer = malloc(7000000);
  43. lseek(fd, 0x31d400, SEEK_SET);
  44. fdo = open("unpack-unknown", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
  45. sz_unk = read(fd, buffer, 7000000);
  46. printf("unknown : %d\n", sz_unk);
  47. write(fdo, buffer, sz_unk);
  48. close(fdo);
  49.  
  50. close(fd);
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment