




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Practice 1: ArrayStorage.cpp将字符数组a与b的首地址传入Initialize ()方法后,对a中的各个元素进行赋值,将字符数组a的0到8位赋值为字符数组“This is A”。又将a的首地址赋值给b的首地址,则在此时,b已经变为指向字符数组a的指针,与a等效。则b8 = B就是将“This is A”改为“This is B”,未对字符数组b进行任何操作。所以当Initialize ()方法运行结束后,字符数组a的内容为“This is A”,而字符数组b的内容仍为空。Practice 2: strchr.cppFgets();fgets()用来
2、从参数stream 所指的文件内读入字符并存到参数s 所指的内存空间, 直到出现换行字符、读到文件尾或是已读了size-1 个字符为止, 最后会加上NULL 作为字符串结束.Strchr();用来查找某字符在字符串中首次出现的位置,其原型为: char * strchr (const char *str, int c);【参数】str 为要查找的字符串,c 为要查找的字符。strchr() 将会找出 str 字符串中第一次出现的字符 c 的地址,然后将该地址返回。Strncmp();strncmp() 用来比较两个字符串的前n个字符,区分大小写,其原型为: int strncmp ( cons
3、t char * str1, const char * str2, size_t n );【参数】str1, str2 为需要比较的两个字符串,n为要比较的字符的数目。字符串大小的比较是以ASCII 码表上的顺序来决定,此顺序亦为字符的值。strncmp()首先将s1 第一个字符值减去s2 第一个字符值,若差值为0 则再继续比较下个字符,直到字符结束标志'0',若差值不为0,则将差值返回。例如字符串"Ac"和"ba"比较则会返回字符"A"(65)和'b'(98)的差值(-33)。Practice 3:
4、Decoding Lab: Understanding a Secret MessageDecoding Lab (Part 1)Objectives: For this exercise, you have to compile a program as attached and supply four secret keys to determine the contents. In this laboratory, you have to supply the first two. The remaining will be done next week. I will guide yo
5、u to solve the problem. This exercise is extracted from the CTE, SSD6 Exercise one.The details are as follows.Start the program:1) invoke the visual C+ and use new to start the workplace.2) Select the New Menu and click “workplace”. The name is called exercise 13) The project is exercise 1: Select W
6、in32 Console4) The output after selecting the project is as follows. 5) Select the empty button until you see the following screen6) Now Select New again and then Files, type the name of file “Exercise 1” and select C+ source file. 7) Click the fileview and the source files you will see exercise1.cp
7、p is there, but is empty.8) Now you download the secret file (secret.cpp) from CTE web site or get it from appendix.9) Compile the program without any bug. Set a breakpoint: Set a break point to force the program to break, press F9. A good programmer must know how to debug.1) Press F9 at the locatio
8、n of int dummy under main()2) Now Click Debug and choose start debug then go, you will see the screenIt means the program stops at this location, You can now dummy the message to analysis the data.3) Right click your mouse and you will get a screen as follows: 4) Select quick watch and you will see
9、a quick watch 5) Type the data and write the addressAddress of data is: _ 0x00424ab0_ (hint: in hex, ox.)6) In the address screen: Enter the value of the address of data: 0x00424ab0_. You can see the value of on the right hand side. Write down the first 40 characters.cccccccccFFrromo: mFr:ie ndC.TTo
10、:E Y.ouTDetermine the value of start and stride:Hint Now you find that if you can extract the message, pick the start message and then the stride (after how many characters for the next), you can then guess how to determine it. For example, 1234567890AStart:0 and stride: 2, will produce 13579AStart:
11、0 and stride: 3, will produce 1245780AStart:0 and stride: 4, will produce 12356790AStart:1 and stride: 3, will produce 235689AIf you choose the value properly, you will get:Start value: in decimal in order to produce the above message is _9_Stride: length of next character (Hint: You have to refer t
12、o the program, the value is 2, 3 or 4 only).Start = 9;Stride = 3;1) Write down the address of dummy _, you have to set a break point beside key1, F9 and Execute debug so that the program goes through the first few lines. Use right click mouse and &dummy (&means the address)Press F10 will adv
13、ance the program.It is an integer: It consists of _4_ bytes. You can determine by checking the location of int start, you then understand the size.Now dummy consists of two parts: stride and start.Write down the value of key1_3_: The difference between dummy and key1, Key2: The first byte: start The
14、 second byte: stride The third and fourth byte can be set to zero.Key2 : 0 x start + 0 x stride :777(第三个与第四个字节可以任取,在此为方便设为0)/*/Key1,Key2计算过程:通过以上两条语句我们可以得知:start是取了dummy这个整形数字的第一个字节上的数字,stride是取了dummy这个整形数字的第二个字节上的数字。所以dummy前两位字节是0x0309通过传入的Key1,Key2,要使得dummy前两位字节是0x0309。则key2的值是后两位字节为0x0309的任意整形数字。
15、Key1 + *Key1 需要为dummy的地址:0x0012ff7c,key的地址为0x0012ff70。0与c相差3个字节,所以key为3./*/2) Now select the project: setting, you will see the following screenEnter the value of key1 and key2 that you have determined and execute, you will get :Appendix:Please note that you dont need to modify any program, but to u
16、nderstand how to enter the keys.You can extract and compile the program:#include <stdio.h>#include <stdlib.h>int prologue = 0x5920453A, 0x54756F0A, 0x6F6F470A, 0x21643A6F,0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69,0x63636363, 0x63636363, 0x72464663, 0x6F6D6F72,0x63636363, 0x63636363,
17、 0x72464663, 0x6F6D6F72,0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966,0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F,0x20206F74, 0x74786565, 0x65617276, 0x32727463,0x594E2020, 0x206F776F, 0x79727574, 0x4563200A;/*int data = 0x63636363, 0x63636363, 0x72464663, 0x6F6D6F72,0x7565636F, 0x20206120, 0x6C
18、616763, 0x74206C6F,0x5920453A, 0x54756F0A, 0x6F6F470A, 0x21643A6F,0x594E2020, 0x206F776F, 0x79727574, 0x4563200A,0x6F786F68, 0x6E696373, 0x6C206765, 0x796C656B,0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966,0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F,0x20206F74, 0x74786565, 0x65617276, 0x32727463
19、,0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69,0x21687467, 0x63002065, 0x6C6C7861, 0x78742078,0x6578206F, 0x72747878, 0x78636178, 0x00783174;*/int data = 0x63636363, 0x63636363, 0x72464663, 0x6F6D6F72,0x466D203A, 0x65693A72, 0x43646E20, 0x6F54540A,0x5920453A, 0x54756F0A, 0x6F6F470A, 0x21643A6F,0x59
20、4E2020, 0x206F776F, 0x79727574, 0x4563200A,0x6F786F68, 0x6E696373, 0x6C206765, 0x796C656B,0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966,0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F,0x20206F74, 0x74786565, 0x65617276, 0x32727463,0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69,0x21687467, 0x63002065
21、, 0x6C6C7861, 0x78742078,0x6578206F, 0x72747878, 0x78636178, 0x00783174;int epilogue = 0x594E2020, 0x206F776F, 0x79727574, 0x4563200A,0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69,0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F,0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966,0x20206F74, 0x74786565, 0
22、x65617276, 0x32727463;char message100;void usage_and_exit(char * program_name) fprintf(stderr, "USAGE: %s key1 key2 key3 key4n", program_name);exit(1);void process_keys12 (int * key1, int * key2) *(int *) (key1 + *key1) = *key2;void process_keys34 (int * key3, int * key4) *(int *)&key3
23、) + *key3) += *key4;char * extract_message1(int start, int stride) int i, j, k;int done = 0;for (i = 0, j = start + 1; ! done; j+) for (k = 1; k < stride; k+, j+, i+) if (*(char *) data) + j) = '0') done = 1;break; messagei = *(char *) data) + j);messagei = '0'return message;char * extract_message2(int start, int stride) int i, j;for (i = 0, j = start; *(char *) data) + j) != '0' i+, j += stride) messagei =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 网络环境下的图书馆服务能力考查试题及答案
- 激光系统升级的必要性试题及答案
- 小高考模拟卷试题及答案
- 深入解析光电工程师考试试题与答案
- 系统规划与管理师考试常用工具的使用指引试题及答案
- 突破系统架构设计师考试的关键技巧试题及答案
- 自拟题目试题及答案大全
- 育婴师发展支持试题及答案
- 肇庆教师面试题目及答案
- 精心设计的护士资格证试题及答案
- 2025福建省泉州市房屋租赁合同范本
- 中华遗产考试题目及答案
- 全厂设施色彩、标志牌统一规定
- 《民航重大安全隐患判定标准(2024 年修订版)》知识培训
- 物业电工安全培训
- 湖南省炎德英才名校联考联合体2024-2025学年高二下学期3月月考-化学+答案
- 国家安全你我有责-2025全民国家安全教育日主题宣教课件
- 楼梯 栏杆 栏板(一)22J403-1
- 合同工期延期补充协议书
- 幼儿园绘本故事《三只小猪盖房子》教学课件全文
- JBT 7387-2014 工业过程控制系统用电动控制阀
评论
0/150
提交评论