mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-07-03 21:21:12 +08:00
Add null checks
This commit is contained in:
parent
7d794e2d65
commit
875f1ce7a9
@ -180,8 +180,13 @@ public class MitmReceiver implements Runnable, ConnectionsListener, MitmListener
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "Receiving data...");
|
||||
if(mSocketFd == null) {
|
||||
Log.d(TAG, "Null socket, abort");
|
||||
mProxyRunning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Receiving data...");
|
||||
try(DataInputStream istream = new DataInputStream(new ParcelFileDescriptor.AutoCloseInputStream(mSocketFd))) {
|
||||
while(mAddon.isConnected()) {
|
||||
String msg_type;
|
||||
|
||||
@ -268,6 +268,8 @@ public class ConnectionDetailsActivity extends BaseActivity implements Connectio
|
||||
|
||||
for(int i=mCurChunks; i<max_check; i++) {
|
||||
PayloadChunk chunk = mConn.getPayloadChunk(i);
|
||||
if(chunk == null)
|
||||
continue;
|
||||
|
||||
if(!mHasHttpTab && (chunk.type == PayloadChunk.ChunkType.HTTP)) {
|
||||
mHasHttpTab = true;
|
||||
|
||||
@ -815,7 +815,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
deleted = (getContentResolver().delete(pcapUri, null, null) == 1);
|
||||
else
|
||||
deleted = DocumentsContract.deleteDocument(getContentResolver(), pcapUri);
|
||||
} catch (FileNotFoundException | UnsupportedOperationException e) {
|
||||
} catch (FileNotFoundException | UnsupportedOperationException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@ -338,6 +338,8 @@ public class PayloadAdapter extends RecyclerView.Adapter<PayloadAdapter.PayloadV
|
||||
public void handleChunksAdded(int tot_chunks) {
|
||||
for(int i = mHandledChunks; i<tot_chunks; i++) {
|
||||
PayloadChunk chunk = mConn.getPayloadChunk(i);
|
||||
if(chunk == null)
|
||||
continue;
|
||||
|
||||
// Exclude unrelated chunks
|
||||
if((mMode != ChunkType.RAW) && (mMode != chunk.type))
|
||||
|
||||
@ -188,7 +188,7 @@ public class ConnectionPayload extends Fragment implements ConnectionDetailsActi
|
||||
return mConn.l7proto.equals("HTTPS");
|
||||
|
||||
PayloadChunk firstChunk = mConn.getPayloadChunk(0);
|
||||
if(firstChunk.type == PayloadChunk.ChunkType.HTTP)
|
||||
if((firstChunk == null) || (firstChunk.type == PayloadChunk.ChunkType.HTTP))
|
||||
return true;
|
||||
|
||||
// guess based on the actual data
|
||||
|
||||
@ -23,6 +23,7 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.emanuelef.remote_capture.AppsResolver;
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
@ -296,7 +297,7 @@ public class ConnectionDescriptor {
|
||||
|
||||
public int getNumPayloadChunks() { return (payload_chunks == null) ? 0 : payload_chunks.size(); }
|
||||
|
||||
public PayloadChunk getPayloadChunk(int idx) {
|
||||
public @Nullable PayloadChunk getPayloadChunk(int idx) {
|
||||
if(getNumPayloadChunks() <= idx)
|
||||
return null;
|
||||
return payload_chunks.get(idx);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user