Re: How to locate compiled binary code relative to source code?

From: Gerry Quinn (gerryq_at_DELETETHISindigo.ie)
Date: 07/13/04


Date: Tue, 13 Jul 2004 22:03:10 +0100

In article <10f7vjmj90o9173@corp.supernews.com>, nope@nospam.com says...
> Win32. I am learning about the guts of the PE format to implement modifying
> an exe
> after distribution. As an exercise I want to solve the following problem:
>
> I need to be able to identify in the compiled EXE a specific location
> relative to the source code.
>
> When it compiles, I need to be able to locate in the binary exe the offsets
> of IDENTIFIER1 and IDENTIFIER2 such that in between these offsets in the
> compiled exe image are the instructions for "some code a, b and c". I don't
> really care about IDENTIFIERs themselves - really all I want is to know is:
> exactly where the instructions are (in the binary) that are in between them
> (a,b,c).

> I thought about using a unique series of inline assembly (that does
> effectively nothing), and searching for the compiled opcodes that
> correspond - but this is very awkward since I may need numerous sequences
> which all have to be unique.

All the same, that's probably what you need. However, I don't think the
problem is as bad as you think. Let's say you identify one unique
series of assembly that does nothing, and that can get compiled reliably
by the compiler (you might have to switch off optimisations around it).

Then it should be easy to make as many unique sequences as you want.
For the sake of argument, say you can identify the following sequence:

Push register A on stack
Load A, 555555555
Pop register A from stack

You probably can, because constants of 555555555 will not appear very
often in code.

Then if you add another line after loading 5555555555:
Load A, n
..you have a distinguishable identifier for every value of n.

I don't know if the exact example above will work, but it should be
possible to do something of the kind.

- Gerry Quinn



Relevant Pages

  • Re: Please help - getting error when open program - "Type Mismatch"
    ... Also I can make it an exe. ... compiles ok... ... 20 b = InputBox("Enter an integer to divide by") ... You may have to compile several debug versions of your app in order to ...
    (microsoft.public.vb.general.discussion)
  • Re: Please help - getting error when open program - "Type Mismatch"
    ... Also I can make it an exe. ... compiles ok... ... 20 b = InputBox("Enter an integer to divide by") ... You may have to compile several debug versions of your app in order to ...
    (microsoft.public.vb.general.discussion)
  • Re: Protecting code
    ... > I know that when an .NET exe is run, ... > compiles them to native code then runs the code. ... method is called it is JIT compiled and the native code is cached in memory. ... > debugger and serialise the exe and assemblies ...
    (microsoft.public.dotnet.security)
  • Re: Still Loving Python
    ... >> A single click compiles, links and runs the resulting independent windows .exe in a fraction of a second ... >> for the above, and I can see the hint, kill the .exe, and go on where I was. ... Not in a fraction of a second, but that's sort of irrelevant to ... Bengt Richter ...
    (comp.lang.python)