Skip to content

content_to_json and the query_content skip check change or drop provider rows #34

Backlog

Description

@abrignoni

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:

  1. 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.
  2. 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".
  3. 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!

Activity

  1. abrignoni commented on Nov 25, 2026

    @abrignoni
    Author

    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.

  2. prosch88 commented on Nov 25, 2026

    @prosch88
    Owner

    Thanks for the input! Empty Rows should now be ignored while building the dbs. I'll look furter for the other issues

  3. prosch88 commented on Nov 25, 2026

    @prosch88
    Owner

    Please check again with your test data

  4. abrignoni commented on Nov 26, 2026

    @abrignoni
    Author

    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.

  5. abrignoni commented on Nov 26, 2026

    @abrignoni
    Author

    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.

    1. A body that is the text NULL is stored as NULL in the rebuilt mmssms.db and as null in sms.json.
    2. 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.
    3. 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.

  6. prosch88 commented on Nov 26, 2026

    @prosch88
    Owner

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions