Using C/C++ TLS callbacks in Visual Studio with your 32 or 64bits programs

In the following article, I share with you how to use TLS callbacks in your C/C++ program compiled with Visual Studio.

Background

TLS (thread local storage) callbacks are a mechanism provided by the Windows loader to give your program a chance to do initialization/deinitialization tasks when the process starts, terminates, a thread is created or terminated.

A TLS callback has the following prototype:

typedef VOID (NTAPI *PIMAGE_TLS_CALLBACK) (
    PVOID DllHandle,
    DWORD Reason,
    PVOID Reserved);

The Reason argument can be any of the following constants:

  • DLL_PROCESS_ATTACH   = 1
  • DLL_PROCESS_DETACH  = 0
  • DLL_THREAD_ATTACH  = 2
  • DLL_THREAD_DETACH  = 3

The TLS callbacks are encoded inside the compiled program’s TLS data directory(IMAGE_DIRECTORY_ENTRY_TLS). Please refer to the PE file structure. Continue reading

The Iceberg Illusion of Success

I found this picture on the internet and I really loved it and as usual, I would like to use it as a launching pad for today’s article.

I still remember my self when I was young, between the ages of 14 to 23, I used to envy people of my age or slightly older who seemed to have achieved the success that I want for myself.

If I saw another guy with a fancy car, I would immediately justify that by telling myself that he must have rich parents.

If I see a smart guy from a good university, I would say to myself that his parents could afford to educate him in such a prestigious university and then I would say to myself: only if I had the means, then I would have been more successful.

If I saw a guy with a hot looking girl, I would say to myself: “He must have money because that’s why the girl is hanging out with him. I don’t have a car or the money to take her out and give her a nice time”.

Back then, I could not afford to buy all the material possessions that I wanted. I remember when my peers used to have a Game Boy or a Sega Mega drive. They used to come to school and play with those game consoles and it made me feel sad and unhappy because I don’t have one myself. Often times, I would think about my parents with a bit of childish resentment. I had the sense of entitlement because I was immature.

Back then, I could not afford to take vacations or travel wherever I wanted. I was living in a continuous state of perceived lack, holding my happiness hostage to external situations. For a big part of my childhood and adulthood, It felt that my self worth really depends on how others perceive me, how much I have, what car I have, what cloth I wear, what kind of a girl friend I had. Continue reading

DC Glass Seattle

I always run into incredible talent at The Pike Market in Seattle, WA.

Today I ran into David Contreras’ handmade glass products.

Make sure you visit his stand in the Pike Market and check out his Instagram page:

You might also like:

 

Online Chatting and The 4 Magic Questions

Back in the days, when I was learning pickup techniques from pickup artists, I ran into “The Magic Questions pattern” by Jack Ellis (the author of “Forbidden Patterns”). The purpose of these questions is to have a nice and fun topic to talk to women whom you just approached in a public setting. Women like it when men talk about them, compliment them or do anything thing that make them feel special.

The Magic Questions

Here are the magic questions, ask them in any order:

  1. Visualize yourself in a white room. You’re in a bed and everything is white. How do you feel?
  2. What is your favorite animal? What qualities do you see it as having?
  3. What is your favorite color? How does it make you feel when you think about it?
  4. Imagine yourself on a beach. Nobody is around and the ocean is right in front of you. What do you do?

Take mental note of the answers because you will have to interpret the answers back to them.

What the answers mean

After you finish asking the questions and taking notes, it is time to interpret the answers back to the interviewee. The meaning of each question is as follows:

  1. This is how they view death and dying
  2. This is how their friends view them
  3. This is how they view themselves
  4. This is how they view sex

Putting it into practice

Let me give you an example. You meet a random girl that you want to approach and talk to. You can use the four magic questions as a nice conversation opener: Continue reading

Five Ancient Lessons of the pencil

When Sri Gurudeva Srila Prabhupada ki jaya was walking today he felt his mind reach out over the blue sea to an island shimmering in the distance. When his mind returned it brought a story with it – a story of spiritual instruction. Strange are the ways of inspiration.

Sri Gurudeva Srila Prabhupada writes:

Continue reading

The “One man band” man!

Meet the “One man band” man! I ran into him in the Boston Common park:

You might also like:

7 DLL injection techniques in Microsoft Windows

In this article, I am going to list half a dozen DLL injection techniques that can be used by a user mode process running on MS Windows. There could be more techniques but I am sharing with you the techniques that I had first hand experience with.

1. AppInit_DLLs

People used to rely on the AppInit_DLLs registry key. The OS loader queries this value and loads the DLLs specified there when a process is created. I have not used this technique in a long while (last time I used it was on Windows XP) and I heard it is now restricted or discontinued because it was widely used by malware.

2. SetWindowsHookEx API

The SetWindowsHookEx API installs an application-defined hook procedure into a given hook chain. There are various supported hook chains (CBT, Journal, Window messages, keyboard, mouse, etc).

When using the SetWindowsHookEx API, you are instructing the operating system to inject your custom hook DLL into other process where it is relevant. The Windows hooks work when the other processes import / use functionality from USER32.dll.

Continue reading