|
[分享]IDAPython---未识别函数创建
## round1 ### 问 ida python脚本 以"push ebp mov ebp, esp"开头的都创建函数 ### 答 在 IDA Pro 中,你可以使用 Python 脚本来自动创建以 "push ebp; mov ebp, esp" 开头的函数。以下是一个简单的示例代码,演示如何做到这一点: ```python import idautils import idc import idaapi # 遍历所有的代码段 for seg_ea in idautils.Segments(): # 获取段的结束地址 seg_end = idc.get_segm_end(seg_ea)
# 在该段内搜索 ea = seg_ea while ea < seg_end: # 搜索 "push ebp" 指令 ea = idc.find_binary(ea, seg_end, "55", 16, idc.SEARCH_DOWN) if ea == idaapi.BADADDR: break # 未找到
# 检查下一条指令是否为 "mov ebp, esp" next_ea = idc.next_head(ea, seg_end) next_mnem = idc.print_insn_mnem(next_ea) if next_mnem == "mov" and idc.get_operand_value(next_ea, 0) == 5 and idc.get_operand_value(next_ea, 1) == 4: # 如果找到匹配,尝试创建函数 if not idaapi.add_func(ea): print("Failed to create function at 0x{:x}".format(ea)) else: print("Function created at 0x{:x}".format(ea))
# 更新地址以继续搜索 ea = idc.next_head(ea, seg_end) ``` 将这段代码复制粘贴到 IDA Pro 的 Python 控制台或者作为脚本运行。它会遍历所有代码段,寻找 "push ebp; mov ebp, esp" 指令序列,并尝试在这些位置创建函数。 注意:这个脚本是非常基础的,只用于演示。在实际应用中,你可能需要考虑更多的边缘情况和优化。 ## round2 ### 问 ida python脚本 在标记为instruction段的位置,搜索"push ebp mov ebp, esp",创建函数 ### 答 在 IDA Pro 中,你可以使用 Python 脚本来在标记为指令(instruction)的段中搜索 "push ebp; mov ebp, esp" 并创建函数。以下是一个示例脚本: ```python import idautils import idc import idaapi # 遍历所有的代码段 for seg_ea in idautils.Segments(): # 检查该段是否包含指令 seg_type = idc.get_segm_attr(seg_ea, idc.SEGATTR_TYPE) if seg_type != idaapi.SEG_CODE: continue
# 获取段的结束地址 seg_end = idc.get_segm_end(seg_ea)
# 在该段内搜索 ea = seg_ea while ea < seg_end: # 搜索 "push ebp" 指令 ea = idc.find_binary(ea, seg_end, "55", 16, idc.SEARCH_DOWN) if ea == idaapi.BADADDR: break # 未找到
# 检查下一条指令是否为 "mov ebp, esp" next_ea = idc.next_head(ea, seg_end) next_mnem = idc.print_insn_mnem(next_ea) if next_mnem == "mov" and idc.get_operand_value(next_ea, 0) == 5 and idc.get_operand_value(next_ea, 1) == 4: # 如果找到匹配,尝试创建函数 if not idaapi.add_func(ea): print(f"无法在 0x{ea:X} 创建函数") else: print(f"已在 0x{ea:X} 创建函数")
# 更新地址以继续搜索 ea = idc.next_head(ea, seg_end) ``` 这个脚本首先遍历所有段,并检查它们是否为代码段。然后,在每个代码段中搜索指令 "push ebp; mov ebp, esp"。找到后,它会尝试在该位置创建函数。 你可以将这段代码复制并粘贴到 IDA Pro 的 Python 控制台,或者保存为 `.py` 文件并在 IDA Pro 中运行该脚本。这将自动在找到的地址处创建函数。 ## round3 ### 问 "push ebp; "和"mov ebp, esp"合并在一起搜索 ### 答 在 IDA Pro 的 Python 脚本中,你可以将 "push ebp" 和 "mov ebp, esp" 的机器码合并,然后一次性搜索它们。以下是如何实现这一点的示例代码: ```python import idautils import idc import idaapi # 合并 "push ebp" 和 "mov ebp, esp" 的机器码 # "push ebp" 的机器码是 55 # "mov ebp, esp" 的机器码是 89 E5 combined_pattern = "55 89 E5" # 遍历所有的代码段 for seg_ea in idautils.Segments(): # 检查该段是否包含指令 seg_type = idc.get_segm_attr(seg_ea, idc.SEGATTR_TYPE) if seg_type != idaapi.SEG_CODE: continue
# 获取段的结束地址 seg_end = idc.get_segm_end(seg_ea)
# 在该段内搜索 ea = seg_ea while ea < seg_end: # 搜索组合的指令模式 ea = idc.find_binary(ea, seg_end, combined_pattern, 16, idc.SEARCH_DOWN) if ea == idaapi.BADADDR: break # 未找到 # 如果找到匹配,尝试创建函数 if not idaapi.add_func(ea): print(f"无法在 0x{ea:X} 创建函数") else: print(f"已在 0x{ea:X} 创建函数")
# 更新地址以继续搜索 ea = idc.next_head(ea, seg_end) ``` 这个脚本将 "push ebp" 和 "mov ebp, esp" 的机器码合并为一个字符串 `combined_pattern`,然后在代码段中搜索这个组合模式。找到匹配项后,它会在该地址处尝试创建一个函数。 你可以将这段代码复制并粘贴到 IDA Pro 的 Python 控制台,或者保存为 `.py` 文件并在 IDA Pro 中运行该脚本。这将自动在找到的地址处创建函数。 ## round4 ### 问 "mov ebp, esp" 的机器码是 8B EC ### 答 非常感谢您的更正。您是对的,"mov ebp, esp" 的机器码实际上是 "8B EC"。基于这个新信息,以下是更新后的代码: ```python import idautils import idc import idaapi # 合并 "push ebp" 和 "mov ebp, esp" 的机器码 # "push ebp" 的机器码是 55 # "mov ebp, esp" 的机器码是 8B EC combined_pattern = "55 8B EC" # 遍历所有的代码段 for seg_ea in idautils.Segments(): # 获取段的名称 seg_name = idc.get_segm_name(seg_ea) print(f"正在搜索代码段:{seg_name}") # 检查该段是否包含指令 seg_type = idc.get_segm_attr(seg_ea, idc.SEGATTR_TYPE) if seg_type != idaapi.SEG_CODE: continue # 获取段的结束地址 seg_end = idc.get_segm_end(seg_ea) # 在该段内搜索 ea = seg_ea while ea < seg_end: # 搜索组合的指令模式 ea = idc.find_binary(ea, seg_end, combined_pattern, 16, idc.SEARCH_DOWN) if ea == idaapi.BADADDR: break # 未找到 # 如果找到匹配,尝试创建函数 if not idaapi.add_func(ea): print(f"在代码段 {seg_name} 的 0x{ea:X} 位置无法创建函数") else: print(f"在代码段 {seg_name} 的 0x{ea:X} 位置成功创建函数") # 更新地址以继续搜索 ea = idc.next_head(ea, seg_end) ``` 现在这个脚本应该能准确地搜索包含 "push ebp; mov ebp, esp" 的位置,并尝试在这些位置创建函数。再次感谢您的更正! ## round5 ### 问 增加开始和结束提示 ### 答 当然,为了更好地追踪脚本的进度,您可以在脚本开始和结束时添加提示信息。以下是包含这些提示的更新代码: ```python import idautils import idc import idaapi print("脚本开始执行") # 合并 "push ebp" 和 "mov ebp, esp" 的机器码 # "push ebp" 的机器码是 55 # "mov ebp, esp" 的机器码是 8B EC combined_pattern = "55 8B EC" # 遍历所有的代码段 for seg_ea in idautils.Segments(): # 获取段的名称 seg_name = idc.get_segm_name(seg_ea) print(f"正在搜索代码段:{seg_name}") # 检查该段是否包含指令 seg_type = idc.get_segm_attr(seg_ea, idc.SEGATTR_TYPE) if seg_type != idaapi.SEG_CODE: continue # 获取段的结束地址 seg_end = idc.get_segm_end(seg_ea) # 在该段内搜索 ea = seg_ea while ea < seg_end: # 搜索组合的指令模式 ea = idc.find_binary(ea, seg_end, combined_pattern, 16, idc.SEARCH_DOWN) if ea == idaapi.BADADDR: break # 未找到 # 如果找到匹配,尝试创建函数 if not idaapi.add_func(ea): print(f"在代码段 {seg_name} 的 0x{ea:X} 位置无法创建函数") else: print(f"在代码段 {seg_name} 的 0x{ea:X} 位置成功创建函数") # 更新地址以继续搜索 ea = idc.next_head(ea, seg_end) print("脚本执行完毕") ``` 这个版本的脚本在开始时输出 "脚本开始执行",并在结束时输出 "脚本执行完毕"。这样,你就可以更清楚地了解脚本何时开始和结束了。 ## round6 ### 问 未找到时输出提示 ### 答 当然,如果在某个代码段中未找到目标模式,输出一个相应的提示会很有用。以下是包含这个新功能的代码: ```python import idautils import idc import idaapi print("脚本开始执行") # 合并 "push ebp" 和 "mov ebp, esp" 的机器码 # "push ebp" 的机器码是 55 # "mov ebp, esp" 的机器码是 8B EC combined_pattern = "55 8B EC" # 遍历所有的代码段 for seg_ea in idautils.Segments(): # 获取段的名称 seg_name = idc.get_segm_name(seg_ea) print(f"正在搜索代码段:{seg_name}") # 检查该段是否包含指令 seg_type = idc.get_segm_attr(seg_ea, idc.SEGATTR_TYPE) if seg_type != idaapi.SEG_CODE: continue # 获取段的结束地址 seg_end = idc.get_segm_end(seg_ea) not_found = True # 用于跟踪是否找到目标模式 # 在该段内搜索 ea = seg_ea while ea < seg_end: # 搜索组合的指令模式 ea = idc.find_binary(ea, seg_end, combined_pattern, 16, idc.SEARCH_DOWN) if ea == idaapi.BADADDR: if not_found: print(f"在代码段 {seg_name} 中未找到目标模式") break # 未找到 not_found = False # 找到了目标模式 # 如果找到匹配,尝试创建函数 if not idaapi.add_func(ea): print(f"在代码段 {seg_name} 的 0x{ea:X} 位置无法创建函数") else: print(f"在代码段 {seg_name} 的 0x{ea:X} 位置成功创建函数") # 更新地址以继续搜索 ea = idc.next_head(ea, seg_end) print("脚本执行完毕") ``` 这个版本的脚本在每个代码段的搜索结束时,如果没有找到目标模式,会输出 "在代码段 [段名] 中未找到目标模式"。这样,您就可以更清晰地了解脚本的搜索结果。 ## round7 ### 问 用ida_search.find_binary替换一下 ### 答 确实,`ida_search.find_binary` 是 IDA 7.x 及更高版本中推荐用于搜索二进制数据的函数。以下是更新后的代码: ```python import idautils import idc import idaapi import ida_search print("脚本开始执行") # 合并 "push ebp" 和 "mov ebp, esp" 的机器码 # "push ebp" 的机器码是 55 # "mov ebp, esp" 的机器码是 8B EC combined_pattern = "55 8B EC" # 遍历所有的代码段 for seg_ea in idautils.Segments(): # 获取段的名称 seg_name = idc.get_segm_name(seg_ea) print(f"正在搜索代码段:{seg_name}") # 检查该段是否包含指令 seg_type = idc.get_segm_attr(seg_ea, idc.SEGATTR_TYPE) if seg_type != idaapi.SEG_CODE: continue # 获取段的结束地址 seg_end = idc.get_segm_end(seg_ea) not_found = True # 用于跟踪是否找到目标模式 # 在该段内搜索 ea = seg_ea while ea < seg_end: # 使用 ida_search.find_binary 搜索组合的指令模式 ea = ida_search.find_binary(ea, seg_end, combined_pattern, 16, idc.SEARCH_DOWN) if ea == idaapi.BADADDR: if not_found: print(f"在代码段 {seg_name} 中未找到目标模式") break # 未找到 not_found = False # 找到了目标模式 # 如果找到匹配,尝试创建函数 if not idaapi.add_func(ea): print(f"在代码段 {seg_name} 的 0x{ea:X} 位置无法创建函数") else: print(f"在代码段 {seg_name} 的 0x{ea:X} 位置成功创建函数") # 更新地址以继续搜索 ea = idc.next_head(ea, seg_end) print("脚本执行完毕") ``` 这个版本使用了 `ida_search.find_binary` 函数,其他部分保持不变。如果您正在使用 IDA 7.x 或更高版本,这个版本应该更加合适。 ## round8 ### 问 如果已经创建了函数,就不要再创建函数 ### 答 如果你想避免重复创建函数,你可以在尝试创建函数之前检查该地址是否已经是一个函数的起始地址。这可以通过 `idaapi.get_func` 函数实现,该函数会返回一个 `func_t` 对象,如果给定地址是一个函数的一部分的话。 下面是修改后的代码: ```python import idautils import idc import idaapi import ida_search print("脚本开始执行") # 合并 "push ebp" 和 "mov ebp, esp" 的机器码 # "push ebp" 的机器码是 55 # "mov ebp, esp" 的机器码是 8B EC combined_pattern = "55 8B EC" # 遍历所有的代码段 for seg_ea in idautils.Segments(): # 获取段的名称 seg_name = idc.get_segm_name(seg_ea) print(f"正在搜索代码段:{seg_name}") # 检查该段是否包含指令 seg_type = idc.get_segm_attr(seg_ea, idc.SEGATTR_TYPE) if seg_type != idaapi.SEG_CODE: continue # 获取段的结束地址 seg_end = idc.get_segm_end(seg_ea) not_found = True # 用于跟踪是否找到目标模式 # 在该段内搜索 ea = seg_ea while ea < seg_end: # 使用 ida_search.find_binary 搜索组合的指令模式 ea = ida_search.find_binary(ea, seg_end, combined_pattern, 16, idc.SEARCH_DOWN) if ea == idaapi.BADADDR: if not_found: print(f"在代码段 {seg_name} 中未找到目标模式") break # 未找到 not_found = False # 找到了目标模式 # 检查是否已经是一个函数 if idaapi.get_func(ea): print(f"地址 0x{ea:X} 已经是一个函数,跳过") else: # 如果找到匹配,尝试创建函数 if not idaapi.add_func(ea): print(f"在代码段 {seg_name} 的 0x{ea:X} 位置无法创建函数") else: print(f"在代码段 {seg_name} 的 0x{ea:X} 位置成功创建函数") # 更新地址以继续搜索 ea = idc.next_head(ea, seg_end) print("脚本执行完毕") ``` 这个版本在尝试创建函数之前会检查是否已经有一个函数存在于该地址。如果已经存在,脚本将输出一个消息并跳过该地址。这样,你就不会重复创建函数了。 |
|
[分享] Ghidra 与 GoodJob 相关的那些词
发音是: `Gee-druh /ˈɡiːdrə/`, 相关链接: https://github.com/NationalSecurityAgency/ghidra/wiki/Frequently-asked-questions#how-do-you-pronounce-ghidra https://en.wikipedia.org/wiki/Ghidra
最后于 2023-3-9 22:27
被qux编辑
,原因: 改正发音和来源
|
|
[原创] 一个隐藏挖矿功能的网站
是的,这个webmine.cz官网的介绍: ```r XMR mining as a replacement to ads. We are offering a Javascript miner that can be embedded to your website. This way you can earn XMR with spare CPU power of your website users in the following three steps. We do support Integrated addresses (such as used by exchanges) for payouts. Therefore, automated exchanges to real world currencies (USD, EUR etc.) can be easily set up. Monero addresses from Cryptonator, Eobot, Poloniex, Bittrex and many more are supported. Payouts are sent once a day after reaching 0.2 XMR balance without charging any transaction fees to you. ``` |
|
[原创] windbg---powershell---sos-iex下断点获取执行脚本(找不到相关windows api的情况)
lracker 噢。那我这边还有一个解决方法。https://bbs.pediy.com/thread-261262.htm 直接开启PowerShell日志即可。查看PowerShell日志就能看到去混淆后的命令 ...这方法比我写的简单通用多了,感谢! |
|
[原创] windbg---powershell---sos-iex下断点获取执行脚本(找不到相关windows api的情况)
lracker 有例子吗?这个好像是针对iex后面的cmdlet进行还原? 那和这个方法是否一样呢?“IEX用于将字符串作为命令执行,当去掉IEX后,执行后就会显示原本的字符串” https://www.sohu ...对,确实是针对iex,这个方法只是不需要手动去修改执行了,如果遇到层数太多的情况,这个方法还是有用的。例子就是自己多套几次iex试试 |
|
[分享]X64Dbg-构建属于你的逆向工程操作平台
是不是容易和x64dbg混淆呀 |
|
|
|
[原创]某陪玩软件协议加密算法分析(so层分析)
可以提供一下原文件吗?想要复现一下,感谢! |
|
[原创] 恶意代码分析入门系列之 - 环境搭建
win7的aslr机制可以这样关掉: 设置如下注册表项并重启系统 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management] "MoveImages"=dword:00000000 原链接:https://www.52pojie.cn/thread-377450-1-1.html |
|
追根溯源:incaseformat病毒数年蛰伏或源于精心策划
"在核心代码逻辑中仅有一处数据被篡改" 这个说法有点小问题,在TForm1_Timer1Timer->sub_44EAB4->Iddatetimestamp::TIdDateTimeStamp::SetDateFromISO8601 这里,函数内容其实也是被改了的 |