com.github.unidbg.ios.file.RandomFileIO Maven / Gradle / Ivy
The newest version!
package com.github.unidbg.ios.file;
import com.github.unidbg.Emulator;
import com.github.unidbg.arm.backend.Backend;
import com.github.unidbg.file.ios.IOConstants;
import com.sun.jna.Pointer;
import java.util.concurrent.ThreadLocalRandom;
public class RandomFileIO extends DriverFileIO {
public RandomFileIO(Emulator> emulator, String path) {
super(emulator, IOConstants.O_RDONLY, path);
}
@Override
public int read(Backend backend, Pointer buffer, int count) {
int total = 0;
byte[] buf = new byte[Math.min(0x1000, count)];
randBytes(buf);
Pointer pointer = buffer;
while (total < count) {
int read = Math.min(buf.length, count - total);
pointer.write(0, buf, 0, read);
total += read;
pointer = pointer.share(read);
}
return total;
}
protected void randBytes(byte[] bytes) {
ThreadLocalRandom.current().nextBytes(bytes);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy