/* Ajith - Syntax Higlighter - End ----------------------------------------------- */

6.14.2008

Using GOOGLE as proxy to hide IP-Adress

NOTE (UPDATED on FEBRUARY 30th 2009): This trick seems to be no more fool proof as sites like tracemyip tracks down your exact IP-Adress even by using the Google Translation Service.

We know that GOOGLE has changed the way we access the web. It has simply became the stepping stone for any body who want to know information about anything in this world .. offcourse of universe too. It had wide variety of web based applications namely search, maps, gmail, gears, adsense, adwords, analyzers, language translators and many in its arsenal.

Now we can use one of the services of GOOGLE as proxy so that we can access the web anonymously without revealing our ipadress, location of our ISP. You might be wondering how our location is revealed out? Let us try out a simple experiment. Just visit the site

http://www.ip-adress.com/
We can see that the site reveals my ISP ipadress as 59.164.98.133 and my ISP location in a google map as Bangalore. If we further check out the site we can find out that the site has ecen information about our browser version, plugins installed, our screen resolution and many other things got revealed.
So how does GOOGLE service can be used a proxy? Let us check out the language translation service provided by the GOOGLE. You can get the link to this service if you type www.google.com and we can see a link to language tools or just click this link.

http://www.google.co.in/language_tools?hl=en

Once you click you are into that page we can see a option named "Translate a Webpage" with options to translate from one language to other. Note we cant translate same language to the same one i.e. for example from English to English. If we try to do it we get a GOOGLE ERROR.
Not let us try to access the site http://www.ip-adress.com/ asking GOOGLE translation service to convert the site from from French to English. Since nothing French is there in that site is simply displayed in English.
Strange it displays my ISP ip-adress as 209.85.170.136 and its location as United States. If I check out the site further I found out that I am getting redirected via google server present at Mountain View, US which is acting as proxy to access the site http://www.ip-adress.com/.
So we can access the any site in this way without revealing our information much. Thats really cool trick to stay anonymous. But there is a problem by doing so as the images cannot seen properly by using this technique. But even if a site is bocked we can access its content in this way. I tried out this trick on one of the torrent sites that are blocked but I can still access its contents.

5.28.2008

Converting mobilephone into webcam

Camera in a mobilephone is getting better day by day and reached upto 5MP with good clarity and cool features. Until now we have used mobile camera for just taking pictures and recording video's. But now we can even use it as a webcam for chatting online on any popular messenger service available.

Let us check out some of the cool softwares that converts a camera phone into a webcam.

Mobiola
It converts your phone into a webcam via Bluetooth or through USB cable.It consists of two parts - a PC application with virtual camera driver and Symbian sis application for smartphone.Features:
  • Transforms your mobile phone into high-quality PC webcam.
  • Connects through USB or Bluetooth.
  • Screen Capture functionality.
  • Works with Skype, Yahoo, YouTube, MSN, AOL IM, ICQ and many others as standard USB webcam.
List of compatible devices (Check out the home site for updated list)
RIM Blackberry - Any Blackberry devices equipped with camera
Windows Mobile - Windows Mobile 5 and 6 devices equipped with camera including Smartphones
Nokia 6600, 6620, 7610, 6630, 6670, 6260,6680, 6681, 6682, 3230, N70,N90, 3250, 5500, E50, E51, E65, E70, E90, N71, N73, N76, N80, N81, N82, N91,N92, N93, N93i, N95, N96
Sony-Ericsson P1i, P990, M600, W950, W960, P800, P900, P910, P990, G700, G900
Motorola Z8, Z10

If you don't have a webcam, or want a more versatile solution to your current cam, then Mobiola WebCam is an essential download.

Limitations:
30 day Trial Period Limited to 5 minutes connection.

Actual Link: http://www.warelex.com/

WWigo
This is an alternative for Mobiola since it is free to use. It has got all most all the features supported by Mobiola.

Actual Link: http://www.motvik.com/

4.07.2008

TinTin E-Book collection

There are download links available below each and every Image of the TiTle book ... If any problem in seeing them please leave a comment .....

01. Tintin in the Land of the Soviets (1930)



02. Tintin in the Congo (1931)



03. Tintin in America (1932)



04. Cigars of the Pharaoh



05. The Blue Lotus (1936)



06. The Broken Ear



07. The Black Island (1938)



08. King Ottokar's Sceptre (1939)



09. The Crab with the Golden Claws (1941)



10. The Shooting Star (1942)



Checkout TinTin ebook collection part2 for the books from 11 to 20

Checkout TinTin ebook collection part3 for the remaining editions.

4.03.2008

Optimization levels in GCC

Compilers have become pretty smart as they can perform all sorts of code transformations — from simple inlining to sophisticated register analysis — that make compiled code run faster.

In most situations, faster is better than smaller, because disk space and memory are quite cheap for desktop users. However, for embedded systems small is often at least as important as fast because of a commonplace environment consisting of extreme memory constraints and no disk space, making code optimization a very important task.

Optimization is a complex process. For each high-level command in the source code there are usually many possible combination's of machine instructions that can be used to achieve the appropriate final result. The compiler must consider these possibilities and choose among them.

In general, different code must be generated for different processors, as they use incompatible assembly and machine languages. Each type of processor also has its own characteristics -- some CPU's provide a large number of registers for holding intermediate results of calculations, while others must store and fetch intermediate results from memory. Appropriate code must be generated in each case.

Furthermore, different amounts of time are needed for different instructions, depending on how they are ordered. GCC takes all these factors into account and tries to produce the fastest executable for a given system when compiling with optimization.

Turning optimization flags ON makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program.

NOTE: While the GCC optimizer does a good job of code optimization, it can sometimes result in larger or slower images (the opposite of what you may be after). It’s important to test your image to ensure that you’re getting what you expect. When you don’t get what you expect, changing the options you provide to the optimizer can usually remedy the situation.

Let us see various optimization levels provided by GCC

LEVEL 0: -O0 Optimization
At this optimization level GCC does not perform any optimization and compiles the source code in the most straightforward way possible. Each command in the source code is converted directly to the corresponding instructions in the executable file, without rearrangement. This is the best option to use when debugging with a source code debugger (such as the GNU Debugger, GDB). It is the default level of optimization if no optimization level option is specified. It can be specified as
[bash]$gcc -O0 hello.c -o hello
or
[bash]$gcc hello.c -o hello

NOTE: -O0 is actually -(Capital O)(Number 0). Similarly -O1 is -(Capital O)(Number 1).

LEVEL 1: -O1 Optimization (-O)
In the first level of optimization, the optimizer’s goal is to compile as quickly as possible and also to reduce the resulting code size and execution time. Compilation may take more time with -O1 (over -O0), but depending upon the source being compiled, this is usually not noticeable. Level 1 also has two sometimes conflicting goals. These goals are to reduce the size of the compiled code while increasing its performance. The set of optimizations provided in -O1 support these goals, in most cases.

The -O1 optimization is usually a safe level if you still desire to safely debug the resulting image. Check out the table given below for optimizations enabled at different levels.

NOTE: Any optimization can be enabled outside of any level simply by specifying its name with the -f prefix, for example, to enable the defer-pop optimization, we would simply define this as
[bash]$ gcc -fdefer-pop hello.c –o hello

We could also enable level 1 optimization and then disable any particular optimization using the -fno- prefix, like this:
[bash]$ gcc -O1 -fno-defer-pop -o test test.c

This command would enable the first level of optimization and then specifically disable the defer-pop optimization.

LEVEL 2: -O2 Optimization
The second level of optimization provides even more optimizations (while including those in -O1, plus a large number of others). Only optimizations that do not require any speed-space tradeoffs are used, so the executable should not increase in size. The compiler will take longer to compile programs and require more memory than with -O1. This option is generally the best choice for deployment of a program, because it provides maximum optimization without increasing the executable size. It is the default optimization level for releases of GNU packages. The second level is enabled as shown below:
[bash]$gcc -O2 hello.c -o hello


LEVEL 2.5: -Os Optimization
The special optimization level (-Os or size) enables all -O2 optimizations that do not increase code size; it puts the emphasis on size over speed. This includes all second-level optimizations, except for the alignment optimizations. The alignment optimizations skip space to align functions, loops, jumps and labels to an address that is a multiple of a power of two, in an architecture-dependent manner. Skipping to these boundaries can increase performance as well as the size of the resulting code and data spaces; therefore, these particular optimizations are disabled.

-Os optimization level simply disables some -O2 optimizations like -falign-labels, -falign-jumps, -falign-labels, and -falign-functions. Each of these has the potential to increase the size of the resulting image, and therefore they are disabled to help build a smaller executable. The size optimization level is enabled as:
[bash]$gcc -Os hello.c -o hello

In gcc 3.2.2, reorder-blocks is enabled at -Os, but in gcc 3.3.2 reorder-blocks is disabled.

LEVEL 3: -O3 Optimization
The third and highest level enables even more optimizations by putting emphasis on speed over size. This includes optimizations enabled at -O2 and rename-register. The optimization inline-functions also is enabled here, which can increase performance but also can drastically increase the size of the object, depending upon the functions that are inlined. The third level is enabled as:
[bash]$gcc -O3 hello.c -o hello

Although -O3 can produce fast code, the increase in the size of the image can have adverse effects on its speed. For example, if the size of the image exceeds the size of the available instruction cache, severe performance penalties can be observed. Therefore, it may be better simply to compile at -O2 to increase the chances that the image fits in the instruction cache.

Architecture Specification
The optimizations discussed thus far can yield significant improvements in software performance and object size, but specifying the target architecture also can yield meaningful benefits.

The -march option of gcc allows the CPU type to be specified

The default architecture is i386. GCC runs on all other i386/x86 architectures, but it can result in degraded performance on more recent processors. If you're concerned about portability of an image, you should compile it with the default. If you're more interested in performance, pick the architecture that matches your own.


References:

1. Optimization in GCC
2. An Introduction to GCC - for the GNU compilers gcc and g++.

2.19.2008

Compilation process in GCC

Compiling a C program - Compiling a simple C program using gcc.

Above article is a high level view of compliation in gcc. In present article let us see in depth view of the compilation order or flow in gcc which is a default C compiler in GCC.

gcc goes through a sequence of different intermediate steps before generating final executable. Those intermediate steps are the result of different tools which are invoked internally to complete the compilation of the source code.

The whole Compilation process is broken down into following phases:

  • Preprocessing
  • Compilation
  • Assembly
  • Linking

As an example, we will examine these compilation stages individually using the same ‘hello.c’ program given below:

#include <stdio.h>
#define STRING "Hello World"

int main (void)
{
printf ("My First program - %s\n",STRING);
return 0;
}

NOTE: We dont need to manually go through all the intermediate stages to generate a executable using gcc. All these stages are directly taken care transparently by gcc internally, and can be seen using the -v option.

Although 'hello.c' program is very simple it uses external header files and libraries, and so exercises all the major steps of the compilation process. If we compile the 'hello.c' with a simple command namely gcc hello.c then we end-up creating an executable file called a.out.

Back in the days of the PDP computer, a.out stood for "assembler output". Today, it simply means an older executable file format. Modern versions of Unix and Linux use the ELF executable file format. The ELF format is much more sophisticated. So even though the default filename of the output of gcc is "a.out", its actually in ELF format.

The Preprocessor
Basically C Preprocessor is responsible for 3 tasks namely:
  • Text Substitution,
  • Stripping of Comments, and
  • File Inclusion.
Text Substitution and File Inclusion is requested in our source code using Preprocessor Directives.

The lines in our code that begin with the “#” character are preprocessor directives.

In 'hello.c' program the first preprocessor directive requests a standard header file, stdio.h, be included into our source file. The other one requests a string substitution to take place in our code.

So in preprocessor stage those included header files and defined macros are expanded and merged within the source file to produce a transitory source file, which the standard calls a Translation unit. Translation units are also known as compilation units.

The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform a C program before compilation. To perform just preprocessing operation use the following command:
[bash]$ cpp hello.c > hello.i
The result is a file named hello.i which contains the source code with all macros expanded.

By convention, preprocessed files are given the file extension ‘.i’ for C programs and ‘.ii’ for C++ programs.

NOTE: By default the preprocessed file is not saved to disk unless the -save-temps option is used in gcc so we are just using the redirection operator to save a copy of preprocessed file.

By using gcc's “-E” flag we can directly do the pre-processing operation.
[bash]$ gcc -E hello.c -o hello.i
Now we will try to check the contents of the preproccessed input file. Since the stdio.h file is fairly large the resultant output is cleaned up a bit.
# 1 "hello.c"
# 1 "/usr/include/stdio.h" 1 3
# 1 "/usr/include/_ansi.h" 1 3
# 1 "/usr/include/sys/config.h" 1 3
# 14 "/usr/include/sys/config.h" 3
# 25 "/usr/include/sys/config.h" 3
# 44 "/usr/include/sys/config.h" 3

# 40 "/usr/include/stdio.h" 2 3
# 1 "/usr/include/sys/reent.h" 1 3

int main(void){

printf ("My First Program - %s\n", "HELLO WORLD" );
return 0;
}
Since our program has requested the stdio.h header be included into our source which in turn, requested a whole bunch of other header files. So, the preprocessor made a note of the file and line number where the request was made and made this information available to the next steps in the compilation process. Thus, the lines,
# 40 "/usr/include/stdio.h" 2 3
# 1 "/usr/include/sys/reent.h" 1 3
indicates that the reent.h file was requested on line 40 of stdio.h. The preprocessor creates a line number and file name entry before what might be "interesting" to subsequent compilation steps, so that if there is an error, the compiler can report exactly where the error occurred.

The Compiler
The next stage of the process is the actual compilation of the preprocessed source code to assembly language, for a specific processor (Depending upon the target processor architecture the source code is converted into particular assembly language and it can be known as cross-compilation).

By using “-S” flag with gcc we can convert the preprocessed C source code into assembly language without creating an object file:
[bash]$ gcc -Wall -S hello.i -o hello.s
The resulting assembly language is stored in the file ‘hello.s’.

NOTE: The assembly code generated depends upon the PC architecture and other reasons. I am just attaching the assembly code generated with the Cygwin - Linux Emulator.


NOTE: Above Assembly code contains a call to the external printf function.

The Assembler
We know that MACHINES (i.e. a computer) can understand only Machine-Level Code. So we require an ASSEMBLER that converts assembly code in "hello.s" file into machine code. Eventhough it is a straightforward one-to-one mapping of assembly language statements to their machine language counterparts, it is tedious and error-prone if done manually.

NOTE: ASSEMBLER was one of the first software tools developed after the invention of the digital electronic computer.

If there are any calls to external functions in the assembly code, the Assembler leaves the addresses of the external functions undefined, to be filled in later by the Linker.

The Assembler as in gcc can be invoked as shown below.
[bash]$ as hello.s -o hello.o
As with gcc, the output file is specified with the -o option. The resulting file ‘hello.o’ contains the machine level code for 'hello.c' program.

or

By using “-c” flag in gcc we can convert the assembly code into machine level code:
[bash]$ gcc -c hello.c
The Linker
The final stage of the compilation process is producing a single executable program file by linking set of object files. An object file and an executable file come in several formats such as ELF (Executable and Linking Format) and COFF (Common Object-File Format). For example, ELF is used on Linux systems, while COFF is used on Windows systems.

In practice, an executable file requires many external functions from system and C run-time libraries. The linker will resolve all of these dependencies and plug in the actual address of the functions.

The linker also does a few additional tasks for us. It combines our program with some standard routines that are needed to make our program run. For example, there is standard code required at the beginning of our program that sets up the running environment, such as passing in command-line parameters and environment variables. Also, there is code that needs to be run at the end of our program so that it can pass back a return code, among other tasks. It turns out that this is no small amount of code.

Actually the mechanism used internally by gcc to link up different files is a bit complicated. For example, the full command for linking the 'hello.c' program might look as shown below:
[bash]$ ld -dynamic-linker /lib/ld-linux.so.2/usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i686/3.3.1/crtbegin.o-L/usr/lib/gcc-lib/i686/3.3.1 hello.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh/usr/lib/gcc-lib/i686/3.3.1/crtend.o /usr/lib/crtn.o
Luckily we are never asked to type the above command directly -- the entire linking process is handled transparently by gcc when invoked as follows:
[bash]$ gcc hello.o
This links the object file ‘hello.o’ to the C standard library, and produces an executable file ‘a.out’.
[bash]$ ./a.out
My First Program - Hello World
An object file for a C++ program can be linked to the C++ standard library in the same way with a single g++ command.