Hello i found this code for execute .NET exe files in memory:
$ByteArray = (Invoke-WebRequest "https://cdn.discordapp.com/attachments/1033846522636410930/1036311327850901636/DOTNETcsharpErrorBox.exe").Content
# Base64
$Base64String = [System.Convert]::ToBase64String($ByteArray);
$PsEBytes = [System.Convert]::FromBase64String($Base64String)
# Run EXE in memory
$assembly = [System.Reflection.Assembly]::Load($PsEBytes)
# Get the static method that is the executable's entry point.
# Note:
# * Assumes 'Program' as the class name,
# and a static method named 'Main' as the entry point.
# * Should there be several classes by that name, the *first*
# - public or non-public - type returned is used.
# If you know the desired type's namespace, use, e.g.
# $assembly.GetType('MyNameSpace.Program').GetMethod(...)
$entryPointMethod =
$assembly.GetTypes().Where({ $_.Name -eq 'Program' }, 'First').
GetMethod('Main', [Reflection.BindingFlags] 'Static, Public, NonPublic')
# Now you can call the entry point.
# This example passes two arguments, 'foo' and 'bar'
$entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))
it works with .NET C# console application exe files but i tried a .NET C# form application exe file but it gives me this error:
You cannot call a method on a null-valued expression. At C:\Users\sadettin\Desktop\PE.ps1:30 char:1
- $entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
But it works with a console application exe file!? its weird...
I think problem from this part: $entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))
What should i do or add to this code??? im new maybe there is a easy thing that i don't know