BOOL FCopy (char *src, char *dst) { HANDLE srcfh, dstfh; BOOL result; ATTRIBUTE_TYPE Attributes; unsigned filedate, filetime; GET_ATTRIBUTES(src, Attributes); if (Attributes == FILE_ATTRIBUTE_DIRECTORY) { fprintf( stderr, "\nUnable to open source"); return FALSE; } if (_dos_creatnew( src, _A_RDONLY, &srcfh) != 0) if (_dos_open( src, O_RDONLY, &srcfh) != 0) { fprintf( stderr, "\nUnable to open source, error code %d", GetLastError() ); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); return FALSE; } if (_dos_getftime(srcfh, &filedate, &filetime) != 0) { fprintf( stderr, "\nUnable to get time of source"); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); return FALSE; } if (_dos_creatnew( dst, _A_NORMAL, &dstfh) != 0) if (_dos_open( dst, O_RDWR, &dstfh) != 0) { fprintf( stderr, "\nUnable to create destination, error code %d", GetLastError() ); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); if (dstfh != INVALID_HANDLE_VALUE) CloseHandle( dstfh ); return FALSE; } result = fastcopy( srcfh, dstfh ); if(!result) { if (dstfh != INVALID_HANDLE_VALUE) { CloseHandle( dstfh ); dstfh = INVALID_HANDLE_VALUE; } DeleteFile( dst ); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); fprintf( stderr, "\nUnable to copy file"); return FALSE; } if (_dos_setftime(dstfh, filedate, filetime != 0)) { fprintf( stderr, "\nUnable to set time of destination"); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); if (dstfh != INVALID_HANDLE_VALUE) CloseHandle( dstfh ); return FALSE; } if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); if (dstfh != INVALID_HANDLE_VALUE) CloseHandle( dstfh ); return TRUE; } // FCopy
unsigned int ZFileGetFTime() { _dos_open(ZFFTimeFName, 0,&ZFTimeHandle); _dos_getftime(ZFTimeHandle,&ZFDate,&ZFTime); _dos_close(ZFTimeHandle); return(0); }
void main(int argc, char *argv[]) { struct Date { unsigned int day:5; unsigned int month:4; unsigned int years:7; } date; struct Time { unsigned seconds:5; unsigned minutes:6; unsigned hours:5; } time; int handle; if (_dos_open(argv[1], O_RDONLY, &handle)) fprintf(stderr, "Error opening source file\n"); else { if (_dos_getftime(handle, &date, &time)) printf("Error getting date and time stamp\n"); else printf("%s last modified %02d-%02d-%d %02d:%02d:%02d\n", argv[1], date.month, /* month */ date.day, /* day */ date.years + 1980, /* year */ time.hours, /* hours */ time.minutes, /* minutes */ time.seconds * 2); /* seconds */ _dos_close(handle); } }
void main( void ) { int handle; unsigned date, time; if( _dos_open( "file", O_RDWR, &handle ) != 0 ) { printf( "Unable to open file\n" ); } else { printf( "Open succeeded\n" ); _dos_getftime( handle, &date, &time ); printf( "The file was last modified on %d/%d/%d", MONTH(date), DAY(date), YEAR(date) ); printf( " at %.2d:%.2d:%.2d\n", HOUR(time), MINUTE(time), SECOND(time) ); /* set the time to 12 noon */ time = (12 << 11) + (0 << 5) + 0; _dos_setftime( handle, date, time ); _dos_getftime( handle, &date, &time ); printf( "The file was last modified on %d/%d/%d", MONTH(date), DAY(date), YEAR(date) ); printf( " at %.2d:%.2d:%.2d\n", HOUR(time), MINUTE(time), SECOND(time) ); _dos_close( handle ); } }
int open(const char *name, int mode, ...) { int hdl; if (0 == _dos_open(name, mode, &hdl)) return hdl; else return -1; }
/* some non-conforming functions to make the executable smaller */ int open(const char *pathname, int flags, ...) { int handle; int result = (flags & O_CREAT ? _dos_creat(pathname, _A_NORMAL, &handle) : _dos_open(pathname, flags & (O_RDONLY | O_WRONLY | O_RDWR), &handle)); return (result == 0 ? handle : -1); }
const char *BatchLink( const char *name ) { char pipeName[ PREFIX_LEN + MAX_NAME ] = PREFIX; if( name == NULL ) name = DEFAULT_NAME; strcpy( pipeName + PREFIX_LEN, name ); if( _dos_open( pipeName, O_RDWR, &pipeHdl ) != 0 ) { return( "can not connect to batcher spawn server" ); } return( NULL ); }
int openfiad(char *filename, int *handle) { struct tifile *ff; char path[80]; char dosname[14]; char fdrname[12]; char tiname[12]; int ti; struct fdrstruc *fdr; _fmode=O_BINARY; if ((ti=*handle=getfreeti(0))!=-1) { ff=&tifiles[ti]; fdr=&ff->fdr; if (split(filename,path,tiname)) { memset(fdrname,0x20,10); memcpy(fdrname,tiname,strlen(tiname)); ti2dos(tiname,dosname); strcat(path,dosname); if ((_dos_open(path,O_RDWR|O_BINARY,&ff->doshandle))==0) { if (read(ff->doshandle,fdr,128)==128) { noansi(fdr->name); if (memicmp(fdr,fdrname,10)==0 && ((fdr->flags&F_VARIABLE) ? fdr->reclen : 1)) { tifiles[ti].inuse=1; Error=0; return 1; } } Error=NOTTIEMUL; close(ff->doshandle); return 0; } else { Error=BADFILE; close(ff->doshandle); return 0; } } } return 0; // split sets Error }
void main() { unsigned len_read; int handle; auto char buffer[80]; if( _dos_open( "file", O_RDONLY, &handle ) != 0 ) { printf( "Unable to open file\n" ); } else { printf( "Open succeeded\n" ); _dos_read( handle, buffer, 80, &len_read ); _dos_close( handle ); } }
emschk(void) { int hdl; unsigned s; if(_dos_open("EMMXXXX0",O_RDONLY,&hdl) != 0) return(NG); inregs.x.ax= 0x4400; inregs.x.bx= hdl; intdos(&inregs,&outregs); if(outregs.x.cflag && !(outregs.x.dx & 0x80)) return(NG); inregs.x.ax= 0x4407; inregs.x.bx= hdl; intdos(&inregs,&outregs); if(outregs.x.cflag && !(outregs.x.dx & 0x80)) return(NG); _dos_close(hdl); if(outregs.h.al != 0xff) return(NG); return(OK); }
int DBMPPrintInfo( char *FileName ) { int Handle; unsigned int RealWidth, Read, DataSize; tBMPHeader BMPHeader; tBITMAPINFOHEADER BITMAPINFOHEADER; if( !FileName ) return 0; if (_dos_open(FileName, O_RDWR | O_BINARY, &Handle) != 0) return 1; _dos_read( Handle, &BMPHeader, sizeof(BMPHeader), &Read ); _dos_read( Handle, &BITMAPINFOHEADER, sizeof(BITMAPINFOHEADER), &Read ); _dos_close(Handle); RealWidth = (BMPHeader.bfSize-BMPHeader.bfOffBits)/BITMAPINFOHEADER.biHeight-1; DataSize = BMPHeader.bfSize-sizeof(BITMAPINFOHEADER)-sizeof(BMPHeader)-SIZE_OF_PALETTE; if( BMPHeader.bfType!=19778 ) // "BM"=19778 { cout << "\n\n " << FileName << " - this is not BMP file...\n"; return 1; } cout << "\n\n " << FileName << " info..."; cout << "\n Size of file: " << BMPHeader.bfSize; cout << "\n Data offset: " << BMPHeader.bfOffBits; cout << "\n Bitmap info header size: " << BITMAPINFOHEADER.biSize; cout << "\n Width " << BITMAPINFOHEADER.biWidth; cout << "\n Height: " << BITMAPINFOHEADER.biHeight; cout << "\n Number of planes (1): " << BITMAPINFOHEADER.biPlanes; cout << "\n Bits per pixel: " << BITMAPINFOHEADER.biBitCount; cout << "\n Type of compression (0): " << BITMAPINFOHEADER.biCompression; cout << "\n Size of image in pixels: " << BITMAPINFOHEADER.biSizeImage; cout << "\n Horizontal resolution pix/m: " << BITMAPINFOHEADER.biXPelsPerMeter; cout << "\n Vertical resolution pix/m: " << BITMAPINFOHEADER.biYPelsPerMeter; cout << "\n Used colors: " << BITMAPINFOHEADER.biClrUsed; cout << "\n Important colors: " << BITMAPINFOHEADER.biClrImportant; cout << "\n\n FileLenght-BMPHeaderHead-BMPHead-pallette(256*3) (READ): " << DataSize; cout << "\n RealWidth is " << RealWidth <<"+1 "; return 0; }
void main() { int handle; /* Try to open "stdio.h" and then close it */ if( _dos_open( "stdio.h", O_RDONLY, &handle ) != 0 ){ dosexterr( &dos_err ); printf( "Unable to open file\n" ); printf( "exterror (AX) = %d\n", dos_err.exterror ); printf( "errclass (BH) = %d\n", dos_err.errclass ); printf( "action (BL) = %d\n", dos_err.action ); printf( "locus (CH) = %d\n", dos_err.locus ); } else { printf( "Open succeeded\n" ); if( _dos_close( handle ) != 0 ) { printf( "Close failed\n" ); } else { printf( "Close succeeded\n" ); } } }
int main(int argc, char *argv[]) { int rc = -1; int index_cmd; index_cmd = mygetopt(argc, argv); if (optH) { usage(); return 0; } if (index_cmd >= argc || !logname) { fprintf(stderr, "Type 'TEECON -?' to help.\n"); return 1; } if (optA) { rc = _dos_open(logname, O_RDWR, &tee_handle); if (rc == 0) my_doslseek(tee_handle, 0L, 2); else if (rc == 2) optO = 1; /* retry with creat when the file is not found */ else optO = 0; } if (optO && tee_handle == -1) rc = _dos_creat(logname, _A_NORMAL, &tee_handle); if (rc != 0) { fprintf(stderr, "FATAL: can't open the log file '%s'\n", logname); return -1; } my_psp = my_getpsp(); org_int21 = _dos_getvect(0x21); _dos_setvect(0x21, Int21Handler); if (argv[index_cmd]) { rc = spawnvp(P_WAIT, argv[index_cmd], (char const * const *)(argv + index_cmd)); } _dos_setvect(0x21, org_int21); fprintf(stderr, "%s : result=%d\n", argv[index_cmd], rc); if (tee_handle != -1) _dos_close(tee_handle); return rc; }
void main(int argc, char *argv[]) { union { struct Date { unsigned int day:5; unsigned int month:4; unsigned int years:7; } bits; unsigned value; } date; union { struct Time { unsigned seconds:5; unsigned minutes:6; unsigned hours:5; } bits; unsigned value; } time; int handle; if (_dos_open(argv[1], O_RDONLY, &handle)) fprintf(stderr, "Error opening source file\n"); else { date.bits.day = 4; date.bits.month = 7; date.bits.years = 14; // 1980 + 14 time.bits.hours = 12; time.bits.minutes = 0; time.bits.seconds = 0; if (_dos_setftime(handle, date.value, time.value)) printf("Error setting date/time stamp\n"); _dos_close(handle); } }
static int __F_NAME(__sopen,__wsopen)( const CHAR_TYPE *name, int mode, int shflag, va_list args ) { int rwmode; int handle; int attr; int permission; unsigned iomode_flags; tiny_ret_t rc; char dummy; #ifdef __WIDECHAR__ char mbName[MB_CUR_MAX * _MAX_PATH]; /* single-byte char */ #endif handle = -1; rc = 0; while( *name == STRING( ' ' ) ) ++name; #ifdef __WIDECHAR__ /*** If necessary, convert the wide filename to multibyte form ***/ if( wcstombs( mbName, name, sizeof( mbName ) ) == -1 ) { mbName[0] = '\0'; } #endif rwmode = mode & ( O_RDONLY | O_WRONLY | O_RDWR | O_NOINHERIT ); if( _dos_open( __F_NAME(name,mbName), rwmode | shflag, &handle ) == 0 ) { if( handle >= __NFiles ) { TinyClose( handle ); __set_errno( EMFILE ); return( -1 ); } } /* 17-apr-90 05-sep-91 */ if( (mode & (O_RDONLY | O_WRONLY | O_RDWR)) != O_RDONLY ) { if( handle != -1 ) { if( ! isatty( handle ) ) { /* if not a device */ #if 0 rc = TinyAccess( name, 0 ); /* check for existence */ if( TINY_ERROR( rc ) ) { /* file does not exist */ TinyClose( handle ); /* close whatever file we got */ handle = -1; } else if( mode & O_EXCL ) { /* must not exist */ #else /* Don't need to do the access check, since the file was opened and therefore must exist (TinyOpen can't create a file). We don't want to do the check because there are classes of items in the file system namespace that are not devices, but the TinyAccess will fail on (e.g. named pipes). */ /* must not exist if O_CREAT specified */ if( (mode & O_EXCL) && (mode & O_CREAT) ) { #endif TinyClose( handle ); __set_errno( EEXIST ); return( -1 ); } else if( mode & O_TRUNC ) { /* truncate file */ rc = TinyWrite( handle, &dummy, 0 ); if( TINY_ERROR( rc ) ) { TinyClose( handle ); return( __set_errno_dos( TINY_INFO( rc ) ) ); } } } } } if( handle == -1 ) { /* could not open */ if( (mode & O_CREAT) == 0 || _RWD_doserrno != E_nofile ) { return( -1 ); } /* creating the file */ permission = va_arg( args, int ); va_end( args ); if( permission == 0 ) permission = S_IWRITE | S_IREAD; permission &= ~_RWD_umaskval; /* 05-jan-95 */ attr = 0; if(( permission & S_IWRITE) == 0 ) attr = _A_RDONLY; #if 0 /* remove this support because it is not consistently available */ if( _RWD_osmajor >= 5 #ifdef __DOS_EXT__ && !_IsFlashTek() && !_IsRational() #endif ) { /* this function is only available in version DOS 5 and up */ /* this new way was added to handle the case of creating a */ /* new file with read-only access, but with a writeable */ /* file handle */ #ifdef __WIDECHAR__ rc = TinyCreateEx( mbName, rwmode|shflag, attr, TIO_OPEN ); #else rc = TinyCreateEx( name, rwmode|shflag, attr, TIO_OPEN ); #endif if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } handle = TINY_INFO( rc ); } else #endif { /* do it the old way */ if( _dos_creat( __F_NAME(name,mbName), attr, &handle ) ) { return( -1 ); } if( handle >= __NFiles ) { TinyClose( handle ); __set_errno( EMFILE ); return( -1 ); } /* 21-nov-90 AFS: the file is created so now the file must be */ /* opened with the correct share permissions */ if( shflag != 0 ) { rc = TinyClose( handle ); if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } if( _dos_open( __F_NAME(name,mbName), rwmode | shflag, &handle ) ) { return( -1 ); } /* handle does not equal -1 now */ } } } iomode_flags = __GetIOMode( handle ); iomode_flags &= ~(_READ|_WRITE|_APPEND|_BINARY); /* 11-aug-88 */ if( isatty( handle ) ) iomode_flags |= _ISTTY; rwmode &= ~O_NOINHERIT; if( rwmode == O_RDWR ) iomode_flags |= _READ | _WRITE; if( rwmode == O_RDONLY) iomode_flags |= _READ; if( rwmode == O_WRONLY) iomode_flags |= _WRITE; if( mode & O_APPEND ) iomode_flags |= _APPEND; if( mode & (O_BINARY|O_TEXT) ) { if( mode & O_BINARY ) iomode_flags |= _BINARY; } else { if( _RWD_fmode == O_BINARY ) iomode_flags |= _BINARY; } __SetIOMode( handle, iomode_flags ); #ifdef DEFAULT_WINDOWING if( _WindowsNewWindow != 0 ) { if( !__F_NAME(stricmp,wcscmp)( name, STRING( "con" ) ) ) { _WindowsNewWindow( NULL, handle, -1 ); } } #endif return( handle ); } #if 0 /* couldn't find any user; please re-enable if it's necessary */ #ifndef __WIDECHAR__ /* compile one version only */ int __set_binary( int handle ) { unsigned iomode_flags; __ChkTTYIOMode( handle ); iomode_flags = __GetIOMode( handle ); iomode_flags |= _BINARY; __SetIOMode( handle, iomode_flags ); if( iomode_flags & _ISTTY ) { tiny_ret_t rc; rc = TinyGetDeviceInfo( handle ); if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } rc = TinySetDeviceInfo( handle, TINY_INFO(rc) | TIO_CTL_RAW ); if( TINY_ERROR( rc ) ) { return( __set_errno_dos( TINY_INFO( rc ) ) ); } } return( 0 ); }
void TOutputDevice::open( const char *portName ) { _dos_open( portName, O_RDWR, (int *)&encoder ); }
int DBMPLoad( char *FileName, byte what ) { byte help[320]; // upside down image byte far *Palette=(unsigned char far *)farmalloc(SIZE_OF_PALETTE); // 4: R+G+B+UNUSED int Handle; word i, x=0, y=0, Read; long RealWidth, DataSize; tBMPHeader BMPHeader; tBITMAPINFOHEADER BITMAPINFOHEADER; if( !FileName ) return 0; if( !Palette ) return 0; // read headers if (_dos_open(FileName, O_RDWR | O_BINARY, &Handle) != 0) return 1; _dos_read( Handle, &BMPHeader, sizeof(BMPHeader), &Read ); _dos_read( Handle, &BITMAPINFOHEADER, sizeof(BITMAPINFOHEADER), &Read ); _dos_read( Handle, Palette, SIZE_OF_PALETTE, &Read ); DataSize=BMPHeader.bfSize-sizeof(BITMAPINFOHEADER)-sizeof(BMPHeader)-SIZE_OF_PALETTE; unsigned char far *import; switch( what ) { case CELLIMPORT: import=(unsigned char far *)farmalloc(DataSize); if( Background==NULL ) return 0; _dos_read( Handle, import, (word)DataSize, &Read ); break; case BACKGROUND: _dos_read( Handle, Background, (word)DataSize, &Read ); break; case GAMEMENU: _dos_read( Handle, GameMenu, (word)DataSize, &Read ); break; } _dos_close(Handle); RealWidth=(BMPHeader.bfSize-BMPHeader.bfOffBits)/BITMAPINFOHEADER.biHeight-1u; if( BMPHeader.bfType!=19778 ) // "BM"=19778 return 1; // Setting pallette: // INT 10H, AH=10H, AL=10H, BX = number of register to set // DH = red value // CH = green value // CL = blue value union REGS registr; if( what==BACKGROUND ) { for (i=0; i<256; i++) { registr.h.bh=0; registr.h.bl=i; registr.h.dh=Palette[i*4+2]>>2;// color must be shifted!!! registr.h.ch=Palette[i*4+1]>>2; registr.h.cl=Palette[i*4+0]>>2; registr.h.ah=0x10; registr.h.al=0x10; int86(0x10,®istr,®istr); } } switch( what ) { case CELLIMPORT: // drawing picture for(i=(word)DataSize; i>0; i--) { if( x>RealWidth) { y++; x=0; } putpixel((word)RealWidth-x, y,(char)import[i-1]); x++; } farfree( import ); break; case BACKGROUND: for( i=0; i<100; i++ ) { for( x=0; x<320; x++ ) help[x]=Background[i*320+x]; for( x=0; x<320; x++ ) Background[i*320+x]=Background[(200-1-i)*320+x]; for( x=0; x<320; x++ ) Background[(200-1-i)*320+x]=help[x]; } break; case GAMEMENU: for( i=0; i<10; i++ ) { for( x=0; x<320; x++ ) help[x]=GameMenu[i*320+x]; for( x=0; x<320; x++ ) GameMenu[i*320+x]=GameMenu[(20-1-i)*320+x]; for( x=0; x<320; x++ ) GameMenu[(20-1-i)*320+x]=help[x]; } break; } farfree( Palette ); return 0; }
static DWORD LoadKey(DWORD appID, const char* filename, DWORD* level, BOOL* valid, HDATA& hRootData) { DWORD ret=0; DWORD Level=0; BOOL Valid=TRUE; if(sign_check_file(filename,1,0,0,0)) { int f; if(_dos_open(filename,O_RDONLY,&f)) return ret; DWORD count; DWORD val=0; _dos_read(f,(void far *)&val,4,(unsigned int*)&count); _dos_close(f); if(count!=4 || val!='wsLK') return ret; if(!DATA_Init_Library((void*(*)(unsigned int))Malloc,Free)) return ret; hRootData=DATA_Add(0,0,AVP_PID_KEYROOT,0,0); if(!hRootData) return ret; DATA_Add(hRootData,0,PID_FILENAME,(DWORD)filename,0); HDATA hInfo; hInfo=DATA_Add(hRootData,0,AVP_PID_KEYINFO,0,0); DATA_Add(hInfo,0, PID_SERIALSTR, (DWORD)"Corrupted", 0); return ret; } _AvpReadFile =AvpReadFile; _AvpWriteFile =AvpWriteFile; _AvpCloseHandle=AvpCloseHandle; _AvpCreateFile =AvpCreateFile; _AvpGetFileSize=AvpGetFileSize; if(!KLDT_Init_Library((void*(*)(unsigned int))Malloc,Free)) return ret; if(!DATA_Init_Library((void*(*)(unsigned int))Malloc,Free)) return ret; AVP_dword dseq[5]; if(!KLDT_DeserializeUsingSWM( filename, &hRootData ))return ret; if(hRootData==NULL) return ret; ret=TRUE; AVP_dword pid; pid=MAKE_AVP_PID(appID, AVP_APID_GLOBAL, avpt_dword, 0); if(AVP_PID_KEYROOT!=DATA_Get_Id( hRootData, 0 ) || !DATA_Get_Val( hRootData, DATA_Sequence(dseq,pid,0), 0, &Level, sizeof(Level)) ) { DATA_Remove( hRootData, 0 ); hRootData=0; return ret; } // ret|=FN_MINIMAL; // if(level>=10) ret|=FN_UPDATES; // if(level>=20) ret|=FN_OPTIONS; // if(level>=30) ret|=FN_FULL; struct dosdate_t stCurrent; SYSTEMTIME stExpir; _dos_getdate(&stCurrent); memset(&stExpir,0,sizeof(SYSTEMTIME)); if( !DATA_Get_Val( hRootData, DATA_Sequence(dseq,AVP_PID_KEYINFO,AVP_PID_KEYEXPDATE,0),0,&stExpir,sizeof(AVP_date)) ) goto dr; AVP_dword keynumber[3]; DATA_Get_Val(hRootData,DATA_Sequence(dseq,AVP_PID_KEYINFO,AVP_PID_KEYSERIALNUMBER,0), 0, keynumber, sizeof(keynumber)); char buf[0x20]; _sprintf(buf,"%04d-%06d-%08d",keynumber[0],keynumber[1],keynumber[2]); DATA_Add(hRootData,DATA_Sequence(dseq,AVP_PID_KEYINFO,0), PID_SERIALSTR, (DWORD)buf,0); BOOL keyIsTrial; keyIsTrial=(DATA_Find(hRootData, DATA_Sequence(dseq,AVP_PID_KEYINFO,AVP_PID_KEYISTRIAL,0)))?1:0; AVP_dword PLPos; PLPos=0; DATA_Get_Val( hRootData, DATA_Sequence(dseq,AVP_PID_KEYINFO,AVP_PID_KEYPLPOS,0), 0, &PLPos, sizeof(AVP_dword)); if(stCurrent.year > stExpir.wYear) Valid=FALSE; else if(stCurrent.year < stExpir.wYear) ; else if(stCurrent.month > stExpir.wMonth) Valid=FALSE; else if(stCurrent.month < stExpir.wMonth) ; else if(stCurrent.day > stExpir.wDay) Valid=FALSE; if(Valid) { AVP_dword life; if( DATA_Get_Val( hRootData, DATA_Sequence(dseq,AVP_PID_KEYINFO,AVP_PID_KEYLIFESPAN,0), 0, &life, sizeof(AVP_dword)) ) { //if(!CheckKeyUseTime(keynumber,life,stExpir,keyIsTrial?&PLPos:NULL))Valid=FALSE; } } if(!Valid &&( keyIsTrial|| !CheckSelfExpir(stExpir))) Level=0; DATA_Set_Val(hRootData,DATA_Sequence(dseq,AVP_PID_KEYINFO,AVP_PID_KEYEXPDATE,0), 0, (DWORD)&stExpir, sizeof(AVP_date)); dr: DATA_Add(hRootData,0,PID_FILENAME,(DWORD)filename,0); if(ret){ if(level) *level=MAX(*level, Level); if(valid) *valid|=Valid; } return ret; }
//static DWORD LoadOldKey(char* filename,CPtrArray* array,DWORD appID) //static DWORD LoadOldKey(char* filename, HDATA& hRootData, DWORD appID) static DWORD LoadOldKey(DWORD appID, const char* filename, DWORD* level, BOOL* valid, HDATA& hRootData) { DWORD ret=0; AVP_KeyHeader avpKeyHeader; int handle; unsigned bytes; unsigned char *cbuf; DWORD Level=0; BOOL Valid=TRUE; BOOL platf=FALSE; if(_dos_open(filename,O_RDONLY,&handle)) return ret; if(_dos_read(handle,(void far *)&avpKeyHeader,sizeof(avpKeyHeader),&bytes) ||avpKeyHeader.Magic!=AVP_KEY_MAGIC||avpKeyHeader.Version!=3 ||((cbuf=(unsigned char *)Malloc(avpKeyHeader.CompressedSize))==0)) { _dos_close(handle); return ret; } //if(KeyHeader.CompressedCRC==CalcSum((BYTE*)cbuf,KeyHeader.CompressedSize)) if(((avpKey=(struct _AVP_Key *)Malloc(avpKeyHeader.UncompressedSize))==NULL) ||_dos_read(handle,(void *)cbuf,avpKeyHeader.CompressedSize,&bytes)) { _dos_close(handle); Free(cbuf); return ret; } _dos_close(handle); if(avpKeyHeader.CompressedCRC==CalcSum((BYTE*)cbuf,avpKeyHeader.CompressedSize)) { for(int i=0;i<avpKeyHeader.CompressedSize;i++) cbuf[i]^=(BYTE)i; if(avpKeyHeader.UncompressedSize==unsqu(cbuf,(unsigned char *)avpKey) )//&&!FFake) { avp_key_present=1; switch(appID) { case AVP_APID_SCANNER_WIN_95: platf=!!(avpKey->Platforms & KEY_P_WIN95); break; case AVP_APID_SCANNER_WIN_NTWS: platf=!!(avpKey->Platforms & KEY_P_WINNT); break; case AVP_APID_MONITOR_WIN_95: platf=!!(avpKey->Platforms & KEY_P_WIN95) && !!(avpKey->Options & KEY_O_MONITOR); break; case AVP_APID_MONITOR_WIN_NTWS: platf=!!(avpKey->Platforms & KEY_P_WINNT) && !!(avpKey->Options & KEY_O_MONITOR); break; case AVP_APID_OS_2: platf=!!(avpKey->Platforms & KEY_P_OS2); break; case AVP_APID_SCANNER_DOS_LITE: platf=!!(avpKey->Platforms & KEY_P_DOSLITE); break; case AVP_APID_NOVELL: platf=!!(avpKey->Platforms & KEY_P_NOVELL); break; case AVP_APID_SCANNER_DOS_32: case AVP_APID_SCANNER_DOS_16: platf=!!(avpKey->Platforms & KEY_P_DOS); break; case AVP_APID_CONTROLCENTER: case AVP_APID_UPDATOR: platf=!!(avpKey->Platforms & KEY_P_WIN95) || !!(avpKey->Platforms & KEY_P_WINNT); break; case AVP_APID_INSPECTOR: case AVP_APID_WEBINSPECTOR: case AVP_APID_EXCHANGE: case AVP_APID_NT_SERVER: default: break; } if(platf) { ret=FN_MINIMAL; ret|=FN_OPTIONS; if(avpKey->Options & KEY_O_REMOTELAUNCH)ret|=FN_NETWORK; if(avpKey->Options & KEY_O_REMOTESCAN) ret|=FN_NETWORK; if(!(avpKey->Options & KEY_O_DISINFECT))ret&=~FN_DISINFECT; if(!(avpKey->Options & KEY_O_UNPACK)) ret&=~FN_UNPACK; if(!(avpKey->Options & KEY_O_EXTRACT)) ret&=~FN_EXTRACT; struct dosdate_t stCurrent; //SYSTEMTIME stCurrent; SYSTEMTIME stExpir; _dos_getdate(&stCurrent); //GetSystemTime(&stCurrent); memset(&stExpir,0,sizeof(struct dosdate_t));//SYSTEMTIME)); stExpir.wYear =avpKey->ExpirYear; stExpir.wMonth=(unsigned char)avpKey->ExpirMonth; stExpir.wDay =(unsigned char)avpKey->ExpirDay; if(stCurrent.year > stExpir.wYear) Valid=FALSE; else if(stCurrent.year < stExpir.wYear) ; else if(stCurrent.month > stExpir.wMonth) Valid=FALSE; else if(stCurrent.month < stExpir.wMonth) ; else if(stCurrent.day > stExpir.wDay) Valid=FALSE; //if(stCurrent.year >stExpir.wYear) goto time_bad; //if(stCurrent.year <stExpir.wYear) goto time_ok; //if(stCurrent.month>stExpir.wMonth)goto time_bad; //if(stCurrent.month<stExpir.wMonth)goto time_ok; //if(stCurrent.day >stExpir.wDay) goto time_bad; //if(stCurrent.day <stExpir.wDay) goto time_ok; //time_bad: // if(!!(avpKey->Flags & KEY_F_INFOEVERYLAUNCH) // || !(avpKey->Flags & KEY_F_REGISTERED) // || !CheckSelfExpir(stExpir)) // goto clo; // ret=0; // else // ret &= ~FN_UPDATES; //time_ok: if(!CheckSelfExpir(stExpir)) Valid=FALSE; else { if(avpKey->Options & KEY_O_DISINFECT) { Level=10; if((avpKey->Options & KEY_O_UNPACK)||(avpKey->Options & KEY_O_EXTRACT)) Level=20; if((avpKey->Options & KEY_O_REMOTELAUNCH)||(avpKey->Options & KEY_O_REMOTESCAN)) Level=30; } else { if(avpKey->Flags & KEY_F_INFOEVERYLAUNCH) Valid=FALSE; else Level=5; } } if(DATA_Init_Library((void*(*)(unsigned int))Malloc,Free)) { hRootData=DATA_Add(0,0,AVP_PID_KEYROOT,0,0); if(hRootData) { DATA_Add(hRootData,0,PID_FILENAME,(DWORD)filename,0); HDATA hInfo; hInfo=DATA_Add(hRootData,0,AVP_PID_KEYINFO,0,0); //OemToChar(buf+Key->RegNumberOffs, buf+Key->RegNumberOffs); //OemToChar(buf+Key->CopyInfoOffs, buf+Key->CopyInfoOffs); //OemToChar(buf+Key->SupportOffs, buf+Key->SupportOffs); DATA_Add(hInfo,0, PID_SERIALSTR,(DWORD)avpKey+avpKey->RegNumberOffs,0); DATA_Add(hInfo,0, AVP_PID_KEYPLPOSNAME, (DWORD)"AVP Key v1.0", 0); DATA_Add(hInfo,0, AVP_PID_KEYLICENCEINFO,(DWORD)avpKey+avpKey->CopyInfoOffs,0); DATA_Add(hInfo,0, AVP_PID_KEYSUPPORTINFO,(DWORD)avpKey+avpKey->SupportOffs,0); if(stExpir.wDay!=0) DATA_Add(hInfo,0, AVP_PID_KEYEXPDATE, (DWORD)&stExpir, sizeof(AVP_date)); } } } } else ret=0; if(!(avpKey->Flags&KEY_F_REGISTERED)||!(avpKey->Platforms&KEY_P_DOS)) ret=0; } else ret=0; //clo: Free(cbuf); if(ret) { if(level) *level=MAX(*level, Level); if(valid) *valid|=Valid; } return ret; }
signed char do_restore(nwBackupParms * parms, char * remote_name, char * local_dir, char * logfile) { char ctrl_file_name[L_tmpnam]; FILE * ctrl_file; dirStack_t dstack; dirStruct_t dummy_curr_dir; fileStruct_t dummy_curr_file; nwBackupCodes nw_rc = SUCCESS; int do_restore_rc = 0; int path_eostr; char current_file_name[FILENAME_MAX]; char * path, * path_and_file, * unix_path, \ * unix_path_and_file, * file_buffer, * in_buffer; uint8_t * ctrl_buffer; path = malloc(129 * 4); file_buffer = malloc(FILE_BUF_SIZE); in_buffer = malloc(OUTBUF_SIZE); ctrl_buffer = malloc(BUFSIZ); /* Should be more than enough... handle dynamically sizing it later. */ //dummy_outbuf = calloc(OUTBUF_SIZE, 1); //This doesn't set the first and third byte //to zero! if(path == NULL || file_buffer == NULL || in_buffer == NULL || ctrl_buffer == NULL) { fprintf(stderr, "Could not allocate memory for path or file buffers!\n"); return -1; } /* Don't bother freeing till end of program- if error, program will terminate soon anyway! */ path_and_file = path + 129; unix_path = path_and_file + 129; unix_path_and_file = unix_path + 129; if(initDirStack(&dstack)) { fprintf(stderr, "Directory Stack Initialization failed!\n"); return -2; } if(!strcpy(path, local_dir)) /* if(strncpy(path, argv[1], DIR_MAX_PATH + 1) >= (DIR_MAX_PATH + 1)) */ { /* Shouldn't fail... but Heartbleed convinces me to code defensively. */ fprintf(stderr, "Specified path name is too long...\n" "Actually if we're got this error on DOS, we have more serious\n" "trouble than just a bad path!\n"); } path_eostr = strlen(path); if(path[path_eostr - 1] == 92) { /* Backslash */ path[path_eostr - 1] = '\0'; local_dir[path_eostr - 1] = '\0'; /* We will need local dir again! */ path_eostr--; /* path_eostr now points to the root path's NULL terminator. */ } //full_unix_path = malloc(strlen(parms-> strlen(remote_name) + ); /* If doing an absolute-path restore, the first push should be deferred until the control file header is read. */ if(pushDir(&dstack, &dummy_curr_dir, path)) { fprintf(stderr, "Initial directory push failed!\n"); return -3; } if(tmpnam(ctrl_file_name) == NULL) { fprintf(stderr, "Attempt to allocate tmpnam() for receiving CONTROL failed!\n"); return -4; } ctrl_file = fopen(ctrl_file_name, "wb+"); if(ctrl_file == NULL) { fprintf(stderr, "Attempt to open temp file for receiving CONTROL failed!\n"); return -5; } nw_rc = initRemote(parms); if(nw_rc != SUCCESS) { do_restore_rc = -6; } nw_rc = chDirRemote(remote_name); if(!(nw_rc == SUCCESS)) { do_restore_rc = -7; } if(!do_restore_rc) { /* Grab the control file from the server */ fprintf(stderr, "Receiving control file from the server (no retry)...\n"); setvbuf(ctrl_file, file_buffer, _IOFBF, FILE_BUF_SIZE); if(restore_file(ctrl_file, "CONTROL.NFO", in_buffer, OUTBUF_SIZE)) { fprintf(stderr, "Couldn't receive control file (%s) to the server. Supply" "the control file manually (not implemented) and try again.\n", ctrl_file_name); do_restore_rc = -8; } else { /* Control file was successfully grabbed. We can continue. */ ctrlEntryType_t entry_type; int8_t all_dirs_restored = 0; unsigned int attr, time, date; long unsigned int size; fprintf(stderr, "Control file received successfully from the server.\n"); fclose(ctrl_file); /* Assume this doesn't fail for now */ ctrl_file = fopen(ctrl_file_name, "rb"); entry_type = getNextEntry(ctrl_file, ctrl_buffer, BUFSIZ); while(!all_dirs_restored && do_restore_rc == 0) { FILE * curr_file; int temp; switch(entry_type) { case CTRL_HEADER: /* For now, absolute-path restores are disabled. Restores are relative to the directory in which the program is invoked. In effect, this code does nothing! */ //parseHeaderEntry(ctrl_buffer, path); /* if(pushDir(&dstack, &dummy_curr_dir, path)) { fprintf(stderr, "Initial directory push failed!\n"); do_restore_rc = -16; } */ fprintf(stderr, "Root directory: %s\n", path); break; case CTRL_DIR: temp = parseDirEntry(ctrl_buffer, current_file_name, &attr, &time, &date, &size); /* Change to snprintf soon */ sprintf(path_and_file, "%s\\%s", path, current_file_name); strcpy(path, path_and_file); unix_path[0] = '\0'; /* Skip the leading separator for now... */ if(createUnixName(unix_path, &path[path_eostr + 1]) == NULL) { fprintf(stderr, "Unix directory name creation failed!\n"); do_restore_rc = -9; break; } /* fprintf(stderr, "Return code: %d Curr directory: %s, Attr: %hu\nUnix name: %s\n",\ temp, path, attr, unix_path); */ if(_mkdir(path)) { fprintf(stderr, "Directory creation failed (%s)!\n", path); do_restore_rc = -10; } else { int dos_handle; fprintf(stderr, "Directory created: %s\n", path); if(_dos_open(path, O_RDONLY, &dos_handle)) { fprintf(stderr, "Warning: Could not open directory to set attributes!\n"); } else { if(_dos_setftime(dos_handle, date, time)) { fprintf(stderr, "Warning: Could not reset date/time on directory %s!\n", path); } _dos_close(dos_handle); if(_dos_setfileattr(path_and_file, attr)) { fprintf(stderr, "Warning: Could not set attributes on directory %s!\n", path); } } } //getchar(); break; case CTRL_FILE: /* Should not cause buffer overflow, since sizeof(current_file_name) set to FILENAME_MAX */ temp = parseFileEntry(ctrl_buffer, current_file_name, &attr, &time, &date, &size); /* Skip the leading separator for now... */ sprintf(path_and_file, "%s\\%s", path, current_file_name); if(!strcmp(path, local_dir)) { /* Don't copy a separator if the path is at the root... otherwise the server won't find the file and/or think the file is at the server's root! */ strcpy(unix_path_and_file, current_file_name); } else { sprintf(unix_path_and_file, "%s/%s", unix_path, current_file_name); } /* fprintf(stderr, "Return code: %d Curr directory: %s, Attr: %hu, Time %hu, Date %hu, Size %lu\n" \ "Unix directory: %s\n", temp, path_and_file, attr, time, date, size, unix_path_and_file); */ /* Receive file scope block. */ { int retry_count = 0; int8_t local_error = 0, rcv_done = 0; fprintf(stderr, "Receiving file %s...\n", unix_path_and_file); while(!rcv_done && !local_error && retry_count <= 3) { int8_t rcv_remote_rc; if(retry_count) { fprintf(stderr, "Retrying operation... (%d)\n", rcv_remote_rc); } curr_file = fopen(path_and_file, "wb"); setvbuf(curr_file, file_buffer, _IOFBF, FILE_BUF_SIZE); rcv_remote_rc = restore_file(curr_file, unix_path_and_file, in_buffer, OUTBUF_SIZE); //rcv_remote_rc = 0; fclose(curr_file); /* Close the file no matter what */ switch(rcv_remote_rc) { case 0: rcv_done = 1; break; case -2: fprintf(stderr, "Read error on file: %s! Not continuing.", path_and_file); local_error = 1; /* Local file error. */ break; case -1: /* Recoverable error. */ default: break; } retry_count++; } if(local_error) { /* If file error, we need to break out. */ do_restore_rc = -11; } else if(retry_count > 3) { do_restore_rc = -12; } else { /* File receive ok, try setting attributes now. */ int dos_handle; if(_dos_open(path_and_file, O_RDONLY, &dos_handle)) { fprintf(stderr, "Warning: Could not open file to set attributes!\n"); } else { if(_dos_setftime(dos_handle, date, time)) { fprintf(stderr, "Warning: Could not reset date/time on file %s!\n", path_and_file); } _dos_close(dos_handle); if(_dos_setfileattr(path_and_file, attr)) { fprintf(stderr, "Warning: Could not set attributes on file %s!\n", path_and_file); } } } } break; case CTRL_CDUP: /* Remove the deepest directory of the path, as long as we are not back at the invocation directory. */ //fprintf(stderr, "CDUP occurred.\n"); if(strcmp(path, local_dir)) { char * separator = strrchr(path, 92); if(separator != NULL) { /* Two characters need to be set to null because */ (* separator) = '\0'; //fprintf(stderr, "Path was stripped. ); } fprintf(stderr, "Directory change. New path is: %s\n", path); /* Skip the leading separator for now... we need to recreate the unix path in case a directory does not follow next! */ if(createUnixName(unix_path, &path[path_eostr + 1]) == NULL) { fprintf(stderr, "Unix directory name creation failed!\n"); do_restore_rc = -13; break; } //getchar(); } break; case CTRL_EOF: all_dirs_restored = 1; fprintf(stderr, "End of control file.\n"); break; default: fprintf(stderr, "Unexpected data from control file!\n"); do_restore_rc = -14; break; } entry_type = getNextEntry(ctrl_file, ctrl_buffer, BUFSIZ); fprintf(stderr, "\n"); } } } if(do_restore_rc) { fprintf(stderr, "Full restore failed with status code %d.\n", do_restore_rc); } else { fprintf(stderr, "Full restore completed successfully.\n"); } fclose(ctrl_file); closeRemote(); remove(ctrl_file_name); return do_restore_rc; }
/* * GrabFile - read in a specified file, dump it to destination */ int GrabFile( char *src, struct stat *stat_s, char *dest, unsigned srcattr ) { #if defined( __OS2__ ) && defined( __386__ ) int result; #else ctrl_block *cb; #endif #if !defined(__WATCOMC__) && ( defined( __NT__ ) ) HANDLE handle; #else int handle; #endif int okay=TRUE; timedate td; unsigned t = 0; unsigned d = 0; /* * file handle */ if( _dos_open( src, O_RDONLY, &handle ) ) { DropPrintALine( "Error opening file %s",src ); IOError( errno ); } /* * get time/date stamp of file */ if( npflag || todflag ) { _dos_getftime( handle, &d, &t ); if( todflag ) { td.yy = (((d & 0xFE00) >> 9) + 1980); td.mm = ((d & 0x01E0 ) >> 5); td.dd = (d & 0x001F); td.hr = ((t & 0xF800) >> 11); td.min = ((t & 0x07E0) >> 5); td.sec = ((t & 0x001F) << 1); /* * see if this file passes the date checks */ if( tflag2 ) { if( td.hr <= after_t_d.hr ) { if( td.hr < after_t_d.hr ) { return( FALSE ); } if( td.min <= after_t_d.min ) { if( td.min < after_t_d.min ) { return( FALSE ); } if( td.sec < after_t_d.sec ) { return( FALSE ); } } } } if( Tflag1 ) { if( td.hr >= before_t_d.hr ) { if( td.hr > before_t_d.hr ) { return( FALSE ); } if( td.min >= before_t_d.min ) { if( td.min > before_t_d.min ) { return( FALSE ); } if( td.sec > before_t_d.sec ) { return( FALSE ); } } } } if( dflag2 ) { if( td.yy <= after_t_d.yy ) { if( td.yy < after_t_d.yy ) { return( FALSE ); } if( td.mm <= after_t_d.mm ) { if( td.mm < after_t_d.mm ) { return( FALSE ); } if( td.dd < after_t_d.dd ) { return( FALSE ); } } } } if( Dflag1 ) { if( td.yy >= before_t_d.yy ) { if( td.yy > before_t_d.yy ) { return( FALSE ); } if( td.mm >= before_t_d.mm ) { if( td.mm > before_t_d.mm ) { return( FALSE ); } if( td.dd > before_t_d.dd ) { return( FALSE ); } } } } } }
int DBMPLoad( char *FileName ) { int Handle; unsigned char far *Palette=(unsigned char far *)farmalloc(SIZE_OF_PALETTE); // 4: R+G+B+UNUSED unsigned int DataSize; unsigned int i, x=0, y=0, RealWidth, Read; tBMPHeader BMPHeader; tBITMAPINFOHEADER BITMAPINFOHEADER; struct palettetype PaletteType; if( !FileName ) return 0; if( !Palette ) return 0; // read headers if (_dos_open(FileName, O_RDWR | O_BINARY, &Handle) != 0) return 1; _dos_read( Handle, &BMPHeader, sizeof(BMPHeader), &Read ); _dos_read( Handle, &BITMAPINFOHEADER, sizeof(BITMAPINFOHEADER), &Read ); _dos_read( Handle, Palette, SIZE_OF_PALETTE, &Read ); DataSize=BMPHeader.bfSize-sizeof(BITMAPINFOHEADER)-sizeof(BMPHeader)-SIZE_OF_PALETTE; unsigned char far *DataBuffer=(unsigned char far *)farmalloc(DataSize); if( DataBuffer==NULL ) return 0; _dos_read( Handle, DataBuffer, DataSize, &Read ); _dos_close(Handle); RealWidth=(BMPHeader.bfSize-BMPHeader.bfOffBits)/BITMAPINFOHEADER.biHeight-1; if( BMPHeader.bfType!=19778 ) // "BM"=19778 return 1; getpalette(&PaletteType); // get system pallette // Setting pallette: // INT 10H, AH=10H, AL=10H, BX = number of register to set // DH = red value // CH = green value // CL = blue value union REGS registr; for (i=0; i<256; i++) { registr.h.bh=0; registr.h.bl=i; registr.h.dh=Palette[i*4+2]>>2;// color must be shifted!!! registr.h.ch=Palette[i*4+1]>>2; registr.h.cl=Palette[i*4+0]>>2; registr.h.ah=0x10; registr.h.al=0x10; int86(0x10,®istr,®istr); } // drawing picture for(i=DataSize; i>0; i--) { if( x>RealWidth) { y++; x=0; } putpixel(RealWidth-x, y,(char)DataBuffer[i-1]); x++; } farfree( DataBuffer ); farfree( Palette ); return 0; }