main函数的参数__网络编程之参数学习
2012-09-28 20:09
330 查看
是否还记得ppt上的这张图片呢?
这个程序可以带参数,是不是和以前的程序不一样呢?
下面我们就来实现,这可花了我半个小时的时间哦!!!
首先,我们和以前写C语言程序一样,新建一个工程,工程的名字当然是vc啦
然后选择A simple application,然后点击finish,完成工程的创建
开始写代码啦,双击打开vc.cpp文件
开始下面的代码,应该能看懂吧,嘿嘿
#include "stdafx.h" #include "stdio.h" int main(int argc, char* argv[]) { if (argc==1) { printf("\n\n The content in argv[0] is :%s \n\n",argv[0]); } if (argc==2) { printf("\n\n The command includes 1 parameter: %s \n\n",argv[1]); printf("The content in argv[0] is :%s \n\n",argv[0]); } if (argc>2) { printf("\n\n bad command !\n"); } return 0; }
这样就OK了哦,很简单吧!
===================下面是我的东西了,hoho~~~====================
反汇编,找到主函数
00401256 |. 52 push edx 00401257 |. A1 847C4200 mov eax, dword ptr [__argv] 0040125C |. 50 push eax 0040125D |. 8B0D 807C4200 mov ecx, dword ptr [__argc] 00401263 |. 51 push ecx 00401264 |. E8 9CFDFFFF call 00401005
运行到00401257看看情况
进入数据窗口查看003D0D90
看出来是什么没?就是argv[0]啦。
继续运行到0040125D
只有一个参数,是不是,因为我们没有输入
下面是主函数
00401005 /$ /E9 06000000 jmp main 0040100A | |CC int3 0040100B | |CC int3 0040100C | |CC int3 0040100D | |CC int3 0040100E | |CC int3 0040100F | |CC int3 00401010 >|> \55 push ebp 00401011 |. 8BEC mov ebp, esp 00401013 |. 83EC 40 sub esp, 40 00401016 |. 53 push ebx 00401017 |. 56 push esi 00401018 |. 57 push edi 00401019 |. 8D7D C0 lea edi, dword ptr [ebp-40] 0040101C |. B9 10000000 mov ecx, 10 00401021 |. B8 CCCCCCCC mov eax, CCCCCCCC 00401026 |. F3:AB rep stos dword ptr es:[edi] 00401028 |. 837D 08 01 cmp dword ptr [ebp+8], 1 0040102C |. 75 13 jnz short 00401041 0040102E |. 8B45 0C mov eax, dword ptr [ebp+C] 00401031 |. 8B08 mov ecx, dword ptr [eax] 00401033 |. 51 push ecx ; /<%s> 00401034 |. 68 90204200 push 00422090 ; |format = LF,LF," The content in argv[0] is :%s ",LF,LF,"" 00401039 |. E8 82000000 call printf ; \printf 0040103E |. 83C4 08 add esp, 8 00401041 |> 837D 08 02 cmp dword ptr [ebp+8], 2 00401045 |. 75 27 jnz short 0040106E 00401047 |. 8B55 0C mov edx, dword ptr [ebp+C] 0040104A |. 8B42 04 mov eax, dword ptr [edx+4] 0040104D |. 50 push eax ; /<%s> 0040104E |. 68 5C204200 push 0042205C ; |format = LF,LF," The command includes 1 parameter: %s ",LF,LF,"" 00401053 |. E8 68000000 call printf ; \printf 00401058 |. 83C4 08 add esp, 8 0040105B |. 8B4D 0C mov ecx, dword ptr [ebp+C] 0040105E |. 8B11 mov edx, dword ptr [ecx] 00401060 |. 52 push edx ; /<%s> 00401061 |. 68 34204200 push 00422034 ; |format = "The content in argv[0] is :%s ",LF,LF,"" 00401066 |. E8 55000000 call printf ; \printf 0040106B |. 83C4 08 add esp, 8 0040106E |> 837D 08 02 cmp dword ptr [ebp+8], 2 00401072 |. 7E 0D jle short 00401081 00401074 |. 68 1C204200 push 0042201C ; /format = LF,LF," bad command !",LF,"" 00401079 |. E8 42000000 call printf ; \printf 0040107E |. 83C4 04 add esp, 4 00401081 |> 33C0 xor eax, eax 00401083 |. 5F pop edi 00401084 |. 5E pop esi 00401085 |. 5B pop ebx ; 7FFD5000 00401086 |. 83C4 40 add esp, 40 00401089 |. 3BEC cmp ebp, esp 0040108B |. E8 B0000000 call _chkesp 00401090 |. 8BE5 mov esp, ebp 00401092 |. 5D pop ebp 00401093 \. C3 retn
很简单,不解释。
相关文章推荐
- IOS学习之 网络编程(8)--发送json数据给服务器以及多值参数
- 网络编程学习笔记(套接口超时)
- IOS网络编程要学习的框架
- Android网络编程之通过Post传递参数
- 网络编程学习笔记(批量输入)
- java学习日记(9)———socket,网络编程的学习
- Java 网络编程简单学习2
- Java学习笔记(十五)网络编程及常用类库
- Coursera deep learning 吴恩达 神经网络和深度学习 第二周 编程作业 Logistic Regression with a Neural Network mindset
- 该学习网络编程了
- (转)机器学习之&&Andrew Ng课程复习---神经网络编程入门
- 网络编程1--毕向东java基础教程视频学习笔记
- java学习之路 之 网络编程-练习题
- UNIX环境高级编程学习之第十六章网络IPC:套接字 - 非阻塞的Socket通信EPoll模型(多路复用), 实用Socket通信模板
- java 网络编程 黑马程序员学习笔记(3)
- 如何学习网络编程
- 网络编程学习_基本socket函数
- Java 网络编程 学习笔记二 Socket 用法
- Java 学习笔记(网络编程 之 URL)
- 西门子PLC学习笔记十七-(不带参数FC编程)