flat assembler
Message board for the users of flat assembler.

Index > Windows > Converting MASM code

Author
Thread Post new topic Reply to topic
TmX



Joined: 02 Mar 2006
Posts: 822
Location: Jakarta, Indonesia
TmX
This is a code about autotyping, written in MASM

Code:
.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
msg db 'Hello Netters in Hanjian Site (http://hanjian.web.id)',13,10
db 'Ini adalah Contoh AutoType with MASM32. Razz',0
app db 'notepad.exe',0
wndclass db 'Notepad',0
childclass db 'Edit',0

.data?
handle dd ?

.code
start:

invoke WinExec,ADDR app,SW_SHOW
invoke FindWindow,ADDR wndclass,0
invoke FindWindowEx,eax,0,ADDR childclass,0
mov handle,eax
mov edx,OFFSET msg
@@:
xor eax,eax
mov al,byte PTR [edx]
or al,al
jz @f
push edx
invoke SendMessage,handle,WM_CHAR,eax,0
invoke Sleep,200
pop edx
inc edx
jmp @b
@@:
invoke ExitProcess,0

END start
    


It's taken from here:
http://www.hanjian-oke.co.cc/2008/08/autotype-with-asm-by-hanjian.html

This is my attempt to translate it to FASM:
Code:
format PE console 4.0
entry start

include 'win32a.inc'
include 'api/kernel32.inc'
include 'api/user32.inc'

section '.data' data readable writeable
        msg db 'Hello Netters in Hanjian Site (http://hanjian.web.id)',13,10
      db 'Ini adalah Contoh AutoType with FASM Razz',0
    app db 'notepad.exe',0
    wndclass db 'Notepad',0
   childclass db 'Edit',0
    handle dd ?

section '.code' code readable executable
start:
 invoke WinExec,addr app,SW_SHOW
     invoke FindWindow,addr wndclass,0
   invoke FindWindowEx,eax,0,addr childclass,0
 mov eax,handle
      mov edx,msg
@@:
      xor eax,eax
 mov al,byte ptr [edx]
       or al,al
    ja @f
       push edx
    invoke SendMessage,handle,WM_CHAR,eax,0
     invoke Sleep,200
    pop edx
     inc edx
     jmp @b

@@:
       invoke ExitProcess,0

section '.idata' import data readable writeable
library kernel32,'kernel32.dll',user32,'user32.dll'

import kernel32,WinExec,'WinExec',\
                Sleep,'Sleep',\
                ExitProcess,'ExitProcess'
import user32,FindWindow,'FindWindow',\
                     FindWindowEx,'FindWindowEx',\
              SendMessage,'SendMessage'  
    


When I tried to compile it, FASM said:
Quote:

flat assembler version 1.67.29 (1267045 kilobytes memory)
typist.asm [25]:
mov al,byte ptr [edx]
error: invalid expression.


How to fix that? Confused
Post 18 Jan 2009, 14:36
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
  mov al, byte [edx] ; or just mov al, [edx] since "byte" is implicit
    
Post 18 Jan 2009, 15:01
View user's profile Send private message Reply with quote
Neutrino



Joined: 18 Dec 2008
Posts: 2
Neutrino
Hi, Tmx!
To get your application work correctly, you also should make some changes in your code:

Code:
format PE console 4.0 entry start include 'win32a.inc' section '.data' data readable writeable         msg db 'Hello Netters in Hanjian Site (http://hanjian.web.id)',13,10             db 'Ini adalah Contoh AutoType with FASM ',0     app db 'notepad.exe',0         wndclass db 'Notepad',0         childclass db 'Edit',0         handle dd ? section '.code' code readable executable start:         invoke WinExec,app,SW_SHOW         invoke FindWindow,wndclass,0         invoke FindWindowEx,eax,0,childclass,0         mov [handle],eax         mov edx,msg @@:         xor eax,eax         mov al,byte[edx]         or al,al         jz @f         push edx         invoke SendMessage,[handle],WM_CHAR,eax,0         invoke Sleep,200         pop edx         inc edx         jmp @b @@:         invoke ExitProcess,0 section '.idata' import data readable writeable library kernel32,'kernel32.dll',user32,'user32.dll' import kernel32,WinExec,'WinExec',\                 Sleep,'Sleep',\                 ExitProcess,'ExitProcess' import user32,FindWindow,'FindWindowA',\                           FindWindowEx,'FindWindowExA',\               SendMessage,'SendMessageA'       

Read FASM manuals for more information Wink

_________________
= )
Post 18 Jan 2009, 17:50
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.