code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def get_zgeneration_for_fallback_image return "" if @note.notestore.version < AppleNoteStoreVersion::IOS_VERSION_17 @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZFALLBACKIMAGEGENERATION " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| return row["ZFALLBACKIMAGEGENERATION"] end end
# This method fetches the appropriate ZFALLBACKGENERATION string to compute media location for iOS 17 and later.
get_zgeneration_for_fallback_image
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedDrawing.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedDrawing.rb
MIT
def compute_all_filepaths # Set up account folder location, default to no where tmp_account_string = "[Unknown Account]/FallbackImages/" tmp_account_string = "#{@note.account.account_folder}FallbackImages/" if @note # Update to somewhere if we know where ["jpeg","png", "jpg"].each do |extension| add_possible_location("#{tmp_account_string}#{@uuid}.#{extension}.encrypted") if @is_password_protected add_possible_location("#{tmp_account_string}#{@uuid}.#{extension}") if !@is_password_protected add_possible_location("#{tmp_account_string}#{@uuid}/#{@zgeneration}/FallbackImage.#{extension}.encrypted") if @is_password_protected add_possible_location("#{tmp_account_string}#{@uuid}/#{@zgeneration}/FallbackImage.#{extension}") if !@is_password_protected end end
# This method computes the various filename permutations seen in iOS.
compute_all_filepaths
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedDrawing.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedDrawing.rb
MIT
def initialize(primary_key, uuid, uti, note, backup) # Set this folder's variables super(primary_key, uuid, uti, note) # Gallery has no direct filename or path, just pointers to other pictures @filename = nil @filepath = nil @backup = backup # Add all the children add_gallery_children end
# Creates a new AppleNotesEmbeddedGallery object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, AppleNote +note+ object representing the parent AppleNote, and AppleBackup +backup+ from the parent AppleNote. Immediately finds the children picture objects and adds them.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedGallery.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedGallery.rb
MIT
def add_gallery_children gzipped_data = nil # If this Gallery is password protected, fetch the mergeable data from the # ZICCLOUDSYNCINGOBJECT.ZENCRYPTEDVALUESJSON column and decrypt it. if @is_password_protected unapplied_encrypted_record_column = "ZUNAPPLIEDENCRYPTEDRECORD" unapplied_encrypted_record_column = unapplied_encrypted_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_18 @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZENCRYPTEDVALUESJSON, ZICCLOUDSYNCINGOBJECT.#{unapplied_encrypted_record_column} " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| encrypted_values = row["ZENCRYPTEDVALUESJSON"] if row[unapplied_encrypted_record_column] keyed_archive = KeyedArchive.new(:data => row[unapplied_encrypted_record_column]) unpacked_top = keyed_archive.unpacked_top() ns_keys = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.keys"] ns_values = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.objects"] encrypted_values = ns_values[ns_keys.index("EncryptedValues")] end decrypt_result = @backup.decrypter.decrypt_with_password(@crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_iv, @crypto_tag, encrypted_values, "AppleNotesEmbeddedGallery #{@uuid}") parsed_json = JSON.parse(decrypt_result[:plaintext]) gzipped_data = Base64.decode64(parsed_json["mergeableData"]) end # Otherwise, pull from the ZICCLOUDSYNCINGOBJECT.ZMERGEABLEDATA column else # Set the appropriate column to find the data in mergeable_column = "ZMERGEABLEDATA1" mergeable_column = "ZMERGEABLEDATA" if @note.version < AppleNoteStoreVersion::IOS_VERSION_13 @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.#{mergeable_column} " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| # Extract the blob gzipped_data = row[mergeable_column] end end # Inflate the GZip if it exists, deleted objects won't if gzipped_data zlib_inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 16) gunzipped_data = zlib_inflater.inflate(gzipped_data) tmp_order = Hash.new tmp_current_uuid = '' tmp_current_order = '' # Read the protobuff mergabledata_proto = MergableDataProto.decode(gunzipped_data) # Loop over the entries to pull out the UUIDs for each child, as well as their ordering information mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry.each do |mergeable_data_object_entry| # This section holds an obvious UUID that matches the ZIDENTIFIER column if mergeable_data_object_entry.custom_map tmp_current_uuid = mergeable_data_object_entry.custom_map.map_entry.first.value.string_value end # This section holds what appears to be ordering information if mergeable_data_object_entry.unknown_message tmp_current_order = mergeable_data_object_entry.unknown_message.unknown_entry.unknown_int2 end # If we ever have both the UUID and order, set them in the hash and clear them if tmp_current_order != '' and tmp_current_uuid != '' tmp_order[tmp_current_order] = tmp_current_uuid tmp_current_uuid = '' tmp_current_order = '' end end # Loop over the Hash to put the images into the right order tmp_order.keys.sort.each do |key| create_child_from_uuid(tmp_order[key]) end end nil end
# Uses database calls to fetch the actual child objects' ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER +uuid+. This requires opening the protobuf inside of ZICCLOUDSYNCINGOBJECT.ZMERGEABLEDATA1 or ZICCLOUDSYNCINGOBJECT.ZMERGEABLEDATA column (if older than iOS13) and returning the referenced ZIDENTIFIER in that object.
add_gallery_children
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedGallery.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedGallery.rb
MIT
def create_child_from_uuid(uuid) @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.Z_PK, ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, " + "ZICCLOUDSYNCINGOBJECT.ZTYPEUTI " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZIDENTIFIER=?", uuid) do |row| @logger.debug("Creating gallery child from #{row["Z_PK"]}: #{uuid}") tmp_child = AppleNotesEmbeddedPublicJpeg.new(row["Z_PK"], row["ZIDENTIFIER"], row["ZTYPEUTI"], @note, @backup, self) tmp_child.search_and_add_thumbnails # This will cause it to regenerate the thumbnail array knowing that this is the parent add_child(tmp_child) end end
# This method takes a String +uuid+ and looks up the necessary information in ZICCLOUDSYNCINGOBJECTs to make a new child object of the appropriate type.
create_child_from_uuid
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedGallery.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedGallery.rb
MIT
def generate_html(individual_files=false) builder = Nokogiri::HTML::Builder.new(encoding: "utf-8") do |doc| doc.div { @child_objects.each do |child_object| doc << child_object.generate_html(individual_files) end } end return builder.doc.root end
# This method generates the HTML necessary to display the image inline.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedGallery.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedGallery.rb
MIT
def initialize(primary_key, uuid, uti, note, alt_text, token_identifier) # Set this object's variables @primary_key = primary_key @uuid = uuid @type = uti @conforms_to = uti @note = note @alt_text = alt_text @token_identifier = token_identifier @backup = @note.backup @database = @note.database @logger = @backup.logger @logger.debug("Note #{@note.note_id}: Created a new Embedded Inline Attachment of type #{@type}") end
# Creates a new AppleNotesEmbeddedInlineAttachment. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI1, AppleNote +note+ object representing the parent AppleNote, a String +alt_text+ from ZICCLOUDSYNCINGOBJECT.ZALTTEXT, and a String +token_identifier+ from ZICCLOUDSYNCINGOBJECT.ZTOKENCONTENTIDENTIFIER representing what the text stands for.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineAttachment.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineAttachment.rb
MIT
def to_csv to_return =[[@primary_key, @note.note_id, "", # Placeholder for parent ID @uuid, @type, "", # Placeholder for filename "", # Placeholder for filepath on phone "", # Placeholder for filepath on computer "", # Placeholder for user title @alt_text, @token_identifier]] return to_return end
# This method returns an Array of the fields used in CSVs for this class Currently spits out the +primary_key+, AppleNote +note_id+, AppleNotesEmbeddedObject parent +primary_key+, +uuid+, +type+, +filepath+, +filename+, and +backup_location+ on the computer. Also computes these for any children and thumbnails.
to_csv
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineAttachment.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineAttachment.rb
MIT
def generate_html(individual_files=false) return self.to_s end
# This method generates the HTML to be embedded into an AppleNote's HTML.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineAttachment.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineAttachment.rb
MIT
def prepare_json to_return = Hash.new() to_return[:primary_key] = @primary_key to_return[:note_id] = @note.note_id to_return[:uuid] = @uuid to_return[:type] = @type to_return[:conforms_to] = @conforms_to to_return[:alt_text] = @alt_text to_return[:token_identifier] = @token_identifier to_return[:html] = generate_html to_return end
# This method prepares the data structure that JSON will use to generate JSON later.
prepare_json
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineAttachment.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineAttachment.rb
MIT
def initialize(primary_key, uuid, uti, note, alt_text, token_identifier) super(primary_key, uuid, uti, note, alt_text, token_identifier) end
# Creates a new AppleNotesEmbeddedInlineCalculateGraphExpression. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI1, AppleNote +note+ object representing the parent AppleNote, a String +alt_text+ from ZICCLOUDSYNCINGOBJECT.ZALTTEXT, and a String +token_identifier+ from ZICCLOUDSYNCINGOBJECT.ZTOKENCONTENTIDENTIFIER representing what the result stands for.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineCalculateGraphExpression.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineCalculateGraphExpression.rb
MIT
def to_s return "" if !@alt_text @alt_text end
# This method just returns the graph equation's variable, which is found in alt_text.
to_s
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineCalculateGraphExpression.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineCalculateGraphExpression.rb
MIT
def initialize(primary_key, uuid, uti, note, alt_text, token_identifier) super(primary_key, uuid, uti, note, alt_text, token_identifier) end
# Creates a new AppleNotesEmbeddedInlineCalculateResult. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI1, AppleNote +note+ object representing the parent AppleNote, a String +alt_text+ from ZICCLOUDSYNCINGOBJECT.ZALTTEXT, and a String +token_identifier+ from ZICCLOUDSYNCINGOBJECT.ZTOKENCONTENTIDENTIFIER representing what the result stands for.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineCalculateResult.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineCalculateResult.rb
MIT
def to_s return "" if !@alt_text @alt_text end
# This method just returns the calculation result's text, which is found in alt_text.
to_s
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineCalculateResult.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineCalculateResult.rb
MIT
def initialize(primary_key, uuid, uti, note, alt_text, token_identifier) super(primary_key, uuid, uti, note, alt_text, token_identifier) end
# Creates a new AppleNotesEmbeddedInlineHashtag. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI1, AppleNote +note+ object representing the parent AppleNote, a String +alt_text+ from ZICCLOUDSYNCINGOBJECT.ZALTTEXT, and a String +token_identifier+ from ZICCLOUDSYNCINGOBJECT.ZTOKENCONTENTIDENTIFIER representing what the text stands for.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineHashtag.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineHashtag.rb
MIT
def to_s return "" if !@alt_text @alt_text end
# This method just returns the hashtag's text, which is found in alt_text.
to_s
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineHashtag.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineHashtag.rb
MIT
def initialize(primary_key, uuid, uti, note, alt_text, token_identifier) super(primary_key, uuid, uti, note, alt_text, token_identifier) end
# Creates a new AppleNotesEmbeddedInlineLink. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI1, AppleNote +note+ object representing the parent AppleNote, a String +alt_text+ from ZICCLOUDSYNCINGOBJECT.ZALTTEXT, and a String +token_identifier+ from ZICCLOUDSYNCINGOBJECT.ZTOKENCONTENTIDENTIFIER representing what the text stands for.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineLink.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineLink.rb
MIT
def to_s return "#{@alt_text} [#{@token_identifier}]" end
# This method just returns a readable String for the object.
to_s
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineLink.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineLink.rb
MIT
def generate_html(individual_files=false) return self.to_s end
# This method generates the HTML to be embedded into an AppleNote's HTML.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineLink.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineLink.rb
MIT
def initialize(primary_key, uuid, uti, note, alt_text, token_identifier) super(primary_key, uuid, uti, note, alt_text, token_identifier) @target_account = nil @target_account = @note.notestore.cloud_kit_participants[@token_identifier] # Fall back to just displaying a local account, this generally appears as __default_owner__ @target_account = @note.notestore.get_account_by_user_record_name(@token_identifier) if !@target_account end
# Creates a new AppleNotesEmbeddedInlineMention. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI1, AppleNote +note+ object representing the parent AppleNote, a String +alt_text+ from ZICCLOUDSYNCINGOBJECT.ZALTTEXT, and a String +token_identifier+ from ZICCLOUDSYNCINGOBJECT.ZTOKENCONTENTIDENTIFIER representing what the text stands for.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineMention.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineMention.rb
MIT
def to_s return "#{@alt_text} [#{@target_account.email}]" if @target_account and @target_account.is_a?(AppleCloudKitShareParticipant) and @target_account.email return "#{@alt_text} [Local Account: #{@target_account.name}]" if @target_account and @target_account.is_a?(AppleNotesAccount) and @target_account.name return "#{@alt_text} [#{@token_identifier}]" end
# This method just returns a readable String for the object. By default it just lists the +alt_text+. Subclasses should override this.
to_s
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineMention.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineMention.rb
MIT
def generate_html(individual_files=false) return self.to_s end
# This method generates the HTML to be embedded into an AppleNote's HTML.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedInlineMention.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedInlineMention.rb
MIT
def initialize(primary_key, uuid, uti, note) # Set this object's variables @primary_key = primary_key @uuid = uuid @type = uti @conforms_to = uti # Set variables to defaults to be overridden later @version = AppleNoteStoreVersion.new(AppleNoteStoreVersion::IOS_VERSION_UNKNOWN) @is_password_protected = false @backup = nil @database = nil @logger = Logger.new(STDOUT) @user_title = "" @filepath = "" @filename = "" @backup_location = nil @possible_locations = Array.new # Variable to hold ZMERGEABLEDATA objects @gzipped_data = nil # Create an Array to hold Thumbnails @thumbnails = Array.new # Create an Array to hold child objects, such as for a gallery @child_objects = Array.new # Zero out cryptographic settings @crypto_iv = nil @crypto_tag = nil @crypto_key = nil @crypto_salt = nil @crypto_iterations = nil @crypto_password = nil # Override the variables if we were given a note self.note=(note) if note log_string = "Created a new Embedded Object of type #{@type}" log_string = "Note #{@note.note_id}: #{log_string}" if @note @logger.debug(log_string) end
# Creates a new AppleNotesEmbeddedObject. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUIT, and AppleNote +note+ object representing the parent AppleNote.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def add_cryptographic_settings @crypto_password = @note.crypto_password unapplied_encrypted_record_column = "ZUNAPPLIEDENCRYPTEDRECORD" unapplied_encrypted_record_column = unapplied_encrypted_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_18 @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZCRYPTOINITIALIZATIONVECTOR, ZICCLOUDSYNCINGOBJECT.ZCRYPTOTAG, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOVERIFIER, ZICCLOUDSYNCINGOBJECT.ZCRYPTOWRAPPEDKEY, " + "ZICCLOUDSYNCINGOBJECT.#{unapplied_encrypted_record_column} " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE Z_PK=?", @primary_key) do |row| @crypto_iv = row["ZCRYPTOINITIALIZATIONVECTOR"] @crypto_tag = row["ZCRYPTOTAG"] @crypto_salt = row["ZCRYPTOSALT"] @crypto_iterations = row["ZCRYPTOITERATIONCOUNT"] @crypto_key = row["ZCRYPTOVERIFIER"] if row["ZCRYPTOVERIFIER"] @crypto_key = row["ZCRYPTOWRAPPEDKEY"] if row["ZCRYPTOWRAPPEDKEY"] correct_settings = (@backup.decrypter.check_cryptographic_settings(@crypto_password, @crypto_salt, @crypto_iterations, @crypto_key) and @crypto_iv) # If there is a blob in ZUNAPPLIEDENCRYPTEDRECORD, we need to use it instead of the database values if row[unapplied_encrypted_record_column] and !correct_settings keyed_archive = KeyedArchive.new(:data => row[unapplied_encrypted_record_column]) unpacked_top = keyed_archive.unpacked_top() ns_keys = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.keys"] ns_values = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.objects"] @crypto_iv = ns_values[ns_keys.index("CryptoInitializationVector")] @crypto_tag = ns_values[ns_keys.index("CryptoTag")] @crypto_salt = ns_values[ns_keys.index("CryptoSalt")] @crypto_iterations = ns_values[ns_keys.index("CryptoIterationCount")] @crypto_key = ns_values[ns_keys.index("CryptoWrappedKey")] end end end
# This function adds cryptographic settings to the AppleNoteEmbeddedObject.
add_cryptographic_settings
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def fetch_mergeable_data_by_uuid(uuid = @uuid) gzipped_data = nil # Set the appropriate column to find the data in mergeable_column = "ZMERGEABLEDATA1" mergeable_column = "ZMERGEABLEDATA" if @version < AppleNoteStoreVersion::IOS_VERSION_13 # If this object is password protected, fetch the mergeable data from the # ZICCLOUDSYNCINGOBJECT.ZENCRYPTEDVALUESJSON column and decrypt it. if @is_password_protected unapplied_encrypted_record_column = "ZUNAPPLIEDENCRYPTEDRECORD" unapplied_encrypted_record_column = unapplied_encrypted_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_18 @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZENCRYPTEDVALUESJSON, ZICCLOUDSYNCINGOBJECT.#{unapplied_encrypted_record_column} " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", uuid) do |row| encrypted_values = row["ZENCRYPTEDVALUESJSON"] if row[unapplied_encrypted_record_column] keyed_archive = KeyedArchive.new(:data => row[unapplied_encrypted_record_column]) unpacked_top = keyed_archive.unpacked_top() ns_keys = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.keys"] ns_values = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.objects"] encrypted_values = ns_values[ns_keys.index("EncryptedValues")] end decrypt_result = @backup.decrypter.decrypt_with_password(@crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_iv, @crypto_tag, encrypted_values, "#{self.class} #{uuid}") parsed_json = JSON.parse(decrypt_result[:plaintext]) gzipped_data = Base64.decode64(parsed_json["mergeableData"]) end # Otherwise, pull from the ZICCLOUDSYNCINGOBJECT.ZMERGEABLEDATA column else @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.#{mergeable_column} " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", uuid) do |row| # Extract the blob gzipped_data = row[mergeable_column] end end if !gzipped_data @logger.error("{self.class} #{@uuid}: Failed to find gzipped data to rebuild the object, check the #{mergeable_column} column for this UUID: \"SELECT hex(#{mergeable_column}) FROM ZICCLOUDSYNCINGOBJECT WHERE ZIDENTIFIER='#{@uuid}';\"") end return gzipped_data end
# This method fetches the gzipped ZMERGEABLE data from the database. It expects a String +uuid+ which defaults to the object's UUID. It returns the gzipped data as a String.
fetch_mergeable_data_by_uuid
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def add_child(child_object) child_object.parent = self # Make sure the parent is set @child_objects.push(child_object) end
# This method adds a +child_object+ to this object.
add_child
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def find_valid_file_path return nil if !@backup @backup.find_valid_file_path(@possible_locations) end
# This method uses the object's [email protected]_valid_file_path+ method to determine the right location on disk to find the file.
find_valid_file_path
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def search_and_add_thumbnails @thumbnails = Array.new @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.Z_PK, ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, " + "ZICCLOUDSYNCINGOBJECT.ZHEIGHT, ZICCLOUDSYNCINGOBJECT.ZWIDTH " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZATTACHMENT=?", @primary_key) do |row| tmp_thumbnail = AppleNotesEmbeddedThumbnail.new(row["Z_PK"], row["ZIDENTIFIER"], "thumbnail", @note, @backup, row["ZHEIGHT"], row["ZWIDTH"], self) @thumbnails.push(tmp_thumbnail) end # Sort the thumbnails so the largest overall size is at the end @thumbnails.sort_by!{|thumbnail| thumbnail.height * thumbnail.width} end
# This method queries ZICCLOUDSYNCINGOBJECT to find any thumbnails for this object. Each one it finds, it adds to the thumbnails Array.
search_and_add_thumbnails
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def to_s "Embedded Object #{@type}: #{@uuid}" end
# This method just returns a readable String for the object. By default it just lists the +type+ and +uuid+. Subclasses should override this.
to_s
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def to_s_with_data(data_type="media") return "Embedded Object #{@type}: #{@uuid} with #{data_type} in #{@backup_location}" if @backup_location "Embedded Object #{@type}: #{@uuid} with #{data_type} in #{@filepath}" end
# This method provides the +to_s+ method used by most objects with actual data.
to_s_with_data
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_media_uuid_from_zidentifier(zidentifier=@uuid) zmedia = get_zmedia_from_zidentifier(zidentifier) return get_zidentifier_from_z_pk(zmedia) end
# Handily pulls the UUID of media from ZIDENTIFIER of the ZMEDIA row
get_media_uuid_from_zidentifier
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_zidentifier_from_z_pk(z_pk) @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?", z_pk) do |row| return row["ZIDENTIFIER"] end end
# This method fetches the ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER column for a row identified by Integer z_pk.
get_zidentifier_from_z_pk
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_media_filepath_with_uuid_and_filename zgeneration = get_zgeneration_for_object zgeneration = "#{zgeneration}/" if (zgeneration and zgeneration.length > 0) return "#{@note.account.account_folder}Media/#{get_media_uuid}/#{zgeneration}#{get_media_uuid}" if @is_password_protected return "#{@note.account.account_folder}Media/#{get_media_uuid}/#{zgeneration}#{@filename}" end
# This handles a striaght forward mapping of UUID and filename
get_media_filepath_with_uuid_and_filename
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_media_filename_from_zfilename(zidentifier=@uuid) z_pk = get_zmedia_from_zidentifier(zidentifier) return get_media_filename_for_row(z_pk) end
# This handles how the media filename is pulled for most "data" objects
get_media_filename_from_zfilename
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_media_filename_for_row(z_pk) @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZFILENAME " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?", z_pk) do |media_row| return media_row["ZFILENAME"] end end
# This method returns the ZFILENAME column for a given row identified by Integer z_pk.
get_media_filename_for_row
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_media_zusertitle_for_row(z_pk=@primary_key) @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZUSERTITLE " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?", z_pk) do |media_row| return media_row["ZUSERTITLE"] end end
# This method returns the ZUSERTITLE column for a given row identified by Integer z_pk. This represents the name a user gave an object, such as an image.
get_media_zusertitle_for_row
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_zmedia_from_zidentifier(zidentifier=@uuid) @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZMEDIA " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", zidentifier) do |row| return row["ZMEDIA"] end end
# This method returns the ZICCLOUDSYNCINGOBJECT.ZMEDIA column for a given row identified by String ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER. This represents the ZICCLOUDSYNCINGOBJECT.Z_PK of another row.
get_zmedia_from_zidentifier
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_zgeneration_for_row(z_pk) # Bail early if we are below iOS 17 so we don't chuck an error on the query return "" if @note.notestore.version < AppleNoteStoreVersion::IOS_VERSION_17 @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZGENERATION, ZICCLOUDSYNCINGOBJECT.ZGENERATION1, " + "ZICCLOUDSYNCINGOBJECT.ZFALLBACKIMAGEGENERATION, ZICCLOUDSYNCINGOBJECT.ZFALLBACKPDFGENERATION, " + "ZICCLOUDSYNCINGOBJECT.ZPAPERBUNDLEGENERATION " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?", z_pk) do |media_row| return media_row["ZGENERATION"] if media_row["ZGENERATION"] return media_row["ZGENERATION1"] if media_row["ZGENERATION1"] return media_row["ZFALLBACKIMAGEGENERATION"] if media_row["ZFALLBACKIMAGEGENERATION"] return media_row["ZFALLBACKPDFGENERATION"] if media_row["ZFALLBACKPDFGENERATION"] return media_row["ZPAPERBUNDLEGENERATION"] if media_row["ZPAPERBUNDLEGENERATION"] return "" end end
# This method returns an array of all the "ZGENERATION" columns for a given row identified by Integer z_pk.
get_zgeneration_for_row
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_parent_primary_key return nil if !@parent return @parent.primary_key end
# This method returns either nil, if there is no parent object, or the parent object's primary_key.
get_parent_primary_key
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def to_csv to_return =[[@primary_key, @note.note_id, get_parent_primary_key, @uuid, @type, @filename, @filepath, @backup_location, @user_title, "", # Used by InlineAttachments "" # Used by InlineAttachments ]] # Add in any child objects @child_objects.each do |child_object| to_return += child_object.to_csv end # Add in any thumbnails @thumbnails.each do |thumbnail| to_return += thumbnail.to_csv end return to_return end
# This method returns an Array of the fields used in CSVs for this class Currently spits out the +primary_key+, AppleNote +note_id+, AppleNotesEmbeddedObject parent +primary_key+, +uuid+, +type+, +filepath+, +filename+, and +backup_location+ on the computer. Also computes these for any children and thumbnails.
to_csv
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def get_thumbnail_size return nil if (!@thumbnails or @thumbnails.length == 0) return {width: @thumbnails.first.width, height: @thumbnails.first.height} end
# This method finds the first thumbnail size, regardless of if the thumbnail's reference location is real. Returns the answer as a Hash with keys {width: xxx, height: yyy}.
get_thumbnail_size
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def generate_html(individual_files=false) return self.to_s end
# This method generates the HTML to be embedded into an AppleNote's HTML.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def generate_html_with_images(individual_files=false) # If we have thumbnails, return the first one with a reference location @thumbnails.each do |thumbnail| return thumbnail.generate_html(individual_files) if thumbnail.reference_location end # If we don't have a thumbnail with a reference location, use ours if @reference_location root = @note.folder.to_relative_root(individual_files) href_target = "#{root}#{@reference_location}" builder = Nokogiri::HTML::Builder.new(encoding: "utf-8") do |doc| thumbnail_size = get_thumbnail_size doc.a(href: href_target) { if thumbnail_size and thumbnail_size[:width] > 0 doc.img(src: href_target).attr("data-apple-notes-zidentifier" => "#{@uuid}").attr("width" => thumbnail_size[:width]) else doc.img(src: href_target).attr("data-apple-notes-zidentifier" => "#{@uuid}") end } end return builder.doc.root end # If we get to here, neither our thumbnails, nor we had a reference location return "{#{type} missing due to not having a file reference location}" end
# This method generates the HTML to be embedded into an AppleNote's HTML for objects that use thumbnails.
generate_html_with_images
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def generate_html_with_link(type="Media", individual_files=false) if @reference_location root = @note.folder.to_relative_root(individual_files) builder = Nokogiri::HTML::Builder.new(encoding: "utf-8") do |doc| doc.a(href: "#{root}#{@reference_location}") { doc.text "#{type} #{@filename}" }.attr("data-apple-notes-zidentifier" => "#{@uuid}") end return builder.doc.root end return "{#{type} missing due to not having a file reference location}" end
# This method generates the HTML to be embedded into an AppleNote's HTML for objects that are just downloadable.
generate_html_with_link
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def prepare_json to_return = Hash.new() to_return[:primary_key] = @primary_key to_return[:parent_primary_key] = @parent_primary_key to_return[:note_id] = @note.note_id to_return[:uuid] = @uuid to_return[:type] = @type to_return[:conforms_to] = @conforms_to to_return[:filename] = @filename if (@filename != "") to_return[:filepath] = @filepath if (@filepath != "") to_return[:backup_location] = @backup_location if @backup_location to_return[:user_title] = @user_title to_return[:is_password_protected] = @is_password_protected to_return[:html] = generate_html # Add in thumbnails in case folks want smaller pictures if @thumbnails.length > 0 to_return[:thumbnails] = Array.new() @thumbnails.each do |thumbnail| to_return[:thumbnails].push(thumbnail.prepare_json) end end if @child_objects.length > 0 to_return[:child_objects] = Array.new() @child_objects.each do |child| to_return[:child_objects].push(child.prepare_json) end end to_return end
# This method prepares the data structure that JSON will use to generate JSON later.
prepare_json
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb
MIT
def initialize(primary_key, uuid, uti, note, backup) # Set this objects's variables super(primary_key, uuid, uti, note) @filename = "" @filepath = "" @backup = backup @zgeneration = get_zgeneration_for_fallback_pdf compute_all_filepaths tmp_stored_file_result = find_valid_file_path if tmp_stored_file_result @filepath = tmp_stored_file_result.filepath @filename = tmp_stored_file_result.filename @backup_location = tmp_stored_file_result.backup_location @reference_location = @backup.back_up_file(@filepath, @filename, @backup_location, @is_password_protected, @crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_iv, @crypto_tag) end end
# Creates a new AppleNotesEmbeddedPaperDocScan object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, AppleNote +note+ object representing the parent AppleNote, and AppleBackup +backup+ from the parent AppleNote. Immediately sets the +filename+ and +filepath+ to point to were the media is stored. Finally, it attempts to copy the file to the output folder.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPaperDocScan.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPaperDocScan.rb
MIT
def add_cryptographic_settings @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZCRYPTOINITIALIZATIONVECTOR, ZICCLOUDSYNCINGOBJECT.ZCRYPTOTAG, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOVERIFIER, ZICCLOUDSYNCINGOBJECT.ZCRYPTOWRAPPEDKEY, " + "ZICCLOUDSYNCINGOBJECT.ZFALLBACKIMAGECRYPTOTAG, ZICCLOUDSYNCINGOBJECT.ZFALLBACKIMAGECRYPTOINITIALIZATIONVECTOR " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE Z_PK=?", @primary_key) do |media_row| @crypto_iv = media_row["ZCRYPTOINITIALIZATIONVECTOR"] @crypto_tag = media_row["ZCRYPTOTAG"] @crypto_fallback_iv = media_row["ZFALLBACKIMAGECRYPTOINITIALIZATIONVECTOR"] @crypto_fallback_tag = media_row["ZFALLBACKIMAGECRYPTOTAG"] @crypto_salt = media_row["ZCRYPTOSALT"] @crypto_iterations = media_row["ZCRYPTOITERATIONCOUNT"] @crypto_key = media_row["ZCRYPTOVERIFIER"] if media_row["ZCRYPTOVERIFIER"] @crypto_key = media_row["ZCRYPTOWRAPPEDKEY"] if media_row["ZCRYPTOWRAPPEDKEY"] end @crypto_password = @note.crypto_password end
# This function overrides the default AppleNotesEmbeddedObject add_cryptographic_settings to include the fallback image settings from ZFALLBACKIMAGECRYPTOTAG and ZFALLBACKIMAGECRYPTOINITIALIZATIONVECTOR for content on disk.
add_cryptographic_settings
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPaperDocScan.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPaperDocScan.rb
MIT
def get_media_uuid return get_media_uuid_from_zidentifer(@uuid) end
# Uses database calls to fetch the actual media object's ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER +uuid+. This requires taking the ZICCLOUDSYNCINGOBJECT.ZMEDIA field on the entry with this object's +uuid+ and reading the ZICCOUDSYNCINGOBJECT.ZIDENTIFIER of the row identified by that number in the ZICCLOUDSYNCINGOBJECT.Z_PK field.
get_media_uuid
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPaperDocScan.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPaperDocScan.rb
MIT
def get_zgeneration_for_fallback_pdf return "" if @note.notestore.version < AppleNoteStoreVersion::IOS_VERSION_17 @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZFALLBACKPDFGENERATION " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| return row["ZFALLBACKPDFGENERATION"] end end
# This method fetches the appropriate ZFALLBACKGENERATION string to compute media location for iOS 17 and later.
get_zgeneration_for_fallback_pdf
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPaperDocScan.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPaperDocScan.rb
MIT
def compute_all_filepaths # Set up account folder location, default to no where tmp_account_string = "[Unknown Account]/FallbackPDFs/" tmp_account_string = "#{@note.account.account_folder}FallbackPDFs/" if @note # Update to somewhere if we know where zgeneration = get_zgeneration_for_fallback_pdf add_possible_location("#{tmp_account_string}#{@uuid}.pdf.encrypted") if @is_password_protected add_possible_location("#{tmp_account_string}#{@uuid}.pdf") if !@is_password_protected add_possible_location("#{tmp_account_string}#{@uuid}/#{zgeneration}/FallbackPDF.pdf.encrypted") if (@is_password_protected and zgeneration and zgeneration.length > 0) add_possible_location("#{tmp_account_string}#{@uuid}/#{zgeneration}/FallbackPDF.pdf") if (!@is_password_protected and zgeneration and zgeneration.length > 0) end
# This method computes the various filename permutations seen in iOS.
compute_all_filepaths
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPaperDocScan.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPaperDocScan.rb
MIT
def initialize(primary_key, uuid, uti, note, backup) # Set this folder's variables super(primary_key, uuid, uti, note) @filename = get_media_filename @filepath = get_media_filepath @backup = backup # Find where on this computer that file is stored add_possible_location(@filepath) tmp_stored_file_result = find_valid_file_path # Copy the file to our output directory if we can if tmp_stored_file_result @backup_location = tmp_stored_file_result.backup_location @filepath = tmp_stored_file_result.filepath @filename = tmp_stored_file_result.filename # Copy the file to our output directory if we can @reference_location = @backup.back_up_file(@filepath, @filename, @backup_location) end end
# Creates a new AppleNotesEmbeddedPDF object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, AppleNote +note+ object representing the parent AppleNote, and AppleBackup +backup+ from the parent AppleNote. Immediately sets the +filename+ and +filepath+ to point to were the vcard is stored. Finally, it attempts to copy the file to the output folder.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPDF.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPDF.rb
MIT
def generate_html(individual_files=false) generate_html_with_link("PDF", individual_files) end
# This method generates the HTML necessary to display the file download link.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPDF.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPDF.rb
MIT
def initialize(primary_key, uuid, uti, note, backup, parent) # Set this object's variables @parent = parent # Do this first so thumbnails don't break super(primary_key, uuid, uti, note) @filename = get_media_filename @filepath = get_media_filepath add_possible_location(@filepath) # Find where on this computer that file is stored tmp_stored_file_result = find_valid_file_path if tmp_stored_file_result @backup_location = tmp_stored_file_result.backup_location @filepath = tmp_stored_file_result.filepath @filename = tmp_stored_file_result.filename # Copy the file to our output directory if we can @reference_location = @backup.back_up_file(@filepath, @filename, @backup_location, @is_password_protected, @crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_asset_iv, @crypto_asset_tag) end end
# Creates a new AppleNotesEmbeddedPublicAudio object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, AppleNote +note+ object representing the parent AppleNote, AppleBackup +backup+ from the parent AppleNote, and AppleEmbeddedObject +parent+ (or nil). Immediately sets the +filename+ and +filepath+ to point to were the media is stored. Finally, it attempts to copy the file to the output folder.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicAudio.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicAudio.rb
MIT
def get_media_uuid @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZMEDIA " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?", row["ZMEDIA"]) do |media_row| return media_row["ZIDENTIFIER"] end end end
# Uses database calls to fetch the actual media object's ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER +uuid+. This requires taking the ZICCLOUDSYNCINGOBJECT.ZMEDIA field on the entry with this object's +uuid+ and reading the ZICCOUDSYNCINGOBJECT.ZIDENTIFIER of the row identified by that number in the ZICCLOUDSYNCINGOBJECT.Z_PK field.
get_media_uuid
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicAudio.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicAudio.rb
MIT
def generate_html(individual_files=false) generate_html_with_link("Audio", individual_files) end
# This method generates the HTML necessary to display the image inline.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicAudio.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicAudio.rb
MIT
def initialize(primary_key, uuid, uti, note, backup, parent) # Set this object's variables @parent = parent # Do this first so thumbnails don't break super(primary_key, uuid, uti, note) @filename = get_media_filename @filepath = get_media_filepath # Default height and width variables @height = 0 @width = 0 add_possible_location(@filepath) # Find where on this computer that file is stored tmp_stored_file_result = find_valid_file_path if tmp_stored_file_result @backup_location = tmp_stored_file_result.backup_location @filepath = tmp_stored_file_result.filepath @filename = tmp_stored_file_result.filename # Copy the file to our output directory if we can @reference_location = @backup.back_up_file(@filepath, @filename, @backup_location, @is_password_protected, @crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_asset_iv, @crypto_asset_tag) end end
# Creates a new AppleNotesEmbeddedPublicJpeg object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, AppleNote +note+ object representing the parent AppleNote, AppleBackup +backup+ from the parent AppleNote, and AppleEmbeddedObject +parent+ (or nil). Immediately sets the +filename+ and +filepath+ to point to were the media is stored. Finally, it attempts to copy the file to the output folder.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicJpeg.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicJpeg.rb
MIT
def add_cryptographic_settings @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZMEDIA " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZCRYPTOINITIALIZATIONVECTOR, ZICCLOUDSYNCINGOBJECT.ZCRYPTOTAG, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOVERIFIER, ZICCLOUDSYNCINGOBJECT.ZCRYPTOWRAPPEDKEY, " + "ZICCLOUDSYNCINGOBJECT.ZASSETCRYPTOTAG, ZICCLOUDSYNCINGOBJECT.ZASSETCRYPTOINITIALIZATIONVECTOR " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE Z_PK=?", row["ZMEDIA"]) do |media_row| @crypto_iv = media_row["ZCRYPTOINITIALIZATIONVECTOR"] @crypto_tag = media_row["ZCRYPTOTAG"] @crypto_asset_iv = media_row["ZASSETCRYPTOINITIALIZATIONVECTOR"] @crypto_asset_tag = media_row["ZASSETCRYPTOTAG"] @crypto_salt = media_row["ZCRYPTOSALT"] @crypto_iterations = media_row["ZCRYPTOITERATIONCOUNT"] @crypto_key = media_row["ZCRYPTOVERIFIER"] if media_row["ZCRYPTOVERIFIER"] @crypto_key = media_row["ZCRYPTOWRAPPEDKEY"] if media_row["ZCRYPTOWRAPPEDKEY"] end end @crypto_password = @note.crypto_password end
# This function overrides the default AppleNotesEmbeddedObject add_cryptographic_settings to use the media's settings. It also adds the ZASSETCRYPTOTAG and ZASSETCRYPTOINITIALIZATIONVECTOR fields for the content on disk.
add_cryptographic_settings
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicJpeg.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicJpeg.rb
MIT
def get_media_filename unapplied_encrypted_record_column = "ZUNAPPLIEDENCRYPTEDRECORD" unapplied_encrypted_record_column = unapplied_encrypted_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_18 @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZMEDIA " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZFILENAME, " + "ZICCLOUDSYNCINGOBJECT.ZENCRYPTEDVALUESJSON, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOWRAPPEDKEY, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOINITIALIZATIONVECTOR, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOTAG, " + "ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " + "ZICCLOUDSYNCINGOBJECT.#{unapplied_encrypted_record_column} " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?", row["ZMEDIA"]) do |media_row| # Initialize the return value filename = nil if @is_password_protected # Need to snag the values from this row's columns as they are different than the original note encrypted_values = media_row["ZENCRYPTEDVALUESJSON"] crypto_tag = media_row["ZCRYPTOTAG"] crypto_salt = media_row["ZCRYPTOSALT"] crypto_iterations = media_row["ZCRYPTOITERATIONCOUNT"] crypto_key = media_row["ZCRYPTOWRAPPEDKEY"] crypto_iv = media_row["ZCRYPTOINITIALIZATIONVECTOR"] if media_row[unapplied_encrypted_record_column] keyed_archive = KeyedArchive.new(:data => media_row[unapplied_encrypted_record_column]) unpacked_top = keyed_archive.unpacked_top() ns_keys = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.keys"] ns_values = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.objects"] encrypted_values = ns_values[ns_keys.index("EncryptedValues")] crypto_iv = ns_values[ns_keys.index("CryptoInitializationVector")] crypto_tag = ns_values[ns_keys.index("CryptoTag")] crypto_salt = ns_values[ns_keys.index("CryptoSalt")] crypto_iterations = ns_values[ns_keys.index("CryptoIterationCount")] crypto_key = ns_values[ns_keys.index("CryptoWrappedKey")] end decrypt_result = @backup.decrypter.decrypt_with_password(@crypto_password, crypto_salt, crypto_iterations, crypto_key, crypto_iv, crypto_tag, encrypted_values, "#{self.class} #{@uuid}") parsed_json = JSON.parse(decrypt_result[:plaintext]) filename = parsed_json["filename"] else filename = media_row["ZFILENAME"] end @logger.debug("#{self.class} #{@uuid}: Filename is #{filename}") return filename end end end
# Uses database calls to fetch the actual media object's ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER +uuid+. This requires taking the ZICCLOUDSYNCINGOBJECT.ZMEDIA field on the entry with this object's +uuid+ and reading the ZICCOUDSYNCINGOBJECT.ZFILENAME of the row identified by that number in the ZICCLOUDSYNCINGOBJECT.Z_PK field.
get_media_filename
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicJpeg.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicJpeg.rb
MIT
def initialize(primary_key, uuid, uti, note, backup) # Set this folder's variables super(primary_key, uuid, uti, note) @filename = get_media_filename @filepath = get_media_filepath @backup = backup add_possible_location(@filepath) # Find where on this computer that file is stored tmp_stored_file_result = find_valid_file_path if tmp_stored_file_result @backup_location = tmp_stored_file_result.backup_location @filepath = tmp_stored_file_result.filepath @filename = tmp_stored_file_result.filename # Copy the file to our output directory if we can @reference_location = @backup.back_up_file(@filepath, @filename, @backup_location, @is_password_protected, @crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_asset_iv, @crypto_asset_tag) end end
# Creates a new AppleNotesEmbeddedPublicObject object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, AppleNote +note+ object representing the parent AppleNote, and AppleBackup +backup+ from the parent AppleNote. Immediately sets the +filename+ and +filepath+ to point to were the object is stored. Finally, it attempts to copy the file to the output folder.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicObject.rb
MIT
def generate_html(individual_files=false) generate_html_with_link("File", individual_files) end
# This method generates the HTML necessary to display the image inline.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicObject.rb
MIT
def initialize(primary_key, uuid, uti, note) # Set this folder's variables super(primary_key, uuid, uti, note) @url = get_referenced_url end
# Creates a new AppleNotesEmbeddedURL object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, and an AppleNote +note+ object representing the parent AppleNote. Immediately sets the URL variable to where this points at.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicURL.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicURL.rb
MIT
def to_s return super + " pointing to #{@url}" end
# This method just returns a readable String for the object. Adds to the AppleNotesEmbeddedObject.to_s by pointing to where the media is.
to_s
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicURL.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicURL.rb
MIT
def get_referenced_url referenced_url = nil # If this URL is password protected, fetch the URL from the # ZICCLOUDSYNCINGOBJECT.ZENCRYPTEDVALUESJSON column and decrypt it. if @is_password_protected unapplied_encrypted_record_column = "ZUNAPPLIEDENCRYPTEDRECORD" unapplied_encrypted_record_column = unapplied_encrypted_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_18 @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZENCRYPTEDVALUESJSON, ZICCLOUDSYNCINGOBJECT.#{unapplied_encrypted_record_column} " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| encrypted_values = row["ZENCRYPTEDVALUESJSON"] if row[unapplied_encrypted_record_column] keyed_archive = KeyedArchive.new(:data => row[unapplied_encrypted_record_column]) unpacked_top = keyed_archive.unpacked_top() ns_keys = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.keys"] ns_values = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.objects"] encrypted_values = ns_values[ns_keys.index("EncryptedValues")] end decrypt_result = @backup.decrypter.decrypt_with_password(@crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_iv, @crypto_tag, encrypted_values, "#{self.class} #{@uuid}") parsed_json = JSON.parse(decrypt_result[:plaintext]) referenced_url = parsed_json["urlString"] end else @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZURLSTRING " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| referenced_url = row["ZURLSTRING"] end end return referenced_url end
# Uses database calls to fetch the object's ZICCLOUDSYNCINGOBJECT.ZURLSTRING +url+. This requires taking the ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER field on the entry with this object's +uuid+ and reading the ZICCOUDSYNCINGOBJECT.ZURLSTRING of the row identified by that number.
get_referenced_url
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicURL.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicURL.rb
MIT
def generate_html(individual_files=false) builder = Nokogiri::HTML::Builder.new(encoding: "utf-8") do |doc| root = @note.folder.to_relative_root(individual_files) doc.span { if (@thumbnails.length > 0 and @thumbnails.first.reference_location) doc.img(src: "#{root}#{@thumbnails.first.reference_location}") end doc.a(href: @url) { doc.text @url } } end return builder.doc.root end
# This method generates the HTML necessary to display the image inline.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicURL.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicURL.rb
MIT
def prepare_json to_return = super() to_return[:url] = @url to_return end
# Generates the data structure used lated by JSON to create a JSON object.
prepare_json
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicURL.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicURL.rb
MIT
def initialize(primary_key, uuid, uti, note, backup) # Set this folder's variables super(primary_key, uuid, uti, note) @filename = get_media_filename @filepath = get_media_filepath @backup = backup add_possible_location(@filepath) # Find where on this computer that file is stored tmp_stored_file_result = find_valid_file_path if tmp_stored_file_result @backup_location = tmp_stored_file_result.backup_location @filepath = tmp_stored_file_result.filepath @filename = tmp_stored_file_result.filename # Copy the file to our output directory if we can @reference_location = @backup.back_up_file(@filepath, @filename, @backup_location, @is_password_protected, @crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_asset_iv, @crypto_asset_tag) end end
# Creates a new AppleNotesEmbeddedPublicVCard object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, AppleNote +note+ object representing the parent AppleNote, and AppleBackup +backup+ from the parent AppleNote. Immediately sets the +filename+ and +filepath+ to point to were the vcard is stored. Finally, it attempts to copy the file to the output folder.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicVCard.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicVCard.rb
MIT
def generate_html(individual_files=false) generate_html_with_link("VCard", individual_files) end
# This method generates the HTML necessary to display the image inline.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicVCard.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicVCard.rb
MIT
def initialize(primary_key, uuid, uti, note, backup, parent) # Set this object's variables @parent = parent # Do this first so thumbnails don't break super(primary_key, uuid, uti, note) @filename = get_media_filename @filepath = get_media_filepath add_possible_location(@filepath) # Find where on this computer that file is stored tmp_stored_file_result = find_valid_file_path if tmp_stored_file_result @backup_location = tmp_stored_file_result.backup_location @filepath = tmp_stored_file_result.filepath @filename = tmp_stored_file_result.filename # Copy the file to our output directory if we can @reference_location = @backup.back_up_file(@filepath, @filename, @backup_location, @is_password_protected, @crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_asset_iv, @crypto_asset_tag) end end
# Creates a new AppleNotesEmbeddedPublicVideo object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, AppleNote +note+ object representing the parent AppleNote, AppleBackup +backup+ from the parent AppleNote, and AppleEmbeddedObject +parent+ (or nil). Immediately sets the +filename+ and +filepath+ to point to were the media is stored. Finally, it attempts to copy the file to the output folder.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicVideo.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicVideo.rb
MIT
def get_media_uuid @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZMEDIA " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?", row["ZMEDIA"]) do |media_row| return media_row["ZIDENTIFIER"] end end end
# Uses database calls to fetch the actual media object's ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER +uuid+. This requires taking the ZICCLOUDSYNCINGOBJECT.ZMEDIA field on the entry with this object's +uuid+ and reading the ZICCOUDSYNCINGOBJECT.ZIDENTIFIER of the row identified by that number in the ZICCLOUDSYNCINGOBJECT.Z_PK field.
get_media_uuid
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedPublicVideo.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPublicVideo.rb
MIT
def initialize(primary_key, uuid, uti, note) # Set this objects's variables super(primary_key, uuid, uti, note) # This will hold our reconstructed table, plaintext and HTML @reconstructed_table = Array.new @reconstructed_table_html = Array.new # These variables hold different parts of the protobuf @row_items = Array.new @table_objects = Array.new @uuid_items = Array.new @type_items = Array.new @total_rows = 0 @total_columns = 0 # This will hold a mapping of UUID index number to row Array index in @reconstructed_table @row_indices = Hash.new # This will hold a mapping of UUID index number to column Array index in @reconstructed_table @column_indices = Hash.new # This will hold the table's direction, it defaults to left-to-right, will be changed during rebuild_table if needed @table_direction = LEFT_TO_RIGHT_DIRECTION #rebuild_table end
# Creates a new AppleNotesEmbeddedTable object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, and AppleNote +note+ object representing the parent AppleNote.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def to_s string_to_add = " with cells: " @reconstructed_table.each do |row| string_to_add += "\n" row.each do |column| string_to_add += "\t#{column}" end end super + string_to_add end
# This method just returns a readable String for the object. Adds to the default to include the text of the table, with each row on a new line.
to_s
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def initialize_table @total_rows.times do |row| @reconstructed_table.push(Array.new(@total_columns, "")) @reconstructed_table_html.push(Array.new(@total_columns, "")) end end
# This method initializes the reconstructed table. It loops over the +total_columns+ and +total_columns+ that were assessed for the table and builds a two dimensional array of empty strings.
initialize_table
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def parse_rows(object_entry) @total_rows = 0 object_entry.ordered_set.ordering.array.attachment.each do |attachment| @row_indices[@uuid_items.index(attachment.uuid)] = @total_rows @total_rows += 1 end # Figure out the translations for where each row points to in the @reconstructed_table object_entry.ordered_set.ordering.contents.element.each do |dictionary_element| key_object = get_target_uuid_from_object_entry(@table_objects[dictionary_element.key.object_index]) value_object = get_target_uuid_from_object_entry(@table_objects[dictionary_element.value.object_index]) @row_indices[value_object] = @row_indices[key_object] end end
# This method takes a MergeableDataObjectEntry +object_entry+ that it expects to include an OrderedSet with type +crRows+. It loops over each attachment to identify the UUIDs that represent table rows and puts them in the appropriate order. It then adds indices to +@row_indices+ to let later code look up where a given row falls in the +@reconstructed_table+.
parse_rows
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def parse_columns(object_entry) @total_columns = 0 object_entry.ordered_set.ordering.array.attachment.each do |attachment| @column_indices[@uuid_items.index(attachment.uuid)] = @total_columns @total_columns += 1 end # Figure out the translations for where each row points to in the @reconstructed_table object_entry.ordered_set.ordering.contents.element.each do |dictionary_element| key_object = get_target_uuid_from_object_entry(@table_objects[dictionary_element.key.object_index]) value_object = get_target_uuid_from_object_entry(@table_objects[dictionary_element.value.object_index]) @column_indices[value_object] = @column_indices[key_object] end end
# This method takes a MergeableDataObjectEntry +object_entry+ that it expects to include an OrderedSet with type +crColumns+. It loops over each attachment to identify the UUIDs that represent table columns and puts them in the appropriate order. It then adds indices to +@column_indices+ to let later code look up where a given column falls in the +@reconstructed_table+.
parse_columns
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def parse_cell_columns(object_entry) # Loop over each of the dictionary elements in the cellColumns object, these are all column pointers object_entry.dictionary.element.each do |column| current_column = get_target_uuid_from_object_entry(@table_objects[column.key.object_index]) target_dictionary_object = @table_objects[column.value.object_index] # Loop over each of the dictionary elements in the Dictionary that was referenced in the prior value, these are rows target_dictionary_object.dictionary.element.each do |row| current_row = get_target_uuid_from_object_entry(@table_objects[row.key.object_index]) target_cell = @table_objects[row.value.object_index] # Check for any embedded objects and generate them if they exist replaced_objects = AppleNotesEmbeddedObject.generate_embedded_objects(@note, target_cell) cell_string_html = AppleNote.htmlify_document(target_cell, replaced_objects[:objects]) cell_string = "" cell_string = replaced_objects[:to_string] if replaced_objects[:to_string] @reconstructed_table[@row_indices[current_row]][@column_indices[current_column]] = cell_string if (@row_indices[current_row] and @column_indices[current_column]) @reconstructed_table_html[@row_indices[current_row]][@column_indices[current_column]] = cell_string_html if (@row_indices[current_row] and @column_indices[current_column]) # Push any embedded objects into the AppleNote's recursive array, pushing onto the regular array would overwrite the table replaced_objects[:objects].each do |replaced_object| @note.embedded_objects_recursive.push(replaced_object) end end end end
# This method does the hard work of building the rows and columns with cells in them. It expects a MergeableDataObjectEntry +object_entry+ which should have a type of +cellColumns+. It loops over each of its Dictionary elements, which represent each column. Inside of each Dictionary element is a key that ends up pointing to a UUID index representing the column and a value that points to a separate object which is a Dictionary of row UUIDs to cell (Note) objects. This calls get_target_uuid_from_table_object on the first key to get th column's index and then does that for each of the rows it points to. With this information, it can look up where in the +@reconstructed_table+ the Note it is pointing to goes.
parse_cell_columns
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def parse_table(object_entry) if object_entry.custom_map and @type_items[object_entry.custom_map.type] == "com.apple.notes.ICTable" # Variable to make sure we don't try to parse cell columns prior to doing rows or columns need_to_parse_cell_columns = false object_entry.custom_map.map_entry.each do |map_entry| case @key_items[map_entry.key] when "crTableColumnDirection" #puts "Column Direction: #{object_entrys[map_entry.value.object_index]}" when "crRows" parse_rows(@table_objects[map_entry.value.object_index]) when "crColumns" parse_columns(@table_objects[map_entry.value.object_index]) when "cellColumns" # parse_cell_columns(@table_objects[map_entry.value.object_index]) need_to_parse_cell_columns = @table_objects[map_entry.value.object_index] end # Check if we have both rows, and columns, and the cell_columns not yet run if @total_rows > 0 and @total_columns > 0 and need_to_parse_cell_columns # If we know how many rows and columns we have, we can initialize the table initialize_table if (@total_columns > 0 and @total_rows > 0 and @reconstructed_table.length < 1) # Actually parse through the values parse_cell_columns(need_to_parse_cell_columns) need_to_parse_cell_columns = false end end # We need to reverse the table if it is right to left if @table_direction == RIGHT_TO_LEFT_DIRECTION @reconstructed_table.each do |row| row.reverse! end @reconstructed_table_html.each do |row| row.reverse! end end end end
# This method takes a MergeableDataObjectEntry +object_entry+ that it expects to be of type +com.apple.notes.ICTable+, representing the actual table. It looks over each of the MapEntry objects within to handle each as it needs to be, using the aforecreated fucntions. The +crTableColumnDirection+ object isn't quite understood yet and is handled elsewhere. As this gets enough information, it initializes the +reconstructed_table+ and flips the tabl's direction if the order changes.
parse_table
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def rebuild_table if !@gzipped_data @gzipped_data = fetch_mergeable_data_by_uuid(@uuid) end if @gzipped_data and @gzipped_data.length > 0 # Inflate the GZip zlib_inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 16) mergeable_data = zlib_inflater.inflate(@gzipped_data) # Read the protobuff mergabledata_proto = MergableDataProto.decode(mergeable_data) # Build list of key items @key_items = Array.new mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_key_item.each do |key_item| @key_items.push(key_item) end # Build list of type items @type_items = Array.new mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_type_item.each do |type_item| @type_items.push(type_item) end # Build list of uuid items @uuid_items = Array.new mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_uuid_item.each do |uuid_item| @uuid_items.push(uuid_item) end # Build Array of objects @table_objects = Array.new mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry.each do |mergeable_data_object_entry| @table_objects.push(mergeable_data_object_entry) # Best way I've found to set the table direction if mergeable_data_object_entry.custom_map if mergeable_data_object_entry.custom_map.map_entry.first.key == @key_items.index("crTableColumnDirection") + 1 #Oddly seems to correspond to 'self' @table_direction = mergeable_data_object_entry.custom_map.map_entry.first.value.string_value end end end # Find the first ICTable, which shuld be the root, and execute mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry.each do |mergeable_data_object_entry| if mergeable_data_object_entry.custom_map and @type_items[mergeable_data_object_entry.custom_map.type] == "com.apple.notes.ICTable" parse_table(mergeable_data_object_entry) end end else # May want to catch this scenario end end
# This method rebuilds the embedded table. It extracts the gzipped data, gunzips it, and builds a MergableDataProto from the result. It then loops over each of the key, type, and UUID items in the proto to build an index for reference. Then it loops over all the objects in the proto to do similar, as well as identifying the table's direction. Finally, it finds the root table and calls parse_table on it.
rebuild_table
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def generate_html(individual_files=false) # Return our to_string function if we aren't reconstructed yet return self.to_s if (!@reconstructed_table_html or @reconstructed_table_html.length == 0) # Create an HTML table builder = Nokogiri::HTML::Builder.new(encoding: "utf-8") do |doc| doc.table { # Loop over each row and create a new table row @reconstructed_table_html.each do |row| doc.tr { # Loop over each column and place the cell value into a td row.each do |column| doc.td { doc << column } end } end } end return builder.doc.root end
# This method generates the HTML necessary to display the table. For display purposes, if a cell would be completely empty, it is displayed as having one space in it.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def prepare_json to_return = super() to_return[:table] = Array.new() return to_return if (!@reconstructed_table or @reconstructed_table.length == 0) @reconstructed_table.each_with_index do |row, row_index| to_return[:table][row_index] = Array.new() row.each_with_index do |column, column_index| to_return[:table][row_index][column_index] = column end end to_return end
# This method prepares the data structure that JSON will use to generate a JSON object later.
prepare_json
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedTable.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb
MIT
def initialize(primary_key, uuid, uti, note, backup, height, width, parent) # Set this folder's variables super(primary_key, uuid, uti, note) @height = height @width = width @parent = parent @filename = "" @filepath = "" @backup = backup @zgeneration = get_zgeneration_for_thumbnail # Find where on this computer that file is stored back_up_file if @backup end
# Creates a new AppleNotesEmbeddedThumbnail object. Expects an Integer +primary_key+ from ZICCLOUDSYNCINGOBJECT.Z_PK, String +uuid+ from ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, AppleNote +note+ object representing the parent AppleNote, and AppleBackup +backup+ from the parent AppleNote. Immediately sets the +filename+ and +filepath+ to point to were the media is stored. Finally, it attempts to copy the file to the output folder.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def back_up_file return if !@backup compute_all_filepaths tmp_stored_file_result = find_valid_file_path if tmp_stored_file_result @logger.debug("Embedded Thumbnail #{@uuid}: \n\tExpected Filepath: '#{@filepath}' (length: #{@filepath.length}), \n\tExpected location: '#{@backup_location}'") @filepath = tmp_stored_file_result.filepath @filename = tmp_stored_file_result.filename @backup_location = tmp_stored_file_result.backup_location # Copy the file to our output directory if we can @reference_location = @backup.back_up_file(@filepath, @filename, @backup_location, @is_password_protected, @crypto_password, @crypto_salt, @crypto_iterations, @crypto_key, @crypto_iv, @crypto_tag) end end
# This method handles setting the relevant +@backup_location+ variable and then backing up the file, if it exists.
back_up_file
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_media_filepath return get_media_filepath_ios16_and_earlier if @version < AppleNoteStoreVersion::IOS_VERSION_17 return get_media_filepath_ios17 end
# This method returns the +filepath+ of this object. This is computed based on the assumed default storage location.
get_media_filepath
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_media_filepath_ios16_and_earlier return "[Unknown Account]/Previews/#{@filename}" if !@note return "#{@note.account.account_folder}Previews/#{@filename}" end
# This method returns the +filepath+ of this object. This is computed based on the assumed default storage location. Examples of valid iOS 16 paths: Accounts/{account_uuid}/Previews/{parent_uuid}-1-192x144-0.png Accounts/{account_uuid}/Previews/{parent_uuid}-1-768x768-0.png.encrypted Accounts/{account_uuid}/Previews/{parent_uuid}-1-216x384-0-oriented.png Accounts/{account_uuid}/Previews/{parent_uuid}-1-144x192-0.jpg Accounts/{account_uuid}/Previews/{parent_uuid}-1-288x384-0.jpg.encrypted
get_media_filepath_ios16_and_earlier
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_media_filepath_ios17 zgeneration_string = "" zgeneration_string = "#{@uuid}/#{@zgeneration}/" if (@zgeneration and @zgeneration.length > 0) return "[Unknown Account]/Previews/#{@filename}" if !@note return "#{@note.account.account_folder}Previews/#{zgeneration_string}#{@filename}" end
# This method returns the +filepath+ of this object. This is computed based on the assumed default storage location. Examples of valid iOS 17 paths: Accounts/{account_uuid}/Previews/{parent_uuid}-1-272x384-0.png Accounts/{account_uuid}/Previews/{parent_uuid}-1-768x768-0.png.encrypted Accounts/{account_uuid}/Previews/{parent_uuid}-1-192x144-0/{zgeneration}/Preview.png Accounts/{account_uuid}/Previews/{parent_uuid}-1-2384x3360-0/{zgeneration}/OrientedPreview.jpeg
get_media_filepath_ios17
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def compute_all_filepaths # Set up account folder location, default to no where tmp_account_string = "[Unknown Account]/Previews/" tmp_account_string = "#{@note.account.account_folder}Previews/" if @note # Update to somewhere if we know where ["jpg","png", "jpeg"].each do |extension| add_possible_location("#{tmp_account_string}#{@uuid}.#{extension}.encrypted") if @is_password_protected add_possible_location("#{tmp_account_string}#{@uuid}/#{@zgeneration}/OrientedPreview.#{extension}") if (!@is_password_protected and @zgeneration) add_possible_location("#{tmp_account_string}#{@uuid}/#{@zgeneration}/Preview.#{extension}") if (!@is_password_protected and @zgeneration) add_possible_location("#{tmp_account_string}#{@uuid}.#{extension}") if !@is_password_protected add_possible_location("#{tmp_account_string}#{@uuid}-oriented.#{extension}") if !@is_password_protected end end
# This method computes the various filename permutations seen in iOS.
compute_all_filepaths
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_media_filename return get_media_filename_ios16_and_earlier if @version < AppleNoteStoreVersion::IOS_VERSION_17 return get_media_filename_ios17 end
# As these are created by Notes, it is just the UUID. These are either .png (apparently created by com.apple.notes.gallery) or .jpeg/.jpg (rest) Encrypted thumbnails just have .encrypted added to the end.
get_media_filename
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_media_filename_ios16_and_earlier return "#{@uuid}.#{get_thumbnail_extension_ios16_and_earlier}.encrypted" if @is_password_protected return "#{@uuid}.#{get_thumbnail_extension_ios16_and_earlier}" end
# Prior to iOS 17, it is just the UUID. These are either .png (apparently created by com.apple.notes.gallery) or .jpg (rest) Encrypted thumbnails just have .encrypted added to the end.
get_media_filename_ios16_and_earlier
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_media_filename_ios17 #zgeneration = get_zgeneration_for_thumbnail #return "#{@uuid}.png.encrypted" if @is_password_protected return "#{@uuid}.#{get_thumbnail_extension_ios17}.encrypted" if @is_password_protected return "Preview.#{get_thumbnail_extension_ios17}" if @zgeneration return "#{@uuid}.#{get_thumbnail_extension_ios17}" end
# As of iOS 17, these appear to be called Preview.png if there is a zgeneration. Examples of valid paths: Accounts/{account_uuid}/Previews/{parent_uuid}-1-768x768-0.png.encrypted Accounts/{account_uuid}/Previews/{parent_uuid}-1-2384x3360-0/{zgeneration}/OrientedPreview.jpeg Accounts/{account_uuid}/Previews/{parent_uuid}-1-192x144-0/{zgeneration}/Preview.png Accounts/{account_uuid}/Previews/{parent_uuid}-1-272x384-0.png
get_media_filename_ios17
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_zgeneration_for_thumbnail return nil if @version < AppleNoteStoreVersion::IOS_VERSION_17 or !@database @database.execute("SELECT ZICCLOUDSYNCINGOBJECT.ZGENERATION " + "FROM ZICCLOUDSYNCINGOBJECT " + "WHERE ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER=?", @uuid) do |row| return row["ZGENERATION"] end end
# This method fetches the appropriate ZFALLBACKGENERATION string to compute media location for iOS 17 and later.
get_zgeneration_for_thumbnail
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_thumbnail_extension return get_thumbnail_extension_ios16_and_earlier if @version < AppleNoteStoreVersion::IOS_VERSION_17 return get_thumbnail_extension_ios17 end
# This method returns the thumbnail's extension. These are either .jpg (apparently created by com.apple.notes.gallery) or .png (rest).
get_thumbnail_extension
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_thumbnail_extension_ios17 return "jpeg" if (@parent and @parent.type == "com.apple.notes.gallery") return "jpeg" if (@parent and @parent.parent and @parent.parent.type == "com.apple.notes.gallery") return "png" end
# This method returns the thumbnail's extension. This is apparently png for iOS 17 and later and jpeg for Galleries.
get_thumbnail_extension_ios17
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def get_thumbnail_extension_ios16_and_earlier return "jpg" if (@parent and @parent.type == "com.apple.notes.gallery") return "jpg" if (@parent and @parent.parent and @parent.parent.type == "com.apple.notes.gallery") return "png" end
# This method returns the thumbnail's extension. These are either .jpg (apparently created by com.apple.notes.gallery) or .png (rest) for iOS 16 and earlier.
get_thumbnail_extension_ios16_and_earlier
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def generate_html(individual_files) if (@parent and @reference_location) # We default to the thumbnail's location to link to... href_target = @reference_location # ...but if possible, we use the parent's location to get the real file href_target = @parent.reference_location if @parent.reference_location root = @note.folder.to_relative_root(individual_files) builder = Nokogiri::HTML::Builder.new(encoding: "utf-8") do |doc| doc.a(href: "#{root}#{href_target}") { doc.img(src: "#{root}#{@reference_location}") }.attr("data-apple-notes-zidentifier" => "#{@parent.uuid}") end return builder.doc.root end return "{Thumbnail missing due to not having file reference point}" end
# This method generates the HTML necessary to display the image inline.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def prepare_json to_return = Hash.new() to_return[:primary_key] = @primary_key to_return[:parent_primary_key] = @parent_primary_key to_return[:note_id] = @note.note_id to_return[:uuid] = @uuid to_return[:type] = @type to_return[:filename] = @filename if (@filename != "") to_return[:filepath] = @filepath if (@filepath != "") to_return[:backup_location] = @backup_location if @backup_location to_return[:is_password_protected] = @is_password_protected to_return end
# This method prepares the data structure that will be used by JSON to generate a JSON object later.
prepare_json
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedThumbnail.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedThumbnail.rb
MIT
def initialize(folder_primary_key, folder_name, folder_account) super() # Initialize notes for this account @notes = Array.new() # Set this folder's variables @primary_key = folder_primary_key @name = folder_name @account = folder_account @account.add_folder(self) @retain_order = false # By default we have no children @child_folders = Array.new() # By default we have no parent folder @parent = nil # Expects an AppleFolder object @parent_id = nil # Expects a z_pk value for a folder @parent_uuid = nil # Expects the zidentifier value for a folder # Pre-bake the sort order to a nice low value @sort_order = (0 - Float::INFINITY) @uuid = "" # Uncomment the below line if you want to see the folder names during creation #puts "Folder #{@primary_key} is called #{@name}" end
# Creates a new AppleNotesFolder. Requires the folder's +primary_key+ as an Integer, +name+ as a String, and +account+ as an AppleNotesAccount.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesFolder.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb
MIT
def has_notes return (@notes.length > 0) end
# This method identifies if an AppleNotesFolder has notes in it.
has_notes
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesFolder.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb
MIT
def add_child(folder) folder.parent_id = @primary_key folder.parent = self @child_folders.push(folder) end
# This method requires an AppleNotesFolder object as +folder+ and adds it to the folder's @child_folders Array. It also sets the child's parent variables to make sure the relationship goes both ways.
add_child
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesFolder.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb
MIT
def is_child? return (@parent != nil) end
# This is a helper function to tell if a folder is a child folder or not
is_child?
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesFolder.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb
MIT
def is_parent? return (@child_folders.length > 0) end
# This is a helper function to tell if a folder is a parent of any folders
is_parent?
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesFolder.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb
MIT
def is_orphan? return (@parent == nil and (@parent_id != nil or @parent_uuid != nil)) end
# This is a helper function to identify child folders that need their parent set
is_orphan?
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesFolder.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb
MIT