Jump to content

Recommended Posts

Hey everyone,

I have a DLL file that I need to use to decrypt text strings by using DllCall in AutoIT. However, I can't seem to get my syntax right in AutoIT to get it to work.

I know the DLL works, because I have written code in VB.net to open the DLL, pass in the encrypted string and reference the hidden key in the DLL. I just pass in the encrypted string as a command line argument, and it prints the decrypted string in the console.

Here is my VB.net code (the DLL file is added as a reference in the project. The DLL file name is "Master.Test.dll"):

Imports Master.Test.Decryption

Public Class DECRYPT

    Public Sub DECRYPT_Load() Handles MyBase.Load

        Me.Visible = False
        Me.ShowInTaskbar = False

        Dim Args = Environment.GetCommandLineArgs()

        Dim Decrypted As String = ""

        If Args.Length > 1 Then

            Dim Encrypted As String = Args(1)

            If Encrypted.Substring(Encrypted.Length - 1, 1) = "=" And Encrypted.Length Mod 4 = 0 Then

                Decrypted = Encrypt.Decrypt(Encrypted, Encrypt.HIDDEN_Key)

            End If

        End If

        If Decrypted.Length > 0 Then

            Console.WriteLine(Decrypted)

        End If

        Application.Exit()

    End Sub

End Class

Here is my code in AutoIT to open the DLL, make the DLL call, and write the results to the console, but I just continue to get errors or "0".

Const $DllFile = "C:\TEST\Master.Test.dll"

Const $Encrypted = "encryptedstring" ;replace with encrypted string

Local $tDll = DllOpen($DllFile)

$tResults = DllCall($tDll, "str", "Master.Test.Decryption.Encrypt.Decrypt", "str", $Encrypted, "str", "Master.Test.Decryption.Encrypt.HIDDEN_Key")

DllClose($DllFile)

ConsoleWrite("Decrypted: " & $tResults)

The console output:

Decrypted: 0+>12:34:15 AutoIt3.exe ended.rc:0

I tried using "$tResults[0]", because I think the return value should be in an array format from what I've read while searching. However, this returns the error:

Subscript used on non-accessible variable.

I'm not sure what else to do. I even tried passing in the hidden key in the DLL manually as it's own string, instead of trying to reference it in the DLL. However, this ends with the same result. So, I must be doing something else wrong.

Edited by HelloAuto
Link to post
Share on other sites

You should test @error first.  I don't think you need "Master.Test.Decryption" prefix.  and passing "Master.Test.Decryption.Encrypt.HIDDEN_Key" will not be converted in the dll as it is expecting the true key (I believe).  You may need to use 'cdecl' method.  Have you look at the dll with dllexp ?  It may give you more information about the function visibility.

 

Link to post
Share on other sites
38 minutes ago, Nine said:

You should test @error first.  I don't think you need "Master.Test.Decryption" prefix.  and passing "Master.Test.Decryption.Encrypt.HIDDEN_Key" will not be converted in the dll as it is expecting the true key (I believe).  You may need to use 'cdecl' method.  Have you look at the dll with dllexp ?  It may give you more information about the function visibility.

 

Thank you.

I tried everything you mentioned, but it still returns "0". "@error" shows "0" too. I even passed in the hidden key value manually. Here is my updated code:

Const $DllFile = "C:\TEST\Master.Test.dll"

Const $Encrypted = "encryptedstring"

Local $tDll = DllOpen($DllFile)

$tResults = DllCall($tDll, "str:cdecl", "Encrypt.Decrypt", "str", $Encrypted, "str", "HIDDENKEYVALUE")

DllClose($DllFile)

ConsoleWrite("Decrypted: " & @error & @CRLF)
ConsoleWrite("Decrypted: " & $tResults & @CRLF)

Oddly, when I used dllexp, I get nothing. I have to use dotPeek in order to find the function names. It's weird that they work in VB.net, but not AutoIT.

Link to post
Share on other sites

You are using @error wrongly, it should immediately follow the dllcall as it is erased with dllclose.  Please modify script and report on @error as I am pretty sure, it will be non-zero.

Link to post
Share on other sites
5 minutes ago, Nine said:

You are using @error wrongly, it should immediately follow the dllcall as it is erased with dllclose.  Please modify script and report on @error as I am pretty sure, it will be non-zero.

You're right. My apologies.

I updated the code, and it returns just the number "3" for @error.

Although, I'm not sure what that means, or how to troubleshoot it.

Link to post
Share on other sites
Quote
3 = "function" not found in the DLL file

From help file.  It is quite obvious.  Either there is an error in spelling the function name or the function is not exported correctly.  Not an AutoIt issue anymore...

Link to post
Share on other sites
2 minutes ago, Nine said:

From help file.  It is quite obvious.  Either there is an error in spelling the function name or the function is not exported correctly.  Not an AutoIt issue anymore...

I'm not saying it's a problem with AutoIT.

I think it's a problem with the syntax I'm using. However, I can't figure out what it wants to call the function.

I know how to do it in VB.net, and it works fine. I just want to replicate that in AutoIT.

Is that possible?

Link to post
Share on other sites

And you're sure that your dll file is a standard Windows dll file implemented in unmanaged code e.g. C or C++ which can be used in AutoIt?

Link to post
Share on other sites
1 minute ago, LarsJ said:

And you're sure that your dll file is a standard Windows dll file implemented in unmanaged code e.g. C or C++ which can be used in AutoIt?

Unfortunately, it's not my DLL file. It was provided to me.

I thought I could use DllCall() to call any Dll with functions.

I even turned my VB.net code into an EXE. I then tried to use that EXE in AutoIT using the Run() function, which worked fine, until I tried to use the GUI Wrapper to compile it. I then get an error stating "Error: The requested action with this object has failed", whenever I actually run the compiled application.

Link to post
Share on other sites

I'm pretty sure your dll file is a .NET assembly dll file implemented in managed code e.g. C#, It's indicated simply by the name. It cannot be used immediately in AutoIt.

Your best chance of using a .NET assembly dll file in AutoIt is through the code in this thread.

Link to post
Share on other sites
37 minutes ago, LarsJ said:

I'm pretty sure your dll file is a .NET assembly dll file implemented in managed code e.g. C#, It's indicated simply by the name. It cannot be used immediately in AutoIt.

Your best chance of using a .NET assembly dll file in AutoIt is through the code in this thread.

This looks like it may lead me to my answer. I wish I found it sooner in my searching. Thank you.

Link to post
Share on other sites

If you want (may be not) my appreciation of the situation.  You are forcing the usage of a DLL while there is multiple UDF (in AutoIt) that can address your users requirements.  I would strongly suggest to take a step back to understand the true needs and then decide of the appropriate solution.

Link to post
Share on other sites
51 minutes ago, Nine said:

If you want (may be not) my appreciation of the situation.  You are forcing the usage of a DLL while there is multiple UDF (in AutoIt) that can address your users requirements.  I would strongly suggest to take a step back to understand the true needs and then decide of the appropriate solution.

Yes, I'm brand new to AutoIT, and am trying to satisfy a request to modify an existing AutoIT solution, using other tools that already exist outside AutoIT.

I think I have found an even easier solution using Crypt.au3 in AutoIT though.

Thank you all for the help!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...