Programmation

hexdump mon ami

Friday, 06 September 2013
|
Écrit par
Grégory Soutadé

Au boulot, je suis souvent amené à lire du binaire. Sous GNU/Linux, il y a l'utilitaire hexdump. S'il est très pratique, je ne supporte pas le formatage par défaut (8 colonnes, 2 octets par colonne, big endian), lui préférant celui d'EMACS (qui est bien plus naturel). En cherchant ici et là, j'ai trouvé comment avoir un résultat un peu plus sympa :

Simple formatage 16 colonnes, 1 octet par colonne

hexdump -v -e '16/1 "%02x " "\n"' test
cd 7d 3a 34 2f 9c b7 17 b2 46 0f 13 96 dc 29 2c
a7 38 15 c1 40 74 07 1d 34 c8 a2 c6 01 e8 ff e1
0c 52 72 66 4c 6d 55 9a 13 9a 3c fb 09 cc f8 5e

Simple formatage 16 colonnes, 2 octets par colonne (affichage big endian)

hexdump -v -e '16/2 "%04x " "\n"' test
7dcd 343a 9c2f 17b7 46b2 130f dc96 2c29 38a7 c115 7440 1d07 c834 c6a2 e801 e1ff
520c 6672 6d4c 9a55 9a13 fb3c cc09 5ef8 c8b5 f747 c076 3a64 4363 ba02 3cc3 b899
2fdd 0c04 15f0 26fc 4840 de08 5682 0795 f938 dfbd 97e0 6219 4dc1 bd11 a217 48a2

Simple formatage 16 colonnes, 4 octets par colonne (affichage big endian)

hexdump -v -e '8/4 "%08x " "\n"' test
343a7dcd 17b79c2f 130f46b2 2c29dc96 c11538a7 1d077440 c6a2c834 e1ffe801
6672520c 9a556d4c fb3c9a13 5ef8cc09 f747c8b5 3a64c076 ba024363 b8993cc3
0c042fdd 26fc15f0 de084840 07955682 dfbdf938 621997e0 bd114dc1 48a2a217
0b2a4ba6 92e126e3 41b390bb c6715665 513d27ce ac133bf9 c4110439 2617d3eb
6be79814 3c87391d 950461d9 e4fc7027 dcd0bf46 0d690fdc eb5b68d7 3d5d0bee
8d78785d 97e315ee f801f1ac b1d8247a 02bd5328 91acb913 0f6b4024 8eadb09d

Avec l'affichage des adresses

hexdump -v -e '"%08_ax " ' -e '16/1 "%02x " "\n"' test
00000000    cd 7d 3a 34 2f 9c b7 17 b2 46 0f 13 96 dc 29 2c
00000010    a7 38 15 c1 40 74 07 1d 34 c8 a2 c6 01 e8 ff e1
00000020    0c 52 72 66 4c 6d 55 9a 13 9a 3c fb 09 cc f8 5e
00000030    b5 c8 47 f7 76 c0 64 3a 63 43 02 ba c3 3c 99 b8

Affichage par octet sans retour à la ligne

hexdump -v -e '/1 "%02x "' test
cd 7d 3a 34 2f 9c b7 17 b2 46 0f 13 96 dc 29 2c a7 38 15 c1 40 74 07

Avec l'affichage des caractères

head -n 3 gpl-3.0.txt| hexdump -e '8/1 "%02X " "\t\t"' -e '8/1 "%c" "\n"'
20 20 20 20 20 20 20 20                
*
20 20 20 20 47 4E 55 20            GNU
47 45 4E 45 52 41 4C 20        GENERAL
50 55 42 4C 49 43 20 4C        PUBLIC L
49 43 45 4E 53 45 0A 20        ICENSE

Variante (sans les étoiles)

head -n 3 gpl-3.0.txt| hexdump -v -e '8/1 "%02X " "\t\t"' -e '8/1 "%c" "\n"'
20 20 20 20 20 20 20 20                
20 20 20 20 20 20 20 20               
20 20 20 20 47 4E 55 20            GNU
47 45 4E 45 52 41 4C 20        GENERAL
50 55 42 4C 49 43 20 4C        PUBLIC L
49 43 45 4E 53 45 0A 20        ICENSE

On peut ainsi combiner les formatages à l'infini pour avoir le résultat souhaité !

KissCount 0.4

Wednesday, 12 June 2013
|
Écrit par
Grégory Soutadé

Fenêtre principale de KissCount

Sortie annuelle de KissCount. Pour ceux qui ne s'en souviennent pas, il s'agit d'un logiciel de comptabilité personnelle dont l'objectif est d'être le plus simple possible : je l'ouvre, je rentre les données (dans une seule fenêtre), je le ferme. Des versions (.deb) pour i386 et amd64 ainsi que pour Windows sont disponibles. Cette version marque une certaine maturité du projet. En effet, les changements sont assez peu nombreux :

  • Ré écriture du composant principal (grille)
  • Export au format CSV
  • Icônes basse résolution
  • Affichage des statistiques dans la recherche
  • Quelques bugs en moins


Quid de la suite ? Probablement une migration vers Qt5. Pour le moment il n'y a pas de nouvelles fonctionnalités de prévu.

Colored make output

Thursday, 18 April 2013
|
Écrit par
Grégory Soutadé

If I often compile under emacs, I use a lot the terminal. Most of people ignore how it's fast and practical to work, not for every tasks but it's perfect for programing. I already talks about Autojump2, today I will present colout. It's true that the terminal miss some colors. For better displays I personaly use black over white, but when you compile some projects, it's hard to see if errors happens.

I tweak colout (written by nojhan) to fit my needs. It's a simple Python software that will color terminal output if it found specific words. The list of words is fix and embedded into the script (unlike the original one that takes them in parameter). My script is available here.

You only need to add colout file into a bin directory (referenced in your $PATH) and edit your .bashrc with (don't forget to make it executable) :

function make() { /usr/bin/make "$@" 2>&1 | colout ;}

So, when you type "make", it will transparently use colout. The only bad thing is that you loss make's returns value.

Example with :

int main() { int a, b; b = a+1; c = a; return 0; }

colout result

It's better, isn't it ?

Command line loader for "Read for PIC" Board

Sunday, 24 March 2013
|
Écrit par
Grégory Soutadé

Ready for PIC board

Some weeks ago I bought a "Ready for PIC" board from MikroElektronika. These board comes with a PIC18F25K22 flashed with a bootloader that receives a program from UART and load it in memory without flashing. The prototype area is very nice for peoples that do not want to weld, it also contains a FTDI chip and can be powered by USB. Plus MikroElektronika supply a GUI software to interact with the bootloader. These GUI is available for Windows and Linux, that's great ! Contrary to microchip, MikroElektronika wants to sell their expensive C/BASIC/Pascal compiler and provide cool boards at a good price. The only thing I regret is that you cannot reset the PIC with the FTDI, you need to press the reset button before and after code is downloaded (so boring...).

Maybe the GUI is useful for electronics peoples, but I found it (on Linux) heavy and sometimes buggy. Moreover you cannot access to serial output just after code is downloaded. So, I wrote a simple console Python program that will download an HEX file with command line and optionally displays the output of UART. This allows to do quicker and simpler tests. You can find the file here, it's licensed under GPL v3.

Notification par SMS

Tuesday, 19 February 2013
|
Écrit par
Grégory Soutadé

SMS in classroom

Un serveur perso c'est bien, un serveur auto hébergé c'est très bien, mais un serveur auto hébergé qui a planté, c'est nul ! L'inconvénient du plantage système est qu'il ne prévient pas, du coup la durée d'indisponibilité peut être longue si l'on ne s'en rend pas compte.

Pour pallier à ce problème, j'ai fait un petit retour vers OVH. Mon compte n'ayant pas été clôturé après la migration du nom de domaine, j'en ai profité pour acheter un pack SMS. Pour environ 10€ TTC, j'ai 100 SMS que je peux envoyer via le web. Ce petit script bash permet de me notifier lorsque le serveur tombe. Bien sûr, il faut pouvoir l'exécuter sur un PC connecté h24...

L'idée est de faire un HEAD sur la favicon de mon blog (qui n'existe pas et qui n'apparaît pas dans les log). La requête est exécutée toutes les 10 minutes. Au bout de 3 échecs successifs (pour éviter les problèmes de changement d'IP), un SMS est envoyé et le script quitte.

#!/bin/bash BASE_URL="https://www.ovh.com/cgi-bin/sms/http2sms.cgi" ACCOUNT="sms-sgXXXXX-1" LOGIN="BBBBBB" PASSWORD="YYYYYYYY" FROM="SOUTADE" TO="%2B33666ZZZZZZ" #+33666ZZZZZZ MESSAGE="Cybelle%20is%20down" # Cybelle is down MAX_TRIES=3 TARGET="http://blog.soutade.fr/favicon.ico" request="$BASE_URL?account=$ACCOUNT&login=$LOGIN&password=$PASSWORD&from=$FROM&to=$TO&message=$MESSAGE&noStop=1" #echo $request tries=$MAX_TRIES while [ 1 ] ; do HEAD $TARGET | grep "404" >/dev/null # Found if [ $? -eq 0 ] ; then # Reset counter if [ ! $tries -eq $MAX_TRIES ] ; then tries=$MAX_TRIES fi else # Fail tries=`expr $tries - 1` fi # No more tries, send notification and exit if [ $tries -eq 0 ] ; then GET "$request" break fi sleep 10m done

PS : Pour utiliser le script, il faut créer un nouvel utilisateur et ajouter un expéditeur depuis l'interface OVH. Attention, les champs doivent être encodés sous la forme URL (voir la partie "encode" de http://soutade.fr/urlunshortener)