Загрузка...

[C#] Определение подсистемы (SUBSYSTEM) приложения

Тема в разделе C# создана пользователем r3xq1 18 авг 2020. 243 просмотра

  1. r3xq1
    r3xq1 Автор темы 18 авг 2020 https://t.me/DarkSoft_Extra 119 27 июл 2018
    Создаём класс Enums.cs
    Код
    using System;

    internal class Enums
    {
    [Flags]
    public enum ExeType : int
    {
    None = 0,
    WinNT = 0x04000000,
    PE = 'P' | ('E' << 8),
    NE = 'N' | ('E' << 8),
    MZ = 'M' | ('Z' << 8),
    }
    }
    Создаём класс NativeMethods.cs
    Код
    using System;
    using System.Runtime.InteropServices;

    internal static class NativeMethods
    {
    // https://docs.microsoft.com/ru-ru/windows/win32/api/shellapi/nf-shellapi-shgetfileinfoa?redirectedfrom=MSDN
    [DllImport("shell32.dll", CharSet = CharSet.Unicode, EntryPoint = "SHGetFileInfo")]
    public static extern Enums.ExeType GetExeType(string pszPath, uint dwFileAttributes = 0, IntPtr psfi = default,
    uint cbFileInfo = 0, uint uFlags = 0x2000);
    }
    В главном классе Program.cs вызываем:

    Код
    using System;
    using System.IO;

    internal static class Program
    {
    public static void Main(string[] args)
    {
    Console.Title = "PE Check SubSystem by r3xq1";
    try
    {
    if (Path.GetExtension(args[0]) != ".exe" && Path.GetExtension(args[0]) != ".dll")
    {
    Console.WriteLine("Only the (.exe and .dll) file extension is available.");
    Console.ReadKey();
    }
    else
    {
    if (args.Length > 0 && File.Exists(args[0]))
    {
    Console.WriteLine($"File: {args[0]}");
    Console.WriteLine($"Type: {CheckSubSystem(args[0])}");
    Console.ReadLine();
    }
    else
    {
    Console.WriteLine("File not found! Try dragging it into this window.");
    Console.ReadKey();
    }
    }
    }
    catch
    {
    Console.WriteLine("Move the file to this window");
    Console.ReadKey();
    }
    }

    private static string CheckSubSystem(string pszPath)
    {
    Enums.ExeType type = NativeMethods.GetExeType(pszPath);
    return type != Enums.ExeType.PE && type != Enums.ExeType.MZ ? "WinForms" : "Console";
    }
    }
    Компилируем!
    После берём любой бинарный файл .exe и перетаскиваем его на наш скомпилированный файл.
     
  2. Lamer_down
    Lamer_down 18 авг 2020 Заблокирован(а) 6 17 июн 2020
    Я то думал тут поды будут:orehus:
     
Загрузка...
Top