GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Jul-2008, 17:22
mmavipc mmavipc is offline
New Member
 
Join Date: Jul 2008
Posts: 1
mmavipc is on a distinguished road

Need help coverting char* to char


Hello I am writing a plugin for AutoIt(autoitscript.com). The problem is that the function used in the AutoIt plugin sdk to get a parameter from the function call in AutoIt returns a char*, whats wrong with that is that the function I wish to use it in will not accept a char*, It will only accept a char. Here is my code.
CPP / C++ / C Code:
char encrypted_buffer[10000]; //big chunk of space :D some packets hit more than 9k you know.
char *IV[4];
AU3_PLUGIN_DEFINE(enc)
{
    AU3_PLUGIN_VAR	*s2au3;
    char *packet;
    int packetlen;
    IV[0] = AU3_GetString(&p_AU3_Params[0]);
    IV[1] = AU3_GetString(&p_AU3_Params[1]);
    IV[2] = AU3_GetString(&p_AU3_Params[2]);
    IV[3] = AU3_GetString(&p_AU3_Params[3]);
    packet = AU3_GetString(&p_AU3_Params[4]);
    packetlen = AU3_GetInt32(&p_AU3_Params[5]);
    InitEncryption(51);
    char buf2send[10240]; //10k ok buf space becuase packets can get bigger than 9k
    char result[10240]; //result of encryption
    char *au3ready;
    strcpy(buf2send,packet);
    mc_encrypt(IV, buf2send, result, packetlen);
    for (int i=0;i<packetlen;i++){
        au3ready[i] = result[i];
    }
    s2au3 = AU3_AllocVar ();
    AU3_SetString(s2au3,au3ready);
   	*p_AU3_Result		= s2au3;
	*n_AU3_ErrorCode	= 0;
	*n_AU3_ExtCode		= 0;   
}
The variable that is the problem is IV. mc_encrypt will only accept a char array and not a char* array. If you are wondering where mc_encrypt is defined, it's defined here:
CPP / C++ / C Code:
int InitEncryption(int value){
	HINSTANCE hGetProcIDDLL = LoadLibraryA("MapleCrypto");
	mc_initalize = pIC_InitDeInit(GetProcAddress(HMODULE (hGetProcIDDLL), "Initialize"));
	mc_finalize = pIC_InitDeInit(GetProcAddress(HMODULE (hGetProcIDDLL), "Finalize"));
	mc_encrypt = pIC_EncDecrypt(GetProcAddress(HMODULE (hGetProcIDDLL), "Encrypt"));
	mc_decrypt = pIC_EncDecrypt(GetProcAddress(HMODULE (hGetProcIDDLL), "Decrypt"));
	mc_encryptWithHeaderToClient = pIC_HeaderEncrypt(GetProcAddress(HMODULE (hGetProcIDDLL), "EncryptWithHeaderToClient"));
	mc_encryptWithHeaderToServer = pIC_HeaderEncrypt(GetProcAddress(HMODULE (hGetProcIDDLL), "EncryptWithHeaderToServer"));
	mc_generateIV = pIC_GenerateIV(GetProcAddress(HMODULE (hGetProcIDDLL), "GenerateIV"));
	return mc_initalize(value);
}
Thanks in advanced
  #2  
Old 21-Jul-2008, 13:11
transfrank transfrank is offline
Junior Member
 
Join Date: Aug 2007
Posts: 67
transfrank will become famous soon enough

Re: Need help coverting char* to char


Quote:
the function I wish to use it in will not accept a char*, It will only accept a char. Here is my code.
1:
That would tend to make more sense for the initial word of an encryption function to use chars.
You need each IV[] to contain a character and declare char IV[4]; You could then stuff it with whatever 8 bit values you want. I don't really see why you decide to stuff it with addresses, and the latter are not 8 bit long either.

2:
I see one problem with your code: Here, this pointer is uninitialized
CPP / C++ / C Code:
char *au3ready;
So over here, you are just writing to some arbitrary memory location:
CPP / C++ / C Code:
au3ready[i] = result[i];
You have a pointer to a single char. I think you really want a char auready3[10240].

3:
Over here at:
CPP / C++ / C Code:
strcpy(buf2send,packet);
The compiler is not forcing to copy all 10240 indices. You may want a strncpy and think about forcing the non used chars to zero.

4:Try to use malloc to allocate chunks of memory, with free to release the chuncks. You have a ton of space there and you could put a different size each time you run them.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 2) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer initialization causing program abend? emanresu C Programming Language 0 12-Dec-2006 10:36
lvalue compile error emanresu C Programming Language 7 16-Nov-2006 10:22
getting an error while compiling and running using different IDE. jaro C Programming Language 0 25-Aug-2006 09:14
Memory cannot be read? dlare9 C Programming Language 3 16-Nov-2005 07:03
Debug Assertion Failed! dlare9 C Programming Language 3 13-Nov-2005 23:18

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:23.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.