@@ -113,44 +113,47 @@ size_t PlatformRegion::size() const {
113113 * @param execute
114114 */
115115void PlatformRegion::setPermissions (bool read, bool write, bool execute) {
116- if (HANDLE ph = OpenProcess (PROCESS_VM_OPERATION, FALSE , edb::v1::debugger_core->process ()->pid ())) {
117- DWORD prot = PAGE_NOACCESS;
118-
119- switch ((static_cast <int >(read) << 2 ) | (static_cast <int >(write) << 1 ) | (static_cast <int >(execute) << 0 )) {
120- case 0x0 :
121- prot = PAGE_NOACCESS;
122- break ;
123- case 0x1 :
124- prot = PAGE_EXECUTE;
125- break ;
126- case 0x2 :
127- prot = PAGE_WRITECOPY;
128- break ;
129- case 0x3 :
130- prot = PAGE_EXECUTE_WRITECOPY;
131- break ;
132- case 0x4 :
133- prot = PAGE_READONLY;
134- break ;
135- case 0x5 :
136- prot = PAGE_EXECUTE_READ;
137- break ;
138- case 0x6 :
139- prot = PAGE_READWRITE;
140- break ;
141- case 0x7 :
142- prot = PAGE_EXECUTE_READWRITE;
143- break ;
144- }
145-
146- prot |= permissions_ & ~KnownPermissions; // keep modifiers
147116
148- DWORD prev_prot;
149- if (VirtualProtectEx (ph, reinterpret_cast <LPVOID>(start ().toUint ()), size (), prot, &prev_prot)) {
150- permissions_ = prot;
117+ if (IProcess *process = edb::v1::debugger_core->process ()) {
118+ if (HANDLE ph = OpenProcess (PROCESS_VM_OPERATION, FALSE , process->pid ())) {
119+ DWORD prot = PAGE_NOACCESS;
120+
121+ switch ((static_cast <int >(read) << 2 ) | (static_cast <int >(write) << 1 ) | (static_cast <int >(execute) << 0 )) {
122+ case 0x0 :
123+ prot = PAGE_NOACCESS;
124+ break ;
125+ case 0x1 :
126+ prot = PAGE_EXECUTE;
127+ break ;
128+ case 0x2 :
129+ prot = PAGE_WRITECOPY;
130+ break ;
131+ case 0x3 :
132+ prot = PAGE_EXECUTE_WRITECOPY;
133+ break ;
134+ case 0x4 :
135+ prot = PAGE_READONLY;
136+ break ;
137+ case 0x5 :
138+ prot = PAGE_EXECUTE_READ;
139+ break ;
140+ case 0x6 :
141+ prot = PAGE_READWRITE;
142+ break ;
143+ case 0x7 :
144+ prot = PAGE_EXECUTE_READWRITE;
145+ break ;
146+ }
147+
148+ prot |= permissions_ & ~KnownPermissions; // keep modifiers
149+
150+ DWORD prev_prot;
151+ if (VirtualProtectEx (ph, reinterpret_cast <LPVOID>(start ().toUint ()), size (), prot, &prev_prot)) {
152+ permissions_ = prot;
153+ }
154+
155+ CloseHandle (ph);
151156 }
152-
153- CloseHandle (ph);
154157 }
155158}
156159
0 commit comments