None of the content is original, so don't waste your time reading this blog.

Wednesday, June 20, 2007

VMware player on Fedora 5

Download and install the VMware Player, i have used the 2.0 for this:
# rpm -Uvh VMware-player-2.0.0-45731.i386.rpm

Now if we try to execute the player, we will get something like this:

# vmplayer
vmware is installed, but it has not been (correctly) configured for this system. To (re-)configure it, invoke the following command: /usr/bin/vmare-config.pl.
This is requering us to execute the configuration script /usr/bin/vmare-config.pl. This is a wizard were ask us for paths, i chose the default for all the questions.
# /usr/bin/vmware-config.pl
Making sure services for VMware Player are stopped.
Stopping VMware services: Virtual machine monitor [ OK ]
Configuring fallback GTK+ 2.4 libraries.

In which directory do you want to install the theme icons? [/usr/share/icons] ...
In some point the script ask us to build the vmmon modules so we answer 'yes'
None of the pre-built vmmon modules for VMware Player is suitable for your running kernel. Do you want this program to try to build the vmmon module for your system (you need to have a C compiler installed on your system)? [yes]
After this the wizard ask us for the kernel sources path:
What is the location of the directory of C header files that match your running kernel? [/usr/src/linux/include]
If we do not have the kernel source, we will have to install it. So we left the wizard and install the sources:
# yum install kernel-devel
So far so good, for me yum installed the sources in /usr/src/kernels/2.6.20-1.2319.fc5-i686 the headers that the wizard ask us are in include directory. Now we pass this full path to the wizard and get:
What is the location of the directory of C header files that match your running kernel? [/usr/src/linux/include] /usr/src/kernels/2.6.20-1.2319.fc5-i686/include

Extracting the sources of the vmmon module.

Building the vmmon module.
Using 2.6.x kernel build system. make: Entering directory `/tmp/vmware-config4/vmmon-only' make -C /usr/src/kernels/2.6.20-1.2925.fc6-i586/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. modules make[1]: Entering directory `/usr/src/kernels/2.6.20-1.2925.fc6-i586'
...
make[1]: Leaving directory `/usr/src/kernels/2.6.20-1.2925.fc6-i586' make: *** [vmmon.ko] Error 2 make: Leaving directory `/tmp/vmware-config4/vmmon-only'
Unable to build the vmmon module.
For more information on how to troubleshoot module-related problems, please visit our Web site at "http://www.vmware.com/download/modules/modules.html" and "http://www.vmware.com/support/reference/linux/prebuilt_modules_linux.html".

Execution aborted.
Damn, what went wrong? After some googling you find out that the script requires the specific sources for your running kernel, yum installed the last sources. So how to know what source to install? well:
# uname -a
Linux localhost.localdomain 2.6.15-1.2054_FC5 ...
# uname -p
i686
The above tell us that we need the sources for the kernel version 2.6.15-1.2054_FC5 and the platform i686. Once we get the right sources, remove the earlier and install the right one:
# rpm -qa kernel-devel*
kernel-devel-2.6.20-1.2319.fc5
# rpm -e kernel-devel-2.6.20-1.2319.fc5
# rpm -i kernel-devel-2.6.15-1.2054_FC5.i686.rpm
Finally we start again the script and pass the new path:
# /usr/bin/vmware-config.pl
...
What is the location of the directory of C header files that match your running kernel? [/lib/modules/2.6.15-1.2054_FC5/build/include] /usr/src/kernels/2.6.15-1.2054_FC5-i686/include
...
...
The module loads perfectly in the running kernel.
...
After building the module successfully, the wizard will ask for other options, i agree with the defaults and all worked smoothly.

Sources

VMware on Fedora Core 5
VMware Server On A Fedora Core 6

Tuesday, March 20, 2007

Tomcat as service

Simple steps to setup Tomcat as service on Redhat:
  1. put this script on /etc/init.d/
  2. edit it, so that the variables JAVA_HOME and TOMCAT_HOME are pointing to correct locations on your system, for instance the script is setted with:
    TOMCAT_HOME=/opt/tomcat
    JAVA_HOME=/usr/java/jdk1.5.0_09
  3. set execution permision to the script:
    # chmod a+x /etc/init.d/tomcat
  4. add a tomcat user, if there is no one already
    # adduser tomcat
  5. make tomcat user the owner of TOMCAT_HOME directory, for instance
    # chown -R tomcat:tomcat /opt/tomcat/
  6. finally, install the script as service
    # chkconfig --add tomcat
now it is easier to manage tomcat with the comands:
# service tomcat [start|status|stop]
Source: http://www.spaceprogram.com/knowledge/2004/01/starting-tomcat-as-service-on-linux.html

Labels:

Saturday, February 03, 2007

Obfuscation for dummies

Most people who worry about obfuscation shouldn't. Nobody wants your code :). Byte-code encryption does not work, so obfuscation only makes reverse engineering sligthly more difficult. At the other end of the scale, mobile development pretty much mandates obfuscation: files need to be as small as possible.

Obfuscation Tools

  • ProGuard Shrinker and obfuscator, JME support. Comes with a wizard, pretty straightforward
  • JMangle
  • Retroguard Shrinker and obfuscate JME applications
  • yGuard

Observations

  • Any methods that are accesssed via reflection need to be excluded from obfuscation
  • properly obfuscating swing applications is very difficult due to the dynamic nature of the swing components
  • expect to spend several iterations of full regression sweeps to validate the obfuscated product
  • if you are adding obfuscation late in the development cycle, expect to produce parallel builds (obfuscated and non obfuscated) so that QA can repro bugs. One big problem with debugging obfuscated code is the fact that you will not get a stack trace that's meaningful
  • obfuscation will drastically reduce your jarsize and your memory footprint
  • good luck patching an obfuscated applicaiton in the field. You will probably have to redeliver a new jar instead of just the updated classes

Issues

Conclusions

  • Obfuscation is not the ultimate solution but if the client feel better if the code is obfuscated then we will have to do it
  • Your are screwed if you use reflection

Decompilers

Java Decompiler JAD.

Labels:

Monday, January 29, 2007

Alternatives to SUN JVM

Alternatives Virtual Machines to SUN JVM

Labels:

Design By Contract

Something that i should check, as much as unit testing. For theory, see the Bertrand Meyer book "Object-Oriented Software Construction"

Libraries

Labels:

Subversion for dummies

Basic steps to install Subversion on any Red Hat based linux flavor, using FSFS file system storage.
# yum install subversión
# adduser svn
# su svn
# mkdir /repos
(svn)$ svnadmin create --fs-type fsfs /repos
By the way, make sure that the user svn owns /repos directory and that everybody has write permissions on it:
# chown -R svn:svn /repos
# chmod a+w -R /repos 
Afterwards, access the repository through your ssh account with svn+ssh://127.0.0.1/repos.

Backup a repository

To backup a repository

# svnadmin dump /path/repository > /backup/repository.dump
Then to recover a backed up repository
# svnadmin load /path/repository < repository.dump

Polarion Subversive

This is a plug-in for Eclipse. To install it, define a new site for this feature, on Software Updates, define a new Remote Site:

Then follow the wizard, and select the options Subversive and Subversive Clients to install.

Links

Labels:

Thursday, October 19, 2006

Derby for Dummies

If you are looking for a lightweight database that starts along with Tomcat, then Derby could be a good choice. The following is how to run an instance of Derby on Tomcat. This is based on the casual scenary of the article Integrate Derby with Tomcat by Lance Bader.

Derby basics

If we read a litle about Derby we know that Derby can be used in two ways: as a embedded database, that is, Derby as part of our application and we start and stop it from the code application itself. For example, to start Derby in embedded way we just need to load the Derby driver:
Connection cnx = DriverManager.getConnection("jdbc:derby:my-db;create=true");
the above starts the Derby engine. To shutdown the engine we issue "jdbc:derby:;shutdown=true". The embedded way only supports one connection at a time, we will get an ugly exception if try to get another connection when there is already one connection running, something like this:
ERROR XJ040: Failed to start database 'my-db', see the next exception for details. ERROR XSDB6: Another instance of Derby may have already booted the database \my-db.
If we want to use Derby in a embedded way, we only need to put Derby engine derby.jar in the CLASSPATH.

The second way to use Derby is on client/server mode, this allow us to open as many connections as we want. This way uses the library derbynet.jar to wrap the Derby engine derby.jar so it is able to listen for tcp connections on a specific port. In order to do this is necesary to create an instance of org.apache.derby.drda.NetworkServerControl and call its method start() to start a threat which listens for connections on a tcp port, usually 1527. Next and example of how to do this:

NetworkServerControl server = new NetworkServerControl(InetAddress.getByName("0.0.0.0"), 1527); server.start(new PrintWriter(System.out));
to shutdown the server call the method server.shutdown().

In order to connect to this Derby mode we issue

...getConnection("jdbc:derby://localhost:1527/my-db;create=true");
or we can give the complete path to the database in this way
...getConnection("jdbc:derby://localhost:1527//home/user/my-db;create=true");
also, put the library derbyclient.jar on the CLASSPATH in order to the above code works.

Derby Libraries

The next chart belong to the article Introdução ao Derby

Command Line interface

Remember to use single quotes from ij tool.

Wiring Derby and Tomcat

Lets start for the easiest part, download Derby libraries and put them on Tomcat. We want that Derby be loaded when Tomcat service start so we have three posibles directories where put Derby libraries:
- tomcat-home/common/lib
- tomcat-home/shared/lib
- tomcat-home/server/lib
The libraries located on common/ and shared/ are accesibles for all the aplications running on Tomcat. For instance, if we put derby.jar on tomcat-home/common/lib/, this is like we had Derby on web-app/WEB-INF/lib/derby.jar, that is, locally to our web application web-app. On the other hand, the directory server/ is reserved to Tomcat specific libraries, i picked this direcory just for fun. We want Derby on client/server mode, so we need that somehow Tomcat calls org.apache.derby.drda.NetworkServerControl's start() and shutdown() for us, that is, start and shutdown Derby server. One way to do this is implementing the interface org.apache.catalina.LifecycleListener. Now lets say that we have a class com.my.packege.DerbyLifecycleListener who does that. We have to put this class on tomcat-home/server/classes/ or we can create a jar file and put it on tomcat-home/server/lib/

Next we have to wire this class with Tomcat, this is done setting tomcat-home/conf/server.xml on the listeners section like this:

<Listener className="org.apache.catalina.core.Apr..."/>
<Listener className="org.apache.catalina.mbeans...."/>
<Listener className="org.apache.catalina.mbeans..."/>
<Listener className="org.apache.catalina.store..."/>
<Listener className="com.my.packege.DerbyLifecycleListener"/>
Tomcat will load DerbyLifecycleListener every time it boots up so Derby engine will be listen for connections. Of course the libraries derbynet.jar and derby.jar must be on tomcat-home/server/lib so DerbyLifecycleListener load them.

Labels:

Friday, September 15, 2006

Optimizing Desktop Performance

I started looking for ways to optimize the performance of my Fedora 5 system, since it just have 256MB of RAM and my cheap boss does not have any intention for buy more. For example, while i am writing those lines, the memory usage was:
# free -m
             total   used   free  shared  buffers  cached
Mem:           217    212      5       0        0      45
-/+ buffers/cache:    166     51
Swap:         1027     92    934
and I just have openned Opera 9 with 8 tabs, a terminal console and Gaim. At this point, i can not complain about the performance, but as soon as I start to open new applications, I see how the amount of used swap grows and my desktop becomes really slow. One interesting source of desktop performance is Tom Adelstein's series I, II, III, and the posts are a great complement of the articles.

Labels:

Friday, June 16, 2006

Dual Boot Setup

Following are the steps to get dual-boot working with GRUB; for more details you should go to the original source of this post. I used to install first Windows 2000 or Windows XP and use the Windows boot loader (NTLDR) installed in MBR to launch GRUB. Also, this should work on Windows NT (all 3 OSs use the same booting architecture).

  1. Install GRUB on the first sector of the /boot partition. DO NOT INSTALL IT ON THE MBR!.
    If you are performing the Red Hat installation, for the "Boot Loader Installation" screen:
    • Select "Use GRUB as the boot loader"
    • Select Install Boot Loader record on "...First sector of boot partition".
    • After finishing the Red Hat installation, reboot into Linux. If you don't have a boot disk, try booting in linux rescue mode
    If you already have Linux installed:
    • Run the following command (e.g. assuming /boot is
      /dev/hda2): grub-install /dev/hda2.
      If you don't know which partition contains /boot, run the df command and check the output.
    • Edit /etc/grub.conf and make sure there is an entry for your version of Windows.
  2. Determine which partition contains the /boot partition by running the df command. You'll see output like this:
    Filesystem 1k-blocks     Used Available Use% Mounted on
    /dev/hda3    8665372  1639580   6585612  20% /
    /dev/hda2      46636     5959     38269  14% /boot
    /dev/hda6     513776   189504    324272  37% /mnt/shared
    none          256624        0    256624   0% /dev/shm
    From this output, we see that /boot is on /dev/hda2.
  3. Make a copy of the Linux boot sector onto a floppy or onto a FAT32 partition. We'll name this copy linux.bin. To make a copy onto a floppy:
    • Mount the floppy drive if it's not mounted (assumes /mnt/floppy exists): mount -t msdos /dev/fd0 /mnt/floppy
    • Run the following command: dd if=/dev/hda2 of=/mnt/floppy linux.bin bs=512 count=1
      Substitute the path for the if= parameter (the input file) with the appropriate partition from the previous step. E.g., set if= to /dev/hda2.
    To make a copy onto a FAT32 (vfat) partition:
    • Mount the FAT32 partition if it's not mounted yet. If it isn't listed in the df output, it hasn't been mounted yet.
    • Run the following command: dd if=/dev/hda2of=/mnt/shared/linux.bin bs=512 count=1, substitute the path for the if= parameter (the inputfile) with the appropriate partition from the previous step. E.g., set if= to /dev/hda2. Substitute the path for the of= parameter (the output file) with whatever is appropriate for your system. The example here (of=/mnt/shared/linux.bin) is for copying onto a FAT32 partition called osshare.
  4. Reboot into Windows
  5. Copy the linux.bin file to C:\
  6. Run notepad and edit C:\boot.ini. Note that C:\boot.ini is a hidden system file, so it probably won't show up in Windows Explorer. To edit the file, try: Start->Run and enter: notepad C:\boot.ini. Add the following line at the end: c:\linux.bin="Linux". If your C: filesystem is NTFS (not FAT32), you must edit C:\boot.ini as a user with administrator-level privileges. To make C:\boot.ini writable, you can either :
    • Use Explorer:
      • Go to Tools->Folder Options->View and select Show hidden files and folders and deselect Hide protected operating system files (Recommended).
      • Right-click on the file, view the Properties and uncheck Read-only. You can now edit the file.
      • After editing the file, restore the settings to their original state.
    • Use the command-line:
      • Make the file writable: attrib -R -S -H C:\boot.ini.
      • After you've finished editing the file, put the settings back: attrib +R +S +H C:\boot.ini
  7. Reboot again. You should be able to pick either Windows or Linux. Selecting Linux will start GRUB

Labels: