Jump to content

[Solved] Assembler - string & array


Ramzes
 Share

Recommended Posts

Hello,

I'm working with ASM in AutoIt and I've problem with string using (Flat Assembler isn't good converter).

1/

I wrote little example of calling MessageBox but it doesn't work.

My code:

#include <Memory.au3>
Global Const $pRemoteCode = _MemVirtualAlloc(0, 512, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE)
Global Const $tCodeBuffer = DllStructCreate("byte[512]", $pRemoteCode)
Global Const $USER32_MessageBoxA = GetFuncAddress("user32.dll", "MessageBoxA")
; String = "Hello"
Global Const $tString = DllStructCreate("char[5]")
Global Const $pString = DllCallbackGetPtr($tString)
DllStructSetData($tString, 1, "Hello")
; --- ASM Code ---
DllStructSetData($tCodeBuffer, 1, _
  "0x" & _
  "68" & SwapEndian(0) & _                               ; push
  "68" & SwapEndian($pString) & _                         ; push
  "68" & SwapEndian($pString) & _                         ; push
  "68" & SwapEndian(0) & _                               ; push
  "B8" & SwapEndian($USER32_MessageBoxA) & _      ; mov eax
  "FFD0" & _                ; call eax
  "C3" _ ; ret
  )
; ----------------
$Return = DllCall("user32.dll", "int", "CallWindowProcW", _
  "ptr", $pRemoteCode, _
  "int", 0, _
  "int", 0, _
  "int", 0, _
  "int", 0)
MsgBox(32, "Return:", $Return[0])
; --- Functions ---
Func SwapEndian($iValue)
Return Hex(Binary($iValue))
EndFunc ;==>SwapEndian
Func GetFuncAddress($Library, $Function)
$Return = DllCall("kernel32.dll", "handle", "GetModuleHandleW", "wstr", $Library)
If @error Then Return 0
$Return = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $Return[0], "str", $Function)
If @error Then Return 0
Return $Return[0]
EndFunc
; ----------------

Result of my work is this window:

Posted Image

"Błąd" means error.

2/

What if I call function which returns array of data? How can I get "array[x]" ?

Edited by Ramzes

Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font]

Link to comment
Share on other sites

To get support here for ASM is a little bit tricky but you can have a look here:

AssembleIt is easier to use than you did a la trancexx.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Firstly, "Hello" is six chars wide, five chars and a nullterminator. This might explain why its fucking up.

Study this code:

#cs
Thread msgbox by Shaggi
#ce
#include <Array.au3>
#include <WinApi.au3>
#AutoIt3Wrapper_UseX64=n
ThreadedMsgBox(0,"HEY","1",0)
ThreadedMsgBox(0,"HEY","2",0)
ThreadedMsgBox(0,"HEY","3",0)
ThreadedMsgBox(0,"HEY","4",0)
ThreadedMsgBox(0,"HEY","5",0)
ThreadedMsgBox(0,"HEY","6",0)
ThreadedMsgBox(0,"HEY","7",0)
ThreadedMsgBox(0,"HEY","8",0)
MsgBox(0,"HEY","Last!")
Func ThreadedMsgBox($Flag,$Title,$Text,$Hwnd)
Static $Count = 0
If NOT IsDeclared("Memory_Management1") Then Global $Memory_Management1[1] = [0]
If NOT IsDeclared("Memory_Management2") Then Global $Memory_Management2[1] = [0]
If NOT IsDeclared("Memory_ASM") Then Global $Memory_ASM[1] = [0]
$Count += 1
_ArrayAdd($Memory_Management1,DllStructCreate("wchar[" & StringLen($Title) +1 & "]"))
_ArrayAdd($Memory_Management2,DllStructCreate("wchar[" & StringLen($Text) +1 & "]"))
DllStructSetData($Memory_Management1[$Count],1,$Title)
DllStructSetData($Memory_Management2[$Count],1,$Text)
$Address = DlLCall("Kernel32.dll","ptr","GetProcAddress","handle",_WinApi_GetModuleHandle("User32.dll"),"str","MessageBoxW")
$Stub = "0x" & _
    "68" & Hex(Binary($Flag),8) & _
    "68" & Hex(Binary(DllStructGetPtr($Memory_Management1[$Count]))) & _
    "68" & Hex(Binary(DllStructGetPtr($Memory_Management2[$Count]))) & _
    "68" & Hex(Binary($Hwnd)) & _
    "B8" & Hex(Binary($Address[0])) & _
    "FFD0" & _
    "C3"
_ArrayAdd($Memory_ASM,DllStructCreate("byte[" & Int(StringLen($Stub))+1 & "]"))
DllStructSetData($Memory_ASM[$Count],1,$stub)
$ret = DllCall("Kernel32.dll","handle","CreateThread","int",0,"int",0,"ptr",DllStructGetPtr($Memory_ASM[$Count]),"int",0,"int",0,"int",0)
Return $Ret[0]
EndFUnc
Func GetMsgBoxReturn($MsgBox)
$iRet = DllCall("Kernel32","int","GetExitCodeThread","handle",$MsgBox,"int*",0)
Return $iRet[2]
EndFunc

Also for your second question, elaborate. Something returning an array of what? did the function allocate it, or did you? Prototype? You cant do $return [x] before you have collected the binary data from a dllstruct into an autoit array

Edited by Shaggi

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Link to comment
Share on other sites

@UEZ

There is only one and not enough good example of using string.

@Shaggi

Thanks!

You code is little strange but it works. I'll study it.

Btw. If I use threads my script is faster?

Edited by Ramzes

Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font]

Link to comment
Share on other sites

I thought that there were some examples. Anyway, here the link with examples but German only: http://www.autoit.de/index.php?page=Thread&threadID=22201

You can use Google Translator.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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...