Exemplo n.º 1
0
 public IntManglerPlugin(IContextImpl context)
     : base(context)
 {
     Rng         = context.Plugin <IRngPlugin>().Get(NetfuserFactory.IntManglerName);
     _finj       = context.FeatureInjector();
     _demanglers = new List <ValueDemangler>();
 }
Exemplo n.º 2
0
 internal Embedding(IContextImpl context, string name, IReadable readable)
 {
     Name       = name;
     Context    = context;
     Readable   = readable;
     Properties = new Dictionary <string, string>();
 }
Exemplo n.º 3
0
 public RSAEncryption(IContextImpl context, string name, int bits, RSAParameters privkey, RSAParameters pubkey) : base(context)
 {
     Name     = name;
     _bits    = bits;
     _private = privkey;
     _public  = pubkey;
 }
 public FeatureInjectorPlugin(IContextImpl context)
     : base(context)
 {
     Rng = context.Plugin <IRngPlugin>().Get(NetfuserFactory.FeatureInjectorName);
     _injectableTypes = new List <InjectableType>();
     _ns = context.Plugin <INaming>();
 }
Exemplo n.º 5
0
 public EmbedderPlugin(IContextImpl context, string name)
     : base(context)
 {
     Name         = name;
     _entries     = new List <Embedding>();
     _uniqueNames = new HashSet <string>();
     _index       = new EmbeddedResource(name, new ReadableDataReaderFactory(this, name), 0, 0);
 }
Exemplo n.º 6
0
 public MetadataManglerPlugin(IContextImpl context, MetadataManglerOptions options)
     : base(context)
 {
     _options = options;
     _root    = new MetadataElement.Root();
     _rng     = context.Plugin <IRngPlugin>().Get(NetfuserFactory.MetadataManglerName);
     _ns      = context.Plugin <INaming>();
 }
Exemplo n.º 7
0
 internal WillMangle(IContextImpl context, TypeMapping tm, MethodDef m, Instruction i)
     : base(context)
 {
     TypeMapping = tm;
     Method      = m;
     Instruction = i;
     String      = (string)i.Operand;
 }
Exemplo n.º 8
0
        protected AbstractPlugin(IContextImpl context)
        {
            _context = context;
            var ln = new StringBuilder(GetType().Name);

            if (this is INamedPlugin np)
            {
                ln.Append('-').Append(np.Name);
            }
            Logger = context.Logger.GetLogger(ln.ToString());
        }
 internal AssemblyWriterPlugin(IContextImpl context, DirectoryInfo dest)
     : base(context)
 {
     if (dest != null)
     {
         context.OutputFolder = dest;
     }
     else
     {
         dest = context.OutputFolder;
     }
     _dest = dest ?? throw new ArgumentException(nameof(dest));
 }
Exemplo n.º 10
0
            public IEnumerable <Var> GetIOVars(ValueManglingFeature feature, IContextImpl ctx)
            {
                foreach (var a in _arglist)
                {
                    yield return(new Var.Arg(Method.Parameters[a]));
                }
                var t = Type;

                while (t != null)
                {
                    foreach (var f in TD.Get(feature, t).Fields)
                    {
                        yield return(new Var.Fld(f, fld => ctx.BasicImporter.Import(fld)));
                    }
                    t = t.Base;
                }
            }
Exemplo n.º 11
0
        public Injectable(IContextImpl context, string name)
            : base(context, name)
        {
            _codecs = new List <ICodec>();
            var finj = context.FeatureInjector();

            _demanglers   = new List <ValueDemangler>();
            _subscription = Context.OfType <FeatureInjectorEvent.HaveInjectableTypes>().Subscribe(ime =>
            {
                _feature = new ValueManglingFeature(Context.TargetModule.CorLibTypes.String);
                var q    = Math.Max(Context.MappedTypes.Count / 100, Mangler.Rng.NextInt32(50, 100));
                foreach (var node in finj.Rate(_feature).OrderByDescending(r => r.Score)
                         .SelectMany(ToNodes).Take(q))
                {
                    _demanglers.Add(node);
                }
            });
        }
Exemplo n.º 12
0
        public Naming(IContextImpl context)
            : base(context)
        {
            _nodes = new Dictionary <TypeDef, INsNode>();
            context.OfType <NetfuserEvent.TypeMapped>().Subscribe(ev =>
            {
                MetaType preserve = 0;
                var source        = ev.Mapping.Source;
                if (source.IsGlobalModuleType)
                {
                    preserve |= MetaType.NamespaceAndType;
                }
                if (source.IsComImport() || source.IsDelegate)
                {
                    preserve |= MetaType.Member;
                }
                if (source.IsRuntimeSpecialName || source.IsSpecialName)
                {
                    preserve |= MetaType.All;
                }

                if (_preserveNamesIfImplements.Count > 0)
                {
                    preserve |= source.Interfaces
                                .Select(i =>
                                        _preserveNamesIfImplements.TryGetValue(i.Interface.FullName, out var v) ? v : 0)
                                .Aggregate(MetaType.None, (a, v) => a | v);
                }
                if (_preserveNamesIfAnnotatedBy.Count > 0)
                {
                    preserve |= source.CustomAttributes
                                .Select(ca =>
                                        _preserveNamesIfAnnotatedBy.TryGetValue(ca.Constructor.DeclaringType.FullName,
                                                                                out var v)
                                ? v
                                : 0).Aggregate(MetaType.None, (a, v) => a | v);
                }
                Preserve(ev.Mapping, preserve);
            });
        }
Exemplo n.º 13
0
 internal CFManglerPlugin(IContextImpl context, CFMangleOptions options)
     : base(context)
 {
     Options = options;
     Rng     = context.Plugin <IRngPlugin>().Get(NetfuserFactory.CodeFlowManglerName);
 }
Exemplo n.º 14
0
 protected Subscribed(IContextImpl context)
     : base(context)
 {
     _subscription = context.Subscribe(Handle);
 }
Exemplo n.º 15
0
 internal ResNameFixer(IContextImpl context)
     : base(context)
 {
 }
Exemplo n.º 16
0
 public FrequencySplitter(IContextImpl context, FrequencySplitterOptions options)
     : base(context)
 {
     Options = options;
 }
Exemplo n.º 17
0
 public LzmaCompression(IContextImpl context)
     : base(context)
 {
 }
Exemplo n.º 18
0
 public IEnumerable <Var> GetIOVars(InjectableMethod r, IContextImpl ctx)
 {
     return(((Injectable)r).GetIOVars(this, ctx));
 }
Exemplo n.º 19
0
        public ProjectLoader(IContextImpl context, string path, ProjectOptions options)
            : base(context)
        {
            _options = options ?? new ProjectOptions();
            if (_options.Configuration == null)
            {
                _options.Configuration = Context.DebugMode ? "Debug" : "Release";
            }
            _allProjects          = new Dictionary <string, Project>();
            _allReferences        = new HashSet <string>();
            _allPackageReferences = new HashSet <string>();


            if (File.Exists(path))
            {
                _root = GetProject(path);
            }
            else if (Directory.Exists(path))
            {
                var files = Directory.GetFiles(path, "*.csproj");
                if (files.Length == 0)
                {
                    throw context.Error($"no .csproj files found in {path}");
                }
                if (files.Length > 1)
                {
                    throw context.Error($"multiple .csproj files found in {path}");
                }
                _root = GetProject(files[0]);
            }
            else
            {
                throw context.Error($"path does not exist: {path}");
            }

            if (context.OutputFolder == null)
            {
                context.OutputFolder = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(_root.AssemblyPath), NetfuserFactory.NetfuserName));
            }

            if (_options.Building != Building.No)
            {
                var builderPath = _options.BuilderPath;
                if (string.IsNullOrEmpty(builderPath))
                {
                    // using https://github.com/Microsoft/vswhere/wiki/Find-MSBuild
                    var vswhere = Environment.ExpandEnvironmentVariables(
                        @"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe");
                    if (File.Exists(vswhere))
                    {
                        var buildTools = Utils.RunProcess(vswhere,
                                                          "-latest -prerelease -products * -requires Microsoft.Component.MSBuild -property installationPath")
                                         .StdOut.ReadLines().FirstOrDefault();
                        if (!string.IsNullOrEmpty(buildTools) && Directory.Exists(buildTools))
                        {
                            var msbuild = Path.Combine(buildTools, @"MSBuild\Current\Bin\MSBuild.exe");
                            if (!File.Exists(msbuild))
                            {
                                msbuild = Path.Combine(buildTools, @"MSBuild\15.0\Bin\MSBuild.exe");
                            }
                            if (File.Exists(msbuild))
                            {
                                var ver = Utils.RunProcess(msbuild, "/version").StdOut.ReadLines().LastOrDefault();
                                if (Version.TryParse(ver, out _msbuildVersion))
                                {
                                    builderPath = msbuild;
                                    _buildTool  = BuildTool.Msbuild;
                                }
                            }
                        }

                        if (string.IsNullOrEmpty(builderPath))
                        {
                            var devenv = Utils.RunProcess(vswhere,
                                                          "-latest -prerelease -property productPath")
                                         .StdOut;
                            if (File.Exists(devenv))
                            {
                                builderPath = devenv;
                                _buildTool  = BuildTool.Devenv;
                            }
                        }
                    }
                }

                if (string.IsNullOrEmpty(builderPath) || _buildTool == BuildTool.None)
                {
                    throw context.Error(
                              "could not find msbuild.exe or devenv.exe on this computer, please specify path in options or set Building to No");
                }
                _builderPath = builderPath;
            }
        }
Exemplo n.º 20
0
 protected CFMangleMethod(IContextImpl context, string name)
     : base(context)
 {
     Name    = name;
     Mangler = context.Plugin <ICFMangler>() ?? throw context.Error($"add ${nameof(ICFMangler)} to the context first");
 }
Exemplo n.º 21
0
 protected StringMangleMethod(IContextImpl context, string name)
     : base(context)
 {
     Name    = name;
     Mangler = context.Plugin <IStringMangler>(() => new StringMangler(context));
 }
Exemplo n.º 22
0
 public AsInt(IContextImpl context)
     : base(context, "int")
 {
 }
Exemplo n.º 23
0
 public DelegateCodec(IContextImpl context, Func <TV, TM> mangler, Func <TM, TV> demangler)
 {
     Context   = context;
     Mangler   = mangler;
     Demangler = demangler;
 }
Exemplo n.º 24
0
 public Switch(IContextImpl context)
     : base(context, NetfuserFactory.CFManglerSwitchName)
 {
 }
Exemplo n.º 25
0
 internal VTablePlugin(IContextImpl context)
     : base(context)
 {
     VTables = DnextFactory.NewVTables();
 }
Exemplo n.º 26
0
 public AsIs(IContextImpl context)
     : base(context, "asis")
 {
 }
Exemplo n.º 27
0
 public Jump(IContextImpl context)
     : base(context, NetfuserFactory.CFManglerJumpName)
 {
 }
 public MapWriterPluginPlugin(IContextImpl context, string dest)
     : base(context)
 {
     _dest = dest ?? "names.xml";
 }
Exemplo n.º 29
0
 public DepsJsonPlugin(IContextImpl context)
     : base(context)
 {
 }
Exemplo n.º 30
0
 /// <summary>
 /// Constructs new feature request
 /// </summary>
 /// <param name="context">Netfuser context</param>
 /// <param name="emitter">IL emitter</param>
 public FeatureRequest(IContextImpl context, IILEmitter emitter)
 {
     Context   = context;
     Emitter   = emitter;
     CallStack = new Stack <MethodDef>();
 }