Giter VIP home page Giter VIP logo

unifiedlogreader's Introduction

UnifiedLogReader

A parser for Unified logging .tracev3 files.

Project Status

alpha (experimental)

This is a work in progress.. Currently this does not support the first version of tracev3 which is seen on macOS 10.12.0 (which uses catalog v2). It has been tested to work on catalog v3 files used in macOS 10.12.5 upto the current 10.15. Also tested on iOS 12.x successfully.

License

MIT

Requirements & Installation

Python 3.6+ and the following modules

  • lz4
  • biplist
  • ipaddress

UnifiedLogReader (and the dependencies) can be installed using pip install unifiedlog lz4 biplist ipaddress

Do not download from here, unless you want the latest code. For development, if you only need the dependencies, use pip install -r requirements.txt

Usage

The script needs access to files from 3 folders (same on iOS or macOS)

  • /private/var/db/diagnostics
  • /private/var/db/diagnostics/timesync
  • /private/var/db/uuidtext

The tracev3 files are located within the diagnostics folder. If you have a disk image, just extract the diagnostics and uuidtext folders (shown at paths above) and provide it to this script.

Currently the script supports the default log output format, TSV and sqlite output.

Output options

SQLITE gives you every available field in an sqlite db
TSV_ALL gives you every available field in a tab-seperated file
LOG_DEFAULT gives only those fields shown by 'log' utility (with no options specified)

G:\>c:\Python37-32\python.exe c:\Github\UnifiedLogReader\UnifiedLogReader.py -h
usage: UnifiedLogReader.py [-h] [-f OUTPUT_FORMAT] [-l LOG_LEVEL]
                           uuidtext_path timesync_path tracev3_path
                           output_path

UnifiedLogReader is a tool to read macOS Unified Logging tracev3 files.
This is version 0.3 tested on macOS 10.12.5 - 10.15 and iOS 12.

Notes:
-----
If you have a .logarchive, then point uuidtext_path to the .logarchive folder,
 the timesync folder is within the logarchive folder

positional arguments:
  uuidtext_path         Path to uuidtext folder (/var/db/uuidtext)
  timesync_path         Path to timesync folder (/var/db/diagnostics/timesync)
  tracev3_path          Path to either tracev3 file or folder to recurse (/var/db/diagnostics)
  output_path           An existing folder where output will be saved

optional arguments:
  -h, --help            show this help message and exit
  -f OUTPUT_FORMAT, --output_format OUTPUT_FORMAT
                        SQLITE, TSV_ALL, LOG_DEFAULT  (Default is LOG_DEFAULT)
  -l LOG_LEVEL, --log_level LOG_LEVEL
                        Log levels: INFO, DEBUG, WARNING, ERROR (Default is INFO)

unifiedlogreader's People

Contributors

a5hlynx avatar joachimmetz avatar ydkhatri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unifiedlogreader's Issues

DecompressTraceV3Log not used?

@ydkhatri going over the code to add more test coverage it looks like:

scripts/UnifiedLogReader.py defines DecompressTraceV3Log but this function is not used
this means that the DecompressTraceV3 function in UnifiedLog/Lib.py is also not used.

Could you confirm if my assessment is correct? And if there is additional context I'm not aware of, why these functions should remain in the code base. Otherwise I'll prep a PR to remove them.

Timesync without items causes tracev3 file to fail to parse

From https://github.com/ydkhatri/UnifiedLogReader/blob/master/UnifiedLog/Lib.py#L300

           elif item_id == 0x6102: # uuid
                self.system_boot_uuid = UUID(bytes=buffer[pos:pos+16])
                self.boot_uuid_ts_list = GetBootUuidTimeSyncList(self.ts_list, self.system_boot_uuid)
                if not self.boot_uuid_ts_list:
                    raise ValueError('Could not get Timesync for boot uuid! Cannot parse file..')

If self.boot_uuid_ts_list is an empty list the tracev3 file fails to parse.

I've change this to if self.boot_uuid_ts_list is None:, since GetBootUuidTimeSyncList returns None if it cannot find a Timesync corresponding with the boot identifier.

Let me know if this matched the intended behavior

NameError: global name 'logger' is not defined & NameError: global name 'virtual_file_system' is not defined

Hi,

Iam trying to use this script for some IOS Unified Logs (dont know if it would work?)
But when using i get two erros:

Traceback (most recent call last):
File "UnifiedLogReader.py", line 500, in
if not Main():
File "UnifiedLogReader.py", line 456, in Main
logger.addHandler(log_console_handler)
NameError: global name 'logger' is not defined

File "UnifiedLogReader.py", line 498, in
if not Main():
File "UnifiedLogReader.py", line 462, in Main
unified_log_reader = UnifiedLogReader()
File "UnifiedLogReader.py", line 286, in init
self._vfs = virtual_file_system.VirtualFileSystem(
NameError: global name 'virtual_file_system' is not defined

Do you have an idea how to fix it?

Some errors on a `log collect`-ed archive in macOS 10.14.6

Hello,

First, thank you for the great work ! It's amazing, it should help us a lot to parse logs in Windows.

After some try, most of the logs are extracted, but we still have some errors. I didn't open a ticket for each one, but I can if needed. Are they known ? Each one are repeated a bunch of times at different frequency, with different address / offset / values.

ERROR - missing data for log @ 0x4F0E8
Traceback (most recent call last):
  File "UnifiedLogReader-master/UnifiedLog/tracev3_file.py", line 674, in RecreateMsgFromFmtStringAndData
    msg += self._ReadNtSid(raw_data)
  File "UnifiedLogReader-master/UnifiedLog/data_format.py", line 76, in _ReadNtSid
    sub_authorities = struct.unpack('<{}I'.format(num_sub_auth), data[8:8*num_sub_auth])
error: unpack requires a string argument of length 4
UnifiedLogReader-master/UnifiedLog/tracev3_file.py:662: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if unk == 'D': # 0x44
UnifiedLogReader-master/UnifiedLog/tracev3_file.py:667: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif unk == '#': #0x23
ERROR - Unknown value for mbr_details found 0xa3 in log @ 0x16C18E8
ERROR - Data Reference not found for unique_ref=0x1000003535BF4D626 ct=3656559941158!
ERROR - Failed to open file system_logs.logarchive/94/D581CA04CA3AA78087D09B74E2AB67
Traceback (most recent call last):
  File "UnifiedLogReader-master/UnifiedLog/virtual_file.py", line 31, in open
IOError: [Errno 24] Too many open files: 'system_logs.logarchive/94/D581CA04CA3AA78087D09B74E2AB67'
ERROR - Did not read data of type 3, t1=location, t2=_CLDaemonStatusStateTrackerState, length=0x28 from log @ 0x5D18 ct=25128227678
ERROR - Did not read data of type 3, t1=location, t2=_CLLocationManagerStateTrackerState, length=0x48 from log @ 0x61560 ct=46065225628
ERROR - Did not read data of type 2, t1=AppStoreDaemon, t2=LogPushConnection, length=0x2E from log @ 0x7C1048 ct=15495190668348
ERROR - Invalid bounds 0x8F1500 for bc166f11-dd33-32af-af67-de0b2c985aa8
INFO - Unknown custom data object type '{public, location:_CLLocationManagerStateTrackerState}' data size=0x48 in log @ 0x1CE798

GetUuidEntryFromUuid raises UnboundLocalError when self.uuid_entries is empty

def GetUuidEntryFromUuid(self, uuid):

when self.uuid_entries is empty and GetUuidEntryFromUuid is called it raises UnboundLocalError: local variable 'b' referenced before assignment

What is the expected behavior? To raise KeyError or return None, or equiv?

To do:

VirtualFile.get_file_size() returns ValueError if file does not exists?

VirtualFile.get_file_size() returns ValueError if file does not exists?

======================================================================
ERROR: testGetFileSize (virtual_file.VirtualFileTest)
Tests the get_file_size function.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "UnifiedLogReader/tests/virtual_file.py", line 24, in testGetFileSize
    file_size = file_entry.get_file_size()
  File "UnifiedLogReader/UnifiedLog/virtual_file.py", line 45, in get_file_size
    raise ValueError('File pointer was invalid. File must be opened before calling get_file_size()')
ValueError: File pointer was invalid. File must be opened before calling get_file_size()

@ydkhatri is this the intended behavior? IMHO an IOError('No such file') or equiv would be more clear.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.