I am working on an emulation tool in windows.
On intercepting an application I landed up with a situation.
I have a c++ structure which has the following format
typedef struct node {
int open;
int version;
const unsigned long long * data;
char* flags;
} _node;
It is a handle to a binary file. I am doing API interception and I get this pointer from an internal API call being made by the application.
Also The data field in the structure above is a pointer to instances of two structures laid out contiguously. The two structures are as follows.
typedef struct header{
unsigned int open;
unsigned int version;
unsigned long long int length;
} _header;
typedef struct body{
unsigned int v1, v2, v3, v4, v5, v6, v7, v8, v9, v10;
unsigned long long int ll1, ll2;
} _body;
I am able to access and print the data field as follows.
_node* First=(node *)address;//Address is a pointer that i get from intercepting an application
_header* nodeHeader=(_header*)First->data;
char *bodyPtr=(char *)(nodeHeader+1);
_body* nodeBody=(_body *)(bodyPtr);
unsigned long long int offset=0;
while(!(nodeBody->v1 & 1) && offset< nodeHeader->length)
{
nodeBody=(_body*)(bodyPtr+offset);
offset=nodeBody->v2+nodeBody->v3;
}
I want to write the struct node instance into a text file and be able to read it back into a struct instance later. What is the best way to do it? I want an answer in c++
I want a c++ code because the code I am working on is in c++. The code i posted here has typedef because people who wrote the structure has written it in C.
If it would help, I need this data in the structure so I could emulate an application with my tool.Since some aspects of the structure are internal and are hidden from me, my best bet is to store the structure members and reconstruct it at a later time (emulation time)