If I have this code:
Dim fs As New System.IO.FileS tream("C:\appli cation.exe",
System.IO.FileM ode.Open)
Dim br As New System.IO.Binar yReader(fs)
Dim data() as Byte
data = br.ReadBytes(Co nvert.ToInt32(f s.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.Reflecti on.Assembly
Dim meth As System.Reflecti on.MethodInfo
Dim obj As Object
oAss = System.Reflecti on.Assembly.Loa d(data)
meth = oAss.EntryPoint
obj = oAss.CreateInst ance(meth.Name)
meth.Invoke(obj , Nothing)
but it stumbled on Load(data) that BadImageFormatE xception "It could
not read the file or collection 77824 bytes loaded from
WindowsApplicat ion1, 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.CreateInst ance 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.FileS tream("C:\appli cation.exe",
System.IO.FileM ode.Open)
Dim br As New System.IO.Binar yReader(fs)
Dim data() as Byte
data = br.ReadBytes(Co nvert.ToInt32(f s.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.Reflecti on.Assembly
Dim meth As System.Reflecti on.MethodInfo
Dim obj As Object
oAss = System.Reflecti on.Assembly.Loa d(data)
meth = oAss.EntryPoint
obj = oAss.CreateInst ance(meth.Name)
meth.Invoke(obj , Nothing)
but it stumbled on Load(data) that BadImageFormatE xception "It could
not read the file or collection 77824 bytes loaded from
WindowsApplicat ion1, 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.CreateInst ance 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.
Comment