Home Hex Edit Home Page
Hex Edit Features Hex Edit Features
Button Testimonials
Button Screen Shots
Button Downloads
Button Forums Home
Button HexEdit FAQ
Button Known Bugs
about help privacy register
Forums
Search Members Help

» Welcome Guest
[ Log In :: Register ]

 

[ Track This Topic :: Email This Topic :: Print this topic ]

reply to topic new topic new poll
Topic: C/C++ source code parsing, Some tips on parsing C structs< Next Oldest | Next Newest >
 Post Number: 1
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 639
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: Feb. 08 2010,23:25   Ignore posts   QUOTE

HexEdit includes a C/C++ parser to assist you when making templates.  It is primarily designed for parsing of structs from C header files (though it is flexible enough to handle just about any C or C++ you throw at it).

I have had two "bug" reports that the parsing of C structs is producing no output.  The problem is that to get the correct results you have to understand how the C language (which the HexEdit parser closely follows) works, and carefully examine the code you are using.  I will give a few examples.

First it is important to remember that generally C header files are used to declare types (including structs) but it is is considered very bad style to declare variables of those type in header files.  A header file will often contain a type declaration like this:

CODE

struct a_
{
 int b;
};


When you paste this code into the HexEdit Parser dialog the parser will remember a type for "a_", but will not create any template STRUCT elements.  (Though you can save this type as a "STRUCT" in the "_custom_types.xml" for later use if you use the "Save Custom Types" checkbox.)

To actually obtain a variable of the type of the struct you need to define one like this:

CODE

struct a_   aa;


A simpler way is to just add a variable name at the end of the structure definition:

CODE

struct a_
{
 int b;
} aa;



Here is something that confuses many people.  The following looks like it is declaring a variable called "A" but in fact the preceding typedef turns this into a type named "A" (synonymous with "struct a_").  Hence nothing is added to the template here either.

CODE

typedef struct a_
{
 int b;
} A;


To use it you must declare a variable of type "A":

CODE

A  aa;



Here are two more examples to make it perfectly clear:

CODE

struct
{
 int b;
};


Nothing is produced here at all as there is no variable name and the structure is anonymous.  (There is not even a type remembered as the structure has no name.)

CODE

struct
{
 int b;
} aa;


Here a STRUCT (called "a") is created in the template (containing an integer DATA element called "b").  The structure is anonymous so no type is remembered.


--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
0 replies since Feb. 08 2010,23:25 < Next Oldest | Next Newest >

[ Track This Topic :: Email This Topic :: Print this topic ]


 
reply to topic new topic new poll

» Quick Reply C/C++ source code parsing
iB Code Buttons
You are posting as:

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code