Jump to content

stringsplit for C++


mmavipc
 Share

Recommended Posts

Have you looked at his code? He's getting the value of AutoIt plugin function parameters and each one is a string that is a character long. He needs to take these and put them into a string.

On second thought, forget a conversion. Why don't you just accept all four characters as a string parameter? That makes a lot more sense.

Link to comment
Share on other sites

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Have you looked at his code? He's getting the value of AutoIt plugin function parameters and each one is a string that is a character long. He needs to take these and put them into a string.

On second thought, forget a conversion. Why don't you just accept all four characters as a string parameter? That makes a lot more sense.

I'm still kind of confused on what he is trying to do. He is trying to convert an array of 1 character + 1 null character strings, into 1 string?

char *IV[4] = {"a", "b", "c", "d"};
char *result = new char[5];
memset(result, 0, sizeof(char) * 5);

for (int i = 0; i < 4; i++) result[i] = *IV[i];

// and when you're done..
delete[] result;

result is now the string.

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] = {0}; //result of encryption

    // allocate our return string...
    char *au3ready = new char[packetlen + 1];
    memset(au3ready, 0, sizeof(char) * (packetlen + 1));

    strcpy(buf2send,packet);
    mc_encrypt(IV, buf2send, result, packetlen);
    strcpy(au3ready, result);

    /*
    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;  
}

?

Edited by cppman
Link to comment
Share on other sites

I'm still kind of confused on what he is trying to do. He is trying to convert an array of 1 character + 1 null character strings, into 1 string?

char *IV[4] = {"a", "b", "c", "d"};
char *result = new char[5];
memset(result, 0, sizeof(char) * 5);

for (int i = 0; i < 4; i++) result[i] = *IV[i];

// and when you're done..
delete[] result;

result is now the string.

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] = {0}; //result of encryption

    // allocate our return string...
    char *au3ready = new char[packetlen + 1];
    memset(au3ready, 0, sizeof(char) * (packetlen + 1));

    strcpy(buf2send,packet);
    mc_encrypt(IV, buf2send, result, packetlen);
    strcpy(au3ready, result);

    /*
    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;  
}

?

au3ready cant be an array

[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

Are you saying you don't know enough about C++ to know a character array? You shouldn't be writing plugins. ^^;

I suggested this though.

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

Instead of that, just send one parameter that is a string, four characters long. Then you can read one parameter into IV.

Link to comment
Share on other sites

current code:

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_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];
    }
    pMyResult = AU3_AllocVar ();
    AU3_SetString(pMyResult,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

make.exe: *** [main.o] Error 1

Execution terminated

line 78: mc_encrypt(IV, buf2send, result, packetlen);

Edit: tried changing au3ready to a pointer and it worked.

Edited 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

You dereference a pointer like this:

int *ptr ...;
 int val = *ptr;
Why do you continue to help somebody who has virtually no knowledge and based on their reaction doesn't seem very willing put forth the effort necessary to get some knowledge on their own? Sometimes, despite the fact that we can help, we just have to say, "No, you need to learn that on your own." Helping people every time and never forcing them to help themselves, that's not really a good thing.
Link to comment
Share on other sites

Why do you continue to help somebody who has virtually no knowledge and based on their reaction doesn't seem very willing put forth the effort necessary to get some knowledge on their own? Sometimes, despite the fact that we can help, we just have to say, "No, you need to learn that on your own." Helping people every time and never forcing them to help themselves, that's not really a good thing.

It isn't exactly easy to figure out what to search for when you are just starting out. It really helps to work off of examples. Thus, I gave him a "dead" example, and a term, in italics, to search for.
Link to comment
Share on other sites

It isn't exactly easy to figure out what to search for when you are just starting out. It really helps to work off of examples. Thus, I gave him a "dead" example, and a term, in italics, to search for.

It's pretty easy to know what to search for when starting out. They're called books. There's a sticky in this forum to them. The OP isn't at the point where they need to search for anything, they are at the point where they need basic knowledge covered by any text book.
Link to comment
Share on other sites

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_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;
    
    return AU3_PLUGIN_OK;   
}

Can anyone tell me why this crashes autoit?

edit: dummies 4TW except that it crashes autoit......

Edit: just noticed soo many replies happened while I was getting a book and reading muttley :)

Edited 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

What was the error returned?

Something Valik suggested to me when I was writing a plugin before was to run the code in it's own program for testing. That way you can use all the debugging tools.

it does that windows crash thingy and autoit.exe exits with this errorcode

!>12:17:40 AutoIT3.exe ended.rc:-1073741819

the testing proggy i used was:

$hplugin = PluginOpen("dll.dll")
ConsoleWrite("lolz" & @lf)
ConsoleWrite(enc(0x00,0x00,0x00,0x00,"lolz",4) & @lf)
PluginClose($hplugin)

How would I run the plugin in it's own program?

[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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...