Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:32:14+00:00 2026-06-14T12:32:14+00:00

To be short the problem is this. I’m writing a kernel-mode Windows driver, that

  • 0

To be short the problem is this. I’m writing a kernel-mode Windows driver, that gets notified when a kernel-mode DLL (or other executable module) is loaded. In some situations I have to intercept the DLL entry point routine. That is, override it so that my routine is called first, and then I may pass control to the original entry point.

On 32-bit (x86 to be exact) there was no problem to do that. I get the module base mapping address, which actually begins with the standard PE header (used by Windows executables). There there’s an RVA (address relative to the image base) of the DLL entry point. I just override it by the address of my routine minus the module base address. Voila!

Now, the things are more complicated in 64-bit. The problem is that RVAs are still 32-bit integers. Such RVAs cover the address range starting from the image base address and ending with 4GB offset. There’s no problem to reference any symbol inside the same executable module (assume it doesn’t exceed 4GB size), however this imposes problems for cross-module interception. Naturally my executable module and the one that I’m trying to hook don’t have to fall into the same 4GB range, hence there’s a problem.

Temporarily I solved this by overriding the original routine prolog code by an unconditional jmp into my code. This takes 12 bytes on 64-bit platform. Then, in order to call the original code from my routine I restore the overridden 12 bytes (means – I save them before overwriting).

So far – no problems. But now the things are changing, and I’ll have to support multi-threaded access to the entry point routine (please don’t ask why, it’s related to multi-session DLL loaded into a so-called “user space”, separate for each terminal session).

One of the solutions is to use a global lock, but I’d like to avoid this.

I know about the so-called “trampoline functions”, but I’d like to avoid this as well. Doing this requires a run-time decoding of the function prolog code to properly identify the instruction boundary and possible branching.

Recently I thought about another idea. What if I could find some “unneeded” portion of the original DLL, which is at least 12 bytes length (size of mov RAX addr + jmp RAX). Then this portion could be overridden by jmp into my hands. Then the entry point RVA could be set to this portion!

All that is needed for this to work is the appropriate portion that can be overwritten. I suppose there is such a possibility, since the PE header contains a lot of historical fields that are no more used for decades.

Is this idea worth trying, or is this a well-known technique? Andy other suggestions?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:32:15+00:00Added an answer on June 14, 2026 at 12:32 pm

    You have several options. Unfortunately, you can only choose 2 out of these 3: 100% solid; easy to implement; cheap.

    There is very high likelihood that at the end of the .TEXT section you’ll find unused space. This is because Windows maps image sections into memory in chunks of 4k, and typically the .text section isn’t an exact multiply.

    Another easy to implement is to use the PE header. An area very safe to override is the DOS stub. The problem there is that there is no guarantee the PE header is in the same section as the entry routine (Microsoft linker put it in same section though, don’t know about GNU or the others).

    Another easy but will work only for system DLL’s is to do what ‘Hot Patching’ is doing, and reuse the 15 bytes set to ‘nop’ in front of each function, and the ‘mov edi,edi’ instruction. This is the case for all DLL’s released with Windows, to support Hot Patching.

    The reliable but hard option is to do what @David Heffeman suggestions. This technique is called ‘landing function’ where you copy the first 12 bytes into a landing function, which will then jmp to the original function.

    The easy, and reliable option is using MS Detour. Microsoft Detour is a product from Microsoft Research that does exactly that, and works great, and it is supported, and it takes care of bunch of corner cases and race conditions that may pop (along with other stuff), and its x86 version is open source. The downside is that a commercial usage is very expensive – last time I checked it was 10k.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Integer summing blues, short += short problem I feel dumb that this
Super-short version: I solved this problem when I was nearly finished writing the question.
In short, the problem is this: we have a news site that has a
So I have a file that in short has this problem... #!/usr/bin/perl -w package
So the wonderful low down on this doozie of a problem: short version: We
Since the beginning I always hat this one problem with rails, short urls without
This is an interesting problem that I’ve not been able to solve yet. I
I have this problem, but in short: I have a self calling function (function
I'm trying to figure out the problem in this short paragraph of code. Any
I am storing some short user data strings in the Windows registry. This worked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.