Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wireshark lua debug.getinfo为零_Lua_Wireshark_Wireshark Dissector - Fatal编程技术网

wireshark lua debug.getinfo为零

wireshark lua debug.getinfo为零,lua,wireshark,wireshark-dissector,Lua,Wireshark,Wireshark Dissector,我现在正在为卢亚的Wireshark写一些剖析器。Lua代码已经变得相当大了。因此,我将其拆分为多个文件(模块)。我让它工作了。顺便说一句,我的目标是用户只需要将文件复制到plugins目录中,这样每次启动Wireshark时都会自动加载解析器 现在,要从“主文件”访问其他文件,我需要执行以下操作: package.prepend\u路径(“.\plugins\3.3\modulesDir”) 本地mymodule=需要“模块” 这很好,但也有一些缺点。最重要的是,如果用户使用不同版本的Wire

我现在正在为卢亚的Wireshark写一些剖析器。Lua代码已经变得相当大了。因此,我将其拆分为多个文件(模块)。我让它工作了。顺便说一句,我的目标是用户只需要将文件复制到plugins目录中,这样每次启动Wireshark时都会自动加载解析器

现在,要从“主文件”访问其他文件,我需要执行以下操作:

package.prepend\u路径(“.\plugins\3.3\modulesDir”)
本地mymodule=需要“模块”

这很好,但也有一些缺点。最重要的是,如果用户使用不同版本的Wireshark,我需要更改Lua代码中的路径。如果是不同的目录(Linuy,Mac OS),则相同

为了解决这个问题,我对如何获取当前Lua文件的路径进行了一些研究,并得出以下结论:

localmoduledir=debug.getinfo(2,“S”)。来源:sub(2)
moduleDir=moduleDir:match((.[/\\])”

这是一个独立的工作平台,所以它看起来是我想要的完美解决方案。如果我使用Wireshark>Tools>Lua>Evaluate执行此操作,它的工作效果会非常好。
但是:如果我在Lua文件(这是我的解析器)中执行此操作,则会出现错误“尝试索引nil值”。我尝试了这一行的各种不同版本,但调试表似乎总是为零。我使用的是Wireshark 3.3版


有人知道如何让它运行吗?或者使用不同的方法来获取Lua文件所在的目录?提前感谢。

如果您正在查找“全局配置目录”,则可以使用
Dir.global\u config\u path()
。在Windows上,我的lua文件位于“Personal lua Plugins”目录中,当您查看Wireshark的“Help->About Wireshark->Folders”对话框时,它只是
%APPDATA%\Wireshark\Plugins
。因此,您可以将文件夹从
path\to\plugins\3.3\modulesDir
移动到
path\to\plugins\modulesDir

我相信你只需要:

package.prepend_path("modulesDir")
这将使您的Lua解析器和模块不仅可以与Wireshark 3.3开发版本一起工作,还可以与未来的版本一起工作。如果您的解剖器由于某种原因无法使用Wireshark的旧版本,您可以随时执行以下操作:

if get_version() < "3.3" then
    return
end
如果get_version()<“3.3”,则
返回
结束

最后,看看Hadriel Kaplan是如何为他的protobuf.lua解析器解决这个问题的,他的所需模块位于“modules”目录中。基本上就像我上面描述的那样。请参阅:

我看到了一些使用arg[0]的建议,但这不起作用。我想是因为脚本是自动调用的,因为它在Wireshark的插件目录中。谢谢你的回答。不幸的是,这没有多大帮助,因为
Dir.global\u config\u path()
只提供Wireshark程序目录。我已经看过Wiresharks LuaAPI文档了。问题是我有一个学生使用实验室PC的情况。因此,根据学生登录的不同,用户插件目录也不同。我希望只需要将它们复制到所有用户的一个目录中。这就是我遇到我的原始帖子中描述的问题的地方。但是谢谢你的回答。嗯,在这种情况下,也许你可以使用
WIRESHARK\u CONFIG\u DIR
和/或
WIRESHARK\u DATA\u DIR
环境变量为所有学生设置一个公共配置目录?(有关这些环境变量的更多信息,请参见Wireshark手册页:)。或者,学生可能会被要求在他们自己的插件目录中添加一个符号链接,指向一个常见的插件位置?我想我现在有点困惑,因为上面你说,“我的目标是,用户只需要将文件复制到插件目录中,这样每次启动Wireshark时,解剖器都会自动加载。”,所以我提出的第一个解决方案不符合这个目标吗?