title: Kernel Development : Hooking Execve And Printing char *const argv[]
body: <p>I am trying to HookExecve and print arguments. I can print the filename just fine. How can I print the arguments of <strong>char *const argv[]</strong> in Kernel mode ? I need to e able to get the amount of them and also be able to print them.</p>
  
  <p>So if I run ls -lah . I should see in argv ["ls", "-lah"] ; I can do this in user space, but All attempts to copy the information from user space to Kernel space seems to lead to crash. </p>
  
  <pre><code>    char CharBuffer [255] = {'\0'};
      char Argz       [255] = {'\0'};
  
      asmlinkage int (*origional_execve)(const char *filename, char *const argv[], char *const envp[]);
      asmlinkage int HookExecve(const char *filename, char *const argv[], char *const envp[]) {
         unsigned int len     = sizeof(CharBuffer) / sizeof(CharBuffer[0]);
         unsigned int Argzlen = sizeof(Argz)       / sizeof(Argz[0]);
  
          copy_from_user(&amp;CharBuffer , filename , len );
          //copy_from_user(Argz , argv[0] , sizeof(argv[0]) );     
          //strncpy_from_user(Argz, argv[0], len ); // Might break stuff
          printk( KERN_INFO "Executable Name %s \n", CharBuffer  );
          memset(CharBuffer, 0 , len);
  
        return (*origional_execve)(filename, argv, envp);
      }
  </code></pre>