2013-03-07 33 views

回答

1

。如果你想在do_execve_common()中執行二進制加載器之前獲得完整的命令行,可以嘗試以下操作: 函數do_execve_common()參數表中有一個參數* argv,爲什麼還要從argv中得到「struct linux_binprm 「?您可以直接使用* argv和以下代碼。在do_execve_common(),插入一些代碼如下:

argc = count(argv, MAX_ARG_STRINGS); 
i = 0; 
while (i < argc) 
{ 
    const char __user *str; 
    int len; 

    ret = -EFAULT; 
    str = get_user_arg_ptr(argv, i); 
    if (IS_ERR(str)) 
     goto out; 

    len = strnlen_user(str, MAX_ARG_STRLEN); 
    if (!len) 
     goto out; 

    //copy the str to kernel temporary storage 
    //NOTE: tmp[] is a string array, 
    //  the memory should have been allocated already for strings storage, 
    //  each string is ended with \0 
    memcpy(tmp[i], str, len) 
} 

執行這些代碼後,我想的argv字符串將被所有保存在TMP []數組。

。雖然如果你想在二進制加載器執行後得到完整的命令行,我認爲在這個時候參數頁已經正確設置,那麼你可以嘗試以下方法來獲取完整的命令行: 有一個函數proc_pid_cmdline() ./fs/proc/base.c文件中,您可以重新使用proc_pid_cmdline()函數中的大部分代碼以從參數頁面獲取完整的命令行。

+0

工作。大!謝謝。 – gregoiregentil 2013-03-11 06:22:34