1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
# include <stdio.h>
# include <unistd.h>
# include <fcntl.h>
# include "hfs.h"
# include "rsrc.h"
static
void die(const char *msg)
{
perror(msg);
exit(2);
}
struct rsrcprocs fileprocs = {
(rsrcseekfunc) hfs_seek,
(rsrcreadfunc) hfs_read,
(rsrcwritefunc) hfs_write
};
int main(int argc, char *argv[])
{
hfsvol *vol;
hfsfile *file;
rsrcfile *rfile;
int i;
if (argc < 3)
{
fprintf(stderr, "Args: vol file\n");
exit(1);
}
vol = hfs_mount(argv[1], 1, HFS_MODE_ANY);
if (vol == 0)
die(hfs_error);
file = hfs_open(vol, argv[2]);
if (file == 0 || hfs_setfork(file, 1) == -1)
die(hfs_error);
rfile = rsrc_open(file, &fileprocs);
if (rfile == 0)
die(rsrc_error);
/* ... */
for (i = rsrc_counttypes(rfile); i > 0; --i)
{
char type[5];
int count;
rsrc_gettype(rfile, i, type);
count = rsrc_count(rfile, type);
while (count > 0)
{
unsigned char *data;
unsigned long len;
FILE *hex;
data = rsrc_getind(rfile, type, count);
if (data)
{
len = rsrc_size(data);
printf("'%s' %d: %lu byte%s\n", type, count, len,
len == 1 ? "" : "s");
fflush(stdout);
hex = popen("hex", "w");
if (hex == 0)
die("error forking `hex'");
fwrite(data, len, 1, hex);
fclose(hex);
rsrc_release(data);
}
else
{
printf("%5d: %s\n", count, rsrc_error);
fflush(stdout);
}
--count;
}
}
/* ... */
if (rsrc_close(rfile) == -1)
die(rsrc_error);
if (hfs_close(file) == -1 ||
hfs_umount(vol) == -1)
die(hfs_error);
return 0;
}
|