Hackers of India

ParseAndC: A Universal Parser and Data Visualization Tool for Security Testing

 Parbati Kumar Manna 

2021/08/04

Abstract

Parsing is the process of extracting the data values of various fields by mapping the data format (known) onto the datastream (known) from a certain offset (known). While it is trivial to write a parser that will output the values corresponding to the fields of a single C structure, that parser becomes useless if now we have to deal with a different C structure. A parser that can handle any and all C structures as its input is essentially a compiler, since even C header files contain enough complexity (#define constants, macros calling macros, variadic macros, conditional code via #if-#else etc., included files, attributes, padding, bitfield, complex variable declarations etc.). This tool is capable of mapping any C structure(s) to any datastream, and then visually displaying the 1:1 correspondence between the variables and the data in a very colorful, intuitive display so that it becomes very easy to understand which field has what value.

This tool is extremely portable – it is a single Python text file of size less than 1MB, supports all versions of Python, is cross-platform (Windows/Mac/Unix), and also works in the terminal /batch mode without GUI. For multi-byte datatypes (e.g. integer or float) it supports both endianness (little/big) and displays value in both decimal and Hex formats. The tool needs no internet connection and is self-contained - it doesn’t import almost anything, to the extent that it implements its own C compiler (front-end) from scratch!!

This tool is useful for both security- and non-security testing alike (reverse engineering, network traffic analyzing, packet processing etc.). It is currently being used at Intel, and in the users’ own words, this tool has reduced their days’ work into minutes. The author of this tool led many security hackathons at Intel and there this tool was found to be very useful.