谁知道strcpy的源代码? 我给他40分,谢了
解决方案 »
- 在vs2010下抄写了vc++深入详解的hook代码,其中让按F2关闭对话框,可在我这里为什么按f2没反应呢??
- 内存内容变化导致出错,求助!
- 请教??
- 问一个很菜的问题^_^很多的分呀
- IE里的OCX控件为什么收不到Back Space等消息?
- 如何打开一个有密码的数据库
- 从IHTMLDocument2到IWebBrowser2
- 关于网络传输速度的问题?指教阿
- ImmGetCompositionString 获取到数据后如何清空?
- 如何在初始何时,默认选中一个工具栏上的CheckButton
- 帮忙翻译一下msdn内有关于CArray<>数组的两个模板参数的说明
- 在多文档程序中如何修改状态栏?
* strcpy - Copy a %NUL terminated string
* @dest: Where to copy the string to
* @src: Where to copy the string from
*/
char * strcpy(char * dest,const char *src)
{
/*because dest addr will not disappear after this functions returning */
char *tmp = dest; while ((*dest++ = *src++) != '\0')
/* nothing */;
return tmp;
}
{
while(*src!='\0')
{
*des=*src;
des++;
src++;
}
*des='\0';
}
我现在没有书,不能给你提供源码。你可以自己去找找,如果是想要真正的源代码的话。
page ,132
title strcat - concatenate (append) one string to another
;***
;strcat.asm - contains strcat() and strcpy() routines
;
; Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
;
;Purpose:
; STRCAT concatenates (appends) a copy of the source string to the
; end of the destination string, returning the destination string.
;
;******************************************************************************* .xlist
include cruntime.inc
.list
page
;***
;char *strcat(dst, src) - concatenate (append) one string to another
;
;Purpose:
; Concatenates src onto the end of dest. Assumes enough
; space in dest.
;
; Algorithm:
; char * strcat (char * dst, char * src)
; {
; char * cp = dst;
;
; while( *cp )
; ++cp; /* Find end of dst */
; while( *cp++ = *src++ )
; ; /* Copy src to end of dst */
; return( dst );
; }
;
;Entry:
; char *dst - string to which "src" is to be appended
; const char *src - string to be appended to the end of "dst"
;
;Exit:
; The address of "dst" in EAX
;
;Uses:
; EAX, ECX
;
;Exceptions:
;
;*******************************************************************************page
;***
;char *strcpy(dst, src) - copy one string over another
;
;Purpose:
; Copies the string src into the spot specified by
; dest; assumes enough room.
;
; Algorithm:
; char * strcpy (char * dst, char * src)
; {
; char * cp = dst;
;
; while( *cp++ = *src++ )
; ; /* Copy src over dst */
; return( dst );
; }
;
;Entry:
; char * dst - string over which "src" is to be copied
; const char * src - string to be copied over "dst"
;
;Exit:
; The address of "dst" in EAX
;
;Uses:
; EAX, ECX
;
;Exceptions:
;*******************************************************************************
CODESEG% public strcat, strcpy ; make both functions available
strcpy proc
push edi ; preserve edi
mov edi,[esp+8] ; edi points to dest string
jmp short copy_startstrcpy endp align 16strcat proc .FPO ( 0, 2, 0, 0, 0, 0 ) mov ecx,[esp+4] ; ecx -> dest string
push edi ; preserve edi
test ecx,3 ; test if string is aligned on 32 bits
je short find_end_of_dest_string_loopdest_misaligned: ; simple byte loop until string is aligned
mov al,byte ptr [ecx]
inc ecx
test al,al
je short start_byte_3
test ecx,3
jne short dest_misaligned align 4find_end_of_dest_string_loop:
mov eax,dword ptr [ecx] ; read 4 bytes
mov edx,7efefeffh
add edx,eax
xor eax,-1
xor eax,edx
add ecx,4
test eax,81010100h
je short find_end_of_dest_string_loop
; found zero byte in the loop
mov eax,[ecx - 4]
test al,al ; is it byte 0
je short start_byte_0
test ah,ah ; is it byte 1
je short start_byte_1
test eax,00ff0000h ; is it byte 2
je short start_byte_2
test eax,0ff000000h ; is it byte 3
je short start_byte_3
jmp short find_end_of_dest_string_loop
; taken if bits 24-30 are clear and bit
; 31 is set
start_byte_3:
lea edi,[ecx - 1]
jmp short copy_start
start_byte_2:
lea edi,[ecx - 2]
jmp short copy_start
start_byte_1:
lea edi,[ecx - 3]
jmp short copy_start
start_byte_0:
lea edi,[ecx - 4]
; jmp short copy_start; edi points to the end of dest string.
copy_start::
mov ecx,[esp+0ch] ; ecx -> sorc string
test ecx,3 ; test if string is aligned on 32 bits
je short main_loop_entrancesrc_misaligned: ; simple byte loop until string is aligned
mov dl,byte ptr [ecx]
inc ecx
test dl,dl
je short byte_0
mov [edi],dl
inc edi
test ecx,3
jne short src_misaligned
jmp short main_loop_entrancemain_loop: ; edx contains first dword of sorc string
mov [edi],edx ; store one more dword
add edi,4 ; kick dest pointer
main_loop_entrance:
mov edx,7efefeffh
mov eax,dword ptr [ecx] ; read 4 bytes add edx,eax
xor eax,-1 xor eax,edx
mov edx,[ecx] ; it's in cache now add ecx,4 ; kick dest pointer
test eax,81010100h je short main_loop
; found zero byte in the loop
; main_loop_end:
test dl,dl ; is it byte 0
je short byte_0
test dh,dh ; is it byte 1
je short byte_1
test edx,00ff0000h ; is it byte 2
je short byte_2
test edx,0ff000000h ; is it byte 3
je short byte_3
jmp short main_loop ; taken if bits 24-30 are clear and bit
; 31 is set
byte_3:
mov [edi],edx
mov eax,[esp+8] ; return in eax pointer to dest string
pop edi
ret
byte_2:
mov [edi],dx
mov eax,[esp+8] ; return in eax pointer to dest string
mov byte ptr [edi+2],0
pop edi
ret
byte_1:
mov [edi],dx
mov eax,[esp+8] ; return in eax pointer to dest string
pop edi
ret
byte_0:
mov [edi],dl
mov eax,[esp+8] ; return in eax pointer to dest string
pop edi
retstrcat endp end