flat assembler
Message board for the users of flat assembler.

Index > Windows > illegal operation encountered, i guess i INVOKE wrongly!

Author
Thread Post new topic Reply to topic
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
hi,
i am in the process to translate my previous IE Switch Image Utility written in VB into FASM.
i face one problem currently and really hope if the gurus here willing to help.

i am able to assemble the code below but once i run it, i got error message from Windows.

This program has performed an "illegal" operation
and will be shut down.
If the problem persists, contact the program
vendor.

Details:
E1 caused an invalid page fault in

module <unknown> at 0000:00000001.
Registers:
EAX=00000001 CS=0137 EIP=00000001 EFLGS=00010202
EBX=00520000 SS=013f ESP=0053fe34 EBP=0053ff78
ECX=00402087 DS=013f ESI=818e4af8 FS=3c9f
EDX=00000001 ES=013f EDI=818eacd8 GS=0000
Bytes at CS:EIP:
01 00 00 00 00 00 00 16 00 cf 08 65 04 70 00 65
Stack dump:
00401054 00000000 bff88e93 818eacd8 818e4af8 00520000
45003145 00004558 818e4af8 00520000 58003145 00504f45
00000000 00000000 00000000 00000000


i am able to see the "IE Switch Image Utility - Win32 Console Mode" text appeared
in my command box in red color.

below is my code, i suspect the problem is around the line
-> invoke WriteConsole,[conHandleOut],conTitle,45,conReturn,0

Code:
format PE console 4.0
entry start

include '%fasminc%\win32a.inc'

section '.code' code readable executable
   start:
          invoke  AllocConsole
                invoke  GetStdHandle,STD_INPUT_HANDLE
               mov             [conHandleIn],eax
           invoke  GetStdHandle,STD_OUTPUT_HANDLE
              mov             [conHandleOut],eax
          
            invoke  SetConsoleTextAttribute,[conHandleOut],[conColor]
           invoke  WriteConsole,[conHandleOut],conTitle,45,conReturn,0
         
    exit:
           invoke  ExitProcess,0

section '.data' data readable writeable
      conTitle        db      'IE Switch Image Utility - Win32 Console Mode',0

      conColor        dd      4
   conReturn       dd      ?
   
    conHandleIn             dd      ?
   conHandleOut    dd      ?
   
section '.idata' import data readable writeable
       library kernel32,'kernel32.dll'
   
    import  kernel32,\
                 lstrlen,                                        'lstrlenA',\
                     AllocConsole,                           'AllocConsole',\
                 GetStdHandle,                           'GetStdHandle',\
                 SetConsoleTextAttribute,        'SetConsoleTextAttribute',\
                      WriteConsole,                           'WriteConsoleA',\
                        ExitProcess,                            'ExitProcess'
    


sincerely,
vbVeryBeginner d(.><)b
http://sulaiman.thefreebizhost.com
Post 18 Aug 2004, 16:54
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7718
Location: Kraków, Poland
Tomasz Grysztar
The fact is: you have discovered a serious bug caused by the optimization improvements added in fasm 1.54. Since it's so critical flaw, I have updated the existing 1.54 packages with a fix immediately - please download the 1.54 once again to get the fixed version.
Post 18 Aug 2004, 17:30
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex
vbVeryBeginner,

You can try this one: ( StdOut function from Hutch's masm32 package )
Code:
format PE CONSOLE 4.0 
entry start 

include '%fasminc%\win32a.inc' 

section '.code' code readable executable 

start: 

invoke       GetStdHandle,STD_OUTPUT_HANDLE 
mov  [conHandleOut],eax 

invoke       SetConsoleTextAttribute,[conHandleOut],[conColor] 
stdcall   StdOut,conTitle
invoke       ExitProcess,0 

proc      StdOut,lpszText
     
    bWritten dd ?
       sl  dd ?
    enter
       invoke  GetStdHandle,STD_OUTPUT_HANDLE
      mov     [conHandleOut],eax
          invoke  lstrlen,[lpszText]
          mov     [sl],eax
            lea     eax,[bWritten]
              invoke  WriteFile,[conHandleOut],[lpszText],[sl],eax,NULL
           mov     eax,[bWritten]
      return
endp

section '.data' data readable writeable 
conTitle db 'IE Switch Image Utility - Win32 Console Mode',0 

conColor dd 4 
conReturn dd ? 

conHandleIn dd ? 
conHandleOut dd ? 

section '.idata' import data readable writeable

  library kernel32,'kernel32.dll'

  import kernel32,\
         ExitProcess,'ExitProcess',\
         GetStdHandle,'GetStdHandle',\
         SetConsoleTextAttribute,'SetConsoleTextAttribute',\
         WriteFile,'WriteFile',\
         lstrlen,'lstrlenA'
    

_________________
Code it... That's all...
Post 18 Aug 2004, 17:37
View user's profile Send private message Visit poster's website Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
privalov, what bug was this?
Post 18 Aug 2004, 18:43
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
to : privalov
just about to download the new fixed 1.54.
never realized it is a bug of fasm, coz i am just kinda start playing win32 using asm. so whenever things go wrong, i will suspect myself first instead of the application ... :p

i guess i need to get some motivation class to increase my self confidence Surprised lol

i discover a serious bug that even if explain to me, i guess i would not be able to understand. <- and that is funny :p

to:vortex
is AllocConcole unnecessary to invoke?
i will try your nice piece later Smile.
thank you.

sincerely,
vbVeryBeginner d(^.-)b
http://sulaiman.thefreebizhost.com
Post 18 Aug 2004, 19:43
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7718
Location: Kraków, Poland
Tomasz Grysztar
coconut: in some situations it did not realize that the value of label has changed and one more pass should be done, this caused invalid address to occur in generated code.
Post 18 Aug 2004, 19:58
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex
vbVeryBeginner,

You have no need to use the function allocating the console box, the statement
Code:
format PE CONSOLE 4.0
    

is enough to create console based applications.

_________________
Code it... That's all...
Post 19 Aug 2004, 09:51
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
ic, thanks... vortex

but does it means also, i dont have to invoke FreeConsole, does the console self-destroyed it self upon the end of application execution?


sincerely,
vbVeryBeginner d(*-*)b
Post 19 Aug 2004, 12:12
View user's profile Send private message Visit poster's website 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.

Powered by rwasa.