Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory: Optimize gum_memory_read for Linux/Android #988

Merged
merged 5 commits into from
Jan 23, 2025

Conversation

DoranekoSystems
Copy link
Contributor

This PR optimizes the performance of gum_memory_read on Linux/Android platforms.

Current Issues:

  • gum_memory_read is significantly slow due to parsing memory maps on each call
  • Memory.readVolatile using gum_memory_read is approximately 1000x slower than Memory.readByteArray

Improvements:

  • Implement process_vm_readv for safe self-process memory reading on Linux kernels >= 3.2
  • Add kernel version detection to ensure compatibility

Benchmark results

let memPtr = Memory.alloc(4096);
let start = Date.now();
for(let i = 0; i < 10000; i++) {
  Memory.readVolatile(memPtr, 4096);
}

let end = Date.now();
console.log(`readVolatile => elapsedTime: ${end - start} ms`);
start = Date.now();
for(let i = 0; i < 10000; i++) {
  Memory.readByteArray(memPtr, 4096);
}

end = Date.now();
console.log(`readByteArray => elapsedTime: ${end - start} ms`);

Device:Android Pixel3a

frida-server:16.6.4
readVolatile => elapsedTime: 49432 ms
readByteArray => elapsedTime: 31 ms

this version
readVolatile => elapsedTime: 45 ms
readByteArray => elapsedTime: 31 ms

@oleavr oleavr merged commit f61b78b into frida:main Jan 23, 2025
26 of 32 checks passed
@oleavr
Copy link
Member

oleavr commented Jan 23, 2025

Thanks, this is amazing!! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants