Google
 

Thursday, December 25, 2008

Null function pointer trick

Few days ago Ayush posted the following code to our class' mailing list. What does the following C code do??


unsigned char *virus;
virus = (char *)(((int) virus + PAGESIZE-1) & ~(PAGESIZE-1));
((void (*)())virus)();

Cracked me a while, but here's the explanation:

Line 1 is pointer to unsigned char, straight forward..

Line 2 looks a bit confusing but is a brilliant technique for 'ceiling'ing integers. This converts the address of virus to next multiple of PAGESIZE. The code is working with memory location, so I assume PAGESIZE is some power of 2. Suppose say if PAGESIZE is 1024, then for

*virus = 123 => 1024
*virus = 2000 => 2048
and so on..

Hope u got the point. Just some bit-arithmetic to change the location pointed by virus to next memory page (assuming PAGESIZE = size of one page)

Line 3 involves simple null function pointer. From line 2, variable virus contains location to start of a page (the page might contain virus code, written by some means like buffer overflow exploit ;)). Now (void (*)()) is null pointer to function. so the above code will execute the function at memory location pointed by virus with no arguments.

Gnome: drag text to file

Got this one by accident. In Gnome, if you drag some text and drop it to desktop or nautilus, it creates a file with the dragged text in it. Simple, but might come handy sometimes..

Drag the text

After dropping, you land into file rename mode :)

Tuesday, December 16, 2008

The init Magazine Issue #3

The third issue of The init Magazine is out. Grab your copy now!

Direct Link:
http://ioefoss.ioelive.com/theinitmagazine/theinitmag03.pdf

Old Issues: http://ioefoss.ioelive.com
Mirror: http://meronepalma.com/initmag

Please send your feedbacks/suggestions at ioefossnewsletter_at_gmail.com

Enjoy!

Sunday, December 14, 2008

Nepali Spell-check Dictionary for Firefox

Under Linux, if you have Nepali Spell-check enabled for OpenOffice.org (instructions here), Nepali spell-check works in Firefox as well. But for those who want it just for Firefox (or, Thunderbird), I've created a small extension which does the job.

Installation Instruction

  • Download the installation package here or from Firefox Addon Page.
  • Drag and drop the file to Firefox and follow the instructions
  • For Nepali spell-check, right click in the textbox and select Languages > ne_NP
Choose ne_NP from Languages menu



The extension is currently experimental at
Firefox Addon Page. Please drop your valuable review/comments there.

Thursday, December 04, 2008

URL Validity

Few days ago NewsFromNepal was asking me for some help on some URL validation code. The task was to verify a list of URLs and print the title of the page if it's valid/working. Here's a simple Python script to do that. The URLs are stored per line in url.txt


#! /usr/bin/python
# URL Validity

import urllib2
import re

urls = open('urls.txt', 'r').readlines()
badurls = []

print "Working URLs:",
for url in urls:
try:
handle = urllib2.urlopen(url)
html = handle.read()
match = re.search("<title>(.*)</title>",html)

print "\n", url.strip(), " -> ",
if match:
print match.groups()[0],
except:
badurls.append(url)

if badurls:
print "\nBad URLs:"
for bad in badurls:
print bad.strip()