diff --git a/CodeReflectionLess6/CodeReflectionLess6.csproj b/CodeReflectionLess6/CodeReflectionLess6.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/CodeReflectionLess6/CodeReflectionLess6.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/CodeReflectionLess6/Program.cs b/CodeReflectionLess6/Program.cs new file mode 100644 index 0000000..b878f78 --- /dev/null +++ b/CodeReflectionLess6/Program.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; + +namespace Less6 +{ + /// + /// После рефлексии 6 задание + /// + + + class Program + { + static void Main(string[] args) + { + string stringa = new string('=', 30); + Console.WriteLine("Task Manager"); + Process[] ps = Process.GetProcesses(); + List list = new List(); + for (;;) + { + int count = 0; + list.AddRange(ps); + Console.WriteLine(string.Format("Кол-во запущуенный {0}", list.Count)); + Console.WriteLine(stringa); + list = (from x in list + orderby x.ProcessName + select x).ToList(); + foreach (Process proc in list) + { + Console.WriteLine(string.Format("[{0}]\t{1}\t{2}\t{3}", new object[] { count, proc.Id, proc.ProcessName, proc.BasePriority })); + count++; + } + Console.Write("Ввести Id для закрытия = "); + string ids = Console.ReadLine(); + int id = -1; + int.TryParse(ids, out id); + bool flag2 = id >= 0; + if (flag2) + { + Process procdel = list.FirstOrDefault((Process p) => p.Id == id); + bool flag3 = procdel != null; + if (flag3) + { + string tempName = procdel.ProcessName; + try + { + procdel.Kill(); + Console.WriteLine(stringa); + Console.WriteLine("close " + tempName + " "); + Console.WriteLine(stringa); + list.Remove(procdel); + Console.WriteLine(string.Format("Кол-во запущуенный {0}", list.Count)); + } + catch (InvalidOperationException) + { + Console.WriteLine("Process " + tempName + " not found!"); + } + catch (Exception ex) + { + Console.WriteLine("Информация об ошибке: " + ex.StackTrace); + } + Console.WriteLine("Закрыть еще процессы или выйти из приложения, y/n "); + string sl = Console.ReadLine().ToLower(); + bool flag = sl == "y"; + bool flag4 = !flag; + if (flag4) + { + Environment.Exit(0); + } + } + } + else + { + Console.WriteLine("Введено не верно"); + } + } + } + + public Program() + { + } + + [CompilerGenerated] + [Serializable] + sealed class __c + { + // Note: this type is marked as 'beforefieldinit'. + static __c() + { + } + + public __c() + { + } + + internal string _Main_b__0_0(Process x) + { + return x.ProcessName; + } + + public static readonly Program.__c __9 = new Program.__c(); + + public static Func __9__0_0; + } + + [CompilerGenerated] + sealed class __c__DisplayClass0_0 + { + public __c__DisplayClass0_0() + { + } + + internal bool _Main_b__1(Process p) + { + return p.Id == this.id; + } + + public int id; + } + } +} diff --git "a/Embedd/1\302\212\302\231\302\226\302\234v\302\217\302\214\302\234\302\234q\302\234\302\237g\302\211\302\220\302\224v.\302\207\302\2238\302\215\302\213\302\231\302\2204\302\235\302\233\302\211qeyft4l" "b/Embedd/1\302\212\302\231\302\226\302\234v\302\217\302\214\302\234\302\234q\302\234\302\237g\302\211\302\220\302\224v.\302\207\302\2238\302\215\302\213\302\231\302\2204\302\235\302\233\302\211qeyft4l" new file mode 100644 index 0000000..62d5601 Binary files /dev/null and "b/Embedd/1\302\212\302\231\302\226\302\234v\302\217\302\214\302\234\302\234q\302\234\302\237g\302\211\302\220\302\224v.\302\207\302\2238\302\215\302\213\302\231\302\2204\302\235\302\233\302\211qeyft4l" differ diff --git a/Embedd/2 b/Embedd/2 new file mode 100644 index 0000000..058e6f9 Binary files /dev/null and b/Embedd/2 differ diff --git a/Embedd/3 b/Embedd/3 new file mode 100644 index 0000000..6633fe9 Binary files /dev/null and b/Embedd/3 differ diff --git a/Embedd/4 b/Embedd/4 new file mode 100644 index 0000000..13952dc Binary files /dev/null and b/Embedd/4 differ diff --git a/Embedd/Embedd.csproj b/Embedd/Embedd.csproj new file mode 100644 index 0000000..6434fef --- /dev/null +++ b/Embedd/Embedd.csproj @@ -0,0 +1,29 @@ + + + + Exe + net5.0 + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Embedd/Program.cs b/Embedd/Program.cs new file mode 100644 index 0000000..db7de1a --- /dev/null +++ b/Embedd/Program.cs @@ -0,0 +1,175 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; + +namespace Embedd +{ + internal class Program + { + + + + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + var tod = DateTime.Now; + var mess = tod.AddMonths(1).AddDays(5); + + _.___(); + + Console.ReadLine(); + + } + public class _ + { + public static void ___() + { + List list = new List(); + //list.Add("˜Embedd.j0œš–•‘bxp“ž†fien.”–œži’b“n6”a’Ž“Š‎"); + //list.Add("Embedd.kf8˜0r“™oncŠd˜b4.™f8š2‹”nžqc5‘œ22h‎"); + //list.Add("Embedd.u˜iœp‡9xj‹•t3xr5f.ˆvŽ8uxˆo4›‰šžek‰3j‎"); + //list.Add("Embedd.˜e™ehxu–‹8n›w0‰.ˆcr1ŠkŽr3Žn‡au1he"); + list.Add("Embedd._"); + list.Add("Embedd.1"); + list.Add("Embedd.2"); + list.Add("Embedd.3"); + list.Add("Embedd.4"); + + + try + { + foreach (var item in list) + { + byte[] array = null; + Stream manifestResourceStream=null; + try + { + + + manifestResourceStream = typeof(_).Assembly.GetManifestResourceStream(item); + array = new byte[manifestResourceStream.Length]; + manifestResourceStream.Read(array, 0, array.Length); + manifestResourceStream.Close(); + } + catch (Exception) + { + + continue; + } + + byte[] array2 = null; + if (typeof(_).Assembly.GetManifestResourceNames().Length > 1) + { + manifestResourceStream = typeof(_).Assembly.GetManifestResourceStream(item); + array2 = new byte[manifestResourceStream.Length]; + manifestResourceStream.Read(array2, 0, array2.Length); + manifestResourceStream.Close(); + } + AppDomain.CurrentDomain.ResourceResolve += _.CurrentDomain_ResourceResolve; + AppDomain.CurrentDomain.AssemblyResolve += _.CurrentDomain_AssemblyResolve; + if (array2 != null) + { + _.__ = Assembly.Load(array, array2); + } + else + { + _.__ = Assembly.Load(array); + System.IO.File.WriteAllBytes("bet.exe", array); + } + AssemblyName[] referencedAssemblies = _.__.GetReferencedAssemblies(); + try + { + foreach (AssemblyName assemblyName in referencedAssemblies) + { + if (assemblyName.Name == "PresentationFramework") + { + foreach (Type type in _.__.GetTypes()) + { + if (type.BaseType.FullName == "System.Windows.Application") + { + type.BaseType.GetProperty("ResourceAssembly").SetValue(null, _.__, null); + break; + } + } + break; + } + } + } + catch (Exception) + { + } + try + { + if (_.__.EntryPoint.GetParameters().Length > 0) + { + string[] array4 = Environment.GetCommandLineArgs(); + if (array4.Length > 0) + { + string[] array5 = new string[array4.Length - 1]; + Array.Copy(array4, 1, array5, 0, array4.Length - 1); + array4 = array5; + } + _.__.EntryPoint.Invoke(null, new object[] { array4 }); + } + else + { + _.__.EntryPoint.Invoke(null, new object[0]); + } + } + catch (Exception ex) + { + //MessageBox.Show(ex.ToString()); + } + } + } + catch (Exception) + { + + //throw; + } + + } + + static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) + { + Assembly result; + lock (_.o) + { + if (_.__ != null && args.Name != null) + { + string a = args.Name.Split(new char[] { ',' })[0]; + if (a == _.__.GetName().Name) + { + return _.__; + } + } + result = null; + } + return result; + } + + static Assembly CurrentDomain_ResourceResolve(object sender, ResolveEventArgs args) + { + if (_.__ != null) + { + return _.__; + } + return null; + } + + public _() + { + } + + // Note: this type is marked as 'beforefieldinit'. + static _() + { + } + + static Assembly __ = null; + + static object o = new List(); + } + } +} \ No newline at end of file diff --git a/Embedd/_ b/Embedd/_ new file mode 100644 index 0000000..74effd2 Binary files /dev/null and b/Embedd/_ differ diff --git "a/Embedd/\302\2301" "b/Embedd/\302\2301" new file mode 100644 index 0000000..55a2eac Binary files /dev/null and "b/Embedd/\302\2301" differ diff --git a/Less6/Less6.csproj b/Less6/Less6.csproj new file mode 100644 index 0000000..2082704 --- /dev/null +++ b/Less6/Less6.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + + diff --git a/Less6/Program.cs b/Less6/Program.cs new file mode 100644 index 0000000..9348e1a --- /dev/null +++ b/Less6/Program.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; + +namespace Less6 +{//Написать консольное приложение Task Manager, + //которое выводит на экран запущенные процессы и позволяет завершить указанный процесс. + //Предусмотреть возможность завершения процессов с помощью указания его ID или имени процесса. + //В качестве примера можно использовать консольные утилиты Windows tasklist и taskkill. + internal class Program + { + static void Main(string[] args) + { + var stringa = new String('=', 30); + Console.WriteLine("Task Manager"); + var ps = Process.GetProcesses(); + List list = new List(); + + + while (true) + { + int count = 0; + list.AddRange(ps); + Console.WriteLine($"Кол-во запущуенный {list.Count}"); + Console.WriteLine(stringa); + //сортируем по имени для удобства + list = list.OrderBy(x => x.ProcessName).ToList(); + + foreach (var proc in list) + { + + Console.WriteLine($"[{count}]\t{proc.Id}\t{proc.ProcessName}\t{proc.BasePriority}"); + count++; + } + Console.Write("Ввести Id для закрытия = "); + var ids = Console.ReadLine(); + int id = -1; + int.TryParse(ids, out id); + if (id >= 0) + { + + var procdel = list.FirstOrDefault(p => p.Id == id); + if (procdel != null) + { + var tempName = procdel.ProcessName; + try + { + procdel.Kill(); + Console.WriteLine(stringa); + Console.WriteLine($"close {tempName} "); + Console.WriteLine(stringa); + list.Remove(procdel); + Console.WriteLine($"Кол-во запущуенный {list.Count}"); + } + catch (InvalidOperationException) + { + Console.WriteLine($"Process {tempName} not found!"); + } + catch(Exception ex) { + Console.WriteLine($"Информация об ошибке: {ex.StackTrace}"); + } + Console.WriteLine("Закрыть еще процессы или выйти из приложения, y/n "); + var sl = Console.ReadLine().ToLower(); + var flag = sl == "y"; + if (!flag) + {//closed is user N + Environment.Exit(0); + } + } + + } + else + { + Console.WriteLine("Введено не верно"); + } + + } + + + Console.ReadLine(); + } + } +} diff --git a/StudyProject.sln b/StudyProject.sln index d04b143..771f710 100644 --- a/StudyProject.sln +++ b/StudyProject.sln @@ -11,6 +11,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "less4", "less4\less4.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "less5", "less5\less5.csproj", "{B371D792-7468-4117-BC92-9F82C4262A17}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Embedd", "Embedd\Embedd.csproj", "{97893459-574E-43F7-A7A5-34BA9BA195F5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Less6", "Less6\Less6.csproj", "{D16B8631-360E-4130-90A4-A57CC75149CB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeReflectionLess6", "CodeReflectionLess6\CodeReflectionLess6.csproj", "{DA2EBBF4-A078-48BA-A1F4-74BC403843F6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +39,18 @@ Global {B371D792-7468-4117-BC92-9F82C4262A17}.Debug|Any CPU.Build.0 = Debug|Any CPU {B371D792-7468-4117-BC92-9F82C4262A17}.Release|Any CPU.ActiveCfg = Release|Any CPU {B371D792-7468-4117-BC92-9F82C4262A17}.Release|Any CPU.Build.0 = Release|Any CPU + {97893459-574E-43F7-A7A5-34BA9BA195F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {97893459-574E-43F7-A7A5-34BA9BA195F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {97893459-574E-43F7-A7A5-34BA9BA195F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {97893459-574E-43F7-A7A5-34BA9BA195F5}.Release|Any CPU.Build.0 = Release|Any CPU + {D16B8631-360E-4130-90A4-A57CC75149CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D16B8631-360E-4130-90A4-A57CC75149CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D16B8631-360E-4130-90A4-A57CC75149CB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D16B8631-360E-4130-90A4-A57CC75149CB}.Release|Any CPU.Build.0 = Release|Any CPU + {DA2EBBF4-A078-48BA-A1F4-74BC403843F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA2EBBF4-A078-48BA-A1F4-74BC403843F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA2EBBF4-A078-48BA-A1F4-74BC403843F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA2EBBF4-A078-48BA-A1F4-74BC403843F6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE