Patchou's Cabana

The personal blog of Patchou

Archive for the Tech Talk

Something new is coming

Hungry anybody?…

Coming soon :)

The Smart Card Detective – Thesis

This week, I’ve read some very interesting posts about Omar S. Choudary’s thesis on credit card’s PIN security (or lack of it). Although it’s based on previously known information, this thesis is probably the first public document to go so deep in every detail that matters. A highly interesting read for the holidays and for those who don’t want to read all of it, here’s a quick summary: it only takes 150$ of easy to find material to build a card capable of charging any “chip protected” credit card with any amount your account allows, without prior knowledge of the PIN.

“Then we have used the SCD to perform the No PIN attack at the local cafeteria and
even in some random shops in Cambridge. We have successfully bought books and DVDs
worth over $50 at one of the shops using the journalist’s card but typing PIN 0000. Even
more, we have performed the tests without warning and nobody has noticed the hidden
device or fake card (the card interface connected to the SCD). After the transaction we
have disclosed the attack to the shop manager who said that such attacks occur very often.
The manager mentioned that during busy periods like Christmas credit card frauds occur
at least once a week. Because shops cannot longer check the cards (as the current policy
is to let the customer handle the card insertion and removal) the criminals can use fake
cards and devices similar to the SCD to perform fraud.”

The entire thesis can be read here.

Resizing transparent bitmaps with the BlackBerry JDE

Here’s a post I made yesterday on the BlackBerry’s Java Development forum. See the original post here. I updated the code since then, the latest version can be found below.

I recently tried to use Bitmap.scaleInto() to resize transparent bitmaps in my application. Although this function is a nice addition to JDE 5, it tends to produce bad-looking results on transparent bitmaps such as PNG24 files. Forum posts I found on the web for this problem talk about using Bitmap.createAlpha() which does restore transparency but still produces artifacts in the final bitmap such as white edges and wicked pixel colors.

To solve this without the use of an external library, I created the following function. It still uses scaleInto() but in a different manner. I added some comments in the function and created a screenshot showing before and after results (don’t mind the pictures, they’re part of the project I’m currently working on). I’m posting the result here in hope it will help other people searching to achieve the same thing. The code was tested in JDE 5 and JDE 6 and the sample pictures were created using different combinations of filter types and aspect ratios.

package com.patchou.ui;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
 * @author    Patchou
 * @version   1.01
public class GPATools
     * Resizes a bitmap with an alpha channel (transparency) without the artifacts introduced
     *   by <code>scaleInto()</code>.
     * @param bmpSrc        Source Bitmap
     * @param nWidth        New Width
     * @param nHeight       New Height
     * @param nFilterType   Filter quality to use. Can be <code>Bitmap.FILTER_LANCZOS</code>,
     *                           <code>Bitmap.FILTER_BILINEAR</code> or
     *                           <code>Bitmap.FILTER_BOX</code>.
     * @param nAspectRatio  Specifies how the picture is resized. Can be
     *                           <code>Bitmap.SCALE_TO_FIT</code>,
     *                           <code>Bitmap.SCALE_TO_FILL</code> or
     *                           <code>Bitmap.SCALE_STRETCH</code>.
     * @return              The resized Bitmap in a new object.
    public static Bitmap ResizeTransparentBitmap(Bitmap bmpSrc, int nWidth, int nHeight, int nFilterType, int nAspectRatio)
        if(bmpsrc== null)
            return null;

        //Get the original dimensions of the bitmap
        int nOriginWidth = bmpSrc.getWidth();
        int nOriginHeight = bmpSrc.getHeight();
        if(nWidth == nOriginWidth && nHeight == nOriginHeight)
            return bmpSrc;

        //Prepare a drawing bitmap and graphic object
        Bitmap bmpOrigin = new Bitmap(nOriginWidth, nOriginHeight);
        Graphics graph = Graphics.create(bmpOrigin);

        //Create a line of transparent pixels for later use
        int[] aEmptyLine = new int[nWidth];
        for(int x = 0; x < nWidth; x++)
            aEmptyLine[x] = 0x00000000;
        //Create two scaled bitmaps
        Bitmap[] bmpScaled = new Bitmap[2];
        for(int i = 0; i < 2; i++)
            //Draw the bitmap on a white background first, then on a black background
            graph.setColor((i == 0) ? Color.WHITE : Color.BLACK);
            graph.fillRect(0, 0, nOriginWidth, nOriginHeight);
            graph.drawBitmap(0, 0, nOriginWidth, nOriginHeight, bmpSrc, 0, 0);

            //Create a new bitmap with the desired size
            bmpScaled[i] = new Bitmap(nWidth, nHeight);
            if(nAspectRatio == Bitmap.SCALE_TO_FIT)
                //Set the alpha channel of all pixels to 0 to ensure transparency is
                //applied around the picture, if needed by the transformation
                for(int y = 0; y < nHeight; y++)
                    bmpScaled[i].setARGB(aEmptyLine, 0, nWidth, 0, y, nWidth, 1);

            //Scale the bitmap
            bmpOrigin.scaleInto(bmpScaled[i], nFilterType, nAspectRatio);

        //Prepare objects for final iteration
        Bitmap bmpFinal = bmpScaled[0];
        int[][] aPixelLine = new int[2][nWidth];

        //Iterate every line of the two scaled bitmaps
        for(int y = 0; y < nHeight; y++)
            bmpScaled[0].getARGB(aPixelLine[0], 0, nWidth, 0, y, nWidth, 1);
            bmpScaled[1].getARGB(aPixelLine[1], 0, nWidth, 0, y, nWidth, 1);

            //Check every pixel one by one
            for(int x = 0; x < nWidth; x++)
                //If the pixel was untouched (alpha channel still at 0), keep it transparent
                if(((aPixelLine[0][x] >> 24) & 0xff) == 0)
                    aPixelLine[0][x] = 0x00000000;
                    //Compute the alpha value based on the difference of intensity
                    //in the red channel
                    int nAlpha = ((aPixelLine[1][x] >> 16) & 0xff) -
                                    ((aPixelLine[0][x] >> 16) & 0xff) + 255;
                    if(nAlpha == 0)
                        aPixelLine[0][x] = 0x00000000; //Completely transparent
                    else if(nAlpha >= 255)
                        aPixelLine[0][x] |= 0xff000000; //Completely opaque
                        //Compute the value of the each channel one by one
                        int nRed = ((aPixelLine[0][x] >> 16 ) & 0xff);
                        int nGreen = ((aPixelLine[0][x] >> 8 ) & 0xff);
                        int nBlue = (aPixelLine[0][x] & 0xff);

                        nRed = (int)(255 + (255.0 * ((double)(nRed-255)/(double)nAlpha)));
                        nGreen = (int)(255 + (255.0 * ((double)(nGreen-255)/(double)nAlpha)));
                        nBlue = (int)(255 + (255.0 * ((double)(nBlue-255)/(double)nAlpha)));

                        if(nRed < 0) nRed = 0;
                        if(nGreen < 0) nGreen = 0;
                        if(nBlue < 0) nBlue = 0;
                        aPixelLine[0][x] = nBlue | (nGreen<<8) | (nRed<<16) | (nAlpha<<24);

            //Change the pixels of this line to their final value
            bmpFinal.setARGB(aPixelLine[0], 0, nWidth, 0, y, nWidth, 1);
        return bmpFinal;

Here’s an example of how to call the function:

Bitmap bmp = Bitmap.getBitmapResource("picture.png");
Bitmap bmpResized = GPATools.ResizeTransparentBitmap(bmp, 30, 60,

Here’s the result:

Welcome to the world of Beta

There are some things in this world that you can always count on to be true: summer comes after spring, rain after the sun, and people request intermediate versions of Messenger Plus! as soon as a beta version of a new Messenger is available. Invariably, negative answers trigger “but whhhhhhhy?!” comments, everybody gets used to the idea, Messenger Plus! gets updated along with the final release of Messenger and life goes on.

Today, something happened that will help shed some light on my no-beta-support policy. As some of you already know, Microsoft recently released a beta version of Windows Live Messenger “Wave 4″. This updated version of Messenger includes new social features, options like tabbed chats, noticebly larger advertisements, etc… Microsoft also modified their setup program, that same setup I downloaded this morning and ran on my computer.

After a quick installation, I was invited to restart my computer, which I did, promptly. This is where things started to get interesting to say the least. After the reboot, I was greeted by brand new error messages I had never seen before in Windows, one in particular saying that my profile, now located in “system32\config\systemprofile”, was not available. Basically, my whole user profile was gone, my desktop empty, the taskbar displayed default blank icons for my old shortcuts and none of my programs remembered who I was. Messenger’s new signin screen was nagging me, coming back after I closed it, and many of the things I tried to do in Windows while trying to figure out what happened displayed error messages. In user terms, my computer was completely “broken”.

After searching a bit about this issue on the web, the only thing I was able to find was posts confirming that this kind of error occurs when a user profile has been badly corrupted in the system and that, in such cases, there’s generally nothing to do but create a brand new profile. For all the tech geeks reading this, yes, I checked the user profile keys in the registry, I tried to clear up the default system profile, etc… I also don’t have anything out of the ordinary running on my station, no shell replacement software, no theming program, no nothing: just Windows 7, Office 2010, Visual Studio and a couple of work tools. I don’t even play games on that system.

Out of despair, I tried System Restore and I have to say it performed admirably. It finally reverted all the changes that the new Windows Live setup had done to my system and restored my user profile to a functionning state. I’ll definitively have to remember to rely more on this feature in the future. In any case, as I refused to admit defeat, I prepped my computer for another try. I erased all the files and settings of my existing version of Messenger (the current public release), did a clean reboot, re-downloaded the setup of the beta version and tried again. Guess what: after the restart, the same error occured, my profile was corrupted again and my computer was back to stone age.

Now, I hope you understand why supporting a beta may not be a good idea. As for Microsoft’s work on this new Messenger, I can say I’m not impressed, at all. I’ve never seen a program cause so many issues on my system and I certainely don’t expect that from an instant-messaging application. Beta or not, I assume that when Microsoft releases something to the public, it’s not going to cause mayhem. I don’t know what that new Messenger is trying to do on our systems but in my view, it’s wrong and uncalled for. Here’s a recommendation for everybody who’s reading this post is: stay away from Messenger beta versions, I certainely will.

Apple’s Monopolistic Practices

Up to recently, I was neutral as far as Apple was concerned. I’ve always been a Windows user, some Apple fanboys always irritated me (Windows fanboys are the same though), but I had nothing against the company itself. Since the success with the iPhone, things have changed.

In the last 2 days alone, I read the following two articles about Apple and how they treat their developers and users. To sum it up: you can’t choose the technology you’ll work with, you can’t choose the features you’ll add and now, you can’t even choose the tools you’ll use for your development. Next time you hear about Microsoft or another software company being sued in Europe, think about them. As for me, I’ll continue to create software with a company who respects and takes care of its developers.

  • Archive

  • Categories

  • Blogroll