From f12118f4d411c0d785836d11bfb44cae0028419e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sun, 1 Jul 2018 14:29:01 +0200 Subject: [PATCH] WIP VisualNavbar --- src/Cutter.cpp | 4 ++++ src/Cutter.h | 1 + src/img/cutter.svg | 29 ++++++++++++++++++++--------- src/widgets/VisualNavbar.cpp | 15 +++++++++++---- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 196ab652..3ab38651 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -1545,6 +1545,9 @@ BlockStatistics CutterCore::getBlockStatistics(unsigned int blocksCount) ret.blocksize = statsObj["blocksize"].toVariant().toULongLong(); QJsonArray blocksArray = statsObj["blocks"].toArray(); + + printf("got %d blocks for requested %u\n", blocksArray.count(), blocksCount); + for (const QJsonValue &value : blocksArray) { QJsonObject blockObj = value.toObject(); BlockDescription block; @@ -1552,6 +1555,7 @@ BlockStatistics CutterCore::getBlockStatistics(unsigned int blocksCount) block.size = blockObj["size"].toVariant().toULongLong(); block.flags = blockObj["flags"].toInt(0); block.functions = blockObj["functions"].toInt(0); + block.inFunctions = blockObj["in_functions"].toInt(0); block.comments = blockObj["comments"].toInt(0); block.symbols = blockObj["symbols"].toInt(0); block.strings = blockObj["strings"].toInt(0); diff --git a/src/Cutter.h b/src/Cutter.h index 2cb571ef..0d52d034 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -280,6 +280,7 @@ struct BlockDescription { RVA size; int flags; int functions; + int inFunctions; int comments; int symbols; int strings; diff --git a/src/img/cutter.svg b/src/img/cutter.svg index 7f2513e0..2ea1a0c4 100644 --- a/src/img/cutter.svg +++ b/src/img/cutter.svg @@ -14,8 +14,8 @@ viewBox="0 0 512.00001 512.00001" id="svg4254" version="1.1" - inkscape:version="0.92.2 (5c3e80d, 2017-08-06)" - sodipodi:docname="cutter_appicon.svg"> + inkscape:version="0.92.2 2405546, 2018-03-11" + sodipodi:docname="cutter.svg"> + inkscape:window-height="1024" + inkscape:window-x="1920" + inkscape:window-y="0" + inkscape:window-maximized="1" /> @@ -46,7 +46,7 @@ image/svg+xml - + @@ -70,5 +70,16 @@ d="M 256.00271,572.36218 C 132.45491,572.36218 32.000055,672.8129 32,796.36215 c 2.7e-5,33.63902 7.491933,65.53883 20.82432,94.19185 L 69.68595,858.80902 C 63.130866,839.19082 59.529221,818.2119 59.529194,796.36215 59.529221,687.69096 147.33276,599.89171 256.00271,599.89171 c 57.4471,0 109.04798,24.54673 144.94228,63.73192 h -95.88977 l -73.12445,137.19058 73.32338,138.70687 h 85.35663 c -35.14099,33.04896 -82.45299,53.31159 -134.60807,53.31159 -48.23544,0 -92.33512,-17.3306 -126.4945,-46.07433 H 90.12319 c 41.00589,45.18743 100.17358,73.60386 165.87952,73.60386 C 379.55049,1020.3622 480,919.91141 480,796.36218 480,672.8129 379.55049,572.36221 256.00271,572.36221 Z M 189.35729,692.20165 68.76116,919.22881 h 194.62926 l -62.62353,-118.46834 57.85968,-108.5588 h -69.26926 z m 162.72874,50.55859 v 56.84417 l 38.07845,-28.42205 38.07309,-28.42209 v 56.84417 56.84418 l -38.07309,-28.4221 -38.07845,-28.42208 v 56.84418 l -38.07305,-28.4221 -38.0785,-28.42208 38.0785,-28.42208 38.07305,-28.42209 z" style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;baseline-shift:baseline;text-anchor:start;white-space:normal;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" /> + Cutter diff --git a/src/widgets/VisualNavbar.cpp b/src/widgets/VisualNavbar.cpp index e8eee37b..f632cb0c 100644 --- a/src/widgets/VisualNavbar.cpp +++ b/src/widgets/VisualNavbar.cpp @@ -71,7 +71,7 @@ void VisualNavbar::paintEvent(QPaintEvent *event) QPainter painter(this); if (previousWidth != this->width()) { - this->fillData(); + fetchAndPaintData(); previousWidth = this->width(); } } @@ -107,6 +107,8 @@ void VisualNavbar::fillData() RVA totalSize = stats.to - stats.from; + printf("from: %llu, to %llu, first: %llu\n", stats.from, stats.to, stats.blocks[0].addr); + double widthPerByte = (double)w / (double)totalSize; auto xFromAddr = [widthPerByte] (RVA addr) -> double { return addr * widthPerByte; @@ -131,18 +133,23 @@ void VisualNavbar::fillData() xToAddress.append(x2a); DataType dataType; - if (block.functions > 0) { + if (block.inFunctions > 0) { dataType = DataType::Code; } else if (block.strings > 0) { dataType = DataType::String; } else if (block.symbols > 0) { dataType = DataType::Symbol; } else { + lastDataType = DataType::Empty; continue; } if (dataType == lastDataType) { - dataItemRect.setRight(xFromAddr(block.addr + block.size)); + double r = xFromAddr(block.addr + block.size); + if (r > dataItemRect.right()) { + dataItemRect.setRight(r); + dataItem->setRect(dataItemRect); + } dataItem->setRect(dataItemRect); continue; } @@ -159,7 +166,7 @@ void VisualNavbar::fillData() } // Update scene width - graphicsScene->setSceneRect(graphicsScene->itemsBoundingRect()); + graphicsScene->setSceneRect(0, 0, w, h); drawCursor(); }