Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

how can use chmod() in assembly debian x86 ?

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
G3n3Rall
Posts: 2
Joined: 2014-08-03 06:54

how can use chmod() in assembly debian x86 ?

#1 Post by G3n3Rall »

hello friends, i wanna use chmod() in linux x86 [debian 3.7.2 x86] but i have some problem in function argv

look at this function:

Code: Select all

 int chmod(const char *path, mode_t mode);
and mode_t modes:

Code: Select all

       S_ISUID  (04000)  set-user-ID  (set  process  effective  user   ID   on
                         execve(2))

       S_ISGID  (02000)  set-group-ID  (set  process  effective  group  ID  on
                         execve(2);  mandatory  locking,   as   described   in
                         fcntl(2);  take a new file's group from parent direcق
                         tory, as described in chown(2) and mkdir(2))

       S_ISVTX  (01000)  sticky bit (restricted deletion flag, as described in
                         unlink(2))

       S_IRUSR  (00400)  read by owner

       S_IWUSR  (00200)  write by owner

       S_IXUSR  (00100)  execute/search  by owner ("search" applies for direcق
                         tories, and means that entries within  the  directory
                         can be accessed)

       S_IRGRP  (00040)  read by group

       S_IWGRP  (00020)  write by group

       S_IXGRP  (00010)  execute/search by group

       S_IROTH  (00004)  read by others

       S_IWOTH  (00002)  write by others

       S_IXOTH  (00001)  execute/search by others
i want to add write permission to my file but it not work !
this code first print hello then change file permission and then exit
print and exit are success but not change file permission
i asked in many forums but no one didn't help ,
code:

Code: Select all

section .text
        global  _start
_start:
        mov     eax,15
        mov     ebx,path
        mov     ecx,mod
        int     0x80
        mov     edx,len
        mov     ecx,msg
        mov     ebx,1
        mov     eax,4
        int     0x80
        mov     ebx,0
        mov     eax,1
        int     0x80
section .data
        msg db          "Hello",0xa
        len equ         $ - msg
        path db           "/root/Desktop/xpl/1.txt"
        mod db       "S_IWUSR|S_IWGRP|S_IWOTH"
i know there is some problem in ecx and mode_t value
anyone can tell me how i do it ? thanks

User avatar
saulgoode
Posts: 1445
Joined: 2007-10-22 11:34
Been thanked: 4 times

Re: how can use chmod() in assembly debian x86 ?

#2 Post by saulgoode »

G3n3Rall wrote:

Code: Select all

        mod db       "S_IWUSR|S_IWGRP|S_IWOTH"
Here you are defining mod as a string (i.e., a pointer to a memory location). You want to define mod as a value. I'm not sure of the exact syntax you should use, but something along the lines of:

Code: Select all

mod equ S_IWUSR|S_IWGRP|S_IWOTH
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan

G3n3Rall
Posts: 2
Joined: 2014-08-03 06:54

Re: how can use chmod() in assembly debian x86 ?

#3 Post by G3n3Rall »

thanks for answer
i did solve this with [ 777 permission ]

Code: Select all

root@g3n3rall:~# gdb --quiet --batch -ex 'print /x 00777 | 01'
$1 = 0x1ff
so

Code: Select all

mov ecx,0x1ff
and also this can use:

Code: Select all

mov    ecx,00777Q

Post Reply