Last active
April 3, 2021 00:08
-
-
Save havenwood/ef5a5f2fdb7a12542b347497f3960746 to your computer and use it in GitHub Desktop.
Playing with grabbing some notes from Apple Notes (See https://www.swiftforensics.com/2018/02/reading-notes-database-on-macos.html)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'sequel' | |
require 'stringio' | |
require 'zlib' | |
module Notes | |
PATH = 'Library/Group Containers/group.com.apple.notes/NoteStore.sqlite' | |
DB = Sequel.sqlite File.join Dir.home, PATH | |
TRAILING_DIVIDOR = "\u001A\u0010\n" | |
module_function | |
def notes | |
blobs.map do |blob| | |
_leading_meta, rest = blob.unpack 'a14a*' | |
notes, _, _trailing_meta = rest.partition TRAILING_DIVIDOR | |
notes | |
end | |
end | |
def blobs | |
compressed_blobs.map do |blob| | |
Zlib::GzipReader.new StringIO.new blob | |
end.map(&:read) | |
end | |
def compressed_blobs | |
DB[:ZICNOTEDATA].map do |row| | |
row[:ZDATA].to_s.b | |
end.reject(&:empty?) | |
end | |
end | |
p Notes.notes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment