Shuffling function addresses in C/C++ with MSVC

The Microsoft C/C++ compiler allows you to specify link order of functions or variables. Using the #pragma directive with either code_seg or data_seg and specifying the segment name and its sorting key, you can tell the linker how to place the object code in the final executable.

Let’s start with a simple example:

#pragma code_seg(push, ".text$EB009")
__declspec(noinline) void f1()
{
    printf("this is f1()\n");
}
#pragma code_seg(pop)


#pragma code_seg(push, ".text$EB005")
__declspec(noinline) void f2()
{
    printf("this is f2()\n");
}
#pragma code_seg(pop)


#pragma code_seg(push, ".text$EB001")
__declspec(noinline) void f3()
{
    printf("this is f3()\n");
}
#pragma code_seg(pop)

int main()
{
    f1();
    f2();
    f3();
    return 0;
}

When the code_seg pragma is used, we can specify where the subsequent code should lie (in which section in the PE file). When the section name contains the “$” sign, then the subsequent text is not part of the section name (the string prior to the “$”) and instead is used as a sorting key. Continue reading “Shuffling function addresses in C/C++ with MSVC”

Klara with Guitar

During my short visit to Brussels, Belgium this year, I met another street performer: her name is Klara and she had a lovely voice. Unlike other public performers though, she was not friendly so I could not interview her and share with you part of her story. We will have to contend with just a short video I captured:

You can visit her Facebook page here: https://www.facebook.com/klarawinterain/

You might also like:

When man got afraid

  • When man got afraid
  • When he got afraid from darkness, he invented electricity
  • When he got afraid from cold, he invented clothing
  • When he got afraid from thirst, he dug wells
  • When he got afraid from disease, he invented medicine
  • When he got afraid of fire, he invented the fire extinguisher
  • When he got afraid from loneliness, he invented the television
  • When he got very bored, he invented social media

You might also like:

Meet Roger, the man who lives in the Amsterdam Airport Schiphol


I was traveling from the US to Europe and I had a layover in Amsterdam. In the men’s room, I met an interesting character called Roger. Roger, in his mid forties, was neat and dressed like a backpack traveler. He started a conversation with me, talking about random stuff. At one point, out of the blue he mentions that he lives in the airport. I was not sure what he meant but he explained that he literally lives in the airport. I asked him if he showers, sleeps and gets his basic needs met in the airport and he said yes. In fact, he uses the handicap toilet to wash himself at nights then he goes to sleep in the airport pretending to be an early morning passenger. In the morning, he also uses to toilets to get himself ready and then leaves the airport for the day.

What an interesting encounter. I had no idea that some people, out of necessity do that. I have walked in the streets of popular European cities and I have met many homeless people. Panhandling and sleeping on the street is a second nature to them unfortunately. Roger at least, gets a warm place and washes himself instead of sleeping out in the freezing cold in the winter.

You might also like:

Learn from…

  • From the mountains, learn highness and glory
  • From rivers and fountains, learn generosity
  • From rocks, learn to be strong
  • From the absent and not manifest, learn silence and reverence
  • From ants, learn hard work
  • From pigeons, learn serenity
  • From the fox, learn intelligence
  • From the rooster, learn early rising
  • From the lion, learn courage

You might also like: