Log in

View Full Version : MFC VC question


LaptoniC
April 19th, 2003, 21:44
I am workiing on Sheriff Licence System Lately.In the staticlibrary there are a lot of usefull function.However I cant make use of it.
function name is
GetSecrets@@YAPAU_SLS_SECRET@@PBDAAH@Z

according to IDA it

want char,pointer to int and return value is pointer to SLS_SECRET structure.How can I link this function to my ap.I have Visual Studio 6.Thanks and sorry I am not familiar with VC and MFC

squidge
April 20th, 2003, 03:26
Looks like standard C++ name mangling to me, so if you extern a reference to the function name GetSecrets and use exactly the same return value and parameters, the compiler should generate the same name and be able to link to it.

_Servil_
April 20th, 2003, 05:57
Hi Laptinic,

If your project in C,

just make a prototype,

like this

SLS_SECRET * __cdecl GetSecrets(char, int *);

in linker put extra /defaultlib:<the_static_library.lib> switch to cmdline, if arguments you stated rite the importdef of ur app should be same as the exportdef.

LaptoniC
April 20th, 2003, 09:12
I tried below

_SLS_SECRET * __cdecl GetSecrets(char const *,int &;

int test1;
GetSecrets("5328-8301-2929-7640-5794"",&test1);

or
SLS_SECRET * __cdecl GetSecrets(char, int *);
GetSecrets("5328-8301-2929-7640-5794"",&test1);

In the dissambly usage is like this

.data
sSize dd 0
pId db "5328-8301-2929-7640-5794"

push offset sSize
push offset pId
call GetSecrets

If you want I can upload my project or send to you.Thanks.

error message is
error C2664: GetSecrets' : cannot convert parameter 1 from 'char [25]' to 'char' This conversion requires a reinterpret_cast, a C-style cast or function-style cast

LaptoniC
April 20th, 2003, 10:42
Finallly below one worked
_SLS_SECRET * __cdecl GetSecrets(char const *,int &;

typedef struct _SLS_SECRET
{
unsigned char Secret[32]; //null-terminate string
} SLS_SECRET;

char * pId="1234-5678-9012-3456-7890";

SLS_SECRET *mysecret;
strcpy(pId,"5328-8301-2929-7640-5794";
mysecret=GetSecrets(pId,sSize);

However I cant show mysecret with messagebox etc.

squidge
April 20th, 2003, 10:51
Have you tried searching for the SDK? It's bound to have been uploaded somewhere public, probably with weak password protection.

LaptoniC
April 20th, 2003, 11:12
I have the sdk it is freely distributed from their website.I finally made it work but given serial number doesnt works.Anyway I guess I will find secret codes with my tool and uses slsgen.exe to make keys.

Thanks

cyberheg
April 20th, 2003, 11:33
Quote:
Originally posted by LaptoniC
Finallly below one worked
_SLS_SECRET * __cdecl GetSecrets(char const *,int &;

typedef struct _SLS_SECRET
{
unsigned char Secret[32]; //null-terminate string
} SLS_SECRET;

char * pId="1234-5678-9012-3456-7890";

SLS_SECRET *mysecret;
strcpy(pId,"5328-8301-2929-7640-5794";
mysecret=GetSecrets(pId,sSize);

However I cant show mysecret with messagebox etc.


You might want to learn programming C++ a bit better before diving into such as this.

I downloaded the sdk though and studied the static library as you said the function would be in.

The prototype of the function should be SLS_SECRET * GetSecrets(const char *, int *);

I don't think you want to use cdecl spec because that would conflict with C++ name mangling. Also the file you have your code in must be named *.cpp and not *.c to make sure you activate the C++ compiler.

From the prototype we see that parameter 1 is not modified by the function and should be zero terminated. For the second parameter you used reference instead of pointer but from the code I found:

.text:00000168 mov ecx, [ebp+arg_4]
.text:0000016B mov dword ptr [ecx], 4

So by using a pointer you make sure you get the correct code generated by the compiler.

So to call it you should do:

SLS_SECRET *pMysecret;
int nSize;
pMysecret = GetSecrets("5328-8301-2929-7640-5794", &nSize);

Now you state that you can't display the SLS_SECRET variable to a messagebox. Why doesn't that not surprise me?
What you really want is not to feed the messagebox with the SLS_SECRET structure but the char string inside it.

Try with something like:

MessageBox(NULL, pMysecret->Secret, "Secret data...!?", MB_OK);

// CyberHeg

LaptoniC
April 20th, 2003, 19:54
I have already writen asm equivalent of GetSecret function and it works quite well.However licence generetion routine of sdk have a lot of C class function and it will took a lot of time to convert.So I thought if I can use GetSecretFunction from lib and with the help of SLS_GenerateLicenceKey function I may genereate licence key.However GenerateLicenceKey function gaves wrong serial number.Anyway if you want interested here is my code
Code:

_SLS_SECRET * __cdecl GetSecrets(char const *,int &;

char * pId="1234-5678-9012-3456-7890";
char LicKey [64];

void CSheriffDlg::OnButton1()
{

int sSize;
char RefCode[30];

SLS_LICENCE LicencePolicy;
SLS_SECRET *mysecret;
GetDlgItemText(IDC_EDIT1,pId,25);
GetDlgItemText(IDC_EDIT2,RefCode,30);
mysecret=GetSecrets(pId,sSize);
LicencePolicy.Type=SLS_TYPE_STANDALONE;
LicencePolicy.CoUsers=1;
SLS_GenerateLicenceKey(pId,mysecret,4,RefCode,&LicencePolicy,LicKey);
SetDlgItemText(IDC_EDIT3,LicKey);

}


Thanks everyone.