S
sebastian nielsen
If I have this code:
Dim fs As New System.IO.FileStream("C:\application.exe",
System.IO.FileMode.Open)
Dim br As New System.IO.BinaryReader(fs)
Dim data() as Byte
data = br.ReadBytes(Convert.ToInt32(fs.Length))
br.close()
fs.close()
Now data() contains the whole EXE in binary format, and I want to run
the binary data like the C:\application.exe was executed.
I tried with this:
Dim oAss As System.Reflection.Assembly
Dim meth As System.Reflection.MethodInfo
Dim obj As Object
oAss = System.Reflection.Assembly.Load(data)
meth = oAss.EntryPoint
obj = oAss.CreateInstance(meth.Name)
meth.Invoke(obj, Nothing)
but it stumbled on Load(data) that BadImageFormatException "It could
not read the file or collection 77824 bytes loaded from
WindowsApplication1, Version=1,0.0.0, Culture=neutral,
PublicKeyToken=null or one of its dependencys. A attempt to read in a
application with a invalid format was made"
Then I tried with another EXE, but the it stumbled on the Invoke(obj,
Nothing) that a incorrect number of parameters was supplied. The
debugger said that obj was "nothing", so apparently the
oAss.CreateInstance method failed.
I want it to work with any EXE, and the application should run the
content in the data() array like he EXE was launched itself.
I don't want to write the EXE to disk and exec it with the Shell()
method or some like that.
Dim fs As New System.IO.FileStream("C:\application.exe",
System.IO.FileMode.Open)
Dim br As New System.IO.BinaryReader(fs)
Dim data() as Byte
data = br.ReadBytes(Convert.ToInt32(fs.Length))
br.close()
fs.close()
Now data() contains the whole EXE in binary format, and I want to run
the binary data like the C:\application.exe was executed.
I tried with this:
Dim oAss As System.Reflection.Assembly
Dim meth As System.Reflection.MethodInfo
Dim obj As Object
oAss = System.Reflection.Assembly.Load(data)
meth = oAss.EntryPoint
obj = oAss.CreateInstance(meth.Name)
meth.Invoke(obj, Nothing)
but it stumbled on Load(data) that BadImageFormatException "It could
not read the file or collection 77824 bytes loaded from
WindowsApplication1, Version=1,0.0.0, Culture=neutral,
PublicKeyToken=null or one of its dependencys. A attempt to read in a
application with a invalid format was made"
Then I tried with another EXE, but the it stumbled on the Invoke(obj,
Nothing) that a incorrect number of parameters was supplied. The
debugger said that obj was "nothing", so apparently the
oAss.CreateInstance method failed.
I want it to work with any EXE, and the application should run the
content in the data() array like he EXE was launched itself.
I don't want to write the EXE to disk and exec it with the Shell()
method or some like that.