void mCheatSetInit(struct mCheatSet* set, const char* name) { mCheatListInit(&set->list, 4); StringListInit(&set->lines, 4); if (name) { set->name = strdup(name); } else { set->name = 0; } set->enabled = true; }
bool mCheatSaveFile(struct mCheatDevice* device, struct VFile* vf) { static const char lineStart[3] = "# "; static const char lineEnd = '\n'; struct StringList directives; StringListInit(&directives, 4); size_t i; for (i = 0; i < mCheatSetsSize(&device->cheats); ++i) { struct mCheatSet* set = *mCheatSetsGetPointer(&device->cheats, i); set->dumpDirectives(set, &directives); if (!set->enabled) { static const char* disabledDirective = "!disabled\n"; vf->write(vf, disabledDirective, strlen(disabledDirective)); } size_t d; for (d = 0; d < StringListSize(&directives); ++d) { char directive[64]; ssize_t len = snprintf(directive, sizeof(directive) - 1, "!%s\n", *StringListGetPointer(&directives, d)); if (len > 1) { vf->write(vf, directive, (size_t) len > sizeof(directive) ? sizeof(directive) : len); } } vf->write(vf, lineStart, 2); if (set->name) { vf->write(vf, set->name, strlen(set->name)); } vf->write(vf, &lineEnd, 1); size_t c; for (c = 0; c < StringListSize(&set->lines); ++c) { const char* line = *StringListGetPointer(&set->lines, c); vf->write(vf, line, strlen(line)); vf->write(vf, &lineEnd, 1); } } size_t d; for (d = 0; d < StringListSize(&directives); ++d) { free(*StringListGetPointer(&directives, d)); } StringListClear(&directives); StringListDeinit(&directives); return true; }
void GBACheatSetInit(struct GBACheatSet* set, const char* name) { GBACheatListInit(&set->list, 4); StringListInit(&set->lines, 4); set->incompleteCheat = 0; set->incompletePatch = 0; set->currentBlock = 0; set->gsaVersion = 0; set->remainingAddresses = 0; set->hook = 0; int i; for (i = 0; i < MAX_ROM_PATCHES; ++i) { set->romPatches[i].exists = false; } if (name) { set->name = strdup(name); } else { set->name = 0; } set->enabled = true; }
bool mCheatParseFile(struct mCheatDevice* device, struct VFile* vf) { char cheat[MAX_LINE_LENGTH]; struct mCheatSet* set = NULL; struct mCheatSet* newSet; bool nextDisabled = false; struct StringList directives; StringListInit(&directives, 4); while (true) { size_t i = 0; ssize_t bytesRead = vf->readline(vf, cheat, sizeof(cheat)); rtrim(cheat); if (bytesRead == 0) { break; } if (bytesRead < 0) { StringListDeinit(&directives); return false; } while (isspace((int) cheat[i])) { ++i; } switch (cheat[i]) { case '#': do { ++i; } while (isspace((int) cheat[i])); newSet = device->createSet(device, &cheat[i]); newSet->enabled = !nextDisabled; nextDisabled = false; if (set) { mCheatAddSet(device, set); } if (set) { newSet->copyProperties(newSet, set); } newSet->parseDirectives(newSet, &directives); set = newSet; break; case '!': do { ++i; } while (isspace((int) cheat[i])); if (strcasecmp(&cheat[i], "disabled") == 0) { nextDisabled = true; break; } if (strcasecmp(&cheat[i], "reset") == 0) { size_t d; for (d = 0; d < StringListSize(&directives); ++d) { free(*StringListGetPointer(&directives, d)); } StringListClear(&directives); break; } *StringListAppend(&directives) = strdup(&cheat[i]); break; default: if (!set) { set = device->createSet(device, NULL); set->enabled = !nextDisabled; nextDisabled = false; } mCheatAddLine(set, cheat, 0); break; } } if (set) { mCheatAddSet(device, set); } size_t d; for (d = 0; d < StringListSize(&directives); ++d) { free(*StringListGetPointer(&directives, d)); } StringListClear(&directives); StringListDeinit(&directives); return true; }
/* * Purpose of this function is to open a device and write random data to it as a way of hiding information on the disk. * * The above is accomplished by opening a plain mapper against the device and then write to the device through the mapper * */ int zuluCryptEXEWriteDeviceWithJunk( const struct_opts * opts,const char * mapping_name,uid_t uid ) { stringList_t stl = StringListInit() ; string_t * mapper = StringListAssign( stl ) ; string_t * confirm = StringListAssign( stl ); double size ; double size_written ; const char * device = opts->device ; char buffer[ SIZE ] ; int ratio ; int prev_ratio ; int k ; struct sigaction sigac; memset( &sigac,'\0',sizeof( struct sigaction ) ) ; sigac.sa_handler = &sigTERMhandler ; sigaction( SIGINT,&sigac,NULL ) ; sigaction( SIGTERM,&sigac,NULL ) ; sigaction( SIGHUP,&sigac,NULL ) ; __exit_as_requested = 0 ; if( ( k = open_plain_as_me_1( opts,mapping_name,uid,0 ) ) != 0 ){ return k ; } *mapper = zuluCryptCreateMapperName( device,mapping_name,uid,ZULUCRYPTshortMapperPath ) ; StringMultiplePrepend( *mapper,"/",crypt_get_dir(),NULL ) ; if( opts->ask_confirmation ){ printf( gettext( "\nWARNING, device \"%s\" will be overwritten with random data destroying all present data.\n" ),device ) ; printf( gettext( "Are you sure you want to proceed? Type \"YES\" and press enter if you are sure: " ) ) ; *confirm = StringGetFromTerminal_1( 3 ) ; if( *confirm == StringVoid ){ return zuluExit( stl,17 ) ; }else{ k = StringEqual( *confirm,gettext( "YES" ) ) ; if( k == 0 ){ if( zuluCryptSecurityGainElevatedPrivileges() ){ zuluCryptCloseMapper( StringContent( *mapper ) ) ; zuluCryptSecurityDropElevatedPrivileges() ; } return zuluExit( stl,5 ) ; } } } k = open( StringContent( *mapper ),O_WRONLY ) ; size = ( double ) blkid_get_dev_size( k ) ; memset( buffer,0,SIZE ) ; size_written = 0 ; prev_ratio = -1 ; while( write( k,buffer,SIZE ) > 0 ){ if( __exit_as_requested == 1 ){ break ; } size_written += SIZE ; ratio = ( int ) ( ( size_written / size ) * 100 ) ; if( ratio > prev_ratio ){ printf( "\r%s %d%%",gettext( "percentage complete: " ),ratio ) ; fflush( stdout ); prev_ratio = ratio ; } } close( k ) ; if( zuluCryptSecurityGainElevatedPrivileges() ){ zuluCryptCloseMapper( StringContent( *mapper ) ) ; zuluCryptSecurityDropElevatedPrivileges() ; } if( __exit_as_requested == 1 ){ return zuluExit( stl,15 ) ; }else{ return zuluExit( stl,3 ) ; } }
int zuluCryptEXERemoveKey( const struct_opts * opts,uid_t uid ) { int ask_confirmation = opts->ask_confirmation ; const char * device = opts->device ; const char * keyType = opts->key_source ; const char * keytoremove = opts->key ; stringList_t stl = StringListInit() ; string_t * pass = StringListAssign( stl ) ; string_t * confirm = StringListAssign( stl ) ; int status = 0 ; const char * key ; size_t key_size ; /* * zuluCryptPartitionIsSystemPartition() is defined in ./partitions.c */ if( zuluCryptPartitionIsSystemPartition( device,uid ) ){ if( !zuluCryptUserIsAMemberOfAGroup( uid,"zulucrypt" ) ){ return zuluExit( 4,stl ) ; } } /* * zuluCryptCanOpenPathForWriting is defined in path_access.c */ status = zuluCryptCanOpenPathForWriting( device,uid ) ; /* * 1-permissions denied * 2-invalid path * 3-shenanigans * 4-common error */ switch( status ){ case 0 : break ; case 1 : return zuluExit( 5,stl ) ; case 2 : return zuluExit( 5,stl ) ; case 3 : return zuluExit( 5,stl ) ; case 4 : return zuluExit( 5,stl ) ; default: return zuluExit( 5,stl ) ; } if( _zuluCryptExECheckEmptySlots( device ) == 3 ){ if( ask_confirmation ){ printf( gettext( "WARNING: There is only one key in the volume and all data in it will be lost if you continue.\n" ) ) ; printf( gettext( "Do you still want to continue? Type \"YES\" if you do: " ) ) ; *confirm = StringGetFromTerminal_1( 3 ) ; if( *confirm == StringVoid ){ return zuluExit( 6,stl ) ; } if( !StringEqual( *confirm,gettext( "YES" ) ) ){ return zuluExit( 7,stl ) ; } } } if( keyType == NULL ){ printf( gettext( "Enter a key to be removed: " ) ) ; /* * ZULUCRYPT_KEY_MAX_SIZE is set in ../constants.h */ switch( StringSilentlyGetFromTerminal_1( pass,ZULUCRYPT_KEY_MAX_SIZE ) ){ case 1 : return zuluExit( 8,stl ) ; case 2 : return zuluExit( 9,stl ) ; } printf( "\n" ) ; key = StringContent( *pass ) ; key_size = StringLength( *pass ) ; zuluCryptSecurityLockMemory_1( *pass ) ; }else{ if( keyType == NULL || keytoremove == NULL ){ return zuluExit( 10,stl ) ; } if( StringsAreEqual( keyType,"-f" ) ){ /* * zuluCryptGetPassFromFile() is defined at path_access.c" */ switch( zuluCryptGetPassFromFile( keytoremove,uid,pass ) ){ case 1 : return zuluExit( 11,stl ) ; case 2 : return zuluExit( 12,stl ) ; case 4 : return zuluExit( 13,stl ) ; case 5 : return zuluExit( 14,stl ) ; } key = StringContent( *pass ) ; key_size = StringLength( *pass ) ; zuluCryptSecurityLockMemory_1( *pass ) ; }else if( StringsAreEqual( keyType, "-p" ) ){ key = keytoremove ; key_size = StringSize( keytoremove ) ; }else{ return zuluExit( 10,stl ) ; } } zuluCryptSecurityGainElevatedPrivileges() ; /* * zuluCryptRemoveKey() is defined in ../lib/remove_key.c */ status = zuluCryptRemoveKey( device,key,key_size ) ; zuluCryptSecurityDropElevatedPrivileges() ; if( status == 1 ){ status = zuluExit_1( status,device,stl ) ; }else{ status = zuluExit( status,stl ) ; } /* * zuluCryptCheckInvalidKey() is defined in check_invalid_key.c */ zuluCryptCheckInvalidKey( opts->device ) ; return status ; }