-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
you might not like this pull request ... #2
base: master
Are you sure you want to change the base?
Changes from all commits
8b52c77
a207dcb
f007799
4142b51
3de4e99
049fdfe
ad06ec1
b461e64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
all: | ||
mkdir -p build | ||
cd build && cmake .. -DDynamoRIO_DIR="$(DYNAMORIO_HOME)/cmake" && make | ||
|
||
install: all | ||
install -d /usr/local/lib/dynamorio | ||
install build/libcfg.so /usr/local/lib/dynamorio | ||
install drcfg.sh /usr/local/bin/ | ||
|
||
save: all | ||
mkdir -p bin/`uname -m` | ||
cp -v build/lib*.so bin/`uname -m` | ||
-@svn add bin/`uname -m` 2> /dev/null | ||
-@svn add bin/`uname -m`/*.so 2> /dev/null | ||
|
||
clean: | ||
rm -rf build |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,22 +18,91 @@ static droption_t<bool> no_cti | |
(DROPTION_SCOPE_CLIENT, "no_cti", false, | ||
"Don't count control transfer instructions", ""); | ||
|
||
static droption_t<std::string> output | ||
droption_t<std::string> output | ||
(DROPTION_SCOPE_CLIENT, "output", "", | ||
"Output results to file", ""); | ||
|
||
droption_t<bool> txt | ||
(DROPTION_SCOPE_CLIENT, "txt", false, | ||
"Print text output while running instead of json at the end of the run - you will have to take care of the doubles youself", ""); | ||
|
||
static void *mutex; | ||
static int tcls_idx; | ||
static FILE *out = stdout; | ||
|
||
typedef struct { | ||
void *addr; | ||
} per_thread_t; | ||
|
||
|
||
void | ||
dr_exit(void) | ||
{ | ||
if (output.get_value() == "") | ||
std::cout << std::setw(2) << construct_json() << std::endl; | ||
else { | ||
std::ofstream ofs(output.get_value()); | ||
ofs << std::setw(2) << construct_json() << std::endl; | ||
if (!txt.get_value()) { | ||
if (output.get_value() == "") | ||
std::cout << std::hex << std::setw(2) << construct_json() << std::endl; | ||
else { | ||
std::ofstream ofs(output.get_value()); | ||
ofs << std::hex << std::setw(2) << construct_json() << std::endl; | ||
} | ||
} | ||
drmgr_exit(); | ||
} | ||
|
||
void | ||
event_thread_context_init(void *drcontext, bool new_depth) | ||
{ | ||
per_thread_t *data; | ||
|
||
if (new_depth) { | ||
data = (per_thread_t *) dr_thread_alloc(drcontext, sizeof(per_thread_t)); | ||
drmgr_set_cls_field(drcontext, tcls_idx, data); | ||
} else { | ||
data = (per_thread_t *) drmgr_get_cls_field(drcontext, tcls_idx); | ||
} | ||
memset(data, 0, sizeof(*data)); | ||
} | ||
|
||
void | ||
event_thread_context_exit(void *drcontext, bool thread_exit) | ||
{ | ||
if (thread_exit) { | ||
per_thread_t *data = (per_thread_t *) drmgr_get_cls_field(drcontext, tcls_idx); | ||
dr_thread_free(drcontext, data, sizeof(per_thread_t)); | ||
drmgr_set_cls_field(drcontext, tcls_idx, NULL); | ||
} | ||
} | ||
|
||
dr_emit_flags_t | ||
event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *instr, | ||
bool for_trace, bool translating, void *user_data) | ||
{ | ||
per_thread_t *data = (per_thread_t *) drmgr_get_cls_field(drcontext, tcls_idx); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is trying to re-implement cbr.cpp. I would not recommend this, as it'll probably be easier to fix cbr.cpp and adapt it for ARM (and potentially re-contribute the fix towards the cbr.c sample in the DynamoRIO repo which should exhibit the same problems). If you do not have the time for this, I can take a stab at it within the next week or so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another thing--I'm wondering if this works in general. DynamoRIO fires an
It's a simple if-then-else statement in C. However, if we record the edge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just reading this after reading & answering your email - just returned from vacation :) actually, you have a point that your a -> b|c ->d might only log one path. that might be the case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, done. I did a comparison to drcfg in your repository (called "before.txt") and my cloned repository with the changes (called "after.txt"). I disabled random address space, and traced "unrar -inul p test.rar"
this looks like 99% similar results. if your assumption would hold true, then for every source, there would only be one target recorded. however I find in the my patched results even results with multiple entries, e.g.:
so it looks like my approach is working. I would feel more sure if you would verify with your own tests though :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, will take a look w/in the next few days :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider the following code: cbr.zip It has the diamond shape, like I mentioned above. This PR yields the following output:
Clearly we're missing one of the targets (to the done branch, I think). |
||
if (data->addr != NULL) { | ||
dr_mutex_lock(mutex); | ||
if (txt.get_value()) { | ||
fprintf(out, "INDIRECT jmp/call from %p to %p\n", data->addr, tag); | ||
} else { | ||
safe_insert((uintptr_t)data->addr, (uintptr_t)tag); | ||
} | ||
dr_mutex_unlock(mutex); | ||
data->addr = NULL; | ||
} | ||
|
||
if (!drmgr_is_last_instr(drcontext, instr)) | ||
return DR_EMIT_DEFAULT; | ||
if (app_should_ignore_tag(tag)) | ||
return DR_EMIT_DEFAULT; | ||
|
||
if (!no_cbr.get_value() && instr_is_cbr(instr)) | ||
data->addr = instr_get_app_pc(instr); | ||
else if (!no_cti.get_value() && instr_is_cbr(instr)) | ||
data->addr = instr_get_app_pc(instr); | ||
|
||
if (app_should_ignore_tag(tag)) | ||
return DR_EMIT_DEFAULT; | ||
} | ||
|
||
DR_EXPORT | ||
void | ||
dr_client_main(client_id_t id, int argc, const char *argv[]) | ||
|
@@ -46,9 +115,21 @@ dr_client_main(client_id_t id, int argc, const char *argv[]) | |
|
||
app_init(); | ||
drmgr_init(); | ||
|
||
if (output.get_value() != "") { | ||
if ((out = fopen(output.get_value().c_str(), "w")) == NULL) | ||
DR_ASSERT_MSG(false, "can not write -outputfile"); | ||
} | ||
|
||
mutex = dr_mutex_create(); | ||
tcls_idx = drmgr_register_cls_field(event_thread_context_init, event_thread_context_exit); | ||
DR_ASSERT_MSG(tcls_idx != -1, "memory problems"); | ||
drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL); | ||
/* | ||
if (!no_cbr.get_value()) | ||
drmgr_register_bb_instrumentation_event(NULL, cbr_event_app_instruction, NULL); | ||
if (!no_cti.get_value()) | ||
drmgr_register_bb_instrumentation_event(NULL, cti_event_app_instruction, NULL); | ||
*/ | ||
dr_register_exit_event(dr_exit); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#/bin/sh | ||
VER=32 | ||
uname -m 2> /dev/null | grep -q 64 > /dev/null 2>&1 && VER=64 | ||
HELP=yes | ||
for i in $*; do | ||
test " $i" = " --" && HELP= | ||
done | ||
test -n "$HELP" && { | ||
echo "Syntax: $0 [options] -- /foo/binary -opts" | ||
echo Options: | ||
$DYNAMORIO_HOME/bin$VER/drrun -c /usr/local/lib/dynamorio/libcfg.so -h -- /bin/sh | ||
exit 1 | ||
} | ||
echo "[drcfg] using DynamoRIO" | ||
$DYNAMORIO_HOME/bin$VER/drrun -c /usr/local/lib/dynamorio/libcfg.so $* | ||
echo "[drcfg] done" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why both of these are gone. On ARM I wouldn't expect cbr.cpp to work (it's a special case of branches for which all branch targets are known statically, inspired by a sample in the DR repo, cbr.c), but why are you deleting cti.cpp? cti.cpp is supposed to cover a superset of what cbr.cpp covers. Maybe we can simply disable cbr.cpp for ARM and let cti.cpp take over?