@@ -21,6 +21,57 @@ bool parser_seccomp_offset(const std::vector<char> &file_buf, size_t start, std: |
21 | 21 | return find_current_task_next_register_offset(file_buf, start, mode_name, v_seccomp); |
22 | 22 | } |
23 | 23 |
|
| 24 | +void cfi_bypass(const std::vector<char>& file_buf, KernelSymbolOffset &sym, std::vector<patch_bytes_data>& vec_patch_bytes_data) { |
| 25 | + if (sym.__cfi_check.offset) { |
| 26 | + PATCH_AND_CONSUME(sym.__cfi_check, patch_ret_cmd(file_buf, sym.__cfi_check.offset, vec_patch_bytes_data)); |
| 27 | + } |
| 28 | + if (sym.__cfi_check_fail) { |
| 29 | + patch_ret_cmd(file_buf, sym.__cfi_check_fail, vec_patch_bytes_data); |
| 30 | + } |
| 31 | + if (sym.__cfi_slowpath_diag) { |
| 32 | + patch_ret_cmd(file_buf, sym.__cfi_slowpath_diag, vec_patch_bytes_data); |
| 33 | + } |
| 34 | + if (sym.__cfi_slowpath) { |
| 35 | + patch_ret_cmd(file_buf, sym.__cfi_slowpath, vec_patch_bytes_data); |
| 36 | + } |
| 37 | + if (sym.__ubsan_handle_cfi_check_fail_abort) { |
| 38 | + patch_ret_cmd(file_buf, sym.__ubsan_handle_cfi_check_fail_abort, vec_patch_bytes_data); |
| 39 | + } |
| 40 | + if (sym.__ubsan_handle_cfi_check_fail) { |
| 41 | + patch_ret_cmd(file_buf, sym.__ubsan_handle_cfi_check_fail, vec_patch_bytes_data); |
| 42 | + } |
| 43 | + if (sym.report_cfi_failure) { |
| 44 | + patch_ret_1_cmd(file_buf, sym.report_cfi_failure, vec_patch_bytes_data); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +void no_use_patch(const std::vector<char>& file_buf, KernelSymbolOffset &sym, std::vector<patch_bytes_data>& vec_patch_bytes_data) { |
| 49 | + if (sym.drm_dev_printk.offset) { |
| 50 | + PATCH_AND_CONSUME(sym.drm_dev_printk, patch_ret_cmd(file_buf, sym.drm_dev_printk.offset, vec_patch_bytes_data)); |
| 51 | + } |
| 52 | + if (sym.dev_printk.offset) { |
| 53 | + PATCH_AND_CONSUME(sym.dev_printk, patch_ret_cmd(file_buf, sym.dev_printk.offset, vec_patch_bytes_data)); |
| 54 | + } |
| 55 | + if (sym.register_die_notifier.offset) { |
| 56 | + PATCH_AND_CONSUME(sym.register_die_notifier, patch_ret_0_cmd(file_buf, sym.register_die_notifier.offset, vec_patch_bytes_data)); |
| 57 | + } |
| 58 | + if (sym.unregister_die_notifier.offset) { |
| 59 | + PATCH_AND_CONSUME(sym.unregister_die_notifier, patch_ret_0_cmd(file_buf, sym.unregister_die_notifier.offset, vec_patch_bytes_data)); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +void write_all_patch(const char* file_path, std::vector<patch_bytes_data>& vec_patch_bytes_data) { |
| 64 | + for (auto& item : vec_patch_bytes_data) { |
| 65 | + std::shared_ptr<char> spData(new (std::nothrow) char[item.str_bytes.length() / 2], std::default_delete<char[]>()); |
| 66 | + hex2bytes((uint8_t*)item.str_bytes.c_str(), (uint8_t*)spData.get()); |
| 67 | + if (!write_file_bytes(file_path, item.write_addr, spData.get(), item.str_bytes.length() / 2)) { |
| 68 | + std::cout << "写入文件发生错误" << std::endl; |
| 69 | + } |
| 70 | + } |
| 71 | + if (vec_patch_bytes_data.size()) { |
| 72 | + std::cout << "Done." << std::endl; |
| 73 | + } |
| 74 | +} |
24 | 75 |
|
25 | 76 | int main(int argc, char* argv[]) { |
26 | 77 | ++argv; |
@@ -122,42 +173,8 @@ int main(int argc, char* argv[]) { |
122 | 173 | } |
123 | 174 |
|
124 | 175 | std::vector<patch_bytes_data> vec_patch_bytes_data; |
125 | | - //cfi bypass |
126 | | - if (sym.__cfi_check.offset) { |
127 | | - PATCH_AND_CONSUME(sym.__cfi_check, patch_ret_cmd(file_buf, sym.__cfi_check.offset, vec_patch_bytes_data)); |
128 | | - } |
129 | | - if (sym.__cfi_check_fail) { |
130 | | - patch_ret_cmd(file_buf, sym.__cfi_check_fail, vec_patch_bytes_data); |
131 | | - } |
132 | | - if (sym.__cfi_slowpath_diag) { |
133 | | - patch_ret_cmd(file_buf, sym.__cfi_slowpath_diag, vec_patch_bytes_data); |
134 | | - } |
135 | | - if (sym.__cfi_slowpath) { |
136 | | - patch_ret_cmd(file_buf, sym.__cfi_slowpath, vec_patch_bytes_data); |
137 | | - } |
138 | | - if (sym.__ubsan_handle_cfi_check_fail_abort) { |
139 | | - patch_ret_cmd(file_buf, sym.__ubsan_handle_cfi_check_fail_abort, vec_patch_bytes_data); |
140 | | - } |
141 | | - if (sym.__ubsan_handle_cfi_check_fail) { |
142 | | - patch_ret_cmd(file_buf, sym.__ubsan_handle_cfi_check_fail, vec_patch_bytes_data); |
143 | | - } |
144 | | - if (sym.report_cfi_failure) { |
145 | | - patch_ret_1_cmd(file_buf, sym.report_cfi_failure, vec_patch_bytes_data); |
146 | | - } |
147 | | - |
148 | | - // ignore patch |
149 | | - if (sym.drm_dev_printk.offset) { |
150 | | - PATCH_AND_CONSUME(sym.drm_dev_printk, patch_ret_cmd(file_buf, sym.drm_dev_printk.offset, vec_patch_bytes_data)); |
151 | | - } |
152 | | - if (sym.dev_printk.offset) { |
153 | | - PATCH_AND_CONSUME(sym.dev_printk, patch_ret_cmd(file_buf, sym.dev_printk.offset, vec_patch_bytes_data)); |
154 | | - } |
155 | | - if (sym.register_die_notifier.offset) { |
156 | | - PATCH_AND_CONSUME(sym.register_die_notifier, patch_ret_0_cmd(file_buf, sym.register_die_notifier.offset, vec_patch_bytes_data)); |
157 | | - } |
158 | | - if (sym.unregister_die_notifier.offset) { |
159 | | - PATCH_AND_CONSUME(sym.unregister_die_notifier, patch_ret_0_cmd(file_buf, sym.unregister_die_notifier.offset, vec_patch_bytes_data)); |
160 | | - } |
| 176 | + cfi_bypass(file_buf, sym, vec_patch_bytes_data); |
| 177 | + no_use_patch(file_buf, sym, vec_patch_bytes_data); |
161 | 178 |
|
162 | 179 | KernelVersionParser kernel_ver(file_buf); |
163 | 180 | PatchDoExecve patchDoExecve(file_buf, sym); |
@@ -235,16 +252,7 @@ int main(int argc, char* argv[]) { |
235 | 252 | std::cout << "#是否需要立即写入修改到文件?(1需要;2不需要):" << std::endl; |
236 | 253 | std::cin >> need_write_modify_in_file; |
237 | 254 | if (need_write_modify_in_file == 1) { |
238 | | - for (auto& item : vec_patch_bytes_data) { |
239 | | - std::shared_ptr<char> spData(new (std::nothrow) char[item.str_bytes.length() / 2], std::default_delete<char[]>()); |
240 | | - hex2bytes((uint8_t*)item.str_bytes.c_str(), (uint8_t*)spData.get()); |
241 | | - if (!write_file_bytes(file_path, item.write_addr, spData.get(), item.str_bytes.length() / 2)) { |
242 | | - std::cout << "写入文件发生错误" << std::endl; |
243 | | - } |
244 | | - } |
245 | | - } |
246 | | - if (vec_patch_bytes_data.size()) { |
247 | | - std::cout << "Done." << std::endl; |
| 255 | + write_all_patch(file_path, vec_patch_bytes_data); |
248 | 256 | } |
249 | 257 | system("pause"); |
250 | 258 | return 0; |
|