Valhalla Legends Forums Archive | Battle.net Bot Development | [C++] getExeInfo

AuthorMessageTime
Okee
I'm using BNCSutil's getExeInfo function to retrive the values for 0x51. My code is as follows...

[code]
                unsigned long EXEVersion;
unsigned int *Version;
char EXEInfo[300];
EXEVersion = getExeInfo(szLocalAccountInfo.EXE, EXEInfo, 256, Version, 0x1);

if(!EXEVersion) {
Disconnect(sckBNET);
AppendText(hBNChat, RED, "Check file location at %s\n", szLocalAccountInfo.EXE);
}
[/code]

The getExeInfo function is making my program crash when it tries to get the info of any game exe file. Whenever I give it a random exe file not related to SC/BW/D2 etc, it displays the version check failed, and the check location @ message.

Anyone know why it might be crashing?

Edit: EXE contains the full path to the exe file.
July 7, 2005, 7:07 PM
Myndfyr
Okay, so now we know that this guy has isolated it to being the getExeInfo function of the BNCSUtil.  We can now ask him...

Did you call kd_init() yet?
July 7, 2005, 10:06 PM
warz
I don't think it's necessary to call kd_init untill youre ready to begin doing the cd key decoding.
July 7, 2005, 11:27 PM
Okee
Yeah I call kd_init() prior to everything in this function. It's the first thing I do.
July 7, 2005, 11:28 PM
Kp
At the risk of stating the obvious, how about posting the line number at which it crashes?  There's several ways to get this.  The easiest would probably be to build BNCSutil + your program with symbols (-g2 or -g3), then run it, and open the resulting core dump in gdb.  Run "bt" at the gdb prompt and post the results.
July 8, 2005, 12:44 AM
shadypalm88
[code]unsigned long EXEVersion;
unsigned int *Version;
char EXEInfo[300];
EXEVersion = getExeInfo(szLocalAccountInfo.EXE, EXEInfo, 256, Version, 0x1);[/code]

Should read:
[code]unsigned long EXEVersion;
unsigned int Version;
char EXEInfo[300];
EXEVersion = getExeInfo(szLocalAccountInfo.EXE, EXEInfo, 256, &Version, 0x1);[/code]

(The declaration for getExeInfo is:)
[code]/**
* Retrieves version and date/size information from executable file.
* Returns 0 on failure or length of exeInfoString.
* If the generated string is longer than the buffer, the needed buffer
* length will be returned, but the string will not be copied into
* exeInfoString.  Applications should check to see if the return value
* is greater than the length of the buffer, and increase its size if
* necessary.
*/
MEXP(int) getExeInfo(
    char* fileName,
    char* exeInfoString,
    unsigned int infoBufferSize, // size of exeInfoString
    uint32_t* version,
    int platform
);[/code]
July 8, 2005, 2:51 AM
Myndfyr
Um, couple questions --

Shouldn't the constant in the parameters be 300? 

You're using the dot operator on a variable called szLocalAccountInfo.  I assume that's a structure of some kind.  My question is -- why are you naming it (according to Hungarian notation conventions) as a null-terminated string, when -- if it's a structure -- it obviously has other members.

Just curious :)
July 8, 2005, 3:08 AM
Kp
Also, shouldn't the prototype for getEXEInfo be:

[pre]uint32_t getExeInfo(const char* fileName, char* exeInfoString, size_t infoBufferSize, uint32_t* version, int platform);[/pre]

Since we know the version and magic version fields to be 32 bits wide, it makes sense to return them in types specifically designated as such.  Also, why make the filename writable?  Finally, it's traditional to use size_t for parameters that specify the length of arrays or other allocations.  This also assists 64-bit portability.

IMO, the constant should be neither 256 nor 300, but instead sizeof(EXEInfo) -- let the compiler figure it out!
July 8, 2005, 4:03 AM
shadypalm88
[quote author=Kp link=topic=12126.msg119599#msg119599 date=1120795397]
Also, shouldn't the prototype for getEXEInfo be:

[pre]uint32_t getExeInfo(const char* fileName, char* exeInfoString, size_t infoBufferSize, uint32_t* version, int platform);[/pre]
[/quote]

Pretty much.  If rewriting it today, it'd be:
[pre]size_t getExeInfo(const char* fileName, char* exeInfoString, size_t infoBufferSize, uint32_t* version, int platform;[/pre]The function returns the length of the string copied into exeInfoString, not the magic version.  That's placed in *version.  You're correct on all the other changes.
July 9, 2005, 6:46 PM

Search