plugin: add hints on 'jmp $5' for translate
[ia32rtools.git] / ida / saveasm / saveasm.cpp
1 /*
2  * ia32rtools
3  * (C) notaz, 2013,2014
4  *
5  * This work is licensed under the terms of 3-clause BSD license.
6  * See COPYING file in the top-level directory.
7  */
8
9 #define NO_OBSOLETE_FUNCS
10 #include <ida.hpp>
11 #include <idp.hpp>
12 #include <bytes.hpp>
13 #include <loader.hpp>
14 #include <kernwin.hpp>
15
16 #include <name.hpp>
17 #include <frame.hpp>
18 #include <struct.hpp>
19 #include <offset.hpp>
20 #include <auto.hpp>
21 #include <intel.hpp>
22
23 #define IS_START(w, y) !strncmp(w, y, strlen(y))
24 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
25
26 static char **name_cache;
27 static size_t name_cache_size;
28
29 // non-local branch targets
30 static ea_t *nonlocal_bt;
31 static int nonlocal_bt_alloc;
32 static int nonlocal_bt_cnt;
33
34 //--------------------------------------------------------------------------
35 static int idaapi init(void)
36 {
37   return PLUGIN_OK;
38 }
39
40 //--------------------------------------------------------------------------
41 static void idaapi term(void)
42 {
43   size_t i;
44
45   if (nonlocal_bt != NULL) {
46     free(nonlocal_bt);
47     nonlocal_bt = NULL;
48   }
49   nonlocal_bt_alloc = 0;
50
51   if (name_cache != NULL) {
52     for (i = 0; i < name_cache_size; i++)
53       free(name_cache[i]);
54     free(name_cache);
55     name_cache = NULL;
56   }
57   name_cache_size = 0;
58 }
59
60 //--------------------------------------------------------------------------
61
62 static const char *reserved_names[] = {
63   "name",
64   "type",
65   "offset",
66   "aam",
67   "text",
68   "size",
69   "c",
70   "align",
71 };
72
73 static int is_name_reserved(const char *name)
74 {
75   int i;
76   for (i = 0; i < ARRAY_SIZE(reserved_names); i++)
77     if (strcasecmp(name, reserved_names[i]) == 0)
78       return 1;
79
80   return 0;
81 }
82
83 static int nonlocal_bt_cmp(const void *p1, const void *p2)
84 {
85   const ea_t *e1 = (const ea_t *)p1, *e2 = (const ea_t *)p2;
86   return *e1 - *e2;
87 }
88
89 static void nonlocal_add(ea_t ea)
90 {
91   if (nonlocal_bt_cnt >= nonlocal_bt_alloc) {
92     nonlocal_bt_alloc += nonlocal_bt_alloc * 2 + 64;
93     nonlocal_bt = (ea_t *)realloc(nonlocal_bt,
94       nonlocal_bt_alloc * sizeof(nonlocal_bt[0]));
95     if (nonlocal_bt == NULL) {
96       msg("OOM\n");
97       return;
98     }
99   }
100   nonlocal_bt[nonlocal_bt_cnt++] = ea;
101 }
102
103 // is instruction a (un)conditional jump (not call)?
104 static int is_insn_jmp(uint16 itype)
105 {
106   return itype == NN_jmp || (NN_ja <= itype && itype <= NN_jz);
107 }
108
109 static void do_def_line(char *buf, size_t buf_size, const char *line,
110   ea_t ea)
111 {
112   ea_t *ea_ret;
113   char *p;
114   int len;
115
116   tag_remove(line, buf, buf_size); // remove color codes
117   len = strlen(buf);
118   if (len < 9) {
119     buf[0] = 0;
120     return;
121   }
122   memmove(buf, buf + 9, len - 9 + 1); // rm address
123
124   p = buf;
125   while (*p && *p != ' ' && *p != ':')
126     p++;
127   if (*p == ':') {
128     ea_ret = (ea_t *)bsearch(&ea, nonlocal_bt, nonlocal_bt_cnt,
129       sizeof(nonlocal_bt[0]), nonlocal_bt_cmp);
130     if (ea_ret != 0) {
131       if (p[1] != ' ')
132         msg("no trailing blank in '%s'\n", buf);
133       else
134         p[1] = ':';
135     }
136   }
137 }
138
139 static int name_cache_cmp(const void *p1, const void *p2)
140 {
141   // masm ignores case, so do we
142   return stricmp(*(char * const *)p1, *(char * const *)p2);
143 }
144
145 static void rebuild_name_cache(void)
146 {
147   size_t i, newsize;
148   void *tmp;
149
150   // build a sorted name cache
151   newsize = get_nlist_size();
152   if (newsize > name_cache_size) {
153     tmp = realloc(name_cache, newsize * sizeof(name_cache[0]));
154     if (tmp == NULL) {
155       msg("OOM for name cache\n");
156       return;
157     }
158     name_cache = (char **)tmp;
159   }
160   for (i = 0; i < name_cache_size; i++)
161     free(name_cache[i]);
162   for (i = 0; i < newsize; i++)
163     name_cache[i] = strdup(get_nlist_name(i));
164
165   name_cache_size = newsize;
166   qsort(name_cache, name_cache_size, sizeof(name_cache[0]),
167     name_cache_cmp);
168 }
169
170 static void my_rename(ea_t ea, char *name)
171 {
172   char buf[256];
173   char *p, **pp;
174   int n = 0;
175
176   qsnprintf(buf, sizeof(buf), "%s", name);
177   do {
178     p = buf;
179     pp = (char **)bsearch(&p, name_cache, name_cache_size,
180         sizeof(name_cache[0]), name_cache_cmp);
181     if (pp == NULL)
182       break;
183
184     qsnprintf(buf, sizeof(buf), "%s_g%d", name, n);
185     n++;
186   }
187   while (n < 100);
188
189   if (n == 100)
190     msg("rename failure? '%s'\n", name);
191
192   do_name_anyway(ea, buf);
193   rebuild_name_cache();
194 }
195
196 static void make_align(ea_t ea)
197 {
198   ea_t tmp_ea;
199   int n;
200
201   tmp_ea = next_head(ea, inf.maxEA);
202   if ((tmp_ea & 0x03) == 0) {
203     n = calc_max_align(tmp_ea);
204     if (n > 4) // masm doesn't like more..
205       n = 4;
206     msg("%x: align %d\n", ea, 1 << n);
207     do_unknown(ea, DOUNK_SIMPLE);
208     doAlign(ea, tmp_ea - ea, n);
209   }
210 }
211
212 static void idaapi run(int /*arg*/)
213 {
214   // isEnabled(ea) // address belongs to disassembly
215   // ea_t ea = get_screen_ea();
216   // extern foo;
217   // foo = DecodeInstruction(ScreenEA());
218   FILE *fout = NULL;
219   int fout_line = 0;
220   char buf[MAXSTR];
221   char buf2[MAXSTR];
222   const char *name;
223   struc_t *frame;
224   func_t *func;
225   ea_t ui_ea_block = 0, ea_size;
226   ea_t tmp_ea, target_ea;
227   ea_t ea;
228   flags_t ea_flags;
229   uval_t idx;
230   int i, o, m, n;
231   int ret;
232   char **pp;
233   char *p;
234
235   nonlocal_bt_cnt = 0;
236
237   // get rid of structs, masm doesn't understand them
238   idx = get_first_struc_idx();
239   while (idx != BADNODE) {
240     tid_t tid = get_struc_by_idx(idx);
241     struc_t *struc = get_struc(tid);
242     get_struc_name(tid, buf, sizeof(buf));
243     msg("removing struct '%s'\n", buf);
244     //del_struc_members(struc, 0, get_max_offset(struc));
245     del_struc(struc);
246
247     idx = get_first_struc_idx();
248   }
249
250   rebuild_name_cache();
251
252   // 1st pass: walk through all funcs
253   ea = inf.minEA;
254   func = get_func(ea);
255   while (func != NULL)
256   {
257     func_tail_iterator_t fti(func);
258     if (!fti.main()) {
259       msg("%x: func_tail_iterator_t main failed\n", ea);
260       return;
261     }
262     const area_t &f_area = fti.chunk();
263     ea = f_area.startEA;
264
265     // rename global syms which conflict with frame member names
266     frame = get_frame(func);
267     if (frame != NULL)
268     {
269       for (m = 0; m < (int)frame->memqty; m++)
270       {
271         ret = get_member_name(frame->members[m].id, buf, sizeof(buf));
272         if (ret <= 0) {
273           msg("%x: member has no name?\n", ea);
274           return;
275         }
276         if (buf[0] == ' ') // what's this?
277           continue;
278         if (IS_START(buf, "arg_") || IS_START(buf, "var_"))
279           continue;
280
281         // check for dupe names
282         int m1, dupe = 0;
283         for (m1 = 0; m1 < m; m1++) {
284           get_member_name(frame->members[m1].id, buf2, sizeof(buf2));
285           if (stricmp(buf, buf2) == 0)
286             dupe = 1;
287         }
288
289         if (is_name_reserved(buf) || dupe) {
290           msg("%x: renaming '%s'\n", ea, buf);
291           qstrncat(buf, "_", sizeof(buf));
292           ret = set_member_name(frame, frame->members[m].soff, buf);
293           if (!ret) {
294             msg("%x: renaming failed\n", ea);
295             return;
296           }
297         }
298
299         p = buf;
300         pp = (char **)bsearch(&p, name_cache, name_cache_size,
301               sizeof(name_cache[0]), name_cache_cmp);
302         if (pp == NULL)
303           continue;
304
305         tmp_ea = get_name_ea(BADADDR, *pp);
306         msg("%x: renaming '%s' because of '%s' at %x\n",
307           tmp_ea, *pp, buf, ea);
308         my_rename(tmp_ea, *pp);
309       }
310     }
311
312     // detect tailcalls to next func with 'jmp $+5' (offset 0)
313     if (f_area.endEA - f_area.startEA >= 5
314       && decode_insn(f_area.endEA - 5) && cmd.itype == NN_jmp
315       && cmd.Operands[0].type == o_near
316       && cmd.Operands[0].addr == f_area.endEA
317       && get_name(BADADDR, f_area.endEA, buf, sizeof(buf))
318       && get_cmt(f_area.endEA - 5, false, buf2, sizeof(buf2)) <= 0)
319     {
320       qsnprintf(buf2, sizeof(buf2), "sctpatch: jmp %s", buf);
321       set_cmt(f_area.endEA - 5, buf2, false);
322     }
323
324     func = get_next_func(ea);
325   }
326
327   // 2nd pass over whole .text and .(ro)data segments
328   for (ea = inf.minEA; ea != BADADDR; ea = next_head(ea, inf.maxEA))
329   {
330     segment_t *seg = getseg(ea);
331     if (!seg)
332       break;
333     if (seg->type == SEG_XTRN)
334       continue;
335     if (seg->type != SEG_CODE && seg->type != SEG_DATA)
336       break;
337
338     ea_flags = get_flags_novalue(ea);
339     func = get_func(ea);
340     if (isCode(ea_flags))
341     {
342       if (!decode_insn(ea)) {
343         msg("%x: decode_insn() failed\n", ea);
344         continue;
345       }
346
347       // masm doesn't understand IDA's float/xmm types
348       if (cmd.itype == NN_fld || cmd.itype == NN_fst
349         || cmd.itype == NN_movapd || cmd.itype == NN_movlpd)
350       {
351         for (o = 0; o < UA_MAXOP; o++) {
352           if (cmd.Operands[o].type == o_void)
353             break;
354
355           if (cmd.Operands[o].type == o_mem) {
356             tmp_ea = cmd.Operands[o].addr;
357             flags_t tmp_ea_flags = get_flags_novalue(tmp_ea);
358             // ..but base float is ok..
359             int is_flt = isDwrd(tmp_ea_flags) || isFloat(tmp_ea_flags);
360             if (!is_flt && !isUnknown(tmp_ea_flags))
361             {
362               buf[0] = 0;
363               get_name(ea, tmp_ea, buf, sizeof(buf));
364               msg("%x: undefining %x '%s'\n", ea, tmp_ea, buf);
365               do_unknown(tmp_ea, DOUNK_EXPAND);
366             }
367           }
368         }
369       }
370       else if (cmd.itype == NN_lea) {
371         // detect code alignment
372         if (cmd.Operands[0].reg == cmd.Operands[1].reg
373           && cmd.Operands[1].type == o_displ
374           && cmd.Operands[1].addr == 0)
375         {
376           // lea eax, [eax+0]
377           make_align(ea);
378         }
379         else if (!isDefArg1(ea_flags)
380           && cmd.Operands[1].type == o_mem // why o_mem?
381           && cmd.Operands[1].dtyp == dt_dword)
382         {
383           if (inf.minEA <= cmd.Operands[1].addr
384             && cmd.Operands[1].addr < inf.maxEA)
385           {
386             // lea to segments, like ds:58D6A8h[edx*8]
387             msg("%x: lea offset to %x\n", ea, cmd.Operands[1].addr);
388             op_offset(ea, 1, REF_OFF32);
389           }
390           else
391           {
392             // ds:0[eax*8] -> [eax*8+0]
393             msg("%x: dropping ds: for %x\n", ea, cmd.Operands[1].addr);
394             op_hex(ea, 1);
395           }
396         }
397       }
398       else if (cmd.itype == NN_mov && cmd.segpref == 0x1e // 2e?
399         && cmd.Operands[0].type == o_reg
400         && cmd.Operands[1].type == o_reg
401         && cmd.Operands[0].dtyp == cmd.Operands[1].dtyp
402         && cmd.Operands[0].reg == cmd.Operands[1].reg)
403       {
404         // db 2Eh; mov eax, eax
405         make_align(ea);
406       }
407
408       // find non-local branches
409       if (is_insn_jmp(cmd.itype) && cmd.Operands[0].type == o_near)
410       {
411         target_ea = cmd.Operands[0].addr;
412         if (func == NULL)
413           nonlocal_add(target_ea);
414         else {
415           ret = get_func_chunknum(func, target_ea);
416           if (ret != 0) {
417             // a jump to another func or chunk
418             // check if it lands on func start
419             if (!isFunc(get_flags_novalue(target_ea)))
420               nonlocal_add(target_ea);
421           }
422         }
423       }
424     }
425     else { // not code
426       int do_undef = 0;
427       ea_size = get_item_size(ea);
428
429       if (func == NULL && isOff0(ea_flags)) {
430         for (tmp_ea = 0; tmp_ea < ea_size; tmp_ea += 4)
431           nonlocal_add(get_long(ea + tmp_ea));
432       }
433
434       // IDA vs masm float/mmx/xmm type incompatibility
435       if (isDouble(ea_flags) || isTbyt(ea_flags)
436        || isPackReal(ea_flags))
437       {
438         do_undef = 1;
439       }
440       else if (isOwrd(ea_flags)) {
441         buf[0] = 0;
442         get_name(BADADDR, ea, buf, sizeof(buf));
443         if (IS_START(buf, "xmm"))
444           do_undef = 1;
445       }
446       // masm doesn't understand IDA's unicode
447       else if (isASCII(ea_flags) && ea_size >= 4
448         && (get_long(ea) & 0xff00ff00) == 0) // lame..
449       {
450         do_undef = 1;
451       }
452       // masm doesn't understand large aligns
453       else if (isAlign(ea_flags) && ea_size > 0x10) {
454         msg("%x: undefining align %d\n", ea, ea_size);
455         do_unknown(ea, DOUNK_EXPAND);
456       }
457
458       if (do_undef) {
459         buf[0] = 0;
460         get_name(BADADDR, ea, buf, sizeof(buf));
461         msg("%x: undefining '%s'\n", ea, buf);
462         do_unknown(ea, DOUNK_EXPAND);
463       }
464     }
465   }
466
467   // check namelist for reserved names
468   n = get_nlist_size();
469   for (i = 0; i < n; i++) {
470     ea = get_nlist_ea(i);
471     name = get_nlist_name(i);
472     if (name == NULL) {
473       msg("%x: null name?\n", ea);
474       continue;
475     }
476
477     // rename vars with '?@' (funcs are ok)
478     int change_qat = 0;
479     ea_flags = get_flags_novalue(ea);
480     if (!isCode(ea_flags) && strpbrk(name, "?@"))
481       change_qat = 1;
482
483     if (change_qat || is_name_reserved(name)) {
484       msg("%x: renaming name '%s'\n", ea, name);
485       qsnprintf(buf, sizeof(buf), "%s", name);
486
487       if (change_qat) {
488         for (p = buf; *p != 0; p++) {
489           if (*p == '?' || *p == '@') {
490             qsnprintf(buf2, sizeof(buf2), "%02x", (unsigned char)*p);
491             memmove(p + 1, p, strlen(p) + 1);
492             memcpy(p, buf2, 2);
493           }
494         }
495       }
496
497       my_rename(ea, buf);
498     }
499   }
500
501   if (nonlocal_bt_cnt > 1) {
502     qsort(nonlocal_bt, nonlocal_bt_cnt,
503       sizeof(nonlocal_bt[0]), nonlocal_bt_cmp);
504   }
505
506   char *fname = askfile_c(1, NULL, "Save asm file");
507   if (fname == NULL)
508     return;
509   fout = qfopen(fname, "w");
510   if (fout == NULL) {
511     msg("couldn't open '%s'\n", fname);
512     return;
513   }
514
515   show_wait_box("Saving..");
516
517   // deal with the beginning
518   ea = inf.minEA;
519   int flags = 0; // calc_default_idaplace_flags();
520   linearray_t ln(&flags);
521   idaplace_t pl;
522   pl.ea = ea;
523   pl.lnnum = 0;
524   ln.set_place(&pl);
525   n = ln.get_linecnt();
526   for (i = 0; i < n - 1; i++) {
527     do_def_line(buf, sizeof(buf), ln.down(), ea);
528     if (strstr(buf, "include"))
529       continue;
530
531     fout_line++;
532     qfprintf(fout, "%s\n", buf);
533     p = strstr(buf, ".mmx");
534     if (p != NULL) {
535       memcpy(p, ".xmm", 4);
536       fout_line++;
537       qfprintf(fout, "%s\n", buf);
538       continue;
539     }
540     p = strstr(buf, ".model");
541     if (p != NULL) {
542       qstrncpy(p, "include imports.inc", sizeof(buf) - (p - buf));
543       fout_line++;
544       qfprintf(fout, "\n%s\n", buf);
545       i++;
546       break;
547     }
548   }
549   pl.lnnum = i;
550
551   for (;;)
552   {
553     int drop_large = 0, do_rva = 0, set_scale = 0, jmp_near = 0;
554     int word_imm = 0, dword_imm = 0, do_pushf = 0, do_nops = 0;
555
556     if ((ea >> 14) != ui_ea_block) {
557       ui_ea_block = ea >> 14;
558       showAddr(ea);
559       if (wasBreak())
560         break;
561     }
562
563     segment_t *seg = getseg(ea);
564     if (!seg || (seg->type != SEG_CODE && seg->type != SEG_DATA))
565       goto pass;
566
567     ea_flags = get_flags_novalue(ea);
568     if (isCode(ea_flags))
569     {
570       if (!decode_insn(ea))
571         goto pass;
572
573       if (is_insn_jmp(cmd.itype) && cmd.Operands[0].type == o_near
574         && cmd.Operands[0].dtyp == dt_dword)
575       {
576         jmp_near = 1;
577       }
578       else if ((cmd.itype == NN_pushf || cmd.itype == NN_popf)
579         && natop())
580       {
581         do_pushf = 1;
582       }
583
584       for (o = 0; o < UA_MAXOP; o++) {
585         const op_t &opr = cmd.Operands[o];
586         if (opr.type == o_void)
587           break;
588
589         // correct?
590         if (opr.type == o_mem && opr.specval_shorts.high == 0x21)
591           drop_large = 1;
592         if (opr.hasSIB && x86_scale(opr) == 0
593           && x86_index(opr) != INDEX_NONE)
594         {
595           set_scale = 1;
596         }
597         // annoying alignment variant..
598         if (opr.type == o_imm && opr.dtyp == dt_dword
599           && (opr.value < 0x80 || opr.value > 0xffffff80)
600           && cmd.size >= opr.offb + 4)
601         {
602           if (get_long(ea + opr.offb) == opr.value)
603             dword_imm = 1;
604         }
605         else if (opr.type == o_imm && opr.dtyp == dt_word
606           && (opr.value < 0x80 || opr.value > 0xff80)
607           && cmd.size >= opr.offb + 2)
608         {
609           if (get_word(ea + opr.offb) == (ushort)opr.value)
610             word_imm = 1;
611         }
612         else if (opr.type == o_displ && opr.addr == 0
613           && opr.offb != 0 && opr.hasSIB && opr.sib == 0x24)
614         {
615           // uses [esp+0] with 0 encoded into op
616           do_nops++;
617         }
618       }
619     }
620     else { // not code
621       if (isOff0(ea_flags))
622         do_rva = 1;
623     }
624
625 pass:
626     n = ln.get_linecnt();
627     for (i = pl.lnnum; i < n; i++) {
628       do_def_line(buf, sizeof(buf), ln.down(), ea);
629
630       char *fw;
631       for (fw = buf; *fw != 0 && *fw == ' '; )
632         fw++;
633
634       // patches..
635       if (drop_large) {
636         p = strstr(fw, "large ");
637         if (p != NULL)
638           memmove(p, p + 6, strlen(p + 6) + 1);
639       }
640       while (do_rva) {
641         p = strstr(fw, " rva ");
642         if (p == NULL)
643           break;
644         memmove(p + 4 + 3, p + 4, strlen(p + 4) + 1);
645         memcpy(p + 1, "offset", 6);
646       }
647       if (set_scale) {
648         p = strchr(fw, '[');
649         if (p != NULL)
650           p = strchr(p, '+');
651         if (p != NULL && p[1] == 'e') {
652           p += 4;
653           // scale is 1, must specify it explicitly so that
654           // masm chooses the right scaled reg
655           memmove(p + 2, p, strlen(p) + 1);
656           memcpy(p, "*1", 2);
657         }
658       }
659       else if (jmp_near) {
660         p = NULL;
661         if (fw != buf && fw[0] == 'j')
662           p = fw;
663         while (p && *p != ' ')
664           p++;
665         while (p && *p == ' ')
666           p++;
667         if (p != NULL) {
668           memmove(p + 9, p, strlen(p) + 1);
669           memcpy(p, "near ptr ", 9);
670           jmp_near = 0;
671         }
672       }
673       if (word_imm) {
674         p = strstr(fw, ", ");
675         if (p != NULL && '0' <= p[2] && p[2] <= '9') {
676           p += 2;
677           memmove(p + 9, p, strlen(p) + 1);
678           memcpy(p, "word ptr ", 9);
679         }
680       }
681       else if (dword_imm) {
682         p = strstr(fw, ", ");
683         if (p != NULL && '0' <= p[2] && p[2] <= '9') {
684           p += 2;
685           memmove(p + 10, p, strlen(p) + 1);
686           memcpy(p, "dword ptr ", 10);
687         }
688       }
689       else if (do_pushf) {
690         p = strstr(fw, "pushf");
691         if (p == NULL)
692           p = strstr(fw, "popf");
693         if (p != NULL) {
694           p = strchr(p, 'f') + 1;
695           memmove(p + 1, p, strlen(p) + 1);
696           *p = 'd';
697         }
698       }
699
700       if (fw[0] == 'a' && IS_START(fw, "assume cs")) {
701         // "assume cs" causes problems with ext syms
702         memmove(fw + 1, fw, strlen(fw) + 1);
703         *fw = ';';
704       }
705       else if (fw[0] == 'e' && IS_START(fw, "end") && fw[3] == ' ') {
706         fout_line++;
707         qfprintf(fout, "include public.inc\n\n");
708
709         // kill entry point
710         fw[3] = 0;
711       }
712
713       fout_line++;
714       qfprintf(fout, "%s\n", buf);
715     }
716
717     while (do_nops-- > 0)
718       qfprintf(fout, "                nop ; adj\n");
719
720     // note: next_head skips some undefined stuff
721     ea = next_not_tail(ea); // correct?
722     if (ea == BADADDR)
723       break;
724
725     pl.ea = ea;
726     pl.lnnum = 0;
727     ln.set_place(&pl);
728   }
729
730   if (fout != NULL)
731     qfclose(fout);
732   if (fname != NULL)
733     qfree(fname);
734
735   hide_wait_box();
736   msg("%d lines saved.\n", fout_line);
737 }
738
739 //--------------------------------------------------------------------------
740
741 static const char comment[] = "Generate disassembly for nasm";
742 static const char help[] = "Generate asm file\n";
743 static const char wanted_name[] = "Save asm";
744 static const char wanted_hotkey[] = "Shift-S";
745
746 //--------------------------------------------------------------------------
747 //
748 //      PLUGIN DESCRIPTION BLOCK
749 //
750 //--------------------------------------------------------------------------
751 plugin_t PLUGIN =
752 {
753   IDP_INTERFACE_VERSION,
754   0,                    // plugin flags
755   init,                 // initialize
756   term,                 // terminate. this pointer may be NULL.
757   run,                  // invoke plugin
758   comment,              // long comment about the plugin
759                         // it could appear in the status line
760                         // or as a hint
761   help,                 // multiline help about the plugin
762   wanted_name,          // the preferred short name of the plugin
763   wanted_hotkey         // the preferred hotkey to run the plugin
764 };
765
766 // vim:ts=2:shiftwidth=2:expandtab