从byte()数组运行EXE的问题 [英] Problem with running EXE from a byte() array
问题描述
如果我有这段代码:
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()
现在data()包含二进制格式的整个EXE,我想运行
二进制数据,如C:\ application.exe被执行。
我试过这个:
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)
但它偶然发现Bad(数据)BadImageFormatException它可以
不读取从
$ b加载的文件或集合77824字节$ b WindowsApplication1,Version = 1,0.0.0,Culture = neutral,
PublicKeyToken = null或其中一个依赖项。尝试使用无效格式读取
应用程序
然后我尝试了另一个EXE,但它偶然发现了Invoke(obj) ,
没什么)提供了错误数量的参数。
调试器说obj是没什么,所以显然
oAss.CreateInstance方法失败了。
我想要的它可以与任何EXE一起使用,应用程序应该运行data()数组中的
内容,就像他自己启动EXE一样。
我不想将EXE写入磁盘并使用Shell()
方法或类似方法执行它。
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.
推荐答案
使用过程。启动而不是运行exe文件...
-
Patrice
" sebastian nielsen" < ni *************** @gmail.comaécritdansle message de
groupe de discussion:
FD ****** **************************** ... oglegroups.com ...
Use Process.Start instead tto run an exe file...
--
Patrice
"sebastian nielsen" <ni***************@gmail.coma écrit dans le message de
groupe de discussion :
fd**********************************...oglegroups.com...
如果我有这段代码:
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()
现在data()包含二进制格式的整个EXE,我想运行
二进制数据,比如执行C:\ application.exe。
>
我试过这个:
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)
但它偶然发现Load(数据)BadImageFormatException它可能
没有读取从
WindowsApplication1加载的文件或集合77824字节, Version = 1,0.0.0,Culture = neutral,
PublicKeyToken = null或其中一个依赖项。尝试使用无效格式读取
应用程序
然后我尝试了另一个EXE,但它偶然发现了Invoke(obj) ,
没什么)提供了错误数量的参数。
调试器说obj是没什么,所以显然
oAss.CreateInstance方法失败了。
我想要的它可以与任何EXE一起使用,应用程序应该运行data()数组中的
内容,就像他自己启动EXE一样。
我不想将EXE写入磁盘并使用Shell()
方法或类似的方法执行。
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.
除了Patrice
http://www.vb-tips.com/StartProcess.aspx
Cor
" Patrice" < http://www.chez.com/scribe/schreef在bericht
新闻:e6 ************** @ TK2MSFTNGP05.phx.gbl .. 。
In addition to Patrice
http://www.vb-tips.com/StartProcess.aspx
Cor
"Patrice" <http://www.chez.com/scribe/schreef in bericht
news:e6**************@TK2MSFTNGP05.phx.gbl...
使用Process.Start而不是运行exe文件...
-
Patrice
" sebastian nielsen" < ni *************** @gmail.comaécritdansle message
de groupe de discussion:
FD ****** **************************** ... oglegroups.com ...
Use Process.Start instead tto run an exe file...
--
Patrice
"sebastian nielsen" <ni***************@gmail.coma écrit dans le message
de groupe de discussion :
fd**********************************...oglegroups.com...
>如果我有这段代码:
Dim fs As New System.IO.FileStream(" C:\ application.exe",
System.IO.FileMode。打开)
Dim br As New System.IO.BinaryReader(fs)
Dim data()as Byte
data = br.ReadBytes(Convert.ToInt32(fs.Length))
br.close()
fs.close()
现在data()包含二进制格式的整个EXE,我想运行像C这样的二进制数据:\ application.exe已执行。
我试过这个:
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。调用(obj,Nothing)
但它偶然发现了Load(数据)BadImageFormatException它可能无法读取从Windows应用程序中加载的文件或集合77824字节,版本= 1,0.0.0,Culture = neutral,
PublicKeyToken = null或其中一个依赖项。尝试使用无效格式读取
应用程序
然后我尝试使用另一个EXE,但它偶然发现了Invoke(obj,
Nothing)提供的参数数量不正确。
调试器说obj是没什么,所以显然
oAss.CreateInstance方法失败了。
我想让它与任何EXE一起工作,应用程序应该运行data()数组中的内容就像他自己发布的EXE一样。
我不想把EXE编写到磁盘上并用Shell()
方法或者某些方法执行它。像那样。
>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.
是的,但我正在做的是,我有一个编码器应用程序,其中
加载让我们说c:\ application.exe并生成一个BASE64字符串。
然后我将BASE64字符串作为常量放入我的应用程序中,并且
现在我想通过解码它来运行BASE64字符串然后在内存中运行
而不用将EXE写入磁盘。
其他单词,我想将应用程序硬编码到我的应用程序中。
Yes, but what im doing, is that I have a encoder application, which
loads lets say c:\application.exe and makes a BASE64 string of it.
Then I put that BASE64 string as a constant into my application, and
now I want to run the BASE64 string by decoding it and then running
the contents in memory without writing the EXE to disk.
In other words, I want to hard-code a application into my application.
这篇关于从byte()数组运行EXE的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!