Category : BBS Programs+Doors
Archive   : UNZIP.ZIP
Filename : UNZIP.C

 
Output of file : UNZIP.C contained in archive : UNZIP.ZIP
#include
#include
#include
#include
#include
#include


#define ZIP_LOCAL_SIG 0x04034b50
#define ZIP_CENT_START_SIG 0x02014b50
#define ZIP_CENT_END_SIG 0x06054b50

typedef struct {
unsigned long signature; /* 0x04034b50 */
unsigned short extract_ver;
unsigned short flags;
unsigned short comp_meth;
unsigned short mod_time;
unsigned short mod_date;
unsigned long crc_32;
unsigned long comp_size;
unsigned long uncomp_size;
unsigned short filename_len;
unsigned short extra_length;
} zip_local_header;

typedef struct {
unsigned long signature; /* 0x02014b50 */
unsigned short made_ver;
unsigned short extract_ver;
unsigned short flags;
unsigned short comp_meth;
unsigned short mod_time;
unsigned short mod_date;
unsigned long crc_32;
unsigned long comp_size;
unsigned long uncomp_size;
unsigned short filename_len;
unsigned short extra_len;
unsigned short comment_len;
unsigned short disk_start;
unsigned short int_attr;
unsigned long ext_attr;
unsigned long rel_ofs_header;
} zip_central_dir;


typedef struct {
unsigned long signature; /* 0x06054b50 */
unsigned short disk_num;
unsigned short cent_dir_disk_num;
unsigned short total_entries_this_disk;
unsigned short total_entries_total;
unsigned long central_dir_size;
unsigned long ofs_cent_dir;
unsigned short comment_len;
} zip_end_dir;


char *bad_words[] = {
"PKZIP",
"PKUNZIP",
"COMMAND",
"DSZ",
"UNZIP",
"\\",
"/",
":",
">",
"<",
"|",
"..",
NULL,
};

long bad_filename(char *fn)
{
int i;

strupr(fn);
for (i=0; bad_words[i]; i++) {
if (strstr(fn,bad_words[i])) {
printf("Questionable file '%s' in that .ZIP file.\n",fn);
return(1);
}
}
return(0);
}

long check_for_files(char *fn)
{
int f;
long l,sig,len;
zip_local_header zl;
zip_central_dir zc;
zip_end_dir ze;
char s[161];

#define READ_FN(ln) {read(f,s,ln); s[ln]=0;}

f=open(fn,O_RDWR | O_BINARY);
if (f>0) {
l=0;
len=filelength(f);
while (l lseek(f,l,SEEK_SET);
read(f,&sig, 4);
lseek(f,l,SEEK_SET);
switch(sig) {
case ZIP_LOCAL_SIG:
read(f,&zl, sizeof(zl));
READ_FN(zl.filename_len);
if (bad_filename(s)) {
close(f);
return(1);
}
l += sizeof(zl);
l += zl.comp_size + zl.filename_len + zl.extra_length;
break;
case ZIP_CENT_START_SIG:
read(f,&zc, sizeof(zc));
READ_FN(zc.filename_len);
if (bad_filename(s)) {
close(f);
return(1);
}
l += sizeof(zc);
l += zc.filename_len + zc.extra_len;
break;
case ZIP_CENT_END_SIG:
read(f,&ze, sizeof(ze));
close(f);
return(0);
default:
close(f);
printf("Error in zip file.\n");
return(1);
}
}
close(f);
return(0);
}

printf("file not found: %s\n",fn);
return(1);
}



void main(int argc, char *argv[])
{
char s[161];

if (argc!=3) {
printf("Put 'UNZIP %1 %2' in INIT.\n");
} else {
if (!check_for_files(argv[1])) {
sprintf(s,"PKUNZIP %s %s",argv[1], argv[2]);
system(s);
} else {
printf("Can't unzip from that .ZIP file.\n\n");
}
}
}



  3 Responses to “Category : BBS Programs+Doors
Archive   : UNZIP.ZIP
Filename : UNZIP.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/