Nmap Development mailing list archives
[NSE patch] patch for pack/unpack to use platform independant types
From: Sven Klemm <sven () c3d2 de>
Date: Thu, 07 Aug 2008 21:37:11 +0200
Hi,currently pack/unpack does not produce the same result across all platforms. The attached patch changes binlib to use platform independant types.
Cheers, Sven -- Sven Klemm http://cthulhu.c3d2.de/~sven/
Index: nse_binlib.cc =================================================================== --- nse_binlib.cc (revision 9387) +++ nse_binlib.cc (working copy) @@ -13,9 +13,9 @@ */ #define OP_ZSTRING 'z' /* zero-terminated string */ -#define OP_BSTRING 'p' /* string preceded by length byte */ -#define OP_WSTRING 'P' /* string preceded by length word */ -#define OP_SSTRING 'a' /* string preceded by length size_t */ +#define OP_BSTRING 'p' /* string preceded by 1 byte integer */ +#define OP_WSTRING 'P' /* string preceded by 2 byte integer */ +#define OP_SSTRING 'a' /* string preceded by 4 byte integer */ #define OP_STRING 'A' /* string */ #define OP_FLOAT 'f' /* float */ #define OP_DOUBLE 'd' /* double */ @@ -46,6 +46,7 @@ #include "lualib.h" #include "lauxlib.h" } +#include <nbase.h> #include "nse_binlib.h" static void badcode(lua_State *L, int c) @@ -168,20 +169,20 @@ ++n; break; } - UNPACKSTRING(OP_BSTRING, unsigned char) - UNPACKSTRING(OP_WSTRING, unsigned short) - UNPACKSTRING(OP_SSTRING, size_t) + UNPACKSTRING(OP_BSTRING, u_int8_t) + UNPACKSTRING(OP_WSTRING, u_int16_t) + UNPACKSTRING(OP_SSTRING, u_int32_t) UNPACKNUMBER(OP_NUMBER, lua_Number) UNPACKNUMBER(OP_DOUBLE, double) UNPACKNUMBER(OP_FLOAT, float) - UNPACKNUMBER(OP_CHAR, char) - UNPACKNUMBER(OP_BYTE, unsigned char) - UNPACKNUMBER(OP_SHORT, short) - UNPACKNUMBER(OP_USHORT, unsigned short) - UNPACKNUMBER(OP_INT, int) - UNPACKNUMBER(OP_UINT, unsigned int) - UNPACKNUMBER(OP_LONG, long) - UNPACKNUMBER(OP_ULONG, unsigned long) + UNPACKNUMBER(OP_CHAR, int8_t) + UNPACKNUMBER(OP_BYTE, u_int8_t) + UNPACKNUMBER(OP_SHORT, int16_t) + UNPACKNUMBER(OP_USHORT, u_int16_t) + UNPACKNUMBER(OP_INT, int32_t) + UNPACKNUMBER(OP_UINT, u_int32_t) + UNPACKNUMBER(OP_LONG, int64_t) + UNPACKNUMBER(OP_ULONG, u_int64_t) case OP_BINMSB: { @@ -305,20 +306,20 @@ luaL_addlstring(&b,a,l+(c==OP_ZSTRING)); break; } - PACKSTRING(OP_BSTRING, unsigned char) - PACKSTRING(OP_WSTRING, unsigned short) - PACKSTRING(OP_SSTRING, size_t) + PACKSTRING(OP_BSTRING, u_int8_t) + PACKSTRING(OP_WSTRING, u_int16_t) + PACKSTRING(OP_SSTRING, u_int32_t) PACKNUMBER(OP_NUMBER, lua_Number) PACKNUMBER(OP_DOUBLE, double) PACKNUMBER(OP_FLOAT, float) - PACKNUMBER(OP_CHAR, char) - PACKNUMBER(OP_BYTE, unsigned char) - PACKNUMBER(OP_SHORT, short) - PACKNUMBER(OP_USHORT, unsigned short) - PACKNUMBER(OP_INT, int) - PACKNUMBER(OP_UINT, unsigned int) - PACKNUMBER(OP_LONG, long) - PACKNUMBER(OP_ULONG, unsigned long) + PACKNUMBER(OP_CHAR, int8_t) + PACKNUMBER(OP_BYTE, u_int8_t) + PACKNUMBER(OP_SHORT, int16_t) + PACKNUMBER(OP_USHORT, u_int16_t) + PACKNUMBER(OP_INT, int32_t) + PACKNUMBER(OP_UINT, u_int32_t) + PACKNUMBER(OP_LONG, int64_t) + PACKNUMBER(OP_ULONG, u_int64_t) case OP_BINMSB: { unsigned char sbyte = 0;
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- [NSE patch] patch for pack/unpack to use platform independant types Sven Klemm (Aug 07)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Sven Klemm (Aug 14)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Philip Pickering (Aug 14)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Philip Pickering (Aug 15)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Sven Klemm (Aug 16)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Fyodor (Aug 16)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Sven Klemm (Aug 17)
- Re: [NSE patch] patch for pack/unpack to use platform independant types doug (Aug 17)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Philip Pickering (Aug 17)
- Message not available
- Re: [NSE patch] patch for pack/unpack to use platform independant types Philip Pickering (Aug 17)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Philip Pickering (Aug 21)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Philip Pickering (Aug 14)
- Re: [NSE patch] patch for pack/unpack to use platform independant types Sven Klemm (Aug 14)