Exemplo n.º 1
0
        private void OpenFileButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter      = "Compiled .NET Files(*.exe;*.dll)|*.exe;*.dll|All Files (*.*)|*.*";
            fileDialog.Multiselect = true;

            if (UserActivityManger.History.OpenFileDialogLastPath.LastValue != default(string))
            {
                fileDialog.InitialDirectory = UserActivityManger.History.OpenFileDialogLastPath.LastValue;
            }
            else
            {
                fileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
            }

            if (fileDialog.ShowDialog() == true)
            {
                foreach (string filename in fileDialog.FileNames)
                {
                    AssemblyStore.RegisterNewAssemblyByFileName(filename);
                }


                UserActivityManger.History.OpenFileDialogLastPath.LastValue = System.IO.Path.GetDirectoryName(fileDialog.FileNames.First());
            }
        }
Exemplo n.º 2
0
        private bool IncludeType(AssemblyDefinition assembly, TypeDefinition classType, Type targetType)
        {
            bool result = false;

            // Check to see if the type is a public class
            // Check to see if the type do not inherited from an object
            // Check that the class inherited from the System.Web.UI.Control class
            if (classType.IsClass &&
                classType.IsPublic &&
                !classType.BaseType.Name.Equals("object", StringComparison.InvariantCultureIgnoreCase)
                )
            {
                // Include the class even that an exception is thrown
                result = true;
                try
                {
                    result = AssemblyStore.IsType((CustomAssemblyResolver)assembly.Resolver, assembly.Name.FullName, classType.FullName, targetType);
                }
                catch (Exception ex)
                {
                    Log.Warning(ex.Message + ". Please define the -DLLReferencePath with the path to the referenced assemblies. " +
                                "However a SafeControl tag for the " + classType.FullName + " class has been created.");
                }
            }
            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="plugindir"></param>
 /// <param name="plugis"></param>
 /// <param name="loaded"></param>
 public Plugin(DirectoryInfo plugindir, Plugins plugis, string name, int[] version, bool loaded)
 {
     this.PluginDir = plugindir;
     this.Plugins = plugis;
     this.Name = name;
     this.Version = version;
     this.DefaultLoad = loaded;
     appDomainToPlugin.Add(plugindir.FullName, this);
     attributeStore = new AssemblyStore();
     attributeStore.Update(plugindir);
     addinstore = new AddInStore(attributeStore);
 }
Exemplo n.º 4
0
        private AssemblyFileReference CreateManagedAssemblyFileReference(AssemblyInfo assemblyInfo)
        {
            Log.Verbose(string.Format("Adding assembly: {0}", assemblyInfo.Key));


            AssemblyFileReference assemblyFileReference = null;

            if (this.AssemblyFileReferenceCollection.ContainsKey(assemblyInfo.Key))
            {
                // Use an existing Assembly Reference from the Temporary List
                assemblyFileReference = this.AssemblyFileReferenceCollection[assemblyInfo.Key];
            }
            else
            {
                // Create a new Assembly Reference, it will be added later.
                assemblyFileReference = new AssemblyFileReference(assemblyInfo, GetDeploymentTarget(assemblyInfo.TargetType));
            }

            // Load the assembly into Cecil object model 'AssemblyDefinition'
            AssemblyDefinition assembly = AssemblyStore.GetAssembly(assemblyInfo.FileHandle.FullName, this.DLLReferencePath.FullName);

            if (assembly != null)
            {
                assemblyFileReference.AssemblyObject = assembly;

                // Build the safecontrols if the assembly is not a Resource or a reference dll
                if (this.BuildSafeControls)
                {
                    CreateSafeControls(assembly, assemblyFileReference);
                }

                // Add the class resources
                ClassResourceDefinition[] definitions = BuildClassResourceDefinition(assemblyInfo.FileHandle);
                assemblyFileReference.ClassResources = AppendArray <ClassResourceDefinition>(assemblyFileReference.ClassResources, definitions);
            }

            return(assemblyFileReference);
        }
Exemplo n.º 5
0
    AssemblyStore GetAssemblyStore(AssemblyIdentity assemblyIdentity) {
      Contract.Requires(assemblyIdentity != null);
      Contract.Ensures(Contract.Result<AssemblyStore>() != null);

      IName assemblyName = assemblyIdentity.Name;
      foreach (AssemblyStore aStore in this.AssemblyHashtable.GetValuesFor((uint)assemblyName.UniqueKey)) {
        if (assemblyIdentity.Equals(aStore.AssemblyIdentity)) return aStore;
      }
      uint value = this.CurrentAssemblyInternValue;
      this.CurrentAssemblyInternValue += 0x00001000;
      AssemblyStore aStore1 = new AssemblyStore(assemblyIdentity, value, this.CurrentNamespaceInternValue++);
      this.AssemblyHashtable.Add((uint)assemblyName.UniqueKey, aStore1);
      return aStore1;
    }
Exemplo n.º 6
0
 AssemblyStore GetAssemblyStore(AssemblyIdentity assemblyIdentity) {
   IName assemblyName = assemblyIdentity.Name;
   foreach (AssemblyStore aStore in this.AssemblyHashtable.GetValuesFor((uint)assemblyName.UniqueKey)) {
     if (assemblyIdentity.Equals(aStore.AssemblyIdentity)) {
       return aStore;
     }
   }
   uint value = this.CurrentAssemblyInternValue;
   this.CurrentAssemblyInternValue += 0x00001000;
   AssemblyStore aStore1 = new AssemblyStore(assemblyIdentity, value, this.CurrentNamespaceInternValue++);
   this.AssemblyHashtable.Add((uint)assemblyName.UniqueKey, aStore1);
   return aStore1;
 }
Exemplo n.º 7
0
        public void TryHook()
        {
            // Validate all options
            CheckOptions();
            // Copy our injected library to the location of the 'to patch' assemblies
            CopyHooksLibrary();
            // Find all needed types
            FindNecessaryTypes();
            // Find all method fullnames that the hookregistry expects
            FetchExpectedMethods();

            // Read all hook functions into memory
            var hookEntries = ReadHooksFile(_options.HooksFilePath);

            // Initialise the AssemblyStore with the given path.
            // All assemblies are parsed from their own location.
            var asStore = AssemblyStore.Get(_options.GamePath);

            // Loop all libraries looking for methods to hook       ! important - core
            // Library is a reference to the filename of the assembly file containing the actual
            // code we want to patch.
            foreach (AssemblyStore.LIB_TYPE library in AssemblyStore.GetAllLibraryTypes())
            {
                // Skip invalid lib!
                if (library == AssemblyStore.LIB_TYPE.INVALID)
                {
                    continue;
                }

                // Full path to current assembly
                string libraryPath = library.GetPath();
                // Full path to processed assembly
                string libraryOutPath = library.GetPathOut();

                // Load the assembly file
                AssemblyDefinition assembly;
                AssemblyStore.GetAssembly(library, out assembly);
                if (assembly.HasPatchMark())
                {
                    Program.Log.Warn(ASSEMBLY_ALREADY_PATCHED, libraryPath);
                    continue;
                }

                // Construct a hooker wrapper around the main Module of the assembly.
                // The wrapper facilitates hooking into method calls.
                ModuleDefinition mainModule = assembly.MainModule;
                Hooker           wrapper    = Hooker.New(mainModule, _options);
                Program.Log.Info(CHECKING_ASSEMBLY, libraryPath);

                // Keep track of hooked methods
                bool isHooked = false;
                // Loop each hook entry looking for registered types and methods
                foreach (HOOK_ENTRY hookEntry in hookEntries)
                {
                    try
                    {
                        wrapper.AddHookBySuffix(hookEntry.TypeName, hookEntry.MethodName, ExpectedMethods);
                        isHooked = true;
                    }
                    catch (MissingMethodException)
                    {
                        // The method is not found in the current assembly.
                        // This is no error because we run all hook entries against all libraries!
                    }
                }

                try
                {
                    // Only save if the file actually changed!
                    if (isHooked)
                    {
                        // Generate backup from original file
                        library.Backup();
                        // Save the manipulated assembly
                        library.Save();

                        // TODO UNCOMMENT
                        // Overwrite the original with the hooked one
                        File.Copy(libraryOutPath, libraryPath, true);
                    }
                    else
                    {
                        Program.Log.Debug(ASSEMBLY_NOT_PATCHED, libraryPath);
                    }
                }
                catch (IOException e)
                {
                    // The file could be locked! Notify user.
                    // .. or certain libraries could not be resolved..
                    // Try to find the path throwing an exception.. but this method is not foolproof!
                    var path = typeof(IOException).GetField("_maybeFullPath", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase)?.GetValue(e);
                    Program.Log.Exception(ERR_WRITE_FILE, null, e?.ToString());

                    throw;
                }
            } // End foreach LIB_TYPE
        }
Exemplo n.º 8
0
 internal ComponentStore(AssemblyStore attributeStore)
 {
     this.attributeStore = attributeStore;
 }
Exemplo n.º 9
0
 internal ComponentStore(DirectoryInfo path, DirectoryInfo loadPath)
 {
     attributeStore = new AssemblyStore();
     attributeStore.Update(path);
 }
Exemplo n.º 10
0
        public void Initialize()
        {
            if (!DataSetFactory.ContainsProvider("memory"))
            {
                DataSetFactory.Register(typeof(MemoryDataSet));
            }
            if (!DataSetFactory.ContainsProvider("ab"))
            {
                DataSetFactory.Register(typeof(AzureBlobDataSet));
            }
            string customTempLocalResourcePath =
                RoleEnvironment.GetLocalResource("localStorage1").RootPath;

            Environment.SetEnvironmentVariable("TMP", customTempLocalResourcePath);
            Environment.SetEnvironmentVariable("TEMP", customTempLocalResourcePath);

            string jobsDatabaseConnectionString = RoleEnvironment.GetConfigurationSettingValue("FetchClimate.JobsDatabaseConnectionString");
            string jobsStorageConnectionString  = RoleEnvironment.GetConfigurationSettingValue("FetchClimate.JobsStorageConnectionString");

            foreach (TraceListener item in Trace.Listeners)
            {
                if (!(item is DefaultTraceListener)) // The default trace listener is always in any TraceSource.Listeners collection.
                {
                    AutoRegistratingTraceSource.RegisterTraceListener(item);
                    WorkerTrace.TraceEvent(TraceEventType.Information, 19, string.Format("TraceListener \"{0}\" registered for accepting data from all AutoRegistratingTraceSources", item.ToString()));
                }
            }

            JobManager.InitializeJobTable(jobsDatabaseConnectionString, false);

            configProvider = new SqlExtendedConfigurationProvider(
                RoleEnvironment.GetConfigurationSettingValue("ConfigurationDatabaseConnectionString"));
            WorkerTrace.TraceEvent(TraceEventType.Information, 6, string.Format("Connected to configuration database. Latest timestamp {0}",
                                                                                configProvider.GetConfiguration(DateTime.MaxValue).TimeStamp));

            azureGAC = new AssemblyStore(RoleEnvironment.GetConfigurationSettingValue("FetchWorker.AssemblyStoreConnectionString"));


            //overriding bug-containing default azure provider with the fixed one
            Type t    = typeof(DataSetFactory);
            var  dict = (System.Collections.IDictionary)t.InvokeMember("providersByName", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField, null, null, null);

            dict.Remove("az");
            DataSetFactory.Register(typeof(Microsoft.Research.Science.Data.Azure.AzureDataSet));
            WorkerTrace.TraceEvent(TraceEventType.Verbose, 9, "Available Scientific DataSet providers:\n" + DataSetFactory.RegisteredToString());


            if (int.TryParse(RoleEnvironment.GetConfigurationSettingValue("JobTouchPeriod"), out touchPeriodInSeconds))
            {
                WorkerTrace.TraceEvent(TraceEventType.Verbose, 10, string.Format("Touch period for processing job is set to {0}", touchPeriodInSeconds));
            }
            else
            {
                WorkerTrace.TraceEvent(TraceEventType.Warning, 11, string.Format("Failed to read touch period from config. Parsing of value failed. touch period is set to {0}", touchPeriodInSeconds));
            }

            manager = new JobManager(jobsDatabaseConnectionString, jobsStorageConnectionString);

            //Scheduling cleanup
            string instanceId = RoleEnvironment.CurrentRoleInstance.Id;

            int.TryParse(instanceId.Substring(instanceId.LastIndexOf(".") + 1), out instanceIndex);
            if (instanceIndex == 0)
            {
                double cleanPeriod = 0;
                if (!double.TryParse(RoleEnvironment.GetConfigurationSettingValue("HoursBetweenCleanup"), out cleanPeriod))
                {
                    cleanPeriod = 23;
                    WorkerTrace.TraceEvent(TraceEventType.Warning, 12, "Failed to parse period between clean-ups from configuration. Setting it to default 23 hours.");
                }
                cleanupTimeSpan = TimeSpan.FromHours(cleanPeriod);
                lastCleanUpTime = manager.LastCleanUpTime;
                DateTime now = DateTime.UtcNow;
                if (now - lastCleanUpTime >= cleanupTimeSpan)
                {
                    manager.SubmitCleanUp();
                    lastCleanUpTime = now;
                }
            }

            WorkerTrace.TraceEvent(TraceEventType.Verbose, 13, string.Format("starting Allocated memory: {0}Mb", GC.GetTotalMemory(false) / 1024 / 1024));
        }