系统级编程lab4.docx
- 文档编号:20132843
- 上传时间:2023-04-25
- 格式:DOCX
- 页数:14
- 大小:396.03KB
系统级编程lab4.docx
《系统级编程lab4.docx》由会员分享,可在线阅读,更多相关《系统级编程lab4.docx(14页珍藏版)》请在冰豆网上搜索。
系统级编程lab4
LaboratoryTwo–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.
cccccccccFFrromo:
mFr:
iendCTTo:
EYouT
Determinethevalueofstartandstride:
[Hint]Nowyoufindthatifyoucanextractthemessage,pickthestartmessageandthenthestride(afterhowmanycharactersforthenext),youcanthenguesshowtodetermineit.Forexample,1234567890A
Start:
0andstride:
2,willproduce13579A
Start:
0andstride:
3,willproduce1245780A
Start:
0andstride:
4,willproduce12356790A
Start:
1andstride:
3,willproduce235689A
Ifyouchoosethevalueproperly,youwillget:
Startvalue:
indecimalinordertoproducetheabovemessageis___9____
Stride:
lengthofnextcharacter(Hint:
Youhavetorefertotheprogram,thevalueis2,3or4only).
1)Writedowntheaddressofdummy__0x0018ff3c____,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______
2)Nowselecttheproject:
setting,youwillseethefollowingscreen
Enterthevalueofkey1andkey2thatyouhavedeterminedandexecute,youwillget:
Appendix:
Pleasenotethatyoudon’tneedtomodifyanyprogram,buttounderstandhowtoenterthekeys.
Youcanextractandcompiletheprogram:
#include
#include
intprologue[]={
0x5920453A,0x54756F0A,0x6F6F470A,0x21643A6F,
0x6E617920,0x680A6474,0x6F697661,0x20646E69,
0x63636363,0x63636363,0x72464663,0x6F6D6F72,
0x63636363,0x63636363,0x72464663,0x6F6D6F72,
0x2C336573,0x7420346E,0x20216F74,0x726F5966,
0x7565636F,0x20206120,0x6C616763,0x74206C6F,
0x20206F74,0x74786565,0x65617276,0x32727463,
0x594E2020,0x206F776F,0x79727574,0x4563200A
};
/*
intdata[]={
0x63636363,0x63636363,0x72464663,0x6F6D6F72,
0x7565636F,0x20206120,0x6C616763,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,
0x6E617920,0x680A6474,0x6F697661,0x20646E69,
0x21687467,0x63002065,0x6C6C7861,0x78742078,
0x6578206F,0x72747878,0x78636178,0x00783174
};*/
intdata[]={
0x63636363,0x63636363,0x72464663,0x6F6D6F72,
0x466D203A,0x65693A72,0x43646E20,0x6F54540A,
0x5920453A,0x54756F0A,0x6F6F470A,0x21643A6F,
0x594E2020,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,0x6C6C7861,0x78742078,
0x6578206F,0x72747878,0x78636178,0x00783174
};
intepilogue[]={
0x594E2020,0x206F776F,0x79727574,0x4563200A,
0x6E617920,0x680A6474,0x6F697661,0x20646E69,
0x7565636F,0x20206120,0x6C616763,0x74206C6F,
0x2C336573,0x7420346E,0x20216F74,0x726F5966,
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 if(*(((char*)data)+j)=='\0'){ done=1; break; } message[i]=*(((char*)data)+j); } } message[i]='\0'; returnmessage; } char*extract_message2(intstart,intstride){ inti,j; for(i=0,j=start; *(((char*)data)+j)! ='\0'; i++,j+=stride) { message[i]=*(((char*)data)+j); } message[i]='\0'; returnmessage; } 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); if(argc>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=='\0'){ process_keys34(&key3,&key4); msg2=extract_message2(start,stride); printf("%s\n",msg2); } else{ printf("%s\n",msg1); } return0; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 系统 编程 lab4
![提示](https://static.bdocx.com/images/bang_tan.gif)