📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  IDA Pro  >>  Possible to Insert Code Using IDA SDK (not patching)?

Topic created on: March 15, 2007 07:40 CDT by stam321 .

For example, an API call that looks like:

insert_instruction(long ea, char *instruction);
  ea          - where to add the instruction;
  instruction - a string like "mov eax, ebx"

Any simple way to do something similar is also good.

Thx,
  Stam

  fileoffset     March 15, 2007 22:29.59 CDT
Firstly, no.

Secondly, that is a very non-trivial task :P

  stam321     March 15, 2007 23:34.20 CDT
I know its not trivial.
But I hoped :).

  Nevar     March 17, 2007 05:14.18 CDT
You may have some limited success if you try to insert it in functions that are bounded by alignment bytes that can be overwritten.  The procedure would then be create a gap for the new instruction by shifting bytes.  For the most part this should work as long as any relative jumps get fixed to account for the inserted instruction.

In any case, the most you might be able to get is one or two instructions in HLL compiled code with mixed success.

-nevar

  seokwoochoi     March 20, 2007 03:14.31 CDT
An insertion of an instruction causes shifting all following instructions.
Then, all addresses referring to the following instructions should be recalculated.
If debugging information like pdb file exists, it may be possible. For example MS Vulcan binary rewriter does it though the tool is not available outside MS.

  Piotr     March 20, 2007 04:58.19 CDT
4514N does so (without pdb and any other additional sh*t), this process is called integrating and yes it is not easy :)
All the refferences,jump/call locations need to be updated or extended if we speak about short and long jumps. Then all the PE structure need to be correctly changed, bla bla...

In case u have missed the integrating video file:
http://piotrbania.com/all/4514N/demo.swf

  seokwoochoi     March 20, 2007 06:37.12 CDT
I agree with piotr in some point.
I've also tried injecting redundant instructions for obfuscation. In small examples like calculator or notepad, code injection was successful like 4514N.
But code injection is unsafe when disassembly is incorrect or some part of address identification is incorrect or missing.
I mentioned pdb file because pdb file assures us correct code injection. And in MS case, IDAPro gets symbol information from MS symbol server. :)

  Piotr     March 20, 2007 08:29.23 CDT
Of course man, but i have also tried larger stuffs like windows network drivers etc. etc. 4514N can be used together with IDA disassembly, and if you know what u are doing everything will work correctly :)

  stam321     March 20, 2007 08:57.49 CDT
When will you release 4514N? It seems great!
Can you release what you got already?
Even the assembler code alone will be great :)

thx,
  stam

  Piotr     March 21, 2007 15:28.00 CDT
> stam321: When will you release 4514N? It seems great!
> Can you release what you got already?
> Even the assembler code alone will be great :)
>
> thx,
>   stam


The answer for your question has already been posted :)
Look last 3 posts here: http://www.openrce.org/blog/view/664/Boring._Boring.


cheers

  key001     May 6, 2007 01:54.01 CDT
> stam321: For example, an API call that looks like:
>
> insert_instruction(long ea, char *instruction);
>   ea          - where to add the instruction;
>   instruction - a string like \"mov eax, ebx\"
>

> Any simple way to do something similar is also good.
>
> Thx,
>   Stam

well, if there is an empty block in the code (with 0's or nop's), it's easy to do.

lets say the code is
push eax
*** you want to insert an instruction here, eg. inc ecx
mov ebx, edx
....

so you need to replace mov ebx,edx and the following instructions with jmp empty_block. also add nop's if jmp overwrites part of some instruction.

but before you do that, put your instruction in the empty block, then copy ebx, edx there, plus a few instructions...

in the end it will look like
push eax
jmp empty_block
tmp:...

empty_block:
inc ecx
mov ebx, edx
....
jmp tmp

hope this helps, and sorry for the thread necromancy ^^

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit