From 01b5a155e1e88d7c5ce41724e048e89768a55a5d Mon Sep 17 00:00:00 2001 From: fyodor Date: Sat, 11 Aug 2007 04:59:14 +0000 Subject: [PATCH] merge soc07 r5063:5065 - added support for nse-C-modules under windows; misc. nse improvements --- mswin32/Makefile | 3 + mswin32/nmap.sln | 17 ++- mswin32/nmap.vcproj | 12 +- nse_bitlib.cc | 75 ---------- nse_bitlib.h | 9 -- nse_init.cc | 9 +- nselib/nse_bitlib.vcproj | 205 ++++++++++++++++++++++++++++ scripts/dns-test-open-recursion.nse | 2 +- 8 files changed, 230 insertions(+), 102 deletions(-) delete mode 100644 nse_bitlib.cc delete mode 100644 nse_bitlib.h create mode 100644 nselib/nse_bitlib.vcproj diff --git a/mswin32/Makefile b/mswin32/Makefile index 9b5257e31..7360d9105 100644 --- a/mswin32/Makefile +++ b/mswin32/Makefile @@ -5,6 +5,7 @@ export NMAP_NUM_VERSION := $(shell grep '^\#[ \t]*define[ \t]\+NMAP_NUM_VERSION' COMMA_VERSION=$(shell echo $(NMAP_NUM_VERSION) | tr '.' ',') LOGLOC=c:nmapbuild.log NSE_FILES = scripts/script.db scripts/*.nse +NSE_LIB_FILES = nselib/*.lua nselib/*.dll winbuild: # VCExpress.exe is devenv.com with the commercial Visual Studio suite instead of VC++ Express @@ -23,6 +24,8 @@ winbuild: cd Release && cp -r ../../CHANGELOG ../../COPYING nmap-mac-prefixes nmap-os-fingerprints nmap-os-db nmap-protocols nmap-rpc nmap-service-probes nmap-services nmap.exe nmap.xsl ../nmap_performance.reg ../../README-WIN32 ../nmap-$(NMAP_VERSION)/ mkdir nmap-$(NMAP_VERSION)/scripts cd Release && cp -f $(NSE_FILES) ../nmap-$(NMAP_VERSION)/scripts/ + mkdir nmap-$(NMAP_VERSION)/nselib + cd Release && cp -f $(NSE_LIB_FILES) ../nmap-$(NMAP_VERSION)/nselib/ zip -r nmap-$(NMAP_VERSION)-win32.zip nmap-$(NMAP_VERSION) cp winpcap/winpcap-nmap-*.exe nmap-$(NMAP_VERSION) cp nsis/AddToPath.nsh nsis/Nmap.nsi nmap-$(NMAP_VERSION) diff --git a/mswin32/nmap.sln b/mswin32/nmap.sln index 650c48d3d..96684aef7 100644 --- a/mswin32/nmap.sln +++ b/mswin32/nmap.sln @@ -2,11 +2,11 @@ Microsoft Visual Studio Solution File, Format Version 9.00 # Visual C++ Express 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nmap", "nmap.vcproj", "{361719F0-AB42-4C93-9DE8-7D2144B96625}" ProjectSection(ProjectDependencies) = postProject - {31FB0767-A71F-4575-8379-002D72B8AF86} = {31FB0767-A71F-4575-8379-002D72B8AF86} - {5DE86C7A-DE72-4265-8807-4CA38F94F22A} = {5DE86C7A-DE72-4265-8807-4CA38F94F22A} - {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C} = {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C} - {F8D6D1E3-D4EA-402C-98AA-168E5309BAF4} = {F8D6D1E3-D4EA-402C-98AA-168E5309BAF4} {B630C8F7-3138-43E8-89ED-78742FA2AC5F} = {B630C8F7-3138-43E8-89ED-78742FA2AC5F} + {F8D6D1E3-D4EA-402C-98AA-168E5309BAF4} = {F8D6D1E3-D4EA-402C-98AA-168E5309BAF4} + {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C} = {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C} + {5DE86C7A-DE72-4265-8807-4CA38F94F22A} = {5DE86C7A-DE72-4265-8807-4CA38F94F22A} + {31FB0767-A71F-4575-8379-002D72B8AF86} = {31FB0767-A71F-4575-8379-002D72B8AF86} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nsock", "..\nsock\nsock.vcproj", "{F8D6D1E3-D4EA-402C-98AA-168E5309BAF4}" @@ -22,6 +22,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dnet", "..\libdnet-stripped EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "liblua", "..\liblua\liblua.vcproj", "{31FB0767-A71F-4575-8379-002D72B8AF86}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nse_bitlib", "..\nselib\nse_bitlib.vcproj", "{FB7F6FD2-A39D-40A1-86DD-9B08370BDEA6}" + ProjectSection(ProjectDependencies) = postProject + {31FB0767-A71F-4575-8379-002D72B8AF86} = {31FB0767-A71F-4575-8379-002D72B8AF86} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -52,6 +57,10 @@ Global {31FB0767-A71F-4575-8379-002D72B8AF86}.Debug|Win32.Build.0 = Debug|Win32 {31FB0767-A71F-4575-8379-002D72B8AF86}.Release|Win32.ActiveCfg = Release|Win32 {31FB0767-A71F-4575-8379-002D72B8AF86}.Release|Win32.Build.0 = Release|Win32 + {FB7F6FD2-A39D-40A1-86DD-9B08370BDEA6}.Debug|Win32.ActiveCfg = Debug|Win32 + {FB7F6FD2-A39D-40A1-86DD-9B08370BDEA6}.Debug|Win32.Build.0 = Debug|Win32 + {FB7F6FD2-A39D-40A1-86DD-9B08370BDEA6}.Release|Win32.ActiveCfg = Release|Win32 + {FB7F6FD2-A39D-40A1-86DD-9B08370BDEA6}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/mswin32/nmap.vcproj b/mswin32/nmap.vcproj index 2eaecc730..9738e95b2 100644 --- a/mswin32/nmap.vcproj +++ b/mswin32/nmap.vcproj @@ -1,7 +1,7 @@ - - @@ -454,10 +450,6 @@ RelativePath="..\nse_auxiliar.h" > - - diff --git a/nse_bitlib.cc b/nse_bitlib.cc deleted file mode 100644 index 96b793c54..000000000 --- a/nse_bitlib.cc +++ /dev/null @@ -1,75 +0,0 @@ -/* 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/ - **/ - -extern "C" { -#include "lauxlib.h" -#include "lua.h" -} - -#include "nse_bitlib.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, \ - 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, 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, 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_bitlib (lua_State *L) { - luaL_openlib(L, NSE_BITLIBNAME, bitlib, 0); - return 1; -} - diff --git a/nse_bitlib.h b/nse_bitlib.h deleted file mode 100644 index 1cc338605..000000000 --- a/nse_bitlib.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef NSE_BITLIB -#define NSE_BITLIB - -#define NSE_BITLIBNAME "bit" - -LUALIB_API int luaopen_bitlib (lua_State *L); - -#endif - diff --git a/nse_init.cc b/nse_init.cc index 0de2873c2..f24415408 100644 --- a/nse_init.cc +++ b/nse_init.cc @@ -4,7 +4,6 @@ #include "nse_debug.h" // 3rd Party libs -#include "nse_bitlib.h" #include "nse_pcrelib.h" #include "nbase.h" @@ -45,7 +44,6 @@ int init_lua(lua_State* l) { {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, {LUA_DBLIBNAME, luaopen_debug}, - {NSE_BITLIBNAME, luaopen_bitlib}, {NSE_PCRELIBNAME, luaopen_pcrelib}, {NULL, NULL} }; @@ -83,7 +81,12 @@ int init_setlualibpath(lua_State* l){ * (which is read from the package-module) appended - * the path for C-modules is as above but it searches for shared libs (*.so) */ luapath= std::string(path) + "?.lua;"; - luacpath= std::string(path) + "?.so;"; +#ifdef WIN32 + luacpath= std::string(path) + "?.dll;"; +#else + luacpath= std::string(path) + "?.so;"; +#endif + lua_getglobal(l,"package"); if(!lua_istable(l,-1)){ error("%s: the lua global-variable package is not a table?!", SCRIPT_ENGINE); diff --git a/nselib/nse_bitlib.vcproj b/nselib/nse_bitlib.vcproj new file mode 100644 index 000000000..abaac01e5 --- /dev/null +++ b/nselib/nse_bitlib.vcproj @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/dns-test-open-recursion.nse b/scripts/dns-test-open-recursion.nse index 5cbad2446..20f7176fa 100644 --- a/scripts/dns-test-open-recursion.nse +++ b/scripts/dns-test-open-recursion.nse @@ -8,7 +8,7 @@ license = "See nmaps COPYING for licence" categories = {"intrusive"} --- require "bit" +require "bit" portrule = function(host, port) if port.number == 53