Skip to content

Commit

Permalink
feat: adding support for Decode As
Browse files Browse the repository at this point in the history
  • Loading branch information
dehydr8 committed May 7, 2024
1 parent 427832c commit 3b17c67
Show file tree
Hide file tree
Showing 10 changed files with 712 additions and 10 deletions.
11 changes: 11 additions & 0 deletions lib/wiregasm/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ EMSCRIPTEN_BINDINGS(DissectSession)
.function("load", &DissectSession::load)
.function("getFrames", &DissectSession::getFrames)
.function("getFrame", &DissectSession::getFrame)
.function("getDecodeAs", &DissectSession::getDecodeAs)
.function("follow", &DissectSession::follow);
}

Expand Down Expand Up @@ -193,6 +194,15 @@ EMSCRIPTEN_BINDINGS(CompleteField)
.field("name", &CompleteField::name);
}

EMSCRIPTEN_BINDINGS(UIDecodeAsItem)
{
value_object<UIDecodeAsItem>("UIDecodeAsItem")
.field("field", &UIDecodeAsItem::field)
.field("value", &UIDecodeAsItem::value)
.field("default_dissector", &UIDecodeAsItem::default_dissector)
.field("current_dissector", &UIDecodeAsItem::current_dissector);
}

EMSCRIPTEN_BINDINGS(stl_wrappers)
{
register_vector<string>("VectorString");
Expand All @@ -204,6 +214,7 @@ EMSCRIPTEN_BINDINGS(stl_wrappers)
register_vector<PrefModule>("VectorPrefModule");
register_vector<PrefData>("VectorPrefData");
register_vector<PrefEnum>("VectorPrefEnum");
register_vector<UIDecodeAsItem>("VectorUIDecodeAsItem");
// Frame::follow is a vector of vectors of strings
register_vector<vector<string>>("VectorVectorString");
}
23 changes: 14 additions & 9 deletions lib/wiregasm/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ wg_dissect_request(capture_file *cfile, guint32 framenum, guint32 frame_ref_num,
wg_dissect_func_t cb, void *data,
int *err, gchar **err_info)
{
epan_dissect_t *old_edt = cfile->edt;
frame_data *fdata;
epan_dissect_t edt;
gboolean create_proto_tree;

fdata = wg_get_frame(cfile, framenum);
Expand All @@ -769,19 +769,21 @@ wg_dissect_request(capture_file *cfile, guint32 framenum, guint32 frame_ref_num,
return DISSECT_REQUEST_READ_ERROR; /* error reading the record */
}

cfile->edt = g_new0(epan_dissect_t, 1);

create_proto_tree = ((dissect_flags & WG_DISSECT_FLAG_PROTO_TREE) ||
((dissect_flags & WG_DISSECT_FLAG_COLOR) && color_filters_used()) ||
(cinfo && have_custom_cols(cinfo)));
epan_dissect_init(&edt, cfile->epan, create_proto_tree, (dissect_flags & WG_DISSECT_FLAG_PROTO_TREE));
epan_dissect_init(cfile->edt, cfile->epan, create_proto_tree, (dissect_flags & WG_DISSECT_FLAG_PROTO_TREE));

if (dissect_flags & WG_DISSECT_FLAG_COLOR)
{
color_filters_prime_edt(&edt);
color_filters_prime_edt(cfile->edt);
fdata->need_colorize = 1;
}

if (cinfo)
col_custom_prime_edt(&edt, cinfo);
col_custom_prime_edt(cfile->edt, cinfo);

/*
* XXX - need to catch an OutOfMemoryError exception and
Expand All @@ -790,22 +792,25 @@ wg_dissect_request(capture_file *cfile, guint32 framenum, guint32 frame_ref_num,
fdata->ref_time = (framenum == frame_ref_num);
fdata->frame_ref_num = frame_ref_num;
fdata->prev_dis_num = prev_dis_num;
epan_dissect_run(&edt, cfile->cd_t, rec,
epan_dissect_run(cfile->edt, cfile->cd_t, rec,
frame_tvbuff_new_buffer(&cfile->provider, fdata, buf),
fdata, cinfo);

if (cinfo)
{
/* "Stringify" non frame_data vals */
epan_dissect_fill_in_columns(&edt, FALSE, TRUE /* fill_fd_columns */);
epan_dissect_fill_in_columns(cfile->edt, FALSE, TRUE /* fill_fd_columns */);
}

cb(cfile, &edt, (dissect_flags & WG_DISSECT_FLAG_PROTO_TREE) ? edt.tree : NULL,
cinfo, (dissect_flags & WG_DISSECT_FLAG_BYTES) ? edt.pi.data_src : NULL,
cb(cfile, cfile->edt, (dissect_flags & WG_DISSECT_FLAG_PROTO_TREE) ? cfile->edt->tree : NULL,
cinfo, (dissect_flags & WG_DISSECT_FLAG_BYTES) ? cfile->edt->pi.data_src : NULL,
data);

wtap_rec_reset(rec);
epan_dissect_cleanup(&edt);

if (old_edt != NULL)
epan_dissect_free(old_edt);

return DISSECT_REQUEST_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions lib/wiregasm/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ link_args = [

sources = files([
'wiregasm.cpp',
'wg_decode_as.cpp',
'lib.cpp',
'bindings.cpp'
])
Expand Down
Loading

0 comments on commit 3b17c67

Please sign in to comment.