Skip to content

Commit

Permalink
Initial modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Egli committed Apr 4, 2022
1 parent 879be79 commit 19689f4
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
74 changes: 74 additions & 0 deletions include/klee/customIncludes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "stdbool.h"

struct tvbuff;

typedef struct tvbuff tvbuff_t;

struct tvbuff {
/* Doubly linked list pointers */
tvbuff_t *next;

/* Record-keeping */
//const struct tvb_ops *ops;

bool initialized;
unsigned int flags;
struct tvbuff *ds_tvb; /**< data source top-level tvbuff */

/** Pointer to the data for this tvbuff.
* It might be null, which either means that 1) it's a
* zero-length tvbuff or 2) the tvbuff was lazily
* constructed, so that we don't allocate a buffer of
* backing data and fill it in unless we need that
* data, e.g. when tvb_get_ptr() is called.
*/
const unsigned char *real_data;

/** Amount of data that's available from the capture
* file. This is the length of virtual buffer (and/or
* real_data). It may be less than the reported
* length if this is from a packet that was cut short
* by the capture process.
*
* This must never be > reported_length or contained_length. */
unsigned int length;

/** Amount of data that was reported as being in
* the packet or other data that this represents.
* As indicated above, it may be greater than the
* amount of data that's available. */
unsigned int reported_length;

/** If this was extracted from a parent tvbuff,
* this is the amount of extracted data that
* was reported as being in the parent tvbuff;
* if this represents a blob of data in that
* tvbuff that has a length specified by data
* in that tvbuff, it might be greater than
* the amount of data that was actually there
* to extract, so it could be greater than
* reported_length.
*
* If this wasn't extracted from a parent tvbuff,
* this is the same as reported_length.
*
* This must never be > reported_length. */
unsigned int contained_length;

/* Offset from beginning of first "real" tvbuff. */
int raw_offset;
};

typedef struct _proto_node {
struct _proto_node *first_child;
struct _proto_node *last_child;
struct _proto_node *next;
struct _proto_node *parent;
//field_info *finfo;
//tree_data_t *tree_data;
} proto_node;

/** A protocol tree element. */
typedef proto_node proto_tree;
/** A protocol item element. */
typedef proto_node proto_item;
10 changes: 10 additions & 0 deletions include/klee/klee.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@
#include "stdint.h"
#include "stddef.h"

#include "customIncludes.h"

#ifdef __cplusplus
extern "C" {
#endif


/* ! ! This is a custom function ! !
*
*
*
*/
void proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb, int start, int length, unsigned int encoding);

/* Add an accesible memory object at a user specified location. It
* is the users responsibility to make sure that these memory
* objects do not overlap. These memory objects will also
Expand Down
33 changes: 32 additions & 1 deletion lib/Core/SpecialFunctionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ static SpecialFunctionHandler::HandlerInfo handlerInfo[] = {
add("malloc", handleMalloc, true),
add("memalign", handleMemalign, true),
add("realloc", handleRealloc, true),


// Custom handler registering
/* Registering the handler, last paramter indicates if there is a return value or not */
add("proto_tree_add_item", handleProtoTreeAddItem, false),

#ifdef SUPPORT_KLEE_EH_CXX
add("_klee_eh_Unwind_RaiseException_impl", handleEhUnwindRaiseExceptionImpl, false),
Expand Down Expand Up @@ -578,10 +583,36 @@ void SpecialFunctionHandler::handleSetForking(ExecutionState &state,
}
}

/* Custom Handler for proto_tree_add_item function
*
*
*
*
*/
void SpecialFunctionHandler::handleProtoTreeAddItem(ExecutionState &state,
KInstruction *target,
std::vector<ref<Expr> > &arguments) {
llvm::errs() << "---------Handler--------" << "\n";
llvm::errs() << "Offset " << ": " << arguments[3] << "\n";

llvm::errs() << "Size is " << ": " << arguments[4] << "\n";
llvm::errs() << "Field type " << ": " << arguments[1] << "\n";
llvm::errs() << "------------------------" << "\n";

}

void SpecialFunctionHandler::handleStackTrace(ExecutionState &state,
KInstruction *target,
std::vector<ref<Expr> > &arguments) {
state.dumpStack(outs());

//state.dumpStack(outs());
llvm::errs() << "--------Dumping-constraints--------" << "\n";
std::vector<ref<Expr>>::iterator it;
for(auto it = state.constraints.begin(), ie = state.constraints.end(); it != ie; ++it){
it->get()->dump();

}
//printf("Constraints : %s\n",state.constraints.print());
}

void SpecialFunctionHandler::handleWarning(ExecutionState &state,
Expand Down
4 changes: 4 additions & 0 deletions lib/Core/SpecialFunctionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ namespace klee {
HANDLER(handleMulOverflow);
HANDLER(handleSubOverflow);
HANDLER(handleDivRemOverflow);

//Custom handlers
HANDLER(handleProtoTreeAddItem);

#undef HANDLER
};
} // End klee namespace
Expand Down

0 comments on commit 19689f4

Please sign in to comment.