mmavipc Posted July 18, 2008 Share Posted July 18, 2008 Hello. I'm trying to make a au3 plugin but my prob is that i need to load a string eg "lolzipwnzcuziizdumbb0z" into a array. if this were autoit I would just stringsplit(string,""). Can anyone tell me how to do this in C++ please. Thank you [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
-Ultima- Posted July 18, 2008 Share Posted July 18, 2008 (edited) @Alienware: Look at the subforum you're posting in, and ask again...? It's not really relevant. @mmavipc: Depends on what kind of strings you're using. If you're using cstrings, then you'll find that they already are arrays of characters, and you can do string to access each character already (until you hit null termination, '\0'). If you're using C++ std::string, you can always get the cstring out of the object using string.c_str(), and then access the characters as described previously. Edit: As Richard mentioned, though, std::string does overload the [] operator, though. Silly me -- I never use it, so it completely slipped my mind. Bad excuse, but oh well muttley Edited July 18, 2008 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
mmavipc Posted July 18, 2008 Author Share Posted July 18, 2008 @Alienware: Look at the subforum you're posting in, and ask again...? @mmavipc: Depends on what kind of strings you're using. If you're using cstrings, then you'll find that they already are arrays of characters, and you can do string to access each character already (until you hit the null termination, '\0'). If you're using C++ std::string, you can always get the cstring out of the object using string.c_str(), and then access the characters as described previously.heres my current code char IV[4]; AU3_PLUGIN_DEFINE(enc) { AU3_PLUGIN_VAR *pMyResult; 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_GetString(&p_AU3_Params[5]); char buf2send[10240] //10k ok buf space becuase packets can get bigger than 9k i need packet to go into buf2send. [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 18, 2008 Share Posted July 18, 2008 (edited) Use strcpy. Edited July 18, 2008 by Richard Robertson Link to comment Share on other sites More sharing options...
LarryDalooza Posted July 18, 2008 Share Posted July 18, 2008 in C it is "strtok"... I think... Lar. AutoIt has helped make me wealthy Link to comment Share on other sites More sharing options...
mmavipc Posted July 18, 2008 Author Share Posted July 18, 2008 Use strcpy.Thank you [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
mmavipc Posted July 19, 2008 Author Share Posted July 19, 2008 heres my new code: 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_GetString(&p_AU3_Params[5]); 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<packetlength;i++){ au3ready = au3ready + result[i]; } s2au3 = AU3_AllocVar (); AU3_SetString(s2au3,au3ready); *p_AU3_Result = s2au3; *n_AU3_ErrorCode = 0; *n_AU3_ExtCode = 0; } Now I'm getting a bunch of invalid conversion from char to char ?????(I am a noob at C++) [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 19, 2008 Share Posted July 19, 2008 Since we don't know anything about mc_encrypt, there may be errors on that call that we can't help you with. Also, where is IV declared? Link to comment Share on other sites More sharing options...
mmavipc Posted July 19, 2008 Author Share Posted July 19, 2008 Since we don't know anything about mc_encrypt, there may be errors on that call that we can't help you with. Also, where is IV declared?here lemmie give yu mroe of the 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_GetString(&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<packetlength;i++){ au3ready = au3ready + result[i]; } s2au3 = AU3_AllocVar (); AU3_SetString(s2au3,au3ready); *p_AU3_Result = s2au3; *n_AU3_ErrorCode = 0; *n_AU3_ExtCode = 0; } and 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); } [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 19, 2008 Share Posted July 19, 2008 Here's a huge problem. You are trying to set a char[] into a char. char IV[4]; means that an array of 4 chars will be declared. Not 4 strings. Use char *IV[4]; I believe. Try that and see what happens next. Link to comment Share on other sites More sharing options...
mmavipc Posted July 19, 2008 Author Share Posted July 19, 2008 (edited) new 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 = au3ready + result[i]; } s2au3 = AU3_AllocVar (); AU3_SetString(s2au3,au3ready); *p_AU3_Result = s2au3; *n_AU3_ErrorCode = 0; *n_AU3_ExtCode = 0; } compile log: Compiler: Default compiler Building Makefile: "D:\Documents and Settings\Maverick\Desktop\thumb\AutoitMSEmu\dllpaser\Makefile.win" Executing make... make.exe -f "D:\Documents and Settings\Maverick\Desktop\thumb\AutoitMSEmu\dllpaser\Makefile.win" all g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" main.cpp: In function `int enc(int, const AU3_PLUGIN_VAR*, AU3_PLUGIN_VAR**, int*, int*)': main.cpp:78: error: cannot convert `char**' to `char*' in argument passing main.cpp:79: error: ISO C++ forbids comparison between pointer and integer main.cpp:83: error: invalid conversion from `char' to `char*' main.cpp:83: error: initializing argument 2 of `void AU3_SetString(AU3_PLUGIN_VAR*, char*)' make.exe: *** [main.o] Error 1 Execution terminated Line 72: packetlen = AU3_GetInt32(&p_AU3_Params[5]); line 78: mc_encrypt(IV, buf2send, result, packetlen); line 79: for (int i=0;i<packetlen;i++){ line: 83: AU3_SetString(s2au3,au3ready); edit: fixed line 72 Edited July 19, 2008 by mmavipc [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
cppman Posted July 19, 2008 Share Posted July 19, 2008 (edited) I added some comments in here, so check them out. //vvv - this should be allocated dynamically if it is a "packet". 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; // it SHOULDN'T be an int* 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); // What string in IV are you trying to send? [0],[1],[2],[N]? mc_encrypt(IV/* <----- */, buf2send, result, packetlen); for (int i=0;i<packetlen;i++){ au3ready = au3ready + result[i]; // ARE YOU TRYING TO APPEND result[i] to au3ready? (it isn't a string) } // not sure how autoit handles allocated memory... so delete at your own risk char *au3ready_str = new char[2]; memset(au3ready_str, 0, sizeof(CHAR) * 2); au3ready_str[0] = au3ready; s2au3 = AU3_AllocVar (); AU3_SetString(s2au3,au3ready_str); *p_AU3_Result = s2au3; *n_AU3_ErrorCode = 0; *n_AU3_ExtCode = 0; } Edited July 19, 2008 by cppman Miva OS Project Link to comment Share on other sites More sharing options...
mmavipc Posted July 19, 2008 Author Share Posted July 19, 2008 I added some comments in here, so check them out. //vvv - this should be allocated dynamically if it is a "packet". 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; // it SHOULDN'T be an int* 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); // What string in IV are you trying to send? [0],[1],[2],[N]? mc_encrypt(IV/* <----- */, buf2send, result, packetlen); for (int i=0;i<packetlen;i++){ au3ready = au3ready + result[i]; // ARE YOU TRYING TO APPEND result[i] to au3ready? (it isn't a string) } // not sure how autoit handles allocated memory... so delete at your own risk char *au3ready_str = new char[2]; memset(au3ready_str, 0, sizeof(CHAR) * 2); au3ready_str[0] = au3ready; s2au3 = AU3_AllocVar (); AU3_SetString(s2au3,au3ready_str); *p_AU3_Result = s2au3; *n_AU3_ErrorCode = 0; *n_AU3_ExtCode = 0; }IV is sent as an array and i'm trying to turn result from an array into a string(each array in result has 1 character) [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 19, 2008 Share Posted July 19, 2008 You'll have to do some weird middle work because when you get the string from a mini variant, you get a char*. What you are actually getting is two characters long. The character you expect and a null. You'll have to write a little conversion code. Link to comment Share on other sites More sharing options...
mmavipc Posted July 19, 2008 Author Share Posted July 19, 2008 You'll have to do some weird middle work because when you get the string from a mini variant, you get a char*. What you are actually getting is two characters long. The character you expect and a null.You'll have to write a little conversion code.how? and add me on msn my msn in mmavipc@yahoo.com [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
cppman Posted July 19, 2008 Share Posted July 19, 2008 (edited) how? and add me on msn my msn in mmavipc@yahoo.comchar * chr2str(char c) { char *ret = new char[2]; memset(ret, 0, sizeof(char) * 2); ret[0] = c; return ret; } Don't forget to delete it, but that returns a string representation of a character. char c = 'a'; char *mystring = chr2str(c); // when you're done with it... delete[] mystring; Edited July 19, 2008 by cppman Miva OS Project Link to comment Share on other sites More sharing options...
mmavipc Posted July 19, 2008 Author Share Posted July 19, 2008 char * chr2str(char c) { char *ret = new char[2]; memset(ret, 0, sizeof(char) * 2); ret[0] = c; return ret; } Don't forget to delete it, but that returns a string representation of a character. char c = 'a'; char *mystring = chr2str(c); // when you're done with it... delete[] mystring;where do i put this? [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 19, 2008 Share Posted July 19, 2008 Chris, you went in the wrong direction. He needs to convert his single character strings (character and a null) to a character. That's what his code was trying to do. Link to comment Share on other sites More sharing options...
mmavipc Posted July 19, 2008 Author Share Posted July 19, 2008 Chris, you went in the wrong direction. He needs to convert his single character strings (character and a null) to a character. That's what his code was trying to do.Can you whip up an example code? [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
cppman Posted July 19, 2008 Share Posted July 19, 2008 (edited) Chris, you went in the wrong direction. He needs to convert his single character strings (character and a null) to a character. That's what his code was trying to do.In that case, there's nothing to convert. Can you whip up an example code?char *test[] = {"a", "b", "c", "d"}; int n = 0; //this is the index of the string array char c = *test[n]; //this gets the character from the specified string Edited July 19, 2008 by cppman Miva OS Project Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now