int xWrite(sqlite3_file*file, const void*buffer, int iAmt, sqlite3_int64 iOfst) { struct my_file_data *my_file = (struct my_file_data*)file; size_t actual; #ifdef LOG_OPERATIONS lprintf( "Write %s %d at %d", my_file->filename, iAmt, iOfst ); //LogBinary( buffer, iAmt ); #endif { size_t filesize = sack_fsize( my_file->file ); if( filesize < iOfst ) { static unsigned char *filler; if( !filler ) { filler = NewArray( unsigned char, 512 ); MemSet( filler, 0, 512 ); } sack_fseek( my_file->file, 0, SEEK_END ); while( filesize < iOfst ) { if( ( iOfst - filesize ) >= 512 ) { sack_fwrite( filler, 1, 512, my_file->file ); filesize += 512; } else { sack_fwrite( filler, 1, ( iOfst - filesize ), my_file->file ); filesize += ( iOfst - filesize ); } } } }
SaneWinMain( argc, argv ) { if( argc > 1 ) { TEXTSTR result; uint8_t* buf; size_t length; FILE *file = sack_fopen( 0, argv[1], "rb" ); length = sack_fseek( file, 0, SEEK_END ); buf = NewArray( uint8_t, length ); sack_fseek( file, 0, SEEK_SET ); sack_fread( buf, 1, length, file ); sack_fclose( file ); result = SRG_EncryptData( buf, length ); { int wrote = 0; while( result[wrote] ) { wrote += printf( "%.80s", result + wrote ); if( result[wrote] ) printf("\\\n" ); } } { size_t testlen; uint8_t* testbuf; SRG_DecryptData( result, &testbuf, &testlen ); if( testlen != length ) printf( "\n length fail \n" ); if( MemCmp( testbuf, buf, testlen ) ) printf( "\nFAIL\n" ); Release( testbuf ); } Release( buf ); Release( result ); } }
int xRead(sqlite3_file*file, void*buffer, int iAmt, sqlite3_int64 iOfst) { struct my_file_data *my_file = (struct my_file_data*)file; size_t actual; #ifdef LOG_OPERATIONS lprintf( "read %s %d %d", my_file->filename, iAmt, iOfst ); #endif sack_fseek( my_file->file, (size_t)iOfst, SEEK_SET ); if( ( actual = sack_fread( buffer, 1, iAmt, my_file->file ) ) == iAmt ) { #ifdef LOG_OPERATIONS //LogBinary( buffer, iAmt ); #endif return SQLITE_OK; } #ifdef LOG_OPERATIONS lprintf( "Errno : %d", errno ); #endif MemSet( ((char*)buffer)+actual, 0, iAmt - actual ); return SQLITE_IOERR_SHORT_READ; }