Changeset 501


Ignore:
Timestamp:
09/08/08 07:21:06 (5 years ago)
Author:
cail
Message:

*HV30*

  • Improvements in dump-xrefs,
  • scan-func_tables improvements,

+ search-language-resources.idc - searches and builds OSD Language Resources and references
+ scan-unicode-pascal.idc - euristic search for Unicode strings and renaming

Location:
branches/cail-digicdv/hv30_analysis/scripts
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/cail-digicdv/hv30_analysis/scripts/_init_sections.idc

    r492 r501  
    88static main() 
    99{ 
     10    memcpy(0x40294, 0x4073FB8, 0x1248); 
     11/* 
    1012    createSegments(); 
    1113 
     
    1517 
    1618    makeNames1(); 
     19//*/ 
    1720} 
    1821 
     
    5962// small RAM segment 
    6063    memcpy(0x419C8, 0x002DB0E4, 0xE4); 
     64 
     65// init_copy_4073FB8_40294_size1248 
     66    memcpy(0x40294, 0x4073FB8, 0x1248); 
     67 
    6168} 
    6269 
  • branches/cail-digicdv/hv30_analysis/scripts/_todo.idc

    r492 r501  
    22 
    33taskCreate_sys xrefs ? 
     4 
     5search copy loops ??? 
     6 
     7 
     8init_main_data_copy_ntsc refs?? 
     9 
     10 
     1117 
     1281 
     13 
     14 
     15 
     16Order: 
     17 
     18 
     19_init_sections.idc 
     20_initial_names.idc 
     21 
     22shell_register.idc 
     23 
     24scan-func_tables.idc 
     25// scan-refs.idc 
     26// scan-strings.idc 
     27search-language-resources.idc 
     28 
     29// call it multiple times 
     30scan-fuctions.idc 
  • branches/cail-digicdv/hv30_analysis/scripts/dump-xrefs.idc

    r492 r501  
    33 
    44#define TRACE 0 
     5 
     6// directory prefix 
    57#define FPREFIX "graphs/" 
    68 
    7 #define SHOW_UNK_DATA 0 
     9// enable unk_ references 
     10#define SHOW_UNK_DATA 1 
     11 
     12// enable showing disassembly line 
     13#define SHOW_DATA_DISASM 0 
     14 
     15// Number of nodes limitation 
     16#define NODES_LIMIT 0 
     17 
     18static is_direction_down() 
     19{ 
     20   auto dir; 
     21 
     22   if (GetArrayId("downIdArray") == -1) return 0; 
     23   else return 1; 
     24} 
     25 
     26#define ZERO_DEPTH 1000 
     27 
    828 
    929// Touchgraph todo: 
     
    1737 */ 
    1838 
    19 static searchTask(start, arr, calleeHash, edgeHash, depth) 
     39static searchTask(start, arr, calleeHash, edgeHash, depth, recurse) 
    2040{ 
    2141  auto x,y, fname, fend; 
     
    2343  auto type; 
    2444  auto name; 
    25    
     45 
    2646  x = GetFunctionAttr(start, FUNCATTR_START); 
    2747  if (x == -1) x = start; 
    2848 
    2949  fend = GetFunctionAttr(start, FUNCATTR_END); 
     50  if (fend == -1) fend = start+4; 
    3051 
    3152  fname = Name(x); //TODO - no-function code refs will be ignored! 
     
    3960  } 
    4061 
    41   if (TRACE) Message("*** " + atoa(start) + "  " + atoa(fend) + " - "+ fname + "\n"); 
     62  if (TRACE) Message(atoa(start) + "  " + atoa(fend) + " - "+ fname + "\n"); 
    4263   
    4364  SetHashLong(arr, fname, x); 
    44   if (depth == 1000) SetHashLong(calleeHash, fname, depth); 
     65  if (depth == ZERO_DEPTH) SetHashLong(calleeHash, fname, depth); 
     66 
     67  if (recurse == 0) return; 
    4568 
    4669  refCount = 1; 
    47  
    48   if (depth >= 1000) { 
    49       for(; x < fend; x = x+2) 
     70   
     71  for(; x < fend; x = x+2) 
     72  { 
     73 
     74      if (is_direction_down() == 1) 
    5075      { 
    51  
    5276          for( y=Rfirst0(x); y != BADADDR; y=Rnext0(x,y) ) 
    5377          { 
     
    6993              SetHashLong(edgeHash, fname+"---"+name, 1); 
    7094 
    71               searchTask(y, arr, calleeHash, edgeHash, depth+1); 
     95              searchTask(y, arr, calleeHash, edgeHash, depth+1, TRUE); 
    7296              refCount = refCount + 1; 
    7397          } 
     98      } 
     99 
     100//      if (is_direction_down() == 1) 
     101      { 
    74102          for(y = Dfirst(x); y != BADADDR; y=Dnext(x,y) ) 
    75103          { 
     
    87115              SetHashLong(edgeHash, fname+"---"+name, 1); 
    88116 
    89               searchTask(y, arr, calleeHash, edgeHash, depth+1); 
     117              searchTask(y, arr, calleeHash, edgeHash, depth+1, (is_direction_down() == 1) ); 
     118 
    90119              refCount = refCount + 1; 
    91120          } 
    92121      } 
    93122  } 
    94 /* 
    95   if (depth <= 1000) 
     123 
     124  if (is_direction_down() == 0) 
    96125  { 
    97126      x = GetFunctionAttr(start, FUNCATTR_START); 
     127      if (x == -1) x = start; 
    98128 
    99129      if (TRACE) Message("* UP " + atoa(start) + "  " + atoa(fend) + " - "+ fname + "\n"); 
     
    114144          SetHashLong(calleeHash, name, depth-1); 
    115145          SetHashLong(edgeHash, name+"---"+fname, 1); 
    116           searchTask(y, arr, calleeHash, edgeHash, depth-1); 
     146          searchTask(y, arr, calleeHash, edgeHash, depth-1, TRUE); 
    117147          refCount = refCount + 1; 
    118148      } 
     
    121151          type = XrefType(); 
    122152          name = GetFunctionName(y); 
    123           name = Name(y); 
    124           if (name == 0){ 
     153          if (name == 0) name = Name(y); 
     154          if (name == 0) { 
    125155            continue; 
    126156            name = atoa(y) + " " + GetDisasm(y); 
     
    128158          SetHashLong(calleeHash, name, depth-1); 
    129159          SetHashLong(edgeHash, name+"---"+fname, 1); 
    130           searchTask(y, arr, calleeHash, edgeHash, depth-1); 
     160          searchTask(y, arr, calleeHash, edgeHash, depth-1, TRUE); 
    131161          refCount = refCount + 1; 
    132162      } 
    133163  } 
    134 */ 
     164 
    135165} 
    136166 
     
    142172  auto length, color, fsize, shape, x, y, label, hint, visible; 
    143173  auto flags, type, depth; 
    144  
    145   fname = GetFunctionName(a); 
    146  
    147   ea = GetFunctionAttr(a, FUNCATTR_START); 
    148    
    149   DeleteArray( GetArrayId("visitedHash") ); 
    150   DeleteArray( GetArrayId("calleeHash") ); 
    151   DeleteArray( GetArrayId("edgeHash") ); 
    152  
    153   visitedHash = CreateArray("visitedHash"); 
    154   calleeHash = CreateArray("calleeHash"); 
    155   edgeHash = CreateArray("edgeHash"); 
    156    
    157   searchTask(ea, visitedHash, calleeHash, edgeHash, 1000); 
    158  
    159     f = fopen(FPREFIX + "xrefs-"+fname+".vna", "w"); 
     174  auto node_addr; 
     175  auto nodes_num; 
     176 
     177    ea = GetFunctionAttr(a, FUNCATTR_START); 
     178    if (ea == -1) ea = a; 
     179 
     180    if (is_direction_down() == 1) 
     181      fname = "xrefs-" + Name(ea); 
     182    else 
     183      fname = "uprefs-" + Name(ea); 
     184     
     185    DeleteArray( GetArrayId("visitedHash") ); 
     186    DeleteArray( GetArrayId("calleeHash") ); 
     187    DeleteArray( GetArrayId("edgeHash") ); 
     188 
     189    visitedHash = CreateArray("visitedHash"); 
     190    calleeHash = CreateArray("calleeHash"); 
     191    edgeHash = CreateArray("edgeHash"); 
     192     
     193    searchTask(ea, visitedHash, calleeHash, edgeHash, ZERO_DEPTH, TRUE); 
     194 
     195 
     196    f = fopen(FPREFIX + fname+".vna", "w"); 
    160197     
    161198    fprintf(f, "*Node data\n"); 
     
    223260 
    224261 
    225     f = fopen(FPREFIX + "xrefs-"+fname+".xml", "w"); 
     262    f = fopen(FPREFIX + fname+".xml", "w"); 
    226263     
    227264    fprintf(f, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); 
    228265    fprintf(f, "<TOUCHGRAPH_LB version='1.20'><NODESET>\n"); 
    229266   
     267    nodes_num = 0; 
    230268    for (t = GetFirstHashKey(calleeHash); t != 0; t = GetNextHashKey(calleeHash, t)) 
    231269    { 
     
    233271        shape = 2; 
    234272        label = t; 
    235         hint = form("0x%x %s", GetHashLong(visitedHash, t), ""); 
     273        node_addr = GetHashLong(visitedHash, t); 
     274        hint = form("<b>0x%x</b> %s", node_addr, ""); 
    236275        visible = "true"; 
    237         depth = GetHashLong(calleeHash, t)-1000; 
    238  
    239         //if (depth == 0) visible = "true"; 
    240  
    241         if (isCode(GetFlags(GetHashLong(visitedHash, t)))) 
    242         { 
    243           fsize = 20 - depth*2; 
    244           if (fsize < 10) fsize = 10; 
     276        depth = GetHashLong(calleeHash, t) - ZERO_DEPTH; 
     277         
     278        nodes_num = nodes_num+1; 
     279        //if (NODES_LIMIT != 0 && nodes_num > NODES_LIMIT) break; 
     280 
     281        if (isCode(GetFlags(node_addr))) 
     282        { 
     283          if (is_direction_down()) 
     284            fsize = 20 - depth*2; 
     285          else 
     286            fsize = 20 + depth*2; 
     287 
     288          if (fsize < 9) fsize = 9; 
    245289          if (fsize > 22) fsize = 22; 
    246           if (!hasUserName(GetFlags(GetHashLong(visitedHash, t)))){ 
     290          if (!hasUserName(GetFlags(node_addr))) 
     291          { 
    247292            color = 0xEE2020; 
    248293          } 
    249294        }else 
    250         if (isASCII(GetFlags(GetHashLong(visitedHash, t)))) 
     295        if (isASCII(GetFlags(node_addr))) 
    251296        { 
    252297          color = 0x6060C0; 
    253298          fsize = 10; 
    254299          shape = 1; 
    255           label = getString(GetHashLong(visitedHash, t)); 
    256           label = replace(label, "&", "@"); 
    257           label = replace(label, "'", "&apos;"); 
    258           label = replace(label, "<", "&lt;"); 
    259           label = replace(label, ">", "&gt;"); 
     300          label = GetString(node_addr, -1, GetStringType(node_addr)); 
    260301          label = replace(label, "\n", ""); 
    261302          label = replace(label, "\r", ""); 
    262           depth = -1; 
     303          depth = -ZERO_DEPTH; 
    263304        }else 
    264305        //if (isData(GetFlags(GetHashLong(visitedHash, t)))) 
     
    267308          fsize = 10; 
    268309          shape = 1; 
    269           if (!hasUserName(GetFlags(GetHashLong(visitedHash, t)))){ 
     310          //if (!hasUserName(GetFlags(node_addr))) { 
     311          if (-1 != strstr(t, "unk_")) { 
    270312            color = 0x70A070; 
    271           } 
    272           label = label + ": " + GetDisasm(GetHashLong(visitedHash, t)); 
    273           depth = -1; 
    274           if (SHOW_UNK_DATA == 0) continue; 
    275         } 
    276         x = 10; 
     313            if (SHOW_UNK_DATA == 0) continue; 
     314          } 
     315          if (SHOW_DATA_DISASM) { 
     316            label = label + ": " + GetDisasm(node_addr); 
     317          } 
     318          depth = -ZERO_DEPTH; 
     319        } 
     320        hint = label + ": " + GetDisasm(node_addr) + "<br><br>" + hint; 
     321 
     322        x = 0; 
    277323        y = 10; 
     324        if (depth == 0) 
     325        { 
     326          x = 100; 
     327          y = 100; 
     328        } 
    278329 
    279330        fprintf(f, "<NODE nodeID='AutoID %s'>\n", t); 
    280331        fprintf(f, " <NODE_LOCATION x='%d' y='%d' visible='%s'/>\n", x, y, visible); 
    281         fprintf(f, " <NODE_LABEL label='%s' shape='%d' backColor='%x' textColor='FFFFFF' fontSize='%d'/>\n", label, shape, color, fsize); 
    282                 if (depth != -1){ 
     332        fprintf(f, " <NODE_LABEL label='%s' shape='%d' backColor='%x' textColor='FFFFFF' fontSize='%d'/>\n", xml_escape(label), shape, color, fsize); 
     333                if (depth != -ZERO_DEPTH){ 
    283334            fprintf(f, " <NODE_BEHAVIOUR logic='com.touchgraph.graphlayout.mods.ApproachYbyWeight' weight='%d'/>\n", depth); 
    284335        } 
    285         fprintf(f, " <NODE_HINT hint='%s' width='200' height='-1' isHTML='true'/>\n", hint); 
     336        fprintf(f, " <NODE_HINT hint='%s' width='200' height='-1' isHTML='true'/>\n", xml_escape(hint)); 
    286337        fprintf(f, "</NODE>\n"); 
    287338    } 
     
    312363          length = 30; 
    313364          color = 0xC0E0C0; 
    314           if (SHOW_UNK_DATA == 0) continue; 
    315365        } 
    316366        //length = length * 10; 
     
    325375    fclose(f); 
    326376 
     377    return fname; 
     378 
     379} 
     380 
     381static xml_escape(label) 
     382{ 
     383    label = replace(label, "&", "@"); 
     384    label = replace(label, "'", "&apos;"); 
     385    label = replace(label, "<", "&lt;"); 
     386    label = replace(label, ">", "&gt;"); 
     387 
     388    return label; 
    327389} 
    328390 
    329391static main() 
    330392{ 
    331      
    332     ResolveTask(ScreenEA()); 
    333  
    334     Message("Done\n"); 
     393    auto fname; 
     394 
     395    auto answer; 
     396     
     397    DeleteArray( GetArrayId("downIdArray") ); 
     398    answer = AskYN(-1, "YES - xrefs down from\nNO - xrefs up to\n"); 
     399    if (answer == -1) 
     400      return; 
     401    if (answer == 1) 
     402      CreateArray("downIdArray"); 
     403     
     404    fname = ResolveTask(ScreenEA()); 
     405 
     406    Message("Done: %s\n", fname); 
    335407} 
  • branches/cail-digicdv/hv30_analysis/scripts/scan-fuctions.idc

    r477 r501  
    1313static main() 
    1414{ 
    15   auto sb, se, a, c, w, d; 
     15  auto sb, se, a, c, w, d, y; 
    1616  auto lr, push; 
    1717 
     
    3131      lr = 1; 
    3232 
     33    if ( d == 0x9F8C ) 
     34      lr = 1; 
     35 
    3336    if (d == 0x1781)  
     37      lr = 1; 
     38    if (d == 0x1708)  
    3439      lr = 1; 
    3540 
     
    3944*/ 
    4045 
    41 //    Message("code:%x, %x\n", (d&0xFF00) == 0x4f00, (d&0x00FF > 0x80)); 
    42 //    Message("lr:%x, push:%x\n",lr, push); 
    43      
    4446    if (!lr && !push) continue; 
    4547 
    46     if (lr && isUnknown(GetFlags(a))) 
    47       MakeCode(a); 
     48    if (!isUnknown(GetFlags(a))) continue; 
    4849 
    49       //MakeFunction(a, BADADDR); 
     50    if (RfirstB0(a) == BADADDR && DfirstB(a) == BADADDR)  continue; 
     51 
     52    for(y = DfirstB(a); y != BADADDR; y=DnextB(a,y) ) 
     53    { 
     54        Message("%08x: %s\n", y, GetDisasm(y)); 
     55    } 
     56 
     57//    Message("lr:%x, push:%x\n",lr, push); 
     58 
     59    MakeFunction(a, BADADDR); 
     60 
     61      // 
    5062/*    else if (isUnknown(GetFlags(a))) 
    5163    { 
  • branches/cail-digicdv/hv30_analysis/scripts/scan-func_tables.idc

    r477 r501  
    1818static isIn(addr) 
    1919{ 
    20   return addr > CODE_START && addr < CODE_END; 
     20  return (addr > CODE_START && addr < CODE_END) || addr == 0; 
    2121} 
     22 
     23 
    2224 
    2325static main() 
    2426{ 
    25   auto sb, se, a, c, w, d; 
    26   sb = CODE_START; 
    27   se = CODE_END; 
     27 
     28  search_table(CODE_START, CODE_END); 
     29 
     30//  search_table(0x40294, 0x40294 + 0x1248); 
     31 
     32} 
     33 
     34 
     35static search_table(sb, se) 
     36{ 
     37  auto a, c, w, d; 
    2838 
    2939  c = 0; 
     
    3242    if (   isIn(Dword(a+0)) 
    3343        && isIn(Dword(a+4)) 
    34         && isIn(Dword(a+8)) 
     44//        && isIn(Dword(a+8)) 
     45        && isUnknown(GetFlags(a+0)) 
    3546        ) 
    3647    { 
    37        Message("Table: %x\n", a); 
     48       Message("%x : item\n", a); 
    3849       //MakeUnknown(a, 4, DOUNK_EXPAND); 
    39        c = c+3; 
     50       c = c+1; 
    4051 
    4152       MakeDword(a+0); 
    4253       MakeDword(a+4); 
    4354       MakeDword(a+8); 
    44        a = a + 8; 
     55       //a = a + 4; 
    4556    } 
    4657 
  • branches/cail-digicdv/hv30_analysis/scripts/scan-lib.idc

    r477 r501  
    44#define ROM_END     (0xBFA00000+0x800000) 
    55 
     6#define TRUE   1 
     7#define FALSE  0 
    68 
    79static getString(addr) 
     
    2628 
    2729 
     30static GetStringPascal(addr) 
     31{ 
     32  auto origa, stringRead, length; 
     33 
     34  stringRead = ""; 
     35  length = Word(addr); 
     36  addr = addr+2; 
     37 
     38  if (length < 2) return 0; 
     39  if (length > 50) return 0; 
     40 
     41  for(; length > 0; length = length-1) 
     42  { 
     43      auto c; 
     44      c = Word(addr); 
     45      if (c < 0x2D || c > 0x7F) c = '_'; 
     46 
     47      stringRead = form("%s%c", stringRead, c); 
     48      addr = addr + 2; 
     49  } 
     50 
     51  return stringRead; 
     52} 
    2853 
    2954 
Note: See TracChangeset for help on using the changeset viewer.