Using C Run-time Library (libc.lib) with Masm
itprofes :: Tài Liệu theo chủ đề :: MASM
Trang 1 trong tổng số 1 trang
Using C Run-time Library (libc.lib) with Masm
Đây là ví dụ về cách sử dụng thư viện Run-time của C vào trong MASM. Ví dụ này cũng rất đơn giản, chỉ là sử dụng các hàm về chuỗi như:
strcat (Hàm nối chuỗi)
Concatenate strings
Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a new null-character is appended at the end of the new string formed by the concatenation of both in destination.
Parameters
destination
Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string.
source
C string to be appended. This should not overlap destination.
Return Value: destination is returned.
Source Code in VC++:
Output:
these strings are concatenated.
strstr (Hàm tìm chuỗi con)
Locate substring
Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.
The matching process does not include the terminating null-characters.
Parameters
str1
C string to be scanned.
str2
C string containing the sequence of characters to match.
Return Value
A pointer to the first occurrence in str1 of any of the entire sequence of characters specified in str2, or a null pointer if the sequence is not present in str1.
Source Code in VC++:
Output:
This is a sample string
Using C Run-time Library (libc.lib) with Masm:
strcat (Hàm nối chuỗi)
- Code:
char * strcat ( char * destination, const char * source );
Concatenate strings
Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a new null-character is appended at the end of the new string formed by the concatenation of both in destination.
Parameters
destination
Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string.
source
C string to be appended. This should not overlap destination.
Return Value: destination is returned.
Source Code in VC++:
- Code:
/* strcat example */
#include
#include
int main ()
{
char str[80];
strcpy (str,"these ");
strcat (str,"strings ");
strcat (str,"are ");
strcat (str,"concatenated.");
puts (str);
return 0;
}
Output:
these strings are concatenated.
strstr (Hàm tìm chuỗi con)
- Code:
const char * strstr ( const char * str1, const char * str2 );
char * strstr ( char * str1, const char * str2 );
Locate substring
Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.
The matching process does not include the terminating null-characters.
Parameters
str1
C string to be scanned.
str2
C string containing the sequence of characters to match.
Return Value
A pointer to the first occurrence in str1 of any of the entire sequence of characters specified in str2, or a null pointer if the sequence is not present in str1.
Source Code in VC++:
- Code:
/* strstr example */
#include
#include
int main ()
{
char str[] ="This is a simple string";
char * pch;
pch = strstr (str,"simple");
strncpy (pch,"sample",6);
puts (str);
return 0;
}
Output:
This is a sample string
Using C Run-time Library (libc.lib) with Masm:
- Code:
;------------------------------------------------------------
; Using C Run-time Library with MASM
; Coded by: NhatPhuongLe
; Homepage: http://nhatphuongle.spaces.live.com/default.aspx
;------------------------------------------------------------
include \masm32\include\masm32rt.inc
includelib libc.lib ; CRT static library
;Define prototype these function from CRT Lib
strcat PROTO C :DWORD,:DWORD
strstr PROTO C :DWORD,:DWORD
strchr PROTO C :DWORD,:DWORD
.data
szDest db 'This is a sample ',0
db 10 dup(0)
szSource db 'using CRT Library in MASM',13,10,0
szString db 'Library',0
crlf db 13,10,0
.data?
szbuffer db 20 dup(?)
.code
start:
invoke strcat,ADDR szDest,ADDR szSource
invoke StdOut,ADDR szDest
invoke strstr,ADDR szDest,ADDR szString
call print
invoke strchr,ADDR szDest,'i'
call print
invoke ExitProcess,0
print PROC
invoke dw2hex,eax,ADDR szbuffer
invoke StdOut,ADDR szbuffer
invoke StdOut,ADDR crlf
ret
print ENDP
END start
Similar topics
» Dynamic Link Library in ASM
» PLAYING XM MUSIC FROM MASM’S EXE
» Tut+Source Masm Key softs
» MASM virus Mai Phuong Thuy
» How to: Enable/Disable Just-In-Time Debugging
» PLAYING XM MUSIC FROM MASM’S EXE
» Tut+Source Masm Key softs
» MASM virus Mai Phuong Thuy
» How to: Enable/Disable Just-In-Time Debugging
itprofes :: Tài Liệu theo chủ đề :: MASM
Trang 1 trong tổng số 1 trang
Permissions in this forum:
Bạn không có quyền trả lời bài viết
27/8/2013, 11:45 am by echcondihoc
» Quản Lí Tiến Trình Dùng Thư Viện PSAPI
11/10/2011, 9:42 pm by CNTT_DH
» xin tai lieu tieng viet
31/8/2011, 6:59 am by bantoisg
» Theo dõi tiến trình
27/8/2011, 5:51 pm by haigaopro01
» Giải pháp Bảo mật của Cisco
17/6/2011, 8:50 am by admin
» Nghiên cứu và đưa ra giải pháp phòng chống tấn công DoS, DDoS (Phần 1)
16/6/2011, 2:32 pm by admin
» Learn to hack !
16/6/2011, 8:49 am by admin
» Giải pháp hệ thống dành cho doanh nghiệp với thiết bị mạng Fortinet (Phần 1)
15/6/2011, 11:12 am by admin
» Ô Long Viên (Tập II)
27/9/2010, 4:56 pm by root
» những ebook về hack tiếng việt cho người mới tìm hiểu.
27/9/2010, 4:54 pm by root