ida_script

Last updated on March 5, 2024 pm

施工中

常用的库:

  1. idc 封装IDA与IDC函数的兼容性模块
  2. idaapi 允许我们访问更加底层的数据
  3. Idautils IDA提供给我们的一个高级实用的模块
    idaapi.get_func(ea):获取地址 ea 所在的函数的范围和信息1
    idautils.FuncItems(ea):获取地址 ea 所在的函数的所有指令地址的迭代器2
    idc.get_wide_byte(ea):获取地址 ea 处的字节值3
    idc.get_wide_word(ea):获取地址 ea 处的字值3
    idc.get_wide_dword(ea):获取地址 ea 处的双字值3
    idc.get_qword(ea):获取地址 ea 处的四字值3
    idc.get_bytes(ea, size):获取地址 ea 开始的 size 个字节的数据
    idc.get_name(ea, flags):获取地址 ea 处的符号名,flags 参数可以指定不同的命名类型5
    idc.get_func_name(ea):获取地址 ea 所在的函数名6
    idc.get_segm_name(ea):获取地址 ea 所在的段名
    idc.get_struc_name(sid):获取结构体 id 的名称
    idc.get_member_name(sid, offset):获取结构体 id 中偏移量为 offset 的成员的名称

idc.patch_byte(addr,data) 更改对应地址的值
idaapi.dbg_read_memory(addr , addr) 它可以接受一个地址和一个长度作为参数,然后返回一个字节序列,表示从该地址开始的内存数据。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import idc
dict ={'byte_1FD0': '0x98', 'byte_1FD1': '0x5D', 'byte_1FD3': '0x61', 'byte_1FD4': '0xFB', 'byte_1FD2': '0xB7', 'byte_1FD5': '0xD2', 'byte_1FD6': '0x23', 'byte_1FD7': '0xC4', 'byte_1FD8': '0x1F', 'byte_1FD9': '0xBB', 'byte_1FDA': '0xB4', 'byte_1FDB': '0x27', 'byte_1FDC': '0x60', 'byte_1FDD': '0xB', 'byte_1FDE': '0xA', 'byte_1FDF': '0x71', 'byte_1FE0': '0xFA', 'byte_1FE1': '0x95', 'byte_1FE2': '0x93', 'byte_1FED': '0x8F', 'byte_1FE3': '0x35', 'byte_1FE4': '0x68', 'byte_1FE5': '0x7F', 'byte_1FE6': '0x4A', 'byte_1FE7': '0x1E', 'byte_1FE8': '0x80', 'byte_1FE9': '0x5D', 'byte_1FEA': '0xC6', 'byte_1FEB': '0x74', 'byte_1FEC': '0xFC', 'byte_1FEE': '0xBA', 'byte_1FEF': '0xF1', 'byte_1FF0': '0xD1', 'byte_1FF1': '0xF5', 'byte_1FF2': '0x6B', 'byte_2040': '0xEE', 'byte_2041': '0xF3', 'byte_2042': '0x29', 'byte_2043': '0xD8', 'byte_2044': '0x21', 'byte_2045': '0xCE', 'byte_2046': '0x8A', 'byte_2047': '0x18', 'byte_2048': '0xE7', 'byte_2049': '0xF7', 'byte_204A': '0x86', 'byte_204B': '0x2E', 'byte_204D': '0xE', 'byte_204E': '0x98', 'byte_204F': '6', 'byte_204C': '0x78', 'byte_2050': '0x7E', 'byte_2051': '0x22', 'byte_2052': '0x50', 'byte_2053': '0xC0', 'byte_2054': '0x9B', 'byte_2055': '0xDE', 'byte_2056': '0xE3', 'byte_2057': '0xB2', 'byte_2058': '0xC5', 'byte_2059': '0x81', 'byte_205A': '0x35', 'byte_205B': '0x4D', 'byte_205C': '0x96', 'byte_205D': '0xAB', 'byte_205E': '0x84', 'byte_205F': '0xEF', 'byte_2061': '0xA', 'byte_2060': '0xA9', 'byte_2062': '0xBF', 'byte_2064': '0x18', 'byte_2063': '0x19', 'byte_2065': '0x5E', 'byte_2067': '0x6B', 'byte_2066': '2', 'byte_2068': '0x41', 'byte_2069': '0xE5', 'byte_206A': '0x62', 'byte_206C': '0xC1', 'byte_206B': '0x2D', 'byte_206D': '0x68', 'byte_206E': '0x32', 'byte_206F': '0x5A', 'byte_2071': '0x2E', 'byte_2070': '0xA9', 'byte_2072': '0x1A', 'byte_2073': '0x62', 'byte_2074': '0xC8', 'byte_2075': '0xBD', 'byte_2076': '0x92', 'byte_2077': '0x35', 'byte_2078': '0x26', 'byte_2079': '0x6E', 'byte_207A': '0x91', 'byte_207B': '0xF0', 'byte_207C': '0xD', 'byte_207D': '0xE6', 'byte_207E': '0x54', 'byte_207F': '0x54', 'byte_2080': '0xCD', 'byte_2081': '0x15', 'byte_2082': '0x64', 'byte_2083': '0x69', 'byte_2084': '0xC3', 'byte_2085': '0x3E', 'byte_2086': '0x74', 'byte_2000': '0x18', 'byte_2001': '0x61', 'byte_2002': '0xD2', 'byte_2003': '0x1E', 'byte_2004': '0xDF', 'byte_2005': '0x1C', 'byte_2006': '0x15', 'byte_2007': '0x1B', 'byte_2008': '0x75', 'byte_2009': '0x58', 'byte_200A': '0x99', 'byte_200D': '6', 'byte_200B': '0xB8', 'byte_200C': '0x34', 'byte_200E': '0x80', 'byte_200F': '0x1A', 'byte_2010': '0xDF', 'byte_2011': '0x4A', 'byte_2012': '9', 'byte_2013': '0x1B', 'byte_2014': '0x5E', 'byte_2015': '0x85', 'byte_2016': '0x8D', 'byte_2017': '0xC3', 'byte_2018': '0x42', 'byte_2019': '0x73', 'byte_201A': '0xF1', 'byte_201B': '0xDA', 'byte_201C': '0xEF', 'byte_201D': '0x6E', 'byte_201E': '0x27', 'byte_201F': '0x5C', 'byte_2020': '0x6E', 'byte_2021': '0x1A', 'byte_2022': '0x52', 'byte_2023': '0x93', 'byte_2025': '0xC6', 'byte_2024': '0xD3', 'byte_2027': '7', 'byte_2028': '0x71', 'byte_202A': '0xB7', 'byte_2029': '0x6B', 'byte_2026': '0xF5', 'byte_202B': '0x31', 'byte_202C': '0xAC', 'byte_202D': '0x14', 'byte_202E': '0x1B', 'byte_202F': '0x5B', 'byte_2030': '0x5A', 'byte_2031': '0x25', 'byte_2032': '0xBE', 'byte_2033': '0x83', 'byte_2034': '0x54', 'byte_2035': '0x2C', 'byte_2036': '0xAE', 'byte_2037': '0xA7', 'byte_2038': '0xD3'}
# 定义起始和结束地址
start = 0x1FD0
end = 0x2100
i = 0
# 遍历地址范围
for addr in range(start, end):
# 获取并打印地址,字节值,反汇编指令,函数名,段名等信息
name = idc.get_name(addr)
if name not in dict:
continue
byte = idc.get_wide_byte(addr)
idc.patch_byte(addr, int(dict[name],16) ^ byte)

i=i+1
print(i)

输出指定地址内的指令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import idc
start = 0x401447
end = 0x401500
addr = start
i = 0
# 遍历地址范围
while addr < end:
# 获取并打印地址,字节值,反汇编指令,函数名,段名等信息
name = idc.get_name(addr)
disasm = idc.GetDisasm(addr)

byte = idc.get_wide_byte(addr)
print(hex(addr),disasm)
size = idc.get_item_size(addr)
i=i+1
addr = addr + size
print(i)

ida_script
https://txpoki.github.io/2024/03/04/ida-script/
Author
John Doe
Posted on
March 4, 2024
Updated on
March 5, 2024
Licensed under