Executing external files from a Netbeans plugin

Posted: Sunday, May 8, 2011 | Posted by කේෂාන් | Keshan | Labels: ,
As developers we are familiar with lot of IDEs among them Netbeans is one of the most popular IDE in the world. it is an open source platform and have a pluggable architecture where developers can extend the features of the IDE by adding plugins. the purpose of this article is not to tell how to write Netbeans plugin this will tell you how to call an external batch file exe or if you use Linux how to call a linux command from a plugin.

first create a Netbeans Modules project
 then right click on the project and select new and Action. that will create an Action for you. then right click on the project and select properties and select Libraries

then choose the Add option. tick the Show Non-API Modules option





























press ok..
add the folliwing import statements.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.netbeans.api.extexecution.ExecutionDescriptor;
import org.netbeans.api.extexecution.ExecutionService;

and add this method into the source code :

    public Integer execute() throws InterruptedException, ExecutionException {
        Callable processCallable = new Callable() {

            public Process call() throws IOException {
                return new ProcessBuilder("/bin/ls").start();
            }
        };

        ExecutionDescriptor descriptor = new ExecutionDescriptor().frontWindow(true).controllable(true);

        ExecutionService service = ExecutionService.newService(processCallable,
                descriptor, "ls command");

        Future task = service.run();
        return task.get();
    }
and then call this execute() method from the actionPerformed() method in the Action class.
here i am running ls command in linux but you can use any other external program by giving its path.
Keep Reading...

Learn Objective-C on Windows

Posted: Friday, January 21, 2011 | Posted by කේෂාන් | Keshan | Labels: ,
In todays world there are loads of Operating systems exists, among them Mac OS easily one of the most eye candy and lovely OS most people want to use but for some reasons most people doesn’t own a Mac. As programmers we all love to program for iPhone I don’t know why but people love to. so how can they develop applications for iPhones basically in Objective-C without an Apple Mac. the simple answer is Hackintosh but there are lot of other alternatives as well I will explain few of them in a later post but today I am going to explain how to learn Objective-C on a Windows machine. recently I installed Mac OS X on my machine but still I use Windows and Linux most of the time. So if there is way for you to at least learn objective-C on Windows that would be really helpful.
in order to compile Objective-C on Windows we need to install following package which is called GNUstep if you are a Windows user go to this link and download and install at least the first three packages.Capture3
then go to start –> all programs –> GNUstep –> shell
it is a Unix like terminal where you can issue some unix terminal commands. Then open your favorite text editor in my case I am using Vim by just typing vim and enter on the shell I opened up earlier but you can use Notepad++ or any other appropriate text editor.
#import <stdio.h>

int main( int argc, const char *argv[] ) {
printf( "hello world\n" );
return 0;
}

Capture4
and save it as hello.m remember to save it in the home folder as GNUstep installed if you’d have used vim there won’t be any problem but if you used any other text editor don’t forget to save it in there in my case the path is : C:\GNUstep\home\Keshan so yours might look similar to this. Then in the terminal type :

gcc `gnustep-config –objc-flags` –L /GNUstep/System/Library/Libraries hello.m –lgnustep-base –lobjc

Capture1
and then to run simply type ./a

Capture2
so this is a basic hello world program but Objective-C is bit different this is simply a C like program actually Objective-C is an extended version of C you can find loads of tutorial about Objective-C and try them out on Windows with this cool package. here is the same code run on Mac OS X

Capture5
Keep Reading...

Assembly Debugger

Posted: Monday, December 27, 2010 | Posted by කේෂාන් | Keshan | Labels: ,
For quite a some time I fell in love with Assembly programming language and now it is my favorite language. it is powerful easy and with assembly I get to know lot about computer architecture and the internal work very well. I am currently doing a project as a hobby implementing thumb and fore finger interface algorithm in assembly and writing a multi touch mouse driver in assembly but last few weeks and until the end of January I don’t have much time to deal with my loving language because of some hectic web projects and university exams.
so today for those who like assembly I will explain how to use assembly debugger if you are a newbie you will need this. this is one of the things I learnt in order to get familiar with assembly.in fact you already know the command prompt. so with windows you can use this debug tool debug.exe which installed with windows without doing any downloads or installings. open a windows command prompt and type debug. then type a100 and press enter
Untitled
here “a”(assemble) is a command and 141A:0100 is the memory location that we are going to enter our code in fact 141A is the segment and 0100 is the memory location inside the segment. you may get a different segment.. now insert this code :

mov ax,0001
mov bx,0010 
add ax,bx 
int 20 

after entering the above code press enter twice to tell the debugger that you have entered the code.this code is simply add two numbers. if you want to see what are the values inside all the registries when executing each instruction use “t” command. as you can see here after the execution the accumulator (AX) has 0011 value. in order to see the value of a given registry use “r” command with the register. 
Untitled
to run a program use “g” command and to go out from debugger use “q” command.
there are some more commands associated with debugger but I think this is enough to get started for any problem don’t hesitate to comment below..
cheers !!
Kesh….
Keep Reading...

Run Android Froyo in your VirtualBox

Posted: Wednesday, December 22, 2010 | Posted by කේෂාන් | Keshan | Labels: , , ,
Sometime ago i wrote how to use Android with VirtualBox. Now it seems lot of people wants to experience Android Froyo on VirtualBox. in this article i will show how to use Android-x86 project and run Android Froyo.

first download the Android Froyo iso or you can visit the download page and select an iso or img file yourself. Now you can use this CD image in two ways.
1. with VirtualBox
2. as a bootable USB
first i will explain how to use it with VirtualBox.
if you don't have VirtualBox installed download and install it. then run it and create a new instance.


likewise clicking next will create a new instance.

then double click on Android-x86 and start the instance.
 and then click on the place where i have circled
next thing add the downloaded ISO and attach it

   
right. after finishing it you can use Android !!
select Live CD or if you want to install it to your virtual hard disk select installation.
 if you experience that you can't use your mouse inside Android(use mouse and there are keyboard instructions as well like escape for going on step back) go to Machine and Disable Mouse Integration. or press Host(normally the right control key + I) once your mouse is captured press right control to come back to host operating system


it is up to you to explore Android with VirtualBox

as i told earlier the second way is to make a bootable USB with this ISO to do it first download UnetBootin and run it.
Select Diskimage and browse and open the iso file then check whether you have an USB in the given drive and click ok it will take sometime and create a bootable USB. so you can boot your computer with that USB and use Android as a Live CD or install it to hard disk....

Cheers !!
Kesh
Keep Reading...

An introduction to Assembly language

Posted: Thursday, December 16, 2010 | Posted by කේෂාන් | Keshan | Labels: ,
These days i don't have much time to get involve in C/C++, assembly and my loving researches on Computer vision things because i have to complete projects and assignments and also prepare for the last examination of my bachelors degree. however today i did some experiments with assembly by writing a simple media player and a email sending(kind of a keylogger though ;) ) application and i found a new IDE(new for me but it is not a new IDE :) ) for assembly. so i will explain how to configure that IDE first. remember i am not going to start a tutorial series in assembly but i hope to tell how to write some few simple applications in assembly.(not today :) because i have to complete my part of the group project)
  1. first of all download this zip file and unzip it into a desired location. then you have to download MASM32 because it's not coming with WinAsm.
  2. install MASM32 (for an example to C:\masm32)
  3. go to unzipped WinAsm folder double click and run WinAsm.exe
  4. before writing any application for the first time you have to set some variables
  5. go to tools -> Options you will get something like this
      6. then select Files & Path tab
      7.  edit the path variables as you installed then and then press ok...

right now you are done. so if you have some sort of a knowledge in assembly you can start coding. or i will give you a simple assembly code to test the IDE

go to file -> New project and create a standard EXE project. then simply copy and paste the below code :
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

.data
MsgBoxCaption    db "Keshan's Tech Gossipz",0
MsgBoxText     db "I love Win32 Assembly !",0

.code
start:
invoke MessageBox, NULL, addr MsgBoxText, addr MsgBoxCaption, MB_OK
invoke ExitProcess, NULL
end start

now go to Make -> Go All. this program will show a dialog box !!  

cheers !
Kesh
      
Keep Reading...

The ugly truth of web security

Posted: Wednesday, December 15, 2010 | Posted by කේෂාන් | Keshan | Labels:
Last few weeks as we all aware there were lot of interesting things happened in the cyber world. Wikileaks, 4chans, Gnosis, LOIC, DDoS are some of the keywords today. couple of days ago a reputed web media company called Gawker media was hacked by a gang known as Gnosis. they didn't stop only by hacking the site but they dump 1.3 million data from Gawker database which includes username passwords the future changes of Gawker site source codes and upload it as a torrent file (i however found that torrent file and downloaded the content :D ) so, if you are using a account to comment on sites like Gizmodolifehacker then you account is most probably been hacked ! and the worst case is if you are using the same password for every site in the web then you are in a huge trouble.

Things i noticed in hacked files

when i go through the downloaded files i noticed there are thousands of people using "password", "password1" without quotations as their password there were few common passwords like "password", "qwerty", "qwerty12". not only the normal Gawker users the people who are in administrative positions had very weak passwords. so, as users people should be more careful when choosing a correct password.

Things web developers should learn

here the hackers exploited a vulnerability in the CMS and took control of everything. there were lot of things that Gawker media web development team has done wrong.
they have saved the password not the salted hash !!!! you must NOT do it. instead you should save the salted hash.
why didn't they use a mechanism like openID or Facebook connect. then the attackers cannot get the users passwords.
and the other main thing as the attackers mentioned in a readme file :

Gawker uses a really outdated hashing algorithm known as DES (Data Encryption Standard) Because DES has a maximum of 8chars using a password like "abcdefgh1234" only the first 8 characters "abcdefgh" are encrypted and stored in the database. If your password is longer than 8 characters you only need to enter the first 8 characters to log in!

YA DONT SAY!! :D?

 Because of this we were only able to recover the first 8 characters of someones password! If the password is 8 characters long there's a good chance that it migt be longer than 8 characters! But still, there's 1000's of people using 1 - 8 character passwords for us to have some fun with! 

so when designing a web site beware of algorithms you are using to hash passwords if it's like in this case the outdated encryption algorithm make hell a lot of trouble..

after this attack there were thousands of articles posted on new security models and i will discuss some of them later, but as for final words i think as users we have the responsibility to keep our privacy as Google CEO once said if you want your privacy don't post anything on the web. when choosing a password security question users should think not twice, thrice.....

cheers !
Kesh
Keep Reading...

How to reduce the dependency hell in Linux

Posted: Sunday, November 14, 2010 | Posted by කේෂාන් | Keshan | Labels:
This is my first post after 2 months !! anyway today i am going to give a special tip for Linux users. if you are a linux user you must have faced with dependency hell. recently i stumble upon to this project on github so, here i will explain how to use that awesome project to reduce the dependency hell in other words you can run a program which run perfectly on your machine in another machine without think about any dependencies or setting up the environment.

click here and download this file from github, if the link doesn't work or if you prefer to download the source code and build yourself follow this instructions

git clone git://github.com/pgbovine/CDE.git
cd CDE
make

if you have downloaded the compiled code follow these instructions

mv cde_2010-11-13_32bit cde
chmod g+x cde

NOTE : cde_2010-11-13_32bit should be replaced with your downloaded filename.

done. now what?
ok let's use this great little program. assuming that the cde file is in your present working directory you can type this in the terminal.

echo "hello" >> test.txt
./cde vim test.txt

here i created a text file and write hello in it and used vim to open the text file you can use any program not only vim (e.g cat, gedit, vi). you will see no difference it opens the vim editor with hello in it. but if you just happen to type a ls you will see a directory which you didn't create ! in that directory it holds all the dependencies need to run the program.


now you can zip that cde-package directory and unzip in any machine which has the same operating system and open your text file with vim. so let's say the second machine doesn't have vim but still you can run vim text.txt !!! using cde you can run not only vim but any program you just need to run the program with cde

./cde program_name

in order to run the program in the second machine you have to follow these instructions

cd cde-root
ls


what can you see ?

it is almost like your root folder ! now go to the directory where you had that text file in my case i had it in /home/keshan/Downloads/Test/ in my original machine so, in your second machine go to the same directory(when you type home omit /) and now type ./vim.cde test.txt

cd home/keshan/Downloads/Test
./vim.cde test.txt

try this out with any program....

cheers !
-Kesh,
Keep Reading...

What will be the next web stack ?

Posted: Friday, September 10, 2010 | Posted by කේෂාන් | Keshan | Labels: , ,

Technology is something which improves rapidly. things we thought decade ago were impossible have become realistic today. Today The Internet plays a major role in day to day life. From one static web page has now become much more agile dynamic web sites and even the rich internet applications(RIA) has made The Internet a more exciting place. now with the emergence of concepts like cloud computing businesses and technology moves into a different direction.

What is a web stack ?
A web stack is simply a stack of software, mainly comprised of open source software, will contain an operating system, Web server, database server, and programming language. One of the most most well-known web stacks is LAMP.

Apache as a web server has been using more than a decade and served for many big web applications but can it do the same thing in next generation ?
with cloud computing it needs a more agile light weight and secure web server like lighttpd. lighttpd is an open source web server which is rapidly redefining efficiency of a webserver; as it is designed and optimized for high performance environments. With a small memory footprint compared to other web-servers, effective management of the cpu-load, and advanced feature set (FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more) lighttpd is the perfect solution for every server that is suffering load problems. big web solutions like YouTube, Wikipedia  are already using lighttpd to serve their clients.
unlike in normal web applications Cloud computing solutions need a distributed file system like GoogleFS which was developed by Google and used by Google. So, Apache Hadoop with MogileFS can be used to fulfill that requirement. Apache Hadoop is a software framework that supports data-intensive distributed applications under a free license. It enables applications to work with thousands of nodes and petabytes of data. Hadoop was inspired by Google's MapReduce and Google File System (GFS) papers.Hadoop is a top-level Apache project being built and used by a global community of contributors, using the Java programming language. Yahoo! has been the largest contributor to the project, and uses Hadoop extensively across its businesses. 


So, with these new concepts and new technologies we could see a more reliable, secure, speed and agile world wide web.


Cheers !
Kesh,
Keep Reading...

How to catch your invisible friends on GTalk

Posted: Sunday, August 29, 2010 | Posted by කේෂාන් | Keshan | Labels: , , ,
If you have a Google account then you might have experienced Google chat which is integrated with GMail and it can also accessed via XMPP. if you have used it then you may know that so many people don't like to go online so they make themselves invisible. today in this post i am going to explain a simple way to find out who are the invisible buddies.
in this post i have used python and python-xmpp library and i have tested this on Linux but i suppose this will work on Windows as well.
since i did this on Linux(Ubuntu) i am writing the steps for Debian based operating systems which normally comes with python. type this in  you terminal

sudo apt-get install python-xmpp python-dnspython

enter your super user password and wait till it installed. then open your favorite text editor in this case i am using gedit. copy and paste this code :
import xmpp

FROM_GMAIL_ID = "kesh.jboy@gmail.com"
GMAIL_PASS = ":Pthisisnotmyrealpassword:P"
GTALK_SERVER = "gmail.com"

jid=xmpp.protocol.JID(FROM_GMAIL_ID)
C=xmpp.Client(jid.getDomain(),debug=[])

if not C.connect((GTALK_SERVER,5222)):
    raise IOError('Can not connect to server.')
if not C.auth(jid.getNode(),GMAIL_PASS):
    raise IOError('Authentication error.')

C.sendInitPresence(requestRoster=1)

def myPresenceHandler(con, event):
   if event.getType() == 'unavailable':
     print event.getFrom().getStripped()

C.RegisterHandler('presence', myPresenceHandler)
while C.Process(1):
  pass

right !!! save this file as mygtalk.py and simply type

python mygtalk.py


in terminal...... wow you can see all your invisible buddies just give them a wink... have fun..

Cheers !
Kesh,
Keep Reading...

Creating a GTalk client with C# - Part 2

Posted: | Posted by කේෂාන් | Keshan | Labels: ,
I think you have already read my previous blog post : Creating a GTalk client with C# - Part 1. So now you have created a login form and only authenticated people can log into the client. in that post when a user authenticated what i did was just disposed the current window so in this post i will create another form and show it instead of disposing the login form. So create another form with VS where you should have a list to load you buddy list, another list to show your chats, a text box to type your chats and a send button.(This is my basic design but it is up to you to design whatever way you like :) )

alright everything is set to do the codings.... go to source and initialize a XmppClientConnection object but this object should be the same object as we created in the previous form. so what i did was made that earlier object static(in form 1) and also create a static method called getXmpp() in form1.cs


static XmppClientConnection xmppCon = new XmppClientConnection();




        public static XmppClientConnection getXmpp()
        {
            return xmppCon;
        }

you may find a better way than this. 

then in form2 add this line.



XmppClientConnection xmppCon = Form1.getXmpp();
now you have to subscribe to events so create a new method called init()


        private void Init()
        {
            chatList.Items.Clear();
            xmppCon.OnRosterStart += new ObjectHandler(OnRosterStart);
            xmppCon.OnRosterEnd += new ObjectHandler(OnRosterEnd);
            xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(OnRosterItem);
            xmppCon.OnPresence += new agsXMPP.protocol.client.PresenceHandler(OnPresence);
            xmppCon.OnError += new ErrorHandler(OnError);
            xmppCon.OnClose += new ObjectHandler(OnClose);
            xmppCon.OnMessage += new agsXMPP.protocol.client.MessageHandler(OnMessage);
        }



 here chatList is the ListBox which we create to show the chats and Roster means the buddies. now invoke this init method in the constructor after InitializeComponent(); 


        public Form2()
        {
            InitializeComponent();
            Init();
        }
now simply create the methods to handle the events which were registered.


       void OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            if (msg.Body == null)
                return;

            if (InvokeRequired)
            {
                BeginInvoke(new agsXMPP.protocol.client.MessageHandler(OnMessage), new object[] { sender, msg });
                return;
            }

            chatList.Items.Add(String.Format("{0} type:{1}", msg.From.Bare, msg.Type.ToString()));
            chatList.Items.Add(msg.Body);
            chatList.SelectedIndex = chatList.Items.Count - 1;          
        }

        void OnClose(object sender)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new ObjectHandler(OnClose), new object[] { sender });
                return;
            };
        }

        void OnError(object sender, Exception ex)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new ErrorHandler(OnError), new object[] { sender, ex });
                return;
            }
            chatList.Items.Add("Error");
            chatList.SelectedIndex = chatList.Items.Count - 1;
        }

       void OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new agsXMPP.protocol.client.PresenceHandler(OnPresence), new object[] { sender, pres });
                return;
            }
            chatList.Items.Add(String.Format("Received Presence from:{0} show:{1} status:{2}", pres.From.ToString(), pres.Show.ToString(), pres.Status));
            chatList.SelectedIndex = chatList.Items.Count - 1;
        }

        void OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new XmppClientConnection.RosterHandler(OnRosterItem), new object[] { sender, item });
                return;
            }
            buddyList.Items.Add(String.Format("{0}", item.Jid.Bare));
            buddyList.SelectedIndex = chatList.Items.Count - 1;
        }

        void OnRosterEnd(object sender)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new ObjectHandler(OnRosterEnd), new object[] { sender });
                return;
            }
            xmppCon.SendMyPresence();
        }

        void OnRosterStart(object sender)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new ObjectHandler(OnRosterStart), new object[] { sender });
                return;
            }
        }

this is simply the code you can customize in whatever way you like. :) so now the last thing in form1 we only dispose the form so now let's replace that line with this :



new Form2().Show();
 ok now run it. select a buddy from buddylist and chat... have fun... if you have any problem regarding the code feel free to comment below or send me an email to : kesh.jboy@gmail.com

cheers !
Kesh,
Keep Reading...
Related Posts Plugin for WordPress, Blogger...