-
Notifications
You must be signed in to change notification settings - Fork 0
/
kiss_unpack.c
107 lines (83 loc) · 1.68 KB
/
kiss_unpack.c
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
101
102
103
104
105
106
107
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include "readbytes.h"
#include "cp932.h"
#ifdef _WIN32
#include "win32compat.h"
#endif
int main(int argc, char *argv[])
{
int i;
char c;
char *name;
char filename[512];
FILE *archive, *out;
unsigned char sbuf[8];
unsigned int count, file_size, file_offset, file_offset_next, pos, end_of_file;
if(argc != 2)
{
printf("%s: <archive.arc>\n", argv[0]);
return 1;
}
archive = fopen(argv[1], "rb");
if(fread(sbuf, 1, 4, archive) != 4)
{
puts("not a KISS archive");
return 1;
}
count = read_uint32_le(sbuf);
fseek(archive, 0, SEEK_END);
end_of_file = ftell(archive);
fseek(archive, 4, SEEK_SET);
if(count == 0)
{
puts("not a KISS archive");
exit(1);
}
printf("index count: %d\n", count);
while(count)
{
i = 0;
while((c = fgetc(archive)) != 0)
{
filename[i] = c;
i++;
}
filename[i] = '\0';
fread(sbuf, 1, 8, archive);
file_offset = read_uint64_le(sbuf);
printf("%d\n", file_offset);
pos = ftell(archive);
if(count - 1)
{
while((c = fgetc(archive)) != 0);
fread(sbuf, 1, 8, archive);
file_offset_next = read_uint64_le(sbuf);
file_size = file_offset_next - file_offset;
fseek(archive, pos, SEEK_SET);
}
else
{
file_size = end_of_file - file_offset;
}
cp932_to_utf8(filename, &name);
printf("filename %s\n", name);
printf("file size %d\n", file_size);
pos = ftell(archive);
fseek(archive, file_offset, SEEK_SET);
out = fopen(name, "wb");
while(file_size)
{
putc(fgetc(archive), out);
file_size--;
}
fclose(out);
fseek(archive, pos, SEEK_SET);
count--;
}
return 0;
}