mirror of
https://github.com/bol-van/zapret2.git
synced 2026-03-14 06:13:09 +00:00
nfqws2: remove any arithmetics beyond 32 bit
This commit is contained in:
@@ -668,10 +668,10 @@ function apply_fooling(desync, dis, fooling_options)
|
||||
if not dis then dis = desync.dis end
|
||||
if dis.tcp then
|
||||
if tonumber(fooling_options.tcp_seq) then
|
||||
dis.tcp.th_seq = dis.tcp.th_seq + fooling_options.tcp_seq
|
||||
dis.tcp.th_seq = u32add(dis.tcp.th_seq, fooling_options.tcp_seq)
|
||||
end
|
||||
if tonumber(fooling_options.tcp_ack) then
|
||||
dis.tcp.th_ack = dis.tcp.th_ack + fooling_options.tcp_ack
|
||||
dis.tcp.th_ack = u32add(dis.tcp.th_ack, fooling_options.tcp_ack)
|
||||
end
|
||||
if fooling_options.tcp_flags_unset then
|
||||
dis.tcp.th_flags = bitand(dis.tcp.th_flags, bitnot(parse_tcp_flags(fooling_options.tcp_flags_unset)))
|
||||
@@ -682,7 +682,7 @@ function apply_fooling(desync, dis, fooling_options)
|
||||
if tonumber(fooling_options.tcp_ts) then
|
||||
local idx = find_tcp_option(dis.tcp.options,TCP_KIND_TS)
|
||||
if idx and (dis.tcp.options[idx].data and #dis.tcp.options[idx].data or 0)==8 then
|
||||
dis.tcp.options[idx].data = bu32(u32(dis.tcp.options[idx].data)+fooling_options.tcp_ts)..string.sub(dis.tcp.options[idx].data,5)
|
||||
dis.tcp.options[idx].data = bu32(u32add(u32(dis.tcp.options[idx].data),fooling_options.tcp_ts))..string.sub(dis.tcp.options[idx].data,5)
|
||||
else
|
||||
DLOG("apply_fooling: timestamp tcp option not present or invalid")
|
||||
end
|
||||
@@ -1196,3 +1196,5 @@ function ipfrag2(dis, ipfrag_options)
|
||||
|
||||
return {dis1,dis2}
|
||||
end
|
||||
|
||||
print(bitor(-4,-2))
|
||||
77
nfq2/lua.c
77
nfq2/lua.c
@@ -68,31 +68,47 @@ static int luacall_DLOG_CONDUP(lua_State *L)
|
||||
static int luacall_bitlshift(lua_State *L)
|
||||
{
|
||||
lua_check_argc(L,"bitlshift",2);
|
||||
lua_pushinteger(L,luaL_checkinteger(L,1) << luaL_checkinteger(L,2));
|
||||
lua_Integer v=luaL_checkinteger(L,1);
|
||||
if (v>0xFFFFFFFF || v<-(lua_Integer)0xFFFFFFFF) luaL_error(L, "out of range");
|
||||
lua_pushinteger(L,v << luaL_checkinteger(L,2));
|
||||
return 1;
|
||||
}
|
||||
static int luacall_bitrshift(lua_State *L)
|
||||
{
|
||||
lua_check_argc(L,"bitrshift",2);
|
||||
lua_pushinteger(L,((LUA_UNSIGNED)luaL_checkinteger(L,1)) >> luaL_checkinteger(L,2));
|
||||
lua_Integer v=luaL_checkinteger(L,1);
|
||||
if (v>0xFFFFFFFF || v<-(lua_Integer)0xFFFFFFFF) luaL_error(L, "out of range");
|
||||
lua_pushinteger(L,v >> luaL_checkinteger(L,2));
|
||||
return 1;
|
||||
}
|
||||
static int luacall_bitand(lua_State *L)
|
||||
{
|
||||
lua_check_argc_range(L,"bitand",2,100);
|
||||
int argc = lua_gettop(L);
|
||||
lua_Integer v=luaL_checkinteger(L,1);
|
||||
for(int i=2;i<=argc;i++) v&=luaL_checkinteger(L,i);
|
||||
lua_pushinteger(L,v);
|
||||
lua_Integer v;
|
||||
uint32_t sum=0xFFFFFFFF;
|
||||
for(int i=1;i<=argc;i++)
|
||||
{
|
||||
v=luaL_checkinteger(L,i);
|
||||
if (v>0xFFFFFFFF || v<-(lua_Integer)0xFFFFFFFF) luaL_error(L, "out of range");
|
||||
sum&=(uint32_t)v;
|
||||
}
|
||||
lua_pushinteger(L,sum);
|
||||
return 1;
|
||||
}
|
||||
static int luacall_bitor(lua_State *L)
|
||||
{
|
||||
lua_check_argc_range(L,"bitor",2,100);
|
||||
lua_check_argc_range(L,"bitor",1,100);
|
||||
int argc = lua_gettop(L);
|
||||
lua_Integer v=0;
|
||||
for(int i=1;i<=argc;i++) v|=luaL_checkinteger(L,i);
|
||||
lua_pushinteger(L,v);
|
||||
lua_Integer v;
|
||||
uint32_t sum=0;
|
||||
for(int i=1;i<=argc;i++)
|
||||
{
|
||||
v=luaL_checkinteger(L,i);
|
||||
if (v>0xFFFFFFFF || v<-(lua_Integer)0xFFFFFFFF) luaL_error(L, "out of range");
|
||||
sum|=(uint32_t)v;
|
||||
}
|
||||
lua_pushinteger(L,sum);
|
||||
return 1;
|
||||
}
|
||||
static int luacall_bitnot(lua_State *L)
|
||||
@@ -103,21 +119,29 @@ static int luacall_bitnot(lua_State *L)
|
||||
}
|
||||
static int luacall_bitxor(lua_State *L)
|
||||
{
|
||||
lua_check_argc_range(L,"bitxor",2,100);
|
||||
lua_check_argc_range(L,"bitxor",1,100);
|
||||
int argc = lua_gettop(L);
|
||||
lua_Integer v=0;
|
||||
for(int i=1;i<=argc;i++) v^=luaL_checkinteger(L,i);
|
||||
lua_pushinteger(L,v);
|
||||
lua_Integer v;
|
||||
uint32_t sum=0;
|
||||
for(int i=1;i<=argc;i++)
|
||||
{
|
||||
v=luaL_checkinteger(L,i);
|
||||
if (v>0xFFFFFFFF || v<-(lua_Integer)0xFFFFFFFF) luaL_error(L, "out of range");
|
||||
sum^=(uint32_t)v;
|
||||
}
|
||||
lua_pushinteger(L,sum);
|
||||
return 1;
|
||||
}
|
||||
static int luacall_bitget(lua_State *L)
|
||||
{
|
||||
lua_check_argc(L,"bitget",3);
|
||||
|
||||
LUA_UNSIGNED what = (LUA_UNSIGNED)luaL_checkinteger(L,1);
|
||||
lua_Integer iwhat = luaL_checkinteger(L,1);
|
||||
if (iwhat>0xFFFFFFFF || iwhat<-(lua_Integer)0xFFFFFFFF) luaL_error(L, "out of range");
|
||||
uint32_t what = (uint32_t)iwhat;
|
||||
lua_Integer from = luaL_checkinteger(L,2);
|
||||
lua_Integer to = luaL_checkinteger(L,3);
|
||||
if (from>to || from>63 || to>63)
|
||||
if (from>to || from>31 || to>31)
|
||||
luaL_error(L, "bit range invalid");
|
||||
|
||||
what = (what >> from) & ~((lua_Integer)-1 << (to-from+1));
|
||||
@@ -129,11 +153,15 @@ static int luacall_bitset(lua_State *L)
|
||||
{
|
||||
lua_check_argc(L,"bitset",4);
|
||||
|
||||
LUA_UNSIGNED what = (LUA_UNSIGNED)luaL_checkinteger(L,1);
|
||||
lua_Integer iwhat = luaL_checkinteger(L,1);
|
||||
if (iwhat>0xFFFFFFFF || iwhat<-(lua_Integer)0xFFFFFFFF) luaL_error(L, "out of range");
|
||||
uint32_t what = (uint32_t)iwhat;
|
||||
lua_Integer from = luaL_checkinteger(L,2);
|
||||
lua_Integer to = luaL_checkinteger(L,3);
|
||||
LUA_UNSIGNED set = (LUA_UNSIGNED)luaL_checkinteger(L,4);
|
||||
if (from>to || from>63 || to>63)
|
||||
lua_Integer iset = luaL_checkinteger(L,4);
|
||||
if (iset>0xFFFFFFFF || iset<-(lua_Integer)0xFFFFFFFF) luaL_error(L, "out of range");
|
||||
uint32_t set = (uint32_t)iset;
|
||||
if (from>to || from>31 || to>31)
|
||||
luaL_error(L, "bit range invalid");
|
||||
|
||||
lua_Integer mask = ~((lua_Integer)-1 << (to-from+1));
|
||||
@@ -214,35 +242,36 @@ static int luacall_swap16(lua_State *L)
|
||||
}
|
||||
static int lua_uxadd(lua_State *L, uint32_t max)
|
||||
{
|
||||
lua_Integer sum=0, v;
|
||||
lua_Integer v;
|
||||
uint32_t sum=0;
|
||||
int argc = lua_gettop(L);
|
||||
for(int i=1;i<=argc;i++)
|
||||
{
|
||||
v = luaL_checkinteger(L,i);
|
||||
if (v>max || v<-(lua_Integer)max) luaL_error(L, "out of range");
|
||||
sum+=v;
|
||||
sum+=(uint32_t)v;
|
||||
}
|
||||
lua_pushinteger(L, sum & max);
|
||||
return 1;
|
||||
}
|
||||
static int luacall_u8add(lua_State *L)
|
||||
{
|
||||
lua_check_argc_range(L,"u8add",2,100);
|
||||
lua_check_argc_range(L,"u8add",1,100);
|
||||
return lua_uxadd(L, 0xFF);
|
||||
}
|
||||
static int luacall_u16add(lua_State *L)
|
||||
{
|
||||
lua_check_argc_range(L,"u16add",2,100);
|
||||
lua_check_argc_range(L,"u16add",1,100);
|
||||
return lua_uxadd(L, 0xFFFF);
|
||||
}
|
||||
static int luacall_u24add(lua_State *L)
|
||||
{
|
||||
lua_check_argc_range(L,"u24add",2,100);
|
||||
lua_check_argc_range(L,"u24add",1,100);
|
||||
return lua_uxadd(L, 0xFFFFFF);
|
||||
}
|
||||
static int luacall_u32add(lua_State *L)
|
||||
{
|
||||
lua_check_argc_range(L,"u32add",2,100);
|
||||
lua_check_argc_range(L,"u32add",1,100);
|
||||
return lua_uxadd(L, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user