May 19, 2020 05:26 AM
(This post was last modified: May 19, 2020 05:28 AM by gurlhackerclub.)
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 07:02 AM
(This post was last modified: May 19, 2020 07:26 AM by gurlhackerclub.)
(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 11:11 AM
(This post was last modified: May 19, 2020 11:12 AM by gurlhackerclub.)
(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:36 AM
(This post was last modified: May 19, 2020 11:37 AM by saltycracker.)
(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.
DO NOT DEAL WITH THIS MEMBER
May 19, 2020 12:51 PM
(This post was last modified: May 19, 2020 04:04 PM by SIM-3991524.)
May 19, 2020 05:18 PM
(This post was last modified: May 19, 2020 05:19 PM by k1r3n.)
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
|