6.2 输出含有 MOVS 指令的函数

当寻找使用了一些漏洞函数的代码时,诸如 strcpy 之类,相对于简单地使用函数来说,您可能需要更进一步做相关处理,还要识别一些使用了 movs 族(movsb,movsd,等)指令的函数。这份插件会遍历所有函数,并搜索任何一条类 movs 指令。

//
// movsfinder.cpp
//
#include <ida.hpp>
#include <idp.hpp>
#include <loader.hpp>
#include <allins.hpp>
int IDAP_init(void)
{
// Only support x86 architecture
if(strncmp(inf.procName, "metapc", 8) != 0) {
error("Only x86 binary type supported, sorry.");
return PLUGIN_SKIP;
}
return PLUGIN_KEEP;
}
void IDAP_term(void)
{
return;
}
void IDAP_run(int arg)
{
// Instructions we're interested in. NN_movs covers movsd,
// movsw, etc.
int movinstrs[] = { NN_movsx, NN_movsd, NN_movs, 0 };
// Loop through all segments
for (int s = 0; s < get_segm_qty(); s++) {
segment_t *seg = getnseg(s);
// We are only interested in segments containing code.
if (seg->type == SEG_CODE) {
// Loop through each function
for (int x = 0; x < get_func_qty(); x++) {
func_t *f = getn_func(x);
char funcName[MAXSTR];
// Get the function name
get_func_name(f->startEA, funcName, sizeof(funcName)-1);
// Loop through the instructions in each function
for (ea_t addr = f->startEA; addr < f->endEA; addr++) {
// Get the flags for this address
flags_t flags = getFlags(addr);
// Only look at the address if it's a head byte, i.e.
// the start of an instruction and is code.
if (isHead(flags) && isCode(flags)) {
char mnem[MAXSTR];
// Fill the cmd structure with the disassembly of
// the current address and get the mnemonic text.
ua_mnem(addr, mnem, sizeof(mnem)-1);
// Check the mnemonic of the address against all
// mnemonics we're interested in.
for (int i = 0; movinstrs[i] != 0; i++) {
if (cmd.itype == movinstrs[i])
msg("%s: found %s at %a!\n", funcName, mnem, addr);
}
}
}
}
}
}
return;
}
char IDAP_comment[] = "MOVSx Instruction Finder";
char IDAP_help[] =
"Searches for all MOVS-like instructions.\n"
"\n"
"This will display a list of all functions along with\n"
"the movs instruction used within.";
char IDAP_name[] = "MOVSx Instruction Finder";
char IDAP_hotkey[] = "Alt-M";
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
0,
IDAP_init,
IDAP_term,
IDAP_run,
IDAP_comment,
IDAP_help,
IDAP_name,
IDAP_hotkey
};

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:0 次

字数:2186

最后编辑:1 个月前

最近更新:JSmiles

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。