flat assembler
Message board for the users of flat assembler.

Index > Windows > struct stat32

Author
Thread Post new topic Reply to topic
render



Joined: 25 Jun 2010
Posts: 14
render
I have trouble, when I get data from stat32 structure.
Code:
format PE console 4.0
include '%fasminc%\win32a.inc'

section '.text' code  readable executable
                     entry ff
    proc ff
                     
    locals
              123 dd ?
            include '%fasminc%\EQUATES\stat.inc'
    endl
                        lea eax,[stat32]        
                    stdcall [_stat],file_file,eax
                       stdcall [printf],STRst_dev,[stat32.st_dev]
                  stdcall [printf],STRst_ino,dword[stat32.st_ino]
                     stdcall [printf],STRst_mode,dword[stat32.st_mode]
                   stdcall [printf],STRst_nlink,dword[stat32.st_nlink]
                 stdcall [printf],STRst_uid,dword[stat32.st_uid]
                     stdcall [printf],STRst_gid,dword[stat32.st_gid]
                     stdcall [printf],STRst_rdev,[stat32.st_rdev]
                        stdcall [printf],STRst_size,[stat32.st_size]
                        stdcall [printf],STRst_atime,[stat32.st_atime]
                      stdcall [printf],STRst_mtime,[stat32.st_mtime]
                      stdcall [printf],STRst_ctime,[stat32.st_ctime]
                      stdcall [ExitProcess],NULL
                  ret
 endp

section '.data' data readable
file_file        db 'd:\123.txt',0
STRst_dev   db 'st_dev: %d',0xA,0
STRst_ino        db 'st_ino: %d',0xA,0
STRst_mode       db 'st_mode: %d',0xA,0
STRst_nlink     db 'st_nlink: %d',0xA,0
STRst_uid      db 'st_uid: %d',0xA,0
STRst_gid        db 'st_gid: %d',0xA,0
STRst_rdev       db 'st_rdev: %d',0xA,0
STRst_size      db 'st_size: %d',0xA,0
STRst_atime     db 'st_atime: %d',0xA,0
STRst_mtime    db 'st_mtime: %d',0xA,0
STRst_ctime    db 'st_ctime: %d',0xA,0

section '.rdata' import data readable writable
library                                kernel32,                               'KERNEL32.DLL',\
                                 user32,                                 'USER32.DLL',\
                                   shell32,                                'SHELL32.DLL',\
                                  msvcrt,                                 'MSVCRT.DLL'
                                      include                                 '%fasminc%\api\KERNEL32.INC'
                                    include                                 '%fasminc%\api\SHELL32.INC'
                                     include                                 '%fasminc%\api\USER32.INC'                  
                                    include                                 '%fasminc%\api\MSVCRT.INC'          
                            
    

stat.inc:
Code:
        struct stat_struct
          st_dev                  dd ?
                st_ino                  dw ?
                st_mode                 dw ?
                st_nlink                dw ?
                st_uid                  dw ?
                st_gid                  dw ?
                st_rdev                 dd ?
                st_size                 dd ?
                st_atime                dd ?
                st_mtime                dd ?
                st_ctime                dd ?
        ends
        stat32 stat_struct
    


C source code
Code:
#include <windows.h>
#include <windows.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>

int main()
{
struct stat file_info;
stat("d:\123.txt",&file_info);
__asm{int 3}
printf("st_dev: %d\n",file_info.st_dev);        
printf("st_ino: %d\n",file_info.st_ino);
printf("st_mode: %d\n",file_info.st_mode);
printf("st_nlink: %d\n",file_info.st_nlink);
printf("st_uid: %d\n",file_info.st_uid);
printf("st_gid: %d\n",file_info.st_gid);
printf("st_rdev: %d\n",file_info.st_rdev);
printf("st_size: %d\n",file_info.st_size);
printf("st_atime: %d\n",file_info.st_atime);
printf("st_mtime: %d\n",file_info.st_mtime);
printf("st_ctime: %d\n",file_info.st_ctime);

return 0;
}
    


C header sys/stat.h
Code:
struct _stat {
        _dev_t st_dev;
        _ino_t st_ino;
        unsigned short st_mode;
        short st_nlink;
        short st_uid;
        short st_gid;
        _dev_t st_rdev;
        _off_t st_size;
        time_t st_atime;
        time_t st_mtime;
        time_t st_ctime;
        };
    


in C source (upps binary) I get from struct correctly data from struct stat32
What I do wrang ?
Post 11 Jan 2011, 22:55
View user's profile Send private message Reply with quote
SFeLi



Joined: 03 Nov 2004
Posts: 140
SFeLi
Padding. Dword values are often aligned to 4-byte boundaries. Try to insert padding_ dw ? before st_rdev dd ?.
Post 12 Jan 2011, 07:12
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
As SFeli Said above, alignment (st_gid):
Code:
struct _stat32
       st_dev dd ?
       st_ino dw ?
       st_mode dw ?
       st_nlink dw ?
       st_uid dw ?
       st_gid dw ?,?
       st_rdev dd ?
       st_size dd ?
       st_atime dd ?
       st_mtime dd ?
       st_ctime dd ?
ends    


Also, use cinvoke instead of stdcall. Because some of the elements are word size, you'll have to load them into a 32bit register first, then print out there values, Example:
Code:
     cinvoke _stat, file_file, stat32
     cinvoke printf, STRst_dev, [stat32.st_dev]
     movzx   eax, [stat32.st_ino]
     cinvoke printf, STRst_ino, eax
     movzx   eax, [stat32.st_mode]
     cinvoke printf, STRst_mode, eax
     movzx   eax, [stat32.st_nlink]
     cinvoke printf, STRst_nlink, eax
     movzx   eax, [stat32.st_uid]
     cinvoke printf, STRst_uid, eax
     movzx   eax, [stat32.st_gid]
     cinvoke printf, STRst_gid, eax
     cinvoke printf, STRst_rdev, [stat32.st_rdev]
     cinvoke printf, STRst_size, [stat32.st_size]
     cinvoke printf, STRst_atime, [stat32.st_atime]
     cinvoke printf, STRst_mtime, [stat32.st_mtime]
     cinvoke printf, STRst_ctime, [stat32.st_ctime]
    
Post 12 Jan 2011, 14:42
View user's profile Send private message Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 521
Location: ( . Y . )
ass0
Hey madmatt, could you please reupload your examples that you use to put here: ftp://68.225.35.57/

Perhaps to http://ifile.it/, they allow resumable downloads btw Very Happy

Thank You in advance.

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 24 Jan 2011, 02:20
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.