Sunday, November 29, 2009

How To Configure BinUtils?

When you simply compile binutils with "./configure; make", objdump will only support your machine's native architecture. In order to enable various targets, you have to use "--enable-targets" option when you configure it.

The simplest way is "--enable-targets=all", which will configure all possible architectures including ARM, MIPS, PowerPC, and so forth. However, this will generate more than 1 GB of object files inside your source code directory.

So, choose your favorite architectures, and use commas to separate them.

For example, if you want to enable ARM and MIPS for your objdump, use the following command.

./configure --enable-targets=arm-elf,mips

You can also use pe-i386 target to objdump PE files in your linux box.

Sunday, November 22, 2009

Use Urlview with Mutt on Mac OS X

Urlview is a simple command line program that extracts urls from a text document. You can easily invoke your web-browser from Mutt to follow hyperlinks in your email.

If you use Linux, you can easily get urlview from your favorite package manger, but not on Mac Os X. However, there exists another version of urlview written in a ruby script. It is simple and safe (not written in C)

You can download a copy from this url.

Here is the Easiest way to use the urlview script with mutt on your Mac OS X.
  1. Download urlview (the ruby version) from here.
  2. Modify the file of line 26, from "BROWSER='firefox'" to "BROWSER='open'"
  3. Comment out the line 31 : $stdin.reopen 'COM1:'
  4. sudo chmod +x ~/Download/urlview.rb
  5. sudo mv ~/Download/urlview.rb /usr/bin
  6. Add the following lines in your muttrc.
    (Note that the macro is binded with f4 key. You can change it to whatever you want.)
    macro index "<f4>" "<pipe-message>urlview.rb<enter>" #URLviewer
    macro pager "<f4>" "<pipe-message>urlview.rb<enter>" #URLviewer
Now you can easily browse any web links from Mutt on Mac.

Saturday, November 21, 2009

Mutt Address Book Lookup on Snow Leopard

I like the default "Address Book" on Mac OS X. It is simple and easy to use. However, since Snow Leopard, we cannot use lbdb (the Little Brother's Database) anymore due to a bug. This is annoying for mutt users like me.

There are many alternative applications including abook, neuron, etc. But, is there any workaround to use the Address Book on Mac for mutt query?

Here is how I use Address Book with mutt on Mac.

Address Book internally uses sqlite database. You should be able to find the database file in the following path: $HOME/Library/Application Support/AddressBook/AddressBook-v22.abcddb. So, we can write a simple script that prints out the query result from the database.

Well, if you look at the database, you will see the name of each database field is kind of obfuscated. But don't worry. You only need to look at these two tables: ZABCDEMAILADDRESS and ZABCDRECORD. By querying the DB over the two tables, we can easily get what we want.

So, here is a brief how-to.
  1. Make a script as follows. (addressbook.rb)
  2. Put the script in your $HOME/.mutt directory.
  3. Modify your .muttrc file. (set query_command="~/.mutt/addressbook.rb '%s'")
  4. Enjoy!

addressbook.rb
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby
if ARGV.count != 1
    puts "Not found."
    exit 1
end

output = `sqlite3 -separator \
\"\t\" ~/Library/Application\\ Support/AddressBook/AddressBook-v22.abcddb \
'select mail.ZADDRESS, rec.ZFIRSTNAME, rec.ZLASTNAME \
from ZABCDEMAILADDRESS as mail,ZABCDRECORD as rec \
where (mail.ZADDRESS like \"%#{ARGV[0]}%\" \
or rec.ZFIRSTNAME like \"%#{ARGV[0]}%\" \
or rec.ZLASTNAME like \"%#{ARGV[0]}%\") and rec.Z_PK=mail.ZOWNER'`

if $? != 0
    raise "Query Error"
else
    if output.empty?
        puts "Not found."
        exit 1
    end
    puts # start with blank line
    output.split("\n").each {|line|
        tuple = line.split("\t")
        if tuple.count != 3
            puts "Not found."
            exit 1
        end
        print tuple[0] + "\t" + tuple[1] + " " + tuple[2] + "\t\n"
    }
    exit 0
end

puts "Not found."
exit 1

About

My photo
Hi, I am a PhD candidate at CMU. I was one of the founding members of PPP (Plaid Parliament of Pwning). I like programming in OCaml, F#, Haskell, and C++.