Abd*_*SSI 2 c x86 assembly nasm strcat
有人可以解释为什么我的 strcat 这样做吗?
我似乎无法找出为什么要重写源字符串的一部分。
输出是这样的: New String: HelloThis 应该在我的反斜杠 0 in str1h 0 in str1 之后
global strcat
extern strlen
Run Code Online (Sandbox Code Playgroud)
字符串:
push ebp
mov ebp, esp
push ecx
push esi
push edi
push ebx
push edx
xor edx, edx
xor edi, edi
xor ebx, ebx
xor esi, esi
xor ecx, ecx
mov edi, [ebp + 8]
mov esi, [ebp + 12]
push edi
call strlen
pop edi
mov ecx, eax
xor eax, eax
push esi
call strlen
pop esi
mov ebx, eax
xor eax, eax
cmp [edi + ecx], byte 0b
je PUT_LINE
jmp FINALIZE_END
Run Code Online (Sandbox Code Playgroud)
PUT_LINE:
cmp ebx, eax
je END
mov dl, [esi + eax]
mov [edi + ecx], dl
xor edx, edx
inc eax
inc ecx
jmp PUT_LINE
Run Code Online (Sandbox Code Playgroud)
结尾:
mov eax, [ebp + 8]
jmp FINALIZE_END
Run Code Online (Sandbox Code Playgroud)
FINALIZE_END:
pop edx
pop ebx
pop edi
pop esi
pop ecx
mov esp, ebp
pop ebp
ret
Run Code Online (Sandbox Code Playgroud)
~
~
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
char* str1;
char* str2;
str1 = strdup("Hello");
str2 = strdup("This shall be after my backslash 0 in str1");
printf("New String : %s\n", strcat(str1, str2));
return (0);
}
Run Code Online (Sandbox Code Playgroud)
~
strcat()将一个字符串中的字符追加到另一个字符串中。目标字符串被修改。所以strcat(str1, str2)修改str1为也包含str2.
由于没有分配足够的内存str1来包含来自两个字符串的字符,这会导致溢出。
| 归档时间: |
|
| 查看次数: |
4182 次 |
| 最近记录: |