Загрузка...

Load assembly using internal method

Тема в разделе C# создана пользователем aysman 7 мар 2018. 235 просмотров

Загрузка...
  1. aysman
    aysman Автор темы 7 мар 2018 0 17 сен 2017
    Код
    public static class NetLoader
    {
    /// <summary>
    /// Load an assembly, using the internal method
    /// </summary>
    /// <param name="buffer">Your .NET PE</param>
    /// <returns>A loaded assembly</returns>
    public static Assembly Load(byte[] buffer)
    {
    var param = GetParameters();
    param[0] = buffer;
    return (Assembly)method.Invoke(null, param);
    }
    private static object[] GetParameters()
    {
    if (MajorVersion() >= 4)
    return new object[] { null, null, null, null, false, null };
    else
    return new object[] { null, null, null, null, false };
    }
    private static new Type GetType()
    {
    if (MajorVersion() >= 4)
    return Type.GetType("System.Reflection.RuntimeAssembly");
    else
    return Type.GetType("System.Reflection.Assembly");
    }
    private static MethodInfo GetMethod(Type type)
    {
    return type.GetMethod("nLoadImage", BindingFlags.Static | BindingFlags.NonPublic);
    }
    private static int MajorVersion()
    {
    return Environment.Version.Major;
    }
    static Type type;
    static MethodInfo method;
    static NetLoader()
    {
    type = GetType();
    method = GetMethod(type);
    }
    }
     
  2. NeZox-
    NeZox- 7 мар 2018 Заблокирован(а) 11 3 мар 2018
    Что это?
     
Top