C Cracking, or Phreaking it’s on C programming,



0 Comment

C programming for the complete newbieHello there im Krisis you may have seen me on irc.hackersclub.com. Well I thought it was about time to write an article like everyone else. Butunlike many others mine wont be on Hacking, Cracking, or Phreaking it’s on C programming, yousee I’m not the best hacker but I’m an ok programmer. So here it goes.

This is based for absolutebeginners so those of you like my friend Chrak wouldn’t be interested in it.1st lets talk about some of C ‘s history. C was invent by Dennis Ritchieand KennethThompson.

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

They modeled it after the language they were using called B. Cwas a subset of B hencethe name. C was made because B was going out of style and they needed a newlanguage to write UNIX in. Yes UNIX was made in C.

C was made popular very quickly becauseevery UNIX sold had a Ccompiler. A compiler is a program thats looks at your source code andtransfers it into object code, after it is transfered into object code it must be linked, once it’slinked it can beexecuted./***********************************************************************************************/2nd Lets talk about variables they are your integers and characters and soon. You have many data types they are.int integerschar characterslong int bigger integersshort int same as intfloat decimal numbersdouble even bigger decimal numbersTo define a variable 1st you must put something like int MyNum;MyNum = 2;or for a character value it would be like char name; name= ‘Jim’;notice the ” you must have those around character values, they are notneeded for integers ordecimals./***********************************************************************************************/3rd I’ll tell you about stuff like #include and #define.

#include is usedto tell the compiler that whatever is in the brackets just be included like its part ofyour code. #include ;stdio.h; #define is used to define something Like the color of a truck or car.#define TRUCK “red”#include and #define must come before any functions are even prototyped(I’ll talk about this later). /***********************************************************************************************/ 4th I’ll talk about functions. Every program must have at least onefunction. That functions name must be main().

The () tells the compiler that it is afunction. All functions must return a value in the main() function a 0 is usually returned. In yourfunctions you willwant to use comment’s to explain your code a comment is begun by using /*and ended by using */ .I will now show you your 1st program.#include <stdio.h> /* Used in most standard Input Output Programs */main()/* Beginning Brackets used to show the beggining ofa block of code */printf(“Hello World”); /* A function already written in Stdio.h */return 0; /* Value returned from the program */} /* Ending bracket used to show end of a block of code */now compile your program in your compiler if your using UNIX do it like this gcc hello.c -o Helloand then run your program bye typing in .

/Hello/***********************************************************************************************/5th I’ll talk about output which is essential to almost all programs. I’ll start you out with printf(); It is defined in Stdio.h so every time youcall printf(); you must include Stdio.h .printf(); ‘s syntax is quite easy you just used it like thisprintf(“What ever you want outputted”);to output variables you do it like this char dog=’scruffy’;printf(“My dogs name is %c”, dog); notice the %c it tells the compiler tolook for a character variable.Now for Integers and Decimalsint age=16;printf(“I am %d year’s old”, age); use %d to print out decimals and integers /***********************************************************************************************/6th Lets talk about multiple functions. When you have more than one functionyou must prototype it. Here is an example.

#include ;stdio.h;void hello(); /* This is a prototype notice the void. Void tells thecompiler that this functiondoes not return a value like return 0; */main() /* Main doesnt ever need to be prototyped */hello();return 0;}void hello(); /* Your prototype must look exactly like your real function */printf(“Im in the function hello!”);} Void is your return type. Other return types are int for returning integersuse float to return decimals and so on.

/***********************************************************************************************/7th I’ll introduce you to input. Ill teach you how to use gets() and scanf()and fgets() properlygets() takes a variable and place data into as do scanf() and fgets() In thenext example I will use all 3#include <stdio.h>#include <conio.h>main()int x, y, z, ans;printf(“What is X ‘s value “);gets(x);printf(“What is Y ‘s value “);scanf(“%d”, &y); /* Scanf is odd I dont recommend using it try and use getsand fgets more */ /* Whatever is used to print the variable type you are using is placed inparantheses and & is used in front of whatever variable you are using */printf(“What is Z ‘s value”);fgets(z, 25, stdin); /* fgets is kinda tricky at first glance */ /* first off you put what variable you want then how many integers orcharacterslong it can be and then stdin,stdin is a macro defined in stdio.h it is usedto represent standard input */ans=x+y+z;printf(“Ans equals %d”, ans);/***********************************************************************************************/8th Lets talk about decision statements like if and else.here is how if is usedif(VariableName==5) printf(“Your variable is 5”); }else is used after if, it is used like thisif(VariableName==5)printf(“Your variable is 5”);}elseprintf(“I dont know what your variable is”);}/***********************************************************************************************/9th Ill talk about While loops and do-while loops. Loops aren’t as hard asthey may seem.

while loops are easy. Just watch and learn.#include <stdio.h>main()int x=1;while(x<2600)printf(“X=%d”,x);x++; /* adds 1 to x */}return 0;} /* While loops dont have to happen only if the right sequence happens dothey execute */Loops can be placed inside of IF and else statements if you want. That canbe very helpful if you want a process to happen a bunch if something happens Like the user pressingX instead of Y.Do-While loops are just as easy.

They automatically execute at least once.#include <stdio.h>main()int x=1;doprintf(“X=%d”,x);x++;}while(x<2600);return 0;}The do tells the program to do this at least once and it doesn’t see thewhile until it has already do the do./***********************************************************************************************/10th I’m going to tell you about another kind of loop the for loop.

Forloops execute a given number of times and then stop. For loops are executed like this.for(x=1; x<100; x++)printf(“X=%d”,x);}That prints 1 through 100. Thats about it about for loops there not veryhard. They can be prettyuseful. But I dont use them alot I’m into While loops.

/***********************************************************************************************/11th is all about Arrays. Arrays are consecutive places in memory. Arrayscan be integers and characters. They can be just about any size.

Here is an example.#include <stdio.h>main()int i2int i1 =2600int i2 =1982 /* Year I was born */printf(” I1 = %d “,i1); printf(” I2 = %d “,i2);return 0;}See how easy that was Arrays aren’t very hard at all./***********************************************************************************************/12th I’ll tell you about passing parameters to functions. Its nots to hardbut I’ve said that about everything.

First you must prototype it before main() I hope youremember how to prototype.Here is an example of passing parameters.#include <stdio.h>int next(int x);main()int age;printf(“please enter you age “);fgets(age, 3 ,stdin);age(age); /* Age is passed on to the next function */return 0;}next(int x);x++;printf(“Next year you will be %d”, x);return 0;}/***********************************************************************************************/13th I’ll say a little sumthin about why C is good to Hacking. It’s goodbecause it is so portable C can be used on all processors and Operating Systems.

So if yourexploit you just wrote works onone UNIX like OS odds are it will work on another, therefore you dont haveto write a whole newprogram just to get a root shell./***********************************************************************************************/Last but not least a sample program.#include <stdio.h>int blah(int x,int y);main()int a,b,r;printf(“Enter some numbers “);scanf(“%d”, &a);scanf(“%d”, &b);r=blah(a,b);printf(“R = %d”,r);return 0;}int blah(int x, int y)return x * y; }What does blah do and how does it work? You tell me./***********************************************************************************************/Thats it for my little tutorial on C. I hope it helped you some.

But forfurther info on C I suggest reading C programming in 12 easy lessons by Greg Perry from Sams Publishing.It helped me a shitload on learning C. You also might want to get some bookson C++ a subset of CYou can mail me at emailprotected

x

Hi!
I'm Adrienne!

Would you like to get a custom essay? How about receiving a customized one?

Check it out