Without changing the source code, use gdb get the program to spit out My name is
ID: 3585009 • Letter: W
Question
Without changing the source code, use gdb
get the program to spit out My name is l33tn00b
Big thumbs up if you got it
#include <iostream>
#include <cstdlib>
#include <cstring>
// "carefully chosen to have 8 bytes so you can just fit it in there"
// l33tn00b
using namespace std;
int main(int argc, char* argv[]){
long* ptr = new long;
long value = 15;
char user[20];
char dev[] = "Andy";
strncpy(user, argv[1], strlen(argv[1]));
*ptr = value;
cout << "My name is " << dev << endl;
cout << "Your name is " << user << endl;
cout << "The pointer has value " << *ptr << endl;
return 0;
}
Explanation / Answer
Hi,
Though using gdb, you can still rely on the defined functions to pritnt your output, so if you want to print a given string by gdb, you can simply use,
where string can have your desired o/p which is l33tn00b in this case
(gdb) printf "%s ", string
Thumbs up if this was helpful, otherwise let me know in comments
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.