How to copy files directly on Frida
Frida를 이용하여 파일을 복사해야 하는 경우,
다음의 스크립트를 활용할 수 있다.
_FileChannel_
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Java.perform(function(){ const File = Java.use('java.io.File'); const FileInputStream = Java.use('java.io.FileInputStream'); const FileOutputStream = Java.use('java.io.FileOutputStream'); const FileChannel = Java.use('java.nio.channels.FileChannel') var sourceFile = File.$new.overload('java.lang.String').call(File, '/data/local/tmp/test.js'); if (sourceFile.exists() && sourceFile.canRead()) { var destinationFile = File.$new.overload('java.lang.String').call(File, '/data/data/net.xiphiasilver.c0pyc4t/cache/test.bak'); destinationFile.createNewFile(); var fileInputStream = FileInputStream.$new.overload('java.io.File').call(FileInputStream, sourceFile); var fileOutputStream = FileOutputStream.$new.overload('java.io.File').call(FileOutputStream, destinationFile); var fileInputStreamChannel = fileInputStream.getChannel(); var fileOutputStreamChannel = fileOutputStream.getChannel(); fileInputStreamChannel.transferTo(0, fileInputStreamChannel.size(), fileOutputStreamChannel); fileInputStream.close(); fileOutputStream.close(); } else { console.log('Error : File cannot read.') } }) |
_BufferedInput/OutputStream_
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
Java.perform(function(){ const File = Java.use('java.io.File'); const FileInputStream = Java.use('java.io.FileInputStream'); const FileOutputStream = Java.use('java.io.FileOutputStream'); const BufferedInputStream = Java.use('java.io.BufferedInputStream'); const BufferedOutputStream = Java.use('java.io.BufferedOutputStream'); var sourceFile = File.$new.overload('java.lang.String').call(File, '/data/local/tmp/test.js'); if (sourceFile.exists() && sourceFile.canRead()) { var destinationFile = File.$new.overload('java.lang.String').call(File, '/data/data/net.xiphiasilver.c0pyc4t/cache/test.bak'); destinationFile.createNewFile(); var fileInputStream = FileInputStream.$new.overload('java.io.File').call(FileInputStream, sourceFile); var fileOutputStream = FileOutputStream.$new.overload('java.io.File').call(FileOutputStream, destinationFile); var bufferedInputStream = BufferedInputStream.$new.overload('java.io.InputStream').call(BufferedInputStream, fileInputStream); var bufferedOutputStream = BufferedOutputStream.$new.overload('java.io.OutputStream').call(BufferedOutputStream, fileOutputStream); var data = 0; while ((data = bufferedInputStream.read()) != -1) { bufferedOutputStream.write(data); console.log('buffuredInputStream : ' + data); } bufferedInputStream.close(); fileInputStream.close(); bufferedOutputStream.close(); fileOutputStream.close(); } else { console.log('Error : File cannot read.') } }) |