Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Concat an array of chars into another array or chars

Want to concat a string of the active logical drives into another string, So that it can be sent over a socket.
The line strcat_s is giving me issues. commented out line.



Code
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <windows.h>

using namespace std;
char lpdrives[1000];
char lpBuffer[100];
DWORD mydrives = 100;// buffer length

int main() {
    cout << "starting drives check ";
    DWORD test = GetLogicalDriveStringsA(mydrives, lpBuffer);
    // Check up to 100 drives...
    int i;
    strcpy_s(lpdrives, sizeof lpdrives, "drives: ");
    for (i = 0; i < 100; i++) {
        cout << lpBuffer[i];
  //      strcat_s(lpdrives, sizeof lpdrives, lpBuffer[i]);
    }
    cout << lpdrives;

    return 0;
}
Well what issues? Post exactly what the problem is.
May you be given directions by software engineer document writers.
(May 19, 2020 05:43 AM)saltycracker Wrote:  Well what issues? Post exactly what the problem is.

nvm,  I got it,  thx

Code
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <windows.h>

using namespace std;
char lpdrives[1000];
char lpBuffer[100];
DWORD mydrives = 100;// buffer length

int main() {
    cout << "starting drives check ";
    DWORD test = GetLogicalDriveStringsA(mydrives, lpBuffer);
    // Check up to 100 drives...
    int i;
    strcpy_s(lpdrives, sizeof lpdrives, "drives: ");
    for (i = 0; i < 100; i++) {
        cout << lpBuffer[i];
        string sym(1, lpBuffer[i]);
        const char* fag  = sym.c_str();
        strcat_s(lpdrives, sizeof lpdrives, fag);
    }
    cout << lpdrives;

    return 0;
}
(May 19, 2020 07:02 AM)gurlhackerclub Wrote:  nvm,  I got it,  thx

Code
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <windows.h>

using namespace std;
char lpdrives[1000];
char lpBuffer[100];
DWORD mydrives = 100;// buffer length

int main() {
   cout << "starting drives check ";
   DWORD test = GetLogicalDriveStringsA(mydrives, lpBuffer);
   // Check up to 100 drives...
   int i;
   strcpy_s(lpdrives, sizeof lpdrives, "drives: ");
   for (i = 0; i < 100; i++) {
       cout << lpBuffer[i];
       string sym(1, lpBuffer[i]);
       const char* fag  = sym.c_str();
       strcat_s(lpdrives, sizeof lpdrives, fag);
   }
   cout << lpdrives;

   return 0;
}

Why are you creating a std::string from character array and then turning it back to a c string? Why not use the character array and skip the whole std::string to c string?
May you be given directions by software engineer document writers.
(May 19, 2020 10:40 AM)saltycracker Wrote:  Why are you creating a std::string from character array and then turning it back to a c string? Why not use the character array and skip the whole std::string to c string?

On this line,
strcat_s(lpdrives, sizeof lpdrives, lpBuffer[i]);

I was getting this error.
errno_t strcat_s(char *,rsize_t,const char *)': cannot convert argument 3 from 'char' to 'const char *'

I needed to send this char array through a socket.
iResult = send(ConnectSocket, lpdrives, (int)strlen(lpdrives), 0);

Ugly, but I got it working. Simple command line RAT. Now the only commands I can send are quit and list active drives.
(May 19, 2020 11:11 AM)gurlhackerclub Wrote:  On this line,
strcat_s(lpdrives, sizeof lpdrives, lpBuffer[i]);

I was getting this _error_.
errno_t strcat_s(char *,rsize_t,const char *)': cannot convert argument 3 from 'char' to 'const char *'

I needed to send this char array through a socket.
iResult = send(ConnectSocket, lpdrives, (int)strlen(lpdrives), 0);

Ugly, but I got it working.  Simple command line RAT.  Now the only commands I can send are quit and list active drives.

Why won't you just pass the array? The array name is the pointer address.

You have this:
Code
strcat_s(lpdrives, sizeof lpdrives, lpBuffer[i]);

But did you try:
Code
strcat_s(lpdrives, sizeof lpdrives, lpBuffer);
May you be given directions by software engineer document writers.
(May 19, 2020 11:36 AM)saltycracker Wrote:  Why won't you just pass the array? The array name is the pointer address.

You have this:
Code
strcat_s(lpdrives, sizeof lpdrives, lpBuffer[i]);

But did you try:
Code
strcat_s(lpdrives, sizeof lpdrives, lpBuffer);

Yea, I got this output.
Code
drives: C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\
D:\cprojects\hackforums\Debug\HackForums.exe (process 20888) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .


I don't understand why, But I got it working. Thank you for your help though.
There is StringCchCatA aswell

https://docs.microsoft.com/en-us/windows...ingcchcata
You already using C++. You can use STL tools for working with strings.

Simple example:
Code
#include <windows.h>
#include <cstdio>

#include <string>

int main() {
    char buffer[MAX_PATH];
    if (!GetLogicalDriveStrings(MAX_PATH, buffer)) return 1;
    printf("%s\n", (std::string(buffer) + "Users\\").c_str());
    return 0;
}

In another case, you can use the tools that migrated from C. For instance: strcat


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by dalton1337Nov 12, 2020 04:38 AM 1 138 Nov 12, 2020 04:38 AM
Last Post: tsuki
[C#] by draxyeeJul 7, 2020 07:29 PM 1 137 Jul 7, 2020 07:29 PM
Last Post: iolaka
[C] by TralenSep 9, 2017 05:13 PM 7 209 Sep 9, 2017 05:13 PM
Last Post: 0xDEAD10CC