[Winpt-commits] r325 - trunk/PTD

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Sep 25 17:51:30 CEST 2009


Author: twoaday
Date: 2009-09-25 17:51:28 +0200 (Fri, 25 Sep 2009)
New Revision: 325

Removed:
   trunk/PTD/wptJPG.cpp
   trunk/PTD/wptJPG.h
   trunk/PTD/wptWipeFile.cpp
   trunk/PTD/wptZIP.cpp
   trunk/PTD/wptZIP.h
Modified:
   trunk/PTD/Makefile.am
   trunk/PTD/PTD.cpp
   trunk/PTD/PTD.def
Log:
Updated.


Modified: trunk/PTD/Makefile.am
===================================================================
--- trunk/PTD/Makefile.am	2009-09-25 15:47:52 UTC (rev 324)
+++ trunk/PTD/Makefile.am	2009-09-25 15:51:28 UTC (rev 325)
@@ -27,13 +27,10 @@
 	resource.rc \
 	resource.h \
 	PTD.cpp \
-	wptZIP.cpp wptZIP.h \
-	wptJPG.cpp wptJPG.h \
-	wptWipeFile.cpp \
 	wptDNSKeys.cpp wptDNSKeys.h
 
 PTD_LDADD = $(srcdir)/PTD.def -L../Gnupg  -lgnupg $(W32LIBS) \
-            -lole32 -loleaut32 -lgdi32 -luuid
+            -lgdi32
 
 resource.o: resource.rc resource.h versioninfo.rc
 

Modified: trunk/PTD/PTD.cpp
===================================================================
--- trunk/PTD/PTD.cpp	2009-09-25 15:47:52 UTC (rev 324)
+++ trunk/PTD/PTD.cpp	2009-09-25 15:51:28 UTC (rev 325)
@@ -1,5 +1,5 @@
 /* PTD.cpp - Privacy Tray Dynamic
- *	Copyright (C) 2002-2007 Timo Schulz
+ *	Copyright (C) 2002-2009 Timo Schulz
  *
  * This file is part of WinPT.
  *
@@ -19,11 +19,7 @@
 
 #include <windows.h>
 #include <stdio.h>
-#include <ocidl.h>
-#include <olectl.h>
 
-#include "wptJPG.h"
-
 HINSTANCE glob_hinst;
 
 /* We need a special section in the DLL for storing our shared data.
@@ -55,9 +51,7 @@
 static HHOOK journ_hook = NULL;	 /* Journaling hook  handle. */
 
 
-void dns_cleanup (void);
 
-
 static LRESULT CALLBACK
 PTD_CBT_proc (int code, WPARAM wparam, LPARAM lparam)
 {
@@ -141,7 +135,6 @@
 {
     if (!cbt_hook)
 	return;
-    dns_cleanup ();
     UnhookWindowsHookEx (cbt_hook);
     cbt_hook = NULL;
     shell_traywnd = NULL;
@@ -199,7 +192,7 @@
     MSG msg;
     journ_keys = keys;
     keyidx = 0;
-    nkeys =  n_keys;    
+    nkeys = n_keys;    
     
     if (journ_hook)
         return FALSE;
@@ -238,50 +231,35 @@
 }
 
 
-/* Display a JPG picture in the given window at the given point. */
-extern "C" int
-PTD_jpg_show (HWND hwnd, POINT *p, LPCSTR name)
-{
-    CJPG jpg;
-    HDC hdc;
-    POINT sizewnd;
-    RECT rwnd;
-    BOOL rc;
+/*FILE *fp;*/
 
-    rc = jpg.load (name);
-    if (!rc)
-	return -1; /* XXX: use real return code. */
-    hdc = GetWindowDC (hwnd);
-    rc = jpg.updateSizeOnDC (hdc);
-    if (!rc) {
-	ReleaseDC (hwnd, hdc);
-	return -2; /* XXX: use real return code. */
-    }
-
-    GetWindowRect (hwnd, &rwnd);
-    sizewnd.x = rwnd.right - rwnd.left;
-    sizewnd.y = rwnd.bottom - rwnd.top;
-    rc = jpg.show (hdc, p, &sizewnd, 0, 0);
-
-    ReleaseDC (hwnd, hdc);
-    jpg.freePictureData ();
-    return rc;
-}
-
-		
 extern "C" BOOL WINAPI 
 DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv)
 {
     switch (reason)  {
     case DLL_PROCESS_ATTACH: 
-	glob_hinst = hinst; 
+	glob_hinst = hinst;
+        /*
+        fp = fopen ("attach_pid.txt", "a+b");
+        if (fp != NULL) {	
+	    fprintf (fp, "[+ %lu]\r\n", GetCurrentProcessId());
+	    fclose (fp);
+	}*/      
 	break;
-    case DLL_THREAD_ATTACH:  
+       
+    case DLL_PROCESS_DETACH:
+	/*fp = fopen ("attach_pid.txt", "a+b");
+        if (fp != NULL) {
+	    fprintf (fp, "[- %lu]\r\n", GetCurrentProcessId());
+	    fclose (fp);
+	}*/
 	break;
+	
+    case DLL_THREAD_ATTACH:  
     case DLL_THREAD_DETACH:  
 	break;
-    case DLL_PROCESS_DETACH: 
-	break;
+	
     }
+    
     return TRUE;
 }

Modified: trunk/PTD/PTD.def
===================================================================
--- trunk/PTD/PTD.def	2009-09-25 15:47:52 UTC (rev 324)
+++ trunk/PTD/PTD.def	2009-09-25 15:51:28 UTC (rev 325)
@@ -1,3 +1,4 @@
+; For Visual C++ compiler only!
 ;SECTIONS
 ;	.SHARDAT READ WRITE SHARED
 
@@ -3,51 +4,32 @@
 EXPORTS
 	PTD_initialize			@201
-	PTD_delete				@202
-	PTD_is_used				@203
+	PTD_delete			@202
+	PTD_is_used			@203
 	PTD_keyb_send			@204
 	PTD_get_curr_hwnd		@205
-	PTD_jpg_show			@208
-
-	gpg_use_armor_filter	@210
+	
+	gpg_use_armor_filter		@210
 	gpg_armor_filter		@211
 	gpg_parse_packet		@213
 	gpg_free_packet			@214	
-	gpg_parse_sig_subpkt2	@215
-	gpg_parse_sig_subpkt	@216	
+	gpg_parse_sig_subpkt2		@215
+	gpg_parse_sig_subpkt		@216	
 	gpg_read_keyblock		@218
 	gpg_keyid_from_sk		@219
 	gpg_keyid_from_pk		@220
 
-	gpg_iobuf_open				@230
+	gpg_iobuf_open			@230
 	gpg_iobuf_push_filter		@231
-	gpg_iobuf_close				@232
-	gpg_iobuf_temp_with_content @234
-	gpg_iobuf_ioctl				@235
-	gpg_iobuf_tell				@236
-	gpg_iobuf_seek				@237
+	gpg_iobuf_close			@232
+	gpg_iobuf_temp_with_content 	@234
+	gpg_iobuf_ioctl			@235
+	gpg_iobuf_tell			@236
+	gpg_iobuf_seek			@237
 	gpg_iobuf_get_filelength	@238
 
-	gpg_release_kbnode			@221
-	gpg_walk_kbnode				@222
+	gpg_release_kbnode		@221
+	gpg_walk_kbnode			@222
 
-	rename_unlink			@240
-	secure_unlink			@241
-	wipe_freespace			@242
-	secure_unlink_set_cb	@243
-
-	pk_archiv_parse			@450
-	pk_archiv_create		@451
-	pk_list_add				@452
-	pk_list_free			@453
-
-	gpg_md_hash_file			@500
-	gpg_md_open					@501
-	gpg_md_close				@502
-	gpg_md_final				@503
-	gpg_md_write				@504
-	gpg_md_putc					@505
-	gpg_md_read					@506
-	gpg_md_selftest				@507
-
-       	dns_free_pka_record                     @600
-       	dns_get_pka_record                      @601
+;	gpg_md_hash_file		@500
+	gpg_md_selftest			@507
+	

Deleted: trunk/PTD/wptJPG.cpp
===================================================================
--- trunk/PTD/wptJPG.cpp	2009-09-25 15:47:52 UTC (rev 324)
+++ trunk/PTD/wptJPG.cpp	2009-09-25 15:51:28 UTC (rev 325)
@@ -1,277 +0,0 @@
-/* wptJPG.cpp - Routines for showing JPG pictures
- *	Copyright (C) 2001 Dr.Yovav Gad
- *	Copyright (C) 2005, 2006 Timo Schulz
- *
- * This file is part of WinPT.
- *
- * WinPT 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.
- * 
- * WinPT 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 PTD; if not, write to the Free Software Foundation, 
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-/*-----------------------------------------------------------------------------
- * Picture (Implementations) Version 1.00
- * Author: Dr. Yovav Gad, EMail: Sources at SuperMain.com
- * Web: www.SuperMain.com
- * 
- * This version uses a stripped down and heavily modified version of 
- * Picture.cpp and Picture.h.
- */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <windows.h>
-#include <ocidl.h>
-#include <olectl.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/stat.h>
-
-#include "wptJPG.h"
-
-#define HIMETRIC_INCH	2540
-#define ERROR_TITLE	"WinPT - CJPG Error"
-
-#define out_of_core() do { \
-	MessageBox (NULL, "Can not allocate memory", ERROR_TITLE, MB_OK|MB_ICONSTOP); \
-	return FALSE; \
-    } while (0)
-
-
-/* Constructor to create an empty JPG container. */
-CJPG::CJPG (void)
-{
-    m_IPicture = NULL;
-    m_Height = 0;
-    m_Weight = 0;
-    m_Width = 0;    
-}
-
-
-/* Deconstructor. Free all internal data. */
-CJPG::~CJPG (void)
-{
-    if (m_IPicture != NULL)
-	freePictureData (); 
-}
-
-
-
-/* Free the allocated memory that holdes the IPicture Interface data
-   and clear picture information. */
-void 
-CJPG::freePictureData (void)
-{
-    if (m_IPicture != NULL) {
-	m_IPicture->Release();
-	m_IPicture = NULL;
-    }
-    m_Height = 0;
-    m_Weight = 0;
-    m_Width = 0;
-}
-
-
-/* Open a JPG File And Load It Into IPicture (Interface) */
-BOOL 
-CJPG::load (LPCSTR sFilePathName)
-{
-    struct stat st;
-    FILE *fp;    
-    BYTE *pBuffer;
-    int n;
-
-    if (m_IPicture != NULL) 
-	freePictureData ();
-
-    fp = fopen (sFilePathName, "rb");
-    if (!fp) {
-	MessageBox (NULL, strerror (errno), ERROR_TITLE, MB_OK|MB_ICONSTOP);
-	return FALSE;
-    }
-
-    /* avoid to load empty JPG files and make sure we still can
-       access the file handle. */
-    if (fstat (fileno (fp), &st) || st.st_size == 0) {
-	fclose (fp);
-	return FALSE;
-    }
-    pBuffer = new BYTE[st.st_size];
-    if  (!pBuffer)
-	out_of_core ();
-    memset (pBuffer, 0, st.st_size);
-    n = fread (pBuffer, 1, st.st_size, fp);
-    fclose (fp);
-
-    /* not the entire file were read in, so abort here. */
-    if (n != st.st_size) {
-	delete []pBuffer;
-	return FALSE;
-    }
-    if (!loadPictureData (pBuffer, st.st_size)) {
-	delete []pBuffer;
-	return FALSE;
-    }
-    delete [] pBuffer;
-
-    m_Weight = st.st_size; /* Update Picture Size Info... */
-    if (m_IPicture == NULL) {
-	m_Height = 0;
-	m_Width = 0;
-	return FALSE;
-    }
-    m_IPicture->get_Height (&m_Height);
-    m_IPicture->get_Width (&m_Width);
-    /* Calculate Its Size On a "Standard" (96 DPI) Device Context */
-    m_Height = MulDiv (m_Height, 96, HIMETRIC_INCH);
-    m_Width  = MulDiv (m_Width,  96, HIMETRIC_INCH);	
-    return TRUE;
-}
-
-
-
-/* read the picture data from a source (file / resource)
-   and load it into the current IPicture object in use */
-BOOL 
-CJPG::loadPictureData (BYTE *pBuffer, int nSize)
-
-{
-    HGLOBAL hGlobal;    
-    IStream* pStream = NULL;
-    void* pData;
-    BOOL bResult = FALSE;
-    
-    hGlobal = GlobalAlloc (GMEM_MOVEABLE, nSize);
-    if (hGlobal == NULL)
-	out_of_core ();
-
-    pData = GlobalLock (hGlobal);
-    memcpy (pData, pBuffer, nSize);
-    GlobalUnlock (hGlobal);
-
-    if (CreateStreamOnHGlobal (hGlobal, TRUE, &pStream) == S_OK) {
-	HRESULT hr;
-	hr = OleLoadPicture (pStream, nSize, FALSE, IID_IPicture, 
-			     (LPVOID *)&m_IPicture);
-	if (hr == E_NOINTERFACE)
-	    MessageBox (NULL, "IPicture interface is not supported", 
-			ERROR_TITLE, MB_OK|MB_ICONSTOP);
-	else { /* S_OK */
-	    pStream->Release ();
-	    pStream = NULL;
-	    bResult = TRUE;
-	}	
-    }
-
-    GlobalFree (hGlobal);
-    return bResult;
-}
-
-
-/* Draw the loaded picture direct to the client DC */
-BOOL 
-CJPG::show (HDC pDC, POINT *leftTop, POINT *widthHeight, 
-	    int magnifyX, int magnifyY)
-
-{
-    RECT drawRect;
-    HRESULT hr = 0;
-    long width  = 0;
-    long height = 0;    
-
-    if (pDC == NULL || m_IPicture == NULL) 
-	return FALSE;
-
-    m_IPicture->get_Width (&width);
-    m_IPicture->get_Height (&height);
-	
-    if (magnifyX == 0) 
-	magnifyX = 0;
-    if (magnifyY == 0) 
-	magnifyY = 0;
-    magnifyX = int(MulDiv (width, GetDeviceCaps(pDC, LOGPIXELSX), HIMETRIC_INCH) * magnifyX);
-    magnifyY = int(MulDiv (height, GetDeviceCaps(pDC, LOGPIXELSY), HIMETRIC_INCH) * magnifyY);
-
-    drawRect.left = leftTop->x;
-    drawRect.top = leftTop->y;
-    drawRect.right = magnifyX;
-    drawRect.bottom = magnifyY;
-
-    hr = m_IPicture->Render (pDC,
-                      leftTop->x,               // Left
-                      leftTop->y,               // Top
-                      widthHeight->x +magnifyX, // Width
-                      widthHeight->y +magnifyY, // Height
-                      0,
-                      height,
-                      width,
-                      -height,
-                      &drawRect);
-
-    if (SUCCEEDED (hr)) 
-	return TRUE;
-
-    return FALSE;
-}
-
-
-/* Get the original picture pixel size (ignore what current DC is using)
-   pointer to a Device Context is needed for pixel calculation, */
-BOOL 
-CJPG::updateSizeOnDC (HDC pDC)
-
-{	
-    if(pDC == NULL || m_IPicture == NULL) { 
-	m_Height = 0; 
-	m_Width = 0; 
-	return FALSE;
-    }
-
-    m_IPicture->get_Height (&m_Height);
-    m_IPicture->get_Width (&m_Width);
-
-    /* Get Current DPI - Dot Per Inch */
-    int CurrentDPI_X = GetDeviceCaps (pDC, LOGPIXELSX);
-    int CurrentDPI_Y = GetDeviceCaps (pDC, LOGPIXELSY);
-
-    m_Height = MulDiv (m_Height, CurrentDPI_Y, HIMETRIC_INCH);
-    m_Width  = MulDiv (m_Width,  CurrentDPI_X, HIMETRIC_INCH);
-
-    return TRUE;
-}
-
-/* Return height of the current image. */
-LONG
-CJPG::getHeight (void)
-{
-    return m_Height;
-}
-
-
-/* Return weight of the current image. */
-LONG 
-CJPG::getWeight (void)
-{
-    return m_Weight;
-}
-
-
-/* Return width of the current image. */
-LONG
-CJPG::getWidth (void)
-{
-    return m_Width;
-}

Deleted: trunk/PTD/wptJPG.h
===================================================================
--- trunk/PTD/wptJPG.h	2009-09-25 15:47:52 UTC (rev 324)
+++ trunk/PTD/wptJPG.h	2009-09-25 15:51:28 UTC (rev 325)
@@ -1,49 +0,0 @@
-/* wptJPG.h - Routins four showing JPG picture files
- *	Copyright (C) 2001 Dr.Yovav Gad <Sources at SuperMain.com>
- *	Copyright (C) 2005 Timo Schulz
- *
- * This file is part of WinPT.
- *
- * WinPT 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.
- * 
- * WinPT 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 PTD; if not, write to the Free Software Foundation, 
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-#ifndef WPT_JPG_H
-#define WPT_JPG_H 1
-
-class CJPG
-{
-private:
-    LONG m_Height; /* height (in pixels ignore what current device context uses) */
-    LONG m_Weight; /* size of the image object in bytes */
-    LONG m_Width;  /* width (in pixels ignore what current device context uses) */
-
-    IPicture* m_IPicture; /* Same As LPPICTURE (typedef IPicture __RPC_FAR *LPPICTURE)*/
-
-public:
-    CJPG ();	
-    virtual ~CJPG ();
-
-    void freePictureData ();
-    BOOL load (LPCSTR sFilePathName);
-    BOOL loadPictureData (BYTE* pBuffer, int nSize);
-    BOOL show (HDC pDC, POINT *leftTop, POINT *widthHeight, 
-	       int magnifyX, int magnifyY);
-    BOOL updateSizeOnDC (HDC pDC);
-
-    LONG getHeight (void);
-    LONG getWeight (void);
-    LONG getWidth (void);
-};
-
-#endif /*WPT_JPG_H*/

Deleted: trunk/PTD/wptWipeFile.cpp
===================================================================
--- trunk/PTD/wptWipeFile.cpp	2009-09-25 15:47:52 UTC (rev 324)
+++ trunk/PTD/wptWipeFile.cpp	2009-09-25 15:51:28 UTC (rev 325)
@@ -1,582 +0,0 @@
-/* wptWipeFile.cpp - Secure file removal
- *	Copyright (C) 2001-2006 Timo Schulz
- *	Copyright (C) 2000 Matt Gauthier
- *
- * (This code based on the sunlink.c file from the SRM project)
- *
- * WinPT 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.
- *
- * WinPT 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 WinPT; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <windows.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <ctype.h>
-#include <direct.h>
-
-#include "wptW32API.h"
-#include "wptErrors.h"
-#include "wptTypes.h"
-
-/* WARNING: Because modern file systems, for example NTFS, use a lot of
-	    features to provide better performance and journaling to recover
-	    the FS after a crash, secure file deleting is extremly
-	    difficult. It can happen that parts of the file are still in
-	    plaintext after wiping the file. To avoid information leakage,
-	    it is recommend to wipe the free space of the disk to destroy
-	    left over pattern. */
-
-#ifdef _MSC_VER
-typedef unsigned __int64 DDWORD;
-#else
-typedef unsigned long long DDWORD;
-#endif
-
-typedef struct {
-    HANDLE fd;		/* file descriptor. */
-    DDWORD filesize;	/* file size of the file. */
-    DDWORD offset;
-    BYTE  *buffer;
-    DWORD  buffsize;
-    const char *name;
-    int    n_passes;
-} wipe_context_s;
-
-#define SBOX_SIZE 256
-struct arcfour_s {
-    BYTE *seed;
-    int  pos;
-    BYTE sbox[SBOX_SIZE];
-    DWORD i;
-    DWORD j;
-};
-
-
-void (*progress_cb) (void *, DDWORD, DDWORD);
-static void *progress_cb_value = NULL;
-
-void (*unlink_cb)(void *, const char *, int, int, int) = NULL;
-static void *unlink_cb_value = NULL;
-
-static int init_done = 0;
-static struct arcfour_s rnd;
-
-
-/* Add the random from buffer @buf with the length @buf_len
-   into the seed @seed. The seed length (256) used to
-   emulate a circular movment. */
-static void
-add_random (BYTE *seed, int *seed_pos, BYTE *buf, int buf_len)
-{
-    int i, s_pos = *seed_pos;
-
-    for (i=0; i < buf_len; i++)
-	seed[(s_pos++ % SBOX_SIZE)] ^= buf[i];
-    *seed_pos = s_pos % SBOX_SIZE;
-}
-
-
-/* Enumerate all child windows. Store their text, their thread ID, 
-   their placement and their dimension. */
-static BOOL CALLBACK 
-child_proc (HWND h, LPARAM l)
-{
-    struct arcfour_s *cb =  (struct arcfour_s*)l;
-    DWORD a = (DWORD)h;
-    WINDOWPLACEMENT p;
-    RECT r;
-    char buf[256];
-    int n;
-
-    n  = GetWindowText (h, buf, DIM (buf)-1);
-    if (n > 0)
-	add_random (cb->seed, &cb->pos, (BYTE*)buf, n);
-    add_random (cb->seed, &cb->pos, (BYTE*)&a, 4);
-    a = GetWindowThreadProcessId (h, NULL);
-    add_random (cb->seed, &cb->pos, (BYTE*)&a, 4);
-    GetWindowPlacement (h, &p);
-    add_random (cb->seed, &cb->pos, (BYTE*)&p, sizeof (p));
-    GetWindowRect (h, &r);
-    add_random (cb->seed, &cb->pos, (BYTE*)&r, sizeof (r));
-    return TRUE;
-}
-
-
-/* Initialize the seed with all kind of system variables. */
-static void
-init_random (unsigned char *seed)
-{
-    int pos=0;
-    DWORD buf[16];
-    int i=0;
-
-    buf[i++] = (DWORD)GetActiveWindow ();
-    buf[i++] = (DWORD)GetCapture ();
-    buf[i++] = (DWORD)GetClipboardOwner ();
-    buf[i++] = (DWORD)GetClipboardViewer ();
-    buf[i++] = (DWORD)GetCurrentProcess ();      
-    buf[i++] = (DWORD)GetCurrentProcessId ();
-    buf[i++] = (DWORD)GetCurrentThread ();
-    buf[i++] = (DWORD)GetDesktopWindow ();
-    buf[i++] = (DWORD)GetFocus ();
-    buf[i++] = (DWORD)GetMessagePos ();
-    buf[i++] = (DWORD)GetOpenClipboardWindow ();
-    buf[i++] = (DWORD)GetProcessHeap ();
-    buf[i++] = (DWORD)GetProcessWindowStation ();
-    buf[i++] = (DWORD)GetQueueStatus (QS_ALLEVENTS);
-    buf[i] = (DWORD)GetTickCount ();
-    add_random (seed, &pos, (BYTE*)buf, 4*i);
-
-    {
-	POINT p;
-	GetCursorPos (&p);
-	add_random (seed, &pos, (BYTE*)&p, sizeof (p));
-	GetCaretPos (&p);
-	add_random (seed, &pos, (BYTE*)&p, sizeof (p));
-    }
-
-    {
-	STARTUPINFO inf;
-	inf.cb = sizeof (inf);
-	GetStartupInfo (&inf);
-	add_random (seed, &pos, (BYTE*)&inf, sizeof (inf));
-    }
-
-    {
-	MEMORYSTATUS st;
-	
-	st.dwLength = sizeof (st);
-	GlobalMemoryStatus (&st);
-	add_random (seed, &pos, (BYTE*)&st, sizeof (st));
-    }
-
-    {
-	LARGE_INTEGER in;
-
-	QueryPerformanceFrequency (&in);
-	add_random (seed, &pos, (BYTE*)&in, sizeof (in));
-	QueryPerformanceCounter (&in);
-	add_random (seed, &pos, (BYTE*)&in, sizeof (in));
-    }
-    {
-	rnd.seed = seed;
-	rnd.pos = pos;
-	EnumChildWindows (GetDesktopWindow (), child_proc, (LPARAM)&rnd);
-    }
-
-}
-
-
-/* Initialize cipher with the seed as the key. */
-static void
-init_arcfour (struct arcfour_s *ctx, BYTE *key)
-{
-    BYTE t;
-
-    ctx->i = 0;
-    ctx->j = 0;
-    for (ctx->i=0; ctx->i < SBOX_SIZE; ctx->i++)
-	ctx->sbox[ctx->i] = (BYTE)ctx->i;
-    for (ctx->i=0; ctx->i < SBOX_SIZE; ctx->i++) {
-	ctx->j += (ctx->j+ctx->sbox[ctx->i]+key[ctx->i]);
-	ctx->j &= 255;
-	t = ctx->sbox[ctx->i];
-	ctx->sbox[ctx->i] = ctx->sbox[ctx->j];
-	ctx->sbox[ctx->j] = t;
-    }
-}
-
-
-/* Generate a single random byte. If the cipher is not
-   init, do an init first. */
-static BYTE 
-rnd_byte (void)
-{
-    struct arcfour_s *ctx = &rnd;
-    BYTE t;
-
-    if (!init_done) {
-	BYTE buf[SBOX_SIZE];
-
-	init_random (buf);
-	init_arcfour (ctx, buf);
-	init_done = 1;
-    }
-
-    ctx->i++; ctx->i &= 255;
-    ctx->j += ctx->sbox[ctx->i]; ctx->j &= 255;
-    t = ctx->sbox[ctx->i];
-    ctx->sbox[ctx->i] = ctx->sbox[ctx->j];
-    ctx->sbox[ctx->j] = t;
-    return ctx->sbox[(ctx->sbox[ctx->i] + ctx->sbox[ctx->j]) & 255];
-}
-
-
-/* Generate a single alpha-num charactor. */
-static char
-random_char (void)
-{	
-    BYTE c = 0;
-
-    while  (!isalnum ((int)c))
-	c = rnd_byte ();
-    return c % 127;
-}
-
-
-/* Use the file handle in the context to overwrite a file
-   with prepared buffer contents. */
-static void 
-overwrite (wipe_context_s *ctx)
-{
-    DDWORD blocks = 0, mod = 0;
-    DWORD nwritten = 0;
-    LONG size_high = 0;
-
-    blocks = ctx->filesize / ctx->buffsize;
-    mod = ctx->filesize % ctx->buffsize;
-    SetFilePointer (ctx->fd, 0, &size_high, FILE_BEGIN);
-    while (blocks--) {
-	if (!WriteFile (ctx->fd, ctx->buffer, ctx->buffsize, &nwritten, NULL))
-	    break;
-	ctx->offset += nwritten;
-	if (unlink_cb)
-	    unlink_cb (unlink_cb_value, ctx->name, 0, (unsigned)ctx->offset, 
-		       (unsigned)ctx->filesize*ctx->n_passes);
-    }
-    if (mod) {
-	WriteFile (ctx->fd, ctx->buffer, (DWORD)mod, &nwritten, NULL);
-	ctx->offset += nwritten;
-	if (unlink_cb)
-	    unlink_cb (unlink_cb_value, ctx->name, 0, (unsigned)ctx->offset, 
-		       (unsigned)ctx->filesize*ctx->n_passes);
-    }
-    FlushFileBuffers (ctx->fd);
-    SetFilePointer (ctx->fd, 0, &size_high, FILE_BEGIN);
-}
-
-
-/* fill the buffer with random of the given level. */
-static void
-randomize_buffer (BYTE *buf, size_t bufsize)
-{
-    const int blocksize = 512;
-    int blocks = bufsize / blocksize;
-    int mod = bufsize % blocksize;
-    int i;
-
-    while (blocks--) {
-	for (i=0; i < blocksize; i++)
-	    buf[i] = rnd_byte ();
-	buf += blocksize;
-    }
-    for (i=0; i < mod; i++)
-	buf[i] = rnd_byte ();
-}
-
-
-/* performs a random overwrite. */
-static void
-overwrite_random (int npasses, wipe_context_s * ctx) 
-{  	
-    int i;
-    
-    for (i = 0; i < npasses; i++) {
-	randomize_buffer (ctx->buffer, ctx->buffsize);
-	overwrite (ctx);
-    }
-}
-
-
-/* perform an overwrite with a specific byte (like 0x00). */
-static void 
-overwrite_byte (int byte, wipe_context_s * ctx) 
-{
-    memset (ctx->buffer, byte, ctx->buffsize);
-    overwrite (ctx);
-}
-
-
-/* perform an overwrite with a specific byte triple (like 0x00, 0xFF, 0xAA). */
-static void
-overwrite_bytes (int byte1, int byte2, int byte3, wipe_context_s * ctx)
-{
-    DWORD i;
-
-    memset (ctx->buffer, byte1, ctx->buffsize);
-    for (i = 1; i < ctx->buffsize; i += 3) {
-	ctx->buffer[i] = byte2;
-	ctx->buffer[i+1] = byte3;
-    }
-    overwrite (ctx);
-}
-
-
-/* For the case the file is not a regular file (this is true for
-   devices or directories) this function tries to rename the file
-   to random pattern and then it will be delete (without random!). */
-extern "C" int 
-rename_unlink (const char *path)
-{
-    struct stat statbuf;
-    char *new_name = NULL, *p = NULL, c;  
-    int i = 0, rc = 0;
-    int is_dir = 0;
-
-    if (GetFileAttributes (path) & FILE_ATTRIBUTE_DIRECTORY)
-	is_dir = 1;
-    
-    new_name = new char[strlen (path)+15];
-    if (!new_name)
-	BUG (0);
-    
-    strcpy (new_name, path);
-    p = strrchr (new_name, '\\');
-    if (p != NULL) {
-	p++;
-	*p = '\0';
-    } 
-    else
-	p = new_name;
-    do {
-	while (i < 14) {
-	    c = random_char ();
-	    *p = c; 
-	    p++;
-	    i++;
-	}
-	*p = '\0';
-    } while (stat (new_name, &statbuf) == 0);
-    
-    if (rename (path, new_name) == -1) {
-	rc = WPTERR_FILE_READ;
-	goto leave;
-    }
-    if (is_dir && RemoveDirectory (new_name) == FALSE)
-	rc = WPTERR_FILE_REMOVE;
-    else if (!DeleteFile (new_name))
-	rc = WPTERR_FILE_REMOVE;
-    
-leave:
-    free_if_alloc (new_name);
-    return rc;
-}
-
-
-/* return the filesize as an 64-bit integer. */
-static DDWORD
-GetFileSize64 (const char * path)
-{
-    FILE *fp = fopen (path, "r");
-    if (fp) {
-	struct _stati64 statbuf;
-	if (_fstati64 (fileno (fp), &statbuf) == -1)
-	    return (DDWORD)-1;
-	fclose (fp);
-	return statbuf.st_size;
-    }
-    return (DDWORD)-1;
-}
-
-
-static int
-_secure_unlink (const char *path, const int mode, 
-		const int passes, HANDLE *r_fd)
-{
-    wipe_context_s ctx;
-    LONG size_high = 0;
-    
-    if (GetFileAttributes (path) & FILE_ATTRIBUTE_DIRECTORY)
-	return rename_unlink (path);
-    
-    memset (&ctx, 0, sizeof (ctx));
-    ctx.name = path;
-    ctx.buffsize = 16384;
-    ctx.buffer = new BYTE[ctx.buffsize];
-    if (!ctx.buffer)
-	BUG (NULL);
-    
-    ctx.filesize = GetFileSize64 (path);
-    if (!ctx.filesize) {
-	free_if_alloc (ctx.buffer);
-	remove (path);
-	return 0;
-    }
-
-    ctx.fd = CreateFile (path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
-			 OPEN_ALWAYS, 0, NULL);
-    if (ctx.fd == INVALID_HANDLE_VALUE) {
-	free_if_alloc (ctx.buffer);
-	return WPTERR_FILE_CREAT;
-    }
-    else if (r_fd)
-	*r_fd = ctx.fd;
-    
-    if (unlink_cb)
-	unlink_cb (unlink_cb_value, ctx.name, 0, 0, 0);
-
-    switch (mode) {
-    case WIPE_MODE_PASSES:
-	ctx.n_passes = passes;
-	overwrite_random (passes, &ctx);
-	break;
-
-    case WIPE_MODE_FAST:
-	ctx.n_passes = 1;
-	overwrite_random (1, &ctx);
-	break;
-
-    case WIPE_MODE_SIMPLE:
-	ctx.n_passes = 2;
-	overwrite_random (2, &ctx);
-	break;
-        
-    case WIPE_MODE_DOD:
-	ctx.n_passes = 5;
-	overwrite_random (1, &ctx);
-	overwrite_byte ((~1) & 0xFF, &ctx);
-	overwrite_random (1, &ctx);
-	overwrite_byte ((~4) & 0xFF, &ctx);
-	overwrite_random (1, &ctx);
-	break;
-        
-    case WIPE_MODE_GUTMANN:
-	ctx.n_passes = 39;
-	overwrite_random (4, &ctx);
-	overwrite_byte( 0x55, &ctx );
-	overwrite_byte ( 0xAA, &ctx );
-	overwrite_bytes( 0x92, 0x49, 0x24, &ctx );
-	overwrite_bytes( 0x49, 0x24, 0x92, &ctx );
-	overwrite_bytes( 0x24, 0x92, 0x49, &ctx );
-	overwrite_byte( 0x00, &ctx );
-	overwrite_byte( 0x11, &ctx );
-	overwrite_byte( 0x22, &ctx );
-	overwrite_byte( 0x33, &ctx );
-	overwrite_byte( 0x44, &ctx );
-	overwrite_byte( 0x55, &ctx );
-	overwrite_byte( 0x66, &ctx );
-	overwrite_byte( 0x77, &ctx );
-	overwrite_byte( 0x88, &ctx );
-	overwrite_byte( 0x99, &ctx );
-	overwrite_byte( 0xAA, &ctx );
-	overwrite_byte( 0xBB, &ctx );
-	overwrite_byte( 0xCC, &ctx );
-	overwrite_byte( 0xDD, &ctx );
-	overwrite_byte( 0xEE, &ctx );
-	overwrite_byte( 0xFF, &ctx );
-	overwrite_bytes( 0x92, 0x49, 0x24, &ctx );
-	overwrite_bytes( 0x49, 0x24, 0x92, &ctx );
-	overwrite_bytes( 0x24, 0x92, 0x49, &ctx );
-	overwrite_bytes( 0x6D, 0xB6, 0xDB, &ctx );
-	overwrite_bytes( 0xB6, 0xDB, 0x6D, &ctx );
-	overwrite_bytes( 0xDB, 0x6D, 0xB6, &ctx );
-	overwrite_random( 4, &ctx );
-	break;
-    }
-        
-    /* Set file length to zero so allocated clusters cannot be trailed */	
-    SetFilePointer (ctx.fd, 0, &size_high, FILE_BEGIN);
-    SetEndOfFile (ctx.fd);
-    CloseHandle (ctx.fd);
-    
-    wipememory (ctx.buffer, ctx.buffsize); /* burn the last evidence */	
-    free_if_alloc (ctx.buffer);
-
-    return rename_unlink (path);
-}
-
-
-/* Try to delete a file in a secure way with the given mode @mode. */
-extern "C" int 
-secure_unlink (const char *path, const int mode, const int passes)
-{
-    /* If the file has one of the following attributes, the
-       chance the file really gets overwritten is very low so
-       we just to an unlink to spare time and entropy. */
-    DWORD attr = GetFileAttributes (path);
-    if ((attr & FILE_ATTRIBUTE_COMPRESSED) ||
-	(attr & FILE_ATTRIBUTE_ENCRYPTED) ||
-	(attr & FILE_ATTRIBUTE_SPARSE_FILE))
-	return DeleteFile (path); /* XXX */
-    return _secure_unlink (path, mode, passes, NULL);
-}
-
-
-/* Set the callback @cb for the wipe function. The callback is call every time
-   the wipe function writes data to the file. */
-extern "C" void
-secure_unlink_set_cb (void (*cb)(void *, const char *, int, int, int), 
-		      void *cb_value)
-{
-    unlink_cb = cb;
-    unlink_cb_value = cb_value;
-}
-
-
-/* wipe all free space of the given drive by creating a temp file
-   which has the size of the free space. This file will be then
-   overwritten with random and static pattern. */
-extern "C" int
-wipe_freespace (const char *drive, HANDLE *r_fd,
-	        void (*cb)(void *, DDWORD, DDWORD), void * cb_value)
-{
-    ULARGE_INTEGER caller, total, frees;
-    LONG hpart=0;
-    HANDLE fd;
-    const char *fmt;
-    char *file;
-    int disktyp = GetDriveType (drive);
-    int rc;
-
-    /* XXX: needs to be modernized or better extracted to a separate
-	    program module. */
-    if (disktyp != DRIVE_FIXED && disktyp != DRIVE_REMOVABLE)
-	return -1;
-    if (!GetDiskFreeSpaceEx (drive, &caller, &total, &frees))
-	return -1;   
-
-    /* disk is full */
-    if (!frees.LowPart)
-	return 0;
-    fmt = "%stemp_winpt.tmp";
-    file = new char[strlen (drive)+strlen (fmt)+8+1];
-    if (!file)
-	BUG (0);
-    sprintf (file, fmt, drive);
-    fd = CreateFile (file,
-		     GENERIC_READ|GENERIC_WRITE,
-		     FILE_SHARE_READ|FILE_SHARE_WRITE,
-		     NULL, CREATE_ALWAYS, 0, NULL);
-    if (fd == INVALID_HANDLE_VALUE) {
-	free_if_alloc (file);
-	return WPTERR_FILE_CREAT;
-    }
-    hpart = frees.HighPart;
-    SetFilePointer (fd, frees.LowPart, &hpart, FILE_BEGIN);
-    SetEndOfFile (fd);
-    CloseHandle (fd);
-
-    if (cb && cb_value) {
-	progress_cb = cb;
-	progress_cb_value = cb_value;
-    }
-    rc = _secure_unlink (file, WIPE_MODE_PASSES, 2, r_fd);
-    free_if_alloc (file);
-    return rc;
-}

Deleted: trunk/PTD/wptZIP.cpp
===================================================================
--- trunk/PTD/wptZIP.cpp	2009-09-25 15:47:52 UTC (rev 324)
+++ trunk/PTD/wptZIP.cpp	2009-09-25 15:51:28 UTC (rev 325)
@@ -1,854 +0,0 @@
-/* wptZIP.cpp
- *        Copyright (C) 2002-2007 Timo Schulz
- *
- * This file is part of WinPT.
- *
- * WinPT 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.
- *
- * WinPT 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.
- */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <windows.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <direct.h>
-#include <time.h>
-
-#include "wptZIP.h"
-
-/*static int debug = 0;*/
-
-enum zip_sig_t {
-    PK_SIG_LOCAL = 0x04034b50,
-    PK_SIG_FILE  = 0x02014b50,
-    PK_SIG_END   = 0x06054b50
-};
-
-enum zip_flag_t {
-    PK_FLAG_ENCRYPTED = 1,	/* archive is encrypted. */
-    PK_FLAG_8KDICT    = 2,	/* used 8k dictionary */
-    PK_FLAG_SF        = 4
-};
-
-
-typedef struct {
-    unsigned long   magic;
-    unsigned short  ver;
-    unsigned short  flags;
-    unsigned short  method;
-    unsigned short  ftime;
-    unsigned short  fdate;
-    unsigned long   crc;
-    unsigned long   c_size;
-    unsigned long   u_size;
-    unsigned short  f_len;
-    unsigned short  extra_len;
-    char 	    *name;
-    FILE 	    *fp;
-} PK_local_hdr;
-
-typedef struct {
-    unsigned long   magic;
-    unsigned short  ver_made;
-    unsigned short  ver_ext;
-    unsigned short  flags;
-    unsigned short  method;
-    unsigned short  ftime;
-    unsigned short  fdate;
-    unsigned long   crc;
-    unsigned long   c_size;
-    unsigned long   u_size;
-    unsigned short  f_len;
-    unsigned short  extra_len;
-    unsigned short  comment_len;
-    unsigned short  disc_nr;
-    unsigned short  int_attr;
-    unsigned long   ext_attr;
-    unsigned long   lochdr_off;
-    char 	    *name;
-    size_t	    size;
-} PK_file_hdr;
-
-
-typedef struct {
-    unsigned long   magic;
-    unsigned short  disc_nr;
-    unsigned short  disc_nr_cd;
-    unsigned short  total_dirs_disc;
-    unsigned short  total_dirs;
-    unsigned long   size_of_dir;
-    unsigned long   off_dir;
-    unsigned short  comment_len;
-    char 	    *comment;
-} PK_end_hdr;
-
-
-typedef struct {
-    union {
-        PK_local_hdr *local;
-        PK_file_hdr  *file;
-        PK_end_hdr   *end;
-    } u;
-    unsigned long pkttype;
-} PK_packet;
-
-
-struct PK_file_list {
-    struct PK_file_list *next;
-    PK_local_hdr 	*hdr;
-    size_t		off;
-    size_t		len;
-    char		*d;
-};
-
-
-static unsigned long crc_table[256] = {
-    0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
-    0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
-    0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
-    0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
-    0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
-    0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
-    0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
-    0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
-    0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
-    0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
-    0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
-    0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
-    0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
-    0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
-    0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
-    0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
-    0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
-    0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
-    0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
-    0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
-    0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
-    0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
-    0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
-    0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
-    0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
-    0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
-    0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
-    0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
-    0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
-    0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
-    0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
-    0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
-    0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
-    0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
-    0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
-    0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
-    0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
-    0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
-    0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
-    0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
-    0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
-    0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
-    0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
-    0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
-    0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
-    0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
-    0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
-    0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
-    0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
-    0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
-    0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
-    0x2d02ef8dL
-};
-
-
-/* Update the crc in @crc with the buffer @buf and the length @buflen. */
-static unsigned long
-update_crc (unsigned long crc, unsigned char *buf, size_t buflen)
-{
-    crc ^= 0xffffffffL;
-    while (buflen--)
-        crc = crc_table[((int)(crc) ^ (*buf++)) & 0xff] ^ ((crc) >> 8);
-    crc ^= 0xffffffffL;
-    return crc;
-}
-
-        
-static unsigned short
-read_16 (FILE *in)
-{
-    unsigned short u;
-    
-    u  = fgetc (in)     ;
-    u |= fgetc (in) << 8;
-    return u;
-}
-
-
-static void
-write_16 (FILE *out, unsigned short a)
-{
-    fputc (a     , out);
-    fputc (a >> 8, out);
-}
-
-
-static unsigned long
-read_32 (FILE *in)
-{
-    unsigned long u;
-    u  = fgetc (in)      ;
-    u |= fgetc (in) <<  8;
-    u |= fgetc (in) << 16;
-    u |= fgetc (in) << 24;
-    return u;
-}
-
-
-static void
-write_32 (FILE * out, unsigned long a)
-{
-    fputc (a      , out);
-    fputc (a >> 8 , out);
-    fputc (a >> 16, out);
-    fputc (a >> 24, out);
-}
-
-
-static unsigned short
-date_to_dos (time_t t)
-{
-    struct tm *tm;
-    
-    tm = localtime (&t);
-    return tm->tm_mday | (tm->tm_mon+1)<<5 | ((tm->tm_year-80)<<9);
-}
-
-
-static unsigned short
-time_to_dos (time_t t)
-{
-    struct tm * tm;
-    tm = localtime (&t);
-    return (tm->tm_hour<<11) | (tm->tm_min<<5) | (tm->tm_sec>>1);
-}
-
-
-static char*
-xstrdup (const char * s)
-{
-    char *p = new char[strlen (s)+1];
-    if (!p)
-	abort ();
-    strcpy (p, s);
-    return p;
-}
-
-
-static PK_local_hdr*
-create_local_header (const char *name, FILE *fp)
-{
-    struct stat statbuf;
-    PK_local_hdr *a;
-
-    if (fstat (fileno (fp), &statbuf))
-        return NULL;
-    a = new PK_local_hdr;
-    if (!a)
-        return NULL;
-    memset (a, 0, sizeof *a);
-    a->magic = PK_SIG_LOCAL;
-    a->ver = 0 | (10 << 8);
-    a->flags = 0;
-    a->method = 0;
-    a->fdate = date_to_dos (statbuf.st_mtime);
-    a->ftime = time_to_dos (statbuf.st_mtime);
-    a->crc = 0;
-    a->c_size = statbuf.st_size;
-    a->u_size = statbuf.st_size;
-    a->f_len = strlen (name);
-    a->name = xstrdup (name);
-    a->extra_len = 0;
-    a->fp = fp;
-    return a;
-}
-
-
-static int
-write_local_header (FILE *out, PK_local_hdr *hdr)
-{
-    long crc_pos, curr_pos;
-    
-    write_32 (out, hdr->magic);
-    write_16 (out, hdr->ver);
-    write_16 (out, hdr->flags);
-    write_16 (out, hdr->method);
-    write_16 (out, hdr->ftime);
-    write_16 (out, hdr->fdate);
-    crc_pos = ftell (out);
-    write_32 (out, hdr->crc);
-    write_32 (out, hdr->c_size);
-    write_32 (out, hdr->u_size);
-    write_16 (out, hdr->f_len);
-    write_16 (out, hdr->extra_len);
-    if (hdr->f_len > 0)
-        fwrite (hdr->name, 1, hdr->f_len, out);
-    if (hdr->extra_len)
-        fwrite (NULL, 1, hdr->extra_len, out); /* xxx */
-    while (!feof (hdr->fp)) {
-        unsigned char buf[2048];
-        unsigned long nread;
-        nread = fread (buf, 1, sizeof buf-1, hdr->fp);
-        if (nread > 0) {
-	    /*fprintf (stderr, "** nread=%d\n", nread);*/
-            hdr->crc = update_crc (hdr->crc, buf, nread);
-            fwrite (buf, 1, nread, out);
-        }
-    }
-    curr_pos = ftell (out);
-    fseek (out, crc_pos, SEEK_SET);
-    write_32 (out, hdr->crc);
-    fseek (out, curr_pos, SEEK_SET);
-    return 0;
-}
-
-
-static int
-create_missing_dirs (const char *name)
-{
-    struct stat dirbuf;
-    char *p, *dir;
-    int rc;
-    
-    p = strrchr (name, '/');
-    if (!p)
-        return PKERR_GENERAL;
-    dir = new char[(p-name)+1];
-    if (!dir)
-	abort ();
-    memset (dir, 0, (p-name)+1);
-    strncpy (dir, name, (p-name));
-    if (!stat (dir, &dirbuf) && (dirbuf.st_mode & _S_IFDIR))
-	rc = 0;
-    else
-	rc = mkdir (dir);
-    delete []dir;
-    return rc;
-}
-
-
-static PK_local_hdr*
-read_local_header (FILE *in, unsigned long magic, int create)
-{
-    PK_local_hdr *hdr;
-    FILE *out = NULL;
-    size_t n;
-
-    if (magic != PK_SIG_LOCAL)
-        return NULL;
-    hdr = new PK_local_hdr;
-    if (!hdr)
-	return NULL;
-    memset (hdr, 0, sizeof * hdr);
-    hdr->magic = magic;
-    hdr->ver = read_16 (in);
-    hdr->flags = read_16 (in);
-    hdr->method = read_16 (in);
-    hdr->ftime = read_16 (in);
-    hdr->fdate = read_16 (in);
-    hdr->crc = read_32 (in);
-    hdr->c_size = read_32 (in);
-    hdr->u_size = read_32 (in);
-    hdr->f_len = read_16 (in);
-    hdr->extra_len = read_16 (in);
-
-    /*if( debug ) {
-        printf("=====BEGIN LOCAL HEADER=====\n");
-        printf( "magic %08lX version=%d\n", hdr->magic, hdr->ver );
-        printf( "flags encrypted=%d 8k dict=%d shannon=%d\n",
-                hdr->flags & PK_FLAG_ENCRYPTED, hdr->flags & PK_FLAG_8KDICT,
-                hdr->flags & PK_FLAG_SF );
-        printf( "method=" );
-        switch( hdr->method ) {
-        case 0: printf( "stored\n" ); break;
-        default: printf( "unknown (%d)\n", hdr->method );
-        }
-        printf( "filetime=%d %d\n", hdr->ftime, hdr->fdate );
-        printf( "CRC=%08lX\n", hdr->crc );
-        printf( "size: compressed=%lu uncompressed=%lu\n",
-                hdr->c_size, hdr->u_size );
-        printf( "filename len=%d extra_len=%d\n", hdr->f_len, hdr->extra_len );
-    }*/
-
-    if (hdr->f_len) {
-        hdr->name = new char[hdr->f_len+1];
-	if (!hdr->name)
-	    abort ();
-	memset (hdr->name, 0, hdr->f_len+1);
-        fread (hdr->name, 1, hdr->f_len, in);
-        /*if (debug)
-            printf ("filename %s\n", hdr->name);*/
-    }
-    /*if (debug)
-        printf ("skip extra header (%d)\n", hdr->extra_len);*/
-    n = hdr->extra_len;
-    while (n-- > 0)
-        fgetc (in);
-    /*if (debug)
-        printf ("skip compressed data (%lu)\n", hdr->c_size);*/
-    if (create && hdr->name) {
-        create_missing_dirs (hdr->name);
-        out = fopen (hdr->name, "wb");
-        /*if (debug)
-            printf( "create output `%s' (status %s)\n", hdr->name,
-                    out? "success" : "failed" );*/
-    }
-    n = hdr->c_size;
-    while (n--) {
-        int c = fgetc (in);
-        if (out)
-            fputc (c, out);
-    }
-    if (out)
-        fclose (out);
-    return hdr;
-}
-
-
-static PK_file_hdr*
-create_file_header (PK_local_hdr * loc, long loc_off)
-{
-    PK_file_hdr * a;
-    
-    a = new PK_file_hdr;
-    if (!a)
-        abort ();
-    memset (a, 0, sizeof *a);
-    a->magic = PK_SIG_FILE;
-    a->ver_made = loc->ver;
-    a->ver_ext = loc->ver;
-    a->flags = loc->flags;
-    a->method = loc->method;
-    a->ftime = loc->ftime;
-    a->fdate = loc->fdate;
-    a->crc = loc->crc;
-    a->c_size = loc->c_size;
-    a->u_size = loc->u_size;
-    a->f_len = loc->f_len;
-    a->extra_len = loc->extra_len;
-    a->comment_len = 0;
-    a->disc_nr = 0;
-    a->int_attr = 0;
-    a->ext_attr = 0;
-    a->lochdr_off = loc_off;
-    a->size = 46 + a->f_len;
-    a->name = xstrdup (loc->name);
-    return a;
-}
-
-
-static int
-write_file_header (FILE *out, PK_file_hdr *hdr)
-{
-    write_32 (out, hdr->magic);
-    write_16 (out, hdr->ver_made);
-    write_16 (out, hdr->ver_ext);
-    write_16 (out, hdr->flags);
-    write_16 (out, hdr->method);
-    write_16 (out, hdr->ftime);
-    write_16 (out, hdr->fdate);
-    write_32 (out, hdr->crc);
-    write_32 (out, hdr->c_size);
-    write_32 (out, hdr->u_size);
-    write_16 (out, hdr->f_len);
-    write_16 (out, hdr->extra_len);
-    write_16 (out, hdr->comment_len);
-    write_16 (out, hdr->disc_nr);
-    write_16 (out, hdr->int_attr);
-    write_32 (out, hdr->ext_attr);
-    write_32 (out, hdr->lochdr_off);
-    if (hdr->f_len > 0)
-        fwrite (hdr->name, 1, hdr->f_len, out);
-    if (hdr->extra_len > 0)
-        fwrite (NULL, 1, hdr->extra_len, out); /* xxx */
-    if (hdr->comment_len > 0)
-        fwrite (NULL, 1, hdr->comment_len, out); /* xxx */
-    return 0;
-}
-    
-
-static PK_file_hdr*
-read_file_header (FILE * in, unsigned long magic)
-{
-    PK_file_hdr * hdr;
-    size_t n;
-
-    if (magic != PK_SIG_FILE)
-        return NULL;
-    hdr = new PK_file_hdr;
-    if (!hdr)
-	return NULL;
-    memset (hdr, 0, sizeof * hdr);
-    hdr->magic = magic;
-    hdr->ver_made = read_16( in );
-    hdr->ver_ext = read_16( in );
-    hdr->flags = read_16( in );
-    hdr->method = read_16( in );
-    hdr->ftime = read_16( in );
-    hdr->fdate = read_16( in );
-    hdr->crc = read_32( in );
-    hdr->c_size = read_32( in );
-    hdr->u_size = read_32( in );
-    hdr->f_len = read_16( in );
-    hdr->extra_len = read_16( in );
-    hdr->comment_len = read_16( in );
-    hdr->disc_nr = read_16( in );
-    hdr->int_attr = read_16( in );
-    hdr->ext_attr = read_32( in );
-    hdr->lochdr_off = read_32( in );
-
-    /*if( debug ) {
-        printf("=====BEGIN FILE HEADER=====\n");
-        printf( "magic=%08lX\n", hdr->magic );
-        printf( "version made=%d needed=%d\n", hdr->ver_made, hdr->ver_ext );
-        printf( "flags encrypted=%d endheader=%d extended=%d\n",
-                hdr->flags & PK_FLAG_ENCRYPTED, hdr->flags & PK_FLAG_8KDICT,
-                hdr->flags & PK_FLAG_SF );
-        printf( "method=" );
-        switch( hdr->method ) {
-        case 0: printf( "stored\n" ); break;
-        default: printf( "unknown (%d)\n", hdr->method );   
-        }
-        printf( "filetime=%d %d\n", hdr->ftime, hdr->fdate );
-        printf( "CRC=%08lX\n", hdr->crc );
-        printf( "size compressed=%lu uncompressed=%lu\n",
-                hdr->c_size, hdr->u_size );
-        printf( "extra len=%d comment len=%d\n", hdr->extra_len,
-                hdr->comment_len );
-        printf( "disk nummer=%d\n", hdr->disc_nr );
-        printf( "attrs intern=%d extern=%lu\n", hdr->int_attr, hdr->ext_attr );
-        printf( "disk offset=%lu\n", hdr->lochdr_off );
-    }*/
-    
-    if (hdr->f_len > 0) {
-        hdr->name = new char[hdr->f_len + 1];
-	if (!hdr->name)
-	    abort ();
-	memset (hdr->name, 0, hdr->f_len+1);
-        fread (hdr->name, 1, hdr->f_len, in);
-        /*if( debug )
-            printf( "filename=%s\n", hdr->name );*/
-    }
-    n = hdr->extra_len;
-    while (n--)
-        fgetc (in);
-    n = hdr->comment_len;
-    while (n--)
-        fgetc (in);
-    return hdr;
-}
-
-
-static PK_end_hdr*
-create_end_header (size_t ntotal, size_t nsize, long off_dir)
-{
-    PK_end_hdr *a;
-
-    a = new PK_end_hdr;
-    if (!a)
-        abort ();
-    memset (a, 0, sizeof * a);
-    a->magic = PK_SIG_END;
-    a->disc_nr = 0;
-    a->disc_nr_cd = 0;
-    a->total_dirs = ntotal;
-    a->total_dirs_disc = ntotal;
-    a->size_of_dir = nsize;
-    a->off_dir = off_dir;
-    a->comment_len = 0;
-    return a;
-}
-
-
-static int
-write_end_header (FILE *out, PK_end_hdr *hdr)
-{
-    write_32 (out, hdr->magic);
-    write_16 (out, hdr->disc_nr);
-    write_16 (out, hdr->disc_nr_cd);
-    write_16 (out, hdr->total_dirs);
-    write_16 (out, hdr->total_dirs_disc);
-    write_32 (out, hdr->size_of_dir);
-    write_32 (out, hdr->off_dir);
-    write_16 (out, hdr->comment_len);
-    if (hdr->comment_len > 0)
-        fwrite (hdr->comment, 1, hdr->comment_len, out);
-    return 0;
-}
-
-
-static PK_end_hdr*
-read_end_header (FILE * in, unsigned long magic)
-{
-    PK_end_hdr * hdr;
-
-    if( magic != PK_SIG_END )
-        return NULL;
-    hdr = new PK_end_hdr;
-    if( !hdr )
-	abort ();
-    memset (hdr, 0, sizeof *hdr);
-    hdr->magic = magic;
-    hdr->disc_nr = read_16( in );
-    hdr->disc_nr_cd = read_16( in );
-    hdr->total_dirs = read_16( in );
-    hdr->total_dirs_disc = read_16( in );
-    hdr->size_of_dir = read_32( in );
-    hdr->off_dir = read_32( in );
-    hdr->comment_len = read_16( in );
-
-    /*if( debug ) {
-        printf("=====BEGIN END HEADER=====\n");
-        printf( "magic=%08lX\n", hdr->magic );
-        printf( "disc number=%d in this directory=%d\n", hdr->disc_nr,
-                hdr->disc_nr_cd );
-        printf( "total number of disc=%d in this directory=%d\n",
-                hdr->total_dirs, hdr->total_dirs_disc );
-        printf( "offset of central directory=%lu\n", hdr->off_dir );
-        printf( "size of directory=%lu\n", hdr->size_of_dir );
-    }*/
-    
-    if (hdr->comment_len > 0) {
-	hdr->comment = new char[hdr->comment_len+1];       
-	if( !hdr->comment )
-	    abort ();
-	memset (hdr->comment, 0, hdr->comment_len+1);
-        fread( hdr->comment, 1, hdr->comment_len, in );
-        /*if( debug )
-            printf( "comment(%d)=%s\n", hdr->comment_len, hdr->comment );*/
-    }
-    return hdr;
-}
-
-
-static void
-free_packet (PK_packet *pkt)
-{
-    switch( pkt->pkttype ) {
-    case PK_SIG_LOCAL:
-        if (pkt->u.local->name)
-            delete []pkt->u.local->name;
-        delete pkt->u.local;
-        break;
-    case PK_SIG_FILE:
-        if (pkt->u.file->name)
-            delete[] pkt->u.file->name;
-        delete pkt->u.file;
-        break;
-    case PK_SIG_END:
-        if (pkt->u.end->comment)
-            delete [] pkt->u.end->comment;
-        delete pkt->u.end;
-        break;
-    }
-    pkt->pkttype = 0;
-}
-
-
-int
-pk_archiv_parse (FILE *in)
-{
-    unsigned long magic;
-    PK_packet pkt;
-    
-    while( !feof( in ) ) {
-        magic = read_32( in );
-        if( feof( in ) )
-            break;
-        /*printf("\n** read magic value %08lX\n\n", magic );*/
-        switch( magic ) {
-        case PK_SIG_LOCAL:
-            pkt.u.local = read_local_header( in, magic, 1 );
-            pkt.pkttype = PK_SIG_LOCAL;
-            break;
-            
-        case PK_SIG_FILE:
-            pkt.u.file = read_file_header( in, magic );
-            pkt.pkttype = PK_SIG_FILE;
-            break;
-            
-        case PK_SIG_END:
-            pkt.u.end = read_end_header( in, magic );
-            pkt.pkttype = PK_SIG_END;
-            break;
-            
-        default:
-            /*printf( "unknown magic value (%08lX).\n", magic );*/
-            if( ftell( in ) == 4 ) {
-                free_packet( &pkt );
-                return PKERR_INV_FILE;
-            }
-            break;
-        }
-        free_packet( &pkt );
-    }
-    return 0;
-}
-
-
-static int
-is_directory (const char * fname)
-{
-    struct stat statbuf;
-    
-    if (stat (fname, &statbuf))
-	return 0;
-    return statbuf.st_mode & S_IFDIR;
-}
-
-
-int
-pk_archiv_create (struct PK_file_list *list, const char *output)
-{
-    struct PK_file_list *r;
-    PK_file_hdr *f;
-    PK_end_hdr *e;
-    PK_packet pkt;
-    FILE *fp, *out;
-    long foff = 0, n = 0;
-    size_t size = 0;
-
-    out = fopen (output, "wb");
-    if (!out)
-        return PKERR_FILE;
-    
-    for (r = list; r; r = r->next) {
-        fprintf (stderr, "process file `%s'\n", r->d);
-	if (is_directory (r->d))
-	    continue;
-        fp = fopen (r->d, "rb");
-        if (!fp) {
-	    fclose (out);
-            return PKERR_FILE;
-	}
-        r->off = ftell (out);
-        r->hdr = create_local_header( r->d, fp );
-        if (!r->hdr) {
-            fclose (fp);
-	    fclose (out);
-            return PKERR_GENERAL;
-        }
-        if (r->off)
-            r->off += r->hdr->c_size;
-        write_local_header (out, r->hdr);
-        n++;
-        fclose (fp);
-    }
-    foff = ftell( out );
-    for (r = list; r; r = r->next) {
-	if (is_directory (r->d))
-	    continue;
-        fp = fopen (r->d, "rb");
-        if (!fp) {
-	    fclose (out);
-            return PKERR_FILE;
-	}
-        f = create_file_header (r->hdr, r->off);
-        size += f->size;
-        write_file_header (out, f);
-        fclose (fp);
-        pkt.u.file = f;
-        free_packet (&pkt);
-    }
-    
-    e = create_end_header (n, size, foff);
-    write_end_header (out, e);
-    fclose (out);
-    return 0;
-}
-
-
-void
-pk_list_add (struct PK_file_list **list, const char *name)
-{
-    struct PK_file_list *l;
-
-    l = new PK_file_list;
-    if (!l)
-	abort ();
-    memset (l, 0, sizeof *l);	
-    l->next = *list;
-    l->d = xstrdup (name);
-    *list = l;
-}
-
-
-void
-pk_list_free (struct PK_file_list *list)
-{
-    struct PK_file_list * l;
-    PK_packet pkt;
-
-    while (list) {
-        l = list->next;
-	if (list->hdr != NULL) {
-	    pkt.pkttype = PK_SIG_LOCAL;
-	    pkt.u.local = list->hdr;
-	    free_packet (&pkt);
-	}
-	if (list->d != NULL)
-	    delete []list->d;
-        delete list;
-        list = l;
-    }
-}
-
-
-#ifdef TEST
-
-static void 
-test (const char *patt, const char *path, const char *out)
-{
-    PK_FILE_LIST list = NULL;
-    WIN32_FIND_DATA findbuf;
-    HANDLE hd;    
-    int rc = 0;
-    
-    hd = FindFirstFile (patt, &findbuf );    
-    if( !hd )
-	return;	
-
-    if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) {
-	char p[256];
-	_snprintf (p, sizeof (p)-1, "%s\\%s", path, findbuf.cFileName);
-	pk_list_add (&list, p);
-    }
-    while( FindNextFile( hd, &findbuf ) ) {
-	if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) {
-	    char p[256];
-	    _snprintf (p, sizeof (p)-1, "%s\\%s", path, findbuf.cFileName);
-	    pk_list_add (&list, p);
-	}
-    }
-
-    rc = pk_archiv_create (list, out);
-
-    pk_list_free (list);
-    FindClose (hd);
-}
-
-int
-main (int argc, char **argv)
-{
-    test ("c:\\gnupg\\*", "c:\\gnupg", "c:\\gnupg\\\\test\\sample.zip");
-    return 0;
-}
-#endif

Deleted: trunk/PTD/wptZIP.h
===================================================================
--- trunk/PTD/wptZIP.h	2009-09-25 15:47:52 UTC (rev 324)
+++ trunk/PTD/wptZIP.h	2009-09-25 15:51:28 UTC (rev 325)
@@ -1,44 +0,0 @@
-/* wptZIP.h - Interface for the ZIP file format
- *        Copyright (C) 2002, 2007 Timo Schulz
- *
- * This file is part of WinPT.
- *
- * WinPT 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.
- *
- * WinPT 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.
- */
-
-#ifndef WPT_ZIP_H
-#define WPT_ZIP_H
-
-enum zip_err_t {
-    PKERR_SUCCESS  =  0,
-    PKERR_INV_FILE = -1,
-    PKERR_FILE     = -2,
-    PKERR_GENERAL  = -3
-};
-
-
-struct PK_file_list;
-typedef struct PK_file_list *PK_FILE_LIST;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int pk_archiv_parse (FILE *in);
-int pk_archiv_create (PK_FILE_LIST list, const char *output);
-void pk_list_add (PK_FILE_LIST *list, const char *name);
-void pk_list_free (PK_FILE_LIST ist);
-
-#ifdef __cplusplus
-}
-#endif
-    
-#endif /*WPT_ZIP_H*/



More information about the Winpt-commits mailing list