内存中加载modlue

内存中加载modlue

    $Domain = [AppDomain]::CurrentDomain
    $DynAssembly = New-Object System.Reflection.AssemblyName('TempAssembly')
    $AssemblyBuilder = $Domain.DefineDynamicAssembly($DynAssembly, [Reflection.Emit.AssemblyBuilderAccess]::Run)
    $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule('TempModule')

    $ModuleBuilder2 = $AssemblyBuilder.DefineDynamicModule('hello.dll')
    $TypeBuilder = $ModuleBuilder.DefineType('TempClass', [Reflection.TypeAttributes]::Public)
    $TypeBuilder.CreateType()
    $HelloDllBytes = [Convert]::FromBase64String('{PE base64}')
    # Calling LoadModule doesn't pass through the internal nLoad method like Assembly/AppDomain.Load does. :)
    $HelloDllModule = [TempClass].Assembly.LoadModule('hello.dll', $HelloDllBytes)
    # Invoke the Hello method within the hello.dll module that was loaded in memory
    $HelloDllModule.GetTypes()[0].GetMethod('Hello').Invoke($null, @())


×

纯属好玩

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
,