Dec 9, 2016 07:03 AM
(This post was last modified: Dec 10, 2016 07:26 PM by caiveman.)
Experienced programmers, please provide constructive criticism
My Skype: [email protected]
Add for any C programming help
Hello All,
I see many posts especially on this section of HF that go something like "Learning C" or "How to learn C++". Hopefully this post will answer some of your questions that I had when I was in your position and end this spam.
Before we start, I want to make sure nobody has the - "I want to learn C by making my own botnet/crypter" mentality. You are guaranteed to give up at the first difficulty if you have this mindset.
Introduction/Background Information
Firstly, an introduction to C. C was developed by AT&T makes up most of UNIX (and Linus' open source copy, Linux). It therefore is a native language to Windows. Many programmers prefer C because of its speed, portability, and the ability to interface with low-level aspects of the operating system, despite it's steep learning curve.
C is not the easiest language to learn as your first. If you have never programmed before, I would highly recommend starting with Python as it is incredibly powerful yet has a simple syntax, and is very hard to fuck up your PC.
Prerequisites
To learn C, it is essential to know basic computer science, aka the stack, bytes, endian-ness, pointers, memory, etc because of the low-level nature of the language. My recommendation for this is to watch this series of lectures by UNSW which covers the basics of computer science. The ~20 videos are available on youtube to watch for free.
It is absolutely crucial to know this stuff to program in C, especially the concept of pointers and addresses.
Tools needed
Do these things before reading on
Google (in order) to familiarise yourself:
Read
Actual Programming
Okay, now to the easiest part of learning C - the syntax. A common misconception that beginners hold when learning a new language is that the most important and hardest aspect is the syntax, or actually writing the code. Any good programmer should be able to learn the syntax to a new language in a couple of days, but it can take months to develop an efficient and effective programming style.
I will put "quiz" questions along the way so you can make sure you know the stuff before moving on.
Deconstructing a C program
Lets have a look at a typical C program
Now, lets go line by line and analyse the code
Variables
Variables store data in memory. In C, you do it like this.
A constant variable is just a variable that cannot be changed.
the "const" can come before or after data type declaration, pick one and stick to it.
Protip: an "unsigned" variable basically means it can only be positive, doubling the "range" of the variable.
Quiz: How many bytes does a signed int hold?
Global variables vs Local variables
Global variables are variables that are declared outside of any function.
aka:
Protip: Try to avoid using global variables, if not at all. 99% of the time there is a better way of doing it (especially in c++)
Loops and conditionals
These are the two core principles found in any programming language.
There are a number of loops that you can use in C, the two most common ones being
and
counting to 100 using each loop
There are more loops, such as the do - while loop, but you don't really need to know these, and it's more "syntactic sugar" to save the programmer a few lines of code.
Input and Output
Input
There are couple of input methods in C, and it is a little bit contentious on which one you should use. Some people use fgets() or getline() but for the purpose of this tutorial I will use scanf.
Example:
Quiz: Think of how you could get multiple characters of input using loops and scanf()...
Output
Use printf for output in C
View the rest of the formatting options here
Strings
Strings are a tricky one in C, because unlike other languages where they are stored as an object, strings are literally just arrays of characters.
Two ways of making a string
All strings end with the null character '\0' so the pc knows when to stop reading. There are obvious advantages and disadvantages to both.
In C++, it is much better because there is actually an inbuilt function in the <string> header
std::string str("sick string with lots of functions");
Further reading on C++ strings
Moving onto C++
C++ retains 99% of the syntax from C, but adds a crucial new concept. Classes and proper Object Oriented Programming.
I don't have time to explain in OOP detail but it is essentially programming Objects that interact with each other.
Read this -> https://www.codeproject.com/Tips/679615/...in-Seconds
Watch this -> https://www.youtube.com/watch?v=lbXsrHGhBAU
This keeps the code nice and organised so other people can understand what you are doing. It's really awesome once you get the hang of it.
Conclusion and further reading
Now if you actually did all those steps and learnt some basic computer science you should have a shallow understanding of the amazing language that is C.
The most helpful piece of advice I can give you is to read lots of good C code, and try to understand it, and replicate it.
Further reading and googling:
Projects to complete from here:
~caiveman
My Skype: [email protected]
Add for any C programming help
Hello All,
I see many posts especially on this section of HF that go something like "Learning C" or "How to learn C++". Hopefully this post will answer some of your questions that I had when I was in your position and end this spam.
Before we start, I want to make sure nobody has the - "I want to learn C by making my own botnet/crypter" mentality. You are guaranteed to give up at the first difficulty if you have this mindset.
Introduction/Background Information
Firstly, an introduction to C. C was developed by AT&T makes up most of UNIX (and Linus' open source copy, Linux). It therefore is a native language to Windows. Many programmers prefer C because of its speed, portability, and the ability to interface with low-level aspects of the operating system, despite it's steep learning curve.
C is not the easiest language to learn as your first. If you have never programmed before, I would highly recommend starting with Python as it is incredibly powerful yet has a simple syntax, and is very hard to fuck up your PC.
Prerequisites
To learn C, it is essential to know basic computer science, aka the stack, bytes, endian-ness, pointers, memory, etc because of the low-level nature of the language. My recommendation for this is to watch this series of lectures by UNSW which covers the basics of computer science. The ~20 videos are available on youtube to watch for free.
It is absolutely crucial to know this stuff to program in C, especially the concept of pointers and addresses.
Tools needed
- Text editor (Highly recommend Sublime Text 3)
- gcc (or MinGW on Windows)
- A brain
Do these things before reading on
Google (in order) to familiarise yourself:
- "C Hello World"
- "C argc and argv meaning"
- "Pointer"
- "C iterators"
- "C conditionals"
- "C main return values"
Read
Actual Programming
Okay, now to the easiest part of learning C - the syntax. A common misconception that beginners hold when learning a new language is that the most important and hardest aspect is the syntax, or actually writing the code. Any good programmer should be able to learn the syntax to a new language in a couple of days, but it can take months to develop an efficient and effective programming style.
I will put "quiz" questions along the way so you can make sure you know the stuff before moving on.
Deconstructing a C program
Lets have a look at a typical C program
Code
#include <stdlib>
#include <stdio>
int main(int argc, char* argv[]){
printf("Hello world!\n");
return 0;
}Now, lets go line by line and analyse the code
Variables
Variables store data in memory. In C, you do it like this.
Code
int year = 2016;
DWORD dwflashDuration;
unsigned char = 'f'';A constant variable is just a variable that cannot be changed.
Code
const int encryption_key = 5497512145; OR
int const encryption_key = 5497512145;the "const" can come before or after data type declaration, pick one and stick to it.
Protip: an "unsigned" variable basically means it can only be positive, doubling the "range" of the variable.
Quiz: How many bytes does a signed int hold?
Global variables vs Local variables
Global variables are variables that are declared outside of any function.
aka:
Code
#include <stdlib>
#include <stdio>
char* name = "caiveman-senpai" <- Global variable, can be used anywhere in the file.
int main(int argc, char* argv[]){
int port = 1337; <- Local variable, can only be used inside the function
return 0;
}Protip: Try to avoid using global variables, if not at all. 99% of the time there is a better way of doing it (especially in c++)
Loops and conditionals
These are the two core principles found in any programming language.
There are a number of loops that you can use in C, the two most common ones being
Code
while (condition)Code
for (variable; condition; iterator)counting to 100 using each loop
Code
#include <stdio>
#include <stdlib>
int main(int argc, char*argv[]){
int i = 0;
while (i <= 100){
printf("%d\n", i);
i++;
}
for (int i =0; i <= 100; i++){
printf("%d\n", i);
}
return 0;
}There are more loops, such as the do - while loop, but you don't really need to know these, and it's more "syntactic sugar" to save the programmer a few lines of code.
Input and Output
Input
There are couple of input methods in C, and it is a little bit contentious on which one you should use. Some people use fgets() or getline() but for the purpose of this tutorial I will use scanf.
Example:
Code
#include <stdlib>
#include <stdio> <<<<< Standard input and output library
int main(int argc, char* argv[]){
int sum;
printf("Enter an int\n");
scanf("%d", &sum); << Get an input into the address of sum
printf("%d\n", sum);
return 0;
}Quiz: Think of how you could get multiple characters of input using loops and scanf()...
Output
Use printf for output in C
Code
printf("%d\n", integer);
printf("%s\n", string);
printf("%d and %.6f", integer, float to 6 places);Strings
Strings are a tricky one in C, because unlike other languages where they are stored as an object, strings are literally just arrays of characters.
Two ways of making a string
Code
char* str = "this string can be as long as u like, but you can't change it once defined (easily)";
char str2[10] = "10 chars";All strings end with the null character '\0' so the pc knows when to stop reading. There are obvious advantages and disadvantages to both.
In C++, it is much better because there is actually an inbuilt function in the <string> header
std::string str("sick string with lots of functions");
Further reading on C++ strings
Moving onto C++
C++ retains 99% of the syntax from C, but adds a crucial new concept. Classes and proper Object Oriented Programming.
I don't have time to explain in OOP detail but it is essentially programming Objects that interact with each other.
Read this -> https://www.codeproject.com/Tips/679615/...in-Seconds
Watch this -> https://www.youtube.com/watch?v=lbXsrHGhBAU
This keeps the code nice and organised so other people can understand what you are doing. It's really awesome once you get the hang of it.
Conclusion and further reading
Now if you actually did all those steps and learnt some basic computer science you should have a shallow understanding of the amazing language that is C.
The most helpful piece of advice I can give you is to read lots of good C code, and try to understand it, and replicate it.
Further reading and googling:
- malloc and it's uses
- c allocate and free memory
- c++ classes
- c++ class inheritence
- c multithreading
- c linked list
Projects to complete from here:
- Write a calculator that takes user input
- Make a linked list program using malloc
- Make a double-linked list using malloc and pointers
- Make a minesweeper hack
- Write a port scanner in C using winsock
- Write a hard hitting self rep decentralized mirai killer botnet with web api
~caiveman


![[Image: T4BXHDP.png]](https://i.imgur.com/T4BXHDP.png)

![[Image: FTnHw1z.gif]](https://i.imgur.com/FTnHw1z.gif)
![[Image: chain.png]](https://i.postimg.cc/NFnfH9zY/chain.png)