You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
content_to_json and the query_content skip check change or drop provider rows #34
Hi, we're looking at how ALEAPP should read ALEX's content provider output (ALEAPP issue abrignoni/ALEAPP#2073), and reading alex.py at 9ef34bf I ran into a few things in content_to_json and query_content. The PRFS zip keeps only the JSON, and recreate_dbs builds mmssms.db, calllog.db, contacts2.db and calendar.db with the same function. So whatever it changes is what ALEAPP reports from the rebuilt databases, and what it would report from the JSON.
I copied content_to_json and the error_text check as they are and ran them on made-up input:
Input (synthetic)
Result
body=Order 77 confirmed, total=40 USD, read=0
body is cut to Order 77 confirmed and a total column appears
a=NULL, b=
both become null, so NULL and empty string can't be told apart
c= padded
padded, spaces removed (strip() also drops a trailing line break)
body=see Row: 7 of the sheet, read=1
the row is split in two at Row: 7 and the rest of the body is lost
body=the app said command not found
query_content skips the whole provider, because the four error strings are matched anywhere in the output
Multi-line values come through fine.
Some ideas, your call of course:
Keep the raw content query text in the zip next to the JSON (for example extra/content_provider/<key>/<key>.txt). Then nothing is lost and a reader can parse it on its own terms.
Treat output as a dump only when it has a line starting with Row: <n> . Anything else (No result found., an error, usage text) could be saved as it is, with a small status file per URI in the zip (rows, empty, error), so a missing file isn't read as "never queried".
In content_to_json, split records only at Row: <n> at the start of a line, keep NULL and empty string apart, and don't strip values. For the , key= case, the column order is the same for every row of a dump, so walking that order (the value of one key runs up to , <next key>=) avoids most false splits.
Happy to test any change against ALEAPP. Thanks for ALEX!
Follow-up with ALEX itself, since the table above came from the functions copied out of alex.py. I ran ALEX at 9ef34bf on a fresh Android 15 emulator (no account), PRFS backup with "Include recreated Databases" and "Include Logs and queried Data" ticked, and ADB backup, sdcard, system folders and exploits unticked.
Run 1, with no messages, calls, contacts or calendar events on the emulator (content query returned No result found. for sms, mms, mms/addr, call_log/calls, contacts, raw_contacts, data, calendar events and calendars). The rebuilt sms, pdu, addr, calls, contacts, raw_contacts, data, Events and Calendars tables each held one row made only of the ressources/*.json defaults (_id 0, times 0). content_to_json("No result found.") returns [{}], and insert_data fills that empty entry from the defaults. ALEAPP reading the rebuilt databases then showed an SMS, an MMS, a call and a calendar event dated 1970-01-01 that don't exist.
Run 2, after adding six synthetic SMS to the emulator's provider. The rebuilt mmssms.db had:
Order 77 confirmed, total=40 USD stored as Order 77 confirmed, with an empty total column added
padded stored as padded
an empty body stored as NULL
see Row: 7 of the sheet stored as see, plus an extra row with _id 0 and date 0
the multi-line body stored correctly
In the same run the PRFS zip had no extra/content_provider/sms/ files at all. One of the six bodies was the app said No result found, and No result found inside that row is what the error_text check matched, so the whole sms provider was skipped (and each sms/... path the same way). Neither the zip, its acquisition_record.json nor the .case.json records the skip. Only the ALEX log does.
Suggestion for the first part: have content_to_json return [] when the output has no Row: <n> line, and set [] instead of [{}] when a query fails, so an empty provider gives an empty table.
Checked with ed3d41e, same emulator and same PRFS options as before (recreated databases and logs ticked; ADB backup, sdcard, system folders and exploits unticked). The emulator still holds the six synthetic SMS and has no calls, contacts, calendar events or MMS.
Everything from the run before is fixed:
The rebuilt tables for the empty providers (calls, contacts, raw_contacts, data, Events, Calendars, pdu, addr, ...) are empty. No more _id 0 rows.
sms holds the six messages with their bodies exactly as inserted: Order 77 confirmed, total=40 USD with no total column, see Row: 7 of the sheet with no extra row, padded with its spaces, the empty body as an empty string, and the two-line body intact.
The zip now has extra/content_provider/sms/ with the raw .txt, the .status.json and the JSON, although one body contains "No result found". The JSON bodies match too. call_log_calls.status.json says empty.
ALEAPP main reads the rebuilt mmssms.db as exactly 6 SMS.
Thanks for the quick fix, and for keeping the raw text and a status per URI in the zip. That makes it a lot easier for ALEAPP to tell an empty provider from a failed or skipped one, and that layout suits the reader proposed in ALEAPP #2073. ALEAPP recognises a rebuilt database by every column being TEXT with user_version 0, so if that ever changes, a heads-up would help.
One limit: this run had six SMS and no other data, so the single-row path for SMS and MMS and the column-intersection split with real MMS, calls or contacts weren't exercised.
Three more cases at ed3d41e, run on the same emulator with ALEX itself (same PRFS options). I added three synthetic SMS to the six already there and backed up twice: once with all three, once without the third.
A body that is the text NULL is stored as NULL in the rebuilt mmssms.db and as null in sms.json.
A body of Order 9 shipped, read=1 today is stored as Order 9 shipped, and the message's read column holds 1 today instead of its real value, 0. read is in every row, so content_to_json treats , read= inside the body as the next column.
A body of line one, a line break, then Row: 7 read=1 breaks the whole provider. With that message present, all nine SMS in the rebuilt sms table and in sms.json have body NULL, _id holds the row up to , read=, and read holds the rest. There is also an extra row (_id 0 in the database, no _id in the JSON). The text after the line break matches \nRow: [0-9]+ (?=\w+=), so that message is cut into two rows: one with the columns up to body, and one with read and every column after body. The only column the two share is read, so the set of columns common to all rows shrinks to read.
In both backups the raw sms.txt in the zip holds what content query printed, and sms.status.json says rows.
One way to avoid the second and third: use the column order from content query itself. Every row prints the same columns in the same order, so the split can walk the known column list: a value runs up to , <next column>=. A row only starts at Row: <next number> <first column>=. The text NULL can't be told apart from a real NULL in content query output, so for case 1 keeping the raw text next to the JSON (as the zip now does) is probably the best there is. Happy to retest.
Thank you very much for these tests! As you can imagine, these cases are much less common in German. I've now set the keys to be checked starting from the right. That way, the “read” in the message is preserved.
Activity
abrignoni commentedon Nov 25, 2026
Follow-up with ALEX itself, since the table above came from the functions copied out of
alex.py. I ran ALEX at 9ef34bf on a fresh Android 15 emulator (no account), PRFS backup with "Include recreated Databases" and "Include Logs and queried Data" ticked, and ADB backup, sdcard, system folders and exploits unticked.Run 1, with no messages, calls, contacts or calendar events on the emulator (
content queryreturnedNo result found.for sms, mms, mms/addr, call_log/calls, contacts, raw_contacts, data, calendar events and calendars). The rebuiltsms,pdu,addr,calls,contacts,raw_contacts,data,EventsandCalendarstables each held one row made only of theressources/*.jsondefaults (_id0, times 0).content_to_json("No result found.")returns[{}], andinsert_datafills that empty entry from the defaults. ALEAPP reading the rebuilt databases then showed an SMS, an MMS, a call and a calendar event dated 1970-01-01 that don't exist.Run 2, after adding six synthetic SMS to the emulator's provider. The rebuilt
mmssms.dbhad:Order 77 confirmed, total=40 USDstored asOrder 77 confirmed, with an emptytotalcolumn addedpaddedstored aspaddedsee Row: 7 of the sheetstored assee, plus an extra row with_id0 and date 0In the same run the PRFS zip had no
extra/content_provider/sms/files at all. One of the six bodies wasthe app said No result found, andNo result foundinside that row is what theerror_textcheck matched, so the wholesmsprovider was skipped (and eachsms/...path the same way). Neither the zip, itsacquisition_record.jsonnor the.case.jsonrecords the skip. Only the ALEX log does.Suggestion for the first part: have
content_to_jsonreturn[]when the output has noRow: <n>line, and set[]instead of[{}]when a query fails, so an empty provider gives an empty table.Skip empty Rows wor recreated dbs (#34)
prosch88 commentedon Nov 25, 2026
Thanks for the input! Empty Rows should now be ignored while building the dbs. I'll look furter for the other issues
prosch88 commentedon Nov 25, 2026
Please check again with your test data
abrignoni commentedon Nov 26, 2026
Checked with ed3d41e, same emulator and same PRFS options as before (recreated databases and logs ticked; ADB backup, sdcard, system folders and exploits unticked). The emulator still holds the six synthetic SMS and has no calls, contacts, calendar events or MMS.
Everything from the run before is fixed:
calls,contacts,raw_contacts,data,Events,Calendars,pdu,addr, ...) are empty. No more_id0 rows.smsholds the six messages with their bodies exactly as inserted:Order 77 confirmed, total=40 USDwith nototalcolumn,see Row: 7 of the sheetwith no extra row,paddedwith its spaces, the empty body as an empty string, and the two-line body intact.extra/content_provider/sms/with the raw.txt, the.status.jsonand the JSON, although one body contains "No result found". The JSON bodies match too.call_log_calls.status.jsonsaysempty.mmssms.dbas exactly 6 SMS.Thanks for the quick fix, and for keeping the raw text and a status per URI in the zip. That makes it a lot easier for ALEAPP to tell an empty provider from a failed or skipped one, and that layout suits the reader proposed in ALEAPP #2073. ALEAPP recognises a rebuilt database by every column being TEXT with user_version 0, so if that ever changes, a heads-up would help.
One limit: this run had six SMS and no other data, so the single-row path for SMS and MMS and the column-intersection split with real MMS, calls or contacts weren't exercised.
abrignoni commentedon Nov 26, 2026
Three more cases at ed3d41e, run on the same emulator with ALEX itself (same PRFS options). I added three synthetic SMS to the six already there and backed up twice: once with all three, once without the third.
NULLis stored as NULL in the rebuiltmmssms.dband asnullinsms.json.Order 9 shipped, read=1 todayis stored asOrder 9 shipped, and the message'sreadcolumn holds1 todayinstead of its real value, 0.readis in every row, socontent_to_jsontreats, read=inside the body as the next column.line one, a line break, thenRow: 7 read=1breaks the whole provider. With that message present, all nine SMS in the rebuiltsmstable and insms.jsonhavebodyNULL,_idholds the row up to, read=, andreadholds the rest. There is also an extra row (_id0 in the database, no_idin the JSON). The text after the line break matches\nRow: [0-9]+ (?=\w+=), so that message is cut into two rows: one with the columns up tobody, and one withreadand every column afterbody. The only column the two share isread, so the set of columns common to all rows shrinks toread.In both backups the raw
sms.txtin the zip holds whatcontent queryprinted, andsms.status.jsonsaysrows.One way to avoid the second and third: use the column order from
content queryitself. Every row prints the same columns in the same order, so the split can walk the known column list: a value runs up to, <next column>=. A row only starts atRow: <next number> <first column>=. The text NULL can't be told apart from a real NULL incontent queryoutput, so for case 1 keeping the raw text next to the JSON (as the zip now does) is probably the best there is. Happy to retest.Read keys for recreated sms-entrys from right to left (#34)
prosch88 commentedon Nov 26, 2026
Thank you very much for these tests! As you can imagine, these cases are much less common in German. I've now set the keys to be checked starting from the right. That way, the “read” in the message is preserved.