Sunday, April 29, 2012

User Mozilla XULRunner for Development (Sample Code Included)

0 comments
Step 1 – Download XULRunner: The
Mozilla developer page lists 1.9.2.15
as the most recent release
The XULRunner download is a ZIP file, not a true install. As a
developer, I like the idea that XULRunner only needs to be unzipped
onto my machine. I am assuming that it doesn’t need to hook into my
Windows system and that’s a good thing.
Step 2 – Install XULRunner: I
unzipped the archive to a new “c:\program files\xulrunner” folder.
Pretty simple so far.
Time to start a simple, bare bones application shell. Call it
a XUL
“Hello World” if you want, but I need to make sure that XULRunner will
work at all. Googling turned up a nice tutorial here.
It is definately worth reading. Using the tutorial, I created a simple
bootstrap application. All of what you see below can be found in Ryan’s
tutorial and the Mozilla XULRunner
documentation pages.
Step 3 – Create application folder struture:
I create the root in a new “c:\program files\xulapp” folder. Here is
the subfolder structure:

/xulapp
  /chrome
    /content
      main.xul
    chrome.manifest
  /defaults
    /preferences
      prefs.js
  application.ini

Notice that there are 4 files in the folder structure:
application.ini, chrome.manifest, prefs.js & main.xul
Step 4 – Setup application.ini:
The application.ini
file acts as the XULRunner entry point for your application. It seems
to be used to configure
how your application intends to use the XULRunner platform as well as
configure some information that XULRunner uses to run your application.
Here is mine:

[App]
Vendor=Finkle
Name=Test App
Version=1.0
BuildID=20060101
Copyright=Copyright (c) 2006 Mark Finkle
ID=xulapp@starkravingfinkle.org

[Gecko]
MinVersion=1.8
MaxVersion=1.8

Step 5 – Setup Chrome Manifest:
The chrome manifest
file is used by XULRunner to define specific URI’s which in turn are
used to locate application resources. This will become clearer when we
see how the “chrome://” URI is used. Applications can be distributed
compressed in a JAR file or uncompressed as folders and files. I am
using the uncompressed method for now. Here is my manifest:
content myapp file:content/
Step 6 – Setup Preferences: The
prefs.js files is used to tell XULRunner the name of the XUL
file to use as the main window
. Here is mine:
pref("toolkit.defaultChromeURI",
"chrome://myapp/content/main.xul");

XULRunner preferences include:

Step 7 – Create some XUL:
Finally, we need to
create a simple XUL window. Nothing fancy here, just the minimum we
need to make a window. No menus or anything:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="main" title="My App" width="300" height="300"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <caption label="Hello World"/>
</window>

Step 8 – Run the App: The moment
of truth. We need
to get XULRunner to launch the bare-bones application. From a command
prompt opened to the “c:\program files\myapp” folder, we should be able
to execute this:
xulrunner.exe application.ini
Of course, xulrunner.exe must be in the PATH. Because of where
I
unzipped XULRunner, I could also try this if xulrunner.exe is not in
the PATH:
..\xulrunner\xulrunner.exe application.ini
Success! Here is a screenshot of
the bare bones application running on Win2K:
My App screenshot
src="http://starkravingfinkle.org/blog/wp-content/uploads/2006/07/myapp.png">
My next step will be to add much more to the bare bones
application.
I want to explore as much of XUL as I can as fast as I can. For those
that want to skip straight to the end, here is a ZIP of the My App
application:

Array over run attack

0 comments
Array over run attack is a technique that can be change the value of a variable in an application or a library. That can be used to skip a authentication, application safety check, illegal access to application. Application written in C and C++ are mostly vulnerable for this type of attacks. Following code sample explain a simple Array over run attack.
    In this application b_cond is initialized to false. That variable is used to prompt and text base on the value. As per the normal behavior, that should be prompted as “Condition Fail”.  But input parameter of SetText function is over ride the b_cond variable. So application will prompt “Condition Passed” as the output. That means the input parameter can be malfunction the application.
    This type of attacks can be avoided by checking the length of strings.

class library
{
public:
    library(void);
    ~library(void);
    void SetText(const char* pz_para)
    {
        strcpy(z_text, pz_para);
        if (b_cond == true)
        {
            cout<<"Condition Passed"<
        }
        else
        {
            cout<<"Condition Fail"<
        }
    }

private:
    //bool b_cond; //<< If variable is declared here. that will NOT over ride by array over run.
    char z_text[200];
    bool b_cond; //<< If variable is declared here. that will be over ride by array over run.
  
};

int _tmain(int argc, _TCHAR* argv[])
{
    library* lib = new library();
    char* cv = new char[300];
    memset(cv,1,300);
    lib->SetText(cv);
    cin>>cv;
    return 0;
}
Monday, March 26, 2012

Dyson bladeless fan: how it works

0 comments
The Air Multiplier, is a desktop fan without blades. Here he explains to Telegraph TV the technology that makes this possible.

Monday, December 5, 2011

Evolution of the Hard Disk !

1 comments

sshot4e94869984867_thumb%25255B2%25255D.jpg?imgmax=800


Monday, November 21, 2011

[video] - The Future of Energy Management

3 comments
Learn how to reduce energy costs by managing Power over Ethernet devices, and much more, with Cisco EnergyWise.




Please put your comments here.
Monday, October 24, 2011

[CODE] Java MCast Sender & Receiver

1 comments
Most people need to test multicast  sender and receiver in
their developments.  So I thought to present a Sample java
code for multicast sender and Receiver.

This MCast sender can send a File as the data of  the payload.
Multicast receiver will capture those data and save those data to a
file.



MCast Sender source code:

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.SocketException;
import java.net.UnknownHostException;

public class MulticastSender {

  public static void main(String[] args) {

    InetAddress ia = null;
    int port = 0;
    String characters = "Here's some multicast data\n";
    byte[] data = null;
    
    try 
    {
  FileInputStream input = new FileInputStream(args[2]);
  System.out.println("Data File Size: " + input.available() + " Bytes");
  data = new byte[input.available()];
  input.read(data);
  System.out.println("Read buffer Size: " + data.length  + " Bytes");
 } catch (FileNotFoundException e1) {
  System.err.println(e1);
  e1.printStackTrace();
 } catch (IOException e) {
  System.err.println(e);
  e.printStackTrace();
 }
    
    
    
    // read the address from the command line
    try {
      try {
        ia = InetAddress.getByName(args[0]);
      } catch (UnknownHostException e) {
        //ia = InetAddressFactory.newInetAddress(args[0]);
      }
      port = Integer.parseInt(args[1]);
    } catch (Exception e) {
      System.err.println(e);
      System.err.println("Usage: java MulticastSender [MulticastAddress] [port]  [File]");
      System.exit(1);
    }

   
    DatagramPacket dp = new DatagramPacket(data, data.length, ia, port);

    try {
      MulticastSocket ms = new MulticastSocket();
      ms.joinGroup(ia);
      ms.send(dp);
      ms.leaveGroup(ia);
      ms.close();
      System.out.println("File send. Length:"+ dp.getLength()  + " Bytes"); 
    } catch (SocketException se) {
      System.err.println(se);
    } catch (IOException ie) {
      System.err.println(ie);
    }

  }


MCast Receiver Source Code: 

import java.net.*;  /* import networking package */
import java.io.*;   /* import input/output package */

public class mcreceive {

  public static final int MAX_LEN  = 1024;  /* max receive buffer */
  public static final int MIN_PORT = 1024;  /* min network port */
  public static final int MAX_PORT = 65535; /* max network port */

  public static void main(String argv[]) {

    InetAddress mcAddress=null; /* multicast address */
    int mcPort=0;               /* multicast port */
    int ttl=1;                  /* time to live */
    boolean done=false;         /* variable for send loop */

     /* validate number of arguments */
    if (argv.length != 2) {
      System.out.println("Usage: mcreceive " +
                        "[Multicast IP] [Multicast Port] [Output File]");
      System.exit(1);
   }

    /* validate the multicast address argument */
    try {
      mcAddress = InetAddress.getByName(args[0]);
        System.out.println("MCast Group: " + group);
    } catch (UnknownHostException e) {
        e.printStackTrace();
      System.err.println(argv[0] + " is not a valid IP address"+ e);
      System.exit(1);
    }

    /* validate address argument is a multicast IP */
    if (! mcAddress.isMulticastAddress()) {
      System.err.println(mcAddress.getHostAddress() +
                         " is not a multicast IP address.");
      System.exit(1);
    }

    /* parse and validate port argument */
    try {
      mcPort = Integer.parseInt(args[1]);
    } catch (NumberFormatException nfe) {
      System.out.println("Invalid port number " + argv[1]);
      System.exit(1);
    }

    if ((mcPort < MIN_PORT) || (mcPort > MAX_PORT)) {
      System.out.println("Invalid port number " + mcPort);
      System.out.println("Port should be in range " + MIN_PORT
                         + " to " + MAX_PORT);
      System.exit(1);
    }

    try {

      /* instantiate a MulticastSocket */
      MulticastSocket sock = new MulticastSocket(mcPort);

      /* set the address reuse option */
      sock.setReuseAddress(true); // Java 1.4 and higher

      /* join the multicast group */
      sock.joinGroup(mcAddress);
     
      while (!done) {  /* loop forever */

        /* create a new DatagramPacket with an empty buffer */
        byte[] buf = new byte[MAX_LEN];
        DatagramPacket packet = new DatagramPacket(buf, buf.length);

        /* wait to receive packet into the DatagramPacket instance */
        sock.receive(packet);

        /* output the data from the packet received */
        System.out.println("Received " + packet.getLength() +
            " bytes from " + packet.getAddress() + ": "
            + new String(packet.getData(),0,packet.getLength()));
        FileOutputStream out = new FileOutputStream(args[2],true);
        byte[] bData = new byte[packet.getLength() + 10];

        for(int i=0;i < packet.getLength();i++)
             bData[i] = packet.getData()[i];
        
        out.write(bData);
        out.close();
      }
      
      sock.leaveGroup(mcAddress);
      sock.close();

    } catch (IOException e) {
      System.err.println(e.toString());
      System.exit(1);
    }
  }
}

Wednesday, October 5, 2011

[WEB] Shorten URL of your Blog or Web Site by Google Url Shortener

0 comments

Most of time we need to use an alias URL for out Blog. That is more use full to add to a different blog or while send to a friend. By our experience the google services are very reliable  and more clear. An other feature is the tracking the visitors. I used Google Url Shortener to create an alias for my blog. Here it is.

http://janaka077.blogsport.com  --->    http://goo.gl/Dmt5F

 http://img403.imageshack.us/img403/7336/46googleurl.jpg