Hex-Rays Decompiler Tips and tricks Volatile memory
https://www.hex-rays.com/products/decompiler/manual/tricks.shtml
First of all, read the troubleshooting page. It explains how to deal with most decompilation problems.
Below is a mix of other useful information that did not fit into any other page:
Volatile memory
Sometimes the decompiler can be overly aggressive and optimize references to volatile memory completely away. A typical situation like the following:
device_ready DCD ? ; VOLATILE! MOV R0, =device_ready
LDR R1, [R0]
LOOP:
LDR R2, [R0]
SUB R2, R1
BEQ LOOPcan be decompiled into
while ( 1 )
;because the decompiler assumes that a variable can not change its value by itself and
it can prove that r0 continues to point to the same location during the loop.To prevent such optimization, we need to mark the variable as volatile.
Currently the decompiler considers memory to be volatile if it belongs to a segment with one of the following names:IO, IOPORTS, PORTS, VOLATILE.
The character case is not important.
Constant memory
Sometimes the decompiler does not optimize the code enough because it assumes that variables may change their values. For example, the following code:
LDR R1, =off_45934
MOV R2, #0
ADD R3, SP, #0x14+var_C
LDR R1, [R1]
LDR R1, [R1] ; int
BL _IOServiceOpencan be decompiled into
IOServiceOpen(r0_1, *off_45934, 0)but this code is much better:
IOServiceOpen(r0_1, mach_task_self, 0)because
off_45934 DCD _mach_task_selfis a pointer that resides in constant memory and will never change its value.
The decompiler considers memory to be constant if one of the following conditions hold:
- the segment has access permissions defined but the write permission is not in the list
(to change the segment permissions use the SetSegmentAttr built-in function)- the segment type is CODE
- the segment name is one of the following (the list may change in the future):
.text, .rdata, .got, .got.plt, __text, __const, __const_coal, __cstring, __literal4,
__literal8, __pointers, __nl_symbol_ptr, __la_symbol_ptr,
__objc_protorefs, __objc_selrefs, __objc_classrefs, __objc_superrefs, __objc_const,
__message_refs, __cls_refs, __inst_meth, __cat_inst_meth, __cat_cls_meth.
CONTAINING_RECORD macro
The decompiler knows about the CONTAINING_RECORD macro and tries to use it in the output.
However, in most cases it is impossible to create this macro automatically,
because the information about the containing record is not available.
The decompiler uses three sources of information to determine if CONTAINING_RECORD should be used:
- If there is an assignment like this:
v1 = (structype *)((char *)v2 - num);it can be converted into
v1 = CONTAINING_RECORD(v2, structype, fieldname);by simply confirming the types of v1 and v2.
NOTE: the variables types must be specified explicitly.
Even if the types are displayed as correct, the user should press Yfollowed by Enter to confirm the variable type.- Struct offsets applied to numbers in the disassembly listing are used as a hint
to create CONTAINING_RECORD. For example, applying structure offset to 0x41C insub eax, 41Chwill have the same effect as in the previous point. Please note that it makes sense to confirm the variable types as explained earlier.
- Struct offsets applied to numbers in the decompiler output. For example, applying _DEVICE_INFO structure offset to-131 in the following code:
deviceInfo = (_DEVICE_INFO *)((char *)&thisEntry[-131] - 4);will convert it to:
deviceInfo = CONTAINING_RECORD(thisEntry, _DEVICE_INFO, ListEntry);Please note that it makes sense to confirm the variable types as explained earlier.
Indirect calls
Since the arguments of indirect calls are collected before defining variables, specifying the type of the variable
that holds the function pointer may not be enough. The user have to specify the function type using other methods in this case.
The following methods exist (in the order of preference):
- For indirect calls of this form:
call ds:funcptrIf funcptr is initialized statically and points to a valid function, just ensure a correct function prototype. The decompiler will use it.
- For indirect calls of this form:
call [reg+offset]If reg points to a structure with a member that is a function pointer, just convert the operand into a structure offset (hotkey T):
call [reg+mystruct.funcptr]and ensure that the type of mystruct::funcptr is a pointer to a function of the desired type.
- Specify the type of the called function using Edit, Operand type, Set operand type.
If the first two methods can not be applied, this is the recommended method.
The operand type has the highest priority, it is always used if present.- If the address of the called function is known, use Edit, Plugins, Change the callee address (hotkey Alt-F11).
The decompiler will use the type of the specified callee. This method is available only for x86.
For other processors adding a code cross reference from the call instruction to the callee will help.
Hex-Rays Decompiler Tips and tricks Volatile memory的更多相关文章
- Matlab tips and tricks
matlab tips and tricks and ... page overview: I created this page as a vectorization helper but it g ...
- Android Studio tips and tricks 翻译学习
Android Studio tips and tricks 翻译 这里是原文的链接. 正文: 如果你对Android Studio和IntelliJ不熟悉,本页提供了一些建议,让你可以从最常见的任务 ...
- Nginx and PHP-FPM Configuration and Optimizing Tips and Tricks
原文链接:http://www.if-not-true-then-false.com/2011/nginx-and-php-fpm-configuration-and-optimizing-tips- ...
- (转) How to Train a GAN? Tips and tricks to make GANs work
How to Train a GAN? Tips and tricks to make GANs work 转自:https://github.com/soumith/ganhacks While r ...
- LoadRunner AJAX TruClient协议Tips and Tricks
LoadRunner AJAX TruClient协议Tips and Trickshttp://automationqa.com/forum.php?mod=viewthread&tid=2 ...
- Tips and Tricks for Debugging in chrome
Tips and Tricks for Debugging in chrome Pretty print On sources panel ,clicking on the {} on the bot ...
- [转]Tips——Chrome DevTools - 25 Tips and Tricks
Chrome DevTools - 25 Tips and Tricks 原文地址:https://www.keycdn.com/blog/chrome-devtools 如何打开? 1.从浏览器菜单 ...
- 10 Essential TypeScript Tips And Tricks For Angular Devs
原文: https://www.sitepoint.com/10-essential-typescript-tips-tricks-angular/ ------------------------- ...
- WWDC笔记:2011 Session 125 UITableView Changes, Tips and Tricks
What’s New Automatic Dimensions - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSect ...
随机推荐
- textile
textile 编辑 Textile是一个人性化的Web文本生成器,以简洁的方式提供HTML标签功能. 目录 1内容 ▪ 短语修饰符 ▪ 块修饰符 ▪ 链接 ▪ 属性 ▪ 排列 ▪ 表格 ▪ 图像 ...
- (转)Visual Studio原生开发的10个调试技巧(二)
我以前关于Visual Studio调试技巧的文章引起了大家很大的兴趣,以至于我决定分享更多调试的知识.以下的列表中你可以看到写原生开发的调试技巧(接着以前的文章来编号).这些技巧可以应用在VS200 ...
- 如何配置Drupal数据库信息?
Drupal的数据库连接信息通过文件settings.php中的变量$databases设置.变量$databases是一个二维的数组,第一维称为key,第二维称为target.使用这种方式可以处理多 ...
- BITMAP CONVERSION FROM ROWIDS
在有些执行计划中,可以会看到 BITMAP CONVERSION FROM ROWIDS这样的东东,也许你会感觉奇怪,我没有使用位图索引怎么出现了bitmap.我通过一个sql和大家分析下原因:sql ...
- 【转】linux下cpio命令使用
转自:http://www.51testing.com/html/32/498132-816949.html 功能说明:备份文件. 补充说明:cpio是用来建立,还原备份档的工具程序,它可以加入,解开 ...
- yield汇编实现
yield汇编实现. #include <stdio.h #include <conio.h #include <iostream.h // // marks a location ...
- bzoj 3594 [Scoi2014]方伯伯的玉米田(DP+二维BIT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3594 [题意] 给定一个n个数的序列,有K次将一个区间内的数加1的机会,问最长不下降子 ...
- Linux系统下查看已经登录用户并踢出的方法
LINUX是个多用户系统,一旦连接到网络中,它可以同时为多个登录用户提供服务. 查看用户的操作 查看当前用户: [ROOT@LOCALHOST ROOT] # W ...
- extjs笔记
1. ExtJs 结构树.. 2 2. 对ExtJs的态度.. 3 3. Ext.form概述.. 4 4. Ext.TabPanel篇.. 5 5. Functio ...
- html5_common.js
(function(){ this.sendAjax = function(url,func,formData,type){ type = type || "POST"; //默认 ...