简体   繁体   English

如何在汇编Linux x86中使用chmod()?

[英]How work with chmod() in assembly linux x86?

How can i use chmod() to change file permissions in Assembly linux x86 ? 我如何使用chmod()更改Assembly linux x86中的文件权限? i want a sample code in assembly , i see help guide but still it's very hard to understand 我想要汇编中的示例代码,我看到了帮助指南,但仍然很难理解

http://man7.org/linux/man-pages/man2/chmod.2.html http://man7.org/linux/man-pages/man2/chmod.2.html

int chmod(const char *pathname, mode_t mode);

chmod() have 2 argv , first is pathfile name and second is mod ! chmod()有2个argv,第一个是路径文件名,第二个是mod!

path /Users/paul/Desktop/file.txt and mode_t modes are : S_ISUID , S_ISGID , S_ISVTX , S_IRUSR ,S_IWUSR 路径/Users/paul/Desktop/file.txt和mode_t模式为:S_ISUID,S_ISGID,S_ISVTX,S_IRUSR,S_IWUSR

and more can see in url first question: i need set these values in the varible of ecx or i must use values numbers ,which one i must use ? 还有更多可以在url中看到的第一个问题:我需要在ecx的变量中设置这些值,或者我必须使用数值number,我必须使用哪个数值? S_IWGRP or 00020 #write by group S_IWGRP或00020#按组写入

second question: Am i doing it truely ? 第二个问题:我是不是真的做到了? i put these in ecx and execute same this : 我将它们放在ecx中并执行以下操作:

mov eax,15   
mov ebx,mypathfile
mov ecx,S_IWUSR
int 0x80

someone can get me code example ? 有人可以给我代码示例吗?

and the last question is , how can i set 777 permission to file (read write execute for all) ? 最后一个问题是,如何设置文件的777权限(对所有人执行读写操作)?

Thanks. 谢谢。

Here is the full program. 这是完整的程序。 That should answer your questions. 那应该回答你的问题。

main.asm: main.asm中:

        global _start
        section .text

_start:
        mov eax, 15             ; sys_chmod                                     
        mov ebx, path
        mov ecx, 0777o
        int 0x80

        mov eax, 1              ; sys_exit                                      
        mov ebx, 0
        int 0x80

        section .data

path:   db "file.ext", 0

Build with: 构建:

nasm -f elf32 -o main.o main.asm
ld -m elf_i386 -o main main.o

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM