Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active April 3, 2021 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/ef5a5f2fdb7a12542b347497f3960746 to your computer and use it in GitHub Desktop.
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)
# 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