Skip to content

Commit 2024132

Browse files
committed
Skip slicer processing for unmodified DEX files
Slicer's `CreateFullIr` and `CreateImage` operations are highly CPU-intensive and cause significant load latency for large DEX files. We hence introduce a fast-path optimization using `memmem` to perform a raw binary scan of the DEX buffer for target signatures prior to processing. If no matching signatures are found, the expensive IR parsing and image rebuilding phases are bypassed entirely, and the original file descriptor is safely returned.
1 parent 356ebde commit 2024132

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

daemon/src/main/jni/obfuscation.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,26 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_lsposed_lspd_service_ObfuscationMa
221221
return nullptr;
222222
}
223223

224+
bool needs_obfuscation = false;
225+
for (const auto &sig : signatures) {
226+
if (memmem(mem, size, sig.first.c_str(), sig.first.length()) != nullptr) {
227+
needs_obfuscation = true;
228+
break;
229+
}
230+
}
231+
232+
if (!needs_obfuscation) {
233+
LOGD("No target signatures found in fd=%d, skipping slicer.", fd);
234+
munmap(mem, size);
235+
236+
// Wrap the duplicated FD into Java objects and return instantly
237+
auto java_fd =
238+
lsplant::JNI_NewObject(env, class_file_descriptor, method_file_descriptor_ctor, fd);
239+
auto java_sm =
240+
lsplant::JNI_NewObject(env, class_shared_memory, method_shared_memory_ctor, java_fd);
241+
return java_sm.release();
242+
}
243+
224244
// Process the DEX and obtain a new file descriptor for the output
225245
int new_fd = obfuscateDexBuffer(mem, size);
226246

0 commit comments

Comments
 (0)