c++ - Finding where a handle is open to -
i'm messing around handles / hooks, , have question. right now, have dll inject process i'm playing with. dll hooks closehandle() function. when closehandle called, following:
int winapi detourclosehandle(handle hobject) { outputdebugstringa("close hadnle"); char name[max_path]; getfinalpathnamebyhandle(hobject, name, max_path, file_name_normalized); outputdebugstringa(name); return oclosehandle(hobject); }
my goal in figure out handle open to, , if handle open process, use handle read processes memory. gets printed out when closehandle called paths random files application reads, noticed random ascii characters being printed @ times, "name" of handle opened to. this can seen here.
sometimes notice paths .exe files. not unusual, application i'm injecting read / @ binary files. question is, when see "name" returned getfinalpathnamebyhandle path exe file, how know if handle opened binary file itself, or if handle file opened actual running process name.
i insight ascii characters being printed are. thanks!
for random data print pasted, because uninitialized garbage in name array, should check getfinalpathnamebyhandle
's return value before name:
dword ret = getfinalpathnamebyhandle(hobject, name, max_path, file_name_normalized); if (ret) { outputdebugstringa(name); } else { outputdebugstringa("getfinalpathnamebyhandle"); // check getlasterror() }
also, note getfinalpathnamebyhandle
thake string tchar
strings, , print via outputdebugstringa
. suggest either use ansi version getfinalpathnamebyhandlea
, or use tchar name[max_path];
, print outputdebugstring
instead.
Comments
Post a Comment