Beispiel #1
0
void VisualNavbar::fillData()
{
    graphicsScene->clear();
    cursorGraphicsItem = nullptr;
    // Do not try to draw if no sections are available.
    if (mappedSegments.length() == 0) {
        return;
    }

    int w = this->graphicsView->width();
    int h = this->graphicsView->height();

    double width_per_byte = (double)w / (double)totalMappedSize;
    xToAddress.clear();
    double current_x = 0;
    for (auto mappedSegment : mappedSegments) {
        RVA segment_size = mappedSegment.address_to - mappedSegment.address_from;
        double segment_width = (double)segment_size * width_per_byte;
        QGraphicsRectItem *rect = new QGraphicsRectItem(current_x, 0, segment_width, h);
        rect->setBrush(QBrush(Config()->getColor("gui.navbar.empty")));
        graphicsScene->addItem(rect);
        drawMetadata(mappedSegment.strings,
                     mappedSegment.address_from,
                     current_x,
                     width_per_byte,
                     h, Config()->getColor("gui.navbar.str"));
        drawMetadata(mappedSegment.symbols,
                     mappedSegment.address_from,
                     current_x,
                     width_per_byte,
                     h, Config()->getColor("gui.navbar.sym"));
        drawMetadata(mappedSegment.functions,
                     mappedSegment.address_from,
                     current_x,
                     width_per_byte,
                     h, Config()->getColor("gui.navbar.code"));

        // Keep track of where which memory segment is mapped so we are able to convert from
        // address to X coordinate and vice versa.
        struct xToAddress x2a;
        x2a.x_start = current_x;
        x2a.x_end = current_x + segment_width;
        x2a.address_from = mappedSegment.address_from;
        x2a.address_to = mappedSegment.address_to;
        xToAddress.append(x2a);

        current_x += segment_width;
    }

    // Update scene width
    graphicsScene->setSceneRect(graphicsScene->itemsBoundingRect());

    // Draw cursor
    drawCursor();
}
/**
 * Creates a new empty graph window.
 *
 * @param maxValue The maximum value of the graph scale. The minimum
 * value is always 0.
 * @param windowName The title of the window the graph will be
 * displayed in.
 */
Graph::Graph(int maxValue, std::string windowName)
{
	this->maxValue = maxValue;
	this->windowName = windowName;
	this->colors = colors;

	imageWidth = 640;
	imageHeight = 480;
	graphAreaWidth = 600;
	graphAreaHeight = 440;
	graphAreaHorizontalOffset = 40;
	graphAreaVerticalOffset = 30;
	currentPosition = 0;
	graph = new int[graphAreaWidth];
	graphInitialized = new bool[graphAreaWidth];

	for (int i = 0; i < graphAreaWidth; i++) {
		graphInitialized[i] = false;
	}

	image = cv::Mat::zeros(cv::Size(imageWidth, imageHeight), CV_8UC3);
	drawMetadata();

	cv::startWindowThread();
	cv::namedWindow(windowName);
	cv::imshow(windowName, image);
}