1 #define NO_OBSOLETE_FUNCS
13 #define IS_START(w, y) !strncmp(w, y, strlen(y))
14 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
16 //--------------------------------------------------------------------------
17 static int idaapi init(void)
22 //--------------------------------------------------------------------------
23 static void idaapi term(void)
27 //--------------------------------------------------------------------------
29 static const char *reserved_names[] = {
34 static int is_name_reserved(const char *name)
37 for (i = 0; i < ARRAY_SIZE(reserved_names); i++)
38 if (strcasecmp(name, reserved_names[i]) == 0)
44 static void do_def_line(char *buf, size_t buf_size, const char *line)
48 tag_remove(line, buf, buf_size); // remove color codes
54 memmove(buf, buf + 9, len - 9 + 1); // rm address
57 static void idaapi run(int /*arg*/)
59 // isEnabled(ea) // address belongs to disassembly
60 // ea_t ea = get_screen_ea();
61 // nextaddr(ea) - no worky?
74 // rename global syms which conflict with frame member names
76 func = get_next_func(ea);
79 frame = get_frame(func);
82 for (m = 0; m < (int)frame->memqty; m++)
84 ret = get_member_name(frame->members[m].id, buf, sizeof(buf));
86 msg("%x: member has no name?\n", ea);
89 if (buf[0] == ' ') // what's this?
91 if (IS_START(buf, "arg_") || IS_START(buf, "var_"))
94 if (is_name_reserved(buf)) {
95 msg("%x: renaming '%s'\n", ea, buf);
96 qstrncat(buf, "_", sizeof(buf));
97 ret = set_member_name(frame, frame->members[m].soff, buf);
99 msg("%x: renaming failed\n", ea);
104 tmp_ea = get_name_ea(ea, buf);
105 if (tmp_ea == 0 || tmp_ea == ~0)
108 msg("%x: from %x: renaming '%s'\n", tmp_ea, ea, buf);
109 qstrncat(buf, "_g", sizeof(buf));
110 set_name(tmp_ea, buf);
114 func = get_next_func(ea);
116 ea = get_next_func_addr(func, ea);
119 char *fname = askfile_c(1, NULL, "Save asm file");
122 fout = qfopen(fname, "w");
124 msg("couldn't open '%s'\n", fname);
128 show_wait_box("Saving..");
130 // deal with the beginning
132 int flags = 0; // calc_default_idaplace_flags();
133 linearray_t ln(&flags);
138 n = ln.get_linecnt();
139 for (i = 0; i < n - 1; i++) {
140 do_def_line(buf, sizeof(buf), ln.down());
141 if (strstr(buf, "include"))
145 qfprintf(fout, "%s\n", buf);
146 p = strstr(buf, ".mmx");
148 memcpy(p, ".xmm", 4);
150 qfprintf(fout, "%s\n", buf);
156 if ((ea >> 14) != ui_ea_block) {
157 ui_ea_block = ea >> 14;
163 segment_t *seg = getseg(ea);
164 if (!seg || seg->type != SEG_CODE)
166 if (!decode_insn(ea))
169 // note: decode_insn() picks up things like dd, size is then weird
170 //cmd_size = cmd.size;
172 for (o = 0; o < UA_MAXOP; o++) {
173 if (cmd.Operands[o].type == o_void)
180 do_def_line(buf, sizeof(buf), ln.down());
181 qfprintf(fout, "%s\n", buf);
183 ea = next_not_tail(ea); // correct?
184 if (ea == 0 || ea == ~0)
190 n = ln.get_linecnt();
191 for (i = 0; i < n - 1; i++)
194 do_def_line(buf, sizeof(buf), ln.down());
195 qfprintf(fout, "%s\n", buf);
203 msg("%d lines saved.\n", fout_line);
206 //--------------------------------------------------------------------------
208 static const char comment[] = "Generate disassembly lines for one address";
209 static const char help[] = "Generate asm file\n";
210 static const char wanted_name[] = "Save asm";
211 static const char wanted_hotkey[] = "Ctrl-F6";
213 //--------------------------------------------------------------------------
215 // PLUGIN DESCRIPTION BLOCK
217 //--------------------------------------------------------------------------
220 IDP_INTERFACE_VERSION,
223 term, // terminate. this pointer may be NULL.
224 run, // invoke plugin
225 comment, // long comment about the plugin
226 // it could appear in the status line
228 help, // multiline help about the plugin
229 wanted_name, // the preferred short name of the plugin
230 wanted_hotkey // the preferred hotkey to run the plugin
233 // vim:ts=2:shiftwidth=2:expandtab