Skip to content

Commit d9628c7

Browse files
committed
Configurable max passes via binja settings
1 parent dd32976 commit d9628c7

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

library.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ extern "C"
99

1010
BINARYNINJAPLUGIN bool CorePluginInit()
1111
{
12+
auto settings = Settings::Instance();
13+
settings->RegisterGroup("nativePredicateSolver", "Native Predicate Solver");
14+
settings->RegisterSetting("nativePredicateSolver.maxPassesPerFunction",
15+
R"~({
16+
"title": "Max passes per function",
17+
"type": "number",
18+
"default": 10,
19+
"description": "Maximum number of passes to run when patching opaque predicates in a single function."
20+
})~");
21+
settings->RegisterSetting("nativePredicateSolver.maxGlobalPasses",
22+
R"~({
23+
"title": "Max global passes",
24+
"type": "number",
25+
"default": 20,
26+
"description": "Maximum number of global passes when patching all functions in the binary."
27+
})~");
28+
1229
PluginCommand::Register(
1330
"Native Predicate Solver\\Patch Opaque Predicates (Current Function)",
1431
"Patch opaque predicates in current function",
@@ -45,7 +62,8 @@ extern "C"
4562

4663
int totalPatches = 0;
4764
int pass = 1;
48-
const int maxPasses = 10;
65+
auto settings = Settings::Instance();
66+
const int maxPasses = static_cast<int>(settings->Get<int64_t>("nativePredicateSolver.maxPassesPerFunction", viewRef));
4967

5068
while (pass <= maxPasses) {
5169
if (task->IsCancelled()) {
@@ -111,6 +129,8 @@ extern "C"
111129

112130
int globalPass = 1;
113131
int totalGlobalPatches = 0;
132+
auto settings = Settings::Instance();
133+
const int maxGlobalPasses = static_cast<int>(settings->Get<int64_t>("nativePredicateSolver.maxGlobalPasses", viewRef));
114134

115135
while (true) {
116136
if (task->IsCancelled()) {
@@ -148,8 +168,10 @@ extern "C"
148168

149169
int funcPatches = 0;
150170
int pass = 1;
171+
auto settings = Settings::Instance();
172+
const int maxPassesPerFunction = static_cast<int>(settings->Get<int64_t>("nativePredicateSolver.maxPassesPerFunction", viewRef));
151173

152-
while (pass <= 10) {
174+
while (pass <= maxPassesPerFunction) {
153175
int patchCount = 0;
154176

155177
for (size_t i = 0; i < mlil->GetInstructionCount(); ++i) {
@@ -196,7 +218,7 @@ extern "C"
196218

197219
globalPass++;
198220

199-
if (globalPass > 20) {
221+
if (globalPass > maxGlobalPasses) {
200222
LogWarn("[!] Maximum passes reached");
201223
break;
202224
}

0 commit comments

Comments
 (0)