Category Archives: Hacking

Hacking Code :)

Recursively checking out ports tree

I’ve come across a problem posted on #bsdports channel few days ago, how to download a port (FreeBSD) and its dependencies without checking out complete ports tree. So, I hacked a solution for this in Haskell to celebrate my recently attained bliss moment:

λ ghci
GHCi, version 7.6.3:  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :load download-portstree.hs
[1 of 1] Compiling Main             ( download-portstree.hs, interpreted )
Ok, modules loaded: Main.
*Main> downloadPortsTree "editors/emacs-nox11"
Loading package transformers- ... linking ... done.
Loading package mtl-2.1.2 ... linking ... done.
Loading package array- ... linking ... done.
Loading package deepseq- ... linking ... done.
Loading package containers- ... linking ... done.
Loading package bytestring- ... linking ... done.
Loading package old-locale- ... linking ... done.
Loading package time- ... linking ... done.
Loading package unix- ... linking ... done.
Loading package filepath- ... linking ... done.
Loading package directory- ... linking ... done.
Loading package process- ... linking ... done.
PortsList {portsSeen = fromList ["converters/libiconv","devel/gettext","devel/gmake","devel/libffi","devel/ncurses","devel/pkgconf","editors/emacs-nox11","lang/perl5.16","math/gmp","print/indexinfo","security/ca_root_nss","security/gnutls","security/libgpg-error","security/libtasn1","security/nettle","security/openssl","security/p11-kit","textproc/libxml2"], portsNew = fromList []}
Checking out port editors/emacs-nox11
Checking out port devel/gmake
Checking out port converters/libiconv
Checking out port devel/gettext
Checking out port devel/ncurses
Checking out port devel/pkgconf
Checking out port print/indexinfo
Checking out port security/gnutls
Checking out port lang/perl5.16
Checking out port security/libgpg-error
Checking out port security/libtasn1
Checking out port security/nettle
Checking out port math/gmp
Checking out port security/openssl
Checking out port security/p11-kit
Checking out port devel/libffi
Checking out port security/ca_root_nss
Checking out port textproc/libxml2

Happy hacking lambdas… 😉

Sagittarius Scheme — FreeBSD port

Created a FreeBSD port for Sagittarius Scheme for fun1, and have this:

SHA256 (sagittarius-scheme-0.5.5.tar.xz) = 1ddf2841af2d79ddf2a54346e97fe7c0e45b9c486df69b866d60e2e6c89f7e03

The only issue pending is, fixing building on 10-CURRENT, and 11-CURRENT (i386) platforms, which I need some time to look.

[UPDATE: There you go]


1In memory of a sagittarian, I once knew.

Listing FreeBSD packages in order of dependency

So, I upgraded GHC (via pkg) few minutes ago, and didn’t upgrade any of hs- packages, which means now their registration information is gone from GHC’s cache. So as a workaround I just decided to invoke their corresponding which would result in their package being registered:

λ pkg info |awk '/^hs-/ { print $1; }' |xargs -n1 pkg info -l |fgrep |xargs -n1 sudo /bin/sh

This was ideal command except it didn’t work because package list (pkg info) was not topologically sorted. And RTFM-ing pkg info didn’t result in any option which could output topologically sorted listing. But thanks to pkg info -d which generates the list of dependencies, I hacked this, which worked:

λ pkg info |awk '/^hs-/ { print $1; }' |xargs -n1 pkg info -d |awk '/^[[:space:]]+hs-/ { print $1; }'  |sort |uniq -c |sort -k1 -nr |awk '{ print $2; }' |sed -re 's/-[[:digit:]._,]+$//g' |xargs -n1 pkg info -l |fgrep |xargs -n1 sudo /bin/sh


Checkout specific patchset of FreeBSD sources

Following is a script to checkout FreeBSD sources (from its subversion repository) to specific patch-level as asked by a friend on IRC:


if [ -z "$1" -o -z "$2" ]; then
        echo Usage: $0 release patchlevel
        echo e.g. To get 8.0-p5, $0 8.0 5

        exit 0



SVNLOG=$(mktemp -t $(basename $0))

if svn log -l $LIMIT $SVNBASE/$RVER/$NEWVERS >$SVNLOG; then
        BASEREV=$(awk 'BEGIN { sec=1; i=0; } /^r[[:digit:]]+/ { sec=0; revs[i++]=rev=$1; } /^(Security|Errata):/ { sec=1; } /^-+$/ { if(sec == 0) { print revs[i-'$PVER'-1]; exit 0; } }' <$SVNLOG)
        echo svn co -$BASEREV $SVNBASE/$RVER
        echo Error executing svn log

rm -f $SVNLOG
exit $RETVAL

Obligatory screenshot:

chateau.d.if!abbe [~/bin] % co-freebsd-sources 7.0 4
svn co -r182740 svn://
chateau.d.if!abbe [~/bin] % svn cat -r 182740 svn://|grep RELEASE-p
Download link:
SHA256 sum: c9958c4fd7cae5a5e9ff3fa84ba3af6adf38d9c8494b7913ad5b3a2f265a3f48

IRC proxy-ing

Sometime ago, I’ve received SSH access to a host which was quite restricted. Lots of executables are denied execution, as it was supposed to be only for learning, so no network access curl/wget/nc/socat/ssh -(L|D|R), or compilers, but then it’s got bash. Here is a tiny hack to connect to IRC from that host:

1. Create a file on $host:

exec 3<>/dev/tcp/
cat <&3 &
cat >&3

2. Add following line to inetd/xinetd (or netcat):

sua     stream  tcp     nowait          $localuser    /usr/bin/ssh    ssh -i $privatekey -l $user $host bash

3. Now connect your IRC client to localhost:sua (localhost:14001).

This is only a fun hack, and not something used to regularly circumvent access. 😛

On numerous occasions, I need to find the direct shared library dependencies (for ELF ofcourse), and not what ldd(1) outputs. And at all those occasions, I’d to RTFM objdump(1) everytime, and now since I plan to ditch laziness, here is a script which I wrote:


if [ -n "$1" ]; then
	objdump --all-headers $1|awk '/^[[:space:]]*NEEDED/ { print "'$1' "$2; }'
	echo Usage: $0

Obligatory screenshot:

chateau.d.if!abbe [~] % /bin/ls