Problem with running code from a Byte() Array.

sebastian

New member
Joined
Jul 5, 2008
Messages
4
Programming Experience
10+
In my software, I have loaded in a VB.NET EXE into a byte-array, encrypted it with System.Security.Cryptography.Rijndael.

Then I encoded the encrypted EXE as a Base64-string and then put it as a string constant in my decryptor application.

The decryptor application asks for a password/licensekey and then Rijndael-decrypt the code, and then tries to run it.

The code which run the decoded software is this, and this run in a new thread:
VB.NET:
        Dim a As Assembly = Assembly.Load(feature1code)
        Dim method As MethodInfo = a.EntryPoint
        Dim o As Object = a.CreateInstance(method.Name)
   >>  method.Invoke(o, New Object(0) {"1"})

feature1code is a byte() array containing the decoded software.

The error message:
System.ArgumentException: Object of type 'String' cannot be converted to type 'String[]' raised at ">>"

Im are 100 % sure that the software decrypts successfully, since when I look at "a" in the debugger, I can see the assembly name of the decrypted application, and all corresponding data.

If you want to try this for yourself, put this in sub main of a consoleapplication:
VB.NET:
Dim feature1code() as Byte
        Dim fs As New System.IO.FileStream("C:\application.exe", System.IO.FileMode.Open)
        Dim bs As New System.IO.BinaryReader(fs)
        feature1code = bs.ReadBytes(Convert.ToInt32(fs.Length))
        bs.Close()
        fs.Close()
        Dim a As System.Reflection.Assembly = System.Reflection.Assembly.Load(feature1code)
        Dim method As System.Reflection.MethodInfo = a.EntryPoint
        Dim o As Object = a.CreateInstance(method.Name)
       method.Invoke(o, New Object(0) {"1"})

*********************************************************
SOLVED
*********************************************************
Solution:
VB.NET:
method.Invoke(o, New Object() {New String() {"1"}})
I posted this in multiple forums, for example Flashback forum and Devshed forums and got answer in Flashback forum.
 
Last edited:
method.Name is not a valid type name and CreateInstance will return Nothing, this value will be correct with the EntryPoint since it is a shared method. So you can shorten the code to this:
VB.NET:
a.EntryPoint.Invoke(Nothing, New Object() {New String() {}})
 
Back
Top