我想得到当前目录,这是我的尝试
asmlinkage ssize_t fake_read(int __fd, void *__buf, size_t __nbytes){
struct path pwd;
get_fs_pwd(current->fs,&pwd);
char x[1000];
dentry_path_raw(pwd.dentry,x,999);
fm_alert("read:%s\n",x);
return real_read(__fd,__buf,__nbytes);
}
但是,我得到的输出是
[ 2170.293439] fsmonko.fake_read: read:ػ\xffffffaf\xffffff80
[ 2170.293466] fsmonko.fake_read: read:ػ\xffffffaf\xffffff80
[ 2170.293483] fsmonko.fake_read: read:\xffffffd8;\xffffff9b\xffffff84
[ 2170.293500] fsmonko.fake_read: read:ػ\xffffffaf\xffffff80
[ 2170.293524] fsmonko.fake_read: read:ػ\xffffffaf\xffffff80
[ 2170.293550] fsmonko.fake_read: read:ػ\xffffffaf\xffffff80
[ 2170.293556] fsmonko.fake_read: read:\xffffffd8;\xffffff9b\xffffff84
它应该打印可读的密码,怎么了?
我的内核版本是
4.13.0-36-generic
Ubuntu 16.04。 最佳答案
dentry_path_raw
将路径放置在缓冲区的末尾。缓冲区(正在打印)的开头仍包含垃圾。路径的实际起点是返回的值dentry_path_raw
。试用
char * path = dentry_path_raw(pwd.dentry,x,999);
fm_alert("read:%s\n", path);
关于c - 如何在内核中获取可读的PWD,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52932897/