From 8a44c9432d839e9edcb7fd2af07944f7b6a6465c Mon Sep 17 00:00:00 2001 From: batrick Date: Wed, 27 Aug 2008 22:23:50 +0000 Subject: [PATCH] Updated NSE's bit library to no longer be a shared library. See this thread: http://seclists.org/nmap-dev/2008/q3/0404.html --- Makefile.in | 24 ++++++++-------- mswin32/nmap.vcproj | 7 +++++ nse_bit.cc | 70 +++++++++++++++++++++++++++++++++++++++++++++ nse_bit.h | 14 +++++++++ nse_init.cc | 8 ++++-- 5 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 nse_bit.cc create mode 100644 nse_bit.h diff --git a/Makefile.in b/Makefile.in index 9efbd88be..bb06a6af0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -59,9 +59,9 @@ INSTALLZENMAP=@INSTALLZENMAP@ UNINSTALLZENMAP=@UNINSTALLZENMAP@ ifneq (@LIBLUA_LIBS@,) -NSE_SRC=nse_main.cc nse_nsock.cc nse_init.cc nse_fs.cc nse_nmaplib.cc nse_debug.cc nse_pcrelib.cc nse_binlib.cc nse_hash.cc -NSE_HDRS=nse_main.h nse_nsock.h nse_init.h nse_fs.h nse_nmaplib.h nse_debug.h nse_macros.h nse_pcrelib.h nse_binlib.h nse_hash.h -NSE_OBJS=nse_main.o nse_nsock.o nse_init.o nse_fs.o nse_nmaplib.o nse_debug.o nse_pcrelib.o nse_binlib.o nse_hash.o +NSE_SRC=nse_main.cc nse_nsock.cc nse_init.cc nse_fs.cc nse_nmaplib.cc nse_debug.cc nse_pcrelib.cc nse_binlib.cc nse_hash.cc nse_bit.cc +NSE_HDRS=nse_main.h nse_nsock.h nse_init.h nse_fs.h nse_nmaplib.h nse_debug.h nse_macros.h nse_pcrelib.h nse_binlib.h nse_hash.h nse_bit.h +NSE_OBJS=nse_main.o nse_nsock.o nse_init.o nse_fs.o nse_nmaplib.o nse_debug.o nse_pcrelib.o nse_binlib.o nse_hash.o nse_bit.o NSESTDLIB=nsestdlib endif @@ -83,8 +83,8 @@ $(TARGET): @LUA_DEPENDS@ @PCAP_DEPENDS@ @PCRE_DEPENDS@ @DNET_DEPENDS@ $(NBASEDIR rm -f $@ $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) -nsestdlib: nselib-bin/Makefile - @echo Compiling nse-standard-library; cd nselib-bin && $(MAKE) +#nsestdlib: nselib-bin/Makefile +# @echo Compiling nse-standard-library; cd nselib-bin && $(MAKE) pcre_build: $(LIBPCREDIR)/Makefile @@ -143,8 +143,8 @@ nsock_clean: -cd $(NSOCKDIR)/src && $(MAKE) clean lua_clean: -cd $(LIBLUADIR) && $(MAKE) clean -nselib_clean: - -cd nselib-bin && $(MAKE) clean +#nselib_clean: +# -cd nselib-bin && $(MAKE) clean zenmap_clean: -cd $(ZENMAPDIR) && $(PYTHON) setup.py clean --all pcap_dist_clean: @@ -155,8 +155,8 @@ dnet_dist_clean: -cd $(LIBDNETDIR) && $(MAKE) distclean lua_dist_clean: -cd $(LIBLUADIR) && $(MAKE) clean -nselib_dist_clean: - -cd nselib-bin && $(MAKE) distclean +#nselib_dist_clean: +#-cd nselib-bin && $(MAKE) distclean nbase_dist_clean: -cd $(NBASEDIR) && $(MAKE) distclean nsock_dist_clean: @@ -220,15 +220,15 @@ install-zenmap: $(ZENMAPDIR)/setup.py NSE_FILES = scripts/script.db scripts/*.nse NSE_LIB_LUA_FILES = nselib/*.lua -NSE_LIB_SO_FILES = nselib-bin/*.so +#NSE_LIB_SO_FILES = nselib-bin/*.so install-nse: $(TARGET) $(INSTALL) -d $(DESTDIR)$(nmapdatadir)/scripts cp -f $(NSE_FILES) $(DESTDIR)$(nmapdatadir)/scripts $(INSTALL) -d $(DESTDIR)$(nmapdatadir)/nselib cp -f $(NSE_LIB_LUA_FILES) $(DESTDIR)$(nmapdatadir)/nselib - $(INSTALL) -d $(DESTDIR)$(nmaplibexecdir)/nselib-bin - cp -f $(NSE_LIB_SO_FILES) $(DESTDIR)$(nmaplibexecdir)/nselib-bin +#$(INSTALL) -d $(DESTDIR)$(nmaplibexecdir)/nselib-bin +#cp -f $(NSE_LIB_SO_FILES) $(DESTDIR)$(nmaplibexecdir)/nselib-bin install: install-nmap $(INSTALLNSE) $(INSTALLZENMAP) @echo "NMAP SUCCESSFULLY INSTALLED" diff --git a/mswin32/nmap.vcproj b/mswin32/nmap.vcproj index 8b1eb95b8..944e9be1a 100644 --- a/mswin32/nmap.vcproj +++ b/mswin32/nmap.vcproj @@ -294,6 +294,9 @@ RelativePath="..\nse_hash.cc" > + @@ -487,6 +490,10 @@ RelativePath="..\nse_hash.h" > + + diff --git a/nse_bit.cc b/nse_bit.cc new file mode 100644 index 000000000..42331c2a4 --- /dev/null +++ b/nse_bit.cc @@ -0,0 +1,70 @@ +/* Bitwise operations library + * by Reuben Thomas (rrt@sc3d.org) + * bitlib is a C library for Lua 5.x that provides bitwise operations + * It is copyright Reuben Thomas 2000-2006, and is released under the + * MIT license, like Lua (see http://www.lua.org/copyright.html for the + * full license; it's basically the same as the BSD license). There is no + * warranty. + * the most recent copy can be found at http://rrt.sc3d.org/Software/Lua/ + **/ + +#include "nse_bit.h" + +typedef long long Integer; +typedef unsigned long long UInteger; + +#define luaL_checkbit(L, n) ((Integer)luaL_checknumber(L, n)) +#define luaL_checkubit(L, n) ((UInteger)luaL_checkbit(L, n)) + +#define TDYADIC(name, op, checkbit1, checkbit2) \ + static int bit_ ## name(lua_State* L) { \ + lua_pushnumber(L, \ + (lua_Number)(checkbit1(L, 1) op checkbit2(L, 2))); \ + return 1; \ + } + +#define DYADIC(name, op) \ + TDYADIC(name, op, luaL_checkbit, luaL_checkbit) + +#define MONADIC(name, op) \ + static int bit_ ## name(lua_State* L) { \ + lua_pushnumber(L, (lua_Number)(op luaL_checkbit(L, 1))); \ + return 1; \ + } + +#define VARIADIC(name, op) \ + static int bit_ ## name(lua_State *L) { \ + int n = lua_gettop(L), i; \ + Integer w = luaL_checkbit(L, 1); \ + for (i = 2; i <= n; i++) \ + w op luaL_checkbit(L, i); \ + lua_pushnumber(L, (lua_Number)w); \ + return 1; \ + } + +MONADIC(bnot, ~) +VARIADIC(band, &=) +VARIADIC(bor, |=) +VARIADIC(bxor, ^=) +TDYADIC(lshift, <<, luaL_checkbit, luaL_checkubit) +TDYADIC(rshift, >>, luaL_checkubit, luaL_checkubit) +TDYADIC(arshift, >>, luaL_checkbit, luaL_checkubit) +DYADIC(mod, %) + +static const struct luaL_reg bitlib[] = { + {"bnot", bit_bnot}, + {"band", bit_band}, + {"bor", bit_bor}, + {"bxor", bit_bxor}, + {"lshift", bit_lshift}, + {"rshift", bit_rshift}, + {"arshift", bit_arshift}, + {"mod", bit_mod}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_bit(lua_State *L) { + luaL_openlib(L, BITLIBNAME, bitlib, 0); + return 1; +} + diff --git a/nse_bit.h b/nse_bit.h new file mode 100644 index 000000000..3a0c240b6 --- /dev/null +++ b/nse_bit.h @@ -0,0 +1,14 @@ +#ifndef BITLIB +#define BITLIB + +#define BITLIBNAME "bit" + +extern "C" { +#include "lauxlib.h" +#include "lua.h" +} + +LUALIB_API int luaopen_bit(lua_State *L); + +#endif + diff --git a/nse_init.cc b/nse_init.cc index 39b9aaaac..f9625d830 100644 --- a/nse_init.cc +++ b/nse_init.cc @@ -6,6 +6,7 @@ // 3rd Party libs #include "nse_pcrelib.h" +#include "nse_bit.h" #include "nse_binlib.h" #include "nse_hash.h" @@ -218,9 +219,10 @@ int init_lua (lua_State *L) int i; static const luaL_Reg libs[] = { {NSE_PCRELIBNAME, luaopen_pcrelib}, // pcre library - {"nmap", luaopen_nmap} // nmap bindings - ,{NSE_BINLIBNAME, luaopen_binlib} - ,{NSE_HASHLIBNAME, luaopen_hashlib} + {"nmap", luaopen_nmap}, // nmap bindings + {NSE_BINLIBNAME, luaopen_binlib}, + {NSE_HASHLIBNAME, luaopen_hashlib}, + {BITLIBNAME, luaopen_bit}, // bit library }; luaL_openlibs(L); // opens all standard libraries