Skip to content
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

Initial implementation of heap parsing for Windows #14218

Merged
merged 23 commits into from Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 16 additions & 36 deletions libr/cons/cons.c
Expand Up @@ -1340,48 +1340,28 @@ R_API int r_cons_get_size(int *rows) {
}

#if __WINDOWS__
R_API os_info *r_sys_get_osinfo();
R_API int r_cons_get_ansicon() {
HKEY key;
DWORD type;
DWORD size;
DWORD major;
DWORD minor;
char release[25];
bool win_support = false;
if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0,
KEY_QUERY_VALUE, &key) != ERROR_SUCCESS) {
goto ANSICON;
}
size = sizeof (major);
if (RegQueryValueExA (key, "CurrentMajorVersionNumber", NULL, &type,
(LPBYTE)&major, &size) != ERROR_SUCCESS
|| type != REG_DWORD) {
goto beach;
}
size = sizeof (minor);
if (RegQueryValueExA (key, "CurrentMinorVersionNumber", NULL, &type,
(LPBYTE)&minor, &size) != ERROR_SUCCESS
|| type != REG_DWORD) {
goto beach;
}
size = sizeof (release);
if (RegQueryValueExA (key, "ReleaseId", NULL, &type,
(LPBYTE)release, &size) != ERROR_SUCCESS
|| type != REG_SZ) {
goto beach;
}
if (major > 10
|| major == 10 && minor > 0
|| major == 10 && minor == 0 && atoi (release) >= 1703) {
os_info *info = r_sys_get_osinfo ();
if (info) {
major = info->major;
minor = info->minor;
if (major > 10
|| major == 10 && minor > 0
|| major == 10 && minor == 0 && info->compilation >= 1703) {
win_support = true;
}
}
free (info);
char *ansicon = r_sys_getenv ("ANSICON");
if (ansicon) {
free (ansicon);
win_support = true;
}
beach:
RegCloseKey (key);
ANSICON:
char *env_ansicon_str = r_sys_getenv ("ANSICON");
bool env_ansicon = !!env_ansicon_str;
free (env_ansicon_str);
return win_support || env_ansicon;
return win_support;
}
#endif

Expand Down
10 changes: 10 additions & 0 deletions libr/core/cmd_debug.c
Expand Up @@ -1430,6 +1430,10 @@ static void cmd_debug_modules(RCore *core, int mode) { // "dmm"
static int cmd_dbg_map_heap_glibc_32(RCore *core, const char *input);
static int cmd_dbg_map_heap_glibc_64(RCore *core, const char *input);
#endif // __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__
#if __WINDOWS__
static int cmd_debug_map_heap_win(RCore *core, const char *input);
#endif // __WINDOWS__


static ut64 addroflib(RCore *core, const char *libname) {
RListIter *iter;
Expand Down Expand Up @@ -1493,8 +1497,12 @@ static int r_debug_heap(RCore *core, const char *input) {
}
#endif
} else {
#if __WINDOWS__
cmd_debug_map_heap_win (core, input + 1);
#else
eprintf ("MALLOC algorithm not supported\n");
return false;
#endif
}
return true;
}
Expand Down Expand Up @@ -1837,6 +1845,8 @@ static int cmd_debug_map(RCore *core, const char *input) {

#if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__
#include "linux_heap_glibc.c"
#elif __WINDOWS__
#include "windows_heap.c"
#endif

// move into basic_types.h
Expand Down
3 changes: 3 additions & 0 deletions libr/core/meson.build
Expand Up @@ -70,6 +70,9 @@ r_core_sources = [
r_core_inc = []
if host_machine.system() != 'windows'
r_core_inc += ['../../shlr/heap/include']
else
r_core_sources += 'windows_heap.c'
r_core_inc += ['../../shlr/heap/include/r_windows']
endif
r_core_inc = [platform_inc, include_directories(r_core_inc)]

Expand Down