Compare commits

..

2 Commits

Author SHA1 Message Date
Rory Flynn
06f65dbbcf Autofix for ruff 2025-01-14 11:50:24 +01:00
Nimrod Adam
1c78874b82 Add command completion docs (#410) 2025-01-13 14:48:47 +01:00
5 changed files with 46 additions and 86 deletions

View File

@@ -8,7 +8,7 @@ To enable it, you need to manually register a special function with your shell,
The following describes how to generate the command completion scripts and add them to your shell configuration. The following describes how to generate the command completion scripts and add them to your shell configuration.
> **Note: You will need to start a new shell for the changes to take effect.** `You will need to start a new shell for the changes to take effect.`
### For Bash ### For Bash
@@ -16,11 +16,8 @@ The following describes how to generate the command completion scripts and add t
# Generates bash completion scripts # Generates bash completion scripts
echo "$(_MVT_IOS_COMPLETE=bash_source mvt-ios)" > ~/.mvt-ios-complete.bash && echo "$(_MVT_IOS_COMPLETE=bash_source mvt-ios)" > ~/.mvt-ios-complete.bash &&
echo "$(_MVT_ANDROID_COMPLETE=bash_source mvt-android)" > ~/.mvt-android-complete.bash echo "$(_MVT_ANDROID_COMPLETE=bash_source mvt-android)" > ~/.mvt-android-complete.bash
```
Add the following to `~/.bashrc`: # Sources the scripts in ~/.bashrc.
```bash
# source mvt completion scripts
. ~/.mvt-ios-complete.bash && . ~/.mvt-android-complete.bash . ~/.mvt-ios-complete.bash && . ~/.mvt-android-complete.bash
``` ```
@@ -30,11 +27,8 @@ Add the following to `~/.bashrc`:
# Generates zsh completion scripts # Generates zsh completion scripts
echo "$(_MVT_IOS_COMPLETE=zsh_source mvt-ios)" > ~/.mvt-ios-complete.zsh && echo "$(_MVT_IOS_COMPLETE=zsh_source mvt-ios)" > ~/.mvt-ios-complete.zsh &&
echo "$(_MVT_ANDROID_COMPLETE=zsh_source mvt-android)" > ~/.mvt-android-complete.zsh echo "$(_MVT_ANDROID_COMPLETE=zsh_source mvt-android)" > ~/.mvt-android-complete.zsh
```
Add the following to `~/.zshrc`: # Sources the scripts in ~/.zshrc.
```bash
# source mvt completion scripts
. ~/.mvt-ios-complete.zsh && . ~/.mvt-android-complete.zsh . ~/.mvt-ios-complete.zsh && . ~/.mvt-android-complete.zsh
``` ```

View File

@@ -98,7 +98,3 @@ You now should have the `mvt-ios` and `mvt-android` utilities installed.
**Notes:** **Notes:**
1. The `--force` flag is necessary to force the reinstallation of the package. 1. The `--force` flag is necessary to force the reinstallation of the package.
2. To revert to using a PyPI version, it will be necessary to `pipx uninstall mvt` first. 2. To revert to using a PyPI version, it will be necessary to `pipx uninstall mvt` first.
## Setting up command completions
See ["Command completions"](command_completion.md)

View File

@@ -3,4 +3,4 @@
# Use of this software is governed by the MVT License 1.1 that can be found at # Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/ # https://license.mvt.re/1.1/
MVT_VERSION = "2.6.0" MVT_VERSION = "2.5.4"

View File

@@ -1095,9 +1095,5 @@
{ {
"version": "18.2", "version": "18.2",
"build": "22C152" "build": "22C152"
},
{
"version": "18.2.1",
"build": "22C161"
} }
] ]

View File

@@ -38,70 +38,44 @@ class NetBase(IOSExtraction):
def _extract_net_data(self): def _extract_net_data(self):
conn = sqlite3.connect(self.file_path) conn = sqlite3.connect(self.file_path)
conn.row_factory = sqlite3.Row
cur = conn.cursor() cur = conn.cursor()
try: cur.execute(
cur.execute(
"""
SELECT
ZPROCESS.ZFIRSTTIMESTAMP,
ZPROCESS.ZTIMESTAMP,
ZPROCESS.ZPROCNAME,
ZPROCESS.ZBUNDLENAME,
ZPROCESS.Z_PK AS ZPROCESS_PK,
ZLIVEUSAGE.ZWIFIIN,
ZLIVEUSAGE.ZWIFIOUT,
ZLIVEUSAGE.ZWWANIN,
ZLIVEUSAGE.ZWWANOUT,
ZLIVEUSAGE.Z_PK AS ZLIVEUSAGE_PK,
ZLIVEUSAGE.ZHASPROCESS,
ZLIVEUSAGE.ZTIMESTAMP AS ZL_TIMESTAMP
FROM ZLIVEUSAGE
LEFT JOIN ZPROCESS ON ZLIVEUSAGE.ZHASPROCESS = ZPROCESS.Z_PK
UNION
SELECT ZFIRSTTIMESTAMP, ZTIMESTAMP, ZPROCNAME, ZBUNDLENAME, Z_PK,
NULL, NULL, NULL, NULL, NULL, NULL, NULL
FROM ZPROCESS WHERE Z_PK NOT IN
(SELECT ZHASPROCESS FROM ZLIVEUSAGE);
""" """
) SELECT
except sqlite3.OperationalError: ZPROCESS.ZFIRSTTIMESTAMP,
# Recent phones don't have ZWIFIIN and ZWIFIOUT columns ZPROCESS.ZTIMESTAMP,
cur.execute( ZPROCESS.ZPROCNAME,
""" ZPROCESS.ZBUNDLENAME,
SELECT ZPROCESS.Z_PK,
ZPROCESS.ZFIRSTTIMESTAMP, ZLIVEUSAGE.ZWIFIIN,
ZPROCESS.ZTIMESTAMP, ZLIVEUSAGE.ZWIFIOUT,
ZPROCESS.ZPROCNAME, ZLIVEUSAGE.ZWWANIN,
ZPROCESS.ZBUNDLENAME, ZLIVEUSAGE.ZWWANOUT,
ZPROCESS.Z_PK AS ZPROCESS_PK, ZLIVEUSAGE.Z_PK,
ZLIVEUSAGE.ZWWANIN, ZLIVEUSAGE.ZHASPROCESS,
ZLIVEUSAGE.ZWWANOUT, ZLIVEUSAGE.ZTIMESTAMP
ZLIVEUSAGE.Z_PK AS ZLIVEUSAGE_PK, FROM ZLIVEUSAGE
ZLIVEUSAGE.ZHASPROCESS, LEFT JOIN ZPROCESS ON ZLIVEUSAGE.ZHASPROCESS = ZPROCESS.Z_PK
ZLIVEUSAGE.ZTIMESTAMP AS ZL_TIMESTAMP UNION
FROM ZLIVEUSAGE SELECT ZFIRSTTIMESTAMP, ZTIMESTAMP, ZPROCNAME, ZBUNDLENAME, Z_PK,
LEFT JOIN ZPROCESS ON ZLIVEUSAGE.ZHASPROCESS = ZPROCESS.Z_PK NULL, NULL, NULL, NULL, NULL, NULL, NULL
UNION FROM ZPROCESS WHERE Z_PK NOT IN
SELECT ZFIRSTTIMESTAMP, ZTIMESTAMP, ZPROCNAME, ZBUNDLENAME, Z_PK, (SELECT ZHASPROCESS FROM ZLIVEUSAGE);
NULL, NULL, NULL, NULL, NULL """
FROM ZPROCESS WHERE Z_PK NOT IN )
(SELECT ZHASPROCESS FROM ZLIVEUSAGE);
"""
)
for row in cur: for row in cur:
# ZPROCESS records can be missing after the JOIN. # ZPROCESS records can be missing after the JOIN.
# Handle NULL timestamps. # Handle NULL timestamps.
if row["ZFIRSTTIMESTAMP"] and row["ZTIMESTAMP"]: if row[0] and row[1]:
first_isodate = convert_mactime_to_iso(row["ZFIRSTTIMESTAMP"]) first_isodate = convert_mactime_to_iso(row[0])
isodate = convert_mactime_to_iso(row["ZTIMESTAMP"]) isodate = convert_mactime_to_iso(row[1])
else: else:
first_isodate = row["ZFIRSTTIMESTAMP"] first_isodate = row[0]
isodate = row["ZTIMESTAMP"] isodate = row[1]
if row["ZL_TIMESTAMP"]: if row[11]:
live_timestamp = convert_mactime_to_iso(row["ZL_TIMESTAMP"]) live_timestamp = convert_mactime_to_iso(row[11])
else: else:
live_timestamp = "" live_timestamp = ""
@@ -109,18 +83,16 @@ class NetBase(IOSExtraction):
{ {
"first_isodate": first_isodate, "first_isodate": first_isodate,
"isodate": isodate, "isodate": isodate,
"proc_name": row["ZPROCNAME"], "proc_name": row[2],
"bundle_id": row["ZBUNDLENAME"], "bundle_id": row[3],
"proc_id": row["ZPROCESS_PK"], "proc_id": row[4],
"wifi_in": row["ZWIFIIN"] if "ZWIFIIN" in row.keys() else None, "wifi_in": row[5],
"wifi_out": row["ZWIFIOUT"] if "ZWIFIOUT" in row.keys() else None, "wifi_out": row[6],
"wwan_in": row["ZWWANIN"], "wwan_in": row[7],
"wwan_out": row["ZWWANOUT"], "wwan_out": row[8],
"live_id": row["ZLIVEUSAGE_PK"], "live_id": row[9],
"live_proc_id": row["ZHASPROCESS"], "live_proc_id": row[10],
"live_isodate": live_timestamp "live_isodate": live_timestamp if row[11] else first_isodate,
if row["ZL_TIMESTAMP"]
else first_isodate,
} }
) )
@@ -136,6 +108,8 @@ class NetBase(IOSExtraction):
) )
record_data_usage = ( record_data_usage = (
record_data + " " record_data + " "
f"WIFI IN: {record['wifi_in']}, "
f"WIFI OUT: {record['wifi_out']} - "
f"WWAN IN: {record['wwan_in']}, " f"WWAN IN: {record['wwan_in']}, "
f"WWAN OUT: {record['wwan_out']}" f"WWAN OUT: {record['wwan_out']}"
) )