静态代码分析PPT课件.ppt

上传人:优*** 文档编号:127681775 上传时间:2020-04-04 格式:PPT 页数:54 大小:894KB
返回 下载 相关 举报
静态代码分析PPT课件.ppt_第1页
第1页 / 共54页
静态代码分析PPT课件.ppt_第2页
第2页 / 共54页
静态代码分析PPT课件.ppt_第3页
第3页 / 共54页
静态代码分析PPT课件.ppt_第4页
第4页 / 共54页
静态代码分析PPT课件.ppt_第5页
第5页 / 共54页
点击查看更多>>
资源描述

《静态代码分析PPT课件.ppt》由会员分享,可在线阅读,更多相关《静态代码分析PPT课件.ppt(54页珍藏版)》请在金锄头文库上搜索。

1、静态代码分析 梁广泰2011 05 25 提纲 动机程序静态分析 概念 实例 程序缺陷分析 科研工作 动机 云平台特点应用程序直接部署在云端服务器上 存在安全隐患直接操作破坏服务器文件系统存在安全漏洞时 可提供黑客入口资源共享 动态分配单个应用的性能低下 会侵占其他应用的资源解决方案之一 在部署应用程序之前 对其进行静态代码分析 是否存在违禁调用 非法文件访问 是否存在低效代码 未借助StringBuilder对String进行大量拼接 是否存在安全漏洞 SQL注入 跨站攻击 拒绝服务 是否存在恶意病毒 提纲 动机程序静态分析 概念 实例 程序缺陷分析 科研工作 静态代码分析 定义 程序静态分

2、析是在不执行程序的情况下对其进行分析的技术 简称为静态分析 对比 程序动态分析 需要实际执行程序程序理解 静态分析这一术语一般用来形容自动化工具的分析 而人工分析则往往叫做程序理解用途 程序翻译 编译 编译器 程序优化重构 软件缺陷检测等过程 大多数情况下 静态分析的输入都是源程序代码或者中间码 如Javabytecode 只有极少数情况会使用目标代码 以特定形式输出分析结果 静态代码分析 BasicBlocksControlFlowGraphDataflowAnalysisLiveVariableAnalysisReachingDefinitionAnalysisLatticeTheory

3、BasicBlocks Abasicblockisamaximalsequenceofconsecutivethree addressinstructionswiththefollowingproperties Theflowofcontrolcanonlyenterthebasicblockthruthe1stinstr Controlwillleavetheblockwithouthaltingorbranching exceptpossiblyatthelastinstr Basicblocksbecomethenodesofaflowgraph withedgesindicatingt

4、heorder BasicBlockExample Leaders i 1j 1t1 10 it2 t1 jt3 8 t2t4 t3 88a t4 0 0j j 1ifj 10goto 3 i i 1ifi 10goto 2 i 1t5 i 1t6 88 t5a t6 1 0i i 1ifi 10goto 13 BasicBlocks Control FlowGraphs Control flowgraph Node aninstructionorsequenceofinstructions abasicblock Twoinstructionsi jinsamebasicblockiffex

5、ecutionofiguaranteesexecutionofjDirectededge potentialflowofcontrolDistinguishedstartnodeEntry ExitFirst lastinstructioninprogram Control FlowEdges Basicblocks nodesEdges AdddirectededgebetweenB1andB2if BranchfromlaststatementofB1tofirststatementofB2 B2isaleader orB2immediatelyfollowsB1inprogramorde

6、randB1doesnotendwithunconditionalbranch goto DefinitionofpredecessorandsuccessorB1isapredecessorofB2B2isasuccessorofB1 CFGExample 静态代码分析 BasicBlocksControlFlowGraphDataflowAnalysisLiveVariableAnalysisReachingDefinitionAnalysisLatticeTheory DataflowAnalysis Compile TimeReasoningAboutRun TimeValuesofV

7、ariablesorExpressionsAtDifferentProgramPointsWhichassignmentstatementsproducedvalueofvariableatthispoint Whichvariablescontainvaluesthatarenolongerusedafterthisprogrampoint Whatistherangeofpossiblevaluesofvariableatthisprogrampoint ProgramPoints OneprogrampointbeforeeachnodeOneprogrampointaftereachn

8、odeJoinpoint pointwithmultiplepredecessorsSplitpoint pointwithmultiplesuccessors LiveVariableAnalysis Avariablevisliveatpointpifvisusedalongsomepathstartingatp andnodefinitionofvalongthepathbeforetheuse Whenisavariablevdeadatpointp Nouseofvonanypathfromptoexitnode orIfallpathsfrompredefinevbeforeusi

9、ngv WhatUseisLivenessInformation Registerallocation Ifavariableisdead canreassignitsregisterDeadcodeelimination Eliminateassignmentstovariablesnotreadlater Butmustnoteliminatelastassignmenttovariable suchasinstancevariable visibleoutsideCFG Caneliminateotherdeadassignments Handlebymakingallexternall

10、yvisiblevariablesliveonexitfromCFG ConceptualIdeaofAnalysis startfromexitandgobackwardsinCFGComputelivenessinformationfromendtobeginningofbasicblocks LivenessExample a x y t a c a x x 0 b t z c y 1 1100100 1110000 Assumea b cvisibleoutsidemethodSoareliveonexitAssumex y z tnotvisibleRepresentLiveness

11、UsingBitVectororderisabcxyzt 1100111 1000111 1100100 0101110 abcxyzt abcxyzt abcxyzt FormalizingAnalysis EachbasicblockhasIN setofvariablesliveatstartofblockOUT setofvariablesliveatendofblockUSE setofvariableswithupwardsexposedusesinblock usepriortodefinition DEF setofvariablesdefinedinblockpriortou

12、seUSE x z x x 1 z xnotinUSE DEF x z x x 1 y 1 x y CompilerscanseachbasicblocktoderiveUSEandDEFsets Algorithm forallnodesninN Exit IN n emptyset OUT Exit emptyset IN Exit use Exit Changed N Exit while Changed emptyset chooseanodeninChanged Changed Changed n OUT n emptyset forallnodessinsuccessors n O

13、UT n OUT n UIN p IN n use n U out n def n if IN n changed forallnodespinpredecessors n Changed ChangedU p 静态代码分析 概念 BasicBlocksControlFlowGraphDataflowAnalysisLiveVariableAnalysisReachingDefinitionAnalysisLatticeTheory ReachingDefinitions Conceptofdefinitionandusea x yisadefinitionofaisauseofxandyAd

14、efinitionreachesauseifvaluewrittenbydefinitionmaybereadbyuse ReachingDefinitions ReachingDefinitionsandConstantPropagation Isauseofavariableaconstant CheckallreachingdefinitionsIfallassignvariabletosameconstantThenuseisinfactaconstantCanreplacevariablewithconstant IsaConstantins s a b Yes Onallreach

15、ingdefinitionsa 4 ConstantPropagationTransform Yes Onallreachingdefinitionsa 4 2020 4 4 27 ComputingReachingDefinitions ComputewithsetsofdefinitionsrepresentsetsusingbitvectorseachdefinitionhasapositioninbitvectorAteachbasicblock computedefinitionsthatreachstartofblockdefinitionsthatreachendofblockD

16、ocomputationbysimulatingexecutionofprogramuntilreachfixedpoint 1 s 0 2 a 4 3 i 0 k 0 4 b 1 5 b 2 0000000 1110000 1110000 1111100 1111100 1111100 1111111 1111111 1111111 1234567 1234567 1234567 1234567 1234567 1234567 1110000 1111000 1110100 1111100 0101111 1111100 1111111 i n 1111111 returns 6 s s a b 7 i i 1 FormalizingReachingDefinitions EachbasicblockhasIN setofdefinitionsthatreachbeginningofblockOUT setofdefinitionsthatreachendofblockGEN setofdefinitionsgeneratedinblockKILL setofdefinitionsk

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号