Exemplo n.º 1
0
        // 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));
            }
        }
Exemplo n.º 2
0
 public CCxxSource(ICCxxSource source) : this(source.SourceFiles)
 {
     EntryPointSymbolName = source.EntryPointSymbolName;
 }
Exemplo n.º 3
0
 public CCxxSourceParameterlessCFunction(ICCxxSource source, string functionName, IEnumerable <string> parameterTypes = null)
     : base(source)
 {
     FunctionName      = functionName;
     ParameterTypeList = parameterTypes ?? new List <string>();
 }
Exemplo n.º 4
0
 public SkeletonDllMainCCxxSource(ICCxxSource source, IEnumerable <string> exportedFunctions = null, bool mergeCCxxSources = true)
     : this(new [] { source }, exportedFunctions, mergeCCxxSources)
 {
 }
Exemplo n.º 5
0
 public DllMainCCxxSource(ICCxxSource source, IEnumerable <string> exportedFunctions = null, string entryPoint = "DllMain")
     : this(source.SourceFiles, exportedFunctions ?? Enumerable.Empty <string>(), entryPoint : entryPoint)
 {
 }
Exemplo n.º 6
0
        private static readonly string FuncDeclarationImplementionFunctionsRegex = @"([\.\w]+)!(\w+)"; // Capture Groups: ( dll name , function name)

        public ShellcodeCCxxSource(ICCxxSource source) : base(source)
        {
        }
Exemplo n.º 7
0
 public ShellcodeCCxxSourceParameterlessCFunction(ICCxxSource source)
     : base(source)
 {
 }
Exemplo n.º 8
0
 public ExeMainCCxxSource(ICCxxSource source, string entryPoint = "main")
     : this(source.SourceFiles, entryPoint : entryPoint)
 {
 }
Exemplo n.º 9
0
 StaticLibrary <Win64ObjectFile> ICCxxCompiler <Win64ObjectFile> .Compile(ICCxxSource source)
 {
     return(Compile <Win64ObjectFile>(source, TargetArch.x64, x => new Win64ObjectFile(x)));
 }