M
Matthew
Hello, I've come upon a weird problem here and haven't been able to
find much help; if anyone here can give me a hand it would be much
appreciated. I'm trying to parse a struct read from a file as is would
appear in text:
e.g.:
struct myStruct {
int a;
DWORD b;
BYTE c[4];
struct SomeOtherStruct;
};
After I parse the struct I want to create a mirrored struct in memory.
Ideally if I parse the "int a;" I would dynamically allocate memory to
an int and have it be the first 4 bytes of a struct I would create in
memory. My question is this: What is the most effective way to
automatically create the data type parsed from the struct? What I have
so far is a union:
Code:
union dataTypes {
BYTE data[8];
bool bType;
unsigned int uiType;
int iType;
BYTE byType;
CHAR cType;;
WORD wType;
short sType;
DWORD dwType;
long lType;
float fType;
double dType;
};
I then do a ReadProcessMemory on whatever data I need and put it in
the data dataTypes::array (8 being the most bytes I would need to read
). What I can then do is have a long if/else chain that stricmps the
data type it parses (say it's a "DWORD") and once it figures that out
it'll do a ultoa(dataTypes.dwType,szLine,16); and return that string
to get the data. However, I find this very ineffective. These stricmp
chains are rediculous, and I can't possibly counter for every
typedef'd unsigned this or pointer that. So I ask, is there another
way? I know this might not be explained very well, but it was the best
I could of. Aut any help would be appreciated
find much help; if anyone here can give me a hand it would be much
appreciated. I'm trying to parse a struct read from a file as is would
appear in text:
e.g.:
struct myStruct {
int a;
DWORD b;
BYTE c[4];
struct SomeOtherStruct;
};
After I parse the struct I want to create a mirrored struct in memory.
Ideally if I parse the "int a;" I would dynamically allocate memory to
an int and have it be the first 4 bytes of a struct I would create in
memory. My question is this: What is the most effective way to
automatically create the data type parsed from the struct? What I have
so far is a union:
Code:
union dataTypes {
BYTE data[8];
bool bType;
unsigned int uiType;
int iType;
BYTE byType;
CHAR cType;;
WORD wType;
short sType;
DWORD dwType;
long lType;
float fType;
double dType;
};
I then do a ReadProcessMemory on whatever data I need and put it in
the data dataTypes::array (8 being the most bytes I would need to read
). What I can then do is have a long if/else chain that stricmps the
data type it parses (say it's a "DWORD") and once it figures that out
it'll do a ultoa(dataTypes.dwType,szLine,16); and return that string
to get the data. However, I find this very ineffective. These stricmp
chains are rediculous, and I can't possibly counter for every
typedef'd unsigned this or pointer that. So I ask, is there another
way? I know this might not be explained very well, but it was the best
I could of. Aut any help would be appreciated