Android : Search Bytes In File In Android Java With FileChannel

on Friday, April 3, 2015


hi my app creates bin file in android/data/package/files/here which analyses about app state and system state but i have made them unrecognized like not plain text only what i can recognized is hex bytes about it here is my code



public boolean p(){
String file = Environment.getExternalStorageDirectory().getPath() + "/Android/data/MY_APP_PACKAGE_NAME/files/sys.bin";

FileChannel searchfile;

byte[] Bytes = new byte[]{0x78 ,0x56 ,0x34}; // just for example

try{
searchfile = new RandomAccessFile(file, "rw").getChannel();

MappedByteBuffer fileBytes = searchfile.map(FileChannel.MapMode.READ_ONLY, 0L, (byte) searchfile.size());

fileBytes.position(0);

while (fileBytes.hasRemaining()) {

fileBytes.position();
int currentPos = fileBytes.position();
byte currentByte = fileBytes.get();

if (currentByte==Bytes[0]) {

fileBytes.position(currentPos + 1);
byte currentByte1 = fileBytes.get();

if (currentByte1==Bytes[1]) {

fileBytes.position(currentPos + 2);
byte currentByte2 = fileBytes.get();

if (currentByte2==Bytes[2]) {

return true;
}

}

}

}

searchfile.close();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;

}


but i am unable to reach my code its not working even i tried adding bin file myself and even then it doesn't search the hex bytes, i tried putting everywhere in the file , can anybody can fix this where i am wrong and can provide fixed code


0 comments:

Post a Comment