Rename PCAPdroid trailer to extensions

This commit is contained in:
emanuele-f
2025-01-04 17:03:42 +01:00
parent 4a28879318
commit d25b4eb707
14 changed files with 63 additions and 61 deletions
@@ -1353,7 +1353,7 @@ public class CaptureService extends VpnService implements Runnable {
public int firewallEnabled() { return(mFirewallEnabled ? 1 : 0); }
public int addPcapdroidTrailer() { return(mSettings.pcapdroid_trailer ? 1 : 0); }
public int dumpExtensionsEnabled() { return(mSettings.dump_extensions ? 1 : 0); }
public int isPcapngEnabled() { return(mSettings.pcapng_format ? 1 : 0); }
@@ -1671,5 +1671,5 @@ public class CaptureService extends VpnService implements Runnable {
public static native void setPayloadMode(int mode);
public static native List<String> getL7Protocols();
public static native void dumpMasterSecret(byte[] secret);
public static native boolean hasSeenPcapdroidTrailer();
public static native boolean hasSeenDumpExtensions();
}
@@ -110,7 +110,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
private boolean mWasStarted = false;
private boolean mStartPressed = false;
private boolean mDecEmptyRulesNoticeShown = false;
private boolean mTrailerNoticeShown = false;
private boolean mExtensionsNoticeShown = false;
private static final String TAG = "Main";
@@ -638,13 +638,13 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
ConnectionsRegister reg = CaptureService.getConnsRegister();
if((reg != null) && (reg.getConnCount() > 0)
&& !CaptureService.hasSeenPcapdroidTrailer()
&& !mTrailerNoticeShown
&& !CaptureService.hasSeenDumpExtensions()
&& !mExtensionsNoticeShown
) {
new AlertDialog.Builder(this)
.setMessage(getString(R.string.pcapdroid_trailer_notice,
getString(R.string.unknown_app), getString(R.string.pcapdroid_trailer)))
.setPositiveButton(R.string.ok, (d, whichButton) -> mTrailerNoticeShown = true)
getString(R.string.unknown_app), getString(R.string.dump_extensions)))
.setPositiveButton(R.string.ok, (d, whichButton) -> mExtensionsNoticeShown = true)
.show();
} else
Utils.showToastLong(this, R.string.pcap_load_success);
@@ -168,7 +168,7 @@ public class OnBoardingActivity extends AppIntro {
addSlide(OnBoardingFragment.createInstance(getString(R.string.traffic_dump),
Utils.getText(this, R.string.app_intro_traffic_dump,
MainActivity.DOCS_URL + "/dump_modes",
MainActivity.DOCS_URL + "/advanced_features#45-pcapdroid-trailer"),
MainActivity.DOCS_URL + "/advanced_features#45-pcapdroid-extensions"),
R.drawable.dump_modes, 0, false));
addSlide(OnBoardingFragment.createInstance(getString(R.string.country_and_asn),
@@ -29,7 +29,7 @@ public class CaptureSettings implements Serializable {
public Prefs.IpMode ip_mode;
public String input_pcap_path;
public boolean root_capture;
public boolean pcapdroid_trailer;
public boolean dump_extensions;
public boolean full_payload;
public Prefs.BlockQuicMode block_quic_mode;
public boolean auto_block_private_dns;
@@ -55,7 +55,7 @@ public class CaptureSettings implements Serializable {
socks5_password = Prefs.isSocks5AuthEnabled(prefs) ? Prefs.getSocks5Password(prefs) : "";
ip_mode = Prefs.getIPMode(prefs);
root_capture = Prefs.isRootCaptureEnabled(prefs);
pcapdroid_trailer = Prefs.isPcapdroidTrailerEnabled(prefs);
dump_extensions = Prefs.isPcapdroidMetadataEnabled(prefs);
capture_interface = Prefs.getCaptureInterface(prefs);
tls_decryption = Prefs.getTlsDecryptionEnabled(prefs);
full_payload = Prefs.getFullPayloadMode(prefs);
@@ -78,7 +78,8 @@ public class CaptureSettings implements Serializable {
socks5_password = getString(intent, Prefs.PREF_SOCKS5_PASSWORD_KEY, "");
ip_mode = Prefs.getIPMode(getString(intent, Prefs.PREF_IP_MODE, Prefs.IP_MODE_DEFAULT));
root_capture = getBool(intent, Prefs.PREF_ROOT_CAPTURE, false);
pcapdroid_trailer = getBool(intent, Prefs.PREF_PCAPDROID_TRAILER, false);
dump_extensions = getBool(intent, Prefs.PREF_DUMP_EXTENSIONS, false) ||
getBool(intent, "pcapdroid_trailer", false) /* deprecated */;
capture_interface = getString(intent, Prefs.PREF_CAPTURE_INTERFACE, "@inet");
pcap_uri = getString(intent, "pcap_uri", "");
pcap_name = getString(intent, "pcap_name", "");
@@ -75,7 +75,7 @@ public class Prefs {
public static final String PREF_ROOT_CAPTURE = "root_capture";
public static final String PREF_VISUALIZATION_MASK = "vis_mask";
public static final String PREF_MALWARE_WHITELIST = "malware_whitelist";
public static final String PREF_PCAPDROID_TRAILER = "pcapdroid_trailer";
public static final String PREF_DUMP_EXTENSIONS = "dump_extensions";
public static final String PREF_BLOCKLIST = "bl";
public static final String PREF_FIREWALL_WHITELIST_MODE = "firewall_wl_mode";
public static final String PREF_FIREWALL_WHITELIST_INIT_VER = "firewall_wl_init";
@@ -205,7 +205,7 @@ public class Prefs {
public static BlockQuicMode getBlockQuicMode(SharedPreferences p) { return(getBlockQuicMode(p.getString(PREF_BLOCK_QUIC, BLOCK_QUIC_MODE_DEFAULT))); }
public static boolean useEnglishLanguage(SharedPreferences p){ return("english".equals(p.getString(PREF_APP_LANGUAGE, "system")));}
public static boolean isRootCaptureEnabled(SharedPreferences p) { return(Utils.isRootAvailable() && p.getBoolean(PREF_ROOT_CAPTURE, false)); }
public static boolean isPcapdroidTrailerEnabled(SharedPreferences p) { return(p.getBoolean(PREF_PCAPDROID_TRAILER, false)); }
public static boolean isPcapdroidMetadataEnabled(SharedPreferences p) { return(p.getBoolean(PREF_DUMP_EXTENSIONS, false)); }
public static String getCaptureInterface(SharedPreferences p) { return(p.getString(PREF_CAPTURE_INTERFACE, "@inet")); }
public static boolean isMalwareDetectionEnabled(Context ctx, SharedPreferences p) {
return(Billing.newInstance(ctx).isPurchased(Billing.MALWARE_DETECTION_SKU)
@@ -281,7 +281,7 @@ public class Prefs {
"\nBlockNewApps: " + blockNewApps(p) +
"\nTargetApps: " + getAppFilter(p) +
"\nIpMode: " + getIPMode(p) +
"\nTrailer: " + isPcapdroidTrailerEnabled(p) +
"\nDumpExtensions: " + isPcapdroidMetadataEnabled(p) +
"\nStartAtBoot: " + startAtBoot(p);
}
}
+1 -1
View File
@@ -430,7 +430,7 @@ static bool handle_packet(pcapdroid_t *pd, pcapd_hdr_t *hdr, const char *buffer,
if(ntohl(trailer->magic) == PCAPDROID_TRAILER_MAGIC) {
hdr->uid = ntohl(trailer->uid);
has_seen_pcapdroid_trailer = true;
has_seen_dump_extensions = true;
}
}
}
+4 -4
View File
@@ -593,7 +593,7 @@ Java_com_emanuelef_remote_1capture_CaptureService_runPacketLoop(JNIEnv *env, jcl
.payload_mode = (payload_mode_t) getIntPref(env, vpn, "getPayloadMode"),
.pcap_dump = {
.enabled = (bool) getIntPref(env, vpn, "pcapDumpEnabled"),
.trailer_enabled = (bool)getIntPref(env, vpn, "addPcapdroidTrailer"),
.dump_extensions = (bool)getIntPref(env, vpn, "dumpExtensionsEnabled"),
.pcapng_format = (bool)getIntPref(env, vpn, "isPcapngEnabled"),
.snaplen = getIntPref(env, vpn, "getSnaplen"),
.max_pkts_per_flow = getIntPref(env, vpn, "getMaxPktsPerFlow"),
@@ -1306,9 +1306,9 @@ Java_com_emanuelef_remote_1capture_CaptureService_dumpMasterSecret(JNIEnv *env,
/* ******************************************************* */
JNIEXPORT jboolean JNICALL
Java_com_emanuelef_remote_1capture_CaptureService_hasSeenPcapdroidTrailer(JNIEnv *env,
jclass clazz) {
return has_seen_pcapdroid_trailer;
Java_com_emanuelef_remote_1capture_CaptureService_hasSeenDumpExtensions(JNIEnv *env,
jclass clazz) {
return has_seen_dump_extensions;
}
#endif // ANDROID
+7 -7
View File
@@ -40,7 +40,7 @@ typedef struct {
struct pcap_dumper {
pcap_dump_format_t format;
bool trailer_enabled;
bool dump_extensions;
pcap_dump_callback *dump_cb;
pcapdroid_t *pd;
int snaplen;
@@ -62,7 +62,7 @@ struct pcap_dumper {
/* ******************************************************* */
pcap_dumper_t* pcap_new_dumper(pcap_dump_format_t format, bool trailer_enabled,
pcap_dumper_t* pcap_new_dumper(pcap_dump_format_t format, bool dump_extensions,
int snaplen, uint64_t max_dump_size,
pcap_dump_callback dumpcb, pcapdroid_t *pd) {
pcap_dumper_t *dumper = pd_calloc(1, sizeof(pcap_dumper_t));
@@ -89,7 +89,7 @@ pcap_dumper_t* pcap_new_dumper(pcap_dump_format_t format, bool trailer_enabled,
dumper->snaplen = snaplen;
dumper->format = format;
dumper->trailer_enabled = trailer_enabled;
dumper->dump_extensions = dump_extensions;
dumper->max_dump_size = max_dump_size;
dumper->dump_cb = dumpcb;
dumper->pd = pd;
@@ -255,7 +255,7 @@ static int get_pcap_file_header(pcap_dumper_t *dumper, char **out) {
pcap_hdr->thiszone = 0;
pcap_hdr->sigfigs = 0;
pcap_hdr->snaplen = dumper->snaplen;
pcap_hdr->network = dumper->trailer_enabled ? LINKTYPE_ETHERNET : LINKTYPE_RAW;
pcap_hdr->network = dumper->dump_extensions ? LINKTYPE_ETHERNET : LINKTYPE_RAW;
*out = (char*)pcap_hdr;
return sizeof(struct pcap_hdr);
@@ -343,7 +343,7 @@ static bool dump_packet_pcap(pcap_dumper_t *dumper, const char *pkt, int pktlen,
bool with_trailer = false;
int trailer_overhead = 0;
if(dumper->trailer_enabled) {
if(dumper->dump_extensions) {
// Pad the frame so that the buffer keeps its 4-bytes alignment
pre_trailer_padding = (~(sizeof(struct ethhdr) + incl_len) + 1) & 0x3;
trailer_overhead = (int)(sizeof(struct ethhdr) + pre_trailer_padding + sizeof(pcapdroid_trailer_t));
@@ -473,7 +473,7 @@ static bool dump_pcapng_uid_mapping(pcap_dumper_t *dumper, int uid) {
static bool dump_packet_pcapng(pcap_dumper_t *dumper, const char *pkt, int pktlen,
const struct timeval *tv, int uid) {
if(dumper->trailer_enabled) {
if(dumper->dump_extensions) {
mapped_uid_t *item;
HASH_FIND_INT(dumper->mapped_uids, &uid, item);
@@ -497,7 +497,7 @@ static bool dump_packet_pcapng(pcap_dumper_t *dumper, const char *pkt, int pktle
uint8_t comment_padding = 0;
bool has_comment = false;
if(dumper->trailer_enabled) {
if(dumper->dump_extensions) {
comment_len = snprintf(comment, sizeof(comment), "u-%d", uid);
comment_padding = (~comment_len + 1) & 0x3;
total_length += sizeof(pcapng_enh_option_t) + comment_len + comment_padding;
+1 -1
View File
@@ -153,7 +153,7 @@ typedef struct pcapdroid_trailer {
struct pcapdroid;
typedef void pcap_dump_callback(struct pcapdroid *pd, const int8_t *buf, int dump_size);
pcap_dumper_t* pcap_new_dumper(pcap_dump_format_t format, bool trailer_enabled, int snaplen, uint64_t max_dump_size,
pcap_dumper_t* pcap_new_dumper(pcap_dump_format_t format, bool dump_extensions, int snaplen, uint64_t max_dump_size,
pcap_dump_callback dumpcb, struct pcapdroid *pd);
void pcap_destroy_dumper(pcap_dumper_t *dumper);
bool pcap_dump_packet(pcap_dumper_t *dumper, const char *pkt, int pktlen, const struct timeval *tv, int uid);
+3 -3
View File
@@ -36,7 +36,7 @@ extern void vpn_process_ndpi(pcapdroid_t *pd, const zdtun_5tuple_t *tuple, pd_co
bool running = false;
uint32_t new_dns_server = 0;
bool block_private_dns = false;
bool has_seen_pcapdroid_trailer = false;
bool has_seen_dump_extensions = false;
bool dump_capture_stats_now = false;
bool reload_blacklists_now = false;
@@ -1165,7 +1165,7 @@ void pd_account_stats(pcapdroid_t *pd, pkt_context_t *pctx) {
int pd_run(pcapdroid_t *pd) {
/* Important: init global state every time. Android may reuse the service. */
running = true;
has_seen_pcapdroid_trailer = false;
has_seen_dump_extensions = false;
netd_resolve_waiting = 0;
/* nDPI */
@@ -1195,7 +1195,7 @@ int pd_run(pcapdroid_t *pd) {
pd->pcap_dump.snaplen = max_snaplen;
pcap_dump_format_t dump_fmt = pd->pcap_dump.pcapng_format ? PCAPNG_DUMP : PCAP_DUMP;
bool trailer_enabled = pd->pcap_dump.trailer_enabled;
bool trailer_enabled = pd->pcap_dump.dump_extensions;
log_d("dump_mode: %d - trailer: %u", dump_fmt, trailer_enabled);
pd->pcap_dump.dumper = pcap_new_dumper(dump_fmt, trailer_enabled,
+2 -2
View File
@@ -242,7 +242,7 @@ typedef struct pcapdroid {
struct {
bool enabled;
bool trailer_enabled;
bool dump_extensions;
bool pcapng_format;
int snaplen;
int max_pkts_per_flow;
@@ -378,7 +378,7 @@ extern uint32_t new_dns_server;
extern bool block_private_dns;
extern bool dump_capture_stats_now;
extern bool reload_blacklists_now;
extern bool has_seen_pcapdroid_trailer;
extern bool has_seen_dump_extensions;
extern int bl_num_checked_connections;
extern int fw_num_checked_connections;
extern char *pd_appver;
+4 -4
View File
@@ -160,9 +160,9 @@
<string name="unknown_app_info">\"Unknown\" marks connections whose app could not be determined</string>
<string name="packets_dropped">Packets dropped</string>
<string name="capture_prefs">Capture</string>
<string name="pcapdroid_trailer">PCAPdroid trailer</string>
<string name="pcapdroid_trailer_summary">A trailer containing additional metadata (such as the app name) will be added to the dumped packets</string>
<string name="trailer_how_to">How to display the trailer data in Wireshark</string>
<string name="dump_extensions">PCAPdroid extensions</string>
<string name="dump_extensions_summary">Extend the packet dump format with additional metadata, such as the app which sent/received a given packet</string>
<string name="dump_extensions_how_to">How to display the PCAPdroid dump extensions in Wireshark</string>
<string name="pending_transaction">Please complete your transaction to redeem this feature</string>
<string name="ctrl_consent">An app wants to capture your device traffic.\nDeny it if you are not sure</string>
<string name="deny">Deny</string>
@@ -367,7 +367,7 @@
<string name="app_intro_traffic_inspection">Inspecting HTTP requests, responses and raw data is easy, thanks to the built-in decoders\n\nGot an encrypted connection? You can enable the <a href='%1$s'>TLS decryption</a> to get the decrypted data</string>
<string name="app_intro_firewall_msg">With the integrated <a href='%1$s'>Firewall</a> you can easily block Internet access to individual apps and domains\n\nCombine this with the built-in traffic visibility to get the ultimate tool to protect your privacy</string>
<string name="app_intro_malware_detection">Enhance the security of your device with the <a href='%1$s'>malware detection</a> feature\n\nBy using up-to-date blacklists, it can detect, block and alert malicious connections in real-time</string>
<string name="app_intro_traffic_dump">PCAPdroid provides <a href='%1$s'>multiple ways</a> to dump the traffic in the standard PCAP format for further analysis\n\nVia the <a href='%2$s'>trailer option</a>, you can add app names to the packets and display them in Wireshark</string>
<string name="app_intro_traffic_dump">PCAPdroid provides <a href='%1$s'>multiple ways</a> to dump the traffic in the standard PCAP format for further analysis\n\nVia the <a href='%2$s'>PCAPdroid extensions option</a>, you can add app names to the packets and display them in Wireshark</string>
<string name="permission_granted">%1$s permission was granted</string>
<string name="permission_grant_fail">%1$s permission could not be granted</string>
<string name="connection_not_found">Could not find the given connection</string>
+22 -22
View File
@@ -87,13 +87,6 @@
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:key="pcapng_format"
app:title="@string/pcapng_format"
app:iconSpaceReserved="false"
app:summary="@string/pcapng_format_summary"
app:defaultValue="true" />
<DropDownPreference
app:key="block_quic_mode"
app:title="@string/block_quick"
@@ -139,6 +132,28 @@
app:summary="@string/vpn_exemptions_summary"
app:iconSpaceReserved="false" />
<SwitchPreference
app:key="pcapng_format"
app:title="@string/pcapng_format"
app:iconSpaceReserved="false"
app:summary="@string/pcapng_format_summary"
app:defaultValue="true" />
<SwitchPreference
app:key="dump_extensions"
app:title="@string/dump_extensions"
app:iconSpaceReserved="false"
app:summary="@string/dump_extensions_summary"
app:defaultValue="false" />
<Preference
app:key="dump_extensions_how_to"
app:title="@string/dump_extensions_how_to"
app:iconSpaceReserved="false">
<intent android:action="android.intent.action.VIEW"
android:data="https://emanuele-f.github.io/PCAPdroid/advanced_features#45-pcapdroid-extensions" />
</Preference>
<Preference
android:key="dns_settings"
app:title="@string/dns_servers"
@@ -159,21 +174,6 @@
app:iconSpaceReserved="false"
app:summary="@string/restart_on_disconnection_summary"
android:defaultValue="false" />
<SwitchPreference
app:key="pcapdroid_trailer"
app:title="@string/pcapdroid_trailer"
app:iconSpaceReserved="false"
app:summary="@string/pcapdroid_trailer_summary"
app:defaultValue="false" />
<Preference
app:key="trailer_how_to"
app:title="@string/trailer_how_to"
app:iconSpaceReserved="false">
<intent android:action="android.intent.action.VIEW"
android:data="https://emanuele-f.github.io/PCAPdroid/advanced_features#45-pcapdroid-trailer" />
</Preference>
</PreferenceCategory>
<PreferenceCategory app:title="@string/security" app:iconSpaceReserved="false" app:key="security">
+4 -3
View File
@@ -31,7 +31,7 @@ adb shell am start -e action start -e pcap_dump_mode udp_exporter -e collector_i
```
then your app can listen for UDP packets on port `5123` to handle the Firefox network packets.
Another interesting option is to enable the [pcapdroid_trailer](https://emanuele-f.github.io/PCAPdroid/advanced_features#45-pcapdroid-trailer) to be able to get the app UID/name into your app.
Another interesting option is to enable the [dump_extensions](https://emanuele-f.github.io/PCAPdroid/advanced_features#45-pcapdroid-extensions) to be able to get the app UID/name into your app.
The Intent above can also be triggered programmatically from your app:
@@ -88,7 +88,7 @@ As shown above, the capture settings can be specified by using intent extras. Th
| socks5_proxy_ip_address | string | | vpn | the SOCKS5 proxy IP address |
| socks5_proxy_port | int | | vpn | the SOCKS5 proxy port |
| root_capture | bool | | | true to capture packets in root mode, false to use the VPNService |
| pcapdroid_trailer | bool | | | true to enable the PCAPdroid trailer |
| pcapdroid_trailer | bool | | | (deprecated) alias for dump_extensions |
| capture_interface | string | | root | @inet \| any \| ifname - network interface to use in root mode |
| snaplen | int | 43 | | max size in bytes for each individual packet in the PCAP dump |
| max_pkts_per_flow | int | 43 | | only dump the first max_pkts_per_flow packets per flow |
@@ -98,10 +98,11 @@ As shown above, the capture settings can be specified by using intent extras. Th
| ip_mode | string | 56 | vpn | which IP addresses to use for the VPN: ipv4 \| ipv6 \| both |
| mitmproxy_opts | string | 62 | | additional options to provide to mitmproxy in decryption mode |
| pcap_name | string | 62 | | write the PCAP to Download/PCAPdroid/*pcap_name* in pcap_file mode |
| pcapng_format | bool | 62 | | true to use the PCAPNG dump format (overrides pcapdroid_trailer)* |
| pcapng_format | bool | 62 | | true to use the PCAPNG dump format* |
| socks5_username | string | 64 | vpn | username for the optional SOCKS5 proxy authentication |
| socks5_password | string | 64 | vpn | password for the optional SOCKS5 proxy authentication |
| block_quic | string | 73 | vpn | never \| always \| to_decrypt (matching the decryption whitelist) |
| dump_extensions | bool | 79 | | extend the packet dump format with additional metadata |
\*: paid feature