Пример #1
0
    static BindGemResult MakeBindGemResultFor(NPath fileName, CSharpProgramConfiguration config)
    {
        NPath prefix = $"artifacts/bindgen/{fileName.FileNameWithoutExtension}-{config.Identifier}/bind-{fileName.FileNameWithoutExtension.Replace(".", "_")}";

        return(new BindGemResult()
        {
            Header = prefix.ChangeExtension("h"),
            Cpp = prefix.ChangeExtension("cpp"),
        });
    }
Пример #2
0
        void Write(AssemblyDefinition assemblyToPatch, NPath assemblyToPatchPath, PatchOptions patchOptions = default)
        {
            // atomic write of file with backup
            // TODO: skip backup if existing file already patched. want the .orig to only be the unpatched file.

            // write to tmp and release the lock
            var tmpPath = assemblyToPatchPath.ChangeExtension(".tmp");

            tmpPath.DeleteIfExists();
            assemblyToPatch.Write(tmpPath); // $$$ , new WriterParameters { WriteSymbols = true }); see https://github.com/jbevain/cecil/issues/421
            assemblyToPatch.Dispose();

            // TODO: peverify obviously won't work with memory written streams. also needs all the dependencies.
            // solution is to create a temp folder, write the patched dll there as well as any of its direct dependencies, and run peverify

            if ((patchOptions & PatchOptions.SkipPeVerify) == 0)
            {
                PeVerify.Verify(tmpPath);
            }

            // move the actual file to backup, and move the tmp to actual
            var backupPath = ElevatedWeaver.GetPatchBackupPathFor(assemblyToPatchPath);

            File.Replace(tmpPath, assemblyToPatchPath, backupPath);
        }
Пример #3
0
        public override DotNetAssembly SetupSpecificConfiguration(CSharpProgramConfiguration config)
        {
            var nonPatchedUnsafeUtility = base.SetupSpecificConfiguration(config);

            var builtPatcher = new CSharpProgram()
            {
                Path       = "artifacts/UnsafeUtilityPatcher/UnsafeUtilityPatcher.exe",
                Sources    = { $"{BuildProgram.LowLevelRoot}/UnsafeUtilityPatcher" },
                Defines    = { "NDESK_OPTIONS" },
                Framework  = { Bee.DotNet.Framework.Framework471 },
                References =
                {
                    MonoCecil.Paths,
                },
                LanguageVersion = "7.3"
            }.SetupDefault();

            var   outDir = nonPatchedUnsafeUtility.Path.Parent.Combine("patched");
            NPath nPath  = outDir.Combine(nonPatchedUnsafeUtility.Path.FileName);

            var builtPatcherProgram = new DotNetRunnableProgram(builtPatcher);
            var args = new[]
            {
                $"--output={nPath}",
                $"--assembly={nonPatchedUnsafeUtility.Path}",
            };

            var result = new DotNetAssembly(nPath, nonPatchedUnsafeUtility.Framework,
                                            nonPatchedUnsafeUtility.DebugFormat,
                                            nPath.ChangeExtension("pdb"), nonPatchedUnsafeUtility.RuntimeDependencies,
                                            nonPatchedUnsafeUtility.ReferenceAssemblyPath);

            Backend.Current.AddAction("Patch", result.Paths,
                                      nonPatchedUnsafeUtility.Paths.Concat(builtPatcher.Paths).ToArray(), builtPatcherProgram.InvocationString,
                                      args);

            return(result);
        }
Пример #4
0
 private static NPath ChangeExtension(string extension, NPath builtProgram, ToolChain toolchain, string subFolderDir)
 {
     return(Copy(builtProgram, builtProgram.ChangeExtension(extension), toolchain, subFolderDir));
 }
 private NPath ChangeMainModuleName(NPath target)
 {
     return(target.ChangeExtension("a"));
 }
Пример #6
0
 private NPath ChangeMainModuleName(NPath target)
 {
     // need to rename to make it start with "lib", otherwise Android have problems with loading native library
     return(target.ChangeExtension("a"));
 }