Sinisterly
Tutorial Source Code Tutorial - Simple Reverse Shell in C - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Coding (https://sinister.li/Forum-Coding--71)
+--- Thread: Tutorial Source Code Tutorial - Simple Reverse Shell in C (/Thread-Tutorial-Source-Code-Tutorial-Simple-Reverse-Shell-in-C)

Pages: 1 2 3


RE: Source Code Tutorial - Simple Reverse Shell in C - m0dem - 10-16-2015

(10-16-2015, 05:28 AM)0xDEAD10CC Wrote: It was a principle that I was trying to show, not that you should have that exact same code, however that doesn't mean that you can't have a function which will set up your socket for you so that it's ready for use; socket options set, bindings, etc...

If you have descriptive function calls, the structure and flow of your program is much easier to read. Ex: *note - just pseudocode*
Code:
init(flag); while (flag) { for (int i = ....) calculate(&x, &y, &z); x += somevalue; y -= x; z = function(x, y); if (condition) flag = false; }

Or:
Code:
init(flag); while (flag) { if (!function(&x, &y, &z) flag = false; }

^^ This makes it much easier to see the flow of your program which isn't complicated and cluttered with the calculations that you may not have to see unless you have to troubleshoot your algorithm. Keep in mind, I have no idea what kind of code would look like this or if this structure would even be useful. I'm just showing how functions can allow your code to be more readable in lots of cases, and unless you're concerned with micro-optimizing your code and reducing a single function call (which can still be optimized in other ways, even if it isn't inlined), you should care more about the readability of your code.

If I have to add code to that while loop too. When writing larger projects, it's nice to know that I'm not going to break the good code that I've well tested, by modifying the body of my loop, whereas in the first example, I have to read over the code and examine it to understand what I shouldn't touch as it would break code that is working fine.

I understand you now. I'll get around to tidying things up in a bit for readability's sake! Smile

I really need to get the pipes to cmd.exe working. I still have to grasp https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx. <- thanks @dotcppfile

For those who are interested, I found this great resource: https://www.hackthissite.org/articles/read/959.