flat assembler
Message board for the users of flat assembler.

Index > Windows > ERROR with structures and "assume"

Author
Thread Post new topic Reply to topic
Necromancer13



Joined: 18 Oct 2007
Posts: 32
Location: Ukraine
Necromancer13 23 Oct 2007, 16:44
Please, help, FASM doensn't want to compile it..
May be, I've defined structures wrong...
And some errors withh assume...

It's a source:

Code:
format PE GUI 4.0
entry start
include '%fasminc%\win32a.inc'
include '%fasminc%\macro\masm.inc'
struc  SEH
{
        .PrevLink        dd ?
        .CurrentHandler  dd ?
        .SafeOffset      dd ?
        .PrevEsp         dd ?
        .PrevEbp         dd ?
}

struc FLOATING_SAVE_AREA
{
    .ControlWord      dd ?
    .StatusWord         dd ?
    .TagWord            dd ?
    .ErrorOffset        dd ?
    .ErrorSelector      dd ?
    .DataOffset         dd ?
    .DataSelector       dd ?
    .RegisterArea       rb SIZE_OF_80387_REGISTERS
    .Cr0NpxStatedd      dd ?
}

struc CONTEXT
{
    .ContextFlags         dd ?
    .Dr0                 dd ?
    .Dr1                dd ?
    .Dr2                dd ?
    .Dr3                dd ?
    .Dr6                dd ?
    .Dr7                dd ?
    .FloatSave                  FLOATING_SAVE_AREA
    .SegGs                dd ?
    .SegFs              dd ?
    .SegEs              dd ?
    .SegDs              dd ?
    .Edi                dd ?
    .Esi                dd ?
    .Ebx                dd ?
    .Edx                dd ?
    .Ecx                dd ?
    .Eax                dd ?
    .Ebp                dd ?
    .Eip                dd ?
    .SegCs              dd ?
    .EFlags             dd ?
    .Esp                dd ?
    .SegSs              dd ?
    .ExtendedRegisters          rb MAXIMUM_SUPPORTED_EXTENSION
}

SIZE_OF_80387_REGISTERS      = 80
IDD_DLG1              = 1
MAXSIZE                  = 512
ButtonID               = 3
section '.data' data readable writeable
hInstance      dd ?
CommandLine     dd ?
ofn             OPENFILENAME
FilterString    db 'EXE-files (*.exe), DLL-files (*.dll)',0,'*.exe;*.dll',0
             db 'All Files (*.*)',0,'*.*',0,0
buffer          rb MAXSIZE
hFileRead dd ?
hMapFile        dd ?
pMemory         dd ?
seh             SEH
section '.code' code readable writeable executable
start:
   invoke  GetModuleHandle,0
   mov     [hInstance],eax
     invoke  GetCommandLine
      mov     [CommandLine],eax
   invoke  DialogBoxParam,[hInstance],IDD_DLG1,HWND_DESKTOP,DlgProc,0
  invoke  ExitProcess,eax
     
proc DlgProc hWnd,uMsg,wParam,lParam
    cmp     [uMsg],WM_INITDIALOG
        jz      .initdialog
 cmp     [uMsg],WM_CLOSE
     jz      .wmclose
    cmp     [uMsg],WM_COMMAND
   jz      .wmcommand
  mov     eax,FALSE
   ret
.initdialog:
     mov     [ofn.lStructSize],sizeof.OPENFILENAME
       push    [hWnd]
      pop     [ofn.hwndOwner]
     push    [hInstance]
 pop     [ofn.hInstance]
     mov     [ofn.lpstrFilter],FilterString
      mov     [ofn.lpstrFile],buffer
      mov     [ofn.nMaxFile],MAXSIZE
      jmp     _finish
.wmclose:
        cmp     [hMapFile],0
        je      @f
        call    CloseMapFile
@@:
   invoke  EndDialog,[hWnd],0
  jmp     _finish
.wmcommand:
  mov     eax,[wParam]
        mov     edx,eax
     shr     edx,16
      cmp     dx,BN_CLICKED
       jne     _finish
     cmp     ax,ButtonID
 jne     _finish
     mov     [ofn.Flags],OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
     invoke  GetOpenFileName,ofn
 cmp     eax,TRUE
    jne     _finish
     invoke  CreateFile,buffer,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
      test    eax,eax
     je      _erroropen
  mov     [hFileRead],eax
     invoke  CreateFileMapping,[hFileRead],0,PAGE_READONLY,0,0,0
 test    eax,eax
     je      _errormap
   mov     [hMapFile],eax
      
    ;=======================================
    ;=======================================
    call    CheckFile
FinalExit:
        test    ecx,ecx
        jne     @next
        push    [seh.PrevLink]
        pop     dword[fs:0]
        invoke  UnmapViewOfFile,[pMemory]
        jmp     @f
ValidText       db 'It''s a valid PE file!',0
AppName         db 'PE View',0
@@:
        invoke  MessageBox,HWND_DESKTOP,ValidText,AppName,MB_ICONINFORMATION
 jmp     _finish
@next:
        push    [seh.PrevLink]
        pop     dword[fs:0]
        invoke  UnmapViewOfFile,[pMemory]
        jmp     @f
InvalidText     db 'It''s not a valid PE file!',0
@@:
        invoke  MessageBox,HWND_DESKTOP,InvalidText,AppName,MB_ICONERROR
        jmp     _finish
        ;=======================================
        ;=======================================
_finish:
    mov     eax,TRUE
    ret
errop           db 'Can not open file for reading',0
errmp           db 'Can not map file',0

_erroropen:
        invoke  MessageBox,HWND_DESKTOP,errop,AppName,MB_ICONERROR
        jmp     _finish
_errormap:
        invoke  MessageBox,HWND_DESKTOP,errmp,AppName,MB_ICONERROR
        jmp     _finish
endp

proc CloseMapFile
        invoke  CloseHandle,[hMapFile]
        mov     [hMapFile],0
        invoke  CloseHandle,[hFileRead]
        ret
endp

proc CheckFile
        invoke  MapViewOfFile,[hMapFile],FILE_MAP_READ,0,0,0
        test    eax,eax
        je      _mappingerror
        mov     [pMemory],eax
        push    dword[fs:0]
        pop     [seh.PrevLink]
        mov     [seh.CurrentHandler],SEHHandler
        mov     [seh.SafeOffset],FinalExit
        mov     eax,seh
        mov     [fs:0],eax
        mov     [seh.PrevEsp],esp
        mov     [seh.PrevEbp],ebp
        mov     edi,[pMemory]
        cmp     word[edi],'MZ'
        jne     .notmz
        add     edi,dword[edi+3Ch]
        cmp     dword[edi],00004550h
        je      _valid
        xor     ecx,ecx
        inc     ecx
        ret
.notmz:
        jmp     @f
NotMZ           db 'MZ-signature is not found!',0
@@:
        invoke  MessageBox,HWND_DESKTOP,NotMZ,AppName,MB_ICONERROR        
        xor     ecx,ecx
        inc     ecx
        ret
_mappingerror:
        jmp     @f
MappingError    db 'Can not map file into memory!',0
@@:
        invoke  MessageBox,HWND_DESKTOP,MappingError,AppName,MB_ICONERROR
        xor     ecx,ecx
        inc     ecx
        ret
_valid:
        xor     ecx,ecx
        ret
endp

proc SEHHandler pExcept,pFrame,pContext,pDispatch
        push    edx
        mov     edx,[pFrame]
        assume  edx:SEH
        mov     eax,[pContext]
        assume  eax:CONTEXT
        push    [edx.SafeOffset]
        pop     [eax.Eip]
        push    [edx.PrevESp]
        pop     [eax.Esp]
        push    [edx.PrevEbp]
        pop     [eax.Ebp]
        xor     ecx,ecx
        inc     ecx
        pop     edx
        ret        
endp

section '.idata' import data readable writeable
  library user32,'user32.dll',\
            kernel32,'kernel32.dll',\
                comdlg32,'comdlg32.dll'
   include '%fasminc%\api\user32.inc'
      include '%fasminc%\api\kernel32.inc'
    include '%fasminc%\api\comdlg32.inc'
section '.rsrc' resource from 'PEView.res' data readable
    


And this is what does FASM write:


FASM "C:\PEView.asm" "C:\PEView.exe"
flat assembler version 1.67.23 (432731 kilobytes memory)
C:\PEView.asm [220]:
assume edx:SEH
C:\FASM\INCLUDE\macro\masm.inc [44] assume [19]:
reg struct
error: reserved word used as symbol.


P.S. I've already tried to define structures by two ways:

1.

struc SomeStruc
{
......
}

2.

struct SomeStruct
....
ends

But FASM doesn't compile it:(

_________________
FASM Rulezzzzzz!
Post 23 Oct 2007, 16:44
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 23 Oct 2007, 17:04
This compiles for me but I can't test it because I don't have the res file and I have not defined the MAXIMUM_SUPPORTED_EXTENSION constant.

Code:
format PE GUI 4.0
entry start 
include '%fasminc%\win32a.inc' 
include '%fasminc%\macro\masm.inc' 
struct  SEH
  PrevLink        dd ?
  CurrentHandler  dd ?
  SafeOffset      dd ?
  PrevEsp         dd ?
  PrevEbp         dd ?
ends

struct FLOATING_SAVE_AREA
  ControlWord        dd ?
  StatusWord         dd ?
  TagWord            dd ?
  ErrorOffset        dd ?
  ErrorSelector      dd ?
  DataOffset         dd ?
  DataSelector       dd ?
  RegisterArea       rb SIZE_OF_80387_REGISTERS
  Cr0NpxStatedd      dd ?
ends

struct CONTEXT
  ContextFlags         dd ?
  Dr0                  dd ?
  Dr1                  dd ?
  Dr2                  dd ?
  Dr3                  dd ?
  Dr6                  dd ?
  Dr7                  dd ?
  FloatSave            FLOATING_SAVE_AREA
  SegGs                dd ?
  SegFs                dd ?
  SegEs                dd ?
  SegDs                dd ?
  Edi                  dd ?
  Esi                  dd ?
  Ebx                  dd ?
  Edx                  dd ?
  Ecx                  dd ?
  Eax                  dd ?
  Ebp                  dd ?
  Eip                  dd ?
  SegCs                dd ?
  EFlags               dd ?
  Esp                  dd ?
  SegSs                dd ?
  MAXIMUM_SUPPORTED_EXTENSION = 1 ; Because I have not this constant defined anywhere. You obviously have to solve this in another way
  ExtendedRegisters    rb MAXIMUM_SUPPORTED_EXTENSION
ends

SIZE_OF_80387_REGISTERS      = 80 
IDD_DLG1                     = 1 
MAXSIZE                      = 512 
ButtonID                     = 3 
section '.data' data readable writeable 
hInstance       dd ? 
CommandLine     dd ? 
ofn             OPENFILENAME 
FilterString    db 'EXE-files (*.exe), DLL-files (*.dll)',0,'*.exe;*.dll',0 
                db 'All Files (*.*)',0,'*.*',0,0 
buffer          rb MAXSIZE 
hFileRead       dd ? 
hMapFile        dd ? 
pMemory         dd ? 
seh             SEH 
section '.code' code readable writeable executable 
start: 
        invoke  GetModuleHandle,0 
        mov     [hInstance],eax 
        invoke  GetCommandLine 
        mov     [CommandLine],eax 
        invoke  DialogBoxParam,[hInstance],IDD_DLG1,HWND_DESKTOP,DlgProc,0 
        invoke  ExitProcess,eax 
         
proc DlgProc hWnd,uMsg,wParam,lParam 
        cmp     [uMsg],WM_INITDIALOG 
        jz      .initdialog 
        cmp     [uMsg],WM_CLOSE 
        jz      .wmclose 
        cmp     [uMsg],WM_COMMAND 
        jz      .wmcommand 
        mov     eax,FALSE 
        ret 
.initdialog: 
        mov     [ofn.lStructSize],sizeof.OPENFILENAME 
        push    [hWnd] 
        pop     [ofn.hwndOwner] 
        push    [hInstance] 
        pop     [ofn.hInstance] 
        mov     [ofn.lpstrFilter],FilterString 
        mov     [ofn.lpstrFile],buffer 
        mov     [ofn.nMaxFile],MAXSIZE 
        jmp     _finish 
.wmclose: 
        cmp     [hMapFile],0 
        je      @f 
        call    CloseMapFile 
@@: 
        invoke  EndDialog,[hWnd],0 
        jmp     _finish 
.wmcommand: 
        mov     eax,[wParam] 
        mov     edx,eax 
        shr     edx,16 
        cmp     dx,BN_CLICKED 
        jne     _finish 
        cmp     ax,ButtonID 
        jne     _finish 
        mov     [ofn.Flags],OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY 
        invoke  GetOpenFileName,ofn 
        cmp     eax,TRUE 
        jne     _finish 
        invoke  CreateFile,buffer,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 
        test    eax,eax 
        je      _erroropen 
        mov     [hFileRead],eax 
        invoke  CreateFileMapping,[hFileRead],0,PAGE_READONLY,0,0,0 
        test    eax,eax 
        je      _errormap 
        mov     [hMapFile],eax 
         
        ;======================================= 
        ;======================================= 
        call    CheckFile 
FinalExit: 
        test    ecx,ecx 
        jne     @next 
        push    [seh.PrevLink] 
        pop     dword[fs:0] 
        invoke  UnmapViewOfFile,[pMemory] 
        jmp     @f 
ValidText       db 'It''s a valid PE file!',0 
AppName         db 'PE View',0 
@@: 
        invoke  MessageBox,HWND_DESKTOP,ValidText,AppName,MB_ICONINFORMATION 
        jmp     _finish 
@next: 
        push    [seh.PrevLink] 
        pop     dword[fs:0] 
        invoke  UnmapViewOfFile,[pMemory] 
        jmp     @f 
InvalidText     db 'It''s not a valid PE file!',0 
@@: 
        invoke  MessageBox,HWND_DESKTOP,InvalidText,AppName,MB_ICONERROR 
        jmp     _finish 
        ;======================================= 
        ;======================================= 
_finish: 
        mov     eax,TRUE 
        ret 
errop           db 'Can not open file for reading',0 
errmp           db 'Can not map file',0 

_erroropen: 
        invoke  MessageBox,HWND_DESKTOP,errop,AppName,MB_ICONERROR 
        jmp     _finish 
_errormap: 
        invoke  MessageBox,HWND_DESKTOP,errmp,AppName,MB_ICONERROR 
        jmp     _finish 
endp 

proc CloseMapFile 
        invoke  CloseHandle,[hMapFile] 
        mov     [hMapFile],0 
        invoke  CloseHandle,[hFileRead] 
        ret 
endp 

proc CheckFile 
        invoke  MapViewOfFile,[hMapFile],FILE_MAP_READ,0,0,0 
        test    eax,eax 
        je      _mappingerror 
        mov     [pMemory],eax 
        push    dword[fs:0] 
        pop     [seh.PrevLink] 
        mov     [seh.CurrentHandler],SEHHandler 
        mov     [seh.SafeOffset],FinalExit 
        mov     eax,seh 
        mov     [fs:0],eax 
        mov     [seh.PrevEsp],esp 
        mov     [seh.PrevEbp],ebp 
        mov     edi,[pMemory] 
        cmp     word[edi],'MZ' 
        jne     .notmz 
        add     edi,dword[edi+3Ch] 
        cmp     dword[edi],00004550h 
        je      _valid 
        xor     ecx,ecx 
        inc     ecx 
        ret 
.notmz: 
        jmp     @f 
NotMZ           db 'MZ-signature is not found!',0 
@@: 
        invoke  MessageBox,HWND_DESKTOP,NotMZ,AppName,MB_ICONERROR         
        xor     ecx,ecx 
        inc     ecx 
        ret 
_mappingerror: 
        jmp     @f 
MappingError    db 'Can not map file into memory!',0 
@@: 
        invoke  MessageBox,HWND_DESKTOP,MappingError,AppName,MB_ICONERROR 
        xor     ecx,ecx 
        inc     ecx 
        ret 
_valid: 
        xor     ecx,ecx 
        ret 
endp 

proc SEHHandler pExcept,pFrame,pContext,pDispatch 
        push    edx 
        mov     edx,[pFrame] 
        assume  edx:SEH 
        mov     eax,[pContext] 
        assume  eax:CONTEXT 
        push    [edx.SafeOffset] 
        pop     [eax.Eip] 
        push    [edx.PrevEsp]
        pop     [eax.Esp] 
        push    [edx.PrevEbp] 
        pop     [eax.Ebp] 
        xor     ecx,ecx 
        inc     ecx 
        pop     edx 
        ret         
endp 

section '.idata' import data readable writeable 
        library user32,'user32.dll',\ 
                kernel32,'kernel32.dll',\ 
                comdlg32,'comdlg32.dll' 
        include '%fasminc%\api\user32.inc' 
        include '%fasminc%\api\kernel32.inc' 
        include '%fasminc%\api\comdlg32.inc'    

(Note that I stripped the resource section only because I have not got the res file, you should still include it).
Post 23 Oct 2007, 17:04
View user's profile Send private message Reply with quote
Necromancer13



Joined: 18 Oct 2007
Posts: 32
Location: Ukraine
Necromancer13 23 Oct 2007, 17:18
Oh... sorry... here is a rc-file:

Code:
#define IDD_DLG1 1
#define IDC_GRP1 2
#define IDC_BTN1 3
IDD_DLG1 DIALOGEX 150,88,192,118
CAPTION "PE View"
FONT 10,"Comic Sans MS",400,0,204
STYLE 0x10CA0000
BEGIN
  CONTROL "PE VIEW",IDC_GRP1,"Button",0x50000007,0,0,192,119
  CONTROL "Open File",IDC_BTN1,"Button",0x50012F00,10,41,168,27
END
    


I'd like not to use rc-file, but define it all in the source like
Code:
section 'rsrc' resource data readable
directory MENU,menus
........
    

but I don't know how to do it...
Post 23 Oct 2007, 17:18
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 23 Oct 2007, 17:51
Read http://flatassembler.net/docs.php?article=win32 and download http://flatassembler.net/examples/quetannon.zip to look an example using source defined dialog.

Besides this now works? Perhaps struct/ends failed to you before because you haven't got defined MAXIMUM_SUPPORTED_EXTENSION neither?

Note that assume macro only works with structures defined with the struct macro, using the built-in struc declaration does not work since it actually is a somewhat diferent thing.
Post 23 Oct 2007, 17:51
View user's profile Send private message Reply with quote
Necromancer13



Joined: 18 Oct 2007
Posts: 32
Location: Ukraine
Necromancer13 23 Oct 2007, 18:00
>Besides this now works? Perhaps struct/ends failed to you before because >you haven't got defined MAXIMUM_SUPPORTED_EXTENSION neither?
Yes, may be...

yes... it works, but there is something strange with it...
it checks all files well, but when i try to check EED1CXX.DLL it doesn't work!

I've put this file here: http://prikolitvc.ucoz.ru/EED1CXX.DLL

It's so strange...
Post 23 Oct 2007, 18:00
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Necromancer13



Joined: 18 Oct 2007
Posts: 32
Location: Ukraine
Necromancer13 23 Oct 2007, 18:05
I have not idea why!
I tried to debug this file in OllyDebugger...

And when OpenFIleDialog is created, and when I put cursor on this file in OpenFileDialog (just put cursor near it, don't select it!), OpenFileDialog closes itself and a debugger writes
Access violation when reading ....
SEH doen's work!
Post 23 Oct 2007, 18:05
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Necromancer13



Joined: 18 Oct 2007
Posts: 32
Location: Ukraine
Necromancer13 23 Oct 2007, 18:45
I didn't even think, that there would be so many problems with this program...
Post 23 Oct 2007, 18:45
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Necromancer13



Joined: 18 Oct 2007
Posts: 32
Location: Ukraine
Necromancer13 23 Oct 2007, 19:51
May be There some errors with SEH here...
Post 23 Oct 2007, 19:51
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.