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:

“Hi, how are you? …”, then you add, “I have a cool personality test that I can do and it reveals a lot about your personality, do you want me to do the test?”

Usually, the girl will answer “Yes, sure”. You can actually sense an increase in her interest and a bit of excitement.

You then tell her: “I am going to ask you 4 fun questions”. You then proceed and ask the 4 questions.

  • You: What’s your favorite animal and why?
  • Her: Oh, I like cats because they are cute and free spirited
  • You: Okay, what’s your favorite color?
  • Her: It is hard for me to decide, but I like the color blue. It makes me feel relaxed and it reminds me of the ocean which I like too much
  • You: Imagine yourself, alone, at a nice sandy beach on nice sunny day, how do you feel?
  • Her: If I am really alone, I would just go butt naked and enjoy myself fully. I would get a tan, swim, run along the shore
  • You: Very good. Now’s the last question. I want you to imagine yourself in a white room all alone, no one around you, you are laying on a white bed. How would you feel?
  • Her: Oh, I don’t like to be alone. But to answer you, I would feel a bit lonely, but I also feel peaceful

There is no right or wrong way on how to do the analysis. In fact, you might be borrowing a lot from cold reading techniques as you give your analysis.

After asking the questions, you now tell her: “Okay, here is my analysis”:

  1. Your favorite animal was the cat. It is how your friends see you. They perceive you as a fun and independent person.
  2. Your favorite color was blue. The color tells about how you perceive yourself. You are a laid back person, chill and open minded. Like the ocean and the sky which are both blue, they are equally big and all encompassing. This also suggests that you are a friendly person
  3. Being on the beach alone and what you would do tells about your sexuality. You are a wild person when it comes to sexuality. You are willing to let go, experiment and show no inhibitions when you feel right about it
  4. Being in a white room alone is analogous to being on the death bed and how you view the end of your life. You might perceive your last moments as moments of peace, yet you feel it is a bit saddening that you are going to leave behind you all your friends whom you treasure and love.

You get the idea! Be creative and make sure you are sincere and try to deduce more about her personality from the chat and the replies to other questions.

You might also like:

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