1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-24 08:29:04 +00:00

merge soc07 r5048 - added nse_bitlib.cc/.h again - because compilation was broken on windows through the c-module support

This commit is contained in:
fyodor
2007-08-11 04:55:50 +00:00
parent 824af7f76e
commit 40d3cd5e37
5 changed files with 90 additions and 4 deletions

View File

@@ -55,9 +55,9 @@ INSTALLNMAPFE=@INSTALLNMAPFE@
INSTALLNSE=@INSTALLNSE@
ifneq (@LIBLUA_LIBS@,)
NSE_SRC=nse_main.cc nse_auxiliar.cc nse_nsock.cc nse_init.cc nse_nmaplib.cc nse_debug.cc nse_pcrelib.cc nse_string.cc
NSE_HDRS=nse_main.h nse_auxiliar.h nse_nsock.h nse_init.h nse_nmaplib.h nse_debug.h nse_macros.h nse_pcrelib.h nse_string.h
NSE_OBJS=nse_main.o nse_auxiliar.o nse_nsock.o nse_init.o nse_nmaplib.o nse_debug.o nse_pcrelib.o nse_string.o
NSE_SRC=nse_main.cc nse_auxiliar.cc nse_nsock.cc nse_init.cc nse_nmaplib.cc nse_debug.cc nse_pcrelib.cc nse_string.cc nse_bitlib.cc
NSE_HDRS=nse_main.h nse_auxiliar.h nse_nsock.h nse_init.h nse_nmaplib.h nse_debug.h nse_macros.h nse_pcrelib.h nse_string.h nse_bitlib.h
NSE_OBJS=nse_main.o nse_auxiliar.o nse_nsock.o nse_init.o nse_nmaplib.o nse_debug.o nse_pcrelib.o nse_string.o nse_bitlib.o
NSESTDLIB=nsestdlib
endif

75
nse_bitlib.cc Normal file
View File

@@ -0,0 +1,75 @@
/* 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;
}

9
nse_bitlib.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef NSE_BITLIB
#define NSE_BITLIB
#define NSE_BITLIBNAME "bit"
LUALIB_API int luaopen_bitlib (lua_State *L);
#endif

View File

@@ -4,6 +4,7 @@
#include "nse_debug.h"
// 3rd Party libs
#include "nse_bitlib.h"
#include "nse_pcrelib.h"
#include "nbase.h"
@@ -44,6 +45,7 @@ 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}
};

View File

@@ -8,7 +8,7 @@ license = "See nmaps COPYING for licence"
categories = {"intrusive"}
require "bit"
-- require "bit"
portrule = function(host, port)
if port.number == 53