unsigned int StandardEncryption::IsFileEncrypted (char *szFilename) { unsigned long lSigone = 0; unsigned long lSigtwo = 0; unsigned long lSigthree = 0; unsigned long lSigfour = 0; bool bSigmatch = true; // If the file is not large enough to hold the signature then return false; if (GetFileSize (szFilename) < (sizeof (unsigned long) * 4)) { OutputText ("File not large enough to be encrypted."); return CRYPTRES_NOTENCRYPTED; } FILE *hSource; if (hSource = fopen (szFilename, "rb")) { // Return nothing } else { OutputText ("Unable to open file for reading!"); return CRYPTRES_FAILED; } fread (&lSigone, 1, sizeof (unsigned long), hSource); fread (&lSigtwo, 1, sizeof (unsigned long), hSource); fread (&lSigthree, 1, sizeof (unsigned long), hSource); fread (&lSigfour, 1, sizeof (unsigned long), hSource); if (lSigone != m_lMagicone) { bSigmatch = false; } if (lSigtwo != m_lMagictwo) { bSigmatch = false; } if (lSigthree != m_lMagicthree) { bSigmatch = false; } if (lSigfour != m_lMagicfour) { bSigmatch = false; } if(hSource) { if(fclose(hSource)) { OutputText ("Unable to close file!"); } } if (bSigmatch == true) { return CRYPTRES_ENCRYPTED; } else { return CRYPTRES_NOTENCRYPTED; } }
void UConsole::Serialize( const TCHAR* V, ELogVerbosity::Type Verbosity, const class FName& Category ) { // e.g. UE_LOG(LogConsoleResponse, Display, TEXT("Test")); static const FName LogConsoleResponse = FName("LogConsoleResponse"); if (Category == LogConsoleResponse) { // log all LogConsoleResponse OutputText(V); } else { static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("con.MinLogVerbosity")); if(CVar) { int MinVerbosity = CVar->GetValueOnGameThread(); if((int)Verbosity <= MinVerbosity) { // log all that is >= the specified verbosity OutputText(V); } } } }
void windy::set_wind() { bool content = false; string s, thouHastSpoken; cout << string(50, '\n'); do { s = "\nPlease enter the wind speed to the nearest whole number: "; OutputText(s); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10); getline(cin, thouHastSpoken);//Get user input SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); content = is_number(thouHastSpoken); //checks if user input is a number if (content == true) { //if userinput is a number, transfer it to wind speed. stringstream(thouHastSpoken) >> wspeed; if (wspeed < 0) { wspeed = NULL; content = false; s = "Have mercy great ruler we cannot process this information!\n"; OutputText(s); } } else { cin.clear(); s = "Have mercy great ruler we cannot process this information!\n"; OutputText(s); } } while (content == false);
bool StandardEncryption::GetMD5Hash (char *szPassword, char *szOutbuf) { HCRYPTPROV hCryptProv; HCRYPTHASH hHash; BYTE bHash[0x7f]; DWORD dwHashLen= 16; // The MD5 algorithm always returns 16 bytes. DWORD cbContent= strlen (szPassword); BYTE* pbContent= (BYTE*) szPassword; char szFinal[SIZE_STRING]; ZeroMemory (szFinal, SIZE_STRING); char szCurchar[SIZE_NAME]; if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) { if(CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash)) { if(CryptHashData(hHash, pbContent, cbContent, 0)) { if(CryptGetHashParam(hHash, HP_HASHVAL, bHash, &dwHashLen, 0)) { for (int i=0;i<16;i++) { ZeroMemory (szCurchar, SIZE_NAME); sprintf_s (szCurchar, SIZE_NAME, "%02x", bHash[i]); strcat_s (szFinal, SIZE_STRING, szCurchar); } } else { OutputText ("GetMD5Hash: Error getting hash param!"); return false; } } else { OutputText ("GetMD5Hash: Error Hashing data!"); return false; } } else { OutputText ("GetMD5Hash: Error Creating Hash!"); return false; } } else { OutputText ("GetMD5Hash: Error Aquiring Context!"); return false; } ZeroMemory (szOutbuf, SIZE_STRING); strcpy_s (szOutbuf, SIZE_STRING, szFinal); CryptDestroyHash(hHash); CryptReleaseContext(hCryptProv, 0); return true; }
void Diagnostics::ParseCommandLine (char *pszCmdline) { //MessageBox (NULL, "Hello", "Info", MB_OK); //MessageBox (NULL, pszCmdline, "Command Line", MB_OK); char szAction[SIZE_STRING]; ZeroMemory (szAction, SIZE_STRING); char szPath[SIZE_STRING]; ZeroMemory (szPath, SIZE_STRING); bool bDiagmode = false; strncpy_s (szAction, SIZE_STRING, pszCmdline, 5); if (strcmp (szAction, "/diag") == 0) { OutputInt ("CmdLine length: ", strlen (pszCmdline)); OutputText ("Time to enter diagnostic mode..."); bDiagmode = true; Show (); } }
void StandardEncryption::MyHandleError(char *s) { DWORD dwError = GetLastError (); char szOutput[SIZE_STRING]; ZeroMemory (szOutput, SIZE_STRING); sprintf_s (szOutput, SIZE_STRING, "An error occurred in running the cipher routine. \n"); OutputText (szOutput); ZeroMemory (szOutput, SIZE_STRING); sprintf_s (szOutput, SIZE_STRING, "%s\n",s); OutputText (szOutput); ZeroMemory (szOutput, SIZE_STRING); sprintf_s (szOutput, SIZE_STRING, "Error number %i.\n", dwError); OutputText (szOutput); } // end MyHandleError
void Encryption::OutputSeed () { char szOutput[SIZE_LARGESTRING]; ZeroMemory (szOutput, SIZE_LARGESTRING); strncpy (szOutput, (char *) m_memSeed.GetBuffer (), m_memSeed.GetAppendPointer ()); OutputText (szOutput); //OutputInt ("m_memSeed Size: ", m_memSeed.GetSize ()); //OutputInt ("m_memSeed Append: ", m_memSeed.GetAppendPointer ()); }
void CPlayerStatusDialog::Clear() { m_strAnalysis.Empty(); m_bAutoHintMode = FALSE; m_nCurrentOutputLevel = 0; m_nOverrideOutputLevel = 0; // m_bCopyHintBlock = FALSE; m_strHintBlock.Empty(); // OutputText(); }
// // AddTrace() // // - adds text to the status dialog text buffer. The window is // updated with the new text only if there's a newline character // in the text. // void CPlayerStatusDialog::AddTrace(const CString& strText) { // no analysis if in express autoplay or output is suppressed #ifdef _TESTING if (m_bSuppressOutput) return; #else if (theApp.InExpressAutoPlay() || m_bSuppressOutput) return; #endif // need to be either printing analysis or providing a hint if (!theApp.GetValue(tbEnableAnalysisTracing) && !m_bCopyHintBlock) return; // CString strNewText; BOOL bOutputText = ConvertNewlines(strNewText, strText); if (m_bSuppressStream) { if (bOutputText) m_bSuppressStream = FALSE; // reset } else { // show analysis notes if enabled if (theApp.GetValue(tbEnableAnalysisTracing)) { m_strAnalysis += strNewText; if (bOutputText) OutputText(); } // and update hint window // if (m_bAutoHintMode && m_bCopyHintBlock && (m_nSuspendHints == 0) && if (m_bCopyHintBlock && (m_nSuspendHints == 0) && (m_nCurrentOutputLevel <= m_nRequiredHintTraceLevel)) { // route to the autohint window m_strHintBlock += strNewText; CAutoHintDialog* pHintDlg = (CAutoHintDialog*) pMAINFRAME->GetDialog(twAutoHintDialog); pHintDlg->SetHintText(m_strHintBlock); } } }
void GameConsoleWindow::ParseText(CEGUI::String inMsg) { // I personally like working with std::string. So i'm going to convert it here. std::string inString = inMsg.c_str(); if (inString.length() >= 1) // Be sure we got a string longer than 0 { if (inString.at(0) == '/') // Check if the first letter is a 'command' { std::string::size_type commandEnd = inString.find(" ", 1); std::string command = inString.substr(1, commandEnd - 1); std::string commandArgs = inString.substr(commandEnd + 1, inString.length() - (commandEnd + 1)); //convert command to lower case for(std::string::size_type i=0; i < command.length(); i++) { command[i] = tolower(command[i]); } // Begin processing if (command == "say") { std::string outString = "You:" + inString; // Append our 'name' to the message we'll display in the list OutputText(outString); } else if (command == "quit") { // do a /quit } else if (command == "help") { // do a /help } else { std::string outString = "<" + inString + "> is an invalid command."; (this)->OutputText(outString,CEGUI::Colour(1.0f,0.0f,0.0f)); // With red ANGRY colors! } } // End if else { (this)->OutputText(inString); // no commands, just output what they wrote } } }
void UConsole::ConsoleCommand(const FString& Command) { // insert into history buffer { HistoryBuffer.Add(Command); NormalizeHistoryBuffer(); } // Save the command history to the INI. SaveConfig(); OutputText(FString::Printf(TEXT("\n>>> %s <<<"), *Command)); UWorld *World = GetOuterUGameViewportClient()->GetWorld(); if(ConsoleTargetPlayer != NULL) { // If there is a console target player, execute the command in the player's context. ConsoleTargetPlayer->PlayerController->ConsoleCommand(Command); } else if(World && World->GetPlayerControllerIterator()) { // If there are any players, execute the command in the first player's context that has a non-null Player. for (auto PCIter = World->GetPlayerControllerIterator(); PCIter; ++PCIter) { APlayerController* PC = *PCIter; if (PC && PC->Player) { PC->ConsoleCommand(Command); break; } } } else { // Otherwise, execute the command in the context of the viewport. GetOuterUGameViewportClient()->ConsoleCommand(Command); } }
void Encryption::DoSingleCipher (HWND hWnd, MemoryBuffer *pinbuffer, MemoryBuffer *poutbuffer, bool bEncrypt) { // SINGLE THREADED FUNCTION // This will spawn the single thread for single threaded encryption. // This is the parent function for single threaded encryption. if (m_bHivecreated == false) { OutputText ("SingleCipher: Hive not created!"); return; } m_hwnd = hWnd; m_outbuffer = poutbuffer; m_pinbuffer_thall = pinbuffer; m_bEncrypt_thall = bEncrypt; m_bsinglethreaddone = false; m_progresssingle = 0; m_lastpercentage = 0; // Start the single cipher thread DoCipherThread (); }
void CPlayerStatusDialog::Trace(const CString& strText) { // sanity check CString strOutput = strText; if (strOutput.IsEmpty() || m_bSuppressStream) return; // AfxMessageBox(strText); // NCR TESTING SHows many types of messages!!!!!!!!!!!! // no analysis if in express autoplay or output is suppressed #ifdef _TESTING if (m_bSuppressOutput) return; #else if (theApp.InExpressAutoPlay() || m_bSuppressOutput) return; #endif // need to be either printing analysis or providing a hint if (!theApp.GetValue(tbEnableAnalysisTracing) && !m_bCopyHintBlock) return; // get and test the trace level int nTraceLevelLimit = theApp.GetValue(tnAnalysisTraceLevel); m_nCurrentOutputLevel = 0; // see if a verbosity escape code is present if (strOutput[0] == '!') { m_bIgnoreStreamLevel = TRUE; strOutput = strOutput.Mid(1); } else { m_bIgnoreStreamLevel = FALSE; } // see if a verbosity level code is present if (isdigit(strOutput[0])) m_nCurrentOutputLevel = strOutput[0] - '0'; else m_nCurrentOutputLevel = tnDefaultTraceLevel; // look for an autohint bypass (not so informative information) BOOL bSkipAutoHint = FALSE; if (strOutput[0] == _T('$')) { bSkipAutoHint = TRUE; strOutput = strOutput.Mid(1); } // check for temporary stream level override if ((m_nOverrideOutputLevel > 0) && (!m_bIgnoreStreamLevel)) m_nCurrentOutputLevel = m_nOverrideOutputLevel; // skip if the verbosity in the stream is too high if (m_nCurrentOutputLevel > nTraceLevelLimit) { // if this string doesn't contain a CR, suppress remainder of output stream if (strOutput.Find('\n') < 0) m_bSuppressStream = TRUE; return; } // strip the verbosity level digit if (isdigit(strOutput[0])) strOutput = strOutput.Mid(1); // convert newlines CString strNewText; BOOL bOutputText = ConvertNewlines(strNewText, strOutput); // show analysis notes if (theApp.GetValue(tbEnableAnalysisTracing)) { m_strAnalysis += strNewText; if (bOutputText) OutputText(); } // and show hints // if (m_bAutoHintMode && m_bCopyHintBlock && !bSkipAutoHint && (m_nSuspendHints == 0) && if (m_bCopyHintBlock && !bSkipAutoHint && (m_nSuspendHints == 0) && (m_nCurrentOutputLevel <= m_nRequiredHintTraceLevel)) { // route to the autohint window m_strHintBlock += strNewText; CAutoHintDialog* pHintDlg = (CAutoHintDialog*) pMAINFRAME->GetDialog(twAutoHintDialog); pHintDlg->SetHintText(m_strHintBlock); } }
bool StandardEncryption::EncryptBuffer (MemoryBuffer *memSource, PCHAR szPassword, bool bEncrypt) { HCRYPTPROV hCryptProv; HCRYPTHASH hHash; HCRYPTKEY hKey; DWORD dwBufferlen; DWORD dwBufsize; MemoryBuffer memOutput; // Get the handle to the default provider. if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROVIDER , 0)) { //printf("A cryptographic provider has been acquired. \n"); } else { MyHandleError("Error during CryptAcquireContext!"); return false; } if(!szPassword ) { return false; } else { // Create a hash object. if(CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash)) { //printf("A hash object has been created. \n"); } else { MyHandleError("Error during CryptCreateHash!"); return false; } //------------------------------------------------------------------- // Hash the password. if(CryptHashData(hHash, (BYTE *)szPassword, strlen(szPassword), 0)) { //printf("The password has been added to the hash. \n"); } else { MyHandleError("Error during CryptHashData."); return false; } //------------------------------------------------------------------- // Derive a session key from the hash object. if(CryptDeriveKey(hCryptProv, m_Currentalg, hHash, m_dwKeylength, &hKey)) { //printf("An encryption key is derived from the password hash. \n"); } else { MyHandleError("Error during CryptDeriveKey!"); return false; } //------------------------------------------------------------------- // Destroy hash object. if(hHash) { if(!(CryptDestroyHash(hHash))) { MyHandleError("Error during CryptDestroyHash"); return false; } hHash = 0; } // Encrypt / Decrypt data. if (bEncrypt == true) { // First get the size of the buffer needed. dwBufferlen = memSource->GetSize (); dwBufsize = memSource->GetSize (); CryptEncrypt (hKey, 0, TRUE, 0, NULL, &dwBufferlen, dwBufsize); if (dwBufferlen > 0) { dwBufsize = dwBufferlen; memOutput.SetSize (dwBufferlen); memOutput.Write (memSource->GetBuffer (), 0, memSource->GetSize ()); if (!CryptEncrypt (hKey, 0, FALSE, 0, (BYTE *) memOutput.GetBuffer (), &dwBufferlen, dwBufsize)) { MyHandleError ("Error during Encrypt."); return false; } else { memSource->Clear (); memSource->SetSize (memOutput.GetSize ()); memSource->Write (memOutput.GetBuffer (), 0, memOutput.GetSize ()); memOutput.Clear (); } } else { OutputText ("Unable to obtain encrypted buffer size."); return false; } } else { dwBufferlen = memSource->GetSize (); memOutput.SetSize (dwBufferlen); memOutput.Write (memSource->GetBuffer (), 0, memSource->GetSize ()); if (!CryptDecrypt (hKey, 0, FALSE, 0, (BYTE *) memOutput.GetBuffer (), &dwBufferlen)) { MyHandleError ("Error during Decrypt."); return false; } else { memSource->Clear (); memSource->SetSize (dwBufferlen); memSource->Write (memOutput.GetBuffer (), 0, dwBufferlen); memOutput.Clear (); } } //------------------------------------------------------------------- // Destroy the session key. if(hKey) { if(!(CryptDestroyKey(hKey))) { MyHandleError("Error during CryptDestroyKey"); return false; } } //------------------------------------------------------------------- // Release the provider handle. if(hCryptProv) { if(!(CryptReleaseContext(hCryptProv, 0))) { MyHandleError("Error during CryptReleaseContext"); return false; } } return true; } }
void ShowMessage(void) { if (messageTimeout <= 0) return; messageTimeout--; OutputText(message); }
bool Encryption::DoPartCipher (HWND hWnd, MemoryBuffer *pinbuffer, unsigned long istartoffset, unsigned long ilength, unsigned long rndHive, unsigned int msgprogress, bool Encrypt) { // MULTI-THREADED FUNCTION // This function is designed to execute in a seperate thread. Part of the multi-threaded // encryption. It only encrypts a part of the input buffer given by the offset and length. // the output is placed in a member output buffer which all threads have access to. // On a Core Duo or HT processor, this will maximise the usage of both CPU cores, or windows. int algsize = 100; unsigned long hivepointer = 0; unsigned long inputoffset = 0; // not to be confused with start offset unsigned long outputoffset = sizeof (unsigned long); int algpointer = 0; unsigned long i = 0; unsigned long iprogress = 0; unsigned long lpercentage = 0; int cTrans = 0; // Transposition value int cAlg = 0; // Transposition multiplier unsigned long cProduct = 0; // Product of Trans * cAlg bool cShift = 0; // The transposition shift - up or down BYTE cByte = 0; // The current byte we're encrypting. if (m_bHivecreated == false) { OutputText ("DoPartCipher: ", "Key hive not created."); return false; } else { if (m_tmpBuffer.GetSize () == 0) { OutputText ("DoPartCipher: ", "Result buffer size not set"); return false; } else { // Remember here we're not generated a random value to get the hive value // this time it is given to us by the part manager. // For decryption we must be told to be offset by the length of any header values // We need to now set the initial hive pointer and alg pointer // values given the start offset we're about to process. hivepointer = ForwardIntEx (istartoffset, m_memHive.GetAppendPointer ()-2); algpointer = ForwardIntEx (istartoffset, algsize); // Start the encryption process for this part for (i=istartoffset;i<istartoffset+ilength;i++) { cTrans = GetHiveValue (hivepointer, 2); cAlg = GetHiveValue (rndHive+algpointer, 1); if (cAlg <= 5) { cShift = true; // true means we transpose up } else { cShift = false; // false means we transpose down } // Now transpose the byte given the values we have. //if (Encrypt == true) { cByte = pinbuffer->GetByte (i); //} else { // cByte = pinbuffer->GetByte (i+outputoffset); //} cProduct = cTrans * cAlg; if (Encrypt == true) { if (cShift == true) { cByte+=cProduct; } else { cByte-=cProduct; } } else { if (cShift == true) { cByte-=cProduct; } else { cByte+=cProduct; } } if (Encrypt == true) { m_tmpBuffer.Write (&cByte, i+outputoffset, sizeof (BYTE)); } else { m_tmpBuffer.Write (&cByte, i, sizeof (BYTE)); } hivepointer+=2; algpointer++; iprogress++; if (iprogress > 50000) { iprogress = 0; lpercentage = (i * 50) / (istartoffset+ilength); //OutputInt ("cipher: ", i); PostMessage (hWnd, CRYPT_MSG, msgprogress, (LPARAM) lpercentage); } if (hivepointer >= m_memHive.GetAppendPointer ()-2) { hivepointer = 0; } if (algpointer >= algsize) { algpointer = 0; } } PostMessage (hWnd, CRYPT_MSG, msgprogress, (LPARAM) -1); return true; } } }
bool UConsole::InputKey_InputLine( int32 ControllerId, FKey Key, EInputEvent Event, float AmountDepressed, bool bGamepad) { //`log(`location@`showvar(Key)); if ( Event == IE_Pressed ) { bCaptureKeyInput = false; } // cycle between console states bool bModifierDown = bCtrl; FModifierKeysState KeyState = FSlateApplication::Get().GetModifierKeys(); bModifierDown |= KeyState.IsAltDown() || KeyState.IsCommandDown() || KeyState.IsShiftDown() || KeyState.IsControlDown(); if ( GetDefault<UInputSettings>()->ConsoleKeys.Contains(Key) && Event == IE_Pressed && !bModifierDown ) { if (ConsoleState == NAME_Typing) { FakeGotoState(NAME_Open); bCaptureKeyInput = true; } else if (ConsoleState == NAME_Open) { FakeGotoState(NAME_None); bCaptureKeyInput = true; } else if (ConsoleState == NAME_None) { FakeGotoState(NAME_Typing); bCaptureKeyInput = true; } return true; } // if user input is open if(ConsoleState != NAME_None) { if (ProcessControlKey(Key, Event)) { return true; } else if( bGamepad ) { return false; } else if( Key == EKeys::Escape && Event == IE_Released ) { if( !TypedStr.IsEmpty() ) { SetInputText(""); SetCursorPos(0); AutoCompleteIndex = 0; AutoCompleteCursor = -1; AutoComplete.Empty(); bAutoCompleteLocked = false; return true; } else { FakeGotoState( NAME_None ); } return true; } else if (Key == EKeys::Tab && Event == IE_Pressed) { if (!bAutoCompleteLocked) { SetInputLineFromAutoComplete(); } return true; } else if( Key == EKeys::Enter && Event == IE_Released ) { if( !TypedStr.IsEmpty() ) { // Make a local copy of the string. FString Temp=TypedStr; SetInputText(TEXT("")); SetCursorPos(0); ConsoleCommand(Temp); //OutputText( Localize("Errors","Exec","Core") ); OutputText( TEXT("") ); if(ConsoleState == NAME_Typing) { // close after each command when in typing mode (single line) FakeGotoState(NAME_None); } UpdateCompleteIndices(); } else { FakeGotoState(NAME_None); } return true; } else if( Event != IE_Pressed && Event != IE_Repeat ) { if( !bGamepad ) { return Key != EKeys::LeftMouseButton && Key != EKeys::MiddleMouseButton && Key != EKeys::RightMouseButton; } return false; } else if( Key == EKeys::Up ) { if (!bCtrl) { if(AutoComplete.Num()) { if(AutoCompleteCursor + 1 < FMath::Min((int32)MAX_AUTOCOMPLETION_LINES, AutoComplete.Num())) { // move cursor within displayed region ++AutoCompleteCursor; } else { // can be negative int32 ScrollRegionSize = AutoComplete.Num() - (int32)MAX_AUTOCOMPLETION_LINES; // can we scroll? if(AutoCompleteIndex + 1 < ScrollRegionSize) { ++AutoCompleteIndex; } } SetInputLineFromAutoComplete(); } else { SetAutoCompleteFromHistory(); SetInputLineFromAutoComplete(); } } return true; } else if( Key == EKeys::Down ) { if (!bCtrl && AutoComplete.Num() > 1) { if(AutoCompleteCursor > 0) { // move cursor within displayed region --AutoCompleteCursor; } else { // can we scroll? if(AutoCompleteIndex > 0) { --AutoCompleteIndex; } bAutoCompleteLocked = false; } SetInputLineFromAutoComplete(); } } else if( Key==EKeys::BackSpace ) { if( TypedStrPos>0 ) { SetInputText(FString::Printf(TEXT("%s%s"), *TypedStr.Left(TypedStrPos-1), *TypedStr.Right( TypedStr.Len() - TypedStrPos))); SetCursorPos(TypedStrPos-1); // unlock auto-complete (@todo - track the lock position so we don't bother unlocking under bogus cases) bAutoCompleteLocked = false; } return true; } else if ( Key== EKeys::Delete ) { if ( TypedStrPos < TypedStr.Len() ) { SetInputText(FString::Printf(TEXT("%s%s"), *TypedStr.Left(TypedStrPos), *TypedStr.Right( TypedStr.Len() - TypedStrPos - 1))); } return true; } else if ( Key==EKeys::Left ) { if (bCtrl) { // find the nearest '.' or ' ' int32 NewPos = FMath::Max(TypedStr.Find(TEXT("."), ESearchCase::CaseSensitive, ESearchDir::FromEnd, TypedStrPos),TypedStr.Find(TEXT(" "),ESearchCase::CaseSensitive, ESearchDir::FromEnd,TypedStrPos)); SetCursorPos(FMath::Max(0,NewPos)); } else { SetCursorPos(FMath::Max(0, TypedStrPos - 1)); } return true; } else if ( Key==EKeys::Right ) { if (bCtrl) { // find the nearest '.' or ' ' int32 SpacePos = TypedStr.Find(TEXT(" ")); int32 PeriodPos = TypedStr.Find(TEXT(".")); // pick the closest valid index int32 NewPos = SpacePos < 0 ? PeriodPos : (PeriodPos < 0 ? SpacePos : FMath::Min(SpacePos,PeriodPos)); // jump to end if nothing in between if (NewPos == INDEX_NONE) { NewPos = TypedStr.Len(); } SetCursorPos(FMath::Min(TypedStr.Len(),FMath::Max(TypedStrPos,NewPos))); } else { SetCursorPos(FMath::Min(TypedStr.Len(), TypedStrPos + 1)); } return true; } else if ( Key==EKeys::Home ) { SetCursorPos(0); return true; } else if ( Key==EKeys::End ) { SetCursorPos(TypedStr.Len()); return true; } else { // auto complete is open and the user adds a key if (AutoComplete.Num() > 0 && !bAutoCompleteLocked && AutoCompleteCursor >= 0) { const FAutoCompleteCommand& Cmd = AutoComplete[AutoCompleteIndex + AutoCompleteCursor]; TypedStr = Cmd.Command; SetCursorPos(TypedStr.Len()); bAutoCompleteLocked = true; // no "return true" so that the following key will be added the auto completed string } } } return false; }
bool Encryption::DoCipher (HWND hWnd, MemoryBuffer *pinbuffer, MemoryBuffer *poutbuffer, bool bEncrypt) { // Single threaded encryption function. Operates in a seperate thread, but a single thread // only. Unfortunately on a Core Duo, or HT processor, it will only max out one of the CPU // windows. MemoryBuffer tmpBuffer; unsigned long rndHive = 0; int algsize = 100; unsigned long hivepointer = 0; unsigned long inputoffset = 0; unsigned long iprogress = 0; unsigned long ipercentage = 0; int algpointer = 0; unsigned long i = 0; int cTrans = 0; // Our transposition value int cAlg = 0; // The algorithm we use alongside the transposition value unsigned long cProduct = 0; // This value is the current result of the transposition multiplication bool cShift = 0; // The transposition shift - up or down BYTE cByte = 0; // The current byte we're working on. if (m_bHivecreated == false) { OutputText ("Encryption: ", "Key hive not created."); return false; } else { tmpBuffer.SetSize ((pinbuffer->GetSize ()+sizeof (unsigned long))*2); OutputInt ("DoCipher: ", pinbuffer->GetSize ()*2); // Generate a random number between 0 and the size of the hive // minus 100 (we use 100 single digits for determining the transposition // shift mechanism and transposition multiplier if (bEncrypt == true) { rndHive = GetRand (m_memHive.GetAppendPointer ()-algsize); tmpBuffer.Append (&rndHive, sizeof (unsigned long)); } else { memcpy (&rndHive, pinbuffer->GetBuffer (), sizeof (unsigned long)); inputoffset+=sizeof (unsigned long); } for (i=0;i<pinbuffer->GetSize ()-inputoffset;i++) { cTrans = GetHiveValue (hivepointer, 2); cAlg = GetHiveValue (rndHive+algpointer, 1); if (cAlg <= 5) { cShift = true; // true means we transpose up } else { cShift = false; // false means we transpose down } // Now transpose the current byte given the current hive value // algorithm value and shift direction. cByte = pinbuffer->GetByte (i+inputoffset); cProduct = cTrans * cAlg; if (bEncrypt == true) { if (cShift == true) { cByte+=cProduct; } else { cByte-=cProduct; } } else { if (cShift == true) { cByte-=cProduct; } else { cByte+=cProduct; } } tmpBuffer.Append (&cByte, sizeof (BYTE)); hivepointer+=2; algpointer++; if (hivepointer >= m_memHive.GetAppendPointer ()-2) { hivepointer = 0; } if (algpointer >= algsize) { algpointer = 0; } iprogress++; if (iprogress > 10000) { iprogress = 0; ipercentage = (i * 10) / (pinbuffer->GetSize ()-inputoffset); PostMessage (hWnd, CRYPT_MSG, CRYPT_PROGRESSSINGLE, (LPARAM) ipercentage*10); } } poutbuffer->SetSize (tmpBuffer.GetAppendPointer ()); poutbuffer->Append (tmpBuffer.GetBuffer (), tmpBuffer.GetAppendPointer ()); tmpBuffer.Clear (); PostMessage (hWnd, CRYPT_MSG, CRYPT_PROGRESSSINGLE, (LPARAM) -1); return true; } }
void Encryption::DoMultiCipher (HWND hWnd, MemoryBuffer *pinbuffer, MemoryBuffer *poutbuffer, bool bEncrypt) { // MULTI-THREADED FUNCTION // This is the function that spawns the smaller threads for multi-threaded encryption. // This can be thought of as the Multi Cipher parent function. // The idea is that this function delegates the whole encryption task to the two threads // that actually perform the encryption. if (m_bHivecreated == false) { OutputText ("MultiCipher: Hive not created!"); return; } m_hwnd = hWnd; m_outbuffer = poutbuffer; // First we make the input buffer accessible by the separate threads unsigned int algsize = 100; //unsigned long part1offset = 0; //unsigned long part1length = 0; //unsigned long part2offset = 0; //unsigned long part2length = 0; unsigned long partlength = 0; m_pinbuffer_thall = pinbuffer; m_bEncrypt_thall = bEncrypt; // Now we generate a random hive value that all the ciper parts will need if (bEncrypt == true) { m_rndHive_thall = GetRand (m_memHive.GetAppendPointer ()-algsize); } else { memcpy (&m_rndHive_thall, pinbuffer->GetBuffer (), sizeof (unsigned long)); } // Now we need to set the size of the working buffer if (bEncrypt == true) { m_tmpBuffer.SetSize ((pinbuffer->GetSize ()+sizeof (unsigned long))); } else { m_tmpBuffer.SetSize ((pinbuffer->GetSize ()-sizeof (unsigned long))); } // Now we need to write the random hive value to the working buffer if (bEncrypt == true) { m_tmpBuffer.Write (&m_rndHive_thall, 0, sizeof (unsigned long)); } // Now start delegating partlength = pinbuffer->GetSize () / 2; if (bEncrypt == true) { m_ilength_th1 = partlength; m_istartoffset_th1 = 0; m_istartoffset_th2 = partlength; m_ilength_th2 = pinbuffer->GetSize () - m_istartoffset_th2; } else { m_ilength_th1 = partlength; m_istartoffset_th1 = sizeof (unsigned long); m_istartoffset_th2 = partlength+sizeof (unsigned long); m_ilength_th2 = pinbuffer->GetSize () - m_istartoffset_th2; } OutputInt ("partlength: ", partlength); OutputInt ("m_istartoffset_th1: ", m_istartoffset_th1); OutputInt ("m_ilength_th1: ", m_ilength_th1); OutputInt ("m_istartoffset_th2: ", m_istartoffset_th2); OutputInt ("m_ilength_th2: ", m_ilength_th2); m_lastpercentage = 0; m_bthread1done = false; m_bthread2done = false; // Now Start Multi-Threaded Encryption!! DoCipher1 (); DoCipher2 (); }