Showing posts with label Tutorials. Show all posts
Showing posts with label Tutorials. Show all posts

Wednesday, January 4, 2012

The C Beginnings: part 3



A couple of days back, someone left a comment on the C Language discussion page of this blog stating that a compiler(miracle compiler) was giving issues/errors. So today in this post, I want to focus on the different type of C compiler I have come across and highlight their advantages/features and the major disadvantage or difficultly that may be experienced in using them. I shall keep it very brief, here goes:

Dev C++  This is an open source (GNU) compiler developed by  ”bloodshed”. It can compile both C and C ++ source files, it can be used to write and edit header and resource files in addition to its primary use for C and C ++. It has ready-made template and can be used to develop windows Applications, Console Applications, DLL (digital linkage library) files.
A major difficulty a beginner might have with this compiler (especially if that person doesn’t know anything about the command prompt) is how to run the compiled source file(i.e. the generated  .exe file). 
A snapshot of the Dev C++ compiler
If the run button is clicked on the user interface of the compiler, it often opens the command prompt, runs the code and closes the command prompt, all these happen so fast that the user does not have enough time to see/view solution or the results of the written program that is displayed on the command line.
A simple solution to this is to put the whole code in a perpetual loop (usually a continuous while loop), for example
int main()
{
while(1)
{
                                // your code goes into this place
}
}
When the code is run, the while loop will prevent the command prompt from closing and the display on the command line can be read. If you wish to close the command prompt just close the command prompt window…
Another method is to place this 

getchar(); 

just before the  return 0;   in your code. This will force the command window to remain open until a character on the keyboard is pressed.
This compiler is free and available for download at their website http://www.bloodshed.net   you can check out their forum here http://www.bloodshed.net/forum
 
Borland C ++   is a C and C++ programming environment (that is, an integrated development environment) for MS-DOS and Microsoft Windows. It was the successor to Turbo C++, and included a better debugger, the Turbo Debugger, which was written in protected mode DOS.
A snapshot of the Borland C++ compiler
This compiler solves the problem encountered in the Dev C ++ compiler by running the compiled (.exe) file and displaying the results in an environment(like notepad) made by the compiler developers. This method takes the burden of having to run the file in the command prompt off the user by providing an easy way to see the results of the program/application. It is easy to use and has a simple user interface; most people find this compiler the best for them when they begin their journey into C programming.
 
You can check their website for more details on how to download the commercial one or the free one. Just go to this address http://www.borland.com  



Visual C ++  This compiler is made by Microsoft, it is a commercial  compiler even though a free version is available. It has a robust integrated development environment (IDE) for the C, C++, and C++/CLI programming languages user interface.  
A snapshot of the Microsoft's Visual C++ compiler

  It has tools for developing and debugging C++ code, especially code written for the Microsoft Windows API, the DirectX API, and the Microsoft .NET Framework .I personally think this compiler is too big in terms of size occupied by it on your computer when compared to other C compilers; it also uses a lot of system resources when compared to the other compilers I discussed above.

 
You can check their website(Microsoft visual C++) for more details on how to download the commercial one or the free one. Just go to this address  http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express 




Miracle C Compiler  
 The Miracle C Compiler runs under MS-Windows targeting MSDOS, all the  traditional C syntax are implemented in the compiler, including record (structures/unions) and enumerated data types, integer (int), long and floating point data types, user type definition, bit fields in structures, initializers for all data types.
Miracle C compiler snapshot
It spots a comprehensive library of functions, some example programs demonstrating compiler features and Windows Helpfile documentation is supplied with the installation package. To download this compiler point your browser to this address http://www.c-compiler.com

The above is just an overview of a few of the numerous available C compilers; it is not in any way a detailed list or even represents a large fraction of the available C compilers available today. It just merely shows you that compilers differ sometimes slightly while at other times very greatly from each other. My suggestion for you is to extensively read up materials on the compiler you wish to use before you use it. Some compilers introduce other keywords that are not present in the standard C library, so know your compiler well.


Happy New Year from Giga Frequency

Thursday, December 29, 2011

The C beginings: part 2

In the last part(i.e part 1) i said something about the origin of C, what C language is about and what it is generally used for. In this post i shall go a step further by giving you an example and explaining every line in details....
In most tutorials, they start by showing you how to display " Hello World " , this is always a good place to start but i will try to run through the C language so that you understand it in great details in the shortest possible time after all you are learning at Gigabyte speed.... So here go...
First i shall explain what happens when a C program/code is complied (i am assuming you know what a compiler is, if you do not; click here for a quick run through )
A program in C language is written by first including a library file that should contain all the functions you will be working with. This includes the particular file that the compiler needs to check in order to know what each of the functions you use stands for. Like in a library where each book holds or contains a particular information that you will need to enable you answer/solve a particular problem set, also for programming you have to tell the compiler which file contains the information it will need to solve a particular task. Below is a sample code that displays the words " Hello World " without the quotes on the command line. For a run through on batch programming in MS-DOS click here.

#include <stdio.h>

int main( )
{
       printf(" Hello World " );
       return 0;
}

I will start explaining the above code line by line. Note the C compiler is not sensitive to spaces in between the wordings, i have spaced the above code in this manner for clarity and it is also a good programming technique to make your code readable by other programmers or by yourself when you go through the code later.
The first line contains the #include <stdio.h>   first notice the word in-between the < > brackets. It is stdio.h and it means standard (std) - input(i) - output(o) - .header file(.h)  . This is the default file in the C standard library that contains functions and methods of interacting with the input and output devices of the machine(could be a computer-PC, micro controller, etc.) you run the code on. The # tells the pre-compiler that this line of code is meant for it, so the code is telling the pre-compiler to go and fetch the standard input output file and include it in the code. The < > bracket mean the the pre-compiler should search all the memory of the computer for that file, in order to specify to the pre-compiler that it should search only the current directory where the file containing your code is stored, you use double quotes(" ") .
The second line starts with int main( )  this tells the compiler that this is the main block where the critical or important code to run is. The int in front of the main( ) is not really necessary because by default all C main methods return an integer value (int for short).
The next line of code tells the compiler that starting from the {  to the } contains a block of code grouped under int main( )
Within the { } contain the code printf(" Hello World ");  meaning print formatted data Hello World to the default output device(in this case the command line screen). The semi colon at the end tells the compiler that it has gotten to the end of a statement. The return 0 on the next line just returns an integer of zero to indicate to the compiler that the code executed properly.
By this stage, i know you have  a lot of questions, feel free to leave them as comments below this post and i will answer it as soon as possible. If you wish to contact me for any reason use the form on the contact page of this blog.



Season's Greetings from Giga Frequency

Wednesday, December 21, 2011

What is a compiler?


A compiler is a special type of computer program that translates source code from a high-level programming language( human readable text file) into a lower level language (e.g., assembly language or machine code) that is a form that the computer can more easily understand. At its most basic level, a computer can only understand binary(  1 and  0). If a human being was to write an instruction for a computer using the language it understands(binary), that person will write very slowly and find the information contained in the long string of 1s and 0s incomprehensible, the person will also be prone to make a lot of mistakes and introduce errors in the intended instruction. A compiler is a computer program that was created to bridges this gap and make writing computer programs(instruction) more human friendly.
In the beginning when compilers were created, they were very simple programs that could only translate symbols into the bits, the 1s and 0s, the computer understood. Programs were also very simple, composed of a series of steps that were originally translated by hand into data the computer could understand. 

This method of programming was very time consuming and prone to mistakes by the writer of the computer instruction, so portions of this task were automated or programmed, and that was how the first compiler was written. This program assembled, or compiled, the steps required to execute the step by step program.
These simple compilers were used to write a more sophisticated compiler. With the newer version, more rules could be added to the compiler program to allow a more natural language structure for the human programmer to operate with. This made writing programs easier and allowed more people to begin writing programs. As more people started writing programs, more ideas about writing programs were offered and used to make more sophisticated compilers. In this way, compiler programs continue to evolve, improve and become easier to use.

If the compiled program can run on a computer whose CPU or operating system is different from the one on which the compiler runs, the compiler is known as a cross-compiler. On the other hand a decompiler is a program that translates from a low level language to a higher level one. A program that translates between high-level languages (e.g from python to JAVA for example) is usually called a language translator, language converter, or source to source translator. A language rewriter is usually a program that translates the form of expressions without a change of language.
A compiler's function include but may not be limited to the following: 
  • lexical analysis
  • pre-processing ( usually a pre-compiler built in with the compiler run through the code first)
  • parsing of the code for syntax errors
  • semantic analysis (Syntax-directed translation)
  • generation of the code
  • also to optimize the generated code
Hope you have gained some knowledge about compilers(at least the basic understanding). For a more detailed explanation you can check Wikipedia here.

Note:
The faults or errors introduced into the compiled program by an incorrect behavior of a compiler in compiling the source code can be very difficult to track down. 

Season Greetings from Giga Frequency

Friday, December 9, 2011

The C beginings...

Hello everyone, i have been posting stuffs about IT news and others.. Well i want to start the day off by discussing a very cool Language, the C language.
C is a general-purpose programming language which spots features such as
  • economy of expression
  • modern flow control and data structures 
  • and a rich set of operators. 
C is not a " very high level '' language, it is small(i.e. it is compact and tiny) , and is not specialized to any particular area of application. But its absence of restrictions and its generality make it more convenient and effective for many tasks than supposedly more powerful languages.

C was originally designed for and implemented on the UNIX operating system on the DEC
PDP-11, by Dennis Ritchie. The operating system, the C compiler - a compiler is a piece of software that converts human readable high language into machine readable language(code) , and essentially all UNIX
applications programs are written in C.
Production compilers also exist for several other machines, including the IBM System/370, the Honeywell 6000, and the Interdata 8/32. C is not tied to any particular hardware or system, however, and it is easy to write programs that will run without change on any machine that supports C.

...i will continue this c stuff later posts....stay tuned...
....to search all the categories on this blog click here

Saturday, December 3, 2011

Video album:Nano technology

Hello guys, today i wanna talk about Nano technology, a topic i fancy so much... Here goes...

Nanotechnology, or sometimes nanotech as some people call it, refers to a field of applied science which focuses on the control of matter on an atomic and molecular scale. Generally nanotechnology deals with structures about 100 nanometers or smaller, and involves developing materials or devices within these small size range, isn't that amazing.

Nanotechnology is an extremely diverse and multidisciplinary field, ranging from novel extensions of conventional device physics, to completely new approaches based upon molecular self-assembly, to developing new materials with dimensions on the nanoscale, or the scale of nothing, even to speculation on whether we can directly control matter on the atomic scale.

Nanotechnology has the potential to create many new materials and devices with wide-ranging applications, such as in medicine, electronics, and energy production the list goes on and on and is only limited by imagination. On the other hand, nanotechnology raises many of the same issues as with any other new and developing technology, including concerns about the toxicity and environmental impact of nanomaterials, and their potential effects on global economics.

Check out this video from youtube about Nano technology, Enjoy....


Tuesday, November 29, 2011

Batch Files:simple games

This is a nice video showing the application (advanced application) of batch files.....
It also gives you a better understanding of how batch files are written and how they work....
.......Enjoy......







Wednesday, November 23, 2011

Batch Files: getting started part IV

This is the part four of the series " Batch Files " , i though it will be nice to post a video on the application of batch files (just an example). The text about batch files i have posted before is quite boring (believe me, i know especially when you don't have a video to watch and do...) so it about time we saw some action.....check out this video i got from youtube, i decided to share it here for whoever is interested...
Enough text, lets watch....

Sunday, November 20, 2011

Batch Files:more on batch files

Hi everyone,
This are some commands you might find yourself using in a batch file....
the list is just to make you familiar with some commands...

For those of us who already know a little of MS-DOS commands, we will know that they are not case sensitive and just like all MS-DOS commands, all batch file commands are not case sensitive as well However, all commands listed below are in caps to help you identify what is a command and what is not.
@Does not echo back the text after the at symbol. This is most commonly used as @ECHO OFF to prevent any of the commands in the batch file from being displayed, just the information needed.
%1The percent followed by a numeric value, beginning with one, allows users to add variables within a batch file. The below line is an example of what can be used in a batch file. ECHO Hello %1
When the above one-line batch file is created, add your name after the batch file. For example, typing myname (being the name of the bat file) and then your name:
myname bob
would output:
Hello bob
Note: This can be extended to %2, %3, and so on.
::One of two ways of adding remarks into the batch file without displaying or executing that line when the batch file is run.

Friday, November 18, 2011

Batch Files: getting started part III

Now lets try to modify the first example a bit...i.e. make it more cooler, so this modified batch file example is going to list all the files in a folder and put the list in a new text file . We will use the directory command "dir" that you are already familiar with.
Open Notepad and enter the line "@echo off" (without quotes).
Next enter another line dir "C:\Program Files" > C:\list_of_program_files.txt(I'm assuming that your Program Files folder is on the C: drive). This will give us the two-line file @echo offdir "C:\Program Files" > C:\list_of_program_files.txt
 Now save this two-line file as "listprograms.bat" (without quotes) to some convenient location. Be sure that Notepad is saving as "All files" and not as a text file

  • Note that complete paths are used for files including the drive letter, even the files' extension is specified. 
  • Also note the quotes

Wednesday, November 16, 2011

Batch Files: getting started part 2


The first line in a batch file often consists of this command
   @echo off
By default, a batch file will display its commands as it runs. The purpose of writing this first command is to make sure the display is turned off. The command "echo off" turns off the display for the whole script, except for the "echo off" command itself. If you wish to make the turn off command apply to the echo command as well then you type the "at" sign "@" in front of the echo command
i.e. @echo off
It doesn't really affect the batch file whether you use "@echo off" or just "echo off" . The scripts we will discuss are very brief and omitting this line won't make any great difference. However, as a matter of good practice, it will be wise to enter it in our scripts, especially if the script is going to be a long one.
If you are familiar with  the commands used in CMD, one of them that we mostly use (or i use a lot) is the "dir" command, without the quotes...It lists all the files and folder in the present directory you are on...try it now
open command prompt,  to run command prompt >>
on windows XP click start...click run...and type cmd....OR go to accessories and click on cmd
on windows 7 just search for cmd and run it,
you will see the prompt below as your present directory if you installed to drive C: or something similar depending on your machine and where you installed your windows

C:\"your work-group e.g Users"\"your home folder">

now type in the dir command and a list of all the files and folders present there will be displayed...
the ones that have a <DIR> in front of them are folders while the rest with extensions e.g .txt .exe .bat are files...

The first batch file example i want to introduce will just

Sunday, November 13, 2011

Batch Files: getting started


Hi, today i wanna start a new series of topics on writing of a batch file to run on a windows machine....A lot of people run windows, so i felt this is a good way to get more from your window's machine.
Batch files allow MS-DOS and Microsoft Windows users to create a lists of commands to run one after the other once the batch file has been execute. Think of them as a to-do list of all what you want your computer to do.
For example, you could write a batch file to run frequently run commands, deleting a series of files, moving files, etc, you get the idea...just basic understanding of MS-DOS commands
is needed to write a batch file.
A good example of a batch file for someone who is more familiar with Windows or the MacOS is to think of a batch file as a shortcut in Windows or an icon on the MacOS. Much like a shortcut, batch files could be used to run one or more commands or programs through the command line.
Another example of a very well known batch file is the autoexec.bat, which is a simple boot file loaded each time the computer is loaded on MS-DOS and early Windows computers. This batch file contained all the necessary commands and programs used to run MS-DOS and Windows each time the computer booted.
As you can see the extension of a batch file is .bat or .cmd, files of this type are recognized and executed through an interface (sometimes called a shell) provided by a system file called the command interpreter. In Windows XP/ Vista the command interpreter is the file cmd.exe. The large assortment of versatile commands available in Windows XP/Vista/7 makes batch files a powerful tool.
Constructing a batch file consists of nothing more than opening any text editor like the accessory Notepad, entering some lines containing commands, and saving the file with an extension BAT or CMD. (The CMD extension is limited to newer Windows systems and is not recognized in Windows 9x/Me systems. In Windows XP, Vista, and 7 there is little practical difference between the two extensions.)

  * Don't use Wordpad or Word unless you are very careful to save all files in pure text format. The commands themselves are often quite simple and there is no need to learn a programming language. Those who wish can explore the intricacies that are available with branching and looping, just follow the links. I will be discussing straightforward application of batch files to everyday tasks. The focus will be on saving time and effort for some routine stuff like system housekeeping and simple file management.
....so stay tuned....

Thursday, November 10, 2011

WEP encryption:very lame

Hello,
you know guys, i still wonder why in this day and time people are still lame enough to use Wired Equivalent Privacy(WEP) encryption for their wireless networks when it is so easily cracked(in less than two hours). I was at a cafe and guess what? WEP encryption for their wireless hotspot...how lame is that?.....
well,
...if you don't know a lot about WEP, check it out here on Wikipedia
I decided to post this video i got from youtube to show you guys how easy it is to hack a wireless network, for those who already know, good for you :-).....
for those who don't know, well.....
This video shows one method of hacking a wireless WEP connection and gives you some tips on how to better secure your wireless.












TERMINAL COMMANDS:

Startx
/etc/init.d/networking start
airmon-ng
airmon-ng stop [wireless card name]
airmon-ng start [wireless card name]
airmon-ng

Friday, November 4, 2011

Also some more CMD stuff...

Also got it from youtube...i know it old info :-(  but for those who don't know them...here they are.......

if you have problems with denied access, run command prompt(cmd) as an administrator. That should fix it :-)...

1. Accessibility Controls - access.cpl
2. Accessibility Wizard - accwiz
3. Add Hardware Wizard - hdwwiz.cpl
4. Add/Remove Programs - appwiz.cpl
5. Administrative Tools - control admintools
6. Automatic Updates - wuaucpl.cpl
7. Bluetooth Transfer Wizard - fsquirt
8. Calculator - calc
9. Certificate Manager - certmgr.msc
10. Character Map - charmap
11. Check Disk Utility - chkdsk
12. Clipboard Viewer - clipbrd
13. Command Prompt - cmd
14. Component Services - dcomcnfg
15. Computer Management - compmgmt.msc
16. Control Panel - control
17. Date and Time Properties - timedate.cpl
18. DDE Shares - ddeshare
19. Device Manager - devmgmt.msc
20. Direct X Troubleshooter - dxdiag
21. Disk Cleanup Utility - cleanmgr
22. Disk Defragment - dfrg.msc
23. Disk Management - diskmgmt.msc
24. Disk Partition Manager - diskpart

Windows Command Tips

Just some CMD tips...i know it is not much...got it from youtube :-) .....


Saturday, October 29, 2011

Crash Course in X Windows Security last part

.....this is the concluding part of this article....enjoy...

7. Trojan X clients - xlock and X based logins

Can you think of a more suitable program for installing a
password-grabbing trojan horse than xlock? I myself cannot. With a few
lines added to the getPassword routine in xlock.c, the password of
every user using the trojan version of xlock can be stashed away in a
file for later use by an intruder. The changes are so minimal, only a
couple of bytes will tell the real version from the trojan version.

If a user has a writable homedir and a ./ in her PATH environment variable, she is vulnerable to this kind of attack. Getting the password is achieved by placing a trojan version of Xlock in the users homedir and waiting for an invocation.  The functionality of the original Xlock is contained in the trojan version.  The trojan version
can even tidy up and destroy itself after one succesfull attempt, and the user will not know that his password has been captured.

Xlock, like every password-prompting program, should be regarded with suspicion if it shows up in places it should not be, like in your own homedir.
Spoofed X based logins however are a bit more tricky for the intruder to accomplish.  He must simulate the login screen of the login program ran by XDM. The only way to ensure that you get the proper XDM login
program (if you want to be really paranoid) is to restart the X-terminal, whatever key combination that will be for the terminal in question.


8. X Security tools - xauth MIT-MAGIC-COOKIE

To avoid unathorized connections to your X display, the command xauth for encrypted X connections is widely used. When you login, xdm creates a file .Xauthority in your homedir. This file is binary, and readable only through the xauth command. If you issue the command

$ xauth list

you will get an output of:

Friday, October 28, 2011

Crash Course in X Windows Security part 2

 Hello guys...yesterday i started this small piece on window x security...this is the part 2....



5. Snooping techniques - reading keyboard

If you can connect to a display, you can also log and store every
keystroke that passes through the X server. A program circulating the
net, called xkey, does this trick. A kind of higher-level version of
the infamous ttysnoop.c. I wrote my own, who could read the keystrokes
of a specific window ID (not just every keystroke, as my version of
xkey).  The window ID's of a specific root-window, can be acquired
with a call to XQueryTree(), that will return the XWindowAttributes of
every window present. The window manager must be able to control every
window-ID and what keys are pressed down at what time.  By use of the
window-manager functions of Xlib, KeyPress events can be captured, and
KeySyms can be turned into characters by continuous calls to
XLookupString.

You can even send KeySym's to a Window. An intruder may therefore not
only snoop on your activity, he can also send keyboard events to
processes, like they were typed on the keyboard.  Reading/writing
keyboard events to an xterm window opens new horizons in process
manipulation from remote. Luckily, xterm has good protection
techniques for prohibiting access to the keyboard events.


6. Xterm - Secure keyboard option

A lot of passwords is typed in an xterm window. It is therefore
crucial that the user has full control over which processes can read
and write to an xterm.  The permission for the X server to send events
to an Xterm window, is set at compile time. The default is false,
meaning that all SendEvent requests from the X server to an xterm
window is discarded. You can overwrite the compile-time setting with a
standard resource definition in the .Xdefaults file:

xterm*allowSendEvents    True

Thursday, October 27, 2011

Crash Course in X Windows Security

 This article is  by
runeb / cF --- runeb@stud.cs.uit.no  ---   http://www.cs.uit.no/~runeb

for those of us who don't really know so much about the x window, a detailed description can be found here on Wikipedia

     Content
1. Motivation / introduction
2. How open X displays are found
3. The local-host problem
4. Snooping techniques - dumping windows
5. Snooping techniques - reading keyboard
6. Xterm - secure keyboard option
7. Trojan X programs [xlock and xdm]
8. X Security tools - xauth MIT-MAGIC-COOKIE
9. Concluding remarks


1. Motivation / introduction

X windows pose a security risk. Through a network, anyone can connect
to an open X display, read the keyboard, dump the screen and windows
and start applications on the unprotected display. Even if this is a
known fact throughout the computer security world, few attempts on
informing the user community of the security risks involved have been
made.  This article deals with some of the aspects of X windows
security. It is in no sense a complete guide to the subject, but
rather an introduction to a not-so-known field of computer
security. Knowledge of the basics of the X windows system is
necessary, I haven't bothered including an introductory section to
explain the fundamentals. I wrote some code during the research for
this article, but none of it is included herein.  If the lingual flow
of English seem mayhap strange and erroneous from byte to byte, this
is due to the fact that I'm Scandinavian.  Bare with it. :)


2. How open X displays are found

An open X display is in formal terms an X server that has its access
control disabled. Disabling access control is normally done with the
xhost command.

$ xhost +

allows connections from any host. A single host can be allowed
connection with the command

$ xhost + ZZZ.ZZZ.ZZZ.ZZZ

where Z is the IP address or host-name. Access control can be enabled
by issuing an

$ xhost -

command. In this case no host but the local-host can connect to the
display.  Period. It is as simple as that - if the display runs in
'xhost -' state, you are safe from programs that scans and attaches to
unprotected X displays.  You can check the access control of your
display by simply typing xhost from a shell. Sadly enough, most sites
run their X displays with access control disabled as default. They are
therefore easy prey for the various scanner programs circulating on
the net.

Anyone with a bit of knowledge about Xlib and sockets programming can
write an X scanner in a couple of hours. The task is normally
accomplished by probing the port that is reserved for X windows,
number 6000. If anything is alive at that port, the scanner calls
XOpenDisplay("IP-ADDRESS:0.0") that will return a pointer to the
display structure, if and only if the target display has its access
control disabled. If access control is enabled, XOpenDisplay returns 0
and reports that the display could not be opened.

E.g:

Xlib: connection to "display:0.0" refused by server
Xlib: Client is not authorized to connect to Server

The probing of port 6000 is necessary because of the fact that calling
XOpenDisplay() on a host that runs