- 1、本文档共6页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
rdtsc指令简介
RDTSC指令的使用以及相关问题1.前言最近碰到的RDTSC指令的问题,感觉挺烦人的,今天下午搞明白了一些东西就先放上来了。--------------------------------------------------2.正文1.使用RDTSC来anti-debug以下内容引用intel指令手册。//引用开始RDTSC—ReadTime-StampCounterOpcodeInstructionDescription0F31RDTSCReadtime-stampcounterintoEDX:EAX????DescriptionLoads?the?current?value?of?the?processor’s?time-stamp?counter?into?the?EDX:EAX?registers.?Thetime-stamp?counter?is?contained?in?a?64-bit?MSR.?The?high-order?32?bits?of?the?MSR?are?loadedinto?the?EDX?register,?and?the?low-order?32?bits?are?loaded?into?the?EAX?register.?The?processorincrements?the?time-stamp?counter?MSR?every?clock?cycle?and?resets?it?to?0?whenever?theprocessor?is?reset.The?time?stamp?disable?(TSD)?flag?in?register?CR4?restricts?the?use?of?the?RDTSC?instruction.When?the?TSD?flag?is?clear,?the?RDTSC?instruction?can?be?executed?at?any?privilege?level;?whenthe?flag?is?set,?the?instruction?can?only?be?executed?at?privilege?level?0.?The?time-stamp?countercan?also?be?read?with?the?RDMSR?instruction,?when?executing?at?privilege?level?0.The?RDTSC?instruction?is?not?a?serializing?instruction.?Thus,?it?does?not?necessarily?wait?untilall?previous?instructions?have?been?executed?before?reading?the?counter.?Similarly,?subsequentinstructions?may?begin?execution?before?the?read?operation?is?performed.This?instruction?was?introduced?into?the?IA-32?Architecture?in?the?Pentium?processor.OperationIF?(CR4.TSD?←?0)?OR?((CR4.TSD?←?1)?AND?(CPL=0))????THEN???????EDX:EAX?←?TimeStampCounter;????ELSE?(*?CR4?is?1?and?CPL?is?1,?2,?or?3?*)???????#GP(0)FI;Flags?AffectedNone.Protected?Mode?Exceptions#GP(0)?????????If?the?TSD?flag?in?register?CR4?is?set?and?the?CPL?is?greater?than?0.Real-Address?Mode?Exceptions#GP????????????If?the?TSD?flag?in?register?CR4?is?set.Virtual-8086?Mode?Exceptions#GP(0)?????????If?the?TSD?flag?in?register?CR4?is?set.//引用结束????英文太多,我也看不懂多少,大概的意思是这样,将计算机启动以来的CPU运行周期数放到EDX:EAX里面,EDX是高位,EAX是低位。????CPU运行周期数指的是CPU的一个时钟触发吧,就是应该是一个上升沿或者一个下降沿表示一个周期。??有一点你应该明白????周期数/CPU主频=CPU通电以来的执行秒数,也就是GetTickcount干
文档评论(0)