如何区分文件中的代码和数据字节

2024-05-17 00:51:04 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上,我试图理解如何区分一堆字节,它们是代码还是数据

假设我有以下已分解的字节:

b'.data\x00\x00\x00'
b"\xb9\x08\x00\x00\x00\xff\xd0\xb8\xff\xff\xff\xff\xe9L\xff\xff\xff\x0f\x1f\x80\x00\x00\x00\x001\xd2\xb9\x0b\x00\x00\x00\xe8\xf4\x06\x00\x00H\x83\xf8\x01tOH\x85\xc0t\x88\xb9\x0b
\x00\x00\x00\xff\xd0\xb8\xff\xff\xff\xff\xe9\x1d\xff\xff\xff\xba\x01\x00\x00\x00\xb9\x04\x00\x00\x00\xe8\xc9\x06\x00\x00\x83\xc8\xff\xe9\x06\xff\xff\xfff\x0f\x1f\x84\x00\x00\x00
\x00\x00\xba\x01\x00\x00\x00\xb9\x08\x00\x00\x00\xe8\xa9\x06\x00\x00\xb8\xff\xff\xff\xff\xe9\xe4\xfe\xff\xff\xba\x01\x00\x00\x00\xb9\x0b\x00\x00\x00\xe8\x90\x06\x00\x00\x83\xc8\
xff\xe9\xcd\xfe\xff\xffATWVSH\x83\xec(H\x8d\r`T\x00\x00\xff\x15.]\x00\x00H\x8b\x1d3T\x00\x00H\x85\xdbt2H\x8b=\xab]\x00\x00H\x8b54]\x00\x00\x8b\x0b\xff\xd7I\x89\xc4\xff\xd6\x85\x
c0u\x0eM\x85\xe4t\tH\x8bC\x08L\x89\xe1\xff\xd0H\x8b[\x10H\x85\xdbu\xdcH\x8d\r\x15T\x00\x00H\x83\xc4([^_A\\H\xff%!]\x00\x00\x0f\x1fD\x00\x00WVSH\x83\xec \x8b\x05\xdbS\x00\x00\x89
\xcfH\x89\xd6\x85\xc0u\nH\x83\xc4 [^_\xc3f\x90\xba\x18\x00\x00\x00\xb9\x01\x00\x00\x00\xe8!\x06\x00\x00H\x89\xc3H\x85\xc0t    <\x898H\x8d\r\xc0S\x00\x00H\x89p\x08\xff\x15\x8a\\\x00\
x00H\x8b\x05\x8fS\x00\x00H\x8d\r\xa8S\x00\x00H\x89\x1d\x81S\x00\x00H\x89C\x10\xff\x15\xb3\\\x00\x001\xc0H\x83\xc4 [^_\xc3\x83\xc8\xff\xeb\x9e\x0f\x1f\x84\x00\x00\x00\x00\x00SH\x
83\xec \x8b\x05]S\x00\x00\x89\xcb\x85\xc0u\x0f1\xc0H\x83\xc4 [\xc3\x0f\x1f\x80\x00\x00\x00\x00H\x8d\rYS\x00\x00\xff\x15'\\\x00\x00H\x8b\r,S\x00\x00H\x85\xc9t*1\xd2\xeb\x0e\x0f\x
1f\x00H\x89\xcaH\x85\xc0t\x1bH\x89\xc1\x8b\x019\xd8H\x8bA\x10u\xebH\x85\xd2t&H\x89B\x10\xe8U\x05\x00\x00H\x8d\r\x16S\x00\x00\xff\x15,\\\x00\x001\xc0H\x83\xc4 [\xc3\x0f\x1f\x84\x
00\x00\x00\x00\x00"
<CsInsn 0x200 [b908000000]: mov ecx, 8>
<CsInsn 0x205 [ffd0]: call rax>
<CsInsn 0x207 [b8ffffffff]: mov eax, 0xffffffff>
<CsInsn 0x20c [e94cffffff]: jmp 0x15d>
<CsInsn 0x211 [0f1f8000000000]: nop dword ptr [rax]>
<CsInsn 0x218 [31d2]: xor edx, edx>
<CsInsn 0x21a [b90b000000]: mov ecx, 0xb>
<CsInsn 0x21f [e8f4060000]: call 0x918>
<CsInsn 0x224 [4883f801]: cmp rax, 1>
<CsInsn 0x228 [744f]: je 0x279>
<CsInsn 0x22a [4885c0]: test rax, rax>
<CsInsn 0x22d [7488]: je 0x1b7>
<CsInsn 0x22f [b90b000000]: mov ecx, 0xb>
<CsInsn 0x234 [ffd0]: call rax>
<CsInsn 0x236 [b8ffffffff]: mov eax, 0xffffffff>
<CsInsn 0x23b [e91dffffff]: jmp 0x15d>
<CsInsn 0x240 [ba01000000]: mov edx, 1>
<CsInsn 0x245 [b904000000]: mov ecx, 4>
<CsInsn 0x24a [e8c9060000]: call 0x918>
<CsInsn 0x24f [83c8ff]: or eax, 0xffffffff>
<CsInsn 0x252 [e906ffffff]: jmp 0x15d>
<CsInsn 0x257 [660f1f840000000000]: nop word ptr [rax + rax]>
<CsInsn 0x260 [ba01000000]: mov edx, 1>
<CsInsn 0x265 [b908000000]: mov ecx, 8>
<CsInsn 0x26a [e8a9060000]: call 0x918>
<CsInsn 0x26f [b8ffffffff]: mov eax, 0xffffffff>
<CsInsn 0x274 [e9e4feffff]: jmp 0x15d>
<CsInsn 0x279 [ba01000000]: mov edx, 1>
<CsInsn 0x27e [b90b000000]: mov ecx, 0xb>
<CsInsn 0x283 [e890060000]: call 0x918>
<CsInsn 0x288 [83c8ff]: or eax, 0xffffffff>
<CsInsn 0x28b [e9cdfeffff]: jmp 0x15d>
<CsInsn 0x290 [4154]: push r12>
<CsInsn 0x292 [57]: push rdi>
<CsInsn 0x293 [56]: push rsi>
<CsInsn 0x294 [53]: push rbx>
<CsInsn 0x295 [4883ec28]: sub rsp, 0x28>
<CsInsn 0x299 [488d0d60540000]: lea rcx, [rip + 0x5460]>
<CsInsn 0x2a0 [ff152e5d0000]: call qword ptr [rip + 0x5d2e]>
<CsInsn 0x2a6 [488b1d33540000]: mov rbx, qword ptr [rip + 0x5433]>
<CsInsn 0x2ad [4885db]: test rbx, rbx>
<CsInsn 0x2b0 [7432]: je 0x2e4>
<CsInsn 0x2b2 [488b3dab5d0000]: mov rdi, qword ptr [rip + 0x5dab]>
<CsInsn 0x2b9 [488b35345d0000]: mov rsi, qword ptr [rip + 0x5d34]>
<CsInsn 0x2c0 [8b0b]: mov ecx, dword ptr [rbx]>
<CsInsn 0x2c2 [ffd7]: call rdi>
<CsInsn 0x2c4 [4989c4]: mov r12, rax>
<CsInsn 0x2c7 [ffd6]: call rsi>
<CsInsn 0x2c9 [85c0]: test eax, eax>
<CsInsn 0x2cb [750e]: jne 0x2db>
<CsInsn 0x2cd [4d85e4]: test r12, r12>
<CsInsn 0x2d0 [7409]: je 0x2db>
<CsInsn 0x2d2 [488b4308]: mov rax, qword ptr [rbx + 8]>
<CsInsn 0x2d6 [4c89e1]: mov rcx, r12>
<CsInsn 0x2d9 [ffd0]: call rax>
<CsInsn 0x2db [488b5b10]: mov rbx, qword ptr [rbx + 0x10]>
<CsInsn 0x2df [4885db]: test rbx, rbx>
<CsInsn 0x2e2 [75dc]: jne 0x2c0>
<CsInsn 0x2e4 [488d0d15540000]: lea rcx, [rip + 0x5415]>
<CsInsn 0x2eb [4883c428]: add rsp, 0x28>
<CsInsn 0x2ef [5b]: pop rbx>
<CsInsn 0x2f0 [5e]: pop rsi>
<CsInsn 0x2f1 [5f]: pop rdi>
<CsInsn 0x2f2 [415c]: pop r12>
<CsInsn 0x2f4 [48ff25215d0000]: jmp qword ptr [rip + 0x5d21]>
<CsInsn 0x2fb [0f1f440000]: nop dword ptr [rax + rax]>
<CsInsn 0x300 [57]: push rdi>
<CsInsn 0x301 [56]: push rsi>
<CsInsn 0x302 [53]: push rbx>
<CsInsn 0x303 [4883ec20]: sub rsp, 0x20>
<CsInsn 0x307 [8b05db530000]: mov eax, dword ptr [rip + 0x53db]>
<CsInsn 0x30d [89cf]: mov edi, ecx>
<CsInsn 0x30f [4889d6]: mov rsi, rdx>
<CsInsn 0x312 [85c0]: test eax, eax>
<CsInsn 0x314 [750a]: jne 0x320>
<CsInsn 0x316 [4883c420]: add rsp, 0x20>
<CsInsn 0x31a [5b]: pop rbx>
<CsInsn 0x31b [5e]: pop rsi>
<CsInsn 0x31c [5f]: pop rdi>
<CsInsn 0x31d [c3]: ret >
<CsInsn 0x31e [6690]: nop >
<CsInsn 0x320 [ba18000000]: mov edx, 0x18>
<CsInsn 0x325 [b901000000]: mov ecx, 1>
<CsInsn 0x32a [e821060000]: call 0x950>
<CsInsn 0x32f [4889c3]: mov rbx, rax>
<CsInsn 0x332 [4885c0]: test rax, rax>
<CsInsn 0x335 [743c]: je 0x373>
<CsInsn 0x337 [8938]: mov dword ptr [rax], edi>
<CsInsn 0x339 [488d0dc0530000]: lea rcx, [rip + 0x53c0]>
<CsInsn 0x340 [48897008]: mov qword ptr [rax + 8], rsi>
<CsInsn 0x344 [ff158a5c0000]: call qword ptr [rip + 0x5c8a]>
<CsInsn 0x34a [488b058f530000]: mov rax, qword ptr [rip + 0x538f]>
<CsInsn 0x351 [488d0da8530000]: lea rcx, [rip + 0x53a8]>
<CsInsn 0x358 [48891d81530000]: mov qword ptr [rip + 0x5381], rbx>
<CsInsn 0x35f [48894310]: mov qword ptr [rbx + 0x10], rax>
<CsInsn 0x363 [ff15b35c0000]: call qword ptr [rip + 0x5cb3]>
<CsInsn 0x369 [31c0]: xor eax, eax>
<CsInsn 0x36b [4883c420]: add rsp, 0x20>
<CsInsn 0x36f [5b]: pop rbx>
<CsInsn 0x370 [5e]: pop rsi>
<CsInsn 0x371 [5f]: pop rdi>
<CsInsn 0x372 [c3]: ret >
<CsInsn 0x373 [83c8ff]: or eax, 0xffffffff>
<CsInsn 0x376 [eb9e]: jmp 0x316>
<CsInsn 0x378 [0f1f840000000000]: nop dword ptr [rax + rax]>
<CsInsn 0x380 [53]: push rbx>
<CsInsn 0x381 [4883ec20]: sub rsp, 0x20>
<CsInsn 0x385 [8b055d530000]: mov eax, dword ptr [rip + 0x535d]>
<CsInsn 0x38b [89cb]: mov ebx, ecx>
<CsInsn 0x38d [85c0]: test eax, eax>
<CsInsn 0x38f [750f]: jne 0x3a0>
<CsInsn 0x391 [31c0]: xor eax, eax>
<CsInsn 0x393 [4883c420]: add rsp, 0x20>
<CsInsn 0x397 [5b]: pop rbx>
<CsInsn 0x398 [c3]: ret >
<CsInsn 0x399 [0f1f8000000000]: nop dword ptr [rax]>
<CsInsn 0x3a0 [488d0d59530000]: lea rcx, [rip + 0x5359]>
<CsInsn 0x3a7 [ff15275c0000]: call qword ptr [rip + 0x5c27]>
<CsInsn 0x3ad [488b0d2c530000]: mov rcx, qword ptr [rip + 0x532c]>
<CsInsn 0x3b4 [4885c9]: test rcx, rcx>
<CsInsn 0x3b7 [742a]: je 0x3e3>
<CsInsn 0x3b9 [31d2]: xor edx, edx>
<CsInsn 0x3bb [eb0e]: jmp 0x3cb>
<CsInsn 0x3bd [0f1f00]: nop dword ptr [rax]>
<CsInsn 0x3c0 [4889ca]: mov rdx, rcx>
<CsInsn 0x3c3 [4885c0]: test rax, rax>
<CsInsn 0x3c6 [741b]: je 0x3e3>
<CsInsn 0x3c8 [4889c1]: mov rcx, rax>
<CsInsn 0x3cb [8b01]: mov eax, dword ptr [rcx]>
<CsInsn 0x3cd [39d8]: cmp eax, ebx>
<CsInsn 0x3cf [488b4110]: mov rax, qword ptr [rcx + 0x10]>
<CsInsn 0x3d3 [75eb]: jne 0x3c0>
<CsInsn 0x3d5 [4885d2]: test rdx, rdx>
<CsInsn 0x3d8 [7426]: je 0x400>
<CsInsn 0x3da [48894210]: mov qword ptr [rdx + 0x10], rax>
<CsInsn 0x3de [e855050000]: call 0x938>
<CsInsn 0x3e3 [488d0d16530000]: lea rcx, [rip + 0x5316]>
<CsInsn 0x3ea [ff152c5c0000]: call qword ptr [rip + 0x5c2c]>
<CsInsn 0x3f0 [31c0]: xor eax, eax>
<CsInsn 0x3f2 [4883c420]: add rsp, 0x20>
<CsInsn 0x3f6 [5b]: pop rbx>
<CsInsn 0x3f7 [c3]: ret >
<CsInsn 0x3f8 [0f1f840000000000]: nop dword ptr [rax + rax]>


b'.CRT\x00\x00\x00\x00'
b"\xba\xd8\x1d\x8fr\xdb\xc0\xd9t$\xf4X1\xc9\xb1V1P\x13\x03P\x13\x83\xe8$\x90z\x8e    <\x82\x85o  \xbc\xe3\x0c\x8a\x8d#j\xde\xbd\x93\xf8\xb21_\xac&\xc2-yHc\x9b_gt\xb0\x9c\xe6\xf6\xcb\x
f0\xc8\xc7\x03\x05\x08\x00y\xe4X\xd9\xf5[MnC`\xe6    <E\xe0\x1b\xf4d\xc1\x8d\x8f>\xc1,\\KH7\x81v\x02\xccq\x0c\x95\x04H\xed:ie\x1cB\xadA\xff1\xc7\xb2\x82A\x1c\xc9X\xc7\x87i*\x7fl\x88
\xff\xe6\xe7\x86\xb4m\xaf\x8aK\xa1\xdb\xb6\xc0D\x0c?\x92b\x88d@\n\x89\xc0'3\xc9\xab\x98\x91\x81A\xcc\xab\xcb\r!\x86\xf3\xcd-\x91\x80\xff\xf2\t\x0f\xb3{\x94\xc8\xc2l'\x06l\xfc\xd
9\xa7\x8c\xd4\x1d\xf3\xdcN\xb7|\xb7\x8e8\xa9-\x85\xaeX\xb1\x99O5\xb3\x99\x9e\x99:\x7f\xf0ql\xd0\xb1!\xcc\x80Y(\xc3\xffzS\x0eh\x10\xbc\xe6\xc0\x8d%\xa3\x9b,\xa9~\xe6o!\x8a\x16!\x
c2\xff\x04V\xb5\xff\xd4\xa7P\xff\xbe\xa3\xf2\xa8V\xae#\x9e\xf8Q\x06\x9d\xff\xae\xd7\x97t\x98M\x97\xe2\xe5\x81\x17\xf3\xb3\xcb\x17\x9bc\xa8D\xbeke\xf9\x13\xfe\x86\xab\xc0\xa9\xee
Q>\x9d\xb0\xaa\x15\x9d\xb7T\xeb\x8a\x1f    <\x13\x8b\x9f\xbcy\x0b\xf0\xd4v$\xff\x14v\xef\xa8    <\xfd~\x1a\xdd\x02\xab\xfaC\x02X'ty\x11\xd8u~;\xbdv~C\xc3K\xa8z\xb1\x8ah9\xca\xb9\xcdhA\x
c1Bj@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@u@\x00\x00\x00\x00\x00`p@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
00\xc0\x18@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa0@\x00\x00\x00\x00\x00\x08\xa0@\x00\x00\x00
\x00\x00\xfcu@\x00\x00\x00\x00\x00@\x90@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00"
<CsInsn 0x200 [bad81d8f72]: mov edx, 0x728f1dd8>
<CsInsn 0x205 [dbc0]: fcmovnb st(0), st(0)>
<CsInsn 0x207 [d97424f4]: fnstenv [rsp - 0xc]>
<CsInsn 0x20b [58]: pop rax>
<CsInsn 0x20c [31c9]: xor ecx, ecx>
<CsInsn 0x20e [b156]: mov cl, 0x56>
<CsInsn 0x210 [315013]: xor dword ptr [rax + 0x13], edx>
<CsInsn 0x213 [035013]: add edx, dword ptr [rax + 0x13]>
<CsInsn 0x216 [83e824]: sub eax, 0x24>
<CsInsn 0x219 [90]: nop >
<CsInsn 0x21a [7a8e]: jp 0x1aa>
<CsInsn 0x21c [3c82]: cmp al, 0x82>
<CsInsn 0x21e [856fbc]: test dword ptr [rdi - 0x44], ebp>
<CsInsn 0x221 [e30c]: jrcxz 0x22f>
<CsInsn 0x223 [8a8d236adebd]: mov cl, byte ptr [rbp - 0x422195dd]>
<CsInsn 0x229 [93]: xchg eax, ebx>
<CsInsn 0x22a [f8]: clc >
<CsInsn 0x22b [b231]: mov dl, 0x31>
<CsInsn 0x22d [5f]: pop rdi>
<CsInsn 0x22e [ac]: lodsb al, byte ptr [rsi]>
<CsInsn 0x22f [26c22d79]: ret 0x792d>
<CsInsn 0x233 [48639b5f6774b0]: movsxd rbx, dword ptr [rbx - 0x4f8b98a1]>
<CsInsn 0x23a [9c]: pushfq >
<CsInsn 0x23b [e6f6]: out 0xf6, al>
<CsInsn 0x23d [cb]: retf >

仅供参考,这两部分首先是运算码中的.data,然后对其进行反汇编,底部是.CRT运算码并进行反汇编

.crt部分包含代码(我在那里植入了一个外壳代码用于测试),但是.data带有二进制代码。我没有在那里手动存储任何东西

谁能告诉我如何分析代码字节和数据字节


Tags: callpopraxripmovx00xffx00h
1条回答
网友
1楼 · 发布于 2024-05-17 00:51:04

没有通用的方法来区分代码和数据。 在一个“好的”windows二进制文件中,答案可以在它的PE头中找到。二进制文件中的所有部分都有一个包含条目(IMAGE_SECTION_HEADER结构)的部分列表。每个节条目都有一个包含节标志的Characteristics字段。“代码”部分应该设置IMAGE_SCN_MEM_EXECUTE标志,这意味着它的内容是可执行的。没有此标志的节应包含不可执行数据

节标志很容易被伪造,因此它们不能提供任何保证。实际上,“好的”可执行部分也可以包含数据,例如跳转表或字符串

通常,反汇编程序从入口点开始反汇编—可执行函数和导出函数的入口点,以及 遵循代码流标记,将代码流到达的所有字节标记为代码,并将代码读取或写入的所有字节标记为数据

相关问题 更多 >