• Welcome to Valhalla Legends Archive.
 

[C++] getExeInfo

Started by Okee, July 07, 2005, 02:07 PM

Previous topic - Next topic

Okee

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


                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);
}


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.

MyndFyre

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?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

warz

I don't think it's necessary to call kd_init untill youre ready to begin doing the cd key decoding.

Okee

Yeah I call kd_init() prior to everything in this function. It's the first thing I do.

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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

shadypalm88

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


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


(The declaration for getExeInfo is:)
/**
* 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
);

MyndFyre

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 :)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

Also, shouldn't the prototype for getEXEInfo be:

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


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!
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

shadypalm88

Quote from: Kp on July 07, 2005, 11:03 PM
Also, shouldn't the prototype for getEXEInfo be:

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


Pretty much.  If rewriting it today, it'd be:
size_t getExeInfo(const char* fileName, char* exeInfoString, size_t infoBufferSize, uint32_t* version, int platform;
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.