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 initialize(root_folder, output_folder, decrypter=AppleDecrypter.new) super(root_folder, AppleBackup::MAC_BACKUP_TYPE, output_folder, decrypter) # Check to make sure we're all good if self.valid? puts "Created a new AppleBackup from Mac backup: #{@root_folder}" # Copy the modern NoteStore to our output directory copy_notes_database(@root_folder + "NoteStore.sqlite", @note_store_modern_location) modern_note_version = AppleNoteStore.guess_ios_version(@note_store_modern_location) modern_note_version.platform=(AppleNoteStoreVersion::VERSION_PLATFORM_MAC) # Create the AppleNoteStore objects create_and_add_notestore(@note_store_modern_location, modern_note_version) @uses_account_folder = check_for_accounts_folder end end
# Creates a new AppleBackupMac. Expects a Pathname +root_folder+ that represents the root of the physical backup and a Pathname +output_folder+ which will hold the results of this run. Immediately sets the NoteStore database file to be the appropriate application's NoteStore.sqlite.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleBackupMac.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackupMac.rb
MIT
def valid? return (@root_folder.directory? and (@root_folder + "NoteStore.sqlite").file? and has_correct_columns?(@root_folder + "NoteStore.sqlite") and (@root_folder + "NotesIndexerState-Modern").file?) end
# This method returns true if it is a value backup of the specified type. For MAC_BACKUP_TYPE this means that the +root_folder+ given is where the root of the directory structure is and the NoteStore.sqlite file is directly underneath.
valid?
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleBackupMac.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackupMac.rb
MIT
def get_real_file_path(filename) pathname = @root_folder + filename return pathname if pathname and pathname.exist? return nil end
# This method returns a Pathname that represents the location on this disk of the requested file or nil. It expects a String +filename+ to look up.
get_real_file_path
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleBackupMac.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackupMac.rb
MIT
def initialize(root_folder, output_folder, decrypter=AppleDecrypter.new) super(root_folder, AppleBackup::PHYSICAL_BACKUP_TYPE, output_folder, decrypter) @physical_backup_app_folder = nil @physical_backup_app_uuid = find_physical_backup_app_uuid # Check to make sure we're all good if self.valid? puts "Created a new AppleBackup from physical backup: #{@root_folder}" # Set the app's folder for ease of reference later @physical_backup_app_folder = (@root_folder + "private" + "var" + "mobile" + "Containers" + "Shared" + "AppGroup" + @physical_backup_app_uuid) # Copy the modern NoteStore to our output directory copy_notes_database(@physical_backup_app_folder + "NoteStore.sqlite", @note_store_modern_location) modern_note_version = AppleNoteStore.guess_ios_version(@note_store_modern_location) # Copy the legacy notes.sqlite to our output directory copy_notes_database(@root_folder + "private" + "var" + "mobile" + "Library" + "Notes" + "notes.sqlite", @note_store_legacy_location) legacy_note_version = AppleNoteStore.guess_ios_version(@note_store_legacy_location) # Create the AppleNoteStore objects create_and_add_notestore(@note_store_modern_location, modern_note_version) create_and_add_notestore(@note_store_legacy_location, legacy_note_version) # Call this a second time, now that we know we are valid and have the right file path @uses_account_folder = check_for_accounts_folder end end
# Creates a new AppleBackupPhysical. Expects a Pathname +root_folder+ that represents the root of the physical backup and a Pathname +output_folder+ which will hold the results of this run. Immediately sets the NoteStore database file to be the appropriate application's NoteStore.sqlite.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleBackupPhysical.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackupPhysical.rb
MIT
def valid? return (@physical_backup_app_uuid != nil) end
# This method returns true if it is a value backup of the specified type. For PHYSICAL_BACKUP_TYPE this means that the +root_folder+ given is where the root of the directory structure is, i.e one step above private.
valid?
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleBackupPhysical.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackupPhysical.rb
MIT
def find_physical_backup_app_uuid # Bail out if this doesn't look obviously right return nil if (!@root_folder or !@root_folder.directory? or !(@root_folder + "private" + "var" + "mobile" + "Containers" + "Shared" + "AppGroup").directory?) # Create a variable to return app_uuid = nil # Create a variable for simplicity app_folder = @root_folder + "private" + "var" + "mobile" + "Containers" + "Shared" + "AppGroup" # Loop over each child entry to check them for what we want app_folder.children.each do |child_entry| if child_entry.directory? and (child_entry + "NoteStore.sqlite").exist? app_uuid = child_entry.basename end end return app_uuid end
# This method iterates through the app UUIDs of a physical backup to identify which one contains Notes. It does it this way to ensure that all files were correctly pulled. It returns the String representing the UUID or nil if not appropriate.
find_physical_backup_app_uuid
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleBackupPhysical.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackupPhysical.rb
MIT
def initialize() # Tracks the AppleCloudKitParticipants this is shared with @share_participants = Array.new() @server_record_data = nil @cloudkit_last_modified_device = nil @cloudkit_creator_record_id = nil @cloudkit_modifier_record_id = nil end
# Creates a new AppleCloudKitRecord. Requires nothing and initializes the share_participants.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleCloudKitRecord.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleCloudKitRecord.rb
MIT
def add_cloudkit_sharing_data(cloudkit_data) keyed_archive = KeyedArchive.new(:data => cloudkit_data) unpacked_top = keyed_archive.unpacked_top() total_added = 0 if unpacked_top unpacked_top["Participants"]["NS.objects"].each do |participant| # Pull out the relevant values if participant["UserIdentity"] participant_user_identity = participant["UserIdentity"] # Initialize a new AppleCloudKitShareParticipant tmp_participant = AppleCloudKitShareParticipant.new() # Read in the user's contact information if participant_user_identity["LookupInfo"] tmp_participant.email = participant_user_identity["LookupInfo"]["EmailAddress"] tmp_participant.phone = participant_user_identity["LookupInfo"]["PhoneNumber"] end # Read in user's record id if participant_user_identity["UserRecordID"] tmp_participant.record_id = participant_user_identity["UserRecordID"]["RecordName"] end # Read in name components if participant_user_identity["NameComponents"] participant_name_components = participant["UserIdentity"]["NameComponents"]["NS.nameComponentsPrivate"] # Split the name up into its components tmp_participant.name_prefix = participant_name_components["NS.namePrefix"] tmp_participant.first_name = participant_name_components["NS.givenName"] tmp_participant.middle_name = participant_name_components["NS.middleName"] tmp_participant.last_name = participant_name_components["NS.familyName"] tmp_participant.name_suffix = participant_name_components["NS.nameSuffix"] tmp_participant.nickname = participant_name_components["NS.nickname"] tmp_participant.name_phonetic = participant_name_components["NS.phoneticRepresentation"] end # Add them to this object @share_participants.push(tmp_participant) total_added += 1 end end end total_added end
# This method adds CloudKit Share data to an AppleCloudKitRecord. It requires a binary String +cloudkit_data+ from the ZSERVERSHAREDATA column.
add_cloudkit_sharing_data
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleCloudKitRecord.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleCloudKitRecord.rb
MIT
def add_cloudkit_server_record_data(server_record_data) @server_record_data = server_record_data keyed_archive = KeyedArchive.new(:data => server_record_data) unpacked_top = keyed_archive.unpacked_top() if unpacked_top @cloudkit_last_modified_device = unpacked_top["ModifiedByDevice"] @cloudkit_creator_record_id = unpacked_top["CreatorUserRecordID"]["RecordName"] @cloudkit_modifier_record_id = unpacked_top["LastModifiedUserRecordID"]["RecordName"] # Sometimes folders don't have their parent reflected in the ZPARENT column and instead # are reflected in this field. Let's set the parent_uuid field and let AppleNoteStore # play cleanup later. if unpacked_top["RecordType"] == "Folder" and unpacked_top["ParentReference"] @parent_uuid = unpacked_top["ParentReference"]["recordID"]["RecordName"] end end end
# This method takes a the binary String +server_record_data+ which is stored in ZSERVERRECORDDATA. Currently just pulls out the last modified device.
add_cloudkit_server_record_data
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleCloudKitRecord.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleCloudKitRecord.rb
MIT
def cloud_kit_record_known?(record_id) @share_participants.each do |participant| return participant if participant.record_id.eql?(record_id) end return false end
# This method takes a String +record_id+ to determine if the particular cloudkit record is known. It returns an AppleCloudKitParticipant object, or False.
cloud_kit_record_known?
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleCloudKitRecord.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleCloudKitRecord.rb
MIT
def to_csv [@record_id, @email, @phone, @name_prefix, @first_name, @middle_name, @last_name, @name_suffix, @name_phonetic] end
# This method generates an Array containing the information necessary to build a CSV
to_csv
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleCloudKitShareParticipant.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleCloudKitShareParticipant.rb
MIT
def prepare_json to_return = Hash.new() to_return[:email] = @email to_return[:record_id] = @record_id to_return[:first_name] = @first_name to_return[:last_name] = @last_name to_return[:middle_name] = @middle_name to_return[:name_prefix] = @name_prefix to_return[:name_suffix] = @name_suffix to_return[:name_phonetic] = @name_phonetic to_return[:phone] = @phone 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/AppleCloudKitShareParticipant.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleCloudKitShareParticipant.rb
MIT
def initialize @logger = Logger.new(STDOUT) @passwords = Array.new @successful_passwords = Array.new @warned_about_empty_password_list = false end
# Creates a new AppleDecrypter. Immediately initalizes +@passwords+ and +@successful_passwords+ as Arrays to keep track of loaded passwords and the ones that worked. Also sets +@warned_about_empty_password_list+ to false in order to nicely warn the user ones if they should be trying to decrypt. Make sure to call logger= at some point if you don't want to dump to STDOUT.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleDecrypter.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb
MIT
def add_passwords_from_file(password_file) if password_file @passwords = Array.new() # Read in each line and add them to our list File.readlines(password_file).each do |password| #@logger.debug("Apple Decrypter: Adding password number #{passwords.length} to our list") @passwords.push(password.chomp) end puts "Added #{@passwords.length} passwords to the AppleDecrypter from #{password_file}" end return @passwords.length end
# This function takes a FilePath +file+ and reads passwords from it one per line to build the overall +@passwords+ Array.
add_passwords_from_file
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleDecrypter.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb
MIT
def decrypt(salt, iterations, key, iv, tag, data, debug_text=nil) # Initialize plaintext variable to be false so we can check if we don't succeed decrypt_result = false # Warn the user if we come across something encrypted and they haven't provided a password list if @passwords.length == 0 and !@warned_about_empty_password_list puts "Apple Decrypter: Attempting to decrypt objects without a password list set, check the -w option for more success" @logger.error("Apple Decrypter: Attempting to decrypt objects without a password list set, check the -w option for more success") @warned_about_empty_password_list = true end # Start with the known good passwords @successful_passwords.each do |password| decrypt_result = decrypt_with_password(password, salt, iterations, key, iv, tag, data, debug_text) if decrypt_result break end end # Only try the full list if we haven't already found the password if !decrypt_result @passwords.each do |password| decrypt_result = decrypt_with_password(password, salt, iterations, key, iv, tag, data, debug_text) if decrypt_result @successful_passwords.push(password) break end end end return decrypt_result end
# This function attempts to decrypt the specified data by looping over all the loaded passwords. It expects a +salt+ as a binary String, the number of +iterations+ as an Integer, a +key+ representing the wrapped key as a binary String, an +iv+ as a binary String, a +tag+ as a binary String, the +data+ to be decrypted as a binary String, and the +item+ being decrypted as an Object to help with debugging. Any successful decrypts will add the corresponding password to the +@successful_passwords+ to be tried first the next time.
decrypt
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleDecrypter.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb
MIT
def check_cryptographic_settings(password, salt, iterations, wrapped_key) tmp_key_encrypting_key = generate_key_encrypting_key(password, salt, iterations) tmp_unwrapped_key = aes_key_unwrap(wrapped_key, tmp_key_encrypting_key) if tmp_key_encrypting_key @successful_passwords.push(password) if (tmp_unwrapped_key and !@successful_passwords.include?(password)) return (tmp_unwrapped_key != nil) end
# This function checks a suspected password, salt, iteration count, and wrapped key to determine if the settings are valid. It does this by checking that the unwrapped key has the correct iv. It returns true if the settings are valid, false otherwise. It expects the +password+ as a String, the +salt+ as a binary String, and the number of +iterations+ as an integer, and the +wrapped_key+ as a binary String.
check_cryptographic_settings
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleDecrypter.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb
MIT
def generate_key_encrypting_key(password, salt, iterations, debug_text=nil, key_size=16, hash_function=OpenSSL::Digest::SHA256.new) # Key length in bytes, multiple by 8 for bits. Apple is using 16 (128-bit) # key_size = 16 generated_key = nil begin generated_key = OpenSSL::PKCS5.pbkdf2_hmac(password, salt, iterations, key_size, hash_function) rescue OpenSSL::Cipher::CipherError puts "Caught CipherError trying to generate PBKDF2 key" @logger.error("Apple Decrypter: #{debug_text} caught a CipherError while trying to generate PBKDF2 key.") rescue OpenSSL::KDF::KDFError puts "Caught KDFError trying to generate PBKDF2 key" @logger.error("Apple Decrypter: #{debug_text} caught a KDFError while trying to generate PBKDF2 key. Length: #{key_size}, Iterations: #{iterations}") end return generated_key end
# This function calls PBKDF2 with Apple's settings to generate a key encrypting key. It expects the +password+ as a String, the +salt+ as a binary String, and the number of +iterations+ as an integer. It returns either nil or the generated key as a binary String. It an error occurs, it will rescue a OpenSSL::Cipher::CipherError and log it.
generate_key_encrypting_key
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleDecrypter.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb
MIT
def aes_key_unwrap(wrapped_key, key_encrypting_key) unwrapped_key = nil begin unwrapped_key = AESKeyWrap.unwrap!(wrapped_key, key_encrypting_key) rescue AESKeyWrap::UnwrapFailedError => error puts error # Not logging this because it will get spammy if different accounts have different passwords end return unwrapped_key end
# This function performs an AES key unwrap function. It expects the +wrapped_key+ as a binary String and the +key_encrypting_key+ as a binary String. It returns either nil or the unwrapped key as a binary String.
aes_key_unwrap
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleDecrypter.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb
MIT
def aes_cbc_decrypt(key, encrypted_data, iv=EMPTY_IV, debug_text=nil) decrypted_data = nil if (!key or !iv or !encrypted_data) @logger.error("AES CBC Decrypt called without either key, iv, or encrypted data.") end begin decrypter = OpenSSL::Cipher.new('aes-256-cbc').decrypt decrypter.decrypt decrypter.padding = 0 # If this is not set to 0, openssl appears to generate an extra block decrypter.key = key decrypter.iv = iv decrypted_data = decrypter.update(encrypted_data) + decrypter.final rescue OpenSSL::Cipher::CipherError => error puts "Failed to decrypt #{debug_text}, unwrapped key likely isn't right." @logger.error("Apple Decrypter: #{debug_text} caught a CipherError while trying final decrypt, likely the unwrapped key is not correct.") end return decrypted_data end
# This function performs an AES-CBC decryption. It expects the +key+ as a binary String, an +iv+ as a binary String, which should be 16 0x00 bytes if you don't have another, and the +encrypted_data+ as a binary String. It returns either nil or the decrypted data as a binary String.
aes_cbc_decrypt
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleDecrypter.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb
MIT
def aes_gcm_decrypt(key, iv, tag, encrypted_data, debug_text=nil) plaintext = nil begin decrypter = OpenSSL::Cipher.new('aes-128-gcm').decrypt decrypter.key = key decrypter.iv_len = iv.length # Just in case the IV isn't 16-bytes decrypter.iv = iv decrypter.auth_tag = tag plaintext = decrypter.update(encrypted_data) + decrypter.final rescue OpenSSL::Cipher::CipherError puts "Failed to decrypt #{debug_text}, unwrapped key likely isn't right." @logger.error("Apple Decrypter: #{debug_text} caught a CipherError while trying final decrypt, likely the unwrapped key is not correct.") end return plaintext end
# This function performs the AES-GCM decryption. It expects a +key+ as a binary String, an +iv+ as a binary String, a +tag+ as a binary String, the +encrypted_data+ as a binary String, and optional +debug_text+ if you want something helpful to hunt in the debug logs. It sets the iv length explicitly to the length of the iv and returns either nil or the plaintext if there was a decrypt. It rescues an OpenSSL::Cipher::CipherError and logs the issue.
aes_gcm_decrypt
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleDecrypter.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb
MIT
def decrypt_with_password(password, salt, iterations, key, iv, tag, data, debug_text=nil) # Create the key with our password @logger.debug("Apple Decrypter: #{debug_text} Attempting decryption.") # Create variables to track our generated and unwrapped keys between blocks decrypt_result = false plainext = false # Generate the key-encrypting key from the user's password generated_key = generate_key_encrypting_key(password, salt, iterations) # Unwrap the key unwrapped_key = aes_key_unwrap(key, generated_key) if generated_key # Decrypt the content only if we have a key plaintext = aes_gcm_decrypt(unwrapped_key, iv, tag, data, debug_text) if unwrapped_key if plaintext decrypt_result = { plaintext: plaintext, password: password } @logger.debug("Apple Decrypter: #{debug_text} decrypted") end return decrypt_result end
# This function attempts to decrypt the note with a specified password. It expects a +password+ as a normal String, a +salt+ as a binary String, the number of +iterations+ as an Integer, a +key+ representing the wrapped key as a binary String, an +iv+ as a binary String, a +tag+ as a binary String, the +data+ to be decrypted as a binary String, and the +item+ being decrypted as an Object to help with debugging. This starts by unwrapping the +wrapped_key+ using the given +password+ by computing the PBDKF2 with the given +salt+ and +iterations+. With the unwrapped key, we can then use the +iv+ to decrypt the +data+ and authenticate it with the +tag+.
decrypt_with_password
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleDecrypter.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb
MIT
def initialize(z_pk, znote, ztitle, zdata, creation_time, modify_time, account, folder) super() # Initialize some other variables while we're here @plaintext = nil @decompressed_data = nil @encrypted_data = nil @widget_snippet = nil @note_proto = nil @crypto_iv = nil @crypto_tag = nil @crypto_key = nil @crypto_salt = nil @crypto_iterations = nil @crypto_password = nil @is_password_protected = false # This holds objects directly in the note itself @embedded_objects = Array.new() # This holds objets embedded in other objects @embedded_objects_recursive = Array.new() # Feed in our arguments @primary_key = z_pk @note_id = znote @title = ztitle @compressed_data = zdata @creation_time = convert_core_time(creation_time) @modify_time = convert_core_time(modify_time) @account = account @folder = folder @notestore = nil @database = nil @backup = nil @logger = Logger.new(STDOUT) @uuid = "" @version = AppleNoteStoreVersion.new # Default to unknown, override this with version= # Handle pinning, added in iOS 11 @is_pinned = false # Cache HTML once generated, useful for multiple outputs that all want the HTML @html = nil end
# Creates a new AppleNote. Expects an Integer +z_pk+, an Integer +znote+ representing the ZICNOTEDATA.ZNOTE field, a String +ztitle+ representing the ZICCLOUDSYNCINGOBJECT.ZTITLE field, a binary String +zdata+ representing the ZICNOTEDATA.ZDATA field, an Integer +creation_time+ representing the iOS CoreTime number found in ZICCLOUDSYNCINGOBJECT.ZCREATIONTIME1 field, an Integer +modify_time+ representing the iOS CoreTime number found in ZICCLOUDSYNCINGOBJECT.ZMODIFICATIONTIME1 field, an AppleNotesAccount +account+ representing the owning account, an AppleNotesFolder +folder+ representing the holding folder, and an AppleNoteStore +notestore+ representing the actual NoteStore representing the full backup.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def process_note # Treat legacy stuff different if @version.legacy? @plaintext = @compressed_data @compressed_data = nil else # Unpack what we can @is_compressed = is_gzip(@compressed_data) decompress_data if @is_compressed extract_plaintext if @decompressed_data replace_embedded_objects if (@plaintext and @database) end end
# This method handles processing the AppleNote's text. For legacy notes that is fairly straightforward and for modern notes that means decompressing and parsing the protobuf.
process_note
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def extract_plaintext if @decompressed_data begin tmp_note_store_proto = NoteStoreProto.decode(@decompressed_data) @plaintext = tmp_note_store_proto.document.note.note_text @note_proto = tmp_note_store_proto rescue Exception puts "Error parsing the protobuf for Note #{@note_id}, have to skip it, see the debug log for more details" @logger.error("Error parsing the protobuf for Note #{@note_id}, have to skip it") @logger.error("Run the following sqlite query to find the appropriate note data, export the ZDATA column as #{@note_id}.blob.gz, gunzip it, and the resulting #{@note_id}.blob contains your protobuf to check with protoc.") @logger.error("\tSELECT ZDATA FROM ZICNOTEDATA WHERE ZNOTE=#{@note_id}") end end end
# This method takes the +decompressed_data+ as an AppleNotesProto protobuf and assigned the plaintext from that protobuf into the +plaintext+ variable.
extract_plaintext
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def replace_embedded_objects if (@plaintext and @account and @folder) tmp_note_store_proto = NoteStoreProto.decode(@decompressed_data) replaced_objects = AppleNotesEmbeddedObject.generate_embedded_objects(self, tmp_note_store_proto) @plaintext = replaced_objects[:to_string] replaced_objects[:objects].each do |replaced_object| @embedded_objects.push(replaced_object) end end end
# This method takes the +plaintext+ that is stored and the +decompressed_data+ as an AppleNotesProto protobuf and loops over all the embedded objects. For each embedded object it finds, it creates a new AppleNotesEmbeddedObject and replaces the "obj" placeholder wth the new object's to_s method. This method creates sub-classes of AppleNotesEmbeddedObject depending on the ZICCLOUDSYNCINGOBJECT.ZTYPEUTI column.
replace_embedded_objects
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def to_csv tmp_pinned = "N" tmp_pinned = "Y" if @is_pinned [@primary_key, @note_id, tmp_pinned, @account.name, @folder.name, @cloudkit_last_modified_device, @cloudkit_creator_record_id, @title, @creation_time, @modify_time, @plaintext, @widget_snippet, @is_password_protected, @crypto_iterations, get_crypto_salt_hex, get_crypto_tag_hex, get_crypto_key_hex, get_crypto_iv_hex, get_encrypted_data_hex, @uuid] end
# This method returns an Array representing the AppleNote CSV export row of this object. Currently that is the +primary_key+, +note_id+, AppleNotesAccount name, AppleNotesFolder name, +title+, +creation_time+, +modify_time+, +plaintext+, and +is_password_protected+. If there are cryptographic variables, it also includes the +crypto_salt+, +crypto_tag+, +crypto_key+, +crypto_iv+, and +encrypted_data+, all as hex, vice binary.
to_csv
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def get_crypto_iv_hex return @crypto_iv if ! @crypto_iv @crypto_iv.unpack("H*") end
# This function returns the +crypto_iv+ as hex, if it exists.
get_crypto_iv_hex
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def get_crypto_key_hex return @crypto_key if ! @crypto_key @crypto_key.unpack("H*") end
# This function returns the +crypto_key+ as hex, if it exists.
get_crypto_key_hex
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def get_crypto_tag_hex return @crypto_tag if ! @crypto_tag @crypto_tag.unpack("H*") end
# This function returns the +crypto_tag+ as hex, if it exists.
get_crypto_tag_hex
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def get_crypto_salt_hex return @crypto_salt if ! @crypto_salt @crypto_salt.unpack("H*") end
# This function returns the +crypto_salt+ as hex, if it exists.
get_crypto_salt_hex
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def get_encrypted_data_hex return @encrypted_data if ! @encrypted_data @encrypted_data.unpack("H*") end
# This function returns the +encrypted_data+ as hex, if it exists.
get_encrypted_data_hex
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def get_note_contents return "Error, note not yet decrypted" if @encrypted_data and !@decompressed_data return "Error, note not yet decompressed" if !@decompressed_data return "Error, note not yet plaintexted" if !@plaintext @plaintext end
# This function returns the +plaintext+ for the note.
get_note_contents
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def is_gzip(data) return false if !data.is_a?(String) return (data.length > 2 and data.bytes[0] == 0x1f and data.bytes[1] == 0x8B) end
# This function checks if specified +data+ is a GZip object by matching the first two bytes.
is_gzip
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def convert_core_time(core_time) return Time.at(0) unless core_time return Time.at(core_time + 978307200) end
# This function converts iOS Core Time, specified as an Integer +core_time+, to a Time object.
convert_core_time
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def decompress_data @decompressed_data = nil # Check for GZip magic number if is_gzip(@compressed_data) zlib_inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 16) begin @decompressed_data = zlib_inflater.inflate(@compressed_data) rescue StandardError => error # warn "\033[101m#{error}\033[m" # Prettified colors @logger.error("AppleNote: Note #{@note_id} somehow tried to decompress something that was GZIP but had to rescue error: #{error}") end else @logger.error("AppleNote: Note #{@note_id} somehow tried to decompress something that was not a GZIP") end end
# This function decompresses the orginally GZipped data present in +compressed_data+. It stores the result in +decompressed_data+
decompress_data
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def add_cryptographic_settings(crypto_iv, crypto_tag, crypto_salt, crypto_iterations, crypto_verifier, crypto_wrapped_key) @encrypted_data = @compressed_data # Move what was in compressed by default over to encrypted @compressed_data = nil @is_password_protected = true @crypto_iv = crypto_iv @crypto_tag = crypto_tag @crypto_salt = crypto_salt @crypto_iterations = crypto_iterations @crypto_key = crypto_verifier if crypto_verifier @crypto_key = crypto_wrapped_key if crypto_wrapped_key end
# This function adds cryptographic settings to the AppleNote. It expects a +crypto_iv+ as a binary String, a +crypto_tag+ as a binary String, a +crypto_salt+ as a binary String, the +crypto_iterations+ as an Integer, a +crypto_verifier+ as a binary String, and a +crypto_wrapped_key+ as a binary String. No AppleNote should ahve both a +crypto_verifier+ and a +crypto_wrapped_key+.
add_cryptographic_settings
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def has_cryptographic_variables? return (@is_password_protected and @encrypted_data and @crypto_iv and @crypto_tag and @crypto_salt and @crypto_iterations and @crypto_key) end
# This function ensures all cryptographic variables are set.
has_cryptographic_variables?
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def decrypt return false if !has_cryptographic_variables? decrypt_result = @backup.decrypter.decrypt(@crypto_salt, @crypto_iterations, @crypto_key, @crypto_iv, @crypto_tag, @encrypted_data, "Apple Note: #{@note_id}") # If we made a decrypt, then kick the result into our normal process to extract everything if decrypt_result @crypto_password = decrypt_result[:password] @compressed_data = decrypt_result[:plaintext] decompress_data extract_plaintext if @decompressed_data replace_embedded_objects if (@plaintext and @database) end return (plaintext != false) end
# This function attempts to decrypt the note by providing its cryptographic variables to the AppleDecrypter.
decrypt
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def has_tags @embedded_objects.each do |embedded_object| return true if embedded_object.is_a? AppleNotesEmbeddedInlineHashtag end return false end
# This method returns true if the AppleNote has any tags on it.
has_tags
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def get_all_tags to_return = [] @embedded_objects.each do |embedded_object| to_return.push(embedded_object) if embedded_object.is_a? AppleNotesEmbeddedInlineHashtag end return to_return end
# This method returns an Array of each AppleNotesEmbeddedInlineHashtag on the AppleNote.
get_all_tags
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def all_embedded_objects @embedded_objects + @embedded_objects_recursive end
# This method returns all the embedded objects in an AppleNote as an Array.
all_embedded_objects
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNote.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb
MIT
def initialize(primary_key, name, identifier) # Initialize some variables we may need later @crypto_salt = nil @crypto_iterations = nil @crypto_key = nil @password = nil @server_record_data = nil # Initialize notes and folders Arrays for this account @notes = Array.new() @folders = Array.new() @retain_order = false # Set this account's variables @primary_key = primary_key @name = name # Default html to empty until we build it @html = nil # Defaulting to the same value as the name, this can be overridden if the sort order is known @sort_order_name = name @identifier = identifier @user_record_name = "" # Figure out the Account's folder for attachments @account_folder = "Accounts/#{@identifier}/" # Uncomment the below line if you want to see the account names during creation # puts "Account #{@primary_key} is called #{@name}" end
# This creates a new AppleNotesAccount. It requires an Integer +primary_key+, a String +name+, and a String +identifier+ representing the ZIDENTIFIER column.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesAccount.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesAccount.rb
MIT
def add_crypto_variables(crypto_salt, crypto_iterations, crypto_key) @crypto_salt = crypto_salt @crypto_iterations = crypto_iterations @crypto_key = crypto_key end
# This method adds the cryptographic variables to the account. This is outside of initialize as older Apple Notes didn't have this functionality. This requires a String of binary +crypto_salt+, an Integer of the number of +iterations+, and a String of binary +crypto_key+. Do not feed in hex.
add_crypto_variables
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesAccount.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesAccount.rb
MIT
def clean_name @name.tr('/:\\', '_') end
# Returns a name with things removed that might allow for poorly placed files
clean_name
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesAccount.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesAccount.rb
MIT
def add_password(password) @password = password end
# This function takes a String +password+. It is unclear how or if this password matters right now.
add_password
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesAccount.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesAccount.rb
MIT
def add_folder(folder) # Remove any copy if we already have it @folders.delete_if {|old_folder| old_folder.primary_key == folder.primary_key} @folders.push(folder) end
# This method requies an AppleNotesFolder object as +folder+ and adds it to the accounts's Array.
add_folder
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesAccount.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesAccount.rb
MIT
def to_csv [@primary_key, @name, @user_record_name, @identifier, @cloudkit_last_modified_device, @notes.length, get_crypto_salt_hex, @crypto_iterations, get_crypto_key_hex] end
# This method generates an Array containing the information needed for CSV generation.
to_csv
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesAccount.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesAccount.rb
MIT
def sorted_folders return @folders if !@retain_order @folders.sort_by{|folder| [folder.sort_order]} end
# This method returns an Array containing the AppleNotesFolders for the account, sorted in appropriate order
sorted_folders
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesAccount.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesAccount.rb
MIT
def generate_html(individual_files: false, use_uuid: false) params = [individual_files, use_uuid] if @html && @html[params] return @html[params] end builder = Nokogiri::HTML::Builder.new(encoding: "utf-8") do |doc| doc.div { doc.h1 { doc.a(id: "account_#{@primary_key}") { doc.text @name } } if @user_record_name.length > 0 doc.div { doc.b { doc.text "Cloudkit Identifier:" } doc.text " " doc.text @user_record_name } end doc.div { doc.b { doc.text "Account Identifier:" } doc.text " " doc.text @identifier } if @cloudkit_last_modified_device doc.div { doc.b { doc.text "Last Modified Device:" } doc.text " " doc.text @cloudkit_last_modified_device } end doc.div { doc.b { doc.text "Number of Notes:" } doc.text " " doc.text @notes.length } doc.div { doc.b { doc.text "Folders:" } doc.ul { sorted_folders.each do |folder| doc << folder.generate_folder_hierarchy_html(individual_files: individual_files, use_uuid: use_uuid) if !folder.is_child? end } } } end @html ||= {} @html[params] = builder.doc.root end
# This method generates HTML to display on the overall output.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesAccount.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesAccount.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 AppleNotesEmbeddedCalendar 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 ics file is stored. Finally, it attempts to copy the file to the output folder.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedCalendar.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedCalendar.rb
MIT
def to_s to_s_with_data("iCal ICS") 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/AppleNotesEmbeddedCalendar.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedCalendar.rb
MIT
def generate_html(individual_files=false) generate_html_with_link("iCal ICS", individual_files) end
# This method generates the HTML necessary to display the image inline.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedCalendar.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedCalendar.rb
MIT
def initialize(uuid, uti, note) # Set this object's variables super("Deleted", uuid, uti, note) end
# Creates a new AppleNotesEmbeddedDeletedObject object. Expects a +uuid+ that would have been the ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, String +uti+ that would have been the ZICCLOUDSYNCINGOBJECT.ZTYPEUTI, and an AppleNote +note+ object representing the parent AppleNote.
initialize
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedDeletedObject.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedDeletedObject.rb
MIT
def generate_html(individual_files=false) generate_html_with_link("Document", individual_files) end
# This method generates the HTML necessary to display the file download link.
generate_html
ruby
threeplanetssoftware/apple_cloud_notes_parser
lib/AppleNotesEmbeddedDocument.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedDocument.rb
MIT
def initialize(primary_key, uuid, uti, note, backup) # Set this folder's variables super(primary_key, uuid, uti, note) @filename = "" @filepath = "" @backup = backup @zgeneration = get_zgeneration_for_fallback_image 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_fallback_iv, @crypto_fallback_tag) end end
# Creates a new AppleNotesEmbeddedDrawing 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/AppleNotesEmbeddedDrawing.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedDrawing.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/AppleNotesEmbeddedDrawing.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedDrawing.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/AppleNotesEmbeddedDrawing.rb
https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedDrawing.rb
MIT
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 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 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 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 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 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 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_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 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 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 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 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) # 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 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 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) # 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