mirror of
https://github.com/nmap/nmap.git
synced 2025-12-31 20:09:02 +00:00
Remove the nselib-bin directory. Almost all references to it have been removed
too. The section in scripting.xml about creating C modules is gone. (But maybe it should be replaced with a tutorial on making static modules?) The only places where nselib-bin is still referenced are in mswin32/nsis/Nmap.nsi, where it is still removed on uninstallation; and in mswin32/nmap.vcproj, from where I don't have the resources now to remove it.
This commit is contained in:
@@ -4019,69 +4019,5 @@ The mainloop function will work on each runlevel grouping of threads in order.
|
||||
repeated until no threads exist in either waiting or running.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="nse-implementation-c-modules">
|
||||
<title>Adding C Modules to Nselib</title>
|
||||
<indexterm><primary>Nmap Scripting Engine (NSE)</primary><secondary>C modules</secondary></indexterm>
|
||||
<para>
|
||||
This section gives a short walk-through for adding
|
||||
nselib modules written in C (or C++) to Nmap's build system, since
|
||||
this has shown to be sometimes tedious. Writing C modules is
|
||||
described at length in
|
||||
<web><ulink url="http://www.amazon.com/exec/obidos/ASIN/8590379825/secbks-20"><citetitle>Programming in Lua, Second Edition</citetitle></ulink>.</web>
|
||||
<print><citetitle>Programming in Lua, Second Edition</citetitle>.</print>
|
||||
Basically C modules consist of the
|
||||
functions they provide to Lua, which have to be of type <ulink url="http://www.lua.org/manual/5.1/manual.html#lua_CFunction">lua_CFunction</ulink>. Additionally they have to contain a function
|
||||
which is used to actually open the module. By convention these function names are <literal>luaopen_<replaceable>modulename</replaceable></literal>.
|
||||
A good starting point for writing such modules is provided by
|
||||
<filename>bit.c</filename><indexterm><primary><varname>bit</varname> NSE module</primary></indexterm>
|
||||
inside
|
||||
the <filename>nselib-bin/</filename> subdirectory of Nmap's source tree.
|
||||
<varname>bit</varname> is a C module already provided by the nselib. C modules
|
||||
basically are shared libraries which get loaded at runtime by Lua.
|
||||
</para>
|
||||
<para>
|
||||
The Unix build system uses <literal>libtool</literal> for
|
||||
compilation in a platform independent way. As long as the new module
|
||||
does not depend on foreign libraries, you should only need to add
|
||||
<literal><replaceable>modulename</replaceable>.so</literal> to the
|
||||
<literal>all</literal> and <literal>clean</literal> targets in
|
||||
<filename>Makefile.in</filename>
|
||||
and copy and adapt the lines from <filename>bit.so</filename>.
|
||||
If your module does have dependencies you will most probably have to
|
||||
add checks for those libraries to <filename>configure.ac</filename>
|
||||
and put the dependencies inside the <literal>libtool</literal>
|
||||
commands in <filename>Makefile.in</filename>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Of course, theory and practice are rarely the same. Most of
|
||||
the trouble building nselib actually comes from the
|
||||
complications of building shared libraries and not nselib
|
||||
itself. Linking with static libraries
|
||||
(e.g. <literal>libnbase</literal>) sometimes leads to
|
||||
problems with exporting symbols on some platforms (in our
|
||||
case the x86_64-linux platform).<indexterm><primary>x86_64 architecture</primary></indexterm>
|
||||
To our knowledge no such
|
||||
problems occur when linking against already existing shared
|
||||
libraries.</para>
|
||||
|
||||
<para>
|
||||
The Windows build system requires C module developers to create a
|
||||
MS Visual Studio Project file for their module
|
||||
(<filename><replaceable>modulename</replaceable>.vcproj</filename>) inside the
|
||||
<filename>nselib</filename> subdirectory. On Windows you have to
|
||||
include the <filename>liblua/</filename> subdirectory as
|
||||
an additional include path as well as a library search path. In addition
|
||||
you have to tell the project to link against the
|
||||
<filename>liblua.lib</filename> static library provided with Nmap.
|
||||
Other properties of the project should be the same as for other
|
||||
nselib C modules (e.g. see <filename>nse_bitlib.vcproj</filename>).
|
||||
Afterwards you have to include the newly created project file in
|
||||
Nmap's Visual Studio solution file
|
||||
(<filename>mswin32\nmap.sln</filename>) and make sure that
|
||||
<filename>nse_bitlib.vcproj</filename> depends on your project,
|
||||
because it is there that nselib modules get copied to their final destinations and are included in Nmap.
|
||||
</para>
|
||||
</sect2>
|
||||
</sect1>
|
||||
<indexterm class="endofrange" startref="nse-indexterm"/>
|
||||
|
||||
Reference in New Issue
Block a user