diff --git a/app/src/main/java/com/emanuelef/remote_capture/ConnDescriptor.java b/app/src/main/java/com/emanuelef/remote_capture/ConnDescriptor.java index abf07119..d9928867 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/ConnDescriptor.java +++ b/app/src/main/java/com/emanuelef/remote_capture/ConnDescriptor.java @@ -23,11 +23,13 @@ class ConnDescriptor implements Serializable { int uid; int incr_id; - /* Invoked by native code */ - public void setData(int _ipproto, String _src_ip, String _dst_ip, int _src_port, int _dst_port, - long _first_seen, long _last_seen, long _sent_bytes, long _rcvd_bytes, - int _sent_pkts, int _rcvd_pkts, String _info, String _l7proto, int _uid, - int _incr_id) { + /* Invoked by native code + * NOTE: interleaving String and int in the parameters is not good as it makes the app crash + * nto the emulator! Better to put the strings first. */ + public void setData(String _src_ip, String _dst_ip, String _info, String _l7proto, + int _ipproto, int _src_port, int _dst_port, long _first_seen, long _last_seen, + long _sent_bytes, long _rcvd_bytes, int _sent_pkts, int _rcvd_pkts, int _uid, + int _incr_id) { /* Metadata */ ipproto = _ipproto; src_ip = _src_ip; diff --git a/app/src/main/jni/vpnproxy-jni/vpnproxy.c b/app/src/main/jni/vpnproxy-jni/vpnproxy.c index 0bc435ff..cfe20dd3 100644 --- a/app/src/main/jni/vpnproxy-jni/vpnproxy.c +++ b/app/src/main/jni/vpnproxy-jni/vpnproxy.c @@ -413,17 +413,17 @@ static int handle_new_connection(zdtun_t *tun, const zdtun_conn_t *conn_info, vo } /* nDPI */ - if((data->ndpi_flow = ndpi_flow_malloc(SIZEOF_FLOW_STRUCT)) == NULL) { + if((data->ndpi_flow = calloc(1, SIZEOF_FLOW_STRUCT)) == NULL) { __android_log_print(ANDROID_LOG_ERROR, VPN_TAG, "ndpi_flow_malloc failed"); free_ndpi(data); } - if((data->src_id = ndpi_malloc(SIZEOF_ID_STRUCT)) == NULL) { + if((data->src_id = calloc(1, SIZEOF_ID_STRUCT)) == NULL) { __android_log_print(ANDROID_LOG_ERROR, VPN_TAG, "ndpi_malloc(src_id) failed"); free_ndpi(data); } - if((data->dst_id = ndpi_malloc(SIZEOF_ID_STRUCT)) == NULL) { + if((data->dst_id = calloc(1, SIZEOF_ID_STRUCT)) == NULL) { __android_log_print(ANDROID_LOG_ERROR, VPN_TAG, "ndpi_malloc(dst_id) failed"); free_ndpi(data); } @@ -609,19 +609,13 @@ static int connection_dumper(zdtun_t *tun, const zdtun_conn_t *conn_info, void * jobject dst_string = (*env)->NewStringUTF(env, dstip); jobject conn_descriptor = (*env)->NewObject(env, dump_data->conn_cls, dump_data->conn_constructor); - if(!conn_descriptor) { - __android_log_print(ANDROID_LOG_ERROR, VPN_TAG, "ConnDescriptor constructor failed"); - - /* Abort */ - return(1); - } - /* NOTE: as an alternative to pass all the params into the constructor, GetFieldID and * SetIntField like methods could be used. */ (*env)->CallVoidMethod(env, conn_descriptor, dump_data->conn_set_data, - conn_info->ipproto, src_string, dst_string, ntohs(conn_info->src_port), ntohs(conn_info->dst_port), + src_string, dst_string, info_string, proto_string, + conn_info->ipproto, ntohs(conn_info->src_port), ntohs(conn_info->dst_port), data->first_seen, data->last_seen, data->sent_bytes, data->rcvd_bytes, - data->sent_pkts, data->rcvd_pkts, info_string, proto_string, data->uid, data->incr_id); + data->sent_pkts, data->rcvd_pkts, data->uid, data->incr_id); /* Add the connection to the array */ (*env)->SetObjectArrayElement(env, dump_data->connections, dump_data->idx++, conn_descriptor); @@ -659,7 +653,8 @@ static void sendConnectionsDump(zdtun_t *tun, vpnproxy_data_t *proxy) { /* NOTE: must match ConnDescriptor::setData */ dump_data.conn_set_data = (*env)->GetMethodID(env, dump_data.conn_cls, "setData", - "(ILjava/lang/String;Ljava/lang/String;IIJJJJIILjava/lang/String;Ljava/lang/String;II)V"); + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIJJJJIIII)V"); + if(dump_data.conn_set_data == NULL) { __android_log_print(ANDROID_LOG_ERROR, VPN_TAG, "GetMethodID(conn_set_data) failed"); return; @@ -676,8 +671,6 @@ static void sendConnectionsDump(zdtun_t *tun, vpnproxy_data_t *proxy) { /* Send the dump */ (*env)->CallVoidMethod(env, proxy->vpn_service, midMethod, dump_data.connections); - - (*env)->DeleteLocalRef(env, dump_data.connections); } /* ******************************************************* */