Skip to content

Instantly share code, notes, and snippets.

@havenwood

havenwood/notes.rb

Last active Apr 3, 2021
Embed
What would you like to do?
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