Jump to content

Assembly support in AutoIt


trancexx
 Share

Recommended Posts

Don't jump on me now for maybe somewhere bombastic title, that is intentional btw :mellow:

Anyway, this is nothing new. I mentioned earlier today in some post that Ward did it some time ago, but I'm not seeing him around lately :(

I'm just translating it to plain human language.

I know that there are some people that are actually very good with assembly (unlike me) and AutoIt (also unlike me) and I'm sure they can elevate this to the level of true AutoIt's virtue.

This script is showing basic mathematical operations on two integers using inline (you might call it that way) assembly:

#NoTrayIcon

ConsoleWrite(_Add(56, 4) & @CRLF)
ConsoleWrite(_Substract(75, 37) & @CRLF)
ConsoleWrite(_Multiply(5, 7) & @CRLF)
ConsoleWrite(_Divide(56, 8) & @CRLF)

Func _Add($iNum1, $iNum2)
    
    #cs
        55                      push ebp
        89E5                    mov ebp, esp
        8B4508                  mov eax, dword[ebp+08]
        03450C                  add eax, dword[ebp+0C]
        5D                      pop ebp
        C3                      ret 
    #ce

    Local $Opcode = "0x5589E58B450803450C5DC3" ;ADD TWO INTEGERS
                
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($CodeBuffer, 1, $Opcode)
    
    Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", _
            "ptr", DllStructGetPtr($CodeBuffer), _
            "int", $iNum1, _
            "int", $iNum2, _
            "int", 0, _
            "int", 0)

    Return $Ret[0]
    
EndFunc   


Func _Substract($iNum1, $iNum2)
    
    #cs
        55                      push ebp
        89E5                    mov ebp, esp
        8B4508                  mov eax, dword[ebp+08]
        2B450C                  sub eax, dword[ebp+0C]
        5D                      pop ebp
        C3                      ret 
    #ce

    Local $Opcode = "0x5589E58B45082B450C5DC3" ;SUBSTRACT TWO INTEGERS  
                
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($CodeBuffer, 1, $Opcode)
    
    Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", _
            "ptr", DllStructGetPtr($CodeBuffer), _
            "int", $iNum1, _
            "int", $iNum2, _
            "int", 0, _
            "int", 0)

    Return $Ret[0]
    
EndFunc 


Func _Multiply($iNum1, $iNum2)
    
    #cs
        55                      push ebp
        89E5                    mov ebp, esp
        8B4508                  mov eax, dword[ebp+08]
        F76D0C                  imul dword[ebp+0C]
        5D                      pop ebp
        C3                      ret 
    #ce

    Local $Opcode = "0x5589E58B4508F76D0C5DC3" ;MULTIPLY TWO INTEGERS
                
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($CodeBuffer, 1, $Opcode)
    
    Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", _
            "ptr", DllStructGetPtr($CodeBuffer), _
            "int", $iNum1, _
            "int", $iNum2, _
            "int", 0, _
            "int", 0)

    Return $Ret[0]
    
EndFunc  


Func _Divide($iNum1, $iNum2)
    
    #cs
        55                      push ebp
        89E5                    mov ebp, esp
        8B4508                  mov eax, dword[ebp+08]
        99                      cdq
        F77D0C                  idiv dword[ebp+0C]
        5D                      pop ebp
        C3                      ret 
    #ce

    Local $Opcode = "0x5589E58B450899F77D0C5DC3" ;DIVIDE TWO INTEGERS
                
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($CodeBuffer, 1, $Opcode)
    
    Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", _
            "ptr", DllStructGetPtr($CodeBuffer), _
            "int", $iNum1, _
            "int", $iNum2, _
            "int", 0, _
            "int", 0)

    Return $Ret[0]
    
EndFunc

edit: typo, typo, eng, eng, typo

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Since you are quiet I would think that "W" is not a problem.

It could be mutual* misunderstanding of your processor and $Opcode.

What processor is there?

Anyway, I wish Ward is here somewhere to help us with (assembly --> opcode) action. Unfortunately it appears that poor lady died. Yes, yes, that's right, Ward was this old lady (very old, like 110-120) and she died few weeks ago (so I was told by her mother) God rest her soul.

One more word about this method. By implementing it you don't need to use external dlls. This is the same thing as that. If you look at any first post function you will actually be seeing a DllCall to some dll (function inside that dll) that is calculating for you. All that would come with that dll is everything arround its hart - the function.

So, this is basically stripping redundancy.

* - funny part

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Interesting! The only thing now is to make a asm interpreter to convert it to opcode :mellow:

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator

VW Bug user

Pinheiral (Pinewood) city:

http://pt.wikipedia.org/wiki/Pinheiral

Link to comment
Share on other sites

Too bad. :mellow: But I guess that was not the intent of showing this.

For $i = 0 to UBound($addArray)-1
    $addArray[$i] = Random(0,100,1)
Next

 ;$tempvar because you can't just add and do nothing with it
$normalAdd = TimerInit()
For $i = 0 to UBound($addArray)-1 Step 2
    $tempvar = $addArray[$i] + $addArray[$i+1]
Next
$timeNormal = TimerDiff($normalAdd)

$assemblyAdd = TimerInit()
For $i = 0 to UBound($addArray)-1 Step 2
    $tempvar = _Add($addArray[$i],$addArray[$i+1])
Next
$timeAssembly = TimerDiff($assemblyAdd)

ConsoleWrite($timeNormal & @CRLF)
ConsoleWrite($timeAssembly & @CRLF)
Edited by Manadar
Link to comment
Share on other sites

Too bad. :mellow: But I guess that was not the intent of showing this.

For $i = 0 to UBound($addArray)-1
    $addArray[$i] = Random(0,100,1)
Next

 ;$tempvar because you can't just add and do nothing with it
$normalAdd = TimerInit()
For $i = 0 to UBound($addArray)-1 Step 2
    $tempvar = $addArray[$i] + $addArray[$i+1]
Next
$timeNormal = TimerDiff($normalAdd)

$assemblyAdd = TimerInit()
For $i = 0 to UBound($addArray)-1 Step 2
    $tempvar = _Add($addArray[$i],$addArray[$i+1])
Next
$timeAssembly = TimerDiff($assemblyAdd)

ConsoleWrite($timeNormal & @CRLF)
ConsoleWrite($timeAssembly & @CRLF)
I respect you and your coding abilities hence me take that as a joke.

edit: words, playing with

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Try unicode version of CallWindowProc.

MSDN link says that CallWindowProc is supported since Windows 95 and Windows NT 3.1

1) on WIN98SE

- with CallWindowProc it crashes

- with CallWindowProcA it crashes too

- with CallWindowProcW it returns 0 without error

2) on WINXP

- with CallWindowProc it works fine and returns good results

Edited by Zedna
Link to comment
Share on other sites

1) on WIN98SE

- with CallWindowProc it crashes

- with CallWindowProcA it crashes too

- with CallWindowProcW it returns 0 without error

2) on WINXP

- with CallWindowProc it works fine and returns good results

Problem appears to be closely related with MSLU. :mellow:

ahhh, well... You know, I have one copy of Microsoft Windows v1.0

Header of programs says "This program requires Microsoft Windows" :(

Try this. This should just print number 128:

#NoTrayIcon

ConsoleWrite(_Ret128() & @CRLF)

Func _Ret128()
    
    #cs
        B8                      mov eax, 00000080
        C3                      ret
    #ce

    Local $Opcode = "0xB880000000C3"
    
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($CodeBuffer, 1, $Opcode)
    
    Local $Ret = DllCall("user32.dll", "int", "CallWindowProcW", _
            "ptr", DllStructGetPtr($CodeBuffer), _
            "int", 0, _
            "int", 0, _
            "int", 0, _
            "int", 0)

    Return $Ret[0]
    
EndFunc

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

trancexx

Hey! Very nice example! Thanks for sharing. But where you found information about this? If this is not a secret, can you post the reference link? :(

No secrets (there was tis girly band named like that, I think :mellow: ) here.

I wouldn't know what to post you as a reference. This was implemented in some scripts posted by mentioned poor, to early passed away, little lady. I'm kidding here, that's obvious, right? I guess nothing can bring to life that non beating autoit heart.

I guess the best reference would be reading Wards posts here on forum and posted codes.

It hit me what is that about when source code of Base64Encode was posted. When I started thinking what would I do with that code if I was a compiler (khm, khm...) some cards were opened. (link to that).

Loading dll from memory and related (link) is something that everyone should read too if interested in this. There can be seen how to implement call - very important instruction.

And link to CallWindowProc function.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Problem appears to be closely related with MSLU. :mellow:

ahhh, well... You know, I have one copy of Microsoft Windows v1.0

Header of programs says "This program requires Microsoft Windows" :(

Try this. This should just print number 128:

#NoTrayIcon

ConsoleWrite(_Ret128() & @CRLF)

Func _Ret128()
    
    #cs
        B8                      mov eax, 00000080
        C3                      ret
    #ce

    Local $Opcode = "0xB880000000C3"
    
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($CodeBuffer, 1, $Opcode)
    
    Local $Ret = DllCall("user32.dll", "int", "CallWindowProcW", _
            "ptr", DllStructGetPtr($CodeBuffer), _
            "int", 0, _
            "int", 0, _
            "int", 0, _
            "int", 0)

    Return $Ret[0]
    
EndFunc
Returns 0 on WIN98SE.
Link to comment
Share on other sites

  • 3 weeks later...

Anyway, I wish Ward is here somewhere to help us with (assembly --> opcode) action. Unfortunately it appears that poor lady died. Yes, yes, that's right, Ward was this old lady (very old, like 110-120) and she died few weeks ago (so I was told by her mother) God rest her soul.

Why I am a old lady :)

Maybe my English is not good enough to understood what do you say :)

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Link to comment
Share on other sites

Why I am a old lady :)

Maybe my English is not good enough to understood what do you say :)

You are alive!!! Someone's been lying o:)

How many ways there are to load assembly code from our scripts, that you know of?

Is there any way for AutoIt script to be compiled to PE format? Why don't you try it? I can see thousands of problems, but I think that few smart heads could even make it happen.

♡♡♡

.

eMyvnE

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...