Instrumenting a function

Hi,

I am trying to inject code into a binary. The code to be injected passes a string from the binary to a function. This function contains the code that needs to be inserted after a particular point in the binary. I am trying to find instrumentation examples that show how this is done. The AddNop example in the samples directory inside Phoenix adds a single Nop operand after every valid instruction.

Code Snippet

// Create a new Nop

Phx.IR.ValueInstruction nop =

Phx.IR.ValueInstruction.New(functionUnit, Phx.Common.Opcode.Nop);

// Insert it before the instruction

instruction.InsertBefore(nop);

// Let lower find right instruction opcode.

functionUnit.Lower.Instruction(nop);

My question is that if I want to inject a whole function after an instruction in my binary, do I need to individually add every instruction. Is it possible to have a dll which contains my function and somehow link to it?

Thanks in Advance!

[1627 byte] By [ArjunDasgupta] at [2008-2-28]
# 1

Yes, certainly you can just call into another dll. The addcall sample shows how for native code, and mtrace does likewise for managed code.

AndyAyers-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio,Phoenix...

Visual Studio

Site Classified