Skip to content

Commit

Permalink
Fix keylog being asked with Pcapng file
Browse files Browse the repository at this point in the history
On newer Android versions, the uri does not contain the ".pcapng" extension

See #351
  • Loading branch information
emanuele-f committed Jun 16, 2024
1 parent 754c657 commit 8ab44d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions app/src/main/java/com/emanuelef/remote_capture/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -142,8 +143,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import javax.net.ssl.HttpsURLConnection;

Expand Down Expand Up @@ -1789,4 +1788,21 @@ public static boolean isReadable(String path) {
return false;
}
}

public static boolean isPcapng(Context ctx, Uri uri) {
try (InputStream in_stream = ctx.getContentResolver().openInputStream(uri)) {
try (DataInputStream data_in = new DataInputStream(in_stream)) {
int block_type = data_in.readInt();
data_in.skipBytes(4);
int magic = data_in.readInt();

return ((block_type == 0x0A0D0D0A) &&
((magic == 0x1a2b3c4d) || (magic == 0x4d3c2b1a)));
}
} catch (IOException e) {
Log.w(TAG, "Reading " + uri + " failed: " + e);
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -920,14 +920,14 @@ private void pcapFileOpenResult(final ActivityResult result) {

Log.d(TAG, "pcapFileOpenResult: " + uri);
if (mOpenPcapDecrypt &&
(!mIab.isPurchased(Billing.PCAPNG_SKU) || !uri.toString().endsWith(".pcapng"))
(!mIab.isPurchased(Billing.PCAPNG_SKU) || !Utils.isPcapng(this, uri))
) {
// Ask to select the keylog
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");

Log.d(TAG, "pcapFileOpenResult: launching dialog");
Log.i(TAG, "separate keylog file needed, launching dialog");
mPcapUri = uri;
Utils.showToast(this, R.string.select_the_keylog_file);
Utils.launchFileDialog(this, intent, keylogFileOpenLauncher);
Expand Down

0 comments on commit 8ab44d0

Please sign in to comment.