Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   copying and repopulating a struct instance with pointers (http://www.go4expert.com/forums/copying-repopulating-struct-instance-t26902/)

ashwinkumar18 11Oct2011 00:51

copying and repopulating a struct instance with pointers
I am working on a tool in windows c++.
I have a c++ structure which has the following format


typedef struct node {
      int open;
      int version;
      const unsigned long long * data;
      char* flags;

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)

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.

All times are GMT +5.5. The time now is 22:56.