Friday, September 23, 2011

Oggi cade un satellite

Oggi cadrà sulla Terra un satellite. E (guarda caso) tra i possibili bersagli c'è proprio l'Italia, come se in questi mesi non avessimo già abbastanza problemi.

Il satellite in questione, che si chiama UARS, è stato lanciato dalla Nasa nel 1991 per studiare il ruolo della termosfera e della esosfera nei cambiamenti climatici. Questo simpatico aggeggino, che monta vari strumenti per la misurazione dei composti chimici all'interno dello strato di ozono, per misurare la forza delle correnti ventose e per studiare quanta energia arriva dal Sole a quelle altitutidini, doveva avere una vita operativa di 3 anni.

Invece è durato molto di più, ma ora, dopo 7317 giorni in orbita, è arrivato per lui il momento di rientrare. Non sarà un rientro tranquillo, perché lo scopo di questa operazione non è quella di recuperarlo per raccogliere dati, no: quelli vengono inviati via radio costantemente. Lo scopo è fare un po' di pulizia, e questo si ottiene facendolo disintegrare a contatto con la stratosfera.

Ma qualcosa è andato storto: le simulazioni della Nasa affermano che non tutti i pezzi si disgregheranno, alcuni riusciranno ad arrivare al suolo. Ovviamente tutto ciò è dedotto da una simulazione computerizzata (e se le simulazioni che fanno loro sono simili a quelle che vedo fare io ogni giorno, ci sta davvero che non si può essere sicuri che il risultato atteso sia esatto!), la conferma ufficiale deve ancora arrivare. Mi viene solo da far notare che probabilmente queste conferme, visti i tempi, arriveranno ben dopo lo schianto dello stesso...


(Queste le possibili traiettorie di caduta)


Quindi c'è una grande allerta. Attenti tutti, che vi casca l'alettone solare in testa tra qualche ora! Le probabilità che qualcuno venga coinvolto sono 1:3200!

Da parte mia, mi viene solo da sperare che il satellite abbia buona mira, e magari prenda in pieno Berlusconi...

Thursday, September 22, 2011

Backwards compatibility of PNG


If you design website templates, the possibility to use transparent images is very useful. In particular, relying on PNG images is somewhat awesome, because it can contain an alpha (transparency) channel, which tells the renderer how much every single pixel must be transparent. This allows, unlike GIF, to create smooth blendings of the images, no matter what the background color/image is.

Unfortunately, this format is not completely supported by every browser (especially by Internet Explorer, prior to version 7), even though the more modern ones are in step with the times. This problem was (is!) so annoying that the W3C Consortium has one page dedicated to inline transparency testing.

Compatibility issues are an important aspect when dealing with websites, most of all if you're running commercial pages.

Several strategies have been proposed to address the alpha channel issue in PNGs. The one I am proposing here is a javascript-based one.

The principle of this technique comes bundled in a filter included in Microsoft Internet Explorer since version 5.5, called AlphaImageLoader. It takes an image and displays it within the boundaries of a pre-existing image in the HTML DOM, giving support for PNG transparency.

The idea is now straightforward: a completely-blank 1px GIF image is displayed, adapted to the desidered size, and then the requested PNG is applied over it. This could be easily done with the following code:



Unfortunately, this is not as fair as we might think. In fact, this code is completely unportable: Chrome, Mozilla or Opera browsers don't implement AlphaImageLoader filter, so under those browsers, we would get just a blank image.

Then, we have to find a workaround to the workaround. This can be done through Microsoft IE's Conditional Comments. In short, what we're going to do, is to produce some javascript code, save it in a .js file, and include it in the html document as follows:

<!--[if gte IE 5.5000]>
<!--[if lte IE 7]>
<script language="JavaScript" src="pngtransp.js"></script>
<![endif]>
<![endif]>

The full source code for pngtransp.js can be found here. Let's now have a closer look at the interesting snippets, starting from the last line:

window.attachEvent("onload", correctPNG);

This is put there just to "arm the code": when the document is fully loaded, the correctPNG starts up automatically.
That function's purpose is to scan for all images in the document, and check whether they are PNGs or not. This is achieved as follows:

for(var i=0; i<document.images.length; i++)
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")

Later on in the code, we retrieve all information about the image, such as its title, alignment, class name and so on.
Then, we generate new code for the image, which is:

var strNewHTML = "<span " + imgID + imgClass + imgTitle;
strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"; strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"; strNewHTML += "(src=\'" + img.src + "\', sizingMethod='scale');\""; strNewHTML += onMouseOver + onMouseOut + "></span>";
in which we create a span with all the previously retrieved information, but with the AlphaImageLoader filter specified. This way, when we invoke:

img.outerHTML = strNewHTML;

the current PNG will be correctly displayed. The procedure is repeated for each PNG image in the document.

The rest of the code is just for overriding the commonly used Dreamweaver's functions to swap images on mouse over, and are not of deep interest to this arcticle.

This way of handling PNG will leave the images untouched if we're using a more "modern" browser, but will correct the alpha blending in more primitive ones.
Though, it has some drawbacks:

  1. Doesn't work in IE versions earlier than 5.5, since AlphaImageLoader is not supported. No cure for those versions.
  2. Javascript must be enabled: you can't assume this on all machines!
  3. CSS image background with PNGs is not supported at all!
  4. If you are displayng a huge document, before the onload event triggers, a while could pass, so at the beginning PNGs could be displayed with the unpleasant gray box around!

The only solution to correctly handle PNGs, is to switch definitively to another web browser!

Tuesday, September 20, 2011

New Template

I decided it was time to drop the support for old 800x600 resolution.

The main reason is that I believe no one is still using it. And if you are, then it's your own business...

As I'm pretty busy now, I went for a predefined template. Yes, it's not stylish, but some customizations will be coming in the next days (as long as I find some time). In the meanwhile, it seems to be helping in readability!

Friday, September 16, 2011

Windows Graffiti (or how to mangle text from 3rd party applications)

When experimenting with low level code, trampolines quickly peep out.

To make the long story short, it's a nice technique which can be used to make some function transparently (to the caller) execute other pieces of code.

It is a technique so powerful (and neat) that it is widely used in fundamental issues (library calls, to make an example, where - in the ELF executable format - got and plt tables are used to dynamically relocate code after the actual process has been started, usually according to some sort of lazy load policy).

Much more interesting is the possibility to use trampolines to dynamically (i.e., at runtime) modify some process, to hijack its execution and make it do something which it was not intended to do when it was written. Several mature tools exist to help achieve this task (like DynamoRIO), and even some simpler tools like DYNINST or a rule-based instrumentor which I'm working on since 2 years (and which will be released, eventually).

Monday, April 11, 2011

Sei modi per mandare Linux in crash. Perché è divertente ed inutile!

Questo è uno di quei post assolutamente senza senso, ma che mi piacciono. È come giocare alla WII: non ha senso, ma ti (ci) piace!
Qui di seguito ci sono alcuni modi per mandare in crash un sistema Unix. Alcuni di essi sono ben conosciuti, come la Fork Bomb, altri sono più oscuri. Alcuni sono irreversibili, altri invece durano soltanto "una sessione", e dopo un bel riavvio tutti gli effetti sono spariti.


  • La Fork Bomb: è un classico che non può essere omesso da questo elenco. In effetti, gli viene dedicata persino un'intera pagina su Wikipedia!
     :(){ :|: & };:
    Questo comando, incollato in una shell, farà terminare alla macchina tutte quante le risorse, a meno che il numero di processi per utente non venga limitato in /etc/security/limits.conf.
  • Il comando seguente sovrascriverà l'MBR com dati (pseudo) casuali. In questo modo, si potrà essere sicuri che la propria macchina non riparta più (no, neppure con Windows).
    dd if=/dev/urandom of=/dev/sda bs=512 count=1
  • Leggere dalle porte di I/O può avere dei simpatici effetti secondari. Provate ad eseguire questo comando, e capirete quello di cui sto parlando:
    sudo less -f /dev/port
    Il risultato sarà che la vostra macchina si inchioderà. Non ho ancora approfondito il motivo alle spalle di questo fenomeno, ma è comunque divertente!
  • Cosa succede se la memoria di un processo viene sovrascritta? Di solito, ci si imbatte in un segfault. Si può infilare un po' di divertimento (casino!) nella memoria di sistema:
    cp /dev/zero /dev/mem
  • Quest'ultimo è diventato un cult, dal momento che un sacco di gente ci si è imbattuta (forse anche tu). In qualche modo si fa confusione, e si rimuove ogni singolo file dal disco rigido
    rm -rf /*


In ultimo, si può utilizzare il potere del comando 'find', con l'argomento 'exec' che eseguirà il comando scritto immediatamente dopo. Questo è esattamente quello che può capitare quando si va di fretta.
find . -type f -name * -exec rm -f {} \;
Per fortuna, molti di questi comandi (eccezion fatta per la Fork Bomb), non danneggeranno il vostro computer se lanciati come utenti senza privilegi di amministratore, perché il sistema non vi lascerà accedere a file per i quali non avete i permessi.
Ovviamente, se si prova a scrivere qualche modulo del kernel, è molto probabile che esso vada in crash con la vostra approvazione! :) A quel punto, qualsiasi cosa è possibile, perché sarete diventati l'"Onnipotente"!

Wednesday, March 23, 2011

Large Hadron Rap

This is an evergreen which dates back to 2008, when this huge experiment was set up at CERN, to find the presence of antimatter... I came again into this some hours ago... And I had to republish this, along with its text and a translation for my fellow Italians... :)



(by the way, alongside there is a second experiment, which demonstrates why scientists should never try to play as showmen... :))

Saturday, March 12, 2011

Come scrivere codice incomprensibile: camuffaggio

Molte delle abilità alla base della scrittura di codice incomprensibile è l'arte del camuffagio: nascondere le cose, o farle apparire per quello che non sono. Molte di queste abilità dipendono da fatto che il compilatore è più bravo dell'occhio umano nel fare fini distinzioni.


Codice che si maschera da commento, e viceversa
Un'ottima idea è quella di includere del codice commentato, che però non sembra esserlo:

for(j = 0; j %lt; array_len; j += 8) { 
   total += array[j+0]; 
   total += array[j+1]; 
   total += array[j+2]; /* Il corpo principale
   total += array[j+3]; * del ciclo è espanso
   total += array[j+4]; * per aumentarne la
   total += array[j+5]; * velocità
   total += array[j+6]; */
   total += array[j+7]; 
}

Se non ci fosse il coloratore della sintassi, qualcuno si accorgerebbe mai che quattro righe di codice sono commentate?


Wednesday, March 9, 2011

Showing a Tree

In these GUIful days, where everything we do on a computer involves using the mouse pointer, sometimes there comes situations where we want an old-fashioned visualization of data.

For example, in these days I'm working hard on the restyling of an application which be released soon. This entails cutting old functions, adding comments, rewriting Makefiles, and rearranging the directory tree. Yes, the boring part off programming.

For easiness, I decided to print the whole directory tree listing of my project, to better visualize the changes I have to apply to my project. Thus, before coming into tree(1) I opted for the hard-coded solution, and produced this command:
ls -R | grep ":" | sed -e 's/://' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
Which will draw the currents' directory tree listing. Surely, using tree is much easier and more efficient, but this old-fashioned approach is what I like most!

Monday, February 21, 2011

Intercepting Keystrokes in any Application

This post is about one simple question: is Windows' software secure?

The answer is: no, it's not.

In the next few lines, I will show you how to easily write some code which will allow you to intercept text which is being typed into any other application! In particular, I will illustrate how to write a simple dll which will delete any lowercase vowel typed by the user...
And yes, this is one of the techniques behind keyloggers...

Since these are multimedial days, here there is a video showing how this dll can interact with a common application (Microsoft Word):



Tuesday, January 25, 2011

Hacking

L'idea di hacking può riunire assieme preconcetti come vandalismo elettronico, spionaggio, capelli tinti e piercing. La maggior parte della gente associa l'hacking all'infrazione della legge, etichettando quindi tutti coloro che si dedicano all'hacking come criminali. Sicuramente in giro c'è gente che utilizza tecniche di hacking per infrangere la legge, ma tutto questo non c'entra nulla con l'hacking in sé.

L'essenza dell'hacking è quella di trovare usi delle leggi o delle proprietà di una data situazione che non erano previsti oppure venivano tenuti segreti, al fine di riapplicarli con modalità nuove e con inventiva per risolvere un problema. Il problema in questione può essere la mancanza di accesso ad un computer, oppure cercare di trovare il modo per utilizzare vecchi apparecchi telefonici per gestire un modello di controllo ferroviario. Di solito, le soluzioni hackerate risolvono questi problemi in modo unico ed inimmaginabile da coloro che sono confinati nella metodologia convenzionale.