5 #include "../windows/windows_debug.h"
35 switch (mbi->Protect) {
39 case PAGE_EXECUTE_READ:
42 case PAGE_EXECUTE_READWRITE:
54 case PAGE_EXECUTE_WRITECOPY:
82 DWORD flags = TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32;
90 goto err_w32_dbg_modules;
92 me.dwSize =
sizeof(MODULEENTRY32);
93 if (!Module32First(h_mod_snap, &me)) {
95 goto err_w32_dbg_modules;
99 char *mod_name = rz_sys_conv_win_to_utf8(me.szModule);
103 dbgmap->
file = rz_sys_conv_win_to_utf8(me.szExePath);
108 }
while (Module32Next(h_mod_snap, &me));
111 CloseHandle(h_mod_snap);
117 IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)pe_hdr;
118 IMAGE_NT_HEADERS *nt_headers;
120 if (dos_header->e_magic == IMAGE_DOS_SIGNATURE) {
121 nt_headers = (IMAGE_NT_HEADERS *)((
char *)dos_header + dos_header->e_lfanew);
123 if (nt_headers->Signature == IMAGE_NT_SIGNATURE)
130 IMAGE_DOS_HEADER *dos_hdr;
131 IMAGE_NT_HEADERS *nt_hdrs;
132 IMAGE_NT_HEADERS32 *nt_hdrs32;
133 IMAGE_SECTION_HEADER *sect_hdr;
141 ReadProcessMemory(h_proc, (LPCVOID)(
size_t)
map->addr, (LPVOID)pe_hdr,
sizeof(pe_hdr), &
len);
142 if (
len == (SIZE_T)
sizeof(pe_hdr) &&
is_pe_hdr(pe_hdr)) {
143 dos_hdr = (IMAGE_DOS_HEADER *)pe_hdr;
144 nt_hdrs = (IMAGE_NT_HEADERS *)((
char *)dos_hdr + dos_hdr->e_lfanew);
145 if (nt_hdrs->FileHeader.Machine == IMAGE_FILE_MACHINE_I386) {
146 nt_hdrs32 = (IMAGE_NT_HEADERS32 *)((
char *)dos_hdr + dos_hdr->e_lfanew);
147 mod->sect_count = nt_hdrs32->FileHeader.NumberOfSections;
148 sect_hdr = (IMAGE_SECTION_HEADER *)((
char *)nt_hdrs32 +
sizeof(IMAGE_NT_HEADERS32));
150 mod->sect_count = nt_hdrs->FileHeader.NumberOfSections;
151 sect_hdr = (IMAGE_SECTION_HEADER *)((
char *)nt_hdrs +
sizeof(IMAGE_NT_HEADERS));
153 if ((
char *)sect_hdr + (
sizeof(IMAGE_SECTION_HEADER) *
mod->sect_count) < ((
char *)pe_hdr +
sizeof(pe_hdr))) {
154 mod->sect_hdr = (IMAGE_SECTION_HEADER *)
malloc(
sizeof(IMAGE_SECTION_HEADER) *
mod->sect_count);
156 memcpy(
mod->sect_hdr, sect_hdr,
sizeof(IMAGE_SECTION_HEADER) *
mod->sect_count);
159 perror(
"malloc set_mod_inf()");
163 if (mod_inf_fill == -1) {
178 rz_list_foreach (mod_list,
iter,
map) {
179 if (
addr >=
map->addr && addr <= map->addr_end) {
186 if (
mod->map &&
mod->sect_hdr &&
mod->sect_count > 0) {
191 p_mask =
si->dwPageSize - 1;
192 for (
i = 0;
i <
mod->sect_count;
i++) {
193 IMAGE_SECTION_HEADER *sect_hdr = &
mod->sect_hdr[
i];
194 ut64 sect_addr =
mod->map->addr + (
ut64)sect_hdr->VirtualAddress;
195 ut64 sect_len = (((
ut64)sect_hdr->Misc.VirtualSize) + p_mask) & ~p_mask;
199 if (sect_addr >=
addr && (sect_addr + sect_len) <= (
addr +
len)) {
202 }
else if (
addr >= sect_addr && (
addr +
len) <= (sect_addr + sect_len)) {
206 char *map_name =
rz_str_newf(
"%s | %.8s",
mod->map->name, sect_hdr->Name);
208 perror(
"rz_str_newf");
211 if (sect_found == 1) {
212 add_map(map_list, map_name, sect_addr, sect_len, mbi);
220 if (sect_count == 0) {
233 WCHAR f_name[MAX_PATH + 1];
235 DWORD len = GetMappedFileNameW(h_proc, mbi->BaseAddress, f_name, MAX_PATH);
237 char *f_name_ = rz_utf16_to_utf8(f_name);
249 SYSTEM_INFO
si = { 0 };
251 MEMORY_BASIC_INFORMATION mbi;
257 cur_addr =
si.lpMinimumApplicationAddress;
261 while (cur_addr <
si.lpMaximumApplicationAddress &&
262 VirtualQueryEx(wrap->
pi.hProcess, cur_addr, &mbi,
sizeof(mbi)) != 0) {
263 if (mbi.State != MEM_FREE) {
275 cur_addr = (LPVOID)(
size_t)((
ut64)(
size_t)mbi.BaseAddress + mbi.RegionSize);
static ut64 baddr(RzBinFile *bf)
static int mr(RzAnalysisEsil *esil, ut64 addr, ut8 *buf, int len)
RZ_API void rz_debug_map_free(RzDebugMap *map)
RZ_API RzDebugMap * rz_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user)
size_t map(int syms, int left, int len)
RZ_API void Ht_() free(HtName_(Ht) *ht)
#define INVALID_HANDLE_VALUE
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * malloc(size_t size)
void(* RzListFree)(void *ptr)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
static struct sockaddr static addrlen static backlog const void static flags void flags
IMAGE_SECTION_HEADER * sect_hdr
if(dbg->bits==RZ_SYS_BITS_64)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static char * get_map_type(MEMORY_BASIC_INFORMATION *mbi)
static RzDebugMap * add_map_reg(RzList *list, const char *name, MEMORY_BASIC_INFORMATION *mbi)
static void proc_mem_img(HANDLE h_proc, RzList *map_list, RzList *mod_list, RWinModInfo *mod, SYSTEM_INFO *si, MEMORY_BASIC_INFORMATION *mbi)
RZ_API RzList * rz_w32_dbg_maps(RzDebug *dbg)
RZ_API RzList * rz_w32_dbg_modules(RzDebug *dbg)
static int set_mod_inf(HANDLE h_proc, RzDebugMap *map, RWinModInfo *mod)
static void proc_mem_map(HANDLE h_proc, RzList *map_list, MEMORY_BASIC_INFORMATION *mbi)
static bool is_pe_hdr(unsigned char *pe_hdr)
static RzDebugMap * add_map(RzList *list, const char *name, ut64 addr, ut64 len, MEMORY_BASIC_INFORMATION *mbi)