Esempio n. 1
0
bool SecureJob::Crypt(const wxString &path, SecureData *data)
{   
	if(wxGetApp().GetAbort()){
		return true;
	}

    if(wxDirExists(path)){
	    wxDir dir(path);
	    wxString filename;
	    if(dir.GetFirst(&filename)){
		    do{
                wxFileName location = wxFileName(path + filename);
                RuleResult result = data->GetRules()->Matches(location);

                if((result == Excluded && location.IsDir()) || 
                  ((result == Included || result == NoMatch))){
                    //We recurse into subdirectories or to crypt files
                    Crypt(location.GetFullPath(), data);
                }
                else{
                    //Do nothing as we are either an excluded file or an 
                    //absolutely excluded folder
                }
		    }
		    while (dir.GetNext(&filename) );
	    }
    }
    else{
        RuleResult res = data->GetRules()->Matches(wxFileName::FileName(path));
        if(res != Excluded && res != AbsoluteExcluded){
            CryptFile(path, data);
        }
    }
	return true;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	DWORD dwFlags = 0;
	char szChoice[3];
	
	printf("\t\t---------KCrypt Engine v2.0 By KOrUPt---------\n\n");
	if(argc != 3){
		printf(
			"Usage: %s <target file> <encryption key>\n\n", argv[0]);
		return 0;
	}
	
	printf("[?] Does %s use PCODE markers? y/n ", argv[1]);
	fgets(szChoice, 2, stdin);
	if(szChoice[0] == 'y'){
		printf("[*] Encrypting marked code segments\n");
		if(CryptMem(argv[1], "..\\stub_files\\kmemcrypt\\kmc_stub", 0) != 1){
			printf("[-] An unknown error occurred whilst trying to memcrypt '%s'\n", argv[1]);
			return 0;
		}
	}
	
	fflush(stdin);
	printf("[?] Would you like %s to be crypted? y/n ", argv[1]);
	fgets(szChoice, 2, stdin);
	if(szChoice[0] == 'y'){
		fflush(stdin);
		printf("[?] Morph stub? y/n ");
		fgets(szChoice, 2, stdin);
		if(szChoice[0] == 'y')
			dwFlags |= MORPH_STUB;
		
		fflush(stdin);
		printf("[?] Add random Import Address Table? y/n ");
		fgets(szChoice, 2, stdin);
		if(szChoice[0] == 'y')
			dwFlags |= ADD_RANDOM_IAT;
	
		if(CryptFile(argv[1], "..\\stub_files\\kbincrypt\\kbc_stub", argv[2], dwFlags) != 1){
			printf("[-] An unknown error occurred whilst trying to filecrypt '%s'\n", argv[1]);
			return 0;
		}else printf("[+] %s crypted successfully\n\n", argv[1]);
	}
	
	return 1;
}
Esempio n. 3
0
int _tmain( int argc, wchar_t* argv[] )
{
	if ( argc < 2 )
	{
		wprintf( L"\n************************************************\n" );
		wprintf( L"ERROR: Not enough parameters!\n" );
		wprintf( L"Format: %s file_to_crypt.exe\n", argv[0] );
		wprintf( L"************************************************\n" );
		return 0;
	}

	DWORD dwFileAttributes = GetFileAttributes( argv[1] );

	if ( dwFileAttributes == INVALID_FILE_ATTRIBUTES )
	{
		int iError = GetLastError();
		wprintf( L"\n************************************************\n" );
		wprintf( L"ERROR: GetLastError(): 0x%X!\n", iError );
		wprintf( L"Format: %s file_to_crypt.exe\n", argv[0] );
		wprintf( L"************************************************\n" );
		return 0;
	}

	srand( GetTickCount() );

	if ( CryptFile( argv[1] ) )
	{
		wprintf( L"\n\n************************************************\n" );
		wprintf( L"File successfully crypted!\n" );
		wprintf( L"************************************************\n" );
	}
	else
	{
		wprintf( L"\n\n************************************************\n" );
		wprintf( L"Failed to crypt file!\n" );
		wprintf( L"************************************************\n" );
	}

	system( "pause" );

	return 0;
}
Esempio n. 4
0
static
rc_t FileToFile (const KDirectory * sd, const char * source,
                 KDirectory *dd, const char * dest_, bool try_rename,
                 char * base)
{
    const KFile * infile;
    rc_t rc;
    uint32_t access;
    KTime_t date;
    bool is_tmp;
    char dest [MY_MAX_PATH + sizeof EncExt];

    strcpy (dest, dest_);
    if (try_rename)
        NameFixUp (dest);

    if ((sd == dd) && (strcmp (source, dest) == 0))
        return FileInPlace (dd, dest, try_rename);

    if (base == NULL)
        STSMSG (1, ("%scrypting file %s to %s", De, source, dest));
    else
        STSMSG (1, ("%scrypting file %s to %s/%s", De, source, base, dest));

    /*
     * A Hack to make stdin/stout work within KFS
     */
    if (UseStdin)
    {
        const KFile * iinfile;
        rc = KFileMakeStdIn (&iinfile);
        if (rc == 0)
        {
            rc = KBufReadFileMakeRead (&infile, iinfile, 64 * 1024);
            KFileRelease (iinfile);
            if (rc == 0)
            {
                access = 0640;
                date = 0;
                goto stdin_shortcut;
            }
            LOGERR (klogErr, rc, "error wrapping stdin");
            return rc;
        }
    }
    rc = 0;
    is_tmp = IsTmpFile (source);

    if (is_tmp)
    {
        TmpFoundFlag = true;
        if (ForceFlag)
            ; /* LOG OVERWRITE */
        else
            ; /* LOG TMP */
    }
    if (!is_tmp || ForceFlag)
    {
        rc = KDirectoryAccess (sd, &access, "%s", source);
        if (rc)
            LOGERR (klogErr, rc, "Error check permission of source");

        else
        {
            rc = KDirectoryDate (sd, &date, "%s", source);
            if (rc)
                LOGERR (klogErr, rc, "Error check date of source");

            else
            {
                rc = KDirectoryOpenFileRead (sd, &infile, "%s", source);
                if (rc)
                    PLOGERR (klogErr, (klogErr, rc,
                                       "Error opening source file '$(S)'",
                                       "S=%s", source));
                else
                {
                    EncScheme scheme;

stdin_shortcut:
                    rc = EncryptionTypeCheck (infile, source, &scheme);
                    if (rc == 0)
                    {
                        KFile * outfile;
                        uint32_t kcm;

                        /*
                         * Hack to support stdout before VFS is complete enough to use here
                         */
                        if (UseStdout)
                        {
                            rc = KFileMakeStdOut (&outfile);
                            if (rc)
                                LOGERR (klogErr, rc, "error wrapping stdout");
                        }
                        else
                        {
                            kcm = ForceFlag ? kcmInit|kcmParents : kcmCreate|kcmParents;

                            rc = KDirectoryCreateFile (dd, &outfile, false, 0600, kcm, "%s", dest);
                            if (rc)
                                PLOGERR (klogErr,(klogErr, rc, "error opening output '$(O)'",
                                                  "O=%s", dest));
                        }
                        if (rc == 0)
                        {
                            const KFile * Infile;
                            KFile * Outfile;

                            rc = CryptFile (infile, &Infile, outfile, &Outfile, scheme);
                            if (rc == 0)
                            {
                                rc = CopyFile (Infile, Outfile, source, dest);
                                if (rc == 0)
                                {
                                    if (UseStdin || UseStdout)
                                        ;
                                    else
                                    {
                                        rc = KDirectorySetAccess (dd, false, access, 0777,
                                                                  "%s", dest);

                                        if (rc == 0 && date != 0)
                                            rc = KDirectorySetDate (dd, false, date, "%s", dest);
                                    }
                                }
                                KFileRelease (Infile);
                                KFileRelease (Outfile);
                            }
                            KFileRelease (outfile);
                        }
                    }
                    KFileRelease (infile);
                }
            }
        }
    }
    return rc;
}
Esempio n. 5
0
static
rc_t FileInPlace (KDirectory * cwd, const char * leaf, bool try_rename)
{
    rc_t rc;
    bool is_tmp;

    STSMSG (1, ("%scrypting file in place %s",De,leaf));

    rc = 0;
    is_tmp = IsTmpFile (leaf);

    if (is_tmp)
    {
        STSMSG (1, ("%s is a vdb-decrypt/vdb-encrypt temporary file and will "
                    "be ignored", leaf));
        TmpFoundFlag = true;
        if (ForceFlag)
            ; /* LOG OVERWRITE */
        else
            ; /* LOG TMP */
    }
    if (!is_tmp || ForceFlag)
    {
        char temp [MY_MAX_PATH];


        rc = KDirectoryResolvePath (cwd, false, temp, sizeof temp, ".%s%s",
                                    leaf, TmpExt);

        if (rc)
            PLOGERR (klogErr, (klogErr, rc, "unable to resolve '.$(S)$(E)'",
                               "S=%s,E=%s",leaf,TmpExt));
        else
        {
            KPathType kpt;
            uint32_t kcm;

            kcm = kcmCreate|kcmParents;
            kpt = KDirectoryPathType (cwd, temp);
            if (kpt != kptNotFound)
            {
                /* log busy */
                if (ForceFlag)
                {
                    kcm = kcmInit|kcmParents;
                    /* log force */
                    kpt = kptNotFound;
                }
            }

            if (kpt == kptNotFound)
            {
                const KFile * infile;

                rc = KDirectoryOpenFileRead (cwd, &infile, "%s", leaf);
                if (rc)
                    PLOGERR (klogErr, (klogErr, rc, "Unable to resolve '$(F)'",
                                       "F=%s",leaf));
                else
                {
                    EncScheme scheme;

                    rc = EncryptionTypeCheck (infile, leaf, &scheme);
                    if (rc == 0)
                    {
                        ArcScheme ascheme;
                        bool changed;
                        bool do_this_file;
                        char new_name [MY_MAX_PATH + sizeof EncExt];

                        do_this_file = DoThisFile (infile, scheme, &ascheme);
                        strcpy (new_name, leaf);
                        if (try_rename)
                            changed = NameFixUp (new_name);
                        else
                            changed = false;
                        /*                         KOutMsg ("### %d \n", changed); */

                        if (!do_this_file)
                        {
                            if (changed)
                            {
                                STSMSG (1, ("renaming %s to %s", leaf, new_name));
                                rc = KDirectoryRename (cwd, false, leaf, new_name);
                            }
                            else
                                STSMSG (1, ("skipping %s",leaf));
                        }
                        else
                        {
                            KFile * outfile;

                            rc = KDirectoryCreateExclusiveAccessFile (cwd, &outfile,
                                    false, 0600, kcm,
                                    temp);
                            if (rc)
                                ;
                            else
                            {
                                const KFile * Infile;
                                KFile * Outfile;

                                rc = CryptFile (infile, &Infile, outfile, &Outfile, scheme);

                                if (rc == 0)
                                {
                                    STSMSG (1, ("copying %s to %s", leaf, temp));

                                    rc = CopyFile (Infile, Outfile, leaf, temp);

                                    if (rc == 0)
                                    {
                                        uint32_t access;
                                        KTime_t date;

                                        rc = KDirectoryAccess (cwd, &access, "%s", leaf);
                                        if (rc == 0)
                                            rc = KDirectoryDate (cwd, &date, "%s", leaf);

                                        KFileRelease (infile);
                                        KFileRelease (outfile);
                                        KFileRelease (Infile);
                                        KFileRelease (Outfile);

                                        if (rc == 0)
                                        {
                                            STSMSG (1, ("renaming %s to %s", temp, new_name));

                                            rc = KDirectoryRename (cwd, true, temp, new_name);
                                            if (rc)
                                                LOGERR (klogErr, rc, "error renaming");
                                            else
                                            {
                                                if (changed)
                                                    KDirectoryRemove (cwd, false, "%s", leaf);

                                                /*rc =*/
                                                KDirectorySetAccess (cwd, false, access,
                                                                     0777, "%s", new_name);
                                                KDirectorySetDate (cwd, false, date, "%s", new_name);
                                                /* gonna ignore an error here I think */
                                                return rc;
                                            }
                                        }
                                    }
                                }
                                KFileRelease (outfile);
                            }
                        }
                    }
                    KFileRelease (infile);
                }
            }
        }
    }
    return rc;
}
Esempio n. 6
0
	BOOL c_era_interface::EncryptCampaignSaveFile(LPCSTR input_dir, LPCSTR filename, LPCSTR output_dir)
	{
		return CryptFile(input_dir, filename, k_encrypted_save_ext, output_dir, c_campaign_save_cryptor::EncryptMemory);
	}
Esempio n. 7
0
	BOOL c_era_interface::EncryptEraFile(LPCSTR input_dir, LPCSTR filename, LPCSTR output_dir)
	{
		return CryptFile(input_dir, filename, k_encrypted_era_ext, output_dir, c_era_cryptor::EncryptMemory);
	}