|
5 | 5 | #include <string> |
6 | 6 | #include <sstream> |
7 | 7 | #include <vector> |
| 8 | +#include <algorithm> |
8 | 9 | #include "ArmAsmHelper.h" |
9 | 10 |
|
10 | 11 |
|
@@ -128,7 +129,6 @@ size_t path_do_execve(const char* file_buf, const string& str_root_key, size_t |
128 | 129 | string strBytes2 = AsmToBytes(sstrAsm2.str()); |
129 | 130 | vec_out_patch_bytes_data.push_back({ strBytes2, do_execve_entry_addr }); |
130 | 131 | hook_func_start_addr += nHookFuncSize; |
131 | | - cout << "#下一段HOOK函数起始可写位置:" << hex << hook_func_start_addr << endl << endl; |
132 | 132 | return hook_func_start_addr; |
133 | 133 | } |
134 | 134 |
|
@@ -202,6 +202,20 @@ bool write_file_bytes(const char* file_path, long offset, const char* bytes, int |
202 | 202 | return true; |
203 | 203 | } |
204 | 204 |
|
| 205 | +size_t get_input_hex_number() { |
| 206 | + std::string input; |
| 207 | + cin >> input; |
| 208 | + transform(input.begin(), input.end(), input.begin(), ::tolower); |
| 209 | + if (input.length() > 2 && input.substr(0, 1) == "0x") { |
| 210 | + input = input.substr(2); |
| 211 | + } |
| 212 | + std::stringstream convert; |
| 213 | + convert << hex << input; |
| 214 | + size_t val; |
| 215 | + convert >> val; |
| 216 | + return val; |
| 217 | +} |
| 218 | + |
205 | 219 | int main(int argc, char* argv[]) { |
206 | 220 | ++argv; |
207 | 221 | --argc; |
@@ -223,36 +237,49 @@ int main(int argc, char* argv[]) { |
223 | 237 | return 0; |
224 | 238 | } |
225 | 239 |
|
| 240 | + |
226 | 241 | //cout << "请输入空闲代码的位置:(即存放执行HOOK代码的位置):" << endl; |
227 | 242 | size_t hook_func_start_addr = 0x300; |
228 | | - //cin >> hex >> hook_func_start_addr; |
| 243 | + //hook_func_start_addr = get_input_hex_number(); |
| 244 | + |
| 245 | + size_t do_execve_entry_addr = -1; |
| 246 | + while (do_execve_entry_addr <= 0 || do_execve_entry_addr % 8) { |
| 247 | + cout << "请输入do_execve函数的入口位置:" << endl; |
| 248 | + do_execve_entry_addr = get_input_hex_number(); |
| 249 | + if (do_execve_entry_addr<=0 || do_execve_entry_addr % 8) { |
| 250 | + cout << "输入的信息有错误" << endl; |
| 251 | + } |
| 252 | + } |
229 | 253 |
|
230 | | - size_t do_execve_entry_addr = 0; |
231 | | - cout << "请输入do_execve函数的入口位置:" << endl; |
232 | | - cin >> hex >> do_execve_entry_addr; |
| 254 | + size_t avc_denied_entry_addr = -1; |
| 255 | + while (avc_denied_entry_addr <= 0 || avc_denied_entry_addr % 8) { |
| 256 | + cout << "请输入avc_denied函数的入口位置:" << endl; |
| 257 | + avc_denied_entry_addr = get_input_hex_number(); |
| 258 | + if (avc_denied_entry_addr <= 0 || avc_denied_entry_addr % 8) { |
| 259 | + cout << "输入的信息有错误" << endl; |
| 260 | + } |
233 | 261 |
|
234 | | - size_t avc_denied_entry_addr = 0; |
235 | | - cout << "请输入avc_denied函数的入口位置:" << endl; |
236 | | - cin >> hex >> avc_denied_entry_addr; |
| 262 | + } |
237 | 263 |
|
238 | 264 | size_t task_struct_offset_cred = -1; |
239 | | - while (task_struct_offset_cred % 8) { |
| 265 | + while (task_struct_offset_cred <= 0 || task_struct_offset_cred % 8) { |
240 | 266 | cout << "请输入task_struct结构体里cred的十六进制偏移值(从proc_pid_status里能看到):" << endl; |
241 | | - cin >> hex >> task_struct_offset_cred; |
242 | | - if (task_struct_offset_cred % 8) { |
| 267 | + task_struct_offset_cred = get_input_hex_number(); |
| 268 | + if (task_struct_offset_cred <= 0 || task_struct_offset_cred % 8) { |
243 | 269 | cout << "输入的信息有错误" << endl; |
244 | 270 | } |
245 | 271 | } |
246 | 272 |
|
247 | 273 | size_t task_struct_offset_seccomp = -1; |
248 | | - while (task_struct_offset_seccomp % 8) { |
| 274 | + while (task_struct_offset_seccomp <= 0 || task_struct_offset_seccomp % 8) { |
249 | 275 | cout << "请输入task_struct结构体里seccomp的十六进制偏移值(从proc_pid_status里能看到):" << endl; |
250 | | - cin >> hex >> task_struct_offset_seccomp; |
251 | | - if (task_struct_offset_seccomp % 8) { |
| 276 | + task_struct_offset_seccomp = get_input_hex_number(); |
| 277 | + if (task_struct_offset_seccomp <= 0 || task_struct_offset_seccomp % 8) { |
252 | 278 | cout << "输入的信息有错误" << endl; |
253 | 279 | } |
254 | 280 | } |
255 | 281 |
|
| 282 | + |
256 | 283 | string str_root_key; |
257 | 284 | size_t create_new_root_key = 0; |
258 | 285 | cout << "是否需要自动随机生成ROOT密匙(1需要;2不需要):" << endl; |
|