@@ -158,6 +158,9 @@ size_t path_do_execve(const char* file_buf, const string& str_root_key, size_t |
158 | 158 | string strAsmCode = sstrAsm.str(); |
159 | 159 | cout << endl << strAsmCode << endl; |
160 | 160 | string strBytes = AsmToBytes(strAsmCode); |
| 161 | + if(!strBytes.length()) { |
| 162 | + return 0; |
| 163 | + } |
161 | 164 | nHookFuncSize = strBytes.length() / 2; |
162 | 165 | char hookOrigCmd[4] = { 0 }; |
163 | 166 | memcpy(&hookOrigCmd, (void*)((size_t)file_buf + do_execve_entry_addr), sizeof(hookOrigCmd)); |
@@ -167,6 +170,9 @@ size_t path_do_execve(const char* file_buf, const string& str_root_key, size_t |
167 | 170 | stringstream sstrAsm2; |
168 | 171 | sstrAsm2 << "B #" << hook_func_start_addr - do_execve_entry_addr << endl; |
169 | 172 | string strBytes2 = AsmToBytes(sstrAsm2.str()); |
| 173 | + if(!strBytes2.length()) { |
| 174 | + return 0; |
| 175 | + } |
170 | 176 | vec_out_patch_bytes_data.push_back({ strBytes2, do_execve_entry_addr }); |
171 | 177 | hook_func_start_addr += nHookFuncSize; |
172 | 178 | return hook_func_start_addr; |
@@ -209,6 +215,10 @@ size_t path_avc_denied(const char* file_buf, size_t hook_func_start_addr, size_t |
209 | 215 | string strAsmCode = sstrAsm.str(); |
210 | 216 | cout << endl << strAsmCode << endl; |
211 | 217 | string strBytes = AsmToBytes(strAsmCode); |
| 218 | + if(!strBytes.length()) { |
| 219 | + return 0; |
| 220 | + } |
| 221 | + |
212 | 222 | size_t nHookFuncSize = strBytes.length() / 2; |
213 | 223 | char hookOrigCmd[4] = { 0 }; |
214 | 224 | memcpy(&hookOrigCmd, (void*)((size_t)file_buf + avc_denied_entry_addr), sizeof(hookOrigCmd)); |
@@ -218,6 +228,10 @@ size_t path_avc_denied(const char* file_buf, size_t hook_func_start_addr, size_t |
218 | 228 | stringstream sstrAsm2; |
219 | 229 | sstrAsm2 << "B #" << hook_func_start_addr - avc_denied_entry_addr << endl; |
220 | 230 | string strBytes2 = AsmToBytes(sstrAsm2.str()); |
| 231 | + if(!strBytes2.length()) { |
| 232 | + return 0; |
| 233 | + } |
| 234 | + |
221 | 235 | vec_out_patch_bytes_data.push_back({ strBytes2, avc_denied_entry_addr }); |
222 | 236 | return hook_func_start_addr + nHookFuncSize; |
223 | 237 | } |
@@ -337,10 +351,19 @@ int main(int argc, char* argv[]) { |
337 | 351 | cin >> str_root_key; |
338 | 352 | } |
339 | 353 | vector<patch_bytes_data> vec_patch_bytes_data; |
340 | | - hook_func_start_addr = path_do_execve(image, str_root_key, hook_func_start_addr, do_execve_entry_addr, |
341 | | - task_struct_offset_cred, task_struct_offset_seccomp, vec_patch_bytes_data); |
342 | | - path_avc_denied(image, hook_func_start_addr, avc_denied_entry_addr, task_struct_offset_cred, vec_patch_bytes_data); |
343 | | - |
| 354 | + hook_func_start_addr = path_do_execve(image, str_root_key, hook_func_start_addr, do_execve_entry_addr, task_struct_offset_cred, task_struct_offset_seccomp, vec_patch_bytes_data); |
| 355 | + if(hook_func_start_addr == 0) { |
| 356 | + cout << "生成汇编代码失败!请检查输入的参数!" << endl; |
| 357 | + system("pause"); |
| 358 | + return 0; |
| 359 | + } |
| 360 | + |
| 361 | + if(path_avc_denied(image, hook_func_start_addr, avc_denied_entry_addr, task_struct_offset_cred, vec_patch_bytes_data) == 0) { |
| 362 | + cout << "生成汇编代码失败!请检查输入的参数!" << endl; |
| 363 | + system("pause"); |
| 364 | + return 0; |
| 365 | + } |
| 366 | + |
344 | 367 | cout << "#获取ROOT权限的密匙:" << str_root_key.c_str() << endl << endl; |
345 | 368 |
|
346 | 369 | size_t need_write_modify_in_file = 0; |
|