Wednesday, 2 October 2013

Handling unknown structs imported from dll

Handling unknown structs imported from dll

I have tried to streamline this, but if you need more detail or code, let
me know.
First, some background: I am making a module for a program using exported
functions from a .dll to communicate with it. I do not have support from
the original developer, so I do not have access to the source code,
headers, .lib, or anything else. I used dependency walker to get a list of
function names, and explicitly linked using getProcAddress with success on
most functions. (Here is the solution I used to get this far.)
Now the problem I have run into is how to handle unknown structs. For
example, I have access to the following equations:
foo::bar::bar(void)
struct foo::bar magic(void)
foo::baz::baz(struct foo::bar const &)
int foo::baz::qux(void)
So the top function is a constructor that makes an object with the same
name as the struct. The second function is a magic function that outputs
the struct with all the data in it. The third function is another
constructor that makes a new object with that struct as an input. The
final function outputs an integer value (what I really care about) with
the object just created.
As you can see, I don't know, nor do I care what is in the struct. It just
gets magically created and immediately passed to another function that
deals with it. So here is how I attempted to handle it (look at the
solution linked in the first paragraph if this doesn't make sense):
struct barStruct {
void** unknown1[1024];
void** unknown2[1024];
void** unknown3[1024];
};
typedef barStruct (*_magic) (char *);
typedef void (*_bazConstructor) (char *, struct barStruct const &);
typedef int (*_qux) (char *);
I think I figured out how many elements there are in barStruct because
bazConstructor will crash if there are too many. The problem is, no matter
what I have tried, qux will crash. I am guessing this has something to do
with how I am handling barStruct. Is it necessary to define the struct
like this? Is there a way to pass it directly from magic to the
bazconstructor without trying to say what is in it?
Basically: How should I handle a struct if I have no idea what it is
supposed to contain?

No comments:

Post a Comment