Working version
parent
3d5938c053
commit
5f595c8fbd
|
@ -1,4 +1,4 @@
|
|||
build/
|
||||
CMakeLists.txt.user
|
||||
.directory
|
||||
*.autosave
|
||||
build
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(MCPC_dissect)
|
||||
|
||||
set(CMAKE_BUILD_TYPE DEBUG)
|
||||
#RelWithDebInfo)
|
||||
add_definitions("-DHAVE_CONFIG_H")
|
||||
add_library(MCPC_dissect SHARED "mcpc.c" "VarUtils.c" "VarUtils.h")
|
||||
include_directories("/usr/include/glib-2.0" "/usr/lib/glib-2.0/include" "/usr/include/wireshark")
|
||||
|
||||
add_library(MCPC_dissect SHARED "mcpc.c")
|
||||
|
|
21
LICENSE
21
LICENSE
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2018 Igor Yourasov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
11
VarUtils.c
11
VarUtils.c
|
@ -1,11 +0,0 @@
|
|||
#include <stdint.h>
|
||||
uint8_t VarIntToInt(char *loc, int32_t *to){
|
||||
static uint8_t ind;
|
||||
ind=0;
|
||||
do{
|
||||
*to |= (loc[ind]&0x7F) << (ind*7);
|
||||
if(ind>5)
|
||||
break;
|
||||
}while((loc[ind++]&0x80) != 0);
|
||||
return ind;
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
#include <stdint.h>
|
||||
uint8_t VarIntToInt(char *loc, int32_t *to);
|
157
mcpc.c
157
mcpc.c
|
@ -9,54 +9,150 @@
|
|||
#include <epan/packet.h>
|
||||
#include <epan/column-info.h>
|
||||
#include <epan/dissectors/packet-tcp.h>
|
||||
#include <ws_version.h>
|
||||
|
||||
#ifndef ENABLE_STATIC
|
||||
WS_DLL_PUBLIC_DEF const gchar plugin_version[] = "0.0.1-pre-b6";
|
||||
WS_DLL_PUBLIC_DEF const gchar plugin_release[] = "2.6"; //VERSION_RELEASE
|
||||
WS_DLL_PUBLIC_DEF const gchar plugin_version[] = "0.0.2-pre-b1";
|
||||
WS_DLL_PUBLIC_DEF const gchar plugin_release[] = "3.2"; //VERSION_RELEASE
|
||||
WS_DLL_PUBLIC_DEF const int plugin_want_major = WIRESHARK_VERSION_MAJOR;
|
||||
WS_DLL_PUBLIC_DEF const int plugin_want_minor = WIRESHARK_VERSION_MINOR;
|
||||
#endif
|
||||
|
||||
#define PROTO_PORT 25565
|
||||
#define PROTO_TAG "MCPC"
|
||||
#define PROTO_TAG_PARTIAL "MCPC partial"
|
||||
|
||||
#include "VarUtils.h"
|
||||
//#include "VarUtils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static int proto_mcpc=-1;
|
||||
static dissector_handle_t mcpc_handle;
|
||||
|
||||
struct delicious{
|
||||
size_t flat;
|
||||
char *chest;
|
||||
};
|
||||
|
||||
// "_U_" not using
|
||||
static int dissect_mcpc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *data _U_){
|
||||
col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTO_TAG);
|
||||
static int32_t u=0;
|
||||
static uint8_t l;
|
||||
static guint plen=tvb_reported_length(tvb);
|
||||
|
||||
l=VarIntToInt(tvb_get_ptr(tvb, pinfo->desegment_offset, plen), &u);
|
||||
|
||||
if(u>pinfo->fd->pkt_len){
|
||||
u=0;
|
||||
static const char *gb;
|
||||
gb=tvb_get_ptr(tvb, pinfo->desegment_offset, plen);
|
||||
l=VarIntToInt(gb, &u);
|
||||
int8_t VarIntToUint(const guint8 *varint, uint32_t *result, uint_fast8_t maxlen){
|
||||
int8_t i=0;
|
||||
*result=0;
|
||||
do{
|
||||
if(i>5)
|
||||
break;
|
||||
*result |= (varint[i]&0x7F) << (i*7);
|
||||
if(i>maxlen)
|
||||
return -1;
|
||||
}while((varint[i++]&0x80) != 0);
|
||||
return i;
|
||||
}
|
||||
static char buf[32];
|
||||
if(l>5)
|
||||
col_set_str(pinfo->cinfo, COL_INFO, "VarInt parse error");
|
||||
else{
|
||||
|
||||
static guint getlen(packet_info *pinfo, tvbuff_t *tvb, int offset _U_, void *data _U_){
|
||||
int8_t ret;
|
||||
uint32_t len;
|
||||
guint8 packet_length;
|
||||
packet_length=tvb_reported_length(tvb);//To read
|
||||
if(packet_length==0)
|
||||
return 0;
|
||||
// return tvb_captured_length(tvb);
|
||||
|
||||
const guint8 *dt;
|
||||
dt=tvb_get_ptr(tvb, pinfo->desegment_offset, packet_length);
|
||||
ret=VarIntToUint(dt, &len, packet_length);
|
||||
if(ret==-1)
|
||||
return 0;
|
||||
else if(ret==0){
|
||||
return 1;
|
||||
}else
|
||||
return len+ret;
|
||||
}
|
||||
|
||||
static int subdissect_mcpc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *data _U_){
|
||||
col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTO_TAG);//Set MCPC protocol tag
|
||||
|
||||
uint32_t protocol_length, varint;
|
||||
guint8 packet_length, readed;
|
||||
int8_t varlen;
|
||||
const guint8 *dt;
|
||||
|
||||
packet_length=tvb_reported_length(tvb);//To read
|
||||
|
||||
dt=tvb_get_ptr(tvb, pinfo->desegment_offset, packet_length);
|
||||
|
||||
readed=VarIntToUint(dt, &protocol_length, packet_length);
|
||||
if(readed<0)
|
||||
return -1;
|
||||
else if(packet_length<protocol_length)
|
||||
return packet_length-protocol_length;
|
||||
|
||||
if(protocol_length<=pinfo->fd->pkt_len){
|
||||
varlen=VarIntToUint(dt+readed, &varint, packet_length-readed);
|
||||
if(varlen>0)
|
||||
readed+=varlen;
|
||||
else
|
||||
return -1;
|
||||
if(varlen>5)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char buf[32];
|
||||
// if(u>10000)
|
||||
// __asm("int $3");
|
||||
sprintf(buf, "Len: %u", u);
|
||||
if(pinfo->destport==25565)
|
||||
sprintf(buf, "Result: [C->S] %u bytes, 0x%X", packet_length, varint);
|
||||
else
|
||||
sprintf(buf, "Result: [S->C] %u bytes, 0x%X"/*Length: %u*/, packet_length, varint);
|
||||
col_set_str(pinfo->cinfo, COL_INFO, buf);
|
||||
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
return tvb_captured_length(tvb);
|
||||
static int dissect_mcpc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data){
|
||||
tcp_dissect_pdus(tvb, pinfo, tree, TRUE, 0,
|
||||
getlen, subdissect_mcpc, data);
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
/*static int dissect_mcpc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *data _U_){
|
||||
col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTO_TAG);//Set MCPC protocol tag
|
||||
|
||||
static dissector_handle_t mcpc_handle;
|
||||
uint32_t protocol_length, varint;
|
||||
guint8 packet_length, readed;
|
||||
int8_t varlen;
|
||||
|
||||
packet_length=tvb_reported_length(tvb);//To read
|
||||
if(packet_length==0)
|
||||
return tvb_captured_length(tvb);
|
||||
|
||||
const guint8 *dt;
|
||||
dt=tvb_get_ptr(tvb, pinfo->desegment_offset, packet_length);
|
||||
|
||||
readed=VarIntToUint(dt, &protocol_length, packet_length);
|
||||
if(readed<0)
|
||||
return -1;
|
||||
else if(packet_length<protocol_length)
|
||||
return packet_length-protocol_length;
|
||||
|
||||
if(protocol_length<=pinfo->fd->pkt_len){
|
||||
varlen=VarIntToUint(dt, &varint, packet_length-readed);
|
||||
if(varlen>0)
|
||||
readed+=varlen;
|
||||
else
|
||||
return -1;
|
||||
if(varlen>5)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char buf[32];
|
||||
if(varlen>5)
|
||||
col_set_str(pinfo->cinfo, COL_INFO, "varint parse error");
|
||||
else{
|
||||
// if(u>10000)
|
||||
// __asm("int $3");
|
||||
if(pinfo->destport==25565)
|
||||
sprintf(buf, "[C->S] Length: %u", packet_length);
|
||||
else
|
||||
sprintf(buf, "[S->C] Length: %u", packet_length);
|
||||
col_set_str(pinfo->cinfo, COL_INFO, buf);
|
||||
}
|
||||
return tvb_captured_length(tvb);
|
||||
}*/
|
||||
|
||||
|
||||
//Protocol register functions
|
||||
static void proto_reg_handoff_mcpc(void)
|
||||
{
|
||||
mcpc_handle = create_dissector_handle(dissect_mcpc, proto_mcpc);
|
||||
|
@ -68,6 +164,9 @@ static void proto_register_mcpc(){
|
|||
"Minecraft",
|
||||
"mcpc");
|
||||
}
|
||||
|
||||
|
||||
//Plugin register function
|
||||
#ifndef ENABLE_STATIC
|
||||
//#if 0
|
||||
WS_DLL_PUBLIC void plugin_register(){
|
||||
|
|
Loading…
Reference in New Issue