I wrote this in C# because it's one of the best languages in the world, IF ONLY, it did not have to rely on the .NET Framework :(
All it does is go through files in the input folder, scan for strings and then use the XOR string function to make it l33ber.
P.S:
- Screw your Hungarian Notation :P
- A few tiny bugs but it shouldn't cause any major problems that you can't fix yourself.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace XORStringCrypter { class Program { static void Main(string[] args) { FileInfo[] files = new DirectoryInfo("./input").GetFiles(); foreach (FileInfo f in files) { ParseFile(f); } Console.ReadLine(); } static void ParseFile(FileInfo f) { StreamReader sr = new StreamReader(f.FullName); StreamWriter sw = new StreamWriter("./output/" + f.Name); string line; int numStrings = 0; while ((line = sr.ReadLine()) != null) { char[] lineData = line.ToCharArray(); List<string> lineStrings = new List<string>(); for (int i = 0; i < lineData.Length; i++) { char currentChar = lineData[i]; if (currentChar == '"') { string s = ""; for (int j = i + 1; j < lineData.Length; j++) { char currentChar_ = lineData[j]; if (currentChar_ == '"') // Reached end of String { //Console.WriteLine("end of string"); i = j; // Set index to end of string so it doesn't get read twice break; } else { //Console.WriteLine("appended "+currentChar_ +" to string"); s += currentChar_; } } lineStrings.Add(s); } } for (int k = 0; k < lineStrings.Count; k++) { //Console.WriteLine(lineStrings[k]); line = line.Replace("\"" + lineStrings[k] + "\"", GenerateXORCode(lineStrings[k])); numStrings++; } sw.WriteLine(line); } Console.WriteLine("Finished Processing " + f.Name + ", Parsed a total of " + numStrings + " strings."); sr.Close(); sw.Close(); } // Taken from xorgen.html (Don't know who coded it so creds to them, converted from Javascript to C# by Me) #region XOR Code static string validChars = " !\"#$%&'()*+'-./0123456789:;<=>?@"; static string GenerateXORCode(string textToEncrypt) { char[] text = textToEncrypt.ToCharArray(); int xorValueStart = GenerateRandomByte(text.Length + DateTime.Now.Millisecond); string xorStringTerminator = "0x" + DecimalToHex(GenerateRandomByte(text.Length * 2 + DateTime.Now.Millisecond)) + DecimalToHex(GenerateRandomByte(text.Length * 3 + DateTime.Now.Millisecond)) + DecimalToHex(GenerateRandomByte(text.Length * 4 + DateTime.Now.Millisecond)) + DecimalToHex(GenerateRandomByte(text.Length * 5 + DateTime.Now.Millisecond)); int finalLength = textToEncrypt.Length; string hexSequence = "\""; int xorValue = xorValueStart; for (int i = 0; i < textToEncrypt.Length; i++) { char currentCharacter = text[i]; int characterVal = 0; if (currentCharacter == '\\') { i++; currentCharacter = text[i]; if (currentCharacter == '\0') { characterVal = 0; } if (currentCharacter == '\n') { characterVal = 10; } if (currentCharacter == '\\') { characterVal = (int)ToAsciiCharacter('\\'); } if (currentCharacter == '\r') { characterVal = 13; } else { /*Console.WriteLine("Invalid control sequence: \\"+characterVal);*/ } finalLength--; } else if (currentCharacter == '|') { characterVal = 0; } else { characterVal = (int)ToAsciiCharacter(currentCharacter); if (characterVal == 0) { Console.WriteLine("Invalid character: \\" + characterVal); return String.Empty; } } characterVal ^= xorValue; xorValue += 1; xorValue %= 256; hexSequence += "\\x" + DecimalToHex((byte)characterVal); } hexSequence += "\""; string output = "/*" + textToEncrypt + "*/ XorStr<0x" + DecimalToHex((byte)xorValueStart) + ", " + finalLength + ", " + xorStringTerminator + ">("; output += hexSequence + " + " + xorStringTerminator + ").s"; return output; } static char ToAsciiCharacter(char c) { string lowerCaseAZ = "abcdefghijklmnopqrstuvwxyz"; validChars += lowerCaseAZ.ToUpper(); validChars += "[\\]^_`"; validChars += lowerCaseAZ; validChars += "{|}~"; int characterIndex = validChars.IndexOf(c); if (characterIndex > -1) { return (char)(32 + characterIndex); } return '\0'; } static string DecimalToHex(byte d) { string hexString = ""; string validHexChars = "0123456789ABCDEF"; int a = d % 16; int b = (d - a) / 16; hexString = validHexChars.ToCharArray()[b] + "" + validHexChars.ToCharArray()[a]; return hexString; } static byte GenerateRandomByte(int seed) { return (byte) (new Random(seed).Next() % 256); } #endregion } }
#define WIN32_LEAN_AND_MEAN #include <windows.h> #include "xorstr.h" BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved_arg) { if(reason == DLL_PROCESS_ATTACH) { MessageBox(NULL, "Hello World!", "This is a Message Box!", NULL); MessageBox(NULL, "This is a Message Box!", "Hello World!", NULL); } }
#define WIN32_LEAN_AND_MEAN #include <windows.h> #include "xorstr.h" BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved_arg) { if(reason == DLL_PROCESS_ATTACH) { MessageBox(NULL, /*Hello World!*/ XorStr<0x2D, 12, 0x636D7781>("\x65\x4B\x43\x5C\x5E\x12\x64\x5B\x47\x5A\x53\x19" + 0x636D7781).s, /*This is a Message Box!*/ XorStr<0x37, 22, 0xF5B2702D>("\x63\x50\x50\x49\x1B\x55\x4E\x1E\x5E\x60\x0C\x27\x30\x37\x24\x21\x22\x68\x0B\x25\x33\x6D" + 0xF5B2702D).s, NULL); MessageBox(NULL, /*This is a Message Box!*/ XorStr<0x37, 22, 0xF5B2702D>("\x63\x50\x50\x49\x1B\x55\x4E\x1E\x5E\x60\x0C\x27\x30\x37\x24\x21\x22\x68\x0B\x25\x33\x6D" + 0xF5B2702D).s, /*Hello World!*/ XorStr<0xAF, 12, 0xBAC4CED8>("\xE7\xD5\xDD\xDE\xDC\x94\xE2\xD9\xC5\xD4\xDD\x9B" + 0xBAC4CED8).s, NULL); } }
Comment