unsigned int ZFileGetFTime() { _dos_open(ZFFTimeFName, 0,&ZFTimeHandle); _dos_getftime(ZFTimeHandle,&ZFDate,&ZFTime); _dos_close(ZFTimeHandle); return(0); }
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 ); } }
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); } }
int main( int argc, const char** argv ) { char buffer[BUF_SIZE]; int src_handle, dst_handle; unsigned int value, red, written; puts("SIMPLE FILE COPIER\n"); if( argc != 3 ) { printf( "TYPE COPIER <SRC_FILE> <DST_FILE>" ); return 1; } printf( "%s -> %s", argv[1], argv[2] ); src_handle = open16l( argv[1], O_RDONLY_16L ); if ( src_handle < 0 ) { printf( "\n%s: %s", argv[1], strerror( -src_handle ) ); return 2; } dst_handle = open16l( argv[2], O_CREAT_TRUNC_16L ); if ( dst_handle < 0 ) { _dos_close( src_handle ); printf( "\n%s: %s", argv[2], strerror( -dst_handle ) ); return 2; } do { value = _dos_read( src_handle, buffer, sizeof( buffer ), &red ); if( value != 0 ) printf( ": ERROR reading file" ); if( value == 0 && red > 0 ) { value = _dos_write( dst_handle, buffer, red, &written ); if( value != 0 || written < red ) printf( ": ERROR writing file" ); } } while( value == 0 && red > 0 ); _dos_close( src_handle ); _dos_close( dst_handle ); return 0; }
int close (int fd) { if (__fd_remove (fd) < 0) return -1; return _dos_close (fd); }
void BatchUnlink( int shutdown ) { char done; done = shutdown ? LNK_SHUTDOWN : LNK_DONE; my_write( pipeHdl, &done, sizeof( done ) ); _dos_close( pipeHdl ); }
void main() { int handle1, handle2; if( _dos_creat( "file", _A_NORMAL, &handle1 ) ){ printf( "Unable to create file\n" ); } else { printf( "Create succeeded\n" ); if( _dos_creatnew( "file", _A_NORMAL, &handle2 ) ){ printf( "Unable to create new file\n" ); } _dos_close( handle1 ); } }
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); } }
int SysClose( int handle ) { if( _dos_close( handle ) ) return( -1 ); return( 0 ); }
void TOutputDevice::close() { _dos_close( 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; }
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; }
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; }
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; }