Friday, February 4, 2011

Some system programing in C Language..

       My another blog on C programming: http://assemblygraphicsinc.blogspot.com/

Its too late for me. Its 2.00AM at night. There is pin drop silence all around, but i am still here to share knowledge among you.

I am going to give you some example regarding low level programing in C. Low level programming is not only interesting to learn but it is faster in execution too. If you have knowledge to understand low level language you will be the start programmer in you college life. 

Here I am going to give an example to access a hardware using low level code. 

This is a virus program named Dancing Dall which change the text on DOS mod. Would you like to know.. let see



#include "stdio.h"
#include "conio.h"
#include "dos.h"
void main(void)
{
   char far *scr;
   int i;
   //change address to 0xB00000000L for monochrome adapter
  scr=(char far *)0xB0008000L;
  while(!kbhit())
  {
      for(i=0;i<=4999;i+=2)
     {
          if(*(scr+i)>='A' && *(scr+i)<='Z')
               *(scr+i)=*(scr+i)+32;
         else if(*(scr+i)>='a' && *(scr+i)<='z')
              *(scr+i)=*(scr+i)-32;
    }
   delay(150);
  }

}

The program below works in TurboC (or MS C).  In some compilers, you
have to fold the address to 20 bits, but here the segment and offset
are separate.


Take another example to Reboot a system


#define MAGIC 0 /* for cold restart */
/* #define MAGIC 0x1234 /* for warm restart */
#define BOOT_SEG 0xffffL
#define BOOT_OFF 0x0000L
#define BOOT_ADR ((BOOT_SEG << 16) | BOOT_OFF)
#define DOS_SEG 0x0040L
#define RESET_FLAG 0x0072L
#define RESET_ADR ((DOS_SEG << 16) | RESET_FLAG)
 

int main()
{
       void ((far *fp)()) = (void (far *)()) BOOT_ADR;
      *(int far *)RESET_ADR = MAGIC;
      (*fp)();
      return 0; /* never gets here, but keeps compiler happy */
}

So Is this program nice to know? Give feedback to get more programing in any lanugage.. hope you have enjoyed this program

Note: Intention to blog this kind of program to share knowledge for learner. Don't miss use the programming skill. Instead of being a destructive programmer be a constructive one.