home *** CD-ROM | disk | FTP | other *** search
- // Make Indexed Jump Table
- // IDC Script for IDA Pro v3.84
- // written by Quine (quine@blacksun.res.cmu.edu)
- // visit Quine's IDA Page at http://surf.to/quine_ida
-
-
- #include <idc.idc>
-
- static main () {
-
- auto base, count, offsets, lookup, index, dest, i, use_enum, _enum, enum_id, name, rc;
- use_enum = 0;
- lookup = Dfirst(ScreenEA());
- if (lookup == BADADDR) {
- Message("Bad lookup!\n");
- return 0;
- }
- base = xtol(AskStr("0","Enter the case base number:"));
- count = xtol(AskStr("0","Enter the count:"));
- offsets = find_next_ijmp(ScreenEA());
- if (offsets == BADADDR) {
- Message("Couldn't find indexed jmp!\n");
- return 0;
- }
-
- _enum = AskStr("","Enter the ENUM name or hit enter to skip:");
- if (_enum!="") {
- enum_id = GetEnum(_enum);
- if (enum_id == -1) {
- Message("Bad enum!\n");
- return 0;
- }
- use_enum = 1;
- }
- for (i=0; i<=count; i++) {
- index = Byte(lookup+i);
- dest = Dword(offsets+index*4);
- if (use_enum) {
- name = form("case %s:", GetConstName(GetConst(enum_id, base+i)));
- } else {
- name = form("case %x:", base+i);
- }
- if ((rc = RptCmt(dest)) != "") {
- name = rc + "\n" + name;
- }
- MakeRptCmt(dest,name);
- }
- }
-
- static find_next_ijmp(ea) {
- auto x;
- for (x=0; x<10; x++) {
- ea = NextNotTail(ea);
- if ((isCode(GetFlags(ea))) && (GetMnem(ea) == "jmp") && (GetOpType(ea,0) == 2)) {
- return Dfirst(ea);
- }
- }
- return BADADDR;
- }
-