#include <idc.idc>
static main()
{
auto seg, current_ea, mnemonic, op1, op2;
for (seg = get_first_seg(); seg != BADADDR; seg = get_next_seg(seg))
{
auto seg_name = get_segm_name(seg);
if (seg_name != ".text" && seg_name != "UPX0")
{
continue;
}
Message("正在处理段: %s (0x%X)\n", seg_name, seg);
auto start_ea = seg;
auto end_ea = get_segm_end(seg);
current_ea = start_ea;
while (current_ea < end_ea && current_ea != BADADDR)
{
mnemonic = print_insn_mnem(current_ea);
op1 = print_operand(current_ea, 0);
op2 = print_operand(current_ea, 1);
if (mnemonic == "movsx" && op2 == "cs:byte0")
{
Message("Target Ins at: 0x%X\n", current_ea);
if (op1 == "eax")
{
patch_byte(current_ea, 0xB8);
}
else if (op1 == "ecx")
{
patch_byte(current_ea, 0xB9);
}
else if (op1 == "edx")
{
patch_byte(current_ea, 0xBA);
}
patch_dword(current_ea + 1, 0);
patch_word(current_ea + 5, 0x9090);
create_insn(current_ea);
}
if (mnemonic == "movsx" && op2 == "cs:byte1")
{
Message("Target Ins at: 0x%X\n", current_ea);
if (op1 == "eax")
{
patch_byte(current_ea, 0xB8);
}
else if (op1 == "ecx")
{
patch_byte(current_ea, 0xB9);
}
else if (op1 == "edx")
{
patch_byte(current_ea, 0xBA);
}
patch_dword(current_ea + 1, 1);
patch_word(current_ea + 5, 0x9090);
create_insn(current_ea);
}
if (mnemonic == "movsx" && op2 == "cs:byte2")
{
Message("Target Ins at: 0x%X\n", current_ea);
if (op1 == "eax")
{
patch_byte(current_ea, 0xB8);
}
else if (op1 == "ecx")
{
patch_byte(current_ea, 0xB9);
}
else if (op1 == "edx")
{
patch_byte(current_ea, 0xBA);
}
patch_dword(current_ea + 1, 2);
patch_word(current_ea + 5, 0x9090);
create_insn(current_ea);
}
if (mnemonic == "movsx" && op2 == "cs:byte3")
{
Message("Target Ins at: 0x%X\n", current_ea);
if (op1 == "eax")
{
patch_byte(current_ea, 0xB8);
}
else if (op1 == "ecx")
{
patch_byte(current_ea, 0xB9);
}
else if (op1 == "edx")
{
patch_byte(current_ea, 0xBA);
}
patch_dword(current_ea + 1, 3);
patch_word(current_ea + 5, 0x9090);
create_insn(current_ea);
}
if (mnemonic == "movsx" && op2 == "cs:byte4")
{
Message("Target Ins at: 0x%X\n", current_ea);
if (op1 == "eax")
{
patch_byte(current_ea, 0xB8);
}
else if (op1 == "ecx")
{
patch_byte(current_ea, 0xB9);
}
else if (op1 == "edx")
{
patch_byte(current_ea, 0xBA);
}
patch_dword(current_ea + 1, 4);
patch_word(current_ea + 5, 0x9090);
create_insn(current_ea);
}
if (mnemonic == "movsx" && op2 == "cs:byte5")
{
Message("Target Ins at: 0x%X\n", current_ea);
if (op1 == "eax")
{
patch_byte(current_ea, 0xB8);
}
else if (op1 == "ecx")
{
patch_byte(current_ea, 0xB9);
}
else if (op1 == "edx")
{
patch_byte(current_ea, 0xBA);
}
patch_dword(current_ea + 1, 5);
patch_word(current_ea + 5, 0x9090);
create_insn(current_ea);
}
if (mnemonic == "movsx" && op2 == "cs:byte6")
{
Message("Target Ins at: 0x%X\n", current_ea);
if (op1 == "eax")
{
patch_byte(current_ea, 0xB8);
}
else if (op1 == "ecx")
{
patch_byte(current_ea, 0xB9);
}
else if (op1 == "edx")
{
patch_byte(current_ea, 0xBA);
}
patch_dword(current_ea + 1, 6);
patch_word(current_ea + 5, 0x9090);
create_insn(current_ea);
}
if (mnemonic == "movsx" && op2 == "cs:byte7")
{
Message("Target Ins at: 0x%X\n", current_ea);
if (op1 == "eax")
{
patch_byte(current_ea, 0xB8);