Le fourre-tout à Geo

Aller au contenu | Aller au menu | Aller à la recherche

mardi, décembre 8 2009

Utterly useless uses of VLC

Last time, I told you how to take a video from some website and see it in VLC media player. Pretty cool, huh?

Yesterday, I was trying to think of funny and useless thing to do with VLC, and it occured to me that Lua gives a lot of opportunities to do that.

So, it is my pleasure to present you with the "Flickr diaporama Lua script for VLC"!

--[[

 Copyright © 2009 the VideoLAN team

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]

-- Probe function.
function probe()
    if vlc.access ~= "http" then
        return false
    end
    vlc.msg.info( vlc.path )
	koreus_site = string.match( vlc.path, "www.flickr.com" )
    if not koreus_site then
        return false
    end
    return (  string.match( vlc.path, "sets" )  )
end

-- Parse function.
function parse()
    _,_,artist = string.find( vlc.path, "photos/(.-)/sets/" )
    vlc.msg.info( artist )
    while true do
        line = vlc.readline()
        if not line then break end
        if string.match( line,"<div id=\"setThumbs\"") then
            start = 0
            pl = {}
            line = vlc.readline()
            while true do
                _,start,url = string.find(line, "<img src=\"(.-)_s.jpg\"", start)
                if start == nil then
                    return pl
                end
                _,_,description = string.find(line, "alt=\"(.-)\"", start)
                opt = { ":fake-duration=5000"; ":fullscreen" }
                pth = "fake://" .. url .. ".jpg"
                table.insert(pl, {path = pth; name = start; title=description; 
                description = description; artist = artist;options=opt})
            end
        end
    end
end

So, how does it work? Give some Flickr album url to VLC, like this one with the funny cats. VLC will parse the page, find all the thumbnails urls (the ones finishing with _s.jpg), deduce the urls of the the full pictures (replacing "_s.jpg" by ".jpg"), and show them. As simple as that.

The fake access module is used to tell VLC that "hey, this is not one picture, it's a video with a lot of frames like this picture". I added the "fake-duration" option, to choose how much time (in ms) the picture will be displayed, and the "fullscreen" option. You can of course tweak it, and, let's say, use the directx wallpaper mode to have a flickr diaporama as your wallpaper!

To use this script, you can either place it in C:\Program Files\VideoLAN\VLC\lua\playlist, or in C:\Users\YOURUSERNAME\AppData\Roaming\vlc\lua\playlist.

I strongly encourage you to try and write your own Lua scripts, it's really easy! Come to the Videolan forum to share your scripts or ask for help.

See also

mercredi, novembre 25 2009

VLC: now with DxVA support

So, this is it. My summer of code has been merged into the main tree, thanks to Laurent's hard work!

You may test and enjoy the GPU acceleration for your H.264 videos using future nightly builds!

lundi, novembre 23 2009

So you want to contribute...

...But you don't want to go through the (sometimes painful) process of building the whole VLC. Well, you can build your own plugin separately. Here is how to do it (this tutorial is Windows centric because 1: I'm too lazy to launch my VM right now; 2:it's easy to do on Ubuntu for the linux trolls):

Ingredients

  • The plugin headers. You can find them in C:\Program Files\VideoLAN\VLC\sdk\include\vlc\plugins on Windows.
  • The libraries. Copy libvlc.dll and libvlccore.dll (you will find them in C:\Program Files\VideoLAN\VLC)
  • A building environment (on Windows, use Mingw+MSYS)
  • Some coffee

Recipe

At the time of writing, the wiki page wasn't really explicit, so I'll detail all the steps, for an example audio filter that switch the left and right audio streams (adapted from the trivial channel mixer plugin).

Let's begin by taking a look at what code you can find in a VLC plugin, like the trivial channel mixer plugin.

Preamble

First, the copyright and license:

/*****************************************************************************
 * trivial.c : trivial channel mixer plug-in (drops unwanted channels)
 *****************************************************************************
 * Copyright (C) 2009 the VideoLAN team
 * $Id: 3ecc0dd8363a50c40f7f123a9e2724a943c0c83c $
 *
 * Authors: Name <email address>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

That's not useful to run the plugin, but you'll have to add it when you send a patch to VideoLAN.

Next, the headers:

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_aout.h>
#include <vlc_filter.h>

the config.h file is generated from the configure step when you build the whole VLC. Each module must include at least vlc_common.h and vlc_plugin.h. The other headers included depend on the type of plugin you want to build (find it in the code of plugins from the category you want).

Note: you will probably need something more like the following for your audio plugin.

#define _(str)  (str)
#define N_(str) (str)

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_messages.h>
#include <vlc_aout.h>
#include <vlc_filter.h>
#include <vlc_fourcc.h>
#include <vlc_block.h>

Don't hesitate to grep the include directory if you have some missing functions or unknown structures.

Module descriptor
static int  Create    ( vlc_object_t * );

static block_t *DoWork( filter_t *, block_t * );

vlc_module_begin ()
    set_description( N_("Audio channel inverser") )
    set_capability( "channel inverser", 1 )
    set_category( CAT_AUDIO )
    set_subcategory( SUBCAT_AUDIO_MISC )
    set_callbacks( Create, NULL )
    add_shortcut( "channel_inverser" )
vlc_module_end ()

First, you see the prototypes of functions used in this plugin. Create is used, well, to create the plugin, and DoWork will handle all the audio data.

Then, the part between vlc_module_begin and vlc_module_end is a set of macros used to declare the plugin structure. This part is used to define which type of module it will be. These macros create a function exported by the plugin and called when VLC looks for a suitable plugin.

If the module can be used, the core of VLC stores the callback (here, the Create function) and calls it later to initialize the plugin.

Create function
static int Create( vlc_object_t *p_this )
{
    filter_t * p_filter = (filter_t *)p_this;

    if ( (p_filter->fmt_in.audio.i_physical_channels
           == p_filter->fmt_out.audio.i_physical_channels
           && p_filter->fmt_in.audio.i_original_channels
               == p_filter->fmt_out.audio.i_original_channels)
          || p_filter->fmt_in.audio.i_format != p_filter->fmt_out.audio.i_format
          || p_filter->fmt_in.audio.i_rate != p_filter->fmt_out.audio.i_rate
          || (p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32
               && p_filter->fmt_in.audio.i_format != VLC_CODEC_FI32) )
    {
        return VLC_EGENERIC;
    }

    p_filter->pf_audio_filter = DoWork;
    return VLC_SUCCESS;
}

The initialization function is used to set some configuration options, initialize memory structures, etc. Look at other modules to see how you can store variables, and how to create preferences variables.

Here, we verify that the number of channels, the format and the bitrate in the input and output are the same, and that the audio isn't stored in float numbers. If it's ok, we give to libvlc a pointer to the DoWork function, which will be called when audio data is available.

DoWork function
static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
{
    int i_input_nb = aout_FormatNbChannels( &p_filter->fmt_in.audio );
    int i_output_nb = aout_FormatNbChannels( &p_filter->fmt_out.audio );

    block_t *p_out_buf;
    if( i_input_nb >= i_output_nb )
    {
        p_out_buf = p_in_buf; /* mix in place */
        p_out_buf->i_buffer = p_in_buf->i_buffer / i_input_nb * i_output_nb;
    }
    else
    {
        p_out_buf = filter_NewAudioBuffer( p_filter,
                              p_in_buf->i_buffer / i_input_nb * i_output_nb );
        if( !p_out_buf )
            goto out;
        p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
    }

    int32_t * p_dest = (int32_t *)p_out_buf->p_buffer;
    const int32_t * p_src = (int32_t *)p_in_buf->p_buffer;


    /* Reverse-stereo mode */
    int i;
    for ( i = p_in_buf->i_nb_samples; i--; )
    {
        *p_dest = p_src[1];
        p_dest++;
        *p_dest = p_src[0];
        p_dest++;
        p_src += 2;
    }

out:
    if( p_in_buf != p_out_buf )
        block_Release( p_in_buf );
    return p_out_buf;
}

The DoWork function manages the buffers and copy them from the input to the output.

Now in the oven

(No preheat please)

Here is the content of my Makefile:

all:
	gcc -I/home/Geal/module/include -L/home/Geal/module/ -lvlccore -shared -std=gnu99 \
	-DWIN32 -D__PLUGIN__ -DMODULE_STRING=\"channel_inverser\" module.c -o libchannel_inverser_plugin.dll
/// 

Adapt it to the name of your plugin, and to the path you use, or copy the one from the wiki. My Makefile only contains what is strictly necessary to build your plugin. Now:

Geal@chezmoi ~/module $ make ///

Eat it while it's still hot

Now, you just need to copy your dll in the plugins directory of VLC media player, and try your plugin! I don't guarantee that it will work (more like I know that it doesn't work and I'm too lazy to fix it because I won't commit it), I just gave you the structure and the Makefile you need to be up and running. Note that you can use the following command line options to help in your development:

  • -vvv: displays a LOT of debug messages
  • --verbose-objects: helps you filter the messages (example: ./vlc -vvv --verbose-objects=-all,+direct3d to display only the messages related to the direct3d module)

Don't forget to send a patch to VideoLAN (subscribe to the vlc-devel mailing-list and attach it to a message). To integrate your module, please read the HACKING file at the root of the VLC source tree.

Now, show me your code!

dimanche, novembre 8 2009

HowTo: audits et logs

Les logs, c'est une liste de messages datés vous indiquant ce qui se passe sur votre système (pour ceux qui ne le savaient pas).

On va me dire: "les logs c'est pas de la sécu, ça protège rien". Et je vais répondre: "est-ce que vous savez si quelqu'un a essayé de se logguer sur votre machine aujourd'hui? Est-ce que cette personne a essayé de se connecter devant la machine, ou depuis le réseau?"

Gérer ses logs, c'est savoir ce qui se passe sur sa machine et être alerté en cas de problèmes. Et puis ça alimente ma paranoïa, donc je suis content :)

J'écris ce billet maintenant car dans les billets suivants, j'ajouterai des éléments aux logs. Si on sait comment ça marche dès le début, la pilule passera mieux.

Allez, on va voir de quoi ça parle: tout d'abord, on va se rajouter les droits pour regarder les logs, parce que depuis l'article précédent, on n'a plus les droits d'admin :). Lancer la console "Local users and groups" (lusrmgr.msc), allez dans Groupes, puis Event log readers, clic droit et Add to group. Rajoutez votre utilisateur. Maintenant, vous pouvez lancer la console de gestion des logs.

L'event viewer

"Démarrer->exécuter" puis eventvwr.msc. Vous pouvez voir plusieurs types de logs.

  • Custom views: les autres logs passés au travers de filtres pour indiquer les infos qui vous intéressent
  • Windows logs: les logs qui nous intéresseront ici. Tous les messages que Windows vous dépose gentiment, en espérant que vous les lirez...
  • Applications and services logs: le reste des applications qui utilisent les logs de Windows.
  • Subscriptions: pour récupérer des logs d'une autre machine.

Parmi les logs de la section Windows, on trouve:

  • Applications: reçoit les événements concernant les applications, comme les crashes (Windows Error Reporting)
  • Security: on ne peut le voir qu'avec les droits d'admin (va falloir Run as Administrator la console de logs, parce que c'est celui qu'on va regarder).
  • Setup: reçoit les événements de mise à jour, installation de .msi, etc.
  • System récupère les événements relatifs aux services, au kernel, etc.
  • Forwarded events est lié à l'envoi de logs sur d'autres machines

events categories

Prenez le temps de fouiner un peu, regarder quelles informations votre machine vous renvoie. Comme vous pouvez le voir, il se passe beaucoup de choses!

Rajoutons des événements

Supposons que je veuille vérifier si quelqu'un a tenté de se connecter à ma machine en mon absence. Je vais vérifier si quelqu'un a tapé un mauvais mot de passe, et je vais vérifier quel utilisateur a réussi à se logguer au cours de la journée.

Lancez secpol.msc. Allez dans Local Policies puis Audit Policy. Choisissez par exemple Audit account logon events et indiquez Failure et Success dans les propriétés.

secpol.msc

Essayez maintenant de vous connecter à un autre compte, en ratant délibérément le mot de passe. Vous verrez apparaître dans les logs Security des lignes contenant le mot clef "Audit failure" pour la tâche "Credential validation". Cliquez sur l'une d'elles: vous verrez que le log indique la date, l'heure, la machine concernée et le compte qui a essayé de se logguer.

login failed

Marrant, non? Et on va peut rajouter des logs pour pas mal de choses. Suppsons que j'aie des documents compromettants (par exemple, la photo d'un prez de BDE complètement bourré). J'aimerais savoir si quelqu'un a essayé de la copier. Je vais donc ajouter un audit sur les accès à ce fichier, et donc afficher une ligne dans les logs si quelqu'un essaie d'ouvrir le fichier.

Il suffit d'aller dans le dossier contenant ce fichier, clic droit puis Propriétés -> Advanced -> Auditing et utiliser ses droits d'admin pour voir les propriétés d'audit.

auditing

Maintenant, on va ajouter des propriétés d'audit pour ce fichier. Je choisis de les mettre sur le groupe Users. Je veux auditer les accès en lecture, et les suppressions de fichier (au cas où quelqu'un voudrait faire disparaître les preuves de ses frasques). Vous pouvez voir de nombreuses options, le système d'audit est très flexible (peut-être trop pour être utilisé par une personne normale).

auditing entries

Maintenant, on va essayer d'ouvrir le fichier, et aller voir le contenu du log. L'event viewer nous indique que "an attempt was made to access an object", par Geal (moi), sur le fichier en question.

log file access

Et voilà! Maintenant, vous allez pouvoir en ajouter beaucoup plus! Il est possible d'auditer des clefs registre, l'usage de privilèges admin, le lancement de programmes, etc. Je proposerai quelques-uns de ces ajouts dans les prochains tutoriels.

Notez bien que la génération des logs peut prendre pas mal de ressources et d'espace disque, donc évitez par exemple de mettre un audit sur toutes les lectures de fichiers sur c:\ et ses sous dossiers (j'ose même pas imaginer ce que ça donne pendant une compilation de vlc).

lundi, novembre 2 2009

HOWTO: la sécurité au quotidien

Je vois partout les mêmes recommandations: utilisez un antivirus, activez votre firewall, changez vos mots de passe régulièrement, ne cliquez pas sur n'importe quel lien, etc. J'en ai MARRE! On vous sort ces solutions à deux sous, qui ne font qu'adresser une partie du problème, qui est:

comment éviter à un boulet de perdre ses données, de se faire voler son n° de carte bleue ou son compte Facebook ou de servir de noeud dans un botnet? Et comment rendre ça user friendly (aka "éviter d'écrire le mot de passe sur un PostIt").

Je me lance dans une entreprise ambitieuse, qui consiste à trouver une série de solutions qui vont bien ensemble pour protéger une machine perso. Je ne parlerai pas de machines sur un réseau d'entreprise, mais j'aborderai éventuellement les problèmes du réseau @home et du WiFi, et de mobilité. Ah, et il s'agira uniquement de Windows: les utilisateurs Linux sont encore pas mal protégés, et les utilisateurs Mac n'écoutent pas quand on leur dit qu'ils ne sont pas à l'abri. Mes tests seront faits sous Windows 7 et Vista (XP si je combats la flemme de m'installer une autre machine) avec toutes les mises à jour effectuées (bien évidemment, si vous ne mettez pas à jour votre OS pour cause de paranoïa et/ou de piratage, je ne peux rien faire pour vous).

J'écrirai une série de billets, sous la forme de tutoriels et/ou tests, sur les sujets suivants:

  • Utilisateurs et groupes d'utilisateurs
  • Logs
  • Mots de passe
  • Droits (UAC, LUA, Integrity Levels, SRP)
  • Firewall
  • Navigateurs
  • virus, chevaux de troie, etc.
  • Applications dangereuses et leurs alternatives
  • Protection des applications
  • Applications web
  • Sauvegarde de données
  • Mises à jour

J'essaierai (dans la mesure du possible) de rendre ces solutions faciles à mettre en place, (ça va être dur) pas trop restrictives à l'utilisation et bien intégrées dans L'OS (aka "pas de hook foireux qui traînent").

- page 1 de 12