PROJET AUTOBLOG


BohwaZ

Site original : BohwaZ

⇐ retour index

Mise à jour

Mise à jour de la base de données, veuillez patienter...

Bubble Babble CLI encoder / decoder

samedi 24 janvier 2015 à 03:16

At my own surprise there is no CLI tool to encode or decode a string to and from the Bubble Babble binary encoding. That's a shame as this encoding would be much more useful than Base64 for exchanging binary data orally or on paper.

So here is one quick PHP script based on my own PHP5 BubbleBabble library to do that: bubblebabble.php

Usage is pretty simple:

$ bubblebabble.php hello.txt
xifok-mirid-bodik-nemyg-temyl-dipyd-cedyx

$ bubblebabble.php -d - <<< xifok-mirid-bodik-nemyg-temyl-dipyd-cedyx
Oh, Hi Mark!

$ fortune | bubblebabble - > encoded.txt

$ bubblebabble -d encoded.txt 
Big book, big bore.
		-- Callimachus

Undocumented PHP/SQLite3 features: openBlob, readOnly, enableExceptions

vendredi 23 janvier 2015 à 01:34

The SQLite3 module of PHP has some undocumented features that you may discover when you are reading the source code (yes that's what I do when I get bored, nothing is more fascinating than reading source code, really, you should try it).

Sqlite3Stmt::readOnly(void)

Available from PHP 5.3.5.

This method returns true if a statement doesn't change the database. This is useful sometimes, like to make sure that a template engine is only reading data and not altering the databse. Another use would be providing a way for the user to make queries on the database to select any data he wants (yes you wouldn't want this to be available to any user).

One example to check if there is no injection:

$_GET['id'] = 42;
$statement = $db->prepare('SELECT * FROM cooking_recipes WHERE id = '.$_GET['id'].';');
var_dump($statement->readOnly());
// bool(true)

And if there was an injection:

$_GET['id'] = 'NULL; DROP TABLE nuclear_warheads_locations;';
$statement = $db->prepare('SELECT * FROM cooking_recipes WHERE id = '.$_GET['id'].';');
var_dump($statement->readOnly());
// bool(false)

Of course you NEVER should insert any PHP variables straight in a SQL query. Instead you should use bindValue:

$statement = $db->prepare('SELECT * FROM cooking_recipes WHERE id = :id;');
$statement->bindValue(':id', $_GET['id']);

SQLite3::openBlob(string table, string column, int rowid [, string dbname])

Another undocumented feature of the PHP SQLite3 object, available since 2009, is openBlob. Basically it's a function that will return a stream pointer to a blob value in a table. Very very useful when you are dealing with files stored in a SQLite3 database.

Source code says:

proto resource SQLite3::openBlob(string table, string column, int rowid [, string dbname])
Open a blob as a stream which we can read / write to.

But despite that it's not possible to write to the blob, only reading is implemented. The blob are always opened as read-only by SQLite, so if you try to write to the stream, nothing will be saved to the database.

One example of use:

$db = new SQLite3('files.sqlite');
$db->exec('CREATE TABLE files (id INTEGER PRIMARY KEY, filename TEXT, content BLOB);');

$statement = $db->prepare('INSERT INTO files (filename, content) VALUES (?, ?);');
$statement->bindValue('filename', 'Archive.zip');
$statement->bindValue('content', file_get_contents('Archive.zip'));
$statement->execute();

$fp = $db->openBlob('files', 'content', $id);

while (!feof($fp))
{
    echo fgets($fp);
}

fclose($fp);

You can also seek in the stream. This is pretty useful for saving large files from the database too, this way you can use stream_copy_to_stream, it will be faster and more memory-efficient than dumping the file in memory before writing it to the disk.

Please note that openBlob() won't work on VIRTUAL FTS4 compressed tables (but no problem with non-compressed virtual tables).

SQLite3::enableExceptions([bool enableExceptions = false])

Available since 2009 (PHP version ??).

If set to true, then errors will be returned as exceptions instead of errors.

Undocumented PHP/SQLite3 features: openBlob, readOnly, enableExceptions

vendredi 23 janvier 2015 à 01:34

The SQLite3 module of PHP has some undocumented features that you may discover when you are reading the source code (yes that's what I do when I get bored, nothing is more fascinating than reading source code, really, you should try it).

Sqlite3Stmt::readOnly(void)

Available from PHP 5.3.5.

This method returns true if a statement doesn't change the database. This is useful sometimes, like to make sure that a template engine is only reading data and not altering the databse. Another use would be providing a way for the user to make queries on the database to select any data he wants (yes you wouldn't want this to be available to any user).

One example to check if there is no injection:

$_GET['id'] = 42;
$statement = $db->prepare('SELECT * FROM cooking_recipes WHERE id = '.$_GET['id'].';');
var_dump($statement->readOnly());
// bool(true)

And if there was an injection:

$_GET['id'] = 'NULL; DROP TABLE nuclear_warheads_locations;';
$statement = $db->prepare('SELECT * FROM cooking_recipes WHERE id = '.$_GET['id'].';');
var_dump($statement->readOnly());
// bool(false)

Of course you NEVER should insert any PHP variables straight in a SQL query. Instead you should use bindValue:

$statement = $db->prepare('SELECT * FROM cooking_recipes WHERE id = :id;');
$statement->bindValue(':id', $_GET['id']);

SQLite3::openBlob(string table, string column, int rowid [, string dbname])

Another undocumented feature of the PHP SQLite3 object, available since 2009, is openBlob. Basically it's a function that will return a stream pointer to a blob value in a table. Very very useful when you are dealing with files stored in a SQLite3 database.

Source code says:

proto resource SQLite3::openBlob(string table, string column, int rowid [, string dbname])
Open a blob as a stream which we can read / write to.

But despite that it's not possible to write to the blob, only reading is implemented. The blob are always opened as read-only by SQLite, so if you try to write to the stream, nothing will be saved to the database.

One example of use:

$db = new SQLite3('files.sqlite');
$db->exec('CREATE TABLE files (id INTEGER PRIMARY KEY, filename TEXT, content BLOB);');

$statement = $db->prepare('INSERT INTO files (filename, content) VALUES (?, ?);');
$statement->bindValue('filename', 'Archive.zip');
$statement->bindValue('content', file_get_contents('Archive.zip'));
$statement->execute();

$fp = $db->openBlob('files', 'content', $id);

while (!feof($fp))
{
    echo fgets($fp);
}

fclose($fp);

You can also seek in the stream. This is pretty useful for saving large files from the database too, this way you can use stream_copy_to_stream, it will be faster and more memory-efficient than dumping the file in memory before writing it to the disk.

Please note that openBlob() won't work on VIRTUAL FTS4 compressed tables (but no problem with non-compressed virtual tables).

SQLite3::enableExceptions([bool enableExceptions = false])

Available since 2009 (PHP version ??).

If set to true, then errors will be returned as exceptions instead of errors.

Ceci n'est pas une suite – Ginger Snaps Unleashed

mercredi 21 janvier 2015 à 00:37

Il ne faut pas se méprendre en se limitant à la jaquette DVD de l'édition française qui repompe Underworld et qui change le titre du film de "Ginger Snaps Unleashed" à "Ginger Snaps Resurrection", cette suite n'en est pas réellement une car en restant dans le thème et avec Brigitte du premier opus, le ton est complètement différent. Il ne faut donc pas s'attendre à voir la même chose que Ginger Snaps mais en plus fort, plus vite, plus mieux, c'est simplement un film différent.

On retrouve ici la talentueuse Emily Perkins et l'excellente Tatiana Maslany qui livrent une prestation extraordinaire dans des registres très différents. Le scénario prend un tournant inattendu avec le rapport entre lycanthropie et addiction aux stupéfiants et envoie le personnage principal dans un hôpital étrange et surréaliste, à moitié abandonné, rempli d'infirmiers corrompus, où elle rencontrera Ghost (Tatiana Maslany), une gamine totalement déjantée.

L'ambiance est campée et nous emmène dans un film d'épouvante relativement dérangeant et bien ficelé, de la musique à la réalisation en passant par les effets spéciaux « old school » (pas de CGI) jusqu'à une fin complètement tarée.

Ceci n'est pas une suite – Ginger Snaps Unleashed

mercredi 21 janvier 2015 à 00:37

Il ne faut pas se méprendre en se limitant à la jaquette DVD de l'édition française qui repompe Underworld et qui change le titre du film de "Ginger Snaps Unleashed" à "Ginger Snaps Resurrection", cette suite n'en est pas réellement une car en restant dans le thème et avec Brigitte du premier opus, le ton est complètement différent. Il ne faut donc pas s'attendre à voir la même chose que Ginger Snaps mais en plus fort, plus vite, plus mieux, c'est simplement un film différent.

On retrouve ici la talentueuse Emily Perkins et l'excellente Tatiana Maslany qui livrent une prestation extraordinaire dans des registres très différents. Le scénario prend un tournant inattendu avec le rapport entre lycanthropie et addiction aux stupéfiants et envoie le personnage principal dans un hôpital étrange et surréaliste, à moitié abandonné, rempli d'infirmiers corrompus, où elle rencontrera Ghost (Tatiana Maslany), une gamine totalement déjantée.

L'ambiance est campée et nous emmène dans un film d'épouvante relativement dérangeant et bien ficelé, de la musique à la réalisation en passant par les effets spéciaux « old school » (pas de CGI) jusqu'à une fin complètement tarée.