Dynamic linker tricks: Using LD_PRELOAD to cheat, inject features and investigate programs

This post assumes some basic C skills.

Linux puts you in full control. This is not always seen from everyone’s perspective, but a power user loves to be in control. I’m going to show you a basic trick that lets you heavily influence the behavior of most applications, which is not only fun, but also, at times, useful.

A motivational example

Let us begin with a simple example. Fun first, science later.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(){
  srand(time(NULL));
  int i = 10;
  while(i--) printf("%d\n",rand()%100);
  return 0;
}

Simple enough, I believe. I compiled it with no special flags, just

gcc random_num.c -o random_num

I hope the resulting output is obvious – ten randomly selected numbers 0-99, hopefully different each time you run this program.

Now let’s pretend we don’t really have the source of this executable. Either delete the source file, or move it somewhere – we won’t need it. We will significantly modify this programs behavior, yet without touching it’s source code nor recompiling it.

For this, lets create another simple C file:

int rand(){
    return 42; //the most random number in the universe
}

We’ll compile it into a shared library.

gcc -shared -fPIC unrandom.c -o unrandom.so

So what we have now is an application that outputs some random data, and a custom library, which implements the rand() function as a constant value of 42.  Now… just run random_num this way, and watch the result:

LD_PRELOAD=$PWD/unrandom.so ./random_nums

If you are lazy and did not do it yourself (and somehow fail to guess what might have happened), I’ll let you know – the output consists of ten 42′s.

Read the rest of this entry »

e4rat – decreasing bootup time on HDD drives

This time I will describe how to set up e4rat in order to speed your Ubuntu’s boot time. Let’s begin with some motivation: my netbook used to boot-up in ~40 seconds. Using e4rat, it takes ~10-15 seconds. Impressive, isn’t it? Let’s see how does this trick work, and I’ll teach you how to enable it on your machine.

Read the rest of this entry »

There is something wrong with the new UDS system.

When I read the news about Canonical’s decision to change the way Ubuntu Developer Summit (original announcement here) I was totally astonished. I expected this change will cause a lot of buzz within the community, especially given the fact that all recent Canonical decisions are considered very controversial. This surprises me heavily, as I can spot a big number of problems that this decision may cause, as well as problems with the way this decision itself was handled. Jono Bacon’s article explaining the decision did not satisfy me either. It explains the general reasoning behind this idea, but it does not clarify everything.

Read the rest of this entry »

vModSynth 1.0 released

Didn’t I mention for the last 2 months I have been working on a synthesizer application?

I am pleased to announce that vModSynth 1.0 is now publicly released and available to download.

What is vModSynth? It’s a modular software synthesizer for Linux. It is not intended to be as convenient as possible, but to resemble the look & feel of a real, analog, modular software synthesizer. See for yourself:

vmod1

Read the rest of this entry »

Dynamically changing Ubuntu Phone wallpaper for your desktop

We have all already seen it. The super-elegant Welcome Screen seen on all demonstrations of Ubuntu Phone OS is appreciated by many for it’s brilliant design and simplicity.

Because of that, some have tried to recreate it to use as a desktop wallpaper. Among several versions that are available, I liked Michał Prędotka’s version most. This version was modified to many different colors by Michael Hall – he has even created a video tutorial on how to make your own color scheme for this wallpaper.

I love the idea of different simple wallpapers that share the design, but vary in colors. But I’m lazy, and I don’t want to change my wallpaper everyday to enjoy another color scheme. Ideally the wallpaper would change automatically. But if the design is identical and only colors change, then it may be neat to change the colors smoothly.

c5c1c3c4c2

(these images are low-res, and are not meant to be downloaded)

Read the rest of this entry »

FitBit trophies as a milestone for Ubuntu Accomplishments

Accomps logoYou may have heard about FitBit badges support in Ubuntu Accomplishments system. Matt Fisher and Chris Wayne have written a new collection of accomplishments which pulls in your FitBit badges to other trophies. You can learn more about what awesome work they did by reading their articles [Matt] [Chris].

To those of you thinking “Hey, that app is Ubuntu accomplishments. How does FitBit relate to Ubuntu?”: that’s what a separate collection means. All trophies are grouped in sets – each set may relate to a different community, may be developed by completely different people – and such sets are called collections. You can think about them as of plugins or add-ons. Collections are installed separatelly, and are optional. That means that you are free to install FitBit accomplishments alongside Ubuntu trophies, and that you can also use just FitBit badges and remove default collections that award you for being active in Ubuntu community.

Now why do I consider FitBit trophies a milestone for the project?

Read the rest of this entry »

BarCamp Wrocław


This Saturday I have attended BarCamp Wrocław, an unconference organised at my city. It happened to have been held at my university ;) The event was awesome, quite a few people turned up, I’ve met the founders of Unexus (who organised this event, kudos to them!), as well as Johan Janssens, co-founder of Joomla, who gave an excelent talk about the concept of FOSS. To my surprise, it turned out that many people in local community are still very confused about what actually FOSS is, and why it’s cool. There were also many interesting talks about few certain software projects, we had a nice discussion on technology-related topics.

I’m definitelly looking for another chance to meet great developers from my city and participate in discussions with international experts. That was a great fun!

Follow

Get every new post delivered to your Inbox.