예제 #1
0
 public virtual TargetPlatform GetTargetPlatform(string assemblyFilePath, ITargetPlatformResolver targetPlatformResolver)
 {
     return(assemblyPathResolver.GetTargetPlatform(assemblyFilePath, targetPlatformResolver));
 }
 private AssemblyFrameworkResolver(ITargetPlatformResolver targetPlatformResolver)
 {
     this.targetPlatformResolver = targetPlatformResolver;
 }
예제 #3
0
        private BaseProjectBuilder GetProjectBuilder(AssemblyDefinition assembly, GeneratorProjectInfo projectInfo, ProjectGenerationSettings settings, ILanguage language, string projFilePath, DecompilationPreferences preferences, IFrameworkResolver frameworkResolver, ITargetPlatformResolver targetPlatformResolver)
        {
            TargetPlatform     targetPlatform = assembly.MainModule.AssemblyResolver.GetTargetPlatform(assembly.MainModule.FilePath, targetPlatformResolver);
            BaseProjectBuilder projectBuilder = null;

            if (targetPlatform == TargetPlatform.NetCore)
            {
                projectBuilder = new NetCoreProjectBuilder(projectInfo.Target, projFilePath, language, preferences, null, NoCacheAssemblyInfoService.Instance, TargetPlatformResolver.Instance, projectInfo.VisualStudioVersion, settings);
            }
            else if (targetPlatform == TargetPlatform.WinRT)
            {
                projectBuilder = new WinRTProjectBuilder(projectInfo.Target, projFilePath, language, preferences, null, NoCacheAssemblyInfoService.Instance, TargetPlatformResolver.Instance, projectInfo.VisualStudioVersion, settings);
            }
            else
            {
                projectBuilder = new MSBuildProjectBuilder(projectInfo.Target, projFilePath, language, frameworkResolver, preferences, null, NoCacheAssemblyInfoService.Instance, TargetPlatformResolver.Instance, projectInfo.VisualStudioVersion, settings);
            }

            return(projectBuilder);
        }
예제 #4
0
        public static ProjectGenerationSettings GetProjectGenerationSettings(string assemblyFilePath, IAssemblyInfoService assemblyInfoService,
                                                                             IFrameworkResolver frameworkResolver, VisualStudioVersion visualStudioVersion, ILanguage language, ITargetPlatformResolver targetPlatformResolver)
        {
            AssemblyDefinition assembly       = Telerik.JustDecompiler.Decompiler.Utilities.GetAssembly(assemblyFilePath);
            AssemblyInfo       assemblyInfo   = assemblyInfoService.GetAssemblyInfo(assembly, frameworkResolver, targetPlatformResolver);
            TargetPlatform     targetPlatform = GlobalAssemblyResolver.Instance.GetTargetPlatform(assemblyFilePath, targetPlatformResolver);

            foreach (KeyValuePair <ModuleDefinition, FrameworkVersion> pair in assemblyInfo.ModulesFrameworkVersions)
            {
                if (pair.Value == FrameworkVersion.Unknown)
                {
                    return(new ProjectGenerationSettings(true, ResourceStrings.GenerateOnlySourceFilesDueToUnknownFrameworkVersion, false));
                }
                else if (pair.Value == FrameworkVersion.WindowsCE ||
                         (targetPlatform == TargetPlatform.WindowsPhone && pair.Value == FrameworkVersion.WindowsPhone) ||
                         (targetPlatform == TargetPlatform.WinRT && WinRTProjectTypeDetector.GetProjectType(assembly) == WinRTProjectType.Unknown))
                {
                    return(new ProjectGenerationSettings(true, ResourceStrings.GenerateOnlySourceFilesDueToNotSupportedProjectType, false));
                }
            }

            string resultErrorMessage;

            if (visualStudioVersion == VisualStudioVersion.VS2010)
            {
                if (!CanBe2010ProjectCreated(assemblyInfo, targetPlatform, out resultErrorMessage))
                {
                    return(new ProjectGenerationSettings(false, resultErrorMessage));
                }
            }
            else if (visualStudioVersion == VisualStudioVersion.VS2012)
            {
                if (!CanBe2012ProjectCreated(assembly, out resultErrorMessage))
                {
                    return(new ProjectGenerationSettings(false, resultErrorMessage));
                }
            }
            else
            {
                if (targetPlatform == TargetPlatform.WinRT && language is IVisualBasic &&
                    WinRTProjectTypeDetector.GetProjectType(assembly) == WinRTProjectType.ComponentForUniversal)
                {
                    resultErrorMessage = string.Format(ResourceStrings.CannotCreateProjectForComponentForUniversalInVB, visualStudioVersion.ToFriendlyString());
                    return(new ProjectGenerationSettings(false, resultErrorMessage));
                }

                if (visualStudioVersion == VisualStudioVersion.VS2013)
                {
                    if (!CanBe2013ProjectCreated(assembly, language, out resultErrorMessage))
                    {
                        return(new ProjectGenerationSettings(false, resultErrorMessage));
                    }
                }
            }

            return(new ProjectGenerationSettings(true));
        }
 public MSBuildProjectBuilder(string assemblyPath, AssemblyDefinition assembly,
                              Dictionary <ModuleDefinition, Mono.Collections.Generic.Collection <TypeDefinition> > userDefinedTypes,
                              Dictionary <ModuleDefinition, Mono.Collections.Generic.Collection <Resource> > resources,
                              string targetPath, ILanguage language, IFrameworkResolver frameworkResolver,
                              IDecompilationPreferences preferences, IAssemblyInfoService assemblyInfoService, ITargetPlatformResolver targetPlatformResolver,
                              VisualStudioVersion visualStudioVersion    = VisualStudioVersion.VS2010, ProjectGenerationSettings projectGenerationSettings = null,
                              IProjectGenerationNotifier projectNotifier = null)
     : base(assemblyPath, assembly, userDefinedTypes, resources, targetPath, language, frameworkResolver, preferences, assemblyInfoService, targetPlatformResolver, visualStudioVersion, projectGenerationSettings, projectNotifier)
 {
     this.projectFileManager = new MsBuildProjectFileManager(this.assembly, this.assemblyInfo, this.visualStudioVersion, this.modulesProjectsGuids, this.language, this.namespaceHierarchyTree);
 }
 public AssemblyPathResolver(AssemblyPathResolverCache pathRepository, ReaderParameters readerParameters, ITargetPlatformResolver targetPlatformResolver)
 {
     this.pathRepository         = pathRepository;
     this.readerParameters       = readerParameters;
     this.targetPlatformResolver = targetPlatformResolver;
 }
예제 #7
0
        public TargetPlatform GetTargetPlatform(string assemblyFilePath, ITargetPlatformResolver targetPlatformResolver)
        {
            if (string.IsNullOrEmpty(assemblyFilePath))
            {
                return(TargetPlatform.None);
            }
            if (pathRepository.AssemblyParts.ContainsKey(assemblyFilePath))
            {
                return(pathRepository.AssemblyParts[assemblyFilePath]);
            }
            else
            {
                ModuleDefinition moduleDef = ModuleDefinition.ReadModule(assemblyFilePath, readerParameters);

                ///*Telerik Authorship*/
                if (moduleDef.Assembly != null && !string.IsNullOrEmpty(moduleDef.Assembly.TargetFrameworkAttributeValue))
                {
                    TargetPlatform targetPlatform = targetPlatformResolver.GetTargetPlatform(moduleDef.Assembly.TargetFrameworkAttributeValue);

                    if (targetPlatform != TargetPlatform.None)
                    {
                        pathRepository.AssemblyParts.Add(assemblyFilePath, targetPlatform);
                        return(targetPlatform);
                    }
                }

                AssemblyNameReference msCorlib = moduleDef.AssemblyReferences.FirstOrDefault(a => a.Name == "mscorlib");

                if (msCorlib == null)
                {
                    TargetPlatform targetPlatform = targetPlatformResolver.GetTargetPlatform(moduleDef);

                    if (targetPlatform != TargetPlatform.None)
                    {
                        pathRepository.AssemblyParts.Add(assemblyFilePath, targetPlatform);
                        return(targetPlatform);
                    }

                    // the next line is only to keep the old functionality
                    msCorlib = moduleDef.Assembly.Name;
                }

                if (moduleDef.Assembly != null && moduleDef.Assembly.Name.IsWindowsRuntime || msCorlib.IsFakeMscorlibReference())
                {
                    pathRepository.AssemblyParts.Add(assemblyFilePath, TargetPlatform.WinRT);
                    return(TargetPlatform.WinRT);
                }

                /*AssemblyName assemblyName = new AssemblyName(msCorlib.Name,
                 *                                  msCorlib.FullName,
                 *                                  msCorlib.Version,
                 *                                  msCorlib.PublicKeyToken,
                 *                                  Path.GetDirectoryName(assemliyFilePath)) { TargetArchitecture = moduleDef.GetModuleArchitecture() };
                 * IEnumerable<string> foundPaths = GetAssemblyPaths(assemblyName);
                 *
                 * return GetTargetPlatform(foundPaths.FirstOrDefault());*/

                /*Telerik Authorship*/
                TargetArchitecture moduleArchitecture = moduleDef.GetModuleArchitecture();
                /*Telerik Authorship*/
                foreach (KeyValuePair <AssemblyName, TargetPlatform> pair in Mscorlibs)
                {
                    if (AreVersionEquals(pair.Key.Version, msCorlib.Version) &&
                        ArePublicKeyEquals(pair.Key.PublicKeyToken, msCorlib.PublicKeyToken) &&
                        moduleArchitecture.CanReference(pair.Key.TargetArchitecture))
                    {
                        pathRepository.AssemblyParts.Add(assemblyFilePath, pair.Value);
                        return(pair.Value);
                    }
                }

                /*Telerik Authorship*/
                pathRepository.AssemblyParts.Add(assemblyFilePath, TargetPlatform.None);
                return(TargetPlatform.None);
            }
        }
예제 #8
0
        public BaseProjectBuilder(string assemblyPath, AssemblyDefinition assembly,
                                  Dictionary <ModuleDefinition, Mono.Collections.Generic.Collection <TypeDefinition> > userDefinedTypes,
                                  Dictionary <ModuleDefinition, Mono.Collections.Generic.Collection <Resource> > resources,
                                  string targetPath, ILanguage language, IFrameworkResolver frameworkResolver,
                                  IDecompilationPreferences preferences, IAssemblyInfoService assemblyInfoService, ITargetPlatformResolver targetPlatformResolver,
                                  VisualStudioVersion visualStudioVersion    = VisualStudioVersion.VS2010, ProjectGenerationSettings projectGenerationSettings = null,
                                  IProjectGenerationNotifier projectNotifier = null)
        {
            this.assemblyPath            = assemblyPath;
            this.assembly                = assembly;
            this.userDefinedTypes        = userDefinedTypes;
            this.resources               = resources;
            this.TargetPath              = targetPath;
            this.targetDir               = Path.GetDirectoryName(targetPath);
            this.targetPlatformResolver  = targetPlatformResolver;
            this.language                = language;
            this.frameworkResolver       = frameworkResolver;
            this.assemblyInfoService     = assemblyInfoService;
            this.currentAssemblyResolver = assembly.MainModule.AssemblyResolver;

            this.visualStudioVersion       = visualStudioVersion;
            this.projectGenerationSettings = projectGenerationSettings;

            this.decompilationPreferences = preferences;

            this.platform = currentAssemblyResolver.GetTargetPlatform(assembly.MainModule.FilePath, TargetPlatformResolver.Instance);
            this.namespaceHierarchyTree = assembly.BuildNamespaceHierarchyTree();

            filePathsService =
                new DefaultFilePathsService(
                    this.assembly,
                    this.assemblyPath,
                    Path.GetFileName(this.TargetPath),
                    this.UserDefinedTypes,
                    this.Resources,
                    this.namespaceHierarchyTree,
                    this.language,
                    Utilities.GetMaxRelativePathLength(targetPath));
            filePathsService.ExceptionThrown += OnExceptionThrown;

            this.resourcesToPathsMap           = this.filePathsService.GetResourcesToFilePathsMap();
            this.xamlResourcesToPathsMap       = this.filePathsService.GetXamlResourcesToFilePathsMap();
            this.modulesToProjectsFilePathsMap = this.filePathsService.GetModulesToProjectsFilePathsMap();

            this.assemblyInfo         = this.assemblyInfoService.GetAssemblyInfo(this.assembly, this.frameworkResolver, this.targetPlatformResolver);
            this.projectNotifier      = projectNotifier;
            this.modulesProjectsGuids = new Dictionary <ModuleDefinition, Guid>();
        }
예제 #9
0
        public WinRTProjectBuilder(string assemblyPath, AssemblyDefinition assembly,
                                   Dictionary <ModuleDefinition, Mono.Collections.Generic.Collection <TypeDefinition> > userDefinedTypes,
                                   Dictionary <ModuleDefinition, Mono.Collections.Generic.Collection <Resource> > resources,
                                   string targetPath, ILanguage language, IDecompilationPreferences preferences, IAssemblyInfoService assemblyInfoService, ITargetPlatformResolver targetPlatformResolver, VisualStudioVersion visualStudioVersion, ProjectGenerationSettings projectGenerationSettings = null)
            : base(assemblyPath, assembly, userDefinedTypes, resources, targetPath, language, null, preferences, assemblyInfoService, targetPlatformResolver, visualStudioVersion, projectGenerationSettings)
        {
            Initialize();

            this.projectFileManager = new WinRTProjectFileManager(this.assembly, this.assemblyInfo, this.language, this.visualStudioVersion, this.namespaceHierarchyTree, this.modulesProjectsGuids, this.projectType, this.IsUWPProject, this.minInstalledUAPVersion, this.maxInstalledUAPVersion);
        }
예제 #10
0
 public NetCoreProjectBuilder(string assemblyPath, string targetPath, ILanguage language, IDecompilationPreferences preferences, IFileGenerationNotifier notifier,
                              IAssemblyInfoService assemblyInfoService, ITargetPlatformResolver targetPlatformResolver, VisualStudioVersion visualStudioVersion = VisualStudioVersion.VS2017, ProjectGenerationSettings projectGenerationSettings = null, IProjectGenerationNotifier projectNotifier = null)
     : base(assemblyPath, targetPath, language, null, preferences, notifier, assemblyInfoService, targetPlatformResolver, visualStudioVersion, projectGenerationSettings, projectNotifier)
 {
     this.projectFileManager = new NetCoreProjectFileManager(this.assembly, this.assemblyInfo, this.modulesProjectsGuids);
 }