2009-01-30

ubuntu 256 bit color urxvt

Steps used to recompile urxvt with the 256 bit color patch.
$ apt-get source rxvt-unicode
$ sudo apt-get build-dep rxvt-unicode
$ cd rxvt-unicode*
$ patch -p1 < doc/urxvt-8.2-256color.patch
$ dpkg-buildpackage -us -uc -rfakeroot
$ sudo dpkg -i rxvt-unicode_9.05-4_i386.deb
$ echo "rxvt-unicode hold" | sudo dpkg --set-selections
The last step makes sure apt doesn't reinstall the old package the next time you update.

urxvt meta character gotcha

I recently switched from xterms to rxvt-unicode, unfortunately the added unicode support broke some key bindings I used to navigate tabs in vim.

Originally I had:
...
map <A-1> 1gt
map <A-2> 2gt
map <A-3> 3gt
map <A-4> 4gt
map <A-5> 5gt
map <A-6> 6gt
map <A-7> 7gt
map <A-8> 8gt
map <A-9> 9gt
map <A-0> 10g
...
Allowing me to switch between tabs with alt 1-10, like firefox.

The way urxvt handles unicode, treats the alt sequence as an escape sequence.

The rxvt-unicode --meta8 option didn't help, neither did anything I found googling.

A little python foo and we have a fix.
$ python -c 'for i in xrange(1, 11): print "map \x1b%d %dgt" %((i%10), i)' >> ~/.vimrc
I now have the following in my .vimrc:
...
map ^[1 1gt
map ^[2 2gt
map ^[3 3gt
map ^[4 4gt
map ^[5 5gt
map ^[6 6gt
map ^[7 7gt
map ^[8 8gt
map ^[9 9gt
map ^[0 10gt
...

2009-01-10

freeze.py disassemble

freeze.py is a tool used to make a standalone binary out of a python script.

freezedis.py is a tool I put together to parse the elf binary and pull the python code back out, recreating the .pyc file. For now, it does not support stripped binaries.
$ more hello.py
#!/usr/bin/env python
import sys

def main(argc, argv):
print "hello"

if __name__ == "__main__":
main(len(sys.argv), sys.argv)

$ /usr/share/doc/python2.5/examples/Tools/freeze/freeze.py hello.py
...
$ make
$ file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.8,
dynamically linked (uses shared libs), not stripped

$ freezedis.py
Usage: freezedis.py [options] filename
-o filename.pyc (defaults to a.pyc, appends .pyc if not included)
-d dump disassembly of newly created pyc

$ freezedis.py -d hello
2 0 LOAD_CONST 0 (-1)
3 LOAD_CONST 1 (None)
6 IMPORT_NAME 0 (sys)
9 STORE_NAME 0 (sys)

4 12 LOAD_CONST 2 ()
15 MAKE_FUNCTION 0
18 STORE_NAME 1 (main)

7 21 LOAD_NAME 2 (__name__)
24 LOAD_CONST 3 ('__main__')
27 COMPARE_OP 2 (==)
30 JUMP_IF_FALSE 29 (to 62)
33 POP_TOP

8 34 LOAD_NAME 1 (main)
37 LOAD_NAME 3 (len)
40 LOAD_NAME 0 (sys)
43 LOAD_ATTR 4 (argv)
46 CALL_FUNCTION 1
49 LOAD_NAME 0 (sys)
52 LOAD_ATTR 4 (argv)
55 CALL_FUNCTION 2
58 POP_TOP
59 JUMP_FORWARD 1 (to 63)
>> 62 POP_TOP
>> 63 LOAD_CONST 1 (None)
66 RETURN_VALUE
Disassembly of main:
5 0 LOAD_CONST 1 ('hello')
3 PRINT_ITEM
4 PRINT_NEWLINE
5 LOAD_CONST 0 (None)
8 RETURN_VALUE