Пример #1
0
        /// <summary>
        /// Fix errors
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static IDictionary <IFixer, FixerMessage> Fix(FixerContext context)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Dictionary <IFixer, FixerMessage> messages;

            messages = new Dictionary <IFixer, FixerMessage>();
            foreach (IFixer fixer in Fixers)
            {
                FixerMessage message;

                if (fixer.Fix(context, out message))
                {
                    messages.Add(fixer, message);
                }
            }
            return(messages);
        }
Пример #2
0
        private static void Main(string[] args)
        {
            if (args is null || args.Length != 1)
            {
                return;
            }

            string assemblyPath;

            try {
                Console.Title = GetTitle();
            }
            catch {
            }
            assemblyPath = Path.GetFullPath(args[0]);
            if (!File.Exists(assemblyPath))
            {
                Console.WriteLine("File doesn't exist.");
                return;
            }
            using (IPEImage peImage = PEImageFactory.Create(assemblyPath)) {
                FixerContext context;
                IDictionary <IFixer, FixerMessage> messages;

                context = new FixerContext(peImage);
                Console.WriteLine("If it is dll, enter Y, otherwise enter N.");
                do
                {
                    string userInput;

                    userInput = Console.ReadLine().Trim().ToUpperInvariant();
                    if (userInput == "Y")
                    {
                        context.IsDll = true;
                        break;
                    }
                    else if (userInput == "N")
                    {
                        context.IsDll = false;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Invalid input");
                    }
                } while (true);
                Console.WriteLine();
                //Console.WriteLine("Checking...");
                //messages = AssemblyFixer.Check(context);
                //Console.WriteLine("Checked errors:");
                //Console.WriteLine();
                //foreach (KeyValuePair<IFixer, FixerMessage> fixerToMessage in messages) {
                //	Console.WriteLine(fixerToMessage.Key.Name + ":");
                //	Console.WriteLine($"Level: {fixerToMessage.Value.Level}");
                //	Console.WriteLine("Message:");
                //	Console.WriteLine(fixerToMessage.Value.Text);
                //	Console.WriteLine();
                //}
                //Console.WriteLine();
                Console.WriteLine("Fixing...");
                messages = AssemblyFixer.Fix(context);
                Console.WriteLine("Fixed errors:");
                Console.WriteLine();
                foreach (KeyValuePair <IFixer, FixerMessage> fixerToMessage in messages)
                {
                    Console.WriteLine(fixerToMessage.Key.Name + ":");
                    Console.WriteLine($"Level: {fixerToMessage.Value.Level}");
                    Console.WriteLine("Message:");
                    Console.WriteLine(fixerToMessage.Value.Text);
                    Console.WriteLine();
                }
                Console.WriteLine();
                Console.WriteLine("If the assembly still does NOT run, may be you should rebuild it!!!");
                Console.WriteLine();
                if (messages.Count != 0)
                {
                    byte[] peImageData;
                    string newAssemblyPath;

                    peImageData = new byte[peImage.Length];
                    Marshal.Copy(peImage.RawData, peImageData, 0, peImageData.Length);
                    newAssemblyPath = PathInsertPostfix(assemblyPath, ".fix");
                    Console.WriteLine("Saving: " + newAssemblyPath);
                    File.WriteAllBytes(newAssemblyPath, peImageData);
                    Console.WriteLine("Finished");
                    Console.WriteLine();
                }
            }
            if (IsN00bUser() || Debugger.IsAttached)
            {
                Console.WriteLine("Press any key to exit...");
                try {
                    Console.ReadKey(true);
                }
                catch {
                }
            }
        }
Пример #3
0
        private static void Main(string[] args)
        {
            if (args is null || args.Length != 1)
            {
                return;
            }

            string assemblyPath;

            try {
                Console.Title = GetTitle();
            }
            catch {
            }
            assemblyPath = Path.GetFullPath(args[0]);
            if (!File.Exists(assemblyPath))
            {
                Console.WriteLine("File doesn't exist.");
                return;
            }
            using (FixerContext context = new FixerContext(PEImageFactory.Create(assemblyPath))) {
                IDictionary <IFixer, FixerMessage> messages;

                switch (assemblyPath.Substring(assemblyPath.Length - 4).ToUpperInvariant())
                {
                case ".EXE":
                    Console.WriteLine("exe detected");
                    context.IsDll = false;
                    break;

                case ".DLL":
                    Console.WriteLine("dll detected");
                    context.IsDll = true;
                    break;

                default:
                    Console.WriteLine("Unknown file extension!!!");
                    context.IsDll = true;
                    break;
                }
                Console.WriteLine();
                Console.WriteLine("Fixing...");
                messages = AssemblyFixer.Fix(context);
                Console.WriteLine("Fixed errors:");
                Console.WriteLine();
                foreach (KeyValuePair <IFixer, FixerMessage> fixerToMessage in messages)
                {
                    Console.WriteLine(fixerToMessage.Key.Name + ":");
                    Console.WriteLine($"Level: {fixerToMessage.Value.Level}");
                    Console.WriteLine("Message:");
                    Console.WriteLine(fixerToMessage.Value.Text);
                    Console.WriteLine();
                }
                Console.WriteLine();
                Console.WriteLine("If the assembly still does NOT run, may be you should rebuild it!!!");
                Console.WriteLine();
                if (messages.Count != 0)
                {
                    byte[] peImageData;
                    string newAssemblyPath;

                    peImageData = new byte[context.Length];
                    Marshal.Copy(context.RawData, peImageData, 0, peImageData.Length);
                    newAssemblyPath = PathInsertPostfix(assemblyPath, ".fix");
                    Console.WriteLine("Saving: " + newAssemblyPath);
                    File.WriteAllBytes(newAssemblyPath, peImageData);
                    Console.WriteLine("Finished");
                    Console.WriteLine();
                }
            }
            if (IsN00bUser() || Debugger.IsAttached)
            {
                Console.WriteLine("Press any key to exit...");
                try {
                    Console.ReadKey(true);
                }
                catch {
                }
            }
        }