{"id":6321,"date":"2022-01-15T17:41:19","date_gmt":"2022-01-15T09:41:19","guid":{"rendered":"https:\/\/www.wangonc.com\/?p=6321"},"modified":"2024-03-01T14:27:32","modified_gmt":"2024-03-01T06:27:32","slug":"unicorn","status":"publish","type":"post","link":"https:\/\/www.wangonc.com\/index.php\/2022\/01\/15\/unicorn\/","title":{"rendered":"unicorn"},"content":{"rendered":"<h1>unicorn<\/h1>\n<h2>\u76f8\u5173\u94fe\u63a5<\/h2>\n<p><strong>unicorn\u5b98\u7f51<\/strong><\/p>\n<p><a href=\"https:\/\/www.unicorn-engine.org\/\">Unicorn<\/a><\/p>\n<p><strong>\u5b98\u65b9\u6559\u7a0b<\/strong><\/p>\n<p><a href=\"https:\/\/www.unicorn-engine.org\/docs\/tutorial.html\">Programming with C &amp; Python languages<\/a><\/p>\n<p><strong>api\u6587\u6863<\/strong><\/p>\n<p><a href=\"https:\/\/github.com\/kabeor\/Unicorn-Engine-Documentation\/blob\/master\/Unicorn-Engine%20Documentation.md\">Unicorn-Engine-Documentation\/Unicorn-Engine Documentation.md at master \u00b7 kabeor\/Unicorn-Engine-Documentation<\/a><\/p>\n<h2>\u4f7f\u7528\u65b9\u6cd5<\/h2>\n<p>\u5728python\u4e0b\u7684\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff08\u4ee5arm\u4e3a\u4f8b\uff09<\/p>\n<pre><code class=\"language-python\">from unicorn import *\nfrom unicorn.arm_const import *\n\ncode =b&#039;\\x01\\x10\\xa0\\xe3\\x02 \\xa0\\xe3\\x010B\\xe0&#039;\n# mov r1, #1\n# mov r2, #2\n# sub r3, r2, r1\nUC = Uc(UC_ARCH_ARM, UC_MODE_LITTLE_ENDIAN)\nADDRESS = 0x1000000\n\nUC.mem_map(ADDRESS, 2 * 1024 * 1024)\nUC.mem_write(ADDRESS, code)\n\nUC.emu_start(ADDRESS, ADDRESS + len(code))\nr1 = UC.reg_read(UC_ARM_REG_R1)\nr2 = UC.reg_read(UC_ARM_REG_R2)\nr3 = UC.reg_read(UC_ARM_REG_R3)\n\nprint(r1,r2,r3)\n\n# \u6267\u884c\u8f93\u51fa\u4e3a\n# 1 2 1<\/code><\/pre>\n<p>\u7531\u4e8e\u8be5\u811a\u672c\u4e2d\u4f7f\u7528\u4e86\u4e00\u4e9b\u5bc4\u5b58\u5668\u5e38\u91cf\uff0c\u6240\u4ee5\u9664\u4e86\u5bfc\u5165<code>unicorn<\/code>,\u8be5\u811a\u672c\u8fd8\u5bfc\u5165\u4e86<code>unicorn.arm_const<\/code><\/p>\n<p><code>UC = Uc(UC_ARCH_ARM, UC_MODE_LITTLE_ENDIAN)<\/code> \u4f5c\u7528\u4e3a\u521d\u59cb\u5316\u4e00\u4e2aUnicorn\u7c7b\uff0c\u5176\u53c2\u6570\u4e3a<strong>\u786c\u4ef6\u67b6\u6784\u548c\u6a21\u5f0f<\/strong><\/p>\n<p><code>UC.mem_map(ADDRESS, 2 * 1024 * 1024)<\/code> \u610f\u4e3a\u5728\u7ed9\u5b9a\u5730\u5740\u5904\u5f00\u8f9f\u4e86\u4e00\u57572Mb\uff082<em>1024<\/em>1024 b\uff09\u5927\u5c0f\u7684\u5185\u5b58<\/p>\n<p><code>UC.mem_write(ADDRESS, code)<\/code> \u7684\u4f5c\u7528\u662f\u5728\u7ed9\u5b9a\u7684\u5730\u5740\u5904\u5c06\u673a\u5668\u7801\u5199\u5165\uff0c\u65b9\u4fbf\u7528\u4e8e\u6a21\u62df\u6267\u884c\u3002\u53ef\u4ee5\u4f7f\u7528keystone\u7528\u6c47\u7f16\u6307\u4ee4\u751f\u6210\u673a\u5668\u7801\u6216\u4f7f\u7528capstone\u89e3\u6790\u673a\u5668\u7801<\/p>\n<p><code>UC.emu_start(ADDRESS, ADDRESS + len(code))<\/code> \u7684\u4f5c\u7528\u662f\u6267\u884c\u4ece<code>ADDRESS<\/code> \u5230<code>ADDRESS + len(code)<\/code> \u8303\u56f4\u5185\u7684\u6307\u4ee4\u3002\u8be5\u51fd\u6570\u539f\u578b\u4e3a<code>emu_start(begin, until, timeout=0, count=0)<\/code> \uff0c\u5176\u53c2\u6570\u542b\u4e49\u5206\u522b\u5982\u4e0b<\/p>\n<p><strong>begin<\/strong>\uff1a\u6a21\u62df\u6267\u884c\u5f00\u59cb\u7684\u5730\u5740<\/p>\n<p><strong>until<\/strong>\uff1a\u6a21\u62df\u6267\u884c\u7ed3\u675f\u7684\u5730\u5740<\/p>\n<p><strong>timeout<\/strong>\uff1a\u6a21\u62df\u6267\u884c\u7684\u65f6\u95f4\uff0c\u5982\u679c\u4e3a0\u5219\u4e0d\u9650\u5236\u65f6\u95f4<\/p>\n<p><strong>count<\/strong>\uff1a\u6a21\u62df\u6267\u884c\u7684\u547d\u4ee4\u6570\uff0c\u5982\u679c\u4e3a0\u5219\u4e0d\u9650\u5236\u547d\u4ee4<\/p>\n<p><code>r1 = UC.reg_read(UC_ARM_REG_R1)<\/code> \u7684\u542b\u4e49\u4e3a\u8bfb\u53d6\u4e86r1\u5bc4\u5b58\u5668\u7684\u503c\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\uff0c\u5176\u53c2\u6570\u4e3a\u5bc4\u5b58\u5668\u5e38\u91cf\uff0c\u4f4d\u4e8eunicorn.arm_const\uff0c\u6bcf\u4e00\u4e2a\u5bc4\u5b58\u5668\u90fd\u62e5\u6709\u4e00\u4e2a\u5bc4\u5b58\u5668\u5e38\u91cf\uff0c\u7528\u4e8e\u65b9\u4fbf\u7d22\u5f15\u76f8\u5e94\u7684\u5bc4\u5b58\u5668<\/p>\n<p>\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>hook_add<\/code>\u51fd\u6570\u7ed9\u6267\u884c\u7684\u4ee3\u7801\u6dfb\u52a0\u4e00\u5b9a\u7684hook\u4e8b\u4ef6<\/p>\n<p>\u8be5\u51fd\u6570\u539f\u578b\u4e3a<strong>hook_add(htype, callback, user_data=None, begin=1, end=0, arg1=0 )<\/strong><\/p>\n<p><strong>htype<\/strong>\uff1ahook\u7c7b\u578b\uff0c\u6240\u6709\u7c7b\u578b\u89c1\u4e0b\u6587<\/p>\n<p><strong>callback<\/strong>\uff1a\u56de\u8c03\u51fd\u6570\uff0chook\u5230\u540e\u6267\u884c\u7684\u51fd\u6570<\/p>\n<p><strong>user_data<\/strong>\uff1a\u7528\u6237\u6570\u636e\uff0chook\u5230\u65f6\u53ef\u4ee5\u5c06\u6b64\u6570\u636e\u4f20\u9012\u7ed9\u56de\u8c03\u51fd\u6570<\/p>\n<p><strong>begin<\/strong>\uff1a\u56de\u8c03\u751f\u6548\u533a\u57df\u7684\u8d77\u59cb\u5730\u5740(\u5305\u62ec)<\/p>\n<p><strong>end<\/strong> \uff1a\u56de\u8c03\u751f\u6548\u533a\u57df\u7684\u7ed3\u675f\u5730\u5740(\u5305\u62ec)\uff0c\u82e5begin&gt;end\uff0c\u5219\u4f1ahook\u6240\u6709\u5185\u5bb9<\/p>\n<p><strong>arg1<\/strong>\uff1a\u53c2\u6570\uff0c\u53d6\u51b3\u4e8ehtype<\/p>\n<p>\u5176\u56de\u8c03\u51fd\u6570\u6a21\u677f\u4e3a<\/p>\n<pre><code class=\"language-python\">def hook_block(uc, address, size, user_data):\n    # unicorn\u7c7b\n    # \u5f53\u524dhook\u5730\u5740\n    # \u5f53\u524dhook\u5927\u5c0f\n    # hook_add\u4e2d\u7ed9\u5b9a\u7684user_data\n    pass<\/code><\/pre>\n<p>\u8c03\u7528\u793a\u4f8b\u5982\u4e0b<\/p>\n<pre><code class=\"language-python\">from capstone import *\nfrom unicorn import *\nfrom unicorn.arm_const import *\n\n# callback for tracing basic blocks\ndef hook_block(uc, address, size, user_data):\n    print(&gt;&gt;&gt; Tracing basic block at 0x%x, block size = 0x%x %(address, size))\n\n# callback for tracing instructions\ndef hook_code(uc, address, size, user_data):\n    print(&gt;&gt;&gt; Tracing instruction at 0x%x, instruction size = 0x%x %(address, size))\n\ncode =b&#039;\\x01\\x10\\xa0\\xe3\\x02 \\xa0\\xe3\\x010B\\xe0&#039;\nCS = Cs(CS_ARCH_ARM, CS_MODE_LITTLE_ENDIAN)\nUC = Uc(UC_ARCH_ARM, UC_MODE_LITTLE_ENDIAN)\nADDRESS = 0x1000000\n\na=CS.disasm_lite(code,0x400000)\n\n# for (address, size, mnemonic, op_str) in Cs.disasm_lite(CS,code,0):\nfor (address, size, mnemonic, op_str) in a:\n    print(hex(address), mnemonic, op_str)\n\nUC.mem_map(ADDRESS, 2 * 1024 * 1024)\nUC.mem_write(ADDRESS, code)\n\n# tracing all basic blocks with customized callback\nUC.hook_add(UC_HOOK_BLOCK, hook_block)\n\n# tracing one instruction at ADDRESS with customized callback\nUC.hook_add(UC_HOOK_CODE, hook_code, begin=ADDRESS, end=ADDRESS)\n\nUC.emu_start(ADDRESS, ADDRESS + len(code))\nr1 = UC.reg_read(UC_ARM_REG_R1)\nr2 = UC.reg_read(UC_ARM_REG_R2)\nr3 = UC.reg_read(UC_ARM_REG_R3)\n\nprint(r1,r2,r3)\n\n# \u6267\u884c\u8f93\u51fa\u4e3a\n# 0x400000 mov r1, #1\n# 0x400004 mov r2, #2\n# 0x400008 sub r3, r2, r1\n# &gt;&gt;&gt; Tracing basic block at 0x1000000, block size = 0xc\n# &gt;&gt;&gt; Tracing instruction at 0x1000000, instruction size = 0x4\n# 1 2 1<\/code><\/pre>\n<hr \/>\n<h2><strong>\u76f8\u5173\u6570\u636e\u7ed3\u6784<\/strong><\/h2>\n<ul>\n<li>\u652f\u6301\u7684\u6240\u6709\u67b6\u6784<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">typedef enum uc_arch {\n        UC_ARCH_ARM = 1,    \/\/ ARM \u67b6\u6784 (\u5305\u62ec Thumb, Thumb-2)\n        UC_ARCH_ARM64,      \/\/ ARM-64, \u4e5f\u79f0 AArch64\n        UC_ARCH_MIPS,       \/\/ Mips \u67b6\u6784\n        UC_ARCH_X86,        \/\/ X86 \u67b6\u6784 (\u5305\u62ec x86 &amp; x86-64)\n        UC_ARCH_PPC,        \/\/ PowerPC \u67b6\u6784 (\u6682\u4e0d\u652f\u6301)\n        UC_ARCH_SPARC,      \/\/ Sparc \u67b6\u6784\n        UC_ARCH_M68K,       \/\/ M68K \u67b6\u6784\n        UC_ARCH_MAX,\n} uc_arch;<\/code><\/pre>\n<ul>\n<li>\u652f\u6301\u7684\u6240\u6709\u6a21\u5f0f<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">typedef enum uc_mode {\n        UC_MODE_LITTLE_ENDIAN = 0,    \/\/ \u5c0f\u7aef\u5e8f\u6a21\u5f0f (\u9ed8\u8ba4)\n        UC_MODE_BIG_ENDIAN = 1 &lt;&lt; 30, \/\/ \u5927\u7aef\u5e8f\u6a21\u5f0f\n\n        \/\/ arm \/ arm64\n        UC_MODE_ARM = 0,              \/\/ ARM \u6a21\u5f0f\n        UC_MODE_THUMB = 1 &lt;&lt; 4,       \/\/ THUMB \u6a21\u5f0f (\u5305\u62ec Thumb-2)\n        UC_MODE_MCLASS = 1 &lt;&lt; 5,      \/\/ ARM&#039;s Cortex-M \u7cfb\u5217 (\u6682\u4e0d\u652f\u6301)\n        UC_MODE_V8 = 1 &lt;&lt; 6,          \/\/ ARMv8 A32 encodings for ARM (\u6682\u4e0d\u652f\u6301)\n\n        \/\/ arm (32bit) cpu \u7c7b\u578b\n        UC_MODE_ARM926 = 1 &lt;&lt; 7,      \/\/ ARM926 CPU \u7c7b\u578b\n        UC_MODE_ARM946 = 1 &lt;&lt; 8,      \/\/ ARM946 CPU \u7c7b\u578b\n        UC_MODE_ARM1176 = 1 &lt;&lt; 9,     \/\/ ARM1176 CPU \u7c7b\u578b\n\n        \/\/ mips\n        UC_MODE_MICRO = 1 &lt;&lt; 4,       \/\/ MicroMips \u6a21\u5f0f (\u6682\u4e0d\u652f\u6301)\n        UC_MODE_MIPS3 = 1 &lt;&lt; 5,       \/\/ Mips III ISA (\u6682\u4e0d\u652f\u6301)\n        UC_MODE_MIPS32R6 = 1 &lt;&lt; 6,    \/\/ Mips32r6 ISA (\u6682\u4e0d\u652f\u6301)\n        UC_MODE_MIPS32 = 1 &lt;&lt; 2,      \/\/ Mips32 ISA\n        UC_MODE_MIPS64 = 1 &lt;&lt; 3,      \/\/ Mips64 ISA\n\n        \/\/ x86 \/ x64\n        UC_MODE_16 = 1 &lt;&lt; 1,          \/\/ 16-bit \u6a21\u5f0f\n        UC_MODE_32 = 1 &lt;&lt; 2,          \/\/ 32-bit \u6a21\u5f0f\n        UC_MODE_64 = 1 &lt;&lt; 3,          \/\/ 64-bit \u6a21\u5f0f\n\n        \/\/ ppc\n        UC_MODE_PPC32 = 1 &lt;&lt; 2,       \/\/ 32-bit \u6a21\u5f0f (\u6682\u4e0d\u652f\u6301)\n        UC_MODE_PPC64 = 1 &lt;&lt; 3,       \/\/ 64-bit \u6a21\u5f0f (\u6682\u4e0d\u652f\u6301)\n        UC_MODE_QPX = 1 &lt;&lt; 4,         \/\/ Quad Processing eXtensions \u6a21\u5f0f (\u6682\u4e0d\u652f\u6301)\n\n        \/\/ sparc\n        UC_MODE_SPARC32 = 1 &lt;&lt; 2,     \/\/ 32-bit \u6a21\u5f0f\n        UC_MODE_SPARC64 = 1 &lt;&lt; 3,     \/\/ 64-bit \u6a21\u5f0f\n        UC_MODE_V9 = 1 &lt;&lt; 4,          \/\/ SparcV9 \u6a21\u5f0f (\u6682\u4e0d\u652f\u6301)\n\n        \/\/ m68k\n    } uc_mode;<\/code><\/pre>\n<ul>\n<li>\u6240\u6709\u5185\u5b58\u8bbf\u95ee\u7c7b\u578b<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">typedef enum uc_mem_type {\n        UC_MEM_READ = 16,   \/\/ \u5185\u5b58\u4ece..\u8bfb\u53d6\n        UC_MEM_WRITE,       \/\/ \u5185\u5b58\u5199\u5165\u5230..\n        UC_MEM_FETCH,       \/\/ \u5185\u5b58\u88ab\u83b7\u53d6\n        UC_MEM_READ_UNMAPPED,    \/\/ \u672a\u6620\u5c04\u5185\u5b58\u4ece..\u8bfb\u53d6\n        UC_MEM_WRITE_UNMAPPED,   \/\/ \u672a\u6620\u5c04\u5185\u5b58\u5199\u5165\u5230..\n        UC_MEM_FETCH_UNMAPPED,   \/\/ \u672a\u6620\u5c04\u5185\u5b58\u88ab\u83b7\u53d6\n        UC_MEM_WRITE_PROT,  \/\/ \u5185\u5b58\u5199\u4fdd\u62a4\uff0c\u4f46\u662f\u5df2\u6620\u5c04\n        UC_MEM_READ_PROT,   \/\/ \u5185\u5b58\u8bfb\u4fdd\u62a4\uff0c\u4f46\u662f\u5df2\u6620\u5c04\n        UC_MEM_FETCH_PROT,  \/\/ \u5185\u5b58\u4e0d\u53ef\u6267\u884c\uff0c\u4f46\u662f\u5df2\u6620\u5c04\n        UC_MEM_READ_AFTER,   \/\/ \u5185\u5b58\u4ece (\u6210\u529f\u8bbf\u95ee\u7684\u5730\u5740) \u8bfb\u5165\n    } uc_mem_type;<\/code><\/pre>\n<ul>\n<li>\u6240\u6709\u7684\u9519\u8bef\u7c7b\u578b<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">typedef enum uc_err {\n        UC_ERR_OK = 0,   \/\/ \u65e0\u9519\u8bef\n        UC_ERR_NOMEM,      \/\/ \u5185\u5b58\u4e0d\u8db3: uc_open(), uc_emulate()\n        UC_ERR_ARCH,     \/\/ \u4e0d\u652f\u6301\u7684\u67b6\u6784: uc_open()\n        UC_ERR_HANDLE,   \/\/ \u4e0d\u53ef\u7528\u53e5\u67c4\n        UC_ERR_MODE,     \/\/ \u4e0d\u53ef\u7528\/\u4e0d\u652f\u6301\u67b6\u6784: uc_open()\n        UC_ERR_VERSION,  \/\/ \u4e0d\u652f\u6301\u7248\u672c (\u4e2d\u95f4\u4ef6)\n        UC_ERR_READ_UNMAPPED, \/\/ \u7531\u4e8e\u5728\u672a\u6620\u5c04\u7684\u5185\u5b58\u4e0a\u8bfb\u53d6\u800c\u9000\u51fa\u6a21\u62df: uc_emu_start()\n        UC_ERR_WRITE_UNMAPPED, \/\/ \u7531\u4e8e\u5728\u672a\u6620\u5c04\u7684\u5185\u5b58\u4e0a\u5199\u5165\u800c\u9000\u51fa\u6a21\u62df: uc_emu_start()\n        UC_ERR_FETCH_UNMAPPED, \/\/ \u7531\u4e8e\u5728\u672a\u6620\u5c04\u7684\u5185\u5b58\u4e2d\u83b7\u53d6\u6570\u636e\u800c\u9000\u51fa\u6a21\u62df: uc_emu_start()\n        UC_ERR_HOOK,    \/\/ \u65e0\u6548\u7684hook\u7c7b\u578b: uc_hook_add()\n        UC_ERR_INSN_INVALID, \/\/ \u7531\u4e8e\u6307\u4ee4\u65e0\u6548\u800c\u9000\u51fa\u6a21\u62df: uc_emu_start()\n        UC_ERR_MAP, \/\/ \u65e0\u6548\u7684\u5185\u5b58\u6620\u5c04: uc_mem_map()\n        UC_ERR_WRITE_PROT, \/\/ \u7531\u4e8eUC_MEM_WRITE_PROT\u51b2\u7a81\u800c\u505c\u6b62\u6a21\u62df: uc_emu_start()\n        UC_ERR_READ_PROT, \/\/ \u7531\u4e8eUC_MEM_READ_PROT\u51b2\u7a81\u800c\u505c\u6b62\u6a21\u62df: uc_emu_start()\n        UC_ERR_FETCH_PROT, \/\/ \u7531\u4e8eUC_MEM_FETCH_PROT\u51b2\u7a81\u800c\u505c\u6b62\u6a21\u62df: uc_emu_start()\n        UC_ERR_ARG,     \/\/ \u63d0\u4f9b\u7ed9uc_xxx\u51fd\u6570\u7684\u65e0\u6548\u53c2\u6570\n        UC_ERR_READ_UNALIGNED,  \/\/ \u672a\u5bf9\u9f50\u8bfb\u53d6\n        UC_ERR_WRITE_UNALIGNED,  \/\/ \u672a\u5bf9\u9f50\u5199\u5165\n        UC_ERR_FETCH_UNALIGNED,  \/\/ \u672a\u5bf9\u9f50\u7684\u63d0\u53d6\n        UC_ERR_HOOK_EXIST,  \/\/ \u6b64\u4e8b\u4ef6\u7684\u94a9\u5b50\u5df2\u7ecf\u5b58\u5728\n        UC_ERR_RESOURCE,    \/\/ \u8d44\u6e90\u4e0d\u8db3: uc_emu_start()\n        UC_ERR_EXCEPTION, \/\/ \u672a\u5904\u7406\u7684CPU\u5f02\u5e38\n        UC_ERR_TIMEOUT \/\/ \u6a21\u62df\u8d85\u65f6\n    } uc_err;<\/code><\/pre>\n<ul>\n<li>\u6240\u6709\u7684hook\u7c7b\u578b<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">typedef enum uc_hook_type {\n        \/\/ Hook \u6240\u6709\u4e2d\u65ad\/syscall \u4e8b\u4ef6\n        UC_HOOK_INTR = 1 &lt;&lt; 0,\n        \/\/ Hook \u4e00\u6761\u7279\u5b9a\u7684\u6307\u4ee4 - \u53ea\u652f\u6301\u975e\u5e38\u5c0f\u7684\u6307\u4ee4\u5b50\u96c6\n        UC_HOOK_INSN = 1 &lt;&lt; 1,\n        \/\/ Hook \u4e00\u6bb5\u4ee3\u7801\n        UC_HOOK_CODE = 1 &lt;&lt; 2,\n        \/\/ Hook \u57fa\u672c\u5757\n        UC_HOOK_BLOCK = 1 &lt;&lt; 3,\n        \/\/ \u7528\u4e8e\u5728\u672a\u6620\u5c04\u7684\u5185\u5b58\u4e0a\u8bfb\u53d6\u5185\u5b58\u7684Hook\n        UC_HOOK_MEM_READ_UNMAPPED = 1 &lt;&lt; 4,\n        \/\/ Hook \u65e0\u6548\u7684\u5185\u5b58\u5199\u4e8b\u4ef6\n        UC_HOOK_MEM_WRITE_UNMAPPED = 1 &lt;&lt; 5,\n        \/\/ Hook \u6267\u884c\u4e8b\u4ef6\u7684\u65e0\u6548\u5185\u5b58\n        UC_HOOK_MEM_FETCH_UNMAPPED = 1 &lt;&lt; 6,\n        \/\/ Hook \u8bfb\u4fdd\u62a4\u7684\u5185\u5b58\n        UC_HOOK_MEM_READ_PROT = 1 &lt;&lt; 7,\n        \/\/ Hook \u5199\u4fdd\u62a4\u7684\u5185\u5b58\n        UC_HOOK_MEM_WRITE_PROT = 1 &lt;&lt; 8,\n        \/\/ Hook \u4e0d\u53ef\u6267\u884c\u5185\u5b58\u4e0a\u7684\u5185\u5b58\n        UC_HOOK_MEM_FETCH_PROT = 1 &lt;&lt; 9,\n        \/\/ Hook \u5185\u5b58\u8bfb\u53d6\u4e8b\u4ef6\n        UC_HOOK_MEM_READ = 1 &lt;&lt; 10,\n        \/\/ Hook \u5185\u5b58\u5199\u5165\u4e8b\u4ef6\n        UC_HOOK_MEM_WRITE = 1 &lt;&lt; 11,\n        \/\/ Hook \u5185\u5b58\u83b7\u53d6\u6267\u884c\u4e8b\u4ef6\n        UC_HOOK_MEM_FETCH = 1 &lt;&lt; 12,\n        \/\/ Hook \u5185\u5b58\u8bfb\u53d6\u4e8b\u4ef6\uff0c\u53ea\u5141\u8bb8\u80fd\u6210\u529f\u8bbf\u95ee\u7684\u5730\u5740\n        \/\/ \u6210\u529f\u8bfb\u53d6\u540e\u5c06\u89e6\u53d1\u56de\u8c03\n        UC_HOOK_MEM_READ_AFTER = 1 &lt;&lt; 13,\n        \/\/ Hook \u65e0\u6548\u6307\u4ee4\u5f02\u5e38\n        UC_HOOK_INSN_INVALID = 1 &lt;&lt; 14,\n    } uc_hook_type;<\/code><\/pre>\n<ul>\n<li>\u5b8f\u5b9a\u4e49Hook\u7c7b\u578b\uff08\u7531\u57fa\u672chook\u7c7b\u578b\u7ec4\u6210\uff09<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">    \/\/ Hook \u6240\u6709\u672a\u6620\u5c04\u5185\u5b58\u8bbf\u95ee\u7684\u4e8b\u4ef6\n    #define UC_HOOK_MEM_UNMAPPED (UC_HOOK_MEM_READ_UNMAPPED + UC_HOOK_MEM_WRITE_UNMAPPED + UC_HOOK_MEM_FETCH_UNMAPPED)\n    \/\/ Hook \u6240\u6709\u5bf9\u53d7\u4fdd\u62a4\u5185\u5b58\u7684\u975e\u6cd5\u8bbf\u95ee\u4e8b\u4ef6\n    #define UC_HOOK_MEM_PROT (UC_HOOK_MEM_READ_PROT + UC_HOOK_MEM_WRITE_PROT + UC_HOOK_MEM_FETCH_PROT)\n    \/\/ Hook \u6240\u6709\u975e\u6cd5\u8bfb\u53d6\u5b58\u50a8\u5668\u7684\u4e8b\u4ef6\n    #define UC_HOOK_MEM_READ_INVALID (UC_HOOK_MEM_READ_PROT + UC_HOOK_MEM_READ_UNMAPPED)\n    \/\/ Hook \u6240\u6709\u975e\u6cd5\u5199\u5165\u5b58\u50a8\u5668\u7684\u4e8b\u4ef6\n    #define UC_HOOK_MEM_WRITE_INVALID (UC_HOOK_MEM_WRITE_PROT + UC_HOOK_MEM_WRITE_UNMAPPED)\n    \/\/ Hook \u6240\u6709\u975e\u6cd5\u83b7\u53d6\u5185\u5b58\u7684\u4e8b\u4ef6\n    #define UC_HOOK_MEM_FETCH_INVALID (UC_HOOK_MEM_FETCH_PROT + UC_HOOK_MEM_FETCH_UNMAPPED)\n    \/\/ Hook \u6240\u6709\u975e\u6cd5\u7684\u5185\u5b58\u8bbf\u95ee\u4e8b\u4ef6\n    #define UC_HOOK_MEM_INVALID (UC_HOOK_MEM_UNMAPPED + UC_HOOK_MEM_PROT)\n    \/\/ Hook \u6240\u6709\u6709\u6548\u5185\u5b58\u8bbf\u95ee\u7684\u4e8b\u4ef6\n    \/\/ \u6ce8\u610f: UC_HOOK_MEM_READ \u5728 UC_HOOK_MEM_READ_PROT \u548c UC_HOOK_MEM_READ_UNMAPPED \u4e4b\u524d\u89e6\u53d1 ,\n    \/\/       \u56e0\u6b64\u8fd9\u4e2aHook\u53ef\u80fd\u4f1a\u89e6\u53d1\u4e00\u4e9b\u65e0\u6548\u7684\u8bfb\u53d6\u3002\n    #define UC_HOOK_MEM_VALID (UC_HOOK_MEM_READ + UC_HOOK_MEM_WRITE + UC_HOOK_MEM_FETCH)<\/code><\/pre>\n<ul>\n<li>\u6620\u5c04\u533a\u57df\u7684\u6743\u9650<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">    typedef enum uc_prot {\n       UC_PROT_NONE = 0,    \/\/\u65e0\n       UC_PROT_READ = 1,    \/\/\u8bfb\u53d6\n       UC_PROT_WRITE = 2,   \/\/\u5199\u5165\n       UC_PROT_EXEC = 4,    \/\/\u53ef\u6267\u884c\n       UC_PROT_ALL = 7,     \/\/\u6240\u6709\u6743\u9650\n    } uc_prot;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>unicorn \u76f8\u5173\u94fe\u63a5 unicorn\u5b98\u7f51 Unicorn \u5b98\u65b9\u6559\u7a0b Programming with C  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6392,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,2,8],"tags":[25],"series":[],"class_list":["post-6321","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-so-reverse-engineering","category-study-notes","category-android-reverse-engineering","tag-unicorn"],"_links":{"self":[{"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/posts\/6321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/comments?post=6321"}],"version-history":[{"count":4,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/posts\/6321\/revisions"}],"predecessor-version":[{"id":7370,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/posts\/6321\/revisions\/7370"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/media\/6392"}],"wp:attachment":[{"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/media?parent=6321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/categories?post=6321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/tags?post=6321"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.wangonc.com\/index.php\/wp-json\/wp\/v2\/series?post=6321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}