Ejemplo n.º 1
0
static void run_first_instance()
{
	char * file;
	slist_t * sl1 = NULL;
	slist_t * sl2 = NULL;
	int ret;

	msg ("\n---------------------------------------------------\n"
		"PatchDiff Plugin v2.0.10\n"
		"Copyright (c) 2010-2011, Nicolas Pouvesle\n"
		"Copyright (C) 2007-2009, Tenable Network Security, Inc\n"
		"---------------------------------------------------\n\n");

	ret = backup_load_results(&d_engine, d_opt);
	if (ret == 1)
	{
		display_results(d_engine);
		return;
	}
	else if (ret == -1)
	{
		return;
	}

	show_wait_box ("PatchDiff is in progress ...");

	msg ("Scanning for functions ...\n");

	msg ("parsing second idb...\n");
	sl2 = parse_second_idb(&file, d_opt);
	if (!sl2)
	{
		msg("Error: IDB2 parsing cancelled or failed.\n");
		hide_wait_box();
		return;
	}

	msg ("parsing first idb...\n");
	sl1 = parse_idb ();
	if (!sl1)
	{
		msg("Error: IDB1 parsing failed.\n");
		siglist_free(sl2);
		hide_wait_box();
		return;
	}

	msg ("diffing...\n");
	generate_diff(&d_engine, sl1, sl2, file, true, d_opt);

	msg ("done!\n");
	hide_wait_box();

	if (sl1) siglist_partial_free(sl1);
	if (sl2) siglist_partial_free(sl2);
}
Ejemplo n.º 2
0
//--------------------------------------------------------------------------
inline void set_wait_box(const char *mesg)
{
  if ( wait_box_visible )
  {
    replace_wait_box("HIDECANCEL\n%s", mesg);
  }
  else
  {
    wait_box_visible = true;
    show_wait_box("HIDECANCEL\n%s", mesg);
  }
}
Ejemplo n.º 3
0
void propagate_match(deng_t * eng, psig_t * s1, psig_t * s2, int options)
{
	size_t i;
	deng_t * d = NULL;
	slist_t * l1, * l2;

	if (options)
	{
		show_wait_box ("PatchDiff is in progress ...");

		l1 = siglist_init(eng->ulist->num, eng->ulist->file);
		l2 = siglist_init(eng->ulist->num, eng->ulist->file);

		for (i=0; i<eng->ulist->num; i++)
			if (!eng->ulist->sigs[i]->msig)
			{
				if (eng->ulist->sigs[i]->nfile == 1)
					siglist_add(l1, eng->ulist->sigs[i]);
				else
					siglist_add(l2, eng->ulist->sigs[i]);
			}

		generate_diff(&d, l1, l2, eng->ulist->file, false, NULL);

		siglist_partial_free(l1);
		siglist_partial_free(l2);

		hide_wait_box();
	}

	i = 0;
	while (i<eng->ulist->num)
	{
		s1 = eng->ulist->sigs[i];
		s2 = s1->msig;

		if (!s2) 
			i++;
		else
		{
			if (s1->nfile == 1)
			{
				if (sig_equal(s1, s2, DIFF_EQUAL_SIG_HASH))
					siglist_add(eng->ilist, s1);
				else
					siglist_add(eng->mlist, s1);
			}

			siglist_remove(eng->ulist, i);
		}
	}
}
Ejemplo n.º 4
0
//---------------------------------------------------------------------------
// Redraw the chart
void __fastcall TChatForm::RefreshChart(TObject *Sender)
{
  ea_t ea1, ea2;
  // check the selection
  if ( callui(ui_readsel, &ea1, &ea2).cnd )
  {
    char buf[MAXSTR];
    qsnprintf(buf, sizeof(buf), "0x%a", ea1); Edit1->Text = buf;
    qsnprintf(buf, sizeof(buf), "0x%a", ea2); Edit2->Text = buf;
  }
  // get the starting and ending addresses
  char err[MAXSTR];
  ea_t here = get_screen_ea();
  if ( !calcexpr_long(here, Edit1->Text.c_str(), &ea1, err, sizeof(err)) )
  {
    warning("%s", err);
    BringToFront();
    return;
  }
  if ( !calcexpr_long(here, Edit2->Text.c_str(), &ea2, err, sizeof(err)) )
  {
    warning("%s", err);
    BringToFront();
    return;
  }
  // fill the data
  show_wait_box("HIDECANCEL\nGenerating the graph");
  ch->Series[0]->Clear();
  while ( ea1 < ea2 )
  {
    char label[MAXSTR];
    ea2str(ea1, label, sizeof(label));  // generation of the label text takes time, you may want to remove it
    ch->Series[0]->AddXY(ea1, get_byte(ea1), label, TColor(clTeeColor));
    ea1 = next_not_tail(ea1);
  }
  hide_wait_box();
}
static void idaapi run(int /* arg */)
{
    static char mapFileName[_MAX_PATH] = { 0 };

    // If user press shift key, show options dialog
    if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
    {
        ShowOptionsDlg();
    }

    ulong numOfSegs = (ulong) get_segm_qty();
    if (0 == numOfSegs)
    {
        warning("Not found any segments");
        return;
    }

    if ('\0' == mapFileName[0])
    {
        // First run
        strncpy(mapFileName, get_input_file_path(), sizeof(mapFileName));
        WIN32CHECK(PathRenameExtension(mapFileName, ".map"));
    }

    // Show open map file dialog
    char *fname = askfile_c(0, mapFileName, "Open MAP file");
    if (NULL == fname)
    {
        msg("LoadMap: User cancel\n");
        return;
    }

    // Open the map file
    LPSTR pMapStart = NULL;
    DWORD mapSize = INVALID_FILE_SIZE;
    MAP_OPEN_ERROR eRet = MapFileOpen(fname, pMapStart, mapSize);
    switch (eRet)
    {
        case WIN32_ERROR:
            warning("Could not open file '%s'.\nWin32 Error Code = 0x%08X",
                    fname, GetLastError());
            return;

        case FILE_EMPTY_ERROR:
            warning("File '%s' is empty, zero size", fname);
            return;

        case FILE_BINARY_ERROR:
            warning("File '%s' seem to be a binary or Unicode file", fname);
            return;

        case OPEN_NO_ERROR:
        default:
            break;
    }

    bool foundHdr = false;
    ulong validSyms = 0;
    ulong invalidSyms = 0;

    // The mark pointer to the end of memory map file
    // all below code must not read or write at and over it
    LPSTR pMapEnd = pMapStart + mapSize;

    show_wait_box("Parsing and applying symbols from the Map file '%s'", fname);

    __try
    {
        LPSTR pLine = pMapStart;
        LPSTR pEOL = pMapStart;
        while (pLine < pMapEnd)
        {
            // Skip the spaces, '\r', '\n' characters, blank lines, seek to the
            // non space character at the beginning of a non blank line
            pLine = SkipSpaces(pEOL, pMapEnd);

            // Find the EOL '\r' or '\n' characters
            pEOL = FindEOL(pLine, pMapEnd);

            size_t lineLen = (size_t) (pEOL - pLine);
            if (lineLen < g_minLineLen)
            {
                continue;
            }

            if (!foundHdr)
            {
                if ((0 == strnicmp(pLine, VC_HDR_START      , lineLen)) ||
                    (0 == strnicmp(pLine, BL_HDR_NAME_START , lineLen)) ||
                    (0 == strnicmp(pLine, BL_HDR_VALUE_START, lineLen)))
                {
                    foundHdr = true;
                }
            }
            else
            {
                ulong seg = SREG_NUM;
                ulong addr = BADADDR;
                char name[MAXNAMELEN + 1];
                char fmt[80];

                name[0] = '\0';
                fmt[0] = '\0';

                // Get segment number, address, name, by pass spaces at beginning,
                // between ':' character, between address and name
                int ret = _snscanf(pLine, min(lineLen, MAXNAMELEN + g_minLineLen),
                                   " %04X : %08X %s", &seg, &addr, name);
                if (3 != ret)
                {
                    // we have parsed to end of value/name symbols table or reached EOF
                    _snprintf(fmt, sizeof(fmt), "Parsing finished at line: '%%.%ds'.\n", lineLen);
                    ShowMsg(fmt, pLine);
                    break;
                }
                else if ((0 == seg) || (--seg >= numOfSegs) ||
                        (BADADDR == addr) || ('\0' == name[0]))
                {
                    sprintf(fmt, "Invalid map line: %%.%ds.\n", lineLen);
                    ShowMsg(fmt, pLine);

                    invalidSyms++;
                }
                else
                {
                    // Ensure name is NULL terminated
                    name[MAXNAMELEN] = '\0';

                    // Determine the DeDe map file
                    bool bNameApply = g_options.bNameApply;
                    char *pname = name;
                    if (('<' == pname[0]) && ('-' == pname[1]))
                    {
                        // Functions indicator symbol of DeDe map
                        pname += 2;
                        bNameApply = true;
                    }
                    else if ('*' == pname[0])
                    {
                        // VCL controls indicator symbol of DeDe map
                        pname++;
                        bNameApply = false;
                    }
                    else if (('-' == pname[0]) && ('>' == pname[1]))
                    {
                        // VCL methods indicator symbol of DeDe map
                        pname += 2;
                        bNameApply = false;
                    }

                    ulong la = addr + getnseg((int) seg)->startEA;
                    flags_t f = getFlags(la);

                    if (bNameApply) // Apply symbols for name
                    {
                        //  Add name if there's no meaningful name assigned.
                        if (g_options.bReplace ||
                            (!has_name(f) || has_dummy_name(f) || has_auto_name(f)))
                        {
                            if (set_name(la, pname, SN_NOWARN))
                            {
                                ShowMsg("%04X:%08X - Change name to '%s' successed\n",
                                        seg, la, pname);
                                validSyms++;
                            }
                            else
                            {
                                ShowMsg("%04X:%08X - Change name to '%s' failed\n",
                                        seg, la, pname);
                                invalidSyms++;
                            }
                        }
                    }
                    else if (g_options.bReplace || !has_cmt(f))
                    {
                        // Apply symbols for comment
                        if (set_cmt(la, pname, false))
                        {
                            ShowMsg("%04X:%08X - Change comment to '%s' successed\n",
                                    seg, la, pname);
                            validSyms++;
                        }
                        else
                        {
                            ShowMsg("%04X:%08X - Change comment to '%s' failed\n",
                                    seg, la, pname);
                            invalidSyms++;
                        }
                    }
                }
            }
        }
    }
    __finally
    {
        MapFileClose(pMapStart);
        hide_wait_box();
    }

    if (!foundHdr)
    {
        warning("File '%s' is not a valid Map file", fname);
    }
    else
    {
        // Save file name for next askfile_c dialog
        strncpy(mapFileName, fname, sizeof(mapFileName));

        // Show the result
        msg("Result of loading and parsing the Map file '%s'\n"
            "   Number of Symbols applied: %d\n"
            "   Number of Invalid Symbols: %d\n\n",
            fname, validSyms, invalidSyms);
    }
}