@@ -49,58 +49,64 @@ string BaseAddressDetectionConfidenceToString(BNBaseAddressDetectionConfidence l
49
49
}
50
50
51
51
52
- uint32_t HexOrDecimalQStringToUint32 (const QString& str)
53
- {
54
- if (str.startsWith (" 0x" ))
55
- return str.mid (2 ).toUInt (nullptr , 16 );
56
- return str.toUInt ();
57
- }
58
-
59
-
60
- uint64_t HexOrDecimalQStringToUint64 (const QString& str)
61
- {
62
- if (str.startsWith (" 0x" ))
63
- return str.mid (2 ).toULongLong (nullptr , 16 );
64
- return str.toULongLong ();
65
- }
66
-
67
-
68
52
void BaseAddressDetectionThread::run ()
69
53
{
70
54
BaseAddressDetectionQtResults results;
71
- uint32_t alignment = HexOrDecimalQStringToUint32 (m_inputs->AlignmentLineEdit ->text ());
72
- if (alignment == 0 )
55
+ uint64_t value;
56
+ string errorStr;
57
+
58
+ if (!BinaryNinja::BinaryView::ParseExpression (
59
+ m_view, m_inputs->AlignmentLineEdit ->text ().toStdString (), value, 0 , errorStr))
73
60
{
74
- results.Status = " Invalid alignment value" ;
61
+ results.Status = " Invalid alignment value ( " + errorStr + " ) " ;
75
62
emit ResultReady (results);
76
63
return ;
77
64
}
65
+ uint32_t alignment = value;
78
66
79
- uint32_t minStrlen = HexOrDecimalQStringToUint32 (m_inputs-> StrlenLineEdit -> text ());
80
- if (minStrlen == 0 )
67
+ if (! BinaryNinja::BinaryView::ParseExpression (
68
+ m_view, m_inputs-> StrlenLineEdit -> text (). toStdString (), value, 0 , errorStr) )
81
69
{
82
- results.Status = " Invalid minimum string length" ;
70
+ results.Status = " Invalid minimum string length ( " + errorStr + " ) " ;
83
71
emit ResultReady (results);
84
72
return ;
85
73
}
74
+ uint32_t minStrlen = value;
86
75
87
- uint64_t upperBoundary = HexOrDecimalQStringToUint64 (m_inputs->UpperBoundary ->text ());
88
- if (upperBoundary == 0 )
76
+ uint64_t upperBoundary;
77
+ if (!BinaryNinja::BinaryView::ParseExpression (
78
+ m_view, m_inputs->UpperBoundary ->text ().toStdString (), upperBoundary, 0 , errorStr))
89
79
{
90
- results.Status = " Invalid upper boundary address" ;
80
+ results.Status = " Invalid upper boundary address (" + errorStr + " )" ;
81
+ emit ResultReady (results);
82
+ return ;
83
+ }
84
+
85
+ uint64_t lowerBoundary;
86
+ if (!BinaryNinja::BinaryView::ParseExpression (
87
+ m_view, m_inputs->LowerBoundary ->text ().toStdString (), lowerBoundary, 0 , errorStr))
88
+ {
89
+ results.Status = " Invalid lower boundary address (" + errorStr + " )" ;
91
90
emit ResultReady (results);
92
91
return ;
93
92
}
94
93
95
- uint64_t lowerBoundary = HexOrDecimalQStringToUint64 (m_inputs->LowerBoundary ->text ());
96
94
if (lowerBoundary >= upperBoundary)
97
95
{
98
96
results.Status = " Upper boundary address is less than lower" ;
99
97
emit ResultReady (results);
100
98
return ;
101
99
}
102
100
103
- uint32_t maxPointersPerCluster = HexOrDecimalQStringToUint32 (m_inputs->MaxPointersPerCluster ->text ());
101
+ if (!BinaryNinja::BinaryView::ParseExpression (
102
+ m_view, m_inputs->MaxPointersPerCluster ->text ().toStdString (), value, 0 , errorStr))
103
+ {
104
+ results.Status = " Invalid max pointers (" + errorStr + " )" ;
105
+ emit ResultReady (results);
106
+ return ;
107
+ }
108
+
109
+ uint32_t maxPointersPerCluster = value;
104
110
if (maxPointersPerCluster < 2 )
105
111
{
106
112
results.Status = " Invalid max pointers (must be >= 2)" ;
@@ -254,7 +260,14 @@ void BaseAddressDetectionWidget::RebaseWithFullAnalysis()
254
260
if (!fileMetadata)
255
261
return ;
256
262
257
- uint64_t address = HexOrDecimalQStringToUint64 (m_reloadBase->text ());
263
+ uint64_t address;
264
+ string errorStr;
265
+ if (!BinaryNinja::BinaryView::ParseExpression (m_view, m_reloadBase->text ().toStdString (), address, 0 , errorStr))
266
+ {
267
+ m_status->setText (QString (" Invalid rebase address (%1)" ).arg (QString::fromStdString (errorStr)));
268
+ return ;
269
+ }
270
+
258
271
if (!fileMetadata->Rebase (mappedView, address))
259
272
return ;
260
273
@@ -291,11 +304,11 @@ void BaseAddressDetectionWidget::CreateAdvancedSettingsGroup()
291
304
auto grid = new QGridLayout ();
292
305
293
306
grid->addWidget (new QLabel (" Min. String Length:" ), row, column, Qt::AlignLeft);
294
- m_inputs.StrlenLineEdit = new QLineEdit (" 10 " );
307
+ m_inputs.StrlenLineEdit = new QLineEdit (" 0n10 " );
295
308
grid->addWidget (m_inputs.StrlenLineEdit , row, column + 1 , Qt::AlignLeft);
296
309
297
310
grid->addWidget (new QLabel (" Alignment:" ), row, column + 2 , Qt::AlignLeft);
298
- m_inputs.AlignmentLineEdit = new QLineEdit (" 1024 " );
311
+ m_inputs.AlignmentLineEdit = new QLineEdit (" 0n1024 " );
299
312
grid->addWidget (m_inputs.AlignmentLineEdit , row++, column + 3 , Qt::AlignLeft);
300
313
301
314
grid->addWidget (new QLabel (" Lower Boundary:" ), row, column, Qt::AlignLeft);
@@ -313,7 +326,7 @@ void BaseAddressDetectionWidget::CreateAdvancedSettingsGroup()
313
326
grid->addWidget (m_inputs.POIBox , row, column + 1 , Qt::AlignLeft);
314
327
315
328
grid->addWidget (new QLabel (" Max Pointers:" ), row, column + 2 , Qt::AlignLeft);
316
- m_inputs.MaxPointersPerCluster = new QLineEdit (" 128 " );
329
+ m_inputs.MaxPointersPerCluster = new QLineEdit (" 0n128 " );
317
330
grid->addWidget (m_inputs.MaxPointersPerCluster , row++, column + 3 , Qt::AlignLeft);
318
331
319
332
m_advancedSettingsGroup = new ExpandableGroup (grid);
0 commit comments