コード例 #1
0
WSLUA_FUNCTION wslua_format_date(lua_State* LS) { /* Formats an absolute timestamp into a human readable date */
#define WSLUA_ARG_format_date_TIMESTAMP 1 /* A timestamp value to convert. */
    lua_Number timestamp = luaL_checknumber(LS,WSLUA_ARG_format_date_TIMESTAMP);
    nstime_t then;
    gchar* str;

    then.secs = (guint32)floor(timestamp);
    then.nsecs = (guint32) ( (timestamp-(double)(then.secs))*1000000000);
    str = abs_time_to_str(&then, ABSOLUTE_TIME_LOCAL, TRUE);
    lua_pushstring(LS,str);

    WSLUA_RETURN(1); /* A string with the formated date */
}
コード例 #2
0
WSLUA_METHOD Tvb_offset(lua_State* L) {
	/* Returns the raw offset (from the beginning of the source Tvb) of a sub Tvb. */
    Tvb tvb = checkTvb(L,1);

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

    lua_pushnumber(L,tvb_raw_offset(tvb->ws_tvb));
    WSLUA_RETURN(1); /* The raw offset of the Tvb. */
}
コード例 #3
0
WSLUA_METHOD Tvb_len(lua_State* L) {
	/* Obtain the length of a TVB */
    Tvb tvb = checkTvb(L,1);

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

    lua_pushnumber(L,tvb_length(tvb->ws_tvb));
    WSLUA_RETURN(1); /* The length of the Tvb. */
}
コード例 #4
0
WSLUA_FUNCTION wslua_format_time(lua_State* LS) { /* Formats a relative timestamp in a human readable form */
#define WSLUA_ARG_format_time_TIMESTAMP 1 /* A timestamp value to convert */
    lua_Number timestamp = luaL_checknumber(LS,WSLUA_ARG_format_time_TIMESTAMP);
    nstime_t then;
    gchar* str;

    then.secs = (guint32)floor(timestamp);
    then.nsecs = (guint32) ( (timestamp-(double)(then.secs))*1000000000);
    str = rel_time_to_str(&then);
    lua_pushstring(LS,str);

    WSLUA_RETURN(1); /* A string with the formated time */
}
コード例 #5
0
ファイル: wslua_tvb.c プロジェクト: linshimiao/wireshark
WSLUA_METAMETHOD Tvb__tostring(lua_State* L) {
    /* Convert the bytes of a `Tvb` into a string, to be used for debugging purposes, as '...'
       will be appended if the string is too long. */
    Tvb tvb = checkTvb(L,1);
    int len = tvb_captured_length(tvb->ws_tvb);
    char* str = tvb_bytes_to_str(NULL,tvb->ws_tvb,0,len);

    lua_pushfstring(L, "TVB(%d) : %s", len, str);

    wmem_free(NULL, str);

    WSLUA_RETURN(1); /* The string. */
}
コード例 #6
0
ファイル: wslua_tvb.c プロジェクト: DHODoS/wireshark
WSLUA_METHOD TvbRange_nstime(lua_State* L) {
    /* Obtain a time_t structure from a `TvbRange`, as an `NSTime` object. */
#define WSLUA_OPTARG_TvbRange_nstime_ENCODING 2 /* An optional ENC_* encoding value to use */
    TvbRange tvbr = checkTvbRange(L,1);
    NSTime nstime;
    const guint encoding = (guint) luaL_optinteger(L, WSLUA_OPTARG_TvbRange_nstime_ENCODING, 0);

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

    nstime = g_new(nstime_t,1);

    if (encoding == 0) {
        if (tvbr->len == 4) {
          nstime->secs = tvb_get_ntohl(tvbr->tvb->ws_tvb, tvbr->offset);
          nstime->nsecs = 0;
        } else if (tvbr->len == 8) {
          nstime->secs = tvb_get_ntohl(tvbr->tvb->ws_tvb, tvbr->offset);
          nstime->nsecs = tvb_get_ntohl(tvbr->tvb->ws_tvb, tvbr->offset + 4);
        } else {
          g_free(nstime);
          WSLUA_ERROR(TvbRange_nstime,"The range must be 4 or 8 bytes long");
          return 0;
        }
        pushNSTime(L, nstime);
        lua_pushinteger(L, tvbr->len);
    }
    else if (encoding & ~ENC_STR_TIME_MASK) {
        WSLUA_OPTARG_ERROR(TvbRange_nstime, ENCODING, "invalid encoding value");
    }
    else {
        gint endoff = 0;
        nstime_t *retval = tvb_get_string_time(tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len,
                                               encoding, nstime, &endoff);
        if (!retval || endoff == 0) {
            g_free(nstime);
            /* push nil nstime and offset */
            lua_pushnil(L);
            lua_pushnil(L);
        }
        else {
            pushNSTime(L, nstime);
            lua_pushinteger(L, endoff);
        }
    }

    WSLUA_RETURN(2); /* The `NSTime` object and number of bytes used, or nil on failure. */
}
コード例 #7
0
ファイル: wslua_dissector.c プロジェクト: CharaD7/wireshark
WSLUA_CONSTRUCTOR Dissector_get (lua_State *L) {
    /* Obtains a dissector reference by name. */
#define WSLUA_ARG_Dissector_get_NAME 1 /* The name of the dissector. */
    const gchar* name = luaL_checkstring(L,WSLUA_ARG_Dissector_get_NAME);
    Dissector d;

    if ((d = find_dissector(name))) {
        pushDissector(L, d);
        WSLUA_RETURN(1); /* The Dissector reference. */
    }

    WSLUA_ARG_ERROR(Dissector_get,NAME,"No such dissector");
    return 0;
}
コード例 #8
0
ファイル: wslua_capture_info.c プロジェクト: Ekleog/wireshark
WSLUA_METAMETHOD CaptureInfo__tostring(lua_State* L) {
    /* Generates a string of debug info for the CaptureInfo */
    CaptureInfo fi = toCaptureInfo(L,1);

    if (!fi || !fi->wth) {
        lua_pushstring(L,"CaptureInfo pointer is NULL!");
    } else {
        wtap *wth = fi->wth;
        lua_pushfstring(L, "CaptureInfo: file_type_subtype=%d, snapshot_length=%d, pkt_encap=%d, file_tsprec='%s'",
            wth->file_type_subtype, wth->snapshot_length, wth->phdr.pkt_encap, wth->file_tsprec);
    }

    WSLUA_RETURN(1); /* String of debug information. */
}
コード例 #9
0
ファイル: wslua_tvb.c プロジェクト: AndresVelasco/wireshark
WSLUA_METHOD TvbRange_strsize(lua_State* L) {
        /* Find the size of a zero terminated string from a TvbRange.  The size of the string includes the terminating zero. */
    TvbRange tvbr = checkTvbRange(L,1);

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

    lua_pushinteger(L, tvb_strsize(tvbr->tvb->ws_tvb, tvbr->offset));

    WSLUA_RETURN(1); /* Length of the zero terminated string */
}
コード例 #10
0
WSLUA_METAMETHOD Column__tostring(lua_State *L) {
    Column c = checkColumn(L,1);
    const gchar* name;

    if (!(c)) {
        return 0;
    }

    /* XXX: should return the column's text ! */
    name = col_id_to_name(c->col);
    lua_pushstring(L,name ? name : "Unknown Column");

    WSLUA_RETURN(1); /* A string representing the column */
}
コード例 #11
0
ファイル: wslua_dumper.c プロジェクト: DuLerWeil/wireshark
WSLUA_CONSTRUCTOR PseudoHeader_none(lua_State* L) {
    /*
     Creates a "no" pseudoheader.

    */
    PseudoHeader ph = (PseudoHeader)g_malloc(sizeof(struct lua_pseudo_header));
    ph->type = PHDR_NONE;
    ph->wph = NULL;

    pushPseudoHeader(L,ph);

    WSLUA_RETURN(1);
    /* A null pseudoheader */
}
コード例 #12
0
WSLUA_METHOD TvbRange_string(lua_State* L) {
	/* Obtain a string from a TvbRange */
    TvbRange tvbr = checkTvbRange(L,1);

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

    lua_pushstring(L, (gchar*)tvb_get_ephemeral_string(tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len) );

    WSLUA_RETURN(1); /* The string */
}
コード例 #13
0
ファイル: wslua_capture_info.c プロジェクト: Ekleog/wireshark
WSLUA_METAMETHOD CaptureInfoConst__tostring(lua_State* L) {
    /* Generates a string of debug info for the CaptureInfoConst */
    CaptureInfoConst fi = toCaptureInfoConst(L,1);

    if (!fi || !fi->wdh) {
        lua_pushstring(L,"CaptureInfoConst pointer is NULL!");
    } else {
        wtap_dumper *wdh = fi->wdh;
        lua_pushfstring(L, "CaptureInfoConst: file_type_subtype=%d, snaplen=%d, encap=%d, compressed=%d, file_tsprec='%s'",
            wdh->file_type_subtype, wdh->snaplen, wdh->encap, wdh->compressed, wdh->tsprecision);
    }

    WSLUA_RETURN(1); /* String of debug information. */
}
コード例 #14
0
ファイル: wslua_tvb.c プロジェクト: AndresVelasco/wireshark
WSLUA_METHOD TvbRange_stringz(lua_State* L) {
	/* Obtain a zero terminated string from a TvbRange */
    TvbRange tvbr = checkTvbRange(L,1);

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

    lua_pushstring(L, (gchar*)tvb_get_stringz(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,NULL) );

    WSLUA_RETURN(1); /* The zero terminated string */
}
コード例 #15
0
ファイル: wslua_tvb.c プロジェクト: jelmer/wireshark
WSLUA_METHOD Tvb_range(lua_State* L) {
	/* Creates a tvbr from this Tvb. This is used also as the Tvb:__call() metamethod. */
#define WSLUA_OPTARG_Tvb_range_OFFSET 2 /* The offset (in octets) from the beginning of the Tvb. Defaults to 0. */
#define WSLUA_OPTARG_Tvb_range_LENGTH 3 /* The length (in octets) of the range. Defaults to until the end of the Tvb. */

    Tvb tvb = checkTvb(L,1);
    int offset = luaL_optint(L,WSLUA_OPTARG_Tvb_range_OFFSET,0);
    int len = luaL_optint(L,WSLUA_OPTARG_Tvb_range_LENGTH,-1);

    if (push_TvbRange(L,tvb->ws_tvb,offset,len)) {
        WSLUA_RETURN(1); /* The TvbRange */
    }

    return 0;
}
コード例 #16
0
ファイル: wslua_tvb.c プロジェクト: AndresVelasco/wireshark
WSLUA_METHOD Tvb_reported_length_remaining(lua_State* L) {
	/* Obtain the reported length of packet data to end of a TVB or -1 if the offset is beyond the end of the TVB */
#define Tvb_reported_length_remaining_OFFSET 2 /* offset */
    Tvb tvb = checkTvb(L,1);
    int offset = luaL_optint(L, Tvb_reported_length_remaining_OFFSET, 0);

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

    lua_pushnumber(L,tvb_reported_length_remaining(tvb->ws_tvb, offset));
    WSLUA_RETURN(1); /* The length of the Tvb. */
}
コード例 #17
0
ファイル: wslua_tvb.c プロジェクト: DHODoS/wireshark
WSLUA_METHOD Tvb_range(lua_State* L) {
    /* Creates a `TvbRange` from this `Tvb`. */
#define WSLUA_OPTARG_Tvb_range_OFFSET 2 /* The offset (in octets) from the beginning of the `Tvb`. Defaults to 0. */
#define WSLUA_OPTARG_Tvb_range_LENGTH 3 /* The length (in octets) of the range. Defaults to until the end of the `Tvb`. */

    Tvb tvb = checkTvb(L,1);
    int offset = (int) luaL_optinteger(L,WSLUA_OPTARG_Tvb_range_OFFSET,0);
    int len = (int) luaL_optinteger(L,WSLUA_OPTARG_Tvb_range_LENGTH,-1);

    if (push_TvbRange(L,tvb->ws_tvb,offset,len)) {
        WSLUA_RETURN(1); /* The TvbRange */
    }

    return 0;
}
コード例 #18
0
WSLUA_CONSTRUCTOR NSTime_new(lua_State *L) {
	/* Creates a new NSTime object */
#define WSLUA_OPTARG_NSTime_new_SECONDS 1 /* Seconds */
#define WSLUA_OPTARG_NSTime_new_NSECONDS 2 /* Nano seconds */
    NSTime time = g_malloc(sizeof(nstime_t));

    if (!time) return 0;

    time->secs = (time_t) luaL_optint(L,WSLUA_OPTARG_NSTime_new_SECONDS,0);
    time->nsecs = luaL_optint(L,WSLUA_OPTARG_NSTime_new_NSECONDS,0);

    pushNSTime(L,time);

    WSLUA_RETURN(1); /* The new NSTime object. */
}
コード例 #19
0
ファイル: wslua_dumper.c プロジェクト: DuLerWeil/wireshark
WSLUA_CONSTRUCTOR PseudoHeader_mtp2(lua_State* L) {
    /* Creates an MTP2 PseudoHeader. */
#define WSLUA_OPTARG_PseudoHeader_mtp2_SENT 1 /* True if the packet is sent, False if received. */
#define WSLUA_OPTARG_PseudoHeader_mtp2_ANNEXA 2 /* True if annex A is used.  */
#define WSLUA_OPTARG_PseudoHeader_mtp2_LINKNUM 3 /* Link Number. */
    PseudoHeader ph = (PseudoHeader)g_malloc(sizeof(struct lua_pseudo_header));
    ph->type = PHDR_MTP2;
    ph->wph = (union wtap_pseudo_header *)g_malloc(sizeof(union wtap_pseudo_header));
    ph->wph->mtp2.sent = (guint8)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_mtp2_SENT,0);
    ph->wph->mtp2.annex_a_used = (guint8)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_mtp2_ANNEXA,0);
    ph->wph->mtp2.link_number = (guint16)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_mtp2_LINKNUM,0);

    pushPseudoHeader(L,ph);
    WSLUA_RETURN(1); /* The MTP2 pseudoheader */
}
コード例 #20
0
ファイル: wslua_pinfo.c プロジェクト: mACH1VO/wireshark
WSLUA_METAMETHOD Column__tostring(lua_State *L) {
    Column c = checkColumn(L,1);
    const gchar* text;

    if (!c->cinfo) {
        text = col_id_to_name(c->col);
        lua_pushfstring(L, "(%s)", text ? text : "unknown");
    }
    else {
        text = col_get_text(c->cinfo, c->col);
        lua_pushstring(L, text ? text : "(nil)");
    }

    WSLUA_RETURN(1); /* The column's string text (in parenthesis if not available). */
}
コード例 #21
0
WSLUA_METHOD TextWindow_get_text(lua_State* L) { /* Get the text of the window */
    TextWindow tw = checkTextWindow(L,1);
	const gchar* text;

	if (!tw)
		WSLUA_ERROR(TextWindow_get_text,"Cannot be called for something not a TextWindow");

    if (tw->expired)
		WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow");

	text = ops->get_text(tw->ws_tw);

    lua_pushstring(L,text);
	WSLUA_RETURN(1); /* The TextWindow's text. */
}
コード例 #22
0
ファイル: wslua_tvb.c プロジェクト: jelmer/wireshark
WSLUA_METAMETHOD ByteArray__concat(lua_State* L) {
	/* Concatenate two ByteArrays */
#define WSLUA_ARG_ByteArray__cat_FIRST 1 /* First array */
#define WSLUA_ARG_ByteArray__cat_SECOND 2 /* Second array */

    ByteArray ba1 = checkByteArray(L,WSLUA_ARG_ByteArray__cat_FIRST);
    ByteArray ba2 = checkByteArray(L,WSLUA_ARG_ByteArray__cat_SECOND);
    ByteArray ba;

    ba = g_byte_array_new();
    g_byte_array_append(ba,ba1->data,ba1->len);
    g_byte_array_append(ba,ba2->data,ba2->len);

    pushByteArray(L,ba);
    WSLUA_RETURN(1); /* The new composite ByteArray. */
}
コード例 #23
0
WSLUA_METAMETHOD ByteArray__concat(lua_State* L) {
	/* Concatenate two ByteArrays */
#define WSLUA_ARG_ByteArray__cat_FIRST 1 /* First array */
#define WSLUA_ARG_ByteArray__cat_SECOND 2 /* Second array */

    ByteArray ba = checkByteArray(L,WSLUA_ARG_ByteArray__cat_FIRST);
    ByteArray ba2 = checkByteArray(L,WSLUA_ARG_ByteArray__cat_SECOND);

    if (! (ba  && ba2) )
        WSLUA_ERROR(ByteArray__cat,"Both arguments must be ByteArrays");

    g_byte_array_append(ba,ba2->data,ba2->len);

    pushByteArray(L,ba);
    WSLUA_RETURN(1); /* The new composite ByteArray. */
}
コード例 #24
0
ファイル: wslua_dumper.c プロジェクト: DuLerWeil/wireshark
WSLUA_CONSTRUCTOR PseudoHeader_eth(lua_State* L) {
    /*
     Creates an ethernet pseudoheader.
     */

#define WSLUA_OPTARG_PseudoHeader_eth_FCSLEN 1 /* The fcs length */

    PseudoHeader ph = (PseudoHeader)g_malloc(sizeof(struct lua_pseudo_header));
    ph->type = PHDR_ETH;
    ph->wph = (union wtap_pseudo_header *)g_malloc(sizeof(union wtap_pseudo_header));
    ph->wph->eth.fcs_len = (gint)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_eth_FCSLEN,-1);

    pushPseudoHeader(L,ph);

    WSLUA_RETURN(1); /* The ethernet pseudoheader */
}
コード例 #25
0
ファイル: wslua_tvb.c プロジェクト: jelmer/wireshark
WSLUA_METHOD TvbRange_string(lua_State* L) {
	/* Obtain a string from a TvbRange */
#define WSLUA_OPTARG_TvbRange_string_ENCODING 2 /* The encoding to use. Defaults to ENC_ASCII. */
    TvbRange tvbr = checkTvbRange(L,1);
    guint encoding = (guint)luaL_optint(L,WSLUA_OPTARG_TvbRange_string_ENCODING, ENC_ASCII|ENC_NA);

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

    lua_pushlstring(L, (gchar*)tvb_get_string_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,encoding), tvbr->len);

    WSLUA_RETURN(1); /* The string */
}
コード例 #26
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 */
}
コード例 #27
0
WSLUA_CONSTRUCTOR ProgDlg_new(lua_State* L) { /* Creates a new TextWindow. */
#define WSLUA_OPTARG_ProgDlg_new_TITLE 2 /* Title of the new window, defaults to "Progress". */
#define WSLUA_OPTARG_ProgDlg_new_TASK 3  /* Current task, defaults to "". */
    ProgDlg pd = g_malloc(sizeof(struct _wslua_progdlg));
    pd->title = g_strdup(luaL_optstring(L,WSLUA_OPTARG_ProgDlg_new_TITLE,"Progress"));
    pd->task = g_strdup(luaL_optstring(L,WSLUA_OPTARG_ProgDlg_new_TASK,""));
    pd->stopped = FALSE;

    if (ops->new_progress_window) {
        pd->pw = ops->new_progress_window(pd->title,pd->task,TRUE,&(pd->stopped));
    }

    pushProgDlg(L,pd);

	WSLUA_RETURN(1); /* The newly created TextWindow object. */
}
コード例 #28
0
ファイル: wslua_tvb.c プロジェクト: jelmer/wireshark
WSLUA_METHOD ByteArray_tohex(lua_State* L) {
    /* Obtain a Lua string of the bytes in a ByteArray as hex-ascii, with given separator */
#define WSLUA_OPTARG_ByteArray_tohex_LOWERCASE 2 /* True to use lower-case hex characters (default=false). */
#define WSLUA_OPTARG_ByteArray_tohex_SEPARATOR 3 /* A string separator to insert between hex bytes (default=nil). */
    ByteArray ba = checkByteArray(L,1);
    gboolean lowercase = FALSE;
    const gchar* sep = NULL;

    if (!ba) return 0;

    lowercase = wslua_optbool(L,WSLUA_OPTARG_ByteArray_tohex_LOWERCASE,FALSE);
    sep = luaL_optstring(L,WSLUA_OPTARG_ByteArray_tohex_SEPARATOR,NULL);

    wslua_bin2hex(L, ba->data, ba->len, lowercase, sep);

    WSLUA_RETURN(1); /* A hex-ascii string representation of the ByteArray. */
}
コード例 #29
0
ファイル: wslua_tvb.c プロジェクト: AndresVelasco/wireshark
/*
 * get a Lilliputian float
 */
WSLUA_METHOD TvbRange_le_float(lua_State* L) {
	/* Get a Little Endian floating point number from a TvbRange. The range must be 4 or 8 octets long. */
    TvbRange tvbr = checkTvbRange(L,1);
    if (!(tvbr && tvbr->tvb)) return 0;

    switch (tvbr->len) {
        case 4:
            lua_pushnumber(L,tvb_get_letohieee_float(tvbr->tvb->ws_tvb,tvbr->offset));
            return 1;
        case 8:
            lua_pushnumber(L,tvb_get_letohieee_double(tvbr->tvb->ws_tvb,tvbr->offset));
            WSLUA_RETURN(1); /* The floating point value */
        default:
            luaL_error(L,"TvbRange:le_float() does not handle %d byte floating numbers",tvbr->len);
            return 0;
    }
}
コード例 #30
0
ファイル: wslua_tvb.c プロジェクト: AndresVelasco/wireshark
WSLUA_METAMETHOD Tvb__tostring(lua_State* L) {
	/* Convert the bytes of a Tvb into a string, to be used for debugging purposes as '...' will be appended in case the string is too long. */
    Tvb tvb = checkTvb(L,1);
    int len;
    gchar* str;

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

    len = tvb_length(tvb->ws_tvb);
    str = ep_strdup_printf("TVB(%i) : %s",len,tvb_bytes_to_str(tvb->ws_tvb,0,len));
    lua_pushstring(L,str);
    WSLUA_RETURN(1); /* The string. */
}