From da97caafcee0c98ab921da77fbec70aa26727d98 Mon Sep 17 00:00:00 2001 From: kramm Date: Mon, 15 Nov 2004 11:08:24 +0000 Subject: [PATCH] fixed empty CVS checkin. --- installer/Makefile | 18 +++ installer/archive.c | 222 ++++++++++++++++++++++++++++++++++ installer/archive.h | 29 +++++ installer/crnfiles.c | 5 + installer/depack.c | 321 +++++++++++++++++++++++++++++++++++++++++++++++++ installer/depack.h | 41 +++++++ installer/installer.c | 132 ++++++++++++++++++++ 7 files changed, 768 insertions(+) diff --git a/installer/Makefile b/installer/Makefile index e69de29..de58c83 100644 --- a/installer/Makefile +++ b/installer/Makefile @@ -0,0 +1,18 @@ +CC=/opt/xmingw/bin/i386-mingw32msvc-gcc -DWIN32 + +all: installer.exe + +LIBS=-lgdi32 -lshlwapi + +crnfiles.o: crnfiles.c + $(CC) -c crnfiles.c + +depack.o: depack.c depack.h Makefile + $(CC) -c depack.c -o depack.o + +archive.o: archive.c archive.c depack.h + $(CC) -c archive.c -o archive.o + +installer.exe: installer.c depack.o archive.o depack.h crnfiles.o Makefile + $(CC) installer.c depack.o archive.o crnfiles.o -o installer.exe $(LIBS) + diff --git a/installer/archive.c b/installer/archive.c index e69de29..82c2de5 100644 --- a/installer/archive.c +++ b/installer/archive.c @@ -0,0 +1,222 @@ +/* archive.c + + Part of the swftools installer. + + Copyright (c) 2004 Matthias Kramm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include +#include +#include +#ifdef WIN32 +#include +#include +#else +#include +#endif +#include "archive.h" +#include "depack.h" + + +typedef struct _reader +{ + unsigned char*mem; + int readpos; +} reader_t; + +static void myread(void*self, void*mem, int len) +{ + /*if(readpos+len >= sizeof(crndata)) { + len = sizeof(crndata) - readpos; + }*/ + reader_t*r = (reader_t*)self; + memcpy(mem, r->mem+r->readpos, len); + r->readpos += len; + //return len; +} + +typedef struct _writer +{ + unsigned char*mem; + int memlen; +} writer_t; + +static void mywrite(void*self, void*buf, int len) +{ + writer_t*w = (writer_t*)self; + memcpy(w->mem+w->memlen, buf, len); + w->memlen += len; +} + +static int verbose = 0; +static void msg(char*format, ...) +{ + char buf[1024]; + int l; + va_list arglist; + if(!verbose) + return; + va_start(arglist, format); + vsprintf(buf, format, arglist); + va_end(arglist); + l = strlen(buf); + while(l && buf[l-1]=='\n') { + buf[l-1] = 0; + l--; + } + printf("(archive) %s\n", buf); + fflush(stdout); +} + +static int create_directory(char*path,statusfunc_t f) +{ + if(!path || !*path || (*path=='.' && (!path[1] || path[1]=='.'))) + return 1; //nothing to do + while(path[0]=='.' && (path[1]=='/' || path[1]=='\\')) + path+=2; + +#ifdef WIN32 + if(PathIsDirectoryA(path)) + return 1; +#else + struct stat st; + if(stat(path, &st)>=0) { + if(S_ISDIR(st.st_mode)) { + return 1; /* already exists */ + } + } +#endif + + if(mkdir(path,0755)<0) { + char buf[1024]; + sprintf(buf, "create directory \"%s\" FAILED", path); + f(-1, buf); + return 0; + } + return 1; +} +static int goto_directory(char*path,statusfunc_t f) +{ + if(chdir(path)<0) { + char buf[1024]; + sprintf(buf, "changing to directory \"%s\" FAILED", path); + f(-1, buf); + return 0; + } + return 1; +} +static char basenamebuf[256]; +static char*get_directory(char*filename) +{ + char*r1 = strrchr(filename, '\\'); + char*r2 = strrchr(filename, '/'); + char*r = r1>r2?r1:r2; + if(!r) + return ""; + memcpy(basenamebuf, filename, r-filename); + basenamebuf[r-filename] = 0; + //msg("directory name of \"%s\" is \"%s\"", filename, basenamebuf); + return basenamebuf; +} +static int write_file(char*filename, void*mem, int len,statusfunc_t f) +{ + while(filename[0]=='.' && (filename[1]=='/' || filename[1]=='\\')) + filename+=2; + + filename=strdup(filename); + + char*p = filename; + while(*p) { + if(*p=='/') *p='\\'; + p++; + } + + msg("create file \"%s\" (%d bytes)", filename, len); + FILE*fo = fopen(filename, "wb"); + if(!fo) { + char buf[1024]; + sprintf(buf, "Couldn't create file %s", filename); + f(-1, buf); + free(filename); + return 0; + } + fwrite(mem, len, 1, fo); + fclose(fo); + free(filename); + return 1; +} + +int unpack_archive(void*data, char*destdir, statusfunc_t f) +{ + depack_t d; + + reader_t r; + r.mem = (unsigned char*)data; + r.readpos = 0; + + f(0, "Reading compressed data"); + depack_init(&d,&r,myread); + + writer_t w; + w.mem = malloc(d.size); + w.memlen = 0; + + f(0, "Decompressing data"); + depack_process(&d,&w,mywrite); + depack_destroy(&d); + + f(0, "Creating installation directory"); + if(!create_directory(destdir,f)) return 0; + f(0, "Changing to installation directory"); + if(!goto_directory(destdir,f)) return 0; + + f(0, "Copying files..."); + int pos = 0; + while(pos + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifndef __archive_h__ +#define __archive_h__ + +typedef void (*statusfunc_t)(int type, char*text); + +int unpack_archive(void*data, char*destdir, statusfunc_t f); + +#endif //__archive_h__ + diff --git a/installer/crnfiles.c b/installer/crnfiles.c index e69de29..35a81a2 100644 --- a/installer/crnfiles.c +++ b/installer/crnfiles.c @@ -0,0 +1,5 @@ +char* crndata = +"\x0\xff\x7f\x0\x1c\x0\x0\x0\x8d\x0\x0)*\x2\x0\x34\x0\x0\x10\x0\x20\x0\x86\x0\xba" +"\x1d\x1\x0NUL\xc\x0tesu\xc8\xba{fil\x0ho\x20w@\x0\x0wrd\xa" +; + diff --git a/installer/depack.c b/installer/depack.c index e69de29..3f3343d 100644 --- a/installer/depack.c +++ b/installer/depack.c @@ -0,0 +1,321 @@ +/* depack.c + + Part of the swftools installer. + + Copyright (c) 1997-2004 Matthias Kramm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include "stdlib.h" +#include "stdio.h" +#include "depack.h" + +U32 dbittab[] = { + 0x1, 0x2, 0x4, 0x8, + 0x10, 0x20, 0x40, 0x80, + 0x100, 0x200, 0x400, 0x800, + 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, + 0x100000, 0x200000, 0x400000, 0x800000, + 0x1000000, 0x2000000, 0x4000000, 0x8000000, + 0x10000000,0x20000000,0x40000000,0x80000000 +}; + +static void* malloc_z(int len) +{ + void* buf = malloc(len); + if(buf == 0) { + fprintf(stderr, "\nout of memory\n"); + exit(1); + } + memset(buf, 0, len); + return buf; +} + +typedef struct _dpackead { + int back; + int len; +} dpackead_t; + +typedef struct _tree { + int depth; + U8 bits[17]; + U32 base[17]; +} tree_t; + +typedef struct _depack_internal +{ + int DMEMSIZE; + int DMEMSIZEA; + + tree_t T_REP; + tree_t T_STORE; + tree_t T_CNUM; + tree_t T_BACK; + tree_t T_BACK2; + tree_t T_BACK3; + + dpackead_t dpackead; + + void*reader; + readfunc_t readfunc; + void*writer; + writefunc_t writefunc; + + U8* mem; + int mempos; + int pos; + U8 c; + U32 b; +} depack_internal_t; + +void depack_destroy(depack_t*d) +{ + depack_internal_t*i = (depack_internal_t*)d->internal; + free(i->mem);i->mem=0; + free(d->internal);d->internal=0;i=0; +} + +static readbytes(depack_t*d, int num) +{ + depack_internal_t*i = (depack_internal_t*)d->internal; + + if(i->mempos+num<=i->DMEMSIZE) { + i->readfunc(i->reader, &i->mem[i->mempos],num); + i->writefunc(i->writer, &i->mem[i->mempos],num); + } else { + i->readfunc(i->reader, &i->mem[i->mempos],i->DMEMSIZE - i->mempos); + i->writefunc(i->writer, &i->mem[i->mempos],i->DMEMSIZE - i->mempos); + i->readfunc(i->reader, &i->mem[0],num-(i->DMEMSIZE - i->mempos)); + i->writefunc(i->writer, &i->mem[0],num-(i->DMEMSIZE - i->mempos)); + } + i->mempos=(i->mempos+num)&i->DMEMSIZEA; + i->pos+=num; +} + +int move(U8*dest, U8*src, int len) +{ + if(len) do { + *dest=*src; + src++; + dest++; + } while(--len); +} + +static lookback(depack_t*d, int back,int len) +{ + depack_internal_t*i = (depack_internal_t*)d->internal; + + int x,z=(i->mempos-back)&i->DMEMSIZEA; + char fail=0; + + if(i->mempos+len <= i->DMEMSIZE && + z+len <= i->DMEMSIZE) + { + move(&i->mem[i->mempos],&i->mem[z],len); + i->writefunc(i->writer, &i->mem[i->mempos],len); + i->mempos=(i->mempos+len)&i->DMEMSIZEA; + } else { + for(x=0;xmem[i->mempos]=i->mem[z]; + i->writefunc(i->writer, &i->mem[i->mempos],1); + i->mempos=(i->mempos+1)&i->DMEMSIZEA; + z=(z+1)&i->DMEMSIZEA; + } + } + i->pos += len; +} + +static inline U8 readbit(depack_internal_t*i) +{ + i->c&=31; + if(i->c==0) i->readfunc(i->reader, &i->b,4); + return (i->b>>(31-i->c++))&1; +} + +static inline U32 readval(depack_internal_t*i,int b) +{ + unsigned v=0; + signed char l; + for(l=b-1;l>=0;l--) + v|=readbit(i)<internal; + + int l; + int x,y,z=0,b=0,r; + tree_t tree; + memset(&tree, 0, sizeof(tree)); + + tree.depth = readval(i,4)+1; + + for(x=0;xttree[n].bits[z]>16) + printf("."); + else + printf("%c","0123456789abcdefg"[ttree[n].bits[z]]); + } + printf("\n");*/ +} + +static void showtree(tree_t tree) +{ + int t; + int last=0; + int lastbits = 0; + for(t=0;t<=tree.depth;t++) + { + if(t>0) + printf("[%d] %d: %05x-%05x (%d=%d+%d+1)\n",t,lastbits, last,tree.base[t],lastbits+(t-1)+1, lastbits,t-1); + last=tree.base[t]; + lastbits = tree.bits[t]; + } +} + +static int gettreeval(depack_t*d, tree_t*tree) +{ + depack_internal_t*i = (depack_internal_t*)d->internal; + + U8 x=0; + while(!readbit(i)) x++; + if(x<17) return tree->base[x]+readval(i, tree->bits[x]); + else return -1; +} + +static int get_memsize(int b) +{ + int t,c=1; + for(t=0;;t++) { + if(c>=b) return c; + c<<=1; + } + return 0; +} + +void depack_init(depack_t*d, void*reader, readfunc_t readfunc) +{ + d->internal = malloc_z(sizeof(depack_internal_t)); + depack_internal_t*i = (depack_internal_t*)d->internal; + if(i==0) { + fprintf(stderr, "depacker not initialized yet"); exit(1); + } + + i->reader = reader; + i->readfunc = readfunc; + + i->mempos=0; + i->pos=0; + i->b=i->c=0; + + i->readfunc(i->reader,&i->dpackead.back, 4); + i->readfunc(i->reader,&i->dpackead.len, 4); + + i->DMEMSIZE = get_memsize(i->dpackead.len); + i->DMEMSIZEA = i->DMEMSIZE-1; + i->mem = malloc_z(i->DMEMSIZE); + + i->T_REP = gettree(d); + i->T_STORE = gettree(d); + i->T_CNUM = gettree(d); + //showtree(i->T_CNUM); + i->T_BACK = gettree(d); + //showtree(i->T_BACK); + i->T_BACK2 = gettree(d); + //showtree(i->T_BACK); + i->T_BACK3 = gettree(d); + //showtree(i->T_BACK3); + + d->size = i->dpackead.len; +} + +void depack_process(depack_t*d, void*writer,writefunc_t writefunc) +{ + depack_internal_t*i = (depack_internal_t*)d->internal; + i->writer = writer; + i->writefunc = writefunc; + while(i->posdpackead.len) + { + int store,rep,x; + + store=gettreeval(d,&i->T_STORE)+1; + + readbytes(d,store); + + if(i->posdpackead.len) + { + rep = gettreeval(d,&i->T_REP)+1; + + for(x=0;xT_CNUM)+1; + + if(len == 1) back = readval(i,3)+1; + if(len == 2) back = gettreeval(d,&i->T_BACK2)+1; + if(len == 3) back = gettreeval(d,&i->T_BACK3)+1; + if(len >= 4) back = gettreeval(d,&i->T_BACK)+1; + + lookback(d,back,len); + } + } + } + + if(i->pos!=i->dpackead.len) { + fprintf(stderr, "Internal error"); + exit(1); + } +} + +/* + + mov eax,[b1] + mov ebx,[b2] + shld eax,ebx,cl + mov [b1],eax + shr ebx,cl + mov [b2],ebx + sub cnt,cl + cmp cnt,32-8 + ja jj +mm: xor eax,eax + call read + shl eax,[cnt] + or [b2],eax + add cnt,8 + cmp cnt,32-8 + jb mm +jj: + +*/ + + diff --git a/installer/depack.h b/installer/depack.h index e69de29..028ab0c 100644 --- a/installer/depack.h +++ b/installer/depack.h @@ -0,0 +1,41 @@ +/* depack.h + + Part of the swftools installer. + + Copyright (c) 2004 Matthias Kramm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifndef Depack_h +#define Depack_h + +typedef unsigned long int U32; +typedef unsigned char U8; + +typedef struct { + void*internal; + int pos; + int size; +} depack_t; + +typedef void (*writefunc_t)(void*writer, void*mem, int len); +typedef void (*readfunc_t)(void*reader, void*mem, int len); + +void depack_init(depack_t*d, void*reader, readfunc_t); +void depack_process(depack_t*d, void*writer, writefunc_t); +void depack_destroy(depack_t*d); + +#endif //Depack_h + diff --git a/installer/installer.c b/installer/installer.c index e69de29..397cd59 100644 --- a/installer/installer.c +++ b/installer/installer.c @@ -0,0 +1,132 @@ +/* installer.c + + Part of the swftools installer (Main program). + + Copyright (c) 2004 Matthias Kramm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include +#include +#include + +#include "depack.h" + +#include "../config.h" //for swftools version + +extern char*crndata; + +LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + printf("%08x, %d %08x %08x\n", hwnd, message, wParam, lParam); + switch(message) + { + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hwnd, message, wParam, lParam); + } + return 0; +} + +#if USE_CONSOLE +static HANDLE console; +#endif +static char*lastmessage = 0; +void myarchivestatus(int type, char*text) +{ + DWORD written = 0; +#if USE_CONSOLE + if(console) { + WriteConsole(console, text, strlen(text), &written, 0); + WriteConsole(console, "\n", 1, &written, 0); + fflush(stdout); + } +#endif + if(!written) { + printf("%s\n", text); + } + + if(type<0) { + while(1) { + int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR); + + /* there is no MB_CANCEL, so, *sigh*, we have to display + the "retry" button. So pretend it's doing anything... */ + if(ret==IDRETRY) + continue; + else + break; + } + } +} + +int WINAPI WinMain(HINSTANCE me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode) +{ + WNDCLASS wcl; + char*install_dir = "C:\\swftools\\"; + + wcl.hInstance = me; + wcl.lpszClassName= "SWFTools-Installer"; + wcl.lpfnWndProc = WindowFunc; + wcl.style = 0; //default style + wcl.hIcon = LoadIcon (NULL, IDI_APPLICATION); + wcl.hCursor = LoadCursor(NULL, IDC_ARROW); + wcl.lpszMenuName = NULL; //no menu + wcl.cbClsExtra = 0; + wcl.cbWndExtra = 0; + wcl.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH); + + if(!RegisterClass(&wcl)) + return 0; + +#if USE_CONSOLE + FreeConsole(); +#endif + + char buf[1024]; + sprintf(buf, "Do you want me to install SWFTools into the directory %s now?", install_dir); + int ret = MessageBox(0, buf, "SWFTools Install", MB_YESNO|MB_ICONQUESTION); + + if(ret == IDNO) + return 0; + +#if USE_CONSOLE + if(AllocConsole()) { + DWORD written; + console = GetStdHandle(STD_OUTPUT_HANDLE); + WriteConsole(console, "\r\n", 1, &written, 0); + } +#endif + + int success = unpack_archive(crndata, "C:\\swftools\\", myarchivestatus); + +#if USE_CONSOLE + FreeConsole(); +#endif + + if(success) { + sprintf(buf, "SWFTools Version %s has been installed into %s successfully", VERSION, install_dir); + ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONINFORMATION); + } else { + /*sprintf(buf, "Installation failed\nLast message: %s", lastmessage); + ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONERROR);*/ + } + exit(0); +} + + + -- 1.7.10.4