예제 #1
0
파일: Core.cpp 프로젝트: nihilus/WhatAPIs
// Plug-in process
void CORE_Process(int iArg)
{
    try
    {
        char version[16];
        sprintf(version, "%u.%u", HIBYTE(MY_VERSION), LOBYTE(MY_VERSION));
        msg("\n>> WhatAPIs: v: %s, built: %s, By Sirmabus\n", version, __DATE__);
        if (!autoIsOk())
        {
            msg("** Must wait for IDA to finish processing before starting plug-in! **\n*** Aborted ***\n\n");
            return;
        }

        // Show UI
        refreshUI();
        int uiResult = AskUsingForm_c(mainDialog, version, doHyperlink);
        if (!uiResult)
        {
            msg(" - Canceled -\n");
            return;
        }

        WaitBox::show();
        TIMESTAMP startTime = getTimeStamp();

        // Build import segment bounds table
        {
            msg("Import segments:\n");
            refreshUI();
            SEGLIST segList;
            for (int i = 0; i < get_segm_qty(); i++)
            {
                if (segment_t *s = getnseg(i))
                {
                    if (s->type == SEG_XTRN)
                    {
                        char buffer[64] = { "unknown" }; buffer[SIZESTR(buffer)] = 0;
                        get_true_segm_name(s, buffer, SIZESTR(buffer));
                        msg(" [%d] \"%s\" "EAFORMAT" - "EAFORMAT"\n", segmentCount, buffer, s->startEA, s->endEA);
                        BOUNDS b = { s->startEA, s->endEA };
                        segList.push_back(b);
                        segmentCount++;
                    }
                }
            }
            refreshUI();

            // Flatten list into an array for speed
            if (segmentCount)
            {
                UINT size = (segmentCount * sizeof(BOUNDS));
                if (segmentPtr = (BOUNDS *)_aligned_malloc(size, 16))
                {
                    BOUNDS *b = segmentPtr;
                    for (SEGLIST::iterator i = segList.begin(); i != segList.end(); i++, b++)
                    {
                        b->startEA = i->startEA;
                        b->endEA   = i->endEA;
                    }
                }
                else
                {
                    msg("\n*** Allocation failure of %u bytes! ***\n", size);
                    refreshUI();
                }
            }
        }

        if (segmentCount)
        {
            // Make a list of all import names
            if (int moduleCount = get_import_module_qty())
            {
                for (int i = 0; i < moduleCount; i++)
                    enum_import_names(i, importNameCallback);

                char buffer[32];
                msg("Parsed %s module imports.\n", prettyNumberString(moduleCount, buffer));
                refreshUI();
            }

            // Iterate through all functions..
            BOOL aborted = FALSE;
            UINT functionCount = get_func_qty();
            char buffer[32];
            msg("Processing %s functions.\n", prettyNumberString(functionCount, buffer));
            refreshUI();

            for (UINT n = 0; n < functionCount; n++)
            {
                processFunction(getn_func(n));

                if (WaitBox::isUpdateTime())
                {
                    if (WaitBox::updateAndCancelCheck((int)(((float)n / (float)functionCount) * 100.0f)))
                    {
                        msg("* Aborted *\n");
                        break;
                    }
                }
            }

            refresh_idaview_anyway();
            WaitBox::hide();
            msg("\n");
            msg("Done. %s comments add/appended in %s.\n", prettyNumberString(commentCount, buffer), timeString(getTimeStamp() - startTime));
            msg("-------------------------------------------------------------\n");
        }
        else
            msg("\n*** No import segments! ***\n");

        if (segmentPtr)
        {
            _aligned_free(segmentPtr);
            segmentPtr = NULL;
        }
        apiMap.clear();
    }
    CATCH()
}
예제 #2
0
파일: funclist.cpp 프로젝트: nealey/vera
//--------------------------------------------------------------------------
void run(int /*arg*/)
{
  if ( !autoIsOk()
    && askyn_c(-1, "HIDECANCEL\n"
                   "The autoanalysis has not finished yet.\n"
                   "The result might be incomplete. Do you want to continue?") < 0 )
    return;

  // gather information about the entry points
  entrylist_t *li = new entrylist_t;
  size_t n = get_entry_qty();
  for ( size_t i=0; i < n; i++ )
  {
    asize_t ord = get_entry_ordinal((int)i);
    ea_t ea = get_entry(ord);
    if ( ord == ea )
      continue;
    qtype type, fnames;
    char decl[MAXSTR];
    char true_name[MAXSTR];
    asize_t argsize = 0;
    get_entry_name(ord, true_name, sizeof(true_name));
    if ( get_tinfo(ea, &type, &fnames)
      && print_type_to_one_line(
                decl, sizeof(decl),
                idati,
                type.c_str(),
                true_name,
                NULL,
                fnames.c_str()) == T_NORMAL )
    {
//    found type info -- calc the args size
      func_type_info_t fi;
      int a = build_funcarg_info(idati, type.c_str(), fnames.c_str(), &fi, 0);
      if ( a != 0 )
      {
        for ( int k=0; k < a; k++ )
        {
          const type_t *ptr = fi[k].type.c_str();
          int s1 = (int)get_type_size(idati, ptr);
          s1 = qmax(s1, inf.cc.size_i);
          argsize += s1;
        }
      }
    }
    else if ( get_long_name(BADADDR, ea, decl, sizeof(decl)) != NULL
           && get_true_name(BADADDR, ea, true_name, sizeof(true_name)) != NULL
           && strcmp(decl, true_name) != 0 )
    {
//      found mangled name
    }
    else
    {
//      found nothing, just show the name
      const char *name = get_name(BADADDR, ea, true_name, sizeof(true_name));
      if ( name == NULL )
        continue;
      qstrncpy(decl, name, sizeof(decl));
    }
    if ( argsize == 0 )
    {
      func_t *pfn = get_func(ea);
      if ( pfn != NULL )
        argsize = pfn->argsize;
    }
    item_t x;
    x.ord = (int)ord;
    x.ea = ea;
    x.decl = decl;
    x.argsize = (uint32)argsize;
    li->push_back(x);
  }

  // now open the window
  choose2(false,                // non-modal window
          -1, -1, -1, -1,       // position is determined by Windows
          li,                   // pass the created array
          qnumber(header),      // number of columns
          widths,               // widths of columns
          sizer,                // function that returns number of lines
          desc,                 // function that generates a line
          "Exported functions", // window title
          -1,                   // use the default icon for the window
          0,                    // position the cursor on the first line
          NULL,                 // "kill" callback
          NULL,                 // "new" callback
          NULL,                 // "update" callback
          NULL,                 // "edit" callback
          enter_cb,             // function to call when the user pressed Enter
          destroy_cb,           // function to call when the window is closed
          NULL,                 // use default popup menu items
          NULL);                // use the same icon for all lines
}