📄 pgpsdadecode.c
字号:
/*__________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: pgpSDAdecode.c,v 1.11 2002/08/06 20:10:16 dallen Exp $
__________________________________________________________________________*/
#if PGP_WIN32
#include <windows.h>
#include <direct.h>
#elif PGP_UNIX
#include <unistd.h>
#endif
#include "pgpTypes.h"
#include "pgpSDACreate.h"
#if PGP_UNIX
#define MAX_PATH PATH_MAX
#endif
void
DecryptBlock512(
SDAHEADER *SDAHeader,
PGPUInt32 *ExpandedKey,
PGPUInt32 blockNumber,
const PGPUInt32 * src,
PGPUInt32 * dest);
typedef struct
{
FILE *fin;
FILE *fout;
SDAHEADER *SDAHeader;
PGPUInt32 *ExpandedKey;
PGPUInt32 blockindex;
PGPUInt32 from_pointer;
#ifdef NO_64INT
PGPUInt32 from_max;
#else /* !NO_64INT */
PGPUInt64 from_max;
#endif /* NO_64INT */
unsigned char *outbuffer;
unsigned char *inbuffer;
PGPError err;
PGPBoolean bHaveFileName;
#ifdef NO_64INT
PGPUInt32 NumFiles;
#else /* !NO_64INT */
PGPUInt64 NumFiles;
#endif /* NO_64INT */
PGPBoolean bFeedFilename;
char FileName[MAX_PATH+1];
#ifdef NO_64INT
PGPUInt32 FileSize;
PGPUInt32 FileIndex;
PGPUInt32 FeedIndex;
#else /* NO_64INT */
PGPUInt64 FileSize;
PGPUInt64 FileIndex;
PGPUInt64 FeedIndex;
#endif /* NO_64INT */
char *szPrefixPath;
FILELIST *fl;
SDACREATECALLBACK UserProc;
void *pUserValue;
} GETPUTINFO;
PGPUInt32 FileListFromFile(FILELIST **filelist,char *filename,PGPBoolean *UserCancel)
{
FILELIST *Current;
if(UserCancel!=NULL)
{
if(*UserCancel)
{
return FALSE;
}
}
Current=(FILELIST *)malloc(sizeof(FILELIST));
memset(Current,0x00,sizeof(FILELIST));
Current->name=(char *)malloc(strlen(filename)+1);
strcpy(Current->name,filename);
Current->next=*filelist;
*filelist=Current;
return TRUE;
}
void RemoveFiles(FILELIST *fl)
{
FILELIST *freeatlast;
int retval;
// Remove the files the SEA extracted
while(fl!=NULL)
{
freeatlast=fl;
fl=fl->next;
// Erase SEA files
if(freeatlast->IsDirectory)
{
#if PGP_WIN32
retval=_rmdir(freeatlast->name);
#else
retval = rmdir(freeatlast->name);
#endif
}
else
{
#if PGP_WIN32
retval = _unlink(freeatlast->name);
#else
retval = unlink(freeatlast->name);
#endif
}
memset(freeatlast->name,0x00,strlen(freeatlast->name));
free(freeatlast->name);
free(freeatlast);
}
}
int decomp_getc_buffer(void *pUserValue)
{
GETPUTINFO *gpi;
SDAEvent Event;
PGPError err;
gpi=(GETPUTINFO *)pUserValue;
if(IsPGPError(gpi->err))
return EOF;
if((gpi->from_pointer==kBlockSize)||
(gpi->blockindex==0))
{
if(gpi->blockindex%10==0)
{
Event.type=kSDAEvent_ProgressEvent;
Event.data.progressData.bytesWritten=gpi->blockindex*kBlockSize;
Event.data.progressData.bytesTotal=gpi->from_max;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
if(IsPGPError(err))
{
gpi->err=err;
// Trick the encryptor engine here. We'll delete
// the file later
return EOF;
}
}
memset(gpi->inbuffer,0x00,kBlockSize);
fread(gpi->inbuffer,1,kBlockSize,gpi->fin);
#ifndef IS_SEA
DecryptBlock512(gpi->SDAHeader,
gpi->ExpandedKey,
gpi->blockindex,
(const PGPUInt32 *)gpi->inbuffer,
(PGPUInt32 *)gpi->outbuffer);
#else
memcpy(gpi->outbuffer,gpi->inbuffer,kBlockSize);
#endif // IS_SEA
gpi->blockindex++;
gpi->from_pointer=0;
}
if((gpi->blockindex-1)*kBlockSize+
gpi->from_pointer==gpi->from_max)
{
return EOF;
}
return(gpi->outbuffer[gpi->from_pointer++]);
}
#if E_BUSINESS_SERVER || PGPREADER
#include <errno.h>
static
int sCreateDir(char *pszBase, char *pszDir)
{
#ifdef WIN32
char seps[] = "\\";
#else /* WIN32 */
char seps[] = "/";
#endif /* WIN32 */
char szDir[256] = {'\0'};
char *pszToken = strtok(pszDir, seps);
char szBase[256] = {'\0'};
int i = 0;
strcpy(szBase, pszBase);
if(szBase[strlen(pszBase) -1] == seps[0])
szBase[strlen(pszBase) - 1] = '\0';
strcpy(szDir, szBase);
while(pszToken != NULL)
{
strcat(szDir, seps);
strcat(szDir, pszToken);
#ifdef WIN32
i = mkdir(szDir);
#else /* !WIN32 */
i = mkdir(szDir, 0700);
#endif /* WIN32 */
if(i != 0 && (errno != EEXIST && errno != EACCES))
{
return -1;
}
pszToken = strtok(NULL, seps);
}
return 1;
}
#endif /* E_BUSINESS_SERVER || PGPREADER*/
// putc_buffer handles the output from the compression
// engine
int decomp_putc_buffer(int c,void *pUserValue)
{
GETPUTINFO *gpi;
SDAEvent Event;
PGPError err;
#ifdef WORDS_BIGENDIAN
#ifndef NO_64INT
PGPUInt64 temp64 = 0;
#else /* !NO_64INT */
PGPUInt32 temp32 = 0;
#endif /* NO_64INT */
#endif /* WORDS_BIGENDIAN */
#if E_BUSINESS_SERVER || PGPREADER
#ifdef WIN32
char szDirSeps[] = "\\";
#else /* !WIN32 */
char szDirSeps[] = "/";
#endif /* WIN32 */
#endif /* E_BUSINESS_SERVER || PGPREADER */
gpi=(GETPUTINFO *)pUserValue;
if(IsPGPError(gpi->err))
return 1;
if(gpi->bFeedFilename)
{
// Grab New File
// Feed in the File Size
#ifdef NO_64INT
if(gpi->FeedIndex<sizeof(PGPUInt32))
#else /* !NO_64INT */
if(gpi->FeedIndex<sizeof(PGPUInt64))
#endif /* NO_64INT */
{
((char *)&(gpi->FileSize))[gpi->FeedIndex]=
(unsigned char)c;
gpi->FeedIndex++;
return 1;
}
#ifdef NO_64INT
/* Skip over second 32 bit int as it isn't used for anything. */
else if((gpi->FeedIndex >= sizeof(PGPUInt32)) &&
(gpi->FeedIndex < (sizeof(PGPUInt32)*2)))
{
gpi->FeedIndex++;
return 1;
}
#endif /* NO_64INT */
#ifdef WORDS_BIGENDIAN
/* Convert file size back to big endian */
#ifdef NO_64INT
if(gpi->FeedIndex == (sizeof(PGPUInt32)*2))
{
pgpUInt32LittleToBigEndian(gpi->FileSize, &temp32);
gpi->FileSize = temp32;
}
#else /* !NO_64INT */
if(gpi->FeedIndex == sizeof(PGPUInt64))
{
pgpUInt64LittleToBigEndian(gpi->FileSize, &temp64);
gpi->FileSize = temp64;
}
#endif /* NO_64INT */
#endif /* WORDS_BIGENDIAN */
// Feed in the File Name
#ifdef PGP_UNIX
if(c == '\\')
c = '/';
#endif /* PGP_UNIX */
#ifdef NO_64INT
gpi->FileName[gpi->FeedIndex-(sizeof(PGPUInt32)*2)]=
#else /* !NO_64INT */
gpi->FileName[gpi->FeedIndex-sizeof(PGPUInt64)]=
#endif /* NO_64INT */
(unsigned char) c;
gpi->FeedIndex++;
// We have the complete file name
if(c==0)
{
// Check that filename does not exceed MAXPATH
if((strlen(gpi->szPrefixPath)+strlen(gpi->FileName))>=MAX_PATH)
{
gpi->err=kPGPError_BufferTooSmall;
Event.type=kSDAEvent_ErrorEvent;
Event.data.errorData.fileName=gpi->FileName;
Event.data.errorData.err=gpi->err;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
return 1;
}
// Create directory and get next file
if(gpi->FileSize==PGPSDA_SIZEDIRECTORY)
{
char dirname[MAX_PATH];
strcpy(dirname,gpi->szPrefixPath);
strcat(dirname,gpi->FileName);
Event.type=kSDAEvent_NewFileEvent;
Event.data.newfileData.fileName=dirname;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
if(IsPGPError(err))
{
gpi->err=err;
// Trick the encryptor engine here. We'll delete
// the file later
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -