25 #include <sys/types.h>
34 #include "mspack/mspack.h"
35 #include "mspack/macros.h"
36 #include "mspack/cab.h"
41 # define FILELEN off_t
59 printf(
"Cabinet information dumper by Stuart Caie <kyzer@cabextract.org.uk>\n");
66 for (
i = 1;
i < argc;
i++) {
78 #define MIN(a,b) ((a)<(b)?(a):(b))
79 #define GETOFFSET (FTELL(fh))
80 #define READ(buf,len) if (myread((void *)(buf),(len))) return
81 #define SKIP(offset) if (FSEEK(fh,(offset),SEEK_CUR)) return
82 #define SEEK(offset) if (FSEEK(fh,(offset),SEEK_SET)) return
88 #define SEARCH_SIZE (32*1024)
94 unsigned long cablen32 = 0, foffset32 = 0;
129 while (*
p++ != 0x4D &&
p < pend);
134 case 1:
state = (*
p++ == 0x53) ? 2 : 0;
break;
135 case 2:
state = (*
p++ == 0x43) ? 3 : 0;
break;
136 case 3:
state = (*
p++ == 0x46) ? 4 : 0;
break;
140 case 8: cablen32 = *
p++;
state++;
break;
141 case 9: cablen32 |= *
p++ << 8;
state++;
break;
142 case 10: cablen32 |= *
p++ << 16;
state++;
break;
143 case 11: cablen32 |= *
p++ << 24;
state++;
break;
147 case 16: foffset32 = *
p++;
state++;
break;
148 case 17: foffset32 |= *
p++ << 8;
state++;
break;
149 case 18: foffset32 |= *
p++ << 16;
state++;
break;
150 case 19: foffset32 |= *
p++ << 24;
153 caboff =
offset + (
p-pstart) - 20;
156 if (foffset32 < cablen32) {
173 #define GETLONG(n) EndGetI32(&buf[n])
174 #define GETWORD(n) EndGetI16(&buf[n])
175 #define GETBYTE(n) ((int)buf[n])
178 unsigned char buf[64];
179 int header_res = 0, folder_res = 0, data_res = 0;
180 int num_folders, num_files,
flags,
i, j;
191 printf(
"CABINET HEADER @%"LD":\n", base_offset);
194 printf(
"- files offset = %"LD"\n", files_offset);
195 printf(
"- format version = %d.%d\n",
197 printf(
"- folder count = %u\n", num_folders);
198 printf(
"- file count = %u\n", num_files);
211 printf(
"- header reserve = %u bytes (@%"LD")\n",
213 printf(
"- folder reserve = %u bytes\n", folder_res);
214 printf(
"- data reserve = %u bytes\n", data_res);
227 for (
i = 0;
i < num_folders;
i++) {
228 FILELEN folder_offset, data_offset;
229 int comp_type, num_blocks, offset_ok;
238 min_data_offset =
MIN(data_offset, min_data_offset);
239 offset_ok = data_offset <
filelen;
246 default: type_name =
"unknown";
break;
249 printf(
"- folder 0x%04x @%"LD" %u data blocks @%"LD"%s %s compression (0x%04x)\n",
250 i, folder_offset, num_blocks, data_offset,
251 offset_ok ?
"" :
" [INVALID OFFSET]",
252 type_name, comp_type);
255 for (j = 0; j < num_blocks; j++) {
264 printf(
" - datablock %d @%"LD" csum=%08x c=%5u u=%5u%s\n",
266 ((clen > (32768+6144)) || (ulen > 32768)) ?
" INVALID" :
"");
268 SKIP(data_res + clen);
275 printf(
"INVALID: file offset in header %"LD
276 " doesn't match start of files %"LD"\n",
280 for (
i = 0;
i < num_files;
i++) {
285 if (file_offset >
filelen)
return;
293 folder_type =
"continued from prev and to next cabinet";
break;
295 folder_type =
"continued from prev cabinet";
break;
297 folder_type =
"continued to next cabinet";
break;
299 folder_type = folder >= num_folders
300 ?
"INVALID FOLDER INDEX"
305 printf(
"- file %-5d @%-12"LD"%s\n",
i, file_offset,
306 (file_offset > min_data_offset ?
" [INVALID FILE OFFSET]" :
""));
309 printf(
" - folder = 0x%04x [%s]\n", folder, folder_type);
312 printf(
" - date = %02d/%02d/%4d %02d:%02d:%02d\n",
319 printf(
" - attrs = 0x%02x %s%s%s%s%s%s\n",
330 #define CAB_NAMEMAX (1024)
336 for (
i = 0;
i <= 256;
i++) {
342 printf(
"INVALID: name length > 256 for at offset %"LD"\n", name_start);
int main(int argc, char *argv[])
char namebuf[CAB_NAMEMAX]
void getinfo(FILELEN base_offset)
unsigned char search_buf[SEARCH_SIZE]
int myread(void *buf, size_t length)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
static static fork const void static count static fd const char const char static newpath char char argv
static struct sockaddr static addrlen static backlog const void static flags void flags