How to use DynamoRIO for the c/c++.

72 views
Skip to first unread message

Rohith Damarla

unread,
Nov 17, 2021, 5:28:00 AM11/17/21
to DynamoRIO Users
Suppose i have a C application 

#include <stdio.h>
void  Print_hell  (){ 
    printf("hello\n");   
}

void  Print_hii  (){ 
printf("hii\n");
}

int main(){
Print_hello();
Print_hii();

}

I have a c library which contains a function  Lib_function

void Lib_function(){
printf("something\n");
}

Can I instrument Lib_functon in each of the binary functons with the help of this tool

If yes please give me an example.

Derek Bruening

unread,
Nov 19, 2021, 6:59:02 PM11/19/21
to dynamor...@googlegroups.com
If you mean can you identify functions and take action upon their execution, yes if they are exported or you have symbols.  See drsyms for symbol lookup.  See drwrap for convenience functions for taking actions on function entry or exit.
See the list of samples some of which use drwrap or drsyms: https://dynamorio.org/API_samples.html

--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dynamorio-users/8c172540-7acc-49f2-8eb0-f56b88e7df8fn%40googlegroups.com.

Rohith Damarla

unread,
Dec 7, 2021, 6:37:10 AM12/7/21
to DynamoRIO Users

Hii Derek, 

Thanks for the reply, I have one more question i.e, in the above-mentioned question how do we call Print_hii() function while calling drwrap on Print_hell  that means how can we call Print_hii with wrap_pre before  Print_hell   in a C binary?
if possible suggest me an example.

John Galea

unread,
Dec 7, 2021, 3:41:04 PM12/7/21
to DynamoRIO Users
Hi,

You achieve this by using drwrap_wrap(), which is provided by the drwrap API.

As Derek stated, you can view the sample to see exactly how this function is invoked: https://github.com/DynamoRIO/dynamorio/blob/master/api/samples/wrap.c

Rohith Damarla

unread,
Dec 8, 2021, 12:37:08 AM12/8/21
to DynamoRIO Users
Hi, thanks for the reply

Actually what I mean is, suppose I have a C binary that has two functions (let's say func1 and func2). Now I'm instrumenting func1 by using wrap.c, how can I call func2 from wrap_pre? 

i.e,  I instrument func1 in module_load_event and use wrap_pre and wrap_post at the entry & exit points. When func1 will be executed, it will invoke wrap_pre. My requirement is to call func2 from wrap_pre

Derek Bruening

unread,
Dec 8, 2021, 6:12:01 PM12/8/21
to dynamor...@googlegroups.com
wrap_pre is running in a tool context.  Do you mean to call func2 *as a tool*?  I.e., with registers and resources isolated from the application?  Or *as the application*?  For the latter, any application code needs to be presented to all tool libraries for monitoring and instrumenting, so in addition to needing to change contexts from tool to application it is not like a direct call can be made: the target code needs to be split into blocks and managed in the code cache like regular application code.  There have been related feature requests like https://github.com/DynamoRIO/dynamorio/issues/497 which contains suggestions on how to do something like this and pointers to other users-list threads but no one has yet implemented a convenience library that auto-magically does this.  If you end up building such a library that others could use please consider contributing it.

Reply all
Reply to author
Forward
0 new messages