ARM执行系统调用的文件路径或文件描述符 [英] File path or file descriptor for ARM execute system call

查看:72
本文介绍了ARM执行系统调用的文件路径或文件描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行时执行ARM执行"系统调用时,我想检索可执行文件的名称.

I would like to retrieve the name of the executable file when an ARM "execute" system call is performed at runtime.

了解ARM程序集中如何翻译执行"系统调用可能会有所帮助.我会知道文件名存储在哪里的寄存器,并在运行时检索它.

It may help to know how an "execute" system call is translated in ARM assembly. I would know the register where the file name is stored and retrieve it at runtime.

谢谢

推荐答案

此示例说明了ARMv7中execu的简单用法.

This example illustrates a simple use of execu in ARMv7.

假设您有一个简单的文件,其中包含一些要排序的文本.

Assumes you have a simple file contain some text to sort.

手册页指示指向可执行文件的指针的位置.在我的示例中,"/bin/sh"是可执行文件.

The man page indicates that placement of the pointer to the executable. In my example "/bin/sh" is the executable.

因此,您正在R0寻找数组结构指针.

So you are looking for an array structure pointer at R0.

NAME
       execve - execute program

SYNOPSIS
       #include <unistd.h>

       int execve(const char *filename, char *const argv[],
                  char *const envp[]);

DESCRIPTION
       execve() executes the program pointed to by filename.  filename must be either a binary executable, or a script starting with a line of the form:

           #! interpreter [optional-arg]

       For details of the latter case, see "Interpreter scripts" below.

       argv  is  an array of argument strings passed to the new program.  By convention, the first of these strings should contain the filename associated with the file being executed.
       envp is an array of strings, conventionally of the form key=value, which are passed as environment to the new program.  Both argv and envp must be terminated by a null  pointer.
       The argument vector and environment can be accessed by the called program's main function, when it is defined as:

           int main(int argc, char *argv[], char *envp[])

       execve() does not return on success, and the text, data, bss, and stack of the calling process are overwritten by that of the program loaded.

示例代码:

.data
        _filename:      .string "/bin/sh"
        arg0:           .string "/bin/sh"
        arg1:           .string "-c"
        arg2:           .string "sort -n myfile.txt"
        args:
                .word arg0
                .word arg1
                .word arg2
.text
        .global  main
main:
        bl _work

_work:
        push {lr}
        mov r7, #11             // execve syscall
        ldr r0,=_filename
        ldr r1,=args
        svc #0
        pop {pc}

简单文本文件:

  $ cat myfile.txt
        9
        1
        5
        233
        5
        6
        723
        91
        0
        3
        2
        4576
        557
        6
        353
        3553

输出示例:

 $ ./simple_exec
0
1
2
3
5
5
6
6
9
91
233
353
557
723
3553
4576

这篇关于ARM执行系统调用的文件路径或文件描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆