Elnee
sad
Necrobumper
klimi
Ибраги́м
Lol I just measure how many lines there and make shallow judgments xD
Don't worry dear, u've made worse life decisions.
MᏫᎻᎯᎷᎷᎬᎠ
And type? Possibly... Not sure
yeah it has the type information such as size to calculate the access so if your type size is 4 and you want to access the 3rd element the calc is just 3 * 4 = the index of the array
MᏫᎻᎯᎷᎷᎬᎠ
Don't worry dear, u've made worse life decisions.
Really? My life was going very well this far
Anonymous
template <typename _Up, typename _Ep, typename = void> struct _Ptr { using type = _Up*; }; template <typename _Up, typename _Ep> struct _Ptr<_Up, _Ep, __void_t<typename remove_reference<_Ep>::type::pointer>> { using type = typename remove_reference<_Ep>::type::pointer; }; this is in __unique_ptr_impl of libstdc++. i don't understand line 6 Edit: nvm i got it
Nils
How do I execvp() without replacing the current process?
Nils
use fork
but how do I tell the fork what to run?
Nils
Can I pass the some pointer to fork()?
Alex
or try system
Nils
or try system
Nope, it's too unsafe.
Alex
but how do I tell the fork what to run?
inside child process call execvp
Nils
Nope, it's too unsafe.
(I am involving user input...)
Nils
inside child process call execvp
but how does the child know that it's a child and which arguments to pass to execvp?
vinícius*
you can tell childs by the PID value
vinícius*
the child will have PID == 0
Nils
fork returns zero for child, and pid of child for parent
but how do I pass the arguments for execvp() to the child?
Nils
Do I need a fd or something like that?
vinícius*
the child will have access to all the variables the parent process had at the moment of forking
vinícius*
nah
Alex
but how do I pass the arguments for execvp() to the child?
you can read from stdin in child or use IPC to pass data from parent
vinícius*
you're trying to make a shell ?
vinícius*
well, you can do something like this: char ** aux = malloc(read_from_pos * sizeof(char *)); for(i=0; i<read_from_pos; i++) aux[i] = parsed[i]; if (fork() == 0) { execvp(aux[0], aux); fprintf(stderr, "%s: command not found.\n", aux[0]); }
vinícius*
nope, anywhere
Nils
nope, anywhere
so fork() always calls the function that it is called from?
vinícius*
fork will always run from where it's called
Nils
vinícius*
vinícius*
yeah
vinícius*
it'll inherit the file descriptors of the parent process, afaik
vinícius*
you wanna use dup2?
Nils
you wanna use dup2?
I want to somehow read the process output
Nils
But I am too much of a beginner in file descriptors, tbh
vinícius*
I want to somehow read the process output
as in saving it to a file or printing it to stdout?
vinícius*
I imagine you can do something like this:
vinícius*
int fds[2]; const char *argv[3] = {"/bin/ls", "-li"}; pipe(fds); if (fork() == 0) { close(fds[0]); dup2(type[0] == 'r' ? 0 : 1, fds[1]); close(fds[1]); execvp(argv[0], argv); exit(-1); } close(fds[1]); FILE * proc_output = fdopen(fds[0], type);
vinícius*
the child's output should be contained within that file, so you can read it with fscanf, fread, whatever
Nils
Can I wait for the fork()ed process to having exited?
vinícius*
yeah
Nils
yeah
just wait(pid)?
vinícius*
wait(0), yup
Nils
thx
Nils
int fds[2]; const char *argv[3] = {"/bin/ls", "-li"}; pipe(fds); if (fork() == 0) { close(fds[0]); dup2(type[0] == 'r' ? 0 : 1, fds[1]); close(fds[1]); execvp(argv[0], argv); exit(-1); } close(fds[1]); FILE * proc_output = fdopen(fds[0], type);
struct databuffer db_fromcmd(const char **command) { struct databuffer outdb; struct databuffer readdb; db_init(&outdb); int stdout_backup = dup(1); dup2(memfd_create("pipe", 0), 1); if (fork() == 0) { execvp(command[0], command); } FILE *proc_out = fdopen(1, "r"); while (!feof(proc_out) == 0) { char outb[16]; fread(outb, sizeof(outb), 1, proc_out); readdb = sized_db(outb, sizeof(outb)); db_append(&outdb, &readdb); } wait(0); close(1); dup2(stdout_backup, 1); return outdb; }
Nils
Right?
Nils
Oh wait I should not forget to dup back the original stdout
Nils
Done
piggyho
Hey. after python, I obviously don't understand how this language works. Why can I access a nonexistent index in an array? where did the given value in this array come from?
bounds checking reduces performance in c/cpp, an array is contiguous memory. and the index is just an offset from the start don't confuse that with std::array
Anik
can u explain me how can i imorove C+
Anonymous
Coding
数学の恋人
q1248 •卜
great
Nils
Hey. after python, I obviously don't understand how this language works. Why can I access a nonexistent index in an array? where did the given value in this array come from?
That's simple, it's called undefined behavior. Avoid accessing out of bounds data as it might make your program go crazy or crash.
Nils
If you want truly efficient bound checking use c++ std::vector
/home/aleksandr/
Okey, thanks :)
Nils
Okey, thanks :)
Or, if you need the bound check while iterating only, use a so-called "null-terminator"
Nils
It is a special byte that marks the end of the array
/home/aleksandr/
I will consider, thank
Liam
Hey. after python, I obviously don't understand how this language works. Why can I access a nonexistent index in an array? where did the given value in this array come from?
In C/C++, raw array stores its data sequentially in memory. When accessing elements in array by arr[i], C/C++ will try to dereference data stored in arr + i, with given type. The behavior is undefined, according to the standard, which means it may cause segmentation fault, or may return as usual, or may do anything else. Programmers are responsible for boundary checking, in these cases, in C/C++ world. In your case, xl + 88 is a valid mem-address for your program, hence no seg-fault caused by dereferencing it.
Anonymous
Hello, how can we use c++ for hacking? Is there any good website or something. I know c++ already
...
What
Mr.James
Hello, how can we use c++ for hacking? Is there any good website or something. I know c++ already
No uh can't hack by using c++ still uh can create viruse by c++
Anonymous
/get cppbookguide
వ్లాదమిర్ పుతిన్
https://dpaste.org/z2eC#L49
వ్లాదమిర్ పుతిన్
am only getting IP from the last line. any fix?
Alex
what do you want to get?
Anonymous
A person, who thinks that (s)he knows C++, knows almost nothing about C++
Anonymous
A person, who thinks that (s)he knows C++, knows almost nothing about C++
No I mean the basics, I have been learning it for a couple of months now (and still learning)