-
Notifications
You must be signed in to change notification settings - Fork 11
Add support of Export objects, conv and endpoint taps. #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@dehydr8 for some reasons I cannot assign reviewers, so pinging you here. |
|
Hi @polesye, I have reviewed the code, thank you for taking the time to contribute it. There is a way to make the different types in a vector work in emscripten. If you want to give it a go, we can leverage polymorphism. This is what the changes might look like: // base struct
struct TapValue {
string tap;
string type;
string proto;
virtual ~TapValue() = default;
}
// derived structs
struct TapConvResponse: TapValue {
bool geoip;
vector<Conversation> convs;
vector<Host> hosts;
};
struct ExportObjectTap: TapValue {
vector<ExportObject> objects;
};
// response struct
struct TapResponse {
vector<shared_ptr<TapValue>> taps;
string error;
};
// pushing to the vector
buf.taps.push_back(make_shared<TapConvResponse>(conv))
buf.taps.push_back(make_shared<ExportObjectTap>(eo))
// bindings
EMSCRIPTEN_BINDINGS(TapValue) {
class_<TapValue>("TapValue")
.smart_ptr<shared_ptr<TapValue>>("TapValue")
.property("tap", &TapValue::tap)
.property("type", &TapValue::type)
.property("proto", &TapValue::proto);
}
EMSCRIPTEN_BINDINGS(TapConvResponse) {
class_<TapConvResponse, base<TapValue>>("TapConvResponse")
.property("geoip", &TapConvResponse::geoip)
.property("convs", &TapConvResponse::convs)
.property("hosts", &TapConvResponse::hosts);
}
EMSCRIPTEN_BINDINGS(ExportObjectTap) {
class_<ExportObjectTap, base<TapValue>>("ExportObjectTap")
.property("objects", &ExportObjectTap::objects);
}
EMSCRIPTEN_BINDINGS(TapResponse) {
class_<TapResponse>("TapResponse")
.property("taps", &TapResponse::taps)
.property("error", &TapResponse::error);
register_vector<shared_ptr<TapValue>>("VectorTapValue");
} for (let i = 0; i < response.taps.size(); i++) {
let tap = response.taps.get(i);
console.log("Tap:", tap.tap, "Type:", tap.type, "Proto:", tap.proto);
if (tap instanceof Module.TapConvResponse) {
console.log("GeoIP:", tap.geoip);
console.log("Convs:", tap.convs);
console.log("Hosts:", tap.hosts);
} else if (tap instanceof Module.ExportObjectTap) {
console.log("Objects:", tap.objects);
}
}This would ensure proper RTTI in JS. We would be able to check Let me know if this is something you would like to do. |
|
@dehydr8 let me try it. |
|
@dehydr8 your solution seems to be working well. The only inconvenience is that we have to manully destroy shared_ptr instances (See e5dff43#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R156). It raises warnign message otherwise. |
|
@polesye this looks really good!
This is expected. Since we explicitly pass on the pointers, we're responsible for memory management. Let me know if you're happy with the changes and I'll merge them. |
|
@dehydr8 yes, this solution is much better. Thanks. |
|
🎉 This PR is included in version 1.7.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |

This PR extends api with
tapanddownloadendpoints that allows us to use export object functionality (see attached screenshot), conversations and endpoint stat.Concerns: the tap endpoint returns different response type based on the passed tap type. I haven't found a better solution to properly bind it in emsc except adding
nlohmann/jsonto the project (is it a good approach to add it that way?) and stringifying each tap result. Hence, js shoud iterate over each tap item and useJSON.parse(See https://github.com/DARTSG/wiregasm/blob/50e9163c0ce00b6ffec3340c3427ad2a9041ccfe/src/index.ts#L118).