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 “Using C/C++ TLS callbacks in Visual Studio with your 32 or 64bits programs”

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 “The Iceberg Illusion of Success”

Online Chatting and The 4 Magic Questions

Back in the days, when I was learning PUA 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 “Online Chatting and The 4 Magic Questions”

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 “Five Ancient Lessons of the pencil”

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 “7 DLL injection techniques in Microsoft Windows”

The corporate cow or the different kind of companies

Source: NewstalkZB

 

Traditional corporation

  • You have two cows
  • You sell one and buy a bull
  • Your herd multiplies, and the economy grows
  • You sell them and retire on the income

A Swiss corporation

  • You have 5000
  • None of them belong to you
  • You charge the owners for storing them

A French corporation

  • You have two cows
  • You go on strike, organize a riot, and block the roads because you want three cows

A Chinese corporation

  • You have two cows
  • You have 300 people milking them
  • You claim that you have full employment and high bovine productivity
  • You arrest the newsman who reported the real situation

A British corporation

  • You have two cows
  • Both are mad

An Indian corporation

  • You have two cows
  • You worship them

An Iraqi corporation

  • Everyone thinks you have lots of cows
  • You tell them that you have none
  • Nobody believes you, so they bomb the crap out of you and invade your country
  • You still have no cows but at least you are now a Democracy

An Australian corporation

  • You have two cows
  • Business seems pretty good
  • You close the office and go for a few beers to celebrate

An Irish corporation

  • You have two cows
  • One of them is a horse

An American corporation

  • You have two cows
  • You sell one, and force the other to produce the milk of four cows
  • Later, you hire a consultant to analyze why the cow has died

An Italian corporation

  • You have two cows but you do not know where they are
  • You decide to have lunch

A greek corporation

  • You have two cows borrowed from French and German banks
  • You eat both of them
  • The banks call to collect their milk, but you cannot deliver so you call the IMF
  • The IMF loans you two cows
  • You eat both of them
  • The banks and the IMF call to collect their cows/milk
  • You are out getting a haircut

Communism

  • You have two cows
  • The State takes both and gives you some milk

Socialism

  • You have two cows
  • You give one to your neighbor

Fascism

  • You have two cows
  • The State takes both and sells you some milk

Bureaucratism

  • You have two cows
  • The State takes both, shoots one, milks the other then throws the milk away

Venture capitalism

  • You have two cows
  • You sell three of them to your publicly listed company, using letters of credit opened by your brother-in-law at the bank, then execute a debt/equity swap with an associated general offer so that you get all for cows back, with a tax exemption for five cows
  • The milk rights of the six cows are transferred via an intermediary to a Cayman Island Company secretly owned by the majority shareholder who sells the rights to all seven cows back to your listed company
  • The annual report says the company owns eight cows, with an option on one more

You might also like:

Why wear a short shorts if you want to keep pulling it down?

Have you ever noticed young girls or even adult women wearing short shorts but yet they feel so self-conscious and shy about it that they keep pulling it down to cover their behinds? Isn’t that ironic?

Why wear it in the first place if it makes you feel uncomfortable or if you don’t like the attention you are getting?

Is it not attention towards your assets the biggest reason as to why you chose to buy and wear that outfit?

“Oh no you! That’s not the reason” you say, “The reason is that it is hot outside and that is very comfy”. Is it really so? I wonder why men don’t feel as hot as you are and are contempt with wearing regular shorts 😉

You might also like:

 

One day, the poor will have nothing to eat but the rich

I was browsing the internet and I found this nice photo and it got me thinking. I would like to use it as a launching pad to share some of my thoughts on the topic of the rich and the poor.

I come from Beirut, Lebanon, a third world country by all means. We have corrupt politicians, political seats handed down from father to son, the worst power and water infrastructure, etc. I wrote a short satirical pamphlet about my home country and published it on Amazon, check it out. The reason I mention my origin is that having lived in the 3rd world country and now I live in the US, I can compare and contrast about the human mentality. Continue reading “One day, the poor will have nothing to eat but the rich”

3 nights and 1200 miles later – Road trip from Seattle, WA to San Diego, CA

Two weeks ago, I started my road trip from Seattle, WA to San Diego, CA. It was my first very long road trip in the US. At first, I was just going to punch-in my destination into my GPS and drive along whatever route it suggests. However, after talking to friends who already took a similar road trip, they advised me to research taking the scenic route instead of the plain and dull I-5 highway. I became intrigued about the scenic route and my research indicated that it would be a longer but much more enjoyable trip.

What follows is my short story where I share my adventure and some tips I learned along the way. Since this is my first road trip from Seattle to San Diego along the Pacific coast and with little to no experience driving along the coast, I am hoping that this article proves to be useful for others who also are looking to embark on a similar experience. Continue reading “3 nights and 1200 miles later – Road trip from Seattle, WA to San Diego, CA”