// TODO: Support compiling source files recursively private StaticLibrary <T> Compile <T>(ICCxxSource source, TargetArch targetArch, Func <byte[], T> TConstructor) where T : ObjectFile, new() { switch (targetArch) { case TargetArch.x86: CConfig.MACHINE = Config.Machine.X86; break; case TargetArch.x64: CConfig.MACHINE = Config.Machine.X64; break; case TargetArch.arm: case TargetArch.arm64: CConfig.MACHINE = Config.Machine.ARM; break; } using (new TemporaryContext()) { var exts = new HashSet <string>(); foreach (var sourceFile in source.SourceFiles) { File.WriteAllText(sourceFile.Filename, sourceFile.Source); if (sourceFile.Type == CCxxSourceFileType.C || sourceFile.Type == CCxxSourceFileType.Cxx) { exts.Add(Path.GetExtension(sourceFile.Filename)); } } var sourceFilenames = exts.Select(ext => "*" + ext); var compilerOptions = CConfig.ToString(); var compileCommand = $"cl.exe /c /nologo /diagnostics:column {compilerOptions} {string.Join(" ", sourceFilenames)}"; var msvcVersion = version.ToString().Replace("v", "").Replace("_", "."); var compileBatFile = @"call ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\VCVARSALL.bat"" {0} -vcvars_ver=" + msvcVersion + "\r\n" + compileCommand; compileBatFile = String.Format(compileBatFile, targetArch.ToString()); File.WriteAllText("compile.bat", compileBatFile); var proc = Process.Start("cmd.exe", "/c " + "compile.bat"); proc.WaitForExit(); string[] objectFilePaths = Directory.GetFiles(".", "*.obj", SearchOption.AllDirectories); var objectFiles = objectFilePaths.ToList().Select((file) => TConstructor(File.ReadAllBytes(file))).ToList(); return(new StaticLibrary <T>(objectFiles)); } }
public CCxxSource(ICCxxSource source) : this(source.SourceFiles) { EntryPointSymbolName = source.EntryPointSymbolName; }
public CCxxSourceParameterlessCFunction(ICCxxSource source, string functionName, IEnumerable <string> parameterTypes = null) : base(source) { FunctionName = functionName; ParameterTypeList = parameterTypes ?? new List <string>(); }
public SkeletonDllMainCCxxSource(ICCxxSource source, IEnumerable <string> exportedFunctions = null, bool mergeCCxxSources = true) : this(new [] { source }, exportedFunctions, mergeCCxxSources) { }
public DllMainCCxxSource(ICCxxSource source, IEnumerable <string> exportedFunctions = null, string entryPoint = "DllMain") : this(source.SourceFiles, exportedFunctions ?? Enumerable.Empty <string>(), entryPoint : entryPoint) { }
private static readonly string FuncDeclarationImplementionFunctionsRegex = @"([\.\w]+)!(\w+)"; // Capture Groups: ( dll name , function name) public ShellcodeCCxxSource(ICCxxSource source) : base(source) { }
public ShellcodeCCxxSourceParameterlessCFunction(ICCxxSource source) : base(source) { }
public ExeMainCCxxSource(ICCxxSource source, string entryPoint = "main") : this(source.SourceFiles, entryPoint : entryPoint) { }
StaticLibrary <Win64ObjectFile> ICCxxCompiler <Win64ObjectFile> .Compile(ICCxxSource source) { return(Compile <Win64ObjectFile>(source, TargetArch.x64, x => new Win64ObjectFile(x))); }