Hello,
Within my current implementation, I am able to split and inject basic
blocks on the basis of PatchAPI. The newly created and injected basic
blocks are currently filled with raw bytes, as stated within the following:
InsertedCode::Ptr icode = PatchModifier::insert(post_block->object(),
bytes, nbytes);
This method of code injection works fine. However, since it is possible
to convert BPatch_snippets into PatchAPI::Snippets, I thought it might
as well be possible to use predefined library functions to be
instumented into the binary into the specified basic block. The
following shows an idea of what I inteded to do:
---
...
BPatch_Vector<BPatch_function *> funcs;
BPatch_function *func_lib;
BPatch_image* img;
img = app->getImage();
/* look for the predefined library function 'prolog' */
funcs.clear();
img->findFunction("pprolog", funcs);
func_lib = funcs[0];
/* no arguments required for function 'pprolog' */
std::vector<BPatch_snippet *> args;
BPatch_funcCallExpr func_instr(*func_lib, args);
SnippetPtr snippet = PatchAPI::convert(func_instr);
...
/* SEGFAULT: Here, I am not quite sure how to get the right point of the
newly created (empty) basic block */
InsertedCode::Ptr icode = PatchModifier::insert(post_block->object(),
snippet, point);
...
---
Unfortunately, this kind of implementation crashed with a Segfault at
the point of insertion. Which might be the result of the fact that I
don't know exactly how to find an entry point of the type
PatchAPI::Point* to the empty basic block. Any help would be appreciated
at this point.
My second question aims at the use of registers:
Is it possible to change the registers of individual instructions with
help of Dynsinst? The following should explain my idea:
---
changing registers from:
mov edx, [esp+0x18]
e.g into:
mov edx, [ebp-0x8]
---
My question is: is it possible to use high level constructs of
DyninstAPI to make these kind of adjustments or is it easier to work on
the level of raw bytes instead? Until now, I was not very successfull in
working with registers with help of DyninstAPI. I would really
appreciate it if someone could provide me a hint how to correctly access
the registers.
Thank you very much in advance.
Best regards,
Sergej
--
Sometimes the problem is to discover what the problem is.
[Gordon Glegg, The Design of Design]
|