Beispiel #1
0
WSLUA_METHOD TvbRange_le_ipv4(lua_State* L) {
	/* Get an Little Endian IPv4 Address from a TvbRange. */
    TvbRange tvbr = checkTvbRange(L,1);
    Address addr;
    guint32* ip_addr;

    if ( !(tvbr && tvbr->tvb)) return 0;
    if (tvbr->tvb->expired) {
        luaL_error(L,"expired tvb");
        return 0;
    }

    if (tvbr->len != 4)
        WSLUA_ERROR(TvbRange_ipv4,"The range must be 4 octets long");

    addr = (address *)g_malloc(sizeof(address));

    ip_addr = (guint32 *)g_malloc(sizeof(guint32));
    *ip_addr = tvb_get_ipv4(tvbr->tvb->ws_tvb,tvbr->offset);
    *((guint32 *)ip_addr) = GUINT32_SWAP_LE_BE(*((guint32 *)ip_addr));

    SET_ADDRESS(addr, AT_IPv4, 4, ip_addr);
    pushAddress(L,addr);

    WSLUA_RETURN(1); /* The IPv4 Address */
}
Beispiel #2
0
void allocLocal(TypePtr typePtr)
{
	if(typePtr == IntegerTypePtr)
		pushInteger(0);
	else if(typePtr == RealTypePtr)
		pushReal((float)0.0);
	else if(typePtr == BooleanTypePtr)
		pushByte(0);
	else if(typePtr == CharTypePtr)
		pushByte(0);
	else
		switch(typePtr->form)
		{
			case FRM_ENUM:
				pushInteger(0);
				break;
// NOTE: We currently are not supporting sub ranges, until
// we really want 'em...
//			case FRM_SUBRANGE:
//				allocLocal(typePtr->info.subrange.rangeTypePtr);
//				break;
			case FRM_ARRAY:
				PSTR ptr = (PSTR)ABLStackMallocCallback(typePtr->size);
				if(!ptr)
					ABL_Fatal(0, " ABL: Unable to AblStackHeap->malloc local array ");
				pushAddress((Address)ptr);
				break;
		}
}
Beispiel #3
0
WSLUA_METHOD TvbRange_ether(lua_State* L) {
	/* Get an Ethernet Address from a TvbRange. */
    TvbRange tvbr = checkTvbRange(L,1);
    Address addr;
    guint8* buff;

    if ( !(tvbr && tvbr->tvb)) return 0;
    if (tvbr->tvb->expired) {
        luaL_error(L,"expired tvb");
        return 0;
    }

    if (tvbr->len != 6) {
        WSLUA_ERROR(TvbRange_ether,"The range must be 6 bytes long");
        return 0;
    }

    addr = g_new(address,1);

    buff = (guint8 *)tvb_memdup(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len);

    SET_ADDRESS(addr, AT_ETHER, 6, buff);
    pushAddress(L,addr);

    WSLUA_RETURN(1); /* The Ethernet Address */
}
Beispiel #4
0
WSLUA_METHOD TvbRange_ipv4(lua_State* L) {
    /* Get an IPv4 Address from a `TvbRange`, as an `Address` object. */
    TvbRange tvbr = checkTvbRange(L,1);
    Address addr;
    guint32* ip_addr;

    if ( !(tvbr && tvbr->tvb)) return 0;
    if (tvbr->tvb->expired) {
        luaL_error(L,"expired tvb");
        return 0;
    }

    if (tvbr->len != 4) {
        WSLUA_ERROR(TvbRange_ipv4,"The range must be 4 octets long");
        return 0;
    }

    addr = (address *)g_malloc(sizeof(address));

    ip_addr = (guint32 *)g_malloc(sizeof(guint32));
    *ip_addr = tvb_get_ipv4(tvbr->tvb->ws_tvb,tvbr->offset);

    set_address(addr, AT_IPv4, 4, ip_addr);
    pushAddress(L,addr);

    WSLUA_RETURN(1); /* The IPv4 `Address` object. */
}
Beispiel #5
0
//***************************************************************************
void pushStackFrameHeader(int32_t oldLevel, int32_t newLevel)
{
	//-----------------------------------
	// Make space for the return value...
	pushInteger(0);
	StackFrameHeaderPtr headerPtr = (StackFrameHeaderPtr)stackFrameBasePtr;
	//----------------------------------------------------------------------
	// STATIC LINK
	// Currently, let's not allow functions defined within functions. Assume
	// the old scope level equals the new scope level, for now.
	if(newLevel == -1)
	{
		//--------------------------------------------------------------------
		// Calling a library function, so push a nullptr static link since
		// it's scope is in a different module than the calling function.
		// Note that global variables in libraries should be STATIC, otherwise
		// they're never in scope! Weird "feature" which we may want
		// to fix later...
		pushAddress(nullptr);
	}
	else if(newLevel == oldLevel + 1)
	{
		//----------------------------------------------------------------
		// Calling a routine nested within the caller, so push the pointer
		// to the caller's stack frame. In ABL, as currently defined
		// (2/22/96), this should only be when a module's code section is
		// calling a function...
		pushAddress((Address)headerPtr);
	}
	else if(newLevel == oldLevel)
	{
		//---------------------------------------------------------------
		// Calling a function at the same scope level. We like that! Push
		// pointer to stack frame of their common parent...
		pushAddress(headerPtr->staticLink.address);
	}
	else
	{
		//-------------------------------------------------------
		// Oops. We don't want nested functions, for now, in ABL.
		runtimeError(ABL_ERR_RUNTIME_NESTED_FUNCTION_CALL);
	}
	pushAddress((Address)stackFrameBasePtr);
	//---------------------------
	// Push the return address...
	pushAddress(0);
}
Beispiel #6
0
static int Address_tipc(lua_State* L) {
    Address addr = g_malloc(sizeof(address));

    SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));

    pushAddress(L,addr);
    return 1;
}
Beispiel #7
0
/* WSLUA_ATTRIBUTE Pinfo_lo RO lower Address of this Packet. */
static int Pinfo_get_lo(lua_State *L) {
    Pinfo pinfo = checkPinfo(L,1);
    Address addr;

    addr = (Address)g_malloc(sizeof(address));
    if (cmp_address(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) < 0) {
        copy_address(addr, &(pinfo->ws_pinfo->src));
    } else {
        copy_address(addr, &(pinfo->ws_pinfo->dst));
    }

    pushAddress(L,addr);
    return 1;
}
Beispiel #8
0
/* WSLUA_ATTRIBUTE Pinfo_hi RW higher Address of this Packet. */
static int Pinfo_get_hi(lua_State *L) {
    Pinfo pinfo = checkPinfo(L,1);
    Address addr;

    addr = (Address)g_malloc(sizeof(address));
    if (CMP_ADDRESS(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) >= 0) {
        COPY_ADDRESS(addr, &(pinfo->ws_pinfo->src));
    } else {
        COPY_ADDRESS(addr, &(pinfo->ws_pinfo->dst));
    }

    pushAddress(L,addr);
    return 1;
}
Beispiel #9
0
WSLUA_CONSTRUCTOR Address_ip(lua_State* L) {
	/* Creates an Address Object representing an IP address. */

#define WSLUA_ARG_Address_ip_HOSTNAME 1 /* The address or name of the IP host. */
    Address addr = g_malloc(sizeof(address));
    guint32* ip_addr = g_malloc(sizeof(guint32));
    const gchar* name = luaL_checkstring(L,WSLUA_ARG_Address_ip_HOSTNAME);

    if (! get_host_ipaddr(name, (guint32*)ip_addr)) {
        *ip_addr = 0;
    }

    SET_ADDRESS(addr, AT_IPv4, 4, ip_addr);
    pushAddress(L,addr);
    WSLUA_RETURN(1); /* The Address object */
}
Beispiel #10
0
TypePtr execConstant(SymTableNodePtr idPtr)
{
	TypePtr typePtr = idPtr->typePtr;
	if ((typePtr == IntegerTypePtr) || (typePtr->form == FRM_ENUM))
		pushInteger(idPtr->defn.info.constant.value.integer);
	else if (typePtr == RealTypePtr)
		pushReal(idPtr->defn.info.constant.value.real);
	else if (typePtr == CharTypePtr)
		pushInteger(idPtr->defn.info.constant.value.character);
	else if (typePtr->form == FRM_ARRAY)
		pushAddress(idPtr->defn.info.constant.value.stringPtr);
	if (debugger)
		debugger->traceDataFetch(idPtr, typePtr, tos);
	getCodeToken();
	return (typePtr);
}
Beispiel #11
0
WSLUA_METHOD TvbRange_ether(lua_State* L) {
    /* Get an Ethernet Address from a `TvbRange`, as an `Address` object. */
    TvbRange tvbr = checkTvbRange(L,1);
    Address addr;

    if ( !(tvbr && tvbr->tvb)) return 0;
    if (tvbr->tvb->expired) {
        luaL_error(L,"expired tvb");
        return 0;
    }

    if (tvbr->len != 6) {
        WSLUA_ERROR(TvbRange_ether,"The range must be 6 bytes long");
        return 0;
    }

    addr = g_new(address,1);
    alloc_address_tvb(NULL,addr,AT_ETHER,6,tvbr->tvb->ws_tvb,tvbr->offset);
    pushAddress(L,addr);

    WSLUA_RETURN(1); /* The Ethernet `Address` object. */
}
Beispiel #12
0
WSLUA_METHOD TvbRange_le_ipv4(lua_State* L) {
    /* Get an Little Endian IPv4 Address from a `TvbRange`, as an `Address` object. */
    TvbRange tvbr = checkTvbRange(L,1);
    Address addr;
    guint32 ip_addr;

    if ( !(tvbr && tvbr->tvb)) return 0;
    if (tvbr->tvb->expired) {
        luaL_error(L,"expired tvb");
        return 0;
    }

    if (tvbr->len != 4) {
        WSLUA_ERROR(TvbRange_ipv4,"The range must be 4 octets long");
        return 0;
    }

    addr = g_new(address,1);
    ip_addr = GUINT32_SWAP_LE_BE(tvb_get_ipv4(tvbr->tvb->ws_tvb,tvbr->offset));
    alloc_address_wmem(NULL, addr, AT_IPv4, sizeof(ip_addr), &ip_addr);
    pushAddress(L,addr);

    WSLUA_RETURN(1); /* The IPv4 `Address` object. */
}
Beispiel #13
0
WSLUA_METAMETHOD FieldInfo__call(lua_State* L) {
    /*
       Obtain the Value of the field
       */
    FieldInfo fi = checkFieldInfo(L,1);

    switch(fi->hfinfo->type) {
        case FT_BOOLEAN:
                lua_pushboolean(L,(int)fvalue_get_uinteger(&(fi->value)));
                return 1;
        case FT_UINT8:
        case FT_UINT16:
        case FT_UINT24:
        case FT_UINT32:
        case FT_FRAMENUM:
                lua_pushnumber(L,(lua_Number)fvalue_get_uinteger(&(fi->value)));
                return 1;
        case FT_INT8:
        case FT_INT16:
        case FT_INT24:
        case FT_INT32:
                lua_pushnumber(L,(lua_Number)fvalue_get_sinteger(&(fi->value)));
                return 1;
        case FT_FLOAT:
        case FT_DOUBLE:
                lua_pushnumber(L,(lua_Number)fvalue_get_floating(&(fi->value)));
                return 1;
        case FT_INT64: {
                Int64 num = (Int64)g_malloc(sizeof(gint64));
                *num = fvalue_get_integer64(&(fi->value));
                pushInt64(L,num);
                return 1;
            }
        case FT_UINT64: {
                UInt64 num = (UInt64)g_malloc(sizeof(guint64));
                *num = fvalue_get_integer64(&(fi->value));
                pushUInt64(L,num);
                return 1;
            }
        case FT_ETHER: {
                Address eth = (Address)g_malloc(sizeof(address));
                eth->type = AT_ETHER;
                eth->len = fi->length;
                eth->data = tvb_memdup(NULL,fi->ds_tvb,fi->start,fi->length);
                pushAddress(L,eth);
                return 1;
            }
        case FT_IPv4:{
                Address ipv4 = (Address)g_malloc(sizeof(address));
                ipv4->type = AT_IPv4;
                ipv4->len = fi->length;
                ipv4->data = tvb_memdup(NULL,fi->ds_tvb,fi->start,fi->length);
                pushAddress(L,ipv4);
                return 1;
            }
        case FT_IPv6: {
                Address ipv6 = (Address)g_malloc(sizeof(address));
                ipv6->type = AT_IPv6;
                ipv6->len = fi->length;
                ipv6->data = tvb_memdup(NULL,fi->ds_tvb,fi->start,fi->length);
                pushAddress(L,ipv6);
                return 1;
            }
        case FT_IPXNET:{
                Address ipx = (Address)g_malloc(sizeof(address));
                ipx->type = AT_IPX;
                ipx->len = fi->length;
                ipx->data = tvb_memdup(NULL,fi->ds_tvb,fi->start,fi->length);
                pushAddress(L,ipx);
                return 1;
            }
        case FT_ABSOLUTE_TIME:
        case FT_RELATIVE_TIME: {
                NSTime nstime = (NSTime)g_malloc(sizeof(nstime_t));
                *nstime = *(NSTime)fvalue_get(&(fi->value));
                pushNSTime(L,nstime);
                return 1;
            }
        case FT_STRING:
        case FT_STRINGZ: {
                gchar* repr = fvalue_to_string_repr(&fi->value,FTREPR_DISPLAY,NULL);
                if (repr)
                    lua_pushstring(L,repr);
                else
                    luaL_error(L,"field cannot be represented as string because it may contain invalid characters");

                return 1;
            }
        case FT_NONE:
                if (fi->length == 0) {
                        lua_pushnil(L);
                        return 1;
                }
                /* FALLTHROUGH */
        case FT_BYTES:
        case FT_UINT_BYTES:
        case FT_GUID:
        case FT_PROTOCOL:
        case FT_REL_OID:
        case FT_SYSTEM_ID:
        case FT_OID: {
                ByteArray ba = g_byte_array_new();
                g_byte_array_append(ba, (const guint8 *)tvb_memdup(wmem_packet_scope(),fi->ds_tvb,fi->start,fi->length),fi->length);
                pushByteArray(L,ba);
                return 1;
            }
        default:
                luaL_error(L,"FT_ not yet supported");
                return 1;
    }
}
Beispiel #14
0
TypePtr execVariable(SymTableNodePtr idPtr, UseType use)
{
	TypePtr typePtr = (TypePtr)(idPtr->typePtr);
	// First, point to the variable's stack item. If the variable's scope
	// level is less than the current scope level, follow the static links
	// to the proper stack frame base...
	StackItemPtr dataPtr = nullptr;
	StackItem tempStackItem;
	switch (idPtr->defn.info.data.varType)
	{
	case VAR_TYPE_NORMAL:
	{
		StackFrameHeaderPtr headerPtr = (StackFrameHeaderPtr)stackFrameBasePtr;
		int32_t delta				  = level - idPtr->level;
		while (delta-- > 0)
			headerPtr = (StackFrameHeaderPtr)headerPtr->staticLink.address;
		dataPtr = (StackItemPtr)headerPtr + idPtr->defn.info.data.offset;
	}
	break;
	case VAR_TYPE_ETERNAL:
		dataPtr = (StackItemPtr)stack + idPtr->defn.info.data.offset;
		break;
	case VAR_TYPE_STATIC:
		//---------------------------------------------------------
		// If we're referencing a library's static variable, we may
		// need to shift to its static data space temporarily...
		if (idPtr->library && (idPtr->library != CurModule))
			StaticDataPtr = idPtr->library->getStaticData();
		dataPtr = (StackItemPtr)StaticDataPtr + idPtr->defn.info.data.offset;
		if (idPtr->library && (idPtr->library != CurModule))
			StaticDataPtr = CurModule->getStaticData();
		break;
	case VAR_TYPE_REGISTERED:
		tempStackItem.address = (PSTR)idPtr->defn.info.data.registeredData;
		dataPtr				  = &tempStackItem;
		break;
	}
	//---------------------------------------------------------------
	// If it's a scalar or enumeration reference parameter, that item
	// points to the actual item...
	if (idPtr->defn.key == DFN_REFPARAM)
		if (typePtr->form != FRM_ARRAY) /* && (typePtr->form != FRM_RECORD)*/
			dataPtr = (StackItemPtr)dataPtr->address;
	ABL_Assert(dataPtr != nullptr, 0, " ABL.execVariable(): dataPtr is nullptr ");
	//-----------------------------------------------------
	// Now, push the address of the variable's data area...
	if ((typePtr->form == FRM_ARRAY) /*|| (typePtr->form == FRM_RECORD)*/)
	{
		// pushInteger(typePtr->size);
		pushAddress((Address)dataPtr->address);
	}
	else if (idPtr->defn.info.data.varType == VAR_TYPE_REGISTERED)
		pushAddress((Address)dataPtr->address);
	else
		pushAddress((Address)dataPtr);
	//-----------------------------------------------------------------------------------
	// If there is a subscript (or field identifier, if records are being used
	// in ABL) then modify the address to point to the proper element of the
	// array (or record)...
	getCodeToken();
	while ((codeToken == TKN_LBRACKET) /*|| (codeTOken == TKN_PERIOD)*/)
	{
		// if (codeToken == TKN_LBRACKET)
		typePtr = execSubscripts(typePtr);
		// else if (codeToken == TKN_PERIOD)
		//	typePtr = execField(typePtr);
	}
	//------------------------------------------------------------
	// Leave the modified address on the top of the stack if:
	//		a) it's an assignment target;
	//		b) it reresents a parameter passed by reference;
	//		c) it's the address of an array or record;
	// Otherwise, replace the address with the value it points to.
	if ((use != USE_TARGET) && (use != USE_REFPARAM) && (typePtr->form != FRM_ARRAY))
	{
		if ((typePtr == IntegerTypePtr) || (typePtr->form == FRM_ENUM))
		{
			tos->integer = *((int32_t*)tos->address);
		}
		else if (typePtr == CharTypePtr)
			tos->byte = *((PSTR)tos->address);
		else
			tos->real = *((float*)tos->address);
	}
	if (debugger)
	{
		if ((use != USE_TARGET) && (use != USE_REFPARAM))
		{
			if (typePtr->form == FRM_ARRAY)
				debugger->traceDataFetch(idPtr, typePtr, (StackItemPtr)tos->address);
			else
				debugger->traceDataFetch(idPtr, typePtr, tos);
		}
	}
	return (typePtr);
}
Beispiel #15
0
TypePtr execFactor(void)
{
	TypePtr resultTypePtr = nullptr;
	switch (codeToken)
	{
	case TKN_IDENTIFIER:
	{
		SymTableNodePtr idPtr = getCodeSymTableNodePtr();
		if (idPtr->defn.key == DFN_FUNCTION)
		{
			SymTableNodePtr thisRoutineIdPtr = CurRoutineIdPtr;
			resultTypePtr					 = execRoutineCall(idPtr, false);
			CurRoutineIdPtr					 = thisRoutineIdPtr;
		}
		else if (idPtr->defn.key == DFN_CONST)
			resultTypePtr = execConstant(idPtr);
		else
			resultTypePtr = execVariable(idPtr, USE_EXPR);
	}
	break;
	case TKN_NUMBER:
	{
		SymTableNodePtr numberPtr = getCodeSymTableNodePtr();
		if (numberPtr->typePtr == IntegerTypePtr)
		{
			pushInteger(numberPtr->defn.info.constant.value.integer);
			resultTypePtr = IntegerTypePtr;
		}
		else
		{
			pushReal(numberPtr->defn.info.constant.value.real);
			resultTypePtr = RealTypePtr;
		}
		getCodeToken();
	}
	break;
	case TKN_STRING:
	{
		SymTableNodePtr nodePtr = getCodeSymTableNodePtr();
		int32_t length			= strlen(nodePtr->name);
		if (length > 1)
		{
			//-----------------------------------------------------------------------
			// Remember, the double quotes are on the back and front of the
			// string...
			pushAddress(nodePtr->info);
			resultTypePtr = nodePtr->typePtr;
		}
		else
		{
			//----------------------------------------------
			// Just push the one character in this string...
			pushByte(nodePtr->name[0]);
			resultTypePtr = CharTypePtr;
		}
		getCodeToken();
	}
	break;
	case TKN_NOT:
		getCodeToken();
		resultTypePtr = execFactor();
		//--------------------------------------
		// Following flips 1 to 0, and 0 to 1...
		tos->integer = 1 - tos->integer;
		break;
	case TKN_LPAREN:
		getCodeToken();
		resultTypePtr = execExpression();
		getCodeToken();
		break;
	}
	return (resultTypePtr);
}
Beispiel #16
0
WSLUA_METAMETHOD FieldInfo__call(lua_State* L) {
	/*
	 Obtain the Value of the field
	 */
	FieldInfo fi = checkFieldInfo(L,1);

	switch(fi->hfinfo->type) {
		case FT_NONE:
			lua_pushnil(L);
			return 1;
		case FT_UINT8:
		case FT_UINT16:
		case FT_UINT24:
		case FT_UINT32:
		case FT_FRAMENUM:
			lua_pushnumber(L,(lua_Number)fvalue_get_uinteger(&(fi->value)));
			return 1;
		case FT_INT8:
		case FT_INT16:
		case FT_INT24:
		case FT_INT32:
			lua_pushnumber(L,(lua_Number)fvalue_get_sinteger(&(fi->value)));
			return 1;
		case FT_FLOAT:
		case FT_DOUBLE:
			lua_pushnumber(L,(lua_Number)fvalue_get_floating(&(fi->value)));
			return 1;
		case FT_INT64: {
			Int64 num = g_malloc(sizeof(gint64));
			*num = fvalue_get_integer64(&(fi->value));
			pushInt64(L,num);
			return 1;
		}
		case FT_UINT64: {
			UInt64 num = g_malloc(sizeof(guint64));
			*num = fvalue_get_integer64(&(fi->value));
			pushUInt64(L,num);
			return 1;
		}
		case FT_ETHER: {
			Address eth = g_malloc(sizeof(address));
			eth->type = AT_ETHER;
			eth->len = fi->length;
			eth->data = tvb_memdup(fi->ds_tvb,fi->start,fi->length);
			pushAddress(L,eth);
			return 1;
		}
		case FT_IPv4:{
			Address ipv4 = g_malloc(sizeof(address));
			ipv4->type = AT_IPv4;
			ipv4->len = fi->length;
			ipv4->data = tvb_memdup(fi->ds_tvb,fi->start,fi->length);
			pushAddress(L,ipv4);
			return 1;
		}
		case FT_IPv6: {
			Address ipv6 = g_malloc(sizeof(address));
			ipv6->type = AT_IPv6;
			ipv6->len = fi->length;
			ipv6->data = tvb_memdup(fi->ds_tvb,fi->start,fi->length);
			pushAddress(L,ipv6);
			return 1;
		}
		case FT_IPXNET:{
			Address ipx = g_malloc(sizeof(address));
			ipx->type = AT_IPX;
			ipx->len = fi->length;
			ipx->data = tvb_memdup(fi->ds_tvb,fi->start,fi->length);
			pushAddress(L,ipx);
			return 1;
		}
		case FT_STRING:
		case FT_STRINGZ: {
			gchar* repr = fvalue_to_string_repr(&fi->value,FTREPR_DISPLAY,NULL);
			if (repr) 
				lua_pushstring(L,repr);
			else
				luaL_error(L,"field cannot be represented as string because it may contain invalid characters");
			
			return 1;
		}
		case FT_BYTES:
		case FT_UINT_BYTES:
		case FT_GUID:
		case FT_OID: {
			ByteArray ba = g_byte_array_new();
			g_byte_array_append(ba, ep_tvb_memdup(fi->ds_tvb,fi->start,fi->length),fi->length);
			pushByteArray(L,ba);
			return 1;
		}
		default:
			luaL_error(L,"FT_ not yet supported");
			return 1;
	}
}
Beispiel #17
0
static void wslua_eth_to_table(lua_State* L, const void* p) { eth_hdr* v = (void*)p; lua_newtable(L);
	lua_pushstring(L,"dst"); { Address a = g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->dst)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"src"); { Address a = g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->src)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"type"); lua_pushnumber(L,(lua_Number)v->type); lua_settable(L,-3);
}
Beispiel #18
0
static void wslua_udp_to_table(lua_State* L, const void* p) { e_udphdr* v = (void*)p; lua_newtable(L);
	lua_pushstring(L,"ip_dst"); { Address a = g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->ip_dst)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"ip_src"); { Address a = g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->ip_src)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"uh_dport"); lua_pushnumber(L,(lua_Number)v->uh_dport); lua_settable(L,-3);
	lua_pushstring(L,"uh_sport"); lua_pushnumber(L,(lua_Number)v->uh_sport); lua_settable(L,-3);
	lua_pushstring(L,"uh_sum"); lua_pushnumber(L,(lua_Number)v->uh_sum); lua_settable(L,-3);
	lua_pushstring(L,"uh_sum_cov"); lua_pushnumber(L,(lua_Number)v->uh_sum_cov); lua_settable(L,-3);
	lua_pushstring(L,"uh_ulen"); lua_pushnumber(L,(lua_Number)v->uh_ulen); lua_settable(L,-3);
}
Beispiel #19
0
static void wslua_tcp_to_table(lua_State* L, const void* p) { tcp_info_t* v = (void*)p; lua_newtable(L);
	lua_pushstring(L,"ip_dst"); { Address a = g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->ip_dst)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"ip_src"); { Address a = g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->ip_src)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"th_ack"); lua_pushnumber(L,(lua_Number)v->th_ack); lua_settable(L,-3);
	lua_pushstring(L,"th_dport"); lua_pushnumber(L,(lua_Number)v->th_dport); lua_settable(L,-3);
	lua_pushstring(L,"th_flags"); lua_pushnumber(L,(lua_Number)v->th_flags); lua_settable(L,-3);
	lua_pushstring(L,"th_have_seglen"); lua_pushboolean(L,(int)v->th_have_seglen); lua_settable(L,-3);
	lua_pushstring(L,"th_hlen"); lua_pushnumber(L,(lua_Number)v->th_hlen); lua_settable(L,-3);
	lua_pushstring(L,"th_seglen"); lua_pushnumber(L,(lua_Number)v->th_seglen); lua_settable(L,-3);
	lua_pushstring(L,"th_seq"); lua_pushnumber(L,(lua_Number)v->th_seq); lua_settable(L,-3);
	lua_pushstring(L,"th_sport"); lua_pushnumber(L,(lua_Number)v->th_sport); lua_settable(L,-3);
	lua_pushstring(L,"th_stream"); lua_pushnumber(L,(lua_Number)v->th_stream); lua_settable(L,-3);
	lua_pushstring(L,"th_win"); lua_pushnumber(L,(lua_Number)v->th_win); lua_settable(L,-3);
}
Beispiel #20
0
static void wslua_ip_to_table(lua_State* L, const void* p) { ws_ip* v = (void*)p; lua_newtable(L);
	lua_pushstring(L,"ip_dst"); { Address a = g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->ip_dst)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"ip_id"); lua_pushnumber(L,(lua_Number)v->ip_id); lua_settable(L,-3);
	lua_pushstring(L,"ip_len"); lua_pushnumber(L,(lua_Number)v->ip_len); lua_settable(L,-3);
	lua_pushstring(L,"ip_off"); lua_pushnumber(L,(lua_Number)v->ip_off); lua_settable(L,-3);
	lua_pushstring(L,"ip_p"); lua_pushnumber(L,(lua_Number)v->ip_p); lua_settable(L,-3);
	lua_pushstring(L,"ip_src"); { Address a = g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->ip_src)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"ip_sum"); lua_pushnumber(L,(lua_Number)v->ip_sum); lua_settable(L,-3);
	lua_pushstring(L,"ip_tos"); lua_pushnumber(L,(lua_Number)v->ip_tos); lua_settable(L,-3);
	lua_pushstring(L,"ip_ttl"); lua_pushnumber(L,(lua_Number)v->ip_ttl); lua_settable(L,-3);
	lua_pushstring(L,"ip_v_hl"); lua_pushnumber(L,(lua_Number)v->ip_v_hl); lua_settable(L,-3);
}
Beispiel #21
0
int32_t ABLModule::execute(ABLParamPtr moduleParamList, SymTableNodePtr functionIdPtr)
{
    CurModule = this;
    if(debugger)
        debugger->setModule(this);
    //--------------------------
    // Execute the ABL module...
    SymTableNodePtr moduleIdPtr = ModuleRegistry[handle].moduleIdPtr;
    if(moduleIdPtr->defn.info.routine.flags & ROUTINE_FLAG_FSM)
        CurFSM = this;
    else
        CurFSM = nullptr;
    NumStateTransitions = 0;
    //--------------------------------------------
    // Point to this module's static data space...
    StaticDataPtr = staticData;
    OrderCompletionFlags = orderCallFlags;
    //---------------------------------
    // Init some important variables...
    CurModuleIdPtr = nullptr;
    CurRoutineIdPtr = nullptr;
    FileNumber = -1;
    errorCount = 0;
    execStatementCount = 0;
    NumExecutions++;
    NewStateSet = false;
    //------------------
    // Init the stack...
    stackFrameBasePtr = tos = (stack + eternalOffset);
    //---------------------------------------
    // Initialize the module's stack frame...
    level = 1;
    CallStackLevel = 0;
    stackFrameBasePtr = tos + 1;
    //-------------------------
    // Function return value...
    pushInteger(0);
    //---------------
    // Static Link...
    pushAddress(nullptr);
    //----------------
    // Dynamic Link...
    pushAddress(nullptr);
    //------------------
    // Return Address...
    pushAddress(nullptr);
    //initDebugger();
    //----------
    // Run it...
    if(moduleParamList)
    {
        //------------------------------------------------------------------------------
        // NOTE: Currently, parameter passing of arrays is not functioning. This MUST be
        // done...
        int32_t curParam = 0;
        for(SymTableNodePtr formalIdPtr = (SymTableNodePtr)(moduleIdPtr->defn.info.routine.params);
                formalIdPtr != nullptr;
                formalIdPtr = formalIdPtr->next)
        {
            TypePtr formalTypePtr = (TypePtr)(formalIdPtr->typePtr);
            if(formalIdPtr->defn.key == DFN_VALPARAM)
            {
                if(formalTypePtr == RealTypePtr)
                {
                    if(moduleParamList[curParam].type == ABL_PARAM_INTEGER)
                    {
                        //---------------------------------------------
                        // Real formal parameter, but integer actual...
                        pushReal((float)(moduleParamList[curParam].integer));
                    }
                    else if(moduleParamList[curParam].type == ABL_PARAM_REAL)
                        pushReal(moduleParamList[curParam].real);
                }
                else if(formalTypePtr == IntegerTypePtr)
                {
                    if(moduleParamList[curParam].type == ABL_PARAM_INTEGER)
                        pushInteger(moduleParamList[curParam].integer);
                    else
                        return(0);
                }
                //----------------------------------------------------------
                // Formal parameter is an array or record, so make a copy...
                if((formalTypePtr->form == FRM_ARRAY)/* || (formalTypePtr->form == FRM_RECORD)*/)
                {
                    //------------------------------------------------------------------------------
                    // The following is a little inefficient, but is kept this way to keep it clear.
                    // Once it's verified to work, optimize...
                    int32_t size = formalTypePtr->size;
                    PSTR dest = (PSTR)ABLStackMallocCallback((size_t)size);
                    if(!dest)
                    {
                        char err[255];
                        sprintf(err, "ABL: Unable to AblStackHeap->malloc array parameter [Module %d]", id);
                        ABL_Fatal(0, err);
                    }
                    PSTR src = tos->address;
                    PSTR savePtr = dest;
                    memcpy(dest, src, size);
                    tos->address = savePtr;
                }
            }
            else
            {
                //-------------------------------
                // pass by reference parameter...
                if(formalTypePtr == RealTypePtr)
                    pushAddress((Address) & (moduleParamList[curParam].real));
                else if(formalTypePtr == IntegerTypePtr)
                    pushAddress((Address) & (moduleParamList[curParam].integer));
                else
                    return(0);
            }
            curParam++;
        }
    }
    CurModuleHandle = handle;
    CallModuleInit = !initCalled;
    initCalled = true;
    ::executeChild(moduleIdPtr, functionIdPtr);
    memcpy(&returnVal, &returnValue, sizeof(StackItem));
    //-----------
    // Summary...
    return(execStatementCount);
}
Beispiel #22
0
/* WSLUA_ATTRIBUTE FieldInfo_value RO The value of this field. */
WSLUA_METAMETHOD FieldInfo__call(lua_State* L) {
    /*
       Obtain the Value of the field.

       Previous to 1.11.4, this function retrieved the value for most field types,
       but for `ftypes.UINT_BYTES` it retrieved the `ByteArray` of the field's entire `TvbRange`.
       In other words, it returned a `ByteArray` that included the leading length byte(s),
       instead of just the *value* bytes. That was a bug, and has been changed in 1.11.4.
       Furthermore, it retrieved an `ftypes.GUID` as a `ByteArray`, which is also incorrect.

       If you wish to still get a `ByteArray` of the `TvbRange`, use `FieldInfo:get_range()`
       to get the `TvbRange`, and then use `Tvb:bytes()` to convert it to a `ByteArray`.
       */
    FieldInfo fi = checkFieldInfo(L,1);

    switch(fi->ws_fi->hfinfo->type) {
        case FT_BOOLEAN:
                lua_pushboolean(L,(int)fvalue_get_uinteger(&(fi->ws_fi->value)));
                return 1;
        case FT_UINT8:
        case FT_UINT16:
        case FT_UINT24:
        case FT_UINT32:
        case FT_FRAMENUM:
                lua_pushnumber(L,(lua_Number)(fvalue_get_uinteger(&(fi->ws_fi->value))));
                return 1;
        case FT_INT8:
        case FT_INT16:
        case FT_INT24:
        case FT_INT32:
                lua_pushnumber(L,(lua_Number)(fvalue_get_sinteger(&(fi->ws_fi->value))));
                return 1;
        case FT_FLOAT:
        case FT_DOUBLE:
                lua_pushnumber(L,(lua_Number)(fvalue_get_floating(&(fi->ws_fi->value))));
                return 1;
        case FT_INT64: {
                pushInt64(L,(Int64)(fvalue_get_sinteger64(&(fi->ws_fi->value))));
                return 1;
            }
        case FT_UINT64: {
                pushUInt64(L,fvalue_get_uinteger64(&(fi->ws_fi->value)));
                return 1;
            }
        case FT_ETHER: {
                Address eth = (Address)g_malloc(sizeof(address));
                eth->type = AT_ETHER;
                eth->len = fi->ws_fi->length;
                eth->data = tvb_memdup(NULL,fi->ws_fi->ds_tvb,fi->ws_fi->start,fi->ws_fi->length);
                pushAddress(L,eth);
                return 1;
            }
        case FT_IPv4:{
                Address ipv4 = (Address)g_malloc(sizeof(address));
                ipv4->type = AT_IPv4;
                ipv4->len = fi->ws_fi->length;
                ipv4->data = tvb_memdup(NULL,fi->ws_fi->ds_tvb,fi->ws_fi->start,fi->ws_fi->length);
                pushAddress(L,ipv4);
                return 1;
            }
        case FT_IPv6: {
                Address ipv6 = (Address)g_malloc(sizeof(address));
                ipv6->type = AT_IPv6;
                ipv6->len = fi->ws_fi->length;
                ipv6->data = tvb_memdup(NULL,fi->ws_fi->ds_tvb,fi->ws_fi->start,fi->ws_fi->length);
                pushAddress(L,ipv6);
                return 1;
            }
        case FT_FCWWN: {
                Address fcwwn = (Address)g_malloc(sizeof(address));
                fcwwn->type = AT_FCWWN;
                fcwwn->len = fi->ws_fi->length;
                fcwwn->data = tvb_memdup(NULL,fi->ws_fi->ds_tvb,fi->ws_fi->start,fi->ws_fi->length);
                pushAddress(L,fcwwn);
                return 1;
            }
        case FT_IPXNET:{
                Address ipx = (Address)g_malloc(sizeof(address));
                ipx->type = AT_IPX;
                ipx->len = fi->ws_fi->length;
                ipx->data = tvb_memdup(NULL,fi->ws_fi->ds_tvb,fi->ws_fi->start,fi->ws_fi->length);
                pushAddress(L,ipx);
                return 1;
            }
        case FT_ABSOLUTE_TIME:
        case FT_RELATIVE_TIME: {
                NSTime nstime = (NSTime)g_malloc(sizeof(nstime_t));
                *nstime = *(NSTime)fvalue_get(&(fi->ws_fi->value));
                pushNSTime(L,nstime);
                return 1;
            }
        case FT_STRING:
        case FT_STRINGZ: {
                gchar* repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DISPLAY,BASE_NONE,NULL);
                if (repr)
                    lua_pushstring(L,repr);
                else
                    luaL_error(L,"field cannot be represented as string because it may contain invalid characters");

                return 1;
            }
        case FT_NONE:
                if (fi->ws_fi->length > 0 && fi->ws_fi->rep) {
                    /* it has a length, but calling fvalue_get() on an FT_NONE asserts,
                       so get the label instead (it's a FT_NONE, so a label is what it basically is) */
                    lua_pushstring(L, fi->ws_fi->rep->representation);
                    return 1;
                }
                return 0;
        case FT_BYTES:
        case FT_UINT_BYTES:
        case FT_REL_OID:
        case FT_SYSTEM_ID:
        case FT_OID:
            {
                ByteArray ba = g_byte_array_new();
                g_byte_array_append(ba, (const guint8 *) fvalue_get(&fi->ws_fi->value),
                                    fvalue_length(&fi->ws_fi->value));
                pushByteArray(L,ba);
                return 1;
            }
        case FT_PROTOCOL:
            {
                ByteArray ba = g_byte_array_new();
                tvbuff_t* tvb = (tvbuff_t *) fvalue_get(&fi->ws_fi->value);
                g_byte_array_append(ba, (const guint8 *)tvb_memdup(wmem_packet_scope(), tvb, 0,
                                            tvb_captured_length(tvb)), tvb_captured_length(tvb));
                pushByteArray(L,ba);
                return 1;
            }

        case FT_GUID:
        default:
                luaL_error(L,"FT_ not yet supported");
                return 1;
    }
}
Beispiel #23
0
static void wslua_wlan_to_table(lua_State* L, const void* p) { const wlan_hdr_t* v _U_; v = (const wlan_hdr_t*)p; lua_newtable(L);
	lua_pushstring(L,"bssid"); { Address a = (Address)g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->bssid)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"dst"); { Address a = (Address)g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->dst)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"src"); { Address a = (Address)g_malloc(sizeof(address)); COPY_ADDRESS(a, &(v->src)); pushAddress(L,a); } lua_settable(L,-3);
	lua_pushstring(L,"type"); lua_pushnumber(L,(lua_Number)v->type); lua_settable(L,-3);
}