Posts

A Simple Python NodeVisitor Example

The Python ast module helps parsing python code into its abstract syntax tree and manipulating the tree. This is immensely useful, e.g., when you want to inspect code for safety or correctness. This page walks you through a very simple example to get you up and running quickly. A Very Simple Parser The first step to analyzing a program is parsing the textual source code into an in-memory walkable tree. Module ast takes away the hard task of implementing a generic lexer and python parser with the function ast.parse() . The module also takes care of walking the tree. All you have to do is implement analysis code for the type of statements you are want to analyze. To do this, you implement a class that derives from class ast.NodeVisitor and only override the member functions that are pertinent to your analysis. NodeVisitor exposes callback member functions that the tree walker ("node visitor") calls when it encounters particular python statements, one for each type of ...

Pierce Firewall from within using netcat (e.g., for Bittorrent)

Opening ports in a firewall If you find yourself behind a firewall that you cannot control, you often have no open network ports for others to contact you on. End-users generally only need this for peer to peer applications, such as Bittorrent and Skype. Pretend to initiate an outbound connection using Netcat Each time you make an outbound connection, the firewall creates a temporary opening to allow the other side to respond (say, Google to return your search results). You can exploit this feature to run Bittorrent or other servers. Pierce the firewall with a packet that originates from your computer and from the port that you want others to later contact you on (say, 6881 for Bittorrent). The easiest is to send a packet using netcat Using openbsd netcat, this worked for me: nc -p 6881 www.google.com 80 Don't wait for a reply, just send the request, close netcat and open your real application. Note that the port will only remain open for a limited time if there is no traffic, ...

Lighttpd with static modules

For the Nexus OS I need a version of lighttpd that is statically linked. Even when you build lighty as a static library, it by defaults expects to load its modules (access, dirlisting, staticfile, cgi, ...) at runtime. The following trick makes lightly include modules in the statically linked binary. It has been tested against version 1.4.25. CFLAGS Compile with the debug flag -DLIGHTTPD_STATIC set. I noticed that my gcc (4.4.1) also complained about syntax, so I had to force gcc to interpret as the C99 standard: make CFLAGS=-DLIGHTTPD_STATIC -std=c99 src/Makefile.in changes In src/Makefile.in (from which configure generates src/Makefile), add the modules you want to include (say, mod_access and mod_staticfile) to all lists of input to target lighttpd. Specifically, add to am__liblightcomp_la_SOURCE_DIST, am__lighttpd_SOURCES_DIST and common_src: mod_access.c mod_staticfile.c And also add the objects. To am__objects_1 and am__objects_2 mod_access.$(OBJEXT) mod_staticfile.$...

Daily git commit emails

Git can send an email for each git push into the repository using the post-receive hook . I wanted to have daily messages, as opposed to one for each commit. The following script does that: #!/bin/bash # duration of log (default: daily) as offset since now RELDATE="24 hours ago" # email recipient EMAIL=a@b # bare repository home GITROOT=/opt/git/nexus # branch BRANCH=refs/heads/master cd $GITROOT/hooks # the latest commit NEWREV=`git rev-list -n 1 HEAD` # the latest commit not to report OLDREV=`git rev-list -n 1 --date=relative --until="$RELDATE" HEAD` # only send an email if there are commits if [[ $NEWREV == $OLDREV ]] then exit 0 fi /usr/share/doc/git-core/contrib/hooks/post-receive-email \ $BRANCH $OLDREV $NEWREV | /usr/sbin/sendmail $EMAIL Change the GITROOT variable to point to the root of your repository and create a daily cron job: crontab -e For instance 12 2 * * * /usr/sbin/git-dailylog.sh Some assumptions: This might only work f...