Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to get a function implementing equivalent in bytecode (maybe get it in byte[] array) , and execute it?
also if i read bytes from an executable file and put them in a byte[] tab, how can i execute it?
thanks for any help!! :-)
Posted
Comments
Sergey Alexandrovich Kryukov 25-Feb-12 17:57pm    
Why on Earth?
--SA

Quick answer: you cannot do it. Moreover, a byte code outside of the whole context of the assembly does not make fully defined meaning. An attempt to solve this problem simply makes no sense.

Perhaps you can explain your ultimate goal; in this case you could possibly get some useful advice.

—SA
 
Share this answer
 
v2
Comments
F. Aro 26-Feb-12 1:46am    
let assume i added a little executable to my project resources as file (i removed extension .exe to hide it type)

* if i want to execute with output environnement :
(make it a file by writing it bytes in a filepath exemple "prog.exe"
using : byte [] b=global::namespace.properties.resources.prog; and system.io ...to make it.....etc...
finally calling system.diagnostics.process to start execution..

* if i want to execute the prog without this hole process, by only having the bytes byte[] as parameter, and start the execution on this set of bytes, without creating an associated file ... how can i ?

the o.s surely executes an executable by loading its bytes bytecode an run it, how to do that in c# ?

thanks.
If it is the full byte[] from an .net executable file, use Assembly.Load(byte[]) or AppDomain.Current.Load(byte[]) and then use Reflection to locate the object or anything you want. (It got no different from loading from a file) Of course you can invoke any of the method found then.

If the byte[] is the IL byte code or similar, you may be able to use ILGenerator.Emit() and create a executable delegate, and then execute it. But I guess you will have a lot of trouble get it working properly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900