Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include "../libaos/libaos.h"
- main(int argc, char**argv)
- {
- int fd,fdo;
- unsigned char *buffer;
- struct flash_header header;
- int sz_unk;
- fd = open(argv[1], O_RDONLY);
- read(fd, &header, sizeof(header));
- // 0xDAE589F0
- printf("sizeof(header)=%ld\n", sizeof(header));
- printf("magic : 0x%08X\n", header.magic);
- printf("bits : 0x%08X\n", header.bits);
- printf("filesize : %d\n", header.filesize);
- printf("entrypt : 0x%08X\n", header.entrypoint);
- printf("cpio : %08X\n", header.cpio);
- printf("cpiosz : %d\n", header.cpio_size);
- fdo = open("unpacked-header", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
- write(fdo, &header, sizeof(header));
- close(fdo);
- fdo = open("unpacked-kernel", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
- buffer = malloc(header.cpio);
- read(fd, buffer, header.cpio - sizeof(header));
- write(fdo, buffer, header.cpio - sizeof(header));
- close(fdo);
- fdo = open("unpacked-cpio.gz", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
- buffer = malloc(header.cpio_size);
- read(fd, buffer, header.cpio_size);
- write(fdo, buffer, header.cpio_size);
- close(fdo);
- buffer = malloc(7000000);
- lseek(fd, 0x31d400, SEEK_SET);
- fdo = open("unpack-unknown", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
- sz_unk = read(fd, buffer, 7000000);
- printf("unknown : %d\n", sz_unk);
- write(fdo, buffer, sz_unk);
- close(fdo);
- close(fd);
- }
Advertisement
Add Comment
Please, Sign In to add comment