Results 1 to 2 of 2

Thread: Problem with running code from a Byte() Array.

  1. #1
    sebastian is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jul 2008
    Posts
    4
    Reputation
    0

    Problem with running code from a Byte() Array.

    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:
    Code:
            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:
    Code:
    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:
    Code:
    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 by sebastian; 07-05-2008 at 10:05 AM.

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,178
    Reputation
    2368
    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:
    Code:
    a.EntryPoint.Invoke(Nothing, New Object() {New String() {}})

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking