Monday, December 15, 2008

ps2pdf A4 paper size

Convert a PS file to PDF with ps2pdf by specifying the paper size to be A4.

ps2pdf -sPAPERSIZE=a4 yourfile.ps

Sunday, December 14, 2008

How to Write Diploma, Master or PhD Thesis?

How to Write Diploma, Master or PhD Thesis? is comprehensive article about how to organize the structure of dimploma, master or PhD thesis.

Sunday, December 07, 2008

Barcelona Guide

You can find very nice touristic guide of Barcelona at this address - www.bcnguide.org (Barcelona Tourist Guide). I ever wanted something like that when travel around.

Tuesday, November 25, 2008

Shell script for synchornizing files between local linux directory and windows share

The given bash script synchronizes can be used to synchronize a directory from a local file system with a windows share.

#!/bin/sh

# Synchronize.sh
# Copyright (C) 2008 Ferad Zyulkyarov
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


#
# Shell script for synchronizes files between local linux directory and
# windows share
#
# This script synchronizes a local directory from a remote windows share.
# First it mounts the remote share then synchronizes and then unmounts
# the remote share.
#
# Requirements: To use this scrypt you need to have installed
# 1. mount.cifs or smbmount
# 2. rsync
#
# Placeholders in the script that should be adapted:
# mount - the mount command to use {smbmount, mount.cifs, mount -t smbfs}
# umount - the umount command to use {smbumount, umount.cifs, umount}.
# remote_share$ e.g. //10.0.0.1/myshare
# mount_dir - where to mount the remote share e.g.
# /home/username/localmyshare
# username - this is the username to access the remote share
# password - your password
# source_synch_dir - the source to synchronize from
# dest_synch_dir - the destination to synchronize to
#

mount='mount.cifs'
umount='umount.cifs'
remote_share='//10.0.0.1/myshare'
mount_dir='/home/username/localmyshare'
username='your username'
password='your password'

source_synch_dir='/home/username/localmyshare'
dest_synch_dir='/home/username/syncdata'

mounted_here=0

print_usage()
{
echo "Usage: $0 {get, put}"
echo " get - synchornize from the remote share to the local"
echo " put - synchornize from local to the remote share"
}

if [ $# -ne 1 ] ; then
print_usage
exit 1
fi

synchronize_command="empty"
if [ $1 = "get" ] ;
then
synchronize_command="rsync -av -delete $source_synch_dir/ $dest_synch_dir"
elif [ $1 = "put" ] ;
then
synchronize_command="rsync -av -delete $dest_synch_dir/ $source_synch_dir"
else
print_usage
exit 1
fi

if [ ! -x $source_synch_dir ] ;
then
echo "Mounting remote file system..."
$mount $remote_share $mount_dir -o username=$username,password=$password
if [ $? -ne 0 ] ; then
echo "Error: Cannot mount the remote file system."
exit 2
else
mounted_here=1
echo "Remote file system was mounted successfully."
fi
fi

echo "Starting synchornization..."
#rsync -av -delete $source_synch_dir $dest_synch_dir
$synchronize_command
synch_result=$?

# unmount the share if we mounted here
if [ $mounted_here -eq 1 ];
then
$umount $mount_dir
if [ $? -ne 0 ] ; then
echo "Error: failed to unmount the remote file system."
else
echo "Remote file system unmounted successfully."
fi
fi

if [ $synch_result -ne 0 ] ; then
echo "Error: Synchornization failed with exit code: " $?
exit 3
else
echo "Synchornization completed successfully."
fi

exit 0

Monday, September 22, 2008

Hijack Return Address

The code segment in this post demonstrates by a simple example how to hijack a return address of a function. The hijacking of a return address is employed by untrusted users which provided data overwrites the program calls tack - stack buffer overflow - by inserting an executable code which execution upon return of the current function would let one to take control of the system.

This code demonstrates how to hicjack the return address of a function. In this example the "foo2" function is not called anywhere, but in function "foo" we change the returns address on the process stack to be the beginning of function "foo2". So when function "foo" returns "foo2" is called instead of returning to "main" function. This causes printing the string "In foo2" and then the return address is again modified to be the place where "foo" function had to return in "main".

The compiled executable is tested and works in x86 32bit architectures. The compiled executable is not tested in 64bit architectures and is not guaranteed to work.

To compile with gcc compiler type the following command (assuming that you copy and paste the code in file named hijack_return_address.c):
$ gcc -o hijack_return_address.exe hijack_return_address.c

#include
#include

long original_return_address = 0;

int foo();
int foo2();

int main()
{
printf("Hijack return address example.\n");

foo();
}

int foo()
{
/*
Get the address where the exection should continue after this
function returns
*/
asm("movl 4(%%ebp), %0" : "=r"(original_return_address));

printf("In foo original_return_address: %x\n", original_return_address);

/* Change the return address to go the beginning of foo2*/
asm("movl %0, 4(%%ebp)" : : "r"(foo2));

return 0;
}

int foo2()
{
printf("In foo2\n");

/* set the original address from main function as a return address */
asm("movl %0, 4(%%ebp)" : : "r"(original_return_address));

return 0;
}

Tuesday, September 09, 2008

Change MAC address in Linux

The command to change the MAC address in linux is
#ifconfig hw

- if the name of the interface to apply the command
- is the class of internet address for Ethernet is "ether"
- is colon delimited MAC address

Example:
# ifconfig eth0 hw ether 00:16:41:E0:B6:08

Monday, August 25, 2008

VTune: glibc-32bit version 9 or higher

When installing a trail version of VTune 9.0 U11-1888 (vtune90_011_lin.tar.gz) on Suse 11.0 64bit architecture the installer complains by printing the following message "glibc-32bit version 9 or higher" and quits. I have double checked that I have all the required libraries including glibc-32bit installed and their proper versions. But the problem continued to exist.

My work around was to take replace the file data/preinstall_vtune_check.sh with one from an earlier build version (VTune 9.0 U1-969 or VTune U7-1448). Then the version check passed and I got an installed VTune.

Compiling the linux kernel

To compile a fresh linux kernel.

1. Download the kernel source from www.kernel.org let's say linux-x.y.z.tar.gz
2. Expand the archive in /usr/src directory "$tar -xzvf linux-x.y.x.tar.gz"
3. Create a linux link to the source directory
$ln -s linux-x.y.x linux

4. $cd linux
go into the source directory

5. If you want to delete the previously compiled kernel object files, configuration files run
$make mrproper

6. Configure the kernel (one of below)
6.1. $make config (you will be promted for each configuration parameter one by one)
6.2. $make menuconfig (you will be have text based menu in the terminal, easier for navigation, requires library ncurses installed)
6.3. $make xconfig (you will be have a graphical window to configure the kernel, you will need to have many packages installed).

7. Build the kernel
$ make

8. Build the modules
$make modules

9. Install the modules
$make modules_install

10. Install the kernel
$make install

This will create four files in directory /boot
  • vmlinuz-x.y.z (the kernel)
  • System.Map-x.y.z
  • config-x.y.y
  • initrd-x.y.z
To use the new kernel you will have to add an entry into me grub menu list, this is file /boot/grub/menu.lst You can look at the existing entries when preparing the entry for the new kernel. When you are done reboot the machine.

Saturday, August 23, 2008

Slow sleep (suspend) in Windows Vista

Why in Vista it takes so long to go in sleep mode?

In Windows Vista it takes significant time to get the system in low-power mode when you select Sleep (or close the Lid of your laptop). The reason for this is that in Vista sleep is not exactly the sleep in XP and is called hybrid sleep.

Hybrid sleep is a combination between the normal sleep (suspend) and hibernate. When Hybrid sleep is enabled, the data in the main memory is stored into the hard drive and then the system goes into low-power mode. The reason for saving the data from the main memory to the hard drive is that an electricity cut will cause the computer to turn off if it does not have battery and all the changes in unsaved files lost. Because of saving the memory into the hard drive the overall sleep process in vista takes quite long time - 30-180 seconds.

Hybrid sleep is more suitable for desktop computers since they don't have batteries. Laptops have batteries and when the power level of the battery reaches the critical level the system automatically hibernates if it is in low-power mode avoiding the risk of losing unsaved data.

To turn off hybrid sleep (bypass saving the data in memory to the hard drive) follow the steps:

1. Open "Power Options"
- Click the Start button and on the search type "Power Options"
2. For any power plan click "Change plan settings"

3. Click "Change advanced power settings"

4. Expand the "Sleep Node" and "Allow hybrid sleep"
- If "Allow hybrid sleep" does not exists then
4.1. Open "Command prompt" as administrator
- In the search box Start menu type "Command prompt" then right click on the icon and select "Run as administrator"
4.2. type "powercfg /hybenrate on"
if necessary start from step 1.
5. Ensure that under "Allow hybrid sleep" both "On battery" and "Plugged in" are selected off.

6. Press OK and if required restart the computer.

7. To make the Sleep processes be faster you have to disable
7.1. Superfetch; and
7.2. ReadyBoost for your devices.

Disable Superfetch.
1. Open up Services from Control Panel (services.msc)
2. Find the service Superfetch in the list, stop it and disable it for future use.

Disabling ReadyBoost
  1. Plug your USB storage device
  2. Right click on the drive letter of the USB storage device and select properties.
  3. Go to ReadyBoostTab
  4. Select "Do not use this device" option
  5. Click OK.

After doing the described procedures your computer should go into Sleep mode for about 5-8 seconds.