系统级编程lab4Word文档下载推荐.docx
- 文档编号:6419386
- 上传时间:2023-05-06
- 格式:DOCX
- 页数:17
- 大小:554.51KB
系统级编程lab4Word文档下载推荐.docx
《系统级编程lab4Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《系统级编程lab4Word文档下载推荐.docx(17页珍藏版)》请在冰点文库上搜索。
strncmp()首先将s1第一个字符值减去s2第一个字符值,若差值为0则再继续比较下个字符,直到字符结束标志'
\0'
,若差值不为0,则将差值返回。
例如字符串"
Ac"
和"
ba"
比较则会返回字符"
A"
(65)和'
b'
(98)的差值(-33)。
Practice3:
DecodingLab:
UnderstandingaSecretMessage
DecodingLab(Part1)
Objectives:
Forthisexercise,youhavetocompileaprogramasattachedandsupplyfoursecretkeystodeterminethecontents.Inthislaboratory,youhavetosupplythefirsttwo.Theremainingwillbedonenextweek.Iwillguideyoutosolvetheproblem.ThisexerciseisextractedfromtheCTE,SSD6–Exerciseone.
Thedetailsareasfollows.
Starttheprogram:
1)invokethevisualC++andusenewtostarttheworkplace.
2)SelecttheNewMenuandclick“workplace”.Thenameiscalledexercise1
3)Theprojectisexercise1:
SelectWin32Console
4)Theoutputafterselectingtheprojectisasfollows.
5)Selecttheemptybuttonuntilyouseethefollowingscreen
6)NowSelectNewagainandthenFiles,typethenameoffile“Exercise1”andselectC++sourcefile.
7)Clickthefileviewandthesourcefilesyouwillseeexercise1.cppisthere,butisempty.
8)Nowyoudownloadthesecretfile(secret.cpp)fromCTEwebsiteorgetitfromappendix.
9)Compiletheprogramwithoutanybug.
Setabreakpoint:
Setabreakpointtoforcetheprogramtobreak,pressF9.Agoodprogrammermustknowhowtodebug.
1)PressF9atthelocationofintdummyundermain()
2)NowClickDebugandchoosestartdebugthengo,youwillseethescreen
Itmeanstheprogramstopsatthislocation,Youcannowdummythemessagetoanalysisthedata.
3)Rightclickyourmouseandyouwillgetascreenasfollows:
4)Selectquickwatchandyouwillseeaquickwatch
5)Typethedataandwritetheaddress
Addressofdatais:
________0x00424ab0_______(hint:
inhex,ox……..)
6)Intheaddressscreen:
Enterthevalueoftheaddressofdata:
0x00424ab0_____.Youcanseethevalueofontherighthandside.
Writedownthefirst40characters.
cccccccccF
Frromo:
mF
r:
iendC.T
To:
EY.ouT
Determinethevalueofstartandstride:
[Hint]Nowyoufindthatifyoucanextractthemessage,pickthestartmessageandthenthestride(afterhowmanycharactersforthenext),youcanthenguesshowtodetermineit.Forexample,1234567890A
Start:
0andstride:
2,willproduce13579A
3,willproduce1245780A
4,willproduce12356790A
1andstride:
3,willproduce235689A
Ifyouchoosethevalueproperly,youwillget:
Startvalue:
indecimalinordertoproducetheabovemessageis______9_____
Stride:
lengthofnextcharacter(Hint:
Youhavetorefertotheprogram,thevalueis2,3or4only).
Start=9;
Stride=3;
1)Writedowntheaddressofdummy___
___,youhavetosetabreakpointbesidekey1,F9andExecutedebugsothattheprogramgoesthroughthefirstfewlines.Userightclickmouseand&
dummy(&
meanstheaddress)
PressF10willadvancetheprogram.
Itisaninteger:
Itconsistsof___4____bytes.Youcandeterminebycheckingthelocationofintstart,youthenunderstandthesize.
Nowdummyconsistsoftwoparts:
strideandstart.
Writedownthevalueofkey1____3___:
Thedifferencebetweendummyandkey1,
Key2:
Thefirstbyte:
start
Thesecondbyte:
stride
Thethirdandfourthbytecanbesettozero.
Key2:
0xstart+0xstride:
777(第三个与第四个字节可以任取,在此为方便设为0)
/************************************************************/
Key1,Key2计算过程:
①
通过以上两条语句我们可以得知:
start是取了dummy这个整形数字的第一个字节上的数字,stride是取了dummy这个整形数字的第二个字节上的数字。
所以dummy前两位字节是0x0309
②
通过传入的Key1,Key2,要使得dummy前两位字节是0x0309。
则key2的值是后两位字节为0x0309的任意整形数字。
③
Key1+*Key1需要为dummy的地址:
0x0012ff7c,key的地址为0x0012ff70。
0与c相差3个字节,所以key为3.
2)Nowselecttheproject:
setting,youwillseethefollowingscreen
Enterthevalueofkey1andkey2thatyouhavedeterminedandexecute,youwillget:
Appendix:
Pleasenotethatyoudon’tneedtomodifyanyprogram,buttounderstandhowtoenterthekeys.
Youcanextractandcompiletheprogram:
#include<
stdio.h>
stdlib.h>
intprologue[]={
0x5920453A,0x54756F0A,0x6F6F470A,0x21643A6F,
0x6E617920,0x680A6474,0x6F697661,0x20646E69,
0x63636363,0x63636363,0x72464663,0x6F6D6F72,
0x2C336573,0x7420346E,0x20216F74,0x726F5966,
0x7565636F,0x20206120,0x6C616763,0x74206C6F,
0x20206F74,0x74786565,0x65617276,0x32727463,
0x594E2020,0x206F776F,0x79727574,0x4563200A
};
/*
intdata[]={
0x594E2020,0x206F776F,0x79727574,0x4563200A,
0x6F786F68,0x6E696373,0x6C206765,0x796C656B,
0x21687467,0x63002065,0x6C6C7861,0x78742078,
0x6578206F,0x72747878,0x78636178,0x00783174
*/
0x466D203A,0x65693A72,0x43646E20,0x6F54540A,
intepilogue[]={
0x20206F74,0x74786565,0x65617276,0x32727463
charmessage[100];
voidusage_and_exit(char*program_name){
fprintf(stderr,"
USAGE:
%skey1key2key3key4\n"
program_name);
exit
(1);
}
voidprocess_keys12(int*key1,int*key2){
*((int*)(key1+*key1))=*key2;
voidprocess_keys34(int*key3,int*key4){
*(((int*)&
key3)+*key3)+=*key4;
char*extract_message1(intstart,intstride){
inti,j,k;
intdone=0;
for(i=0,j=start+1;
!
done;
j++){
for(k=1;
k<
stride;
k++,j++,i++){
if(*(((char*)data)+j)=='
){
done=1;
break;
}
message[i]=*(((char*)data)+j);
}
}
message[i]='
;
returnmessage;
char*extract_message2(intstart,intstride){
inti,j;
for(i=0,j=start;
*(((char*)data)+j)!
='
i++,j+=stride)
{
intmain(intargc,char*argv[])
{
intdummy=1;
intstart,stride;
intkey1,key2,key3,key4;
char*msg1,*msg2;
key3=key4=0;
if(argc<
3){
usage_and_exit(argv[0]);
key1=strtol(argv[1],NULL,0);
key2=strtol(argv[2],NULL,0);
if(argc>
3)key3=strtol(argv[3],NULL,0);
4)key4=strtol(argv[4],NULL,0);
process_keys12(&
key1,&
key2);
start=(int)(*(((char*)&
dummy)));
stride=(int)(*(((char*)&
dummy)+1));
if(key3!
=0&
&
key4!
=0){
process_keys34(&
key3,&
key4);
msg1=extract_message1(start,stride);
if(*msg1=='
msg2=extract_message2(start,stride);
printf("
%s\n"
msg2);
else{
msg1);
return0;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 系统 编程 lab4