//------------------------------------------------ //--- 010 Editor v4.0.1 Script File // // File: XORSelectionHex.1sc // Authors: yoggy // Website: https://github.com/yoggy // Version: 1.2 // Purpose: Similar to XORSelection.1sc but you can enter // the XOR key in HEX style. // Category: Binary // History: // 1.2 2017-01-04 SweetScape: XOR key now accepted in different formats (e.g. 'a0f2a7', 'a0,f2,a7' or 'a0 f2 a7'). // 1.1 2016-02-10 SweetScape Software: Updated header for repository submission. // 1.0 yoggy: Initial release. //------------------------------------------------ int i; int iStart, size, iKeyLength, iHexKeyLength; string sKey, sHexKey = ""; char cHex; string sHex; string sTemp; // Check that a file is open if (FileCount() == 0) { MessageBox(idOk, "XORSelectionHex", "XORSelectionHex can only be executed when a file is loaded."); return -1; } // Initializes the variables size = GetSelSize(); iStart = GetSelStart(); // Check that bytes were selected if (size == 0) { MessageBox( idOk, "XORSelectionHex", "Please select bytes before running this script." ); return -1; } // input hex key string sKey = InputString("XORSelectionHex", "Input the XOR hex key (ex.\"50,4b,03,04\" or \"a0f2a7\")", "50,4b,03,04"); if (sKey == "") { MessageBox(idOk, "XORSelectionHex", "Please enter a valid hex key."); return -1; } iKeyLength = Strlen(sKey); iHexKeyLength = 0; (int)((iKeyLength / 3.0) + 1.0); i = 0; while( i < iKeyLength-1 ) { sHex = SubStr(sKey, i, 2); SScanf(sHex, "%02x", cHex); sHexKey += (cHex & (char)0xff); iHexKeyLength++; i+=2; // Allow spaces or commas between hex codes if( (i < iKeyLength) && ((sKey[i] == ' ') || (sKey[i] == ',')) ) i++; } Printf("key=%s\n", sHexKey); // Modify the selection for (i = 0; i < size; i++) { WriteUByte(iStart + i, ReadUByte(iStart + i) ^ sHexKey[i % iHexKeyLength]); }