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 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 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_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 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 |
def to_csv
participant_emails = @share_participants.map {|participant| participant.email}.join(",")
parent_id = ""
parent_name = ""
if is_child?
parent_id = @parent.primary_key
parent_name = @parent.name
end
to_return = [@primary_key, @name, @notes.length, @account.primary_key, @account.name, participant_emails, parent_id, parent_name, "", @uuid]
return to_return
end | #
This method generates an Array containing the information needed for CSV generation | to_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def full_name_with_links(individual_files: false, use_uuid: false, relative_root: to_uri, include_id: false)
builder = Nokogiri::HTML::Builder.new(encoding: "utf-8") do |doc|
current_node = self
parents = Array.new
doc.span {
# Build the list of folders we need to traverse
while current_node.is_child?
current_node = current_node.parent
parents.push current_node
end
# traverse the list, creating a link for each
parents.reverse.each do |parent|
tmp_folder = parent.anchor_link(use_uuid: use_uuid)
if individual_files
tmp_folder = parent.to_uri.join("index.html").relative_path_from(relative_root)
end
options = {href: tmp_folder}
options[:id] = "folder_#{parent.unique_id(use_uuid)}" if include_id
doc.a(options) {
doc.text parent.name
}
doc.text " -> "
end
tmp_folder = anchor_link(use_uuid: use_uuid)
if individual_files
tmp_folder = relative_root.join("index.html").relative_path_from(relative_root)
end
options = {href: tmp_folder}
options[:id] = "folder_#{unique_id(use_uuid)}" if include_id
doc.a(options) {
doc.text @name
}
}
end
return builder.doc.root
end | This method prepares the folder name, as displayed in HTML, with links
to each of its parents via a recursive approach. | full_name_with_links | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def sorted_notes
return @notes if !@retain_order
@notes.sort_by { |note| [note.is_pinned ? 1 : 0, note.modify_time] }.reverse
end | #
This method returns an Array of AppleNote objects in the appropriate order based on current sort settings. | sorted_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 to_account_root(individual_files=false)
return "../" if !individual_files
return (@parent.to_account_root(individual_files) + "../") if @parent
return "../"
end | This method computes the path to get to the account root folder. It only
has meaning when using the --individual-files switch at runtime. | to_account_root | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def to_path
# If this folder has a parent, we do NOT want to embed the account name every time
if @parent
return @parent.to_path.join(Pathname.new("#{clean_name}"))
end
# If we get here, the folder is a root folder and we DO want to preface it with the account namespace
return Pathname.new("#{@account.clean_name}-#{clean_name}")
end | This method is used to generate the filepath on disk for a folder, if the
--individual-files switch is passed at run time. | to_path | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def to_uri
# If this folder has a parent, we do NOT want to embed the account name every time
if @parent
return @parent.to_uri.join(Pathname.new(CGI.escapeURIComponent(clean_name)))
end
# If we get here, the folder is a root folder and we DO want to preface it with the account namespace
return Pathname.new(CGI.escapeURIComponent("#{@account.clean_name}-#{clean_name}"))
end | This method is used to generate the actual clickable URI to get to a specific folder
if the --individual-files switch is passed at runtime | to_uri | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def initialize(folder_primary_key, folder_name, folder_account, query)
super(folder_primary_key, folder_name, folder_account)
@query = query
end | #
Creates a new AppleNotesSmartFolder.
Requires the folder's +primary_key+ as an Integer, +name+ as a String,
+account+ as an AppleNotesAccount, and +query+ as a String representing
how this folder selects notes to display. | initialize | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesSmartFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesSmartFolder.rb | MIT |
def initialize(file_path, version)
@file_path = file_path
@database = nil
@logger = Logger.new(STDOUT)
@version = version
@notes = Hash.new()
@folders = Hash.new()
@folder_order = Hash.new()
@accounts = Hash.new()
@cloud_kit_participants = Hash.new()
@retain_order = false
@html = nil
@range_start = 0
@range_end = Time.now.to_i
end | #
Creates a new AppleNoteStore. Expects a FilePath +file_path+ to the NoteStore.sqlite
database itself. Uses that to create a SQLite3::Database object to query into it. Immediately
creates an Array to hold the +notes+, an Array to hold the +folders+ and an Array to hold
the +accounts+. Then it calls +rip_accounts+ and +rip_folders+ to populate them. Also
expects an Integer +version+ to know what type it is. | initialize | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def open
return if @database
@database = SQLite3::Database.new(@file_path.to_s, {results_as_hash: true})
end | #
This method opens the AppleNoteStore's database. | open | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def close
@database.close if @database
end | #
This method nicely closes the database handle. | close | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def valid_notes?
return true if @version >= AppleNoteStoreVersion::IOS_LEGACY_VERSION # Easy out if we've already identified the version
# Just because my fingerprinting isn't great yet, adding in a more manual check for the key tables we need
expected_tables = ["ZICCLOUDSYNCINGOBJECT",
"ZICNOTEDATA"]
@database.execute("SELECT name FROM sqlite_master WHERE type='table'") do |row|
expected_tables.delete(row["name"])
end
return (expected_tables.length == 0)
end | #
This method ensures that the SQLite3::Database is a valid iCloud version of Apple Notes. | valid_notes? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_all_objects
open
rip_accounts()
rip_folders()
rip_notes()
puts "Updated AppleNoteStore object with #{@notes.length} AppleNotes in #{@folders.length} folders belonging to #{@accounts.length} accounts."
end | #
This method kicks off the parsing of all the objects | rip_all_objects | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_account_csv
to_return = [AppleNotesAccount.to_csv_headers]
@accounts.each do |key, account|
to_return.push(account.to_csv)
end
to_return
end | #
This method returns an Array of rows to build the +accounts+
CSV object. | get_account_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def add_plain_text_to_database
return if @version < AppleNoteStoreVersion::IOS_VERSION_9 # Fail out if we're prior to the compressed data age
# Warn the user
puts "Adding the ZICNOTEDATA.ZPLAINTEXT and ZICNOTEDATA.ZDECOMPRESSEDDATA columns, this takes a few seconds"
# Add the new ZPLAINTEXT column
@database.execute("ALTER TABLE ZICNOTEDATA ADD COLUMN ZPLAINTEXT TEXT")
@database.execute("ALTER TABLE ZICNOTEDATA ADD COLUMN ZDECOMPRESSEDDATA TEXT")
# Loop over each AppleNote
@notes.each do |key, note|
# Update the database to include the plaintext
@database.execute("UPDATE ZICNOTEDATA " +
"SET ZPLAINTEXT=?, ZDECOMPRESSEDDATA=? " +
"WHERE Z_PK=?",
[note.plaintext, note.decompressed_data, note.primary_key]) if note.plaintext
end
end | #
This method adds the ZPLAINTEXT column to ZICNOTEDATA
and then populates it with each note's plaintext. | add_plain_text_to_database | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_embedded_object_csv
to_return = [AppleNotesEmbeddedObject.to_csv_headers]
# Loop over each AppleNote
@notes.each do |key, note|
# Loop over eac AppleNotesEmbeddedObject
note.all_embedded_objects.each do |embedded_object|
# Get the results of AppleNotesEmbeddedObject.to_csv
embedded_object_csv = embedded_object.to_csv
# Check to see if the first element is an Array
if embedded_object_csv.first.is_a? Array
# If it is, loop over each entry to add it to our results
embedded_object_csv.each do |embedded_array|
to_return.push(embedded_array)
end
else
to_return.push(embedded_object_csv)
end
end
end
to_return
end | #
This method returns an Array of rows to build the
CSV object holding all AppleNotesEmbeddedObject instances in its +notes+. | get_embedded_object_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_folder_csv
to_return = [AppleNotesFolder.to_csv_headers]
@folders.sort_by{|key, folder| key}.each do |key, folder|
to_return.push(folder.to_csv)
end
to_return
end | #
This method returns an Array of rows to build the +folders+
CSV object. | get_folder_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_cloudkit_participants_csv
to_return = [AppleCloudKitShareParticipant.to_csv_headers]
@cloud_kit_participants.each do |key, participant|
to_return.push(participant.to_csv)
end
to_return
end | #
This method returns an Array of rows to build the +cloudkit_participants+
CSV object. | get_cloudkit_participants_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_note_csv
to_return = [AppleNote.to_csv_headers]
@notes.each do |key, note|
to_return.push(note.to_csv)
end
to_return
end | #
This method returns an Array of rows to build the +notes+
CSV object. | get_note_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_account_by_user_record_name(user_record_name)
@accounts.each_pair do |account_id, account|
return account if (account.user_record_name == user_record_name)
end
return nil
end | #
This method looks up an AppleNotesAccount based on the given +user_record_name+.
User record nameshould be a String that represents the ZICCLOUDSYNCINGOBJECT.ZUSERRECORDNAME of the account. | get_account_by_user_record_name | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_folder_by_uuid(folder_uuid)
@folders.each_value do |folder|
return folder if folder.uuid == folder_uuid
end
return nil
end | #
This method looks up an AppleNotesFolder based on the given +folder_uuid+.
ID should be a String that represents the ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER of the folder. | get_folder_by_uuid | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_accounts()
if @version.modern?
@database.execute("SELECT ZICCLOUDSYNCINGOBJECT.Z_PK " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICCLOUDSYNCINGOBJECT.ZNAME IS NOT NULL") do |row|
rip_account(row["Z_PK"])
end
end
if @version.legacy?
@database.execute("SELECT ZACCOUNT.Z_PK FROM ZACCOUNT") do |row|
rip_account(row["Z_PK"])
end
end
@accounts.each_pair do |key, account|
@logger.debug("Rip Accounts final array: #{key} corresponds to #{account.name}")
end
end | #
This function identifies all AppleNotesAccount potential
objects in ZICCLOUDSYNCINGOBJECTS and calls +rip_account+ on each. | rip_accounts | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_account(account_id)
@logger.debug("Rip Account: Calling rip_account on Account ID #{account_id}")
# Set the ZSERVERRECORD column to look at
server_record_column = "ZSERVERRECORD"
server_record_column = server_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZSERVERSHARE column to look at
server_share_column = "ZSERVERSHARE"
server_share_column = server_share_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZACCOUNTDATA column to look at
account_data_column = "-1 as ZACCOUNTDATA"
account_data_column = "ZICCLOUDSYNCINGOBJECT.ZACCOUNTDATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_13 # This column appears to show up in iOS 12
@logger.debug("Rip Account: Using server_record_column of #{server_record_column}")
# Set the query
query_string = "SELECT ZICCLOUDSYNCINGOBJECT.ZNAME, ZICCLOUDSYNCINGOBJECT.Z_PK, " +
"ZICCLOUDSYNCINGOBJECT.#{server_record_column}, ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOVERIFIER, ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, " +
"ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, ZICCLOUDSYNCINGOBJECT.#{server_share_column}, " +
"ZICCLOUDSYNCINGOBJECT.ZUSERRECORDNAME, #{account_data_column}, " +
"ZICCLOUDSYNCINGOBJECT.ZACCOUNTNAMEFORACCOUNTLISTSORTING " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?"
# Change the query for legacy IOS
if @version.legacy?
query_string = "SELECT ZACCOUNT.ZNAME, ZACCOUNT.Z_PK, " +
"ZACCOUNT.ZACCOUNTIDENTIFIER as ZIDENTIFIER " +
"FROM ZACCOUNT " +
"WHERE ZACCOUNT.Z_PK=?"
end
@logger.debug("Rip Account: Query is #{query_string}")
# Run the query
@database.execute(query_string, account_id) do |row|
# Create account object
tmp_account = AppleNotesAccount.new(row["Z_PK"],
row["ZNAME"],
row["ZIDENTIFIER"])
tmp_account.retain_order = @retain_order
# Handle LocalAccounts that are in odd places
likely_location = @backup.root_folder + tmp_account.account_folder
if tmp_account.identifier == "LocalAccount" and not likely_location.exist?
tmp_account.account_folder = ""
@logger.debug("Rip Account: LocalAccount found with files in the Notes root folder, not an account folder, this is fine.")
end
# Add server-side data, if relevant
tmp_account.user_record_name = row["ZUSERRECORDNAME"] if row["ZUSERRECORDNAME"]
tmp_account.add_cloudkit_server_record_data(row[server_record_column]) if row[server_record_column]
# Set the sort order for the account so we can properly sort things later
tmp_account.sort_order_name = row["ZACCOUNTNAMEFORACCOUNTLISTSORTING"] if row["ZACCOUNTNAMEFORACCOUNTLISTSORTING"]
if(row[server_share_column])
tmp_account.add_cloudkit_sharing_data(row[server_share_column])
# Add any share participants to our overall list
tmp_account.share_participants.each do |participant|
@cloud_kit_participants[participant.record_id] = participant
end
end
# Add cryptographic variables, if relevant
if row["ZCRYPTOVERIFIER"]
tmp_account.add_crypto_variables(row["ZCRYPTOSALT"],
row["ZCRYPTOITERATIONCOUNT"],
row["ZCRYPTOVERIFIER"])
end
# Store the folder structure if we have one
if row["ZACCOUNTDATA"] and row["ZACCOUNTDATA"] > 0
account_data_query_string = "SELECT ZICCLOUDSYNCINGOBJECT.ZMERGEABLEDATA " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE Z_PK=?"
@database.execute(account_data_query_string, row["ZACCOUNTDATA"]) do |account_data_row|
gzipped_data = account_data_row["ZMERGEABLEDATA"]
# Make sure this exists before we try to unpack it
@logger.debug("Rip Account: row['ZMERGEABLEDATA'] is empty!") if !gzipped_data
if gzipped_data
# 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)
# Loop over all the mergeable data object entries to find the list
mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry.each do |mergeable_data_object_entry|
# Once you find the list, loop over each entry to...
if mergeable_data_object_entry.list
mergeable_data_object_entry.list.list_entry.each do |list_entry|
# Fetch the folder order, which is an int64 in the protobuf
additional_details_index = list_entry.additional_details.id.object_index
additional_details_object = mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry[additional_details_index]
tmp_folder_placement = additional_details_object.unknown_message.unknown_entry.unknown_int2
# Pull out the object index we can find the UUID at
list_index = list_entry.id.object_index
# Use that index to find the UUID's object
tmp_folder_uuid_object = mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry[list_index]
# Look inside that object to get the string value that is saved in the custom map
tmp_folder_uuid = tmp_folder_uuid_object.custom_map.map_entry.first.value.string_value
@folder_order[tmp_folder_uuid] = tmp_folder_placement
end
end
end
end
end
end
@logger.debug("Rip Account: Created account #{tmp_account.name}")
@accounts[account_id] = tmp_account
end
end | #
This function takes a specific AppleNotesAccount potential
object in ZICCLOUDSYNCINGOBJECTS, identified by Integer +account_id+, and pulls the needed information to create the object.
If encryption information is present, it adds it with AppleNotesAccount.add_crypto_variables. | rip_account | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_folders()
if @version.modern?
@database.execute("SELECT ZICCLOUDSYNCINGOBJECT.Z_PK " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICCLOUDSYNCINGOBJECT.ZTITLE2 IS NOT NULL") do |row|
rip_folder(row["Z_PK"])
end
end
# In legacy Notes the "folders" were "stores"
if @version.legacy?
@database.execute("SELECT ZSTORE.Z_PK FROM ZSTORE") do |row|
rip_folder(row["Z_PK"])
end
end
# Loop over all folders to do some clean up
@folders.each_pair do |key, folder|
if folder.is_orphan?
tmp_parent_folder = get_folder(folder.parent_id) if folder.parent_id
tmp_parent_folder = get_folder_by_uuid(folder.parent_uuid) if folder.parent_uuid
@logger.debug("Rip Folder: Identified parent UUID #{folder.parent_uuid} for Folder #{folder.primary_key} (#{folder.name}) in ZSERVERRECORD data")
if tmp_parent_folder
tmp_parent_folder.add_child(folder)
@logger.debug("Rip Folder: Added folder #{folder.primary_key} (#{folder.full_name}) as child to #{tmp_parent_folder.name}")
else
@logger.debug("Rip Folder: Could not find parent folder for Folder #{folder.primary_key}")
end
end
@logger.debug("Rip Folders final array: #{key} corresponds to #{folder.name}")
end
# Sort the folders if we want to retain the order, group each account together
if @retain_order
@folders = @folders.sort_by{|folder_id, folder| [folder.account.sort_order_name, folder.sort_order]}.to_h
# Also organize the child folders nicely
@folders.each do |folder_id, folder|
folder.sort_children
end
end
end | #
This function identifies all AppleNotesFolder potential
objects in ZICCLOUDSYNCINGOBJECTS and calls +rip_folder+ on each. | rip_folders | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_folder(folder_id)
@logger.debug("Rip Folder: Calling rip_folder on Folder ID #{folder_id}")
# Set the ZSERVERRECORD column to look at
server_record_column = "ZSERVERRECORD"
server_record_column = server_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZSERVERSHARE column to look at
server_share_column = "ZSERVERSHARE"
server_share_column = server_share_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
smart_folder_query = "'' as ZSMARTFOLDERQUERYJSON"
smart_folder_query = "ZICCLOUDSYNCINGOBJECT.ZSMARTFOLDERQUERYJSON" if @version >= AppleNoteStoreVersion::IOS_VERSION_15
query_string = "SELECT ZICCLOUDSYNCINGOBJECT.ZTITLE2, ZICCLOUDSYNCINGOBJECT.ZOWNER, " +
"ZICCLOUDSYNCINGOBJECT.#{server_record_column}, ZICCLOUDSYNCINGOBJECT.#{server_share_column}, " +
"ZICCLOUDSYNCINGOBJECT.Z_PK, ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, " +
"ZICCLOUDSYNCINGOBJECT.ZPARENT, #{smart_folder_query} " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?"
#Change things up for the legacy version
if @version.legacy?
query_string = "SELECT ZSTORE.Z_PK, ZSTORE.ZNAME as ZTITLE2, " +
"ZSTORE.ZACCOUNT as ZOWNER, '' as ZIDENTIFIER " +
"FROM ZSTORE " +
"WHERE ZSTORE.Z_PK=?"
end
@database.execute(query_string, folder_id) do |row|
tmp_folder = AppleNotesFolder.new(row["Z_PK"],
row["ZTITLE2"],
get_account(row["ZOWNER"]))
# If this is a smart folder, instead build an AppleNotesSmartFolder
if row["ZSMARTFOLDERQUERYJSON"] and row["ZSMARTFOLDERQUERYJSON"].length > 0
tmp_folder = AppleNotesSmartFolder.new(row["Z_PK"],
row["ZTITLE2"],
get_account(row["ZOWNER"]),
row["ZSMARTFOLDERQUERYJSON"])
end
if row["ZIDENTIFIER"]
tmp_folder.uuid = row["ZIDENTIFIER"]
end
# Set whether the folder displays notes in numeric order, or by modification date
tmp_folder.retain_order = @retain_order
tmp_folder.sort_order = @folder_order[row["ZIDENTIFIER"]] if @folder_order[row["ZIDENTIFIER"]]
# Remember folder heirarchy
if row["ZPARENT"]
tmp_parent_folder_id = row["ZPARENT"]
tmp_folder.parent_id = tmp_parent_folder_id
end
# Add server-side data, if relevant
tmp_folder.add_cloudkit_server_record_data(row[server_record_column]) if row[server_record_column]
if(row[server_share_column])
tmp_folder.add_cloudkit_sharing_data(row[server_share_column])
# Add any share participants to our overall list
tmp_folder.share_participants.each do |participant|
@cloud_kit_participants[participant.record_id] = participant
end
end
@logger.debug("Rip Folder: Created folder #{tmp_folder.name}")
# Whether child or not, we add it to the overall tracker so we can look up by folder ID.
# We'll clean up on output by testing to see if a folder has a parent.
@folders[folder_id] = tmp_folder
end
end | #
This function takes a specific AppleNotesFolder potential
object in ZICCLOUDSYNCINGOBJECTS, identified by Integer +folder_id+, and pulls the needed information to create the object.
This used to use ZICCLOUDSYNCINGOBJECT.ZACCOUNT4, but that value also appears to be duplicated in ZOWNER which goes back further. | rip_folder | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_notes()
range_start_core = (@range_start - 978307200)
range_end_core = (@range_end - 978307200)
@logger.debug("Rip Notes: Ripping notes between #{Time.at(range_start)} and #{Time.at(range_end)}")
if @version.modern?
tmp_query = "SELECT ZICNOTEDATA.ZNOTE " +
"FROM ZICNOTEDATA, ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICNOTEDATA.ZDATA NOT NULL AND ZICCLOUDSYNCINGOBJECT.Z_PK=ZICNOTEDATA.ZNOTE AND " +
"ZICCLOUDSYNCINGOBJECT.ZMODIFICATIONDATE1 >= ? AND " +
"ZICCLOUDSYNCINGOBJECT.ZMODIFICATIONDATE1 <= ?"
@database.execute(tmp_query, [range_start_core, range_end_core]) do |row|
begin
self.rip_note(row["ZNOTE"])
rescue StandardError => error
# warn "\033[101m#{e}\033[m"
@logger.error("AppleNoteStore: NoteStore tried to rip Note #{row["ZNOTE"]} but had to rescue error: #{error}")
@logger.error("Backtrace: #{error.backtrace.join("\n\t")}") # if error.is_a? FrozenError
end
end
end
if @version.legacy?
@database.execute("SELECT ZNOTE.Z_PK FROM ZNOTE") do |row|
self.rip_note(row["Z_PK"])
end
end
end | #
This function identifies all AppleNote potential
objects in ZICNOTEDATA and calls +rip_note+ on each. | rip_notes | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_note(note_id)
@logger.debug("Rip Note: Ripping note from Note ID #{note_id}")
# Set the ZSERVERRECORD column to look at
server_record_column = "ZSERVERRECORD"
server_record_column = server_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZSERVERSHARE column to look at
server_share_column = "ZSERVERSHARE"
server_share_column = server_share_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZWIDGETSNIPPET column, blank if earlier than iOS 17
widget_snippet_column = ""
widget_snippet_column = ", ZWIDGETSNIPPET" if @version >= AppleNoteStoreVersion::IOS_VERSION_17
# Set the ZUNAPPLIEDENCRYPTEDRECORD column to look at
unapplied_encrypted_record_column = "ZUNAPPLIEDENCRYPTEDRECORD"
unapplied_encrypted_record_column = unapplied_encrypted_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_18 # In iOS 17 this was ZUNAPPLIEDENCRYPTEDRECORD, in 18 and later it becomes ZUNAPPLIEDENCRYPTEDRECORDDATA
folder_field = "ZFOLDER"
account_field = "ZACCOUNT7"
note_id_field = "ZNOTE"
creation_date_field = "ZCREATIONDATE1"
# In version 15, what is now in ZACCOUNT7 as of iOS 16 (the account ID) was in ZACCOUNT4
if @version == AppleNoteStoreVersion::IOS_VERSION_15
account_field = "ZACCOUNT4"
end
# In version 13 and 14, what is now in ZACCOUNT4 as of iOS 15 (the account ID) was in ZACCOUNT3
if @version < AppleNoteStoreVersion::IOS_VERSION_15
account_field = "ZACCOUNT3"
end
# In iOS 15 it appears ZCREATIONDATE1 moved to ZCREATIONDATE3 for notes
if @version > AppleNoteStoreVersion::IOS_VERSION_14
creation_date_field = "ZCREATIONDATE3"
end
query_string = "SELECT ZICNOTEDATA.Z_PK, ZICNOTEDATA.ZNOTE, " +
"ZICNOTEDATA.ZCRYPTOINITIALIZATIONVECTOR, ZICNOTEDATA.ZCRYPTOTAG, " +
"ZICNOTEDATA.ZDATA, ZICCLOUDSYNCINGOBJECT.ZCRYPTOVERIFIER, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOWRAPPEDKEY, ZICCLOUDSYNCINGOBJECT.ZISPASSWORDPROTECTED, " +
"ZICCLOUDSYNCINGOBJECT.ZMODIFICATIONDATE1, ZICCLOUDSYNCINGOBJECT.#{creation_date_field}, " +
"ZICCLOUDSYNCINGOBJECT.ZTITLE1, ZICCLOUDSYNCINGOBJECT.#{account_field}, " +
"ZICCLOUDSYNCINGOBJECT.ZACCOUNT2, ZICCLOUDSYNCINGOBJECT.#{folder_field}, " +
"ZICCLOUDSYNCINGOBJECT.#{server_record_column}, ZICCLOUDSYNCINGOBJECT.#{unapplied_encrypted_record_column}, " +
"ZICCLOUDSYNCINGOBJECT.#{server_share_column}, ZICCLOUDSYNCINGOBJECT.ZISPINNED, " +
"ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER #{widget_snippet_column} " +
"FROM ZICNOTEDATA, ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICNOTEDATA.ZNOTE=? AND ZICCLOUDSYNCINGOBJECT.Z_PK=ZICNOTEDATA.ZNOTE"
# In version 12, what is now in ZACCOUNT3 (the account ID) was in ZACCOUNT2
if @version == AppleNoteStoreVersion::IOS_VERSION_12
account_field = "ZACCOUNT2"
end
# In version 11, what is now in ZACCOUNT3 was in ZACCOUNT2 and the ZFOLDER field was in a completely separate table
if @version == AppleNoteStoreVersion::IOS_VERSION_11
query_string = "SELECT ZICNOTEDATA.Z_PK, ZICNOTEDATA.ZNOTE, " +
"ZICNOTEDATA.ZCRYPTOINITIALIZATIONVECTOR, ZICNOTEDATA.ZCRYPTOTAG, " +
"ZICNOTEDATA.ZDATA, ZICCLOUDSYNCINGOBJECT.ZCRYPTOVERIFIER, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOWRAPPEDKEY, ZICCLOUDSYNCINGOBJECT.ZISPASSWORDPROTECTED, " +
"ZICCLOUDSYNCINGOBJECT.ZMODIFICATIONDATE1, ZICCLOUDSYNCINGOBJECT.ZCREATIONDATE1, " +
"ZICCLOUDSYNCINGOBJECT.ZTITLE1, ZICCLOUDSYNCINGOBJECT.ZACCOUNT2, " +
"Z_11NOTES.Z_11FOLDERS, ZICCLOUDSYNCINGOBJECT.#{server_record_column}, " +
"ZICCLOUDSYNCINGOBJECT.#{unapplied_encrypted_record_column}, ZICCLOUDSYNCINGOBJECT.#{server_share_column}, " +
"ZICCLOUDSYNCINGOBJECT.ZISPINNED, ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER " +
"FROM ZICNOTEDATA, ZICCLOUDSYNCINGOBJECT, Z_11NOTES " +
"WHERE ZICNOTEDATA.ZNOTE=? AND ZICCLOUDSYNCINGOBJECT.Z_PK=ZICNOTEDATA.ZNOTE AND Z_11NOTES.Z_8NOTES=ZICNOTEDATA.ZNOTE"
folder_field = "Z_11FOLDERS"
account_field = "ZACCOUNT2"
end
# In the legecy version, everything is different
if @version.legacy?
query_string = "SELECT ZNOTE.Z_PK, ZNOTE.ZCREATIONDATE as ZCREATIONDATE1, " +
"ZNOTE.ZMODIFICATIONDATE as ZMODIFICATIONDATE1, ZNOTE.ZTITLE as ZTITLE1, " +
"ZNOTEBODY.ZCONTENT as ZDATA, ZSTORE.Z_PK as ZFOLDER, ZSTORE.ZACCOUNT, " +
"0 as ZISPINNED " +
"FROM ZNOTE, ZNOTEBODY, ZSTORE " +
"WHERE ZNOTE.Z_PK=? AND ZNOTEBODY.Z_PK=ZNOTE.ZBODY AND ZSTORE.Z_PK=ZNOTE.ZSTORE"
folder_field = "ZFOLDER"
account_field = "ZACCOUNT"
note_id_field = "Z_PK"
end
# Uncomment these lines if we ever think there is weirdness with using the wrong fields for the right version
#@logger.debug("Rip Note: Query string is #{query_string}")
#@logger.debug("Rip Note: account field is #{account_field}")
#@logger.debug("Rip Note: folder field is #{folder_field}")
#@logger.debug("Rip Note: Note ID is #{note_id}")
# Execute the query
@database.execute(query_string, note_id) do |row|
# Create our note
tmp_account_id = row[account_field]
tmp_folder_id = row[folder_field]
@logger.debug("Rip Note: Looking up account for #{tmp_account_id}")
@logger.debug("Rip Note: Looking up folder for #{tmp_folder_id}")
tmp_account = get_account(tmp_account_id)
tmp_folder = get_folder(tmp_folder_id)
@logger.error("Rip Note: Somehow could not find account!") if !tmp_account
@logger.error("Rip Note: Somehow could not find folder!") if !tmp_folder
tmp_note = AppleNote.new(row["Z_PK"],
row[note_id_field],
row["ZTITLE1"],
row["ZDATA"],
row[creation_date_field],
row["ZMODIFICATIONDATE1"],
tmp_account,
tmp_folder)
# Set the note's version
tmp_note.version=(@version)
tmp_note.notestore=(self)
# Set the pinned status
if row["ZISPINNED"] == 1
tmp_note.is_pinned = true
end
# Set the UUID, if it exists
if row["ZIDENTIFIER"]
tmp_note.uuid = row["ZIDENTIFIER"]
end
# Set the widget snippet, if it exists
if row["ZWIDGETSNIPPET"]
tmp_note.widget_snippet = row["ZWIDGETSNIPPET"]
end
tmp_account.add_note(tmp_note) if tmp_account
tmp_folder.add_note(tmp_note) if tmp_folder
# Add server-side data, if relevant
if row[server_record_column]
tmp_note.add_cloudkit_server_record_data(row[server_record_column])
end
if(row[server_share_column])
tmp_note.add_cloudkit_sharing_data(row[server_share_column])
# Add any share participants to our overall list
tmp_note.share_participants.each do |participant|
@cloud_kit_participants[participant.record_id] = participant
end
end
# If this is protected, add the cryptographic variables
if row["ZISPASSWORDPROTECTED"] == 1
# Set values initially from the expected columns
crypto_iv = row["ZCRYPTOINITIALIZATIONVECTOR"]
crypto_tag = row["ZCRYPTOTAG"]
crypto_salt = row["ZCRYPTOSALT"]
crypto_iterations = row["ZCRYPTOITERATIONCOUNT"]
crypto_verifier = row["ZCRYPTOVERIFIER"]
crypto_wrapped_key = row["ZCRYPTOWRAPPEDKEY"]
# Try the initial set of credentials, this is cheap if they are
# missing, decrypt just returns false.
tmp_note.add_cryptographic_settings(crypto_iv,
crypto_tag,
crypto_salt,
crypto_iterations,
crypto_verifier,
crypto_wrapped_key)
# Try each password and see if any generate a decrypt.
found_password = tmp_note.decrypt
# If they aren't there, we need to use the ZUNAPPLIEDENCRYPTEDRECORD
if row[unapplied_encrypted_record_column] and !found_password
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_wrapped_key = ns_values[ns_keys.index("CryptoWrappedKey")]
tmp_note.add_cryptographic_settings(crypto_iv,
crypto_tag,
crypto_salt,
crypto_iterations,
crypto_verifier,
crypto_wrapped_key)
# Try each password and see if any generate a decrypt.
found_password = tmp_note.decrypt
end
if !found_password
@logger.debug("Apple Note Store: Note #{tmp_note.note_id} could not be decrypted with our passwords.")
end
end
# Only add the note if we have both a folder and account for it, otherwise things blow up
if tmp_account and tmp_folder
@notes[tmp_note.note_id] = tmp_note
tmp_note.process_note
else
@logger.error("Rip Note: Skipping note #{tmp_note.note_id} due to a missing account.") if !tmp_account
@logger.error("Rip Note: Skipping note #{tmp_note.note_id} due to a missing folder.") if !tmp_folder
if !tmp_account or !tmp_folder
@logger.error("Consider running these sqlite queries to take a look yourself, if ZDATA is NULL, that means you aren't missing anything: ")
@logger.error("\tSELECT Z_PK, #{account_field}, #{folder_field} FROM ZICCLOUDSYNCINGOBJECT WHERE Z_PK=#{tmp_note.primary_key}")
@logger.error("\tSELECT #{note_id_field}, ZDATA FROM ZICNOTEDATA WHERE #{note_id_field}=#{tmp_note.note_id}")
end
puts "Skipping Note ID #{tmp_note.note_id} due to a missing folder or account, check the debug log for more details."
end
end
end | #
This function takes a specific AppleNotesAccount potential
object in ZICCLOUDSYNCINGOBJECTS and ZICNOTEDATA, identified by Integer +account_id+,
and pulls the needed information to create the object. An AppleNote remembers the AppleNotesFolder
and AppleNotesAccount it is part of. If encryption information is present, it adds
it with AppleNotesAccount.add_crypto_variables. | rip_note | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def initialize()
original_filepath = nil # The filepath, as it was originally stored on the phone or Mac
original_filename = nil # The filename, as it was originally stored on the phone or Mac
storage_filepath = nil # The filepath of the file on disk in the backup
end | #
Creates a new AppleStoredFileResilt.
Requires nothing and initiailizes some variables | initialize | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def has_paths?
return (original_filepath and original_filename and storage_filepath)
end | #
Helper function that returns true only if this has
the paths needed for success | has_paths? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def exist?
return storage_filepath.exist?
end | #
Helper function that returns true only if the original filepath exists | exist? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def backup_location
return storage_filepath
end | #
To make it in line with legacy calls to variable names | backup_location | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def initialize(uti)
# Set this object's variables
@uti = uti
end | #
Creates a new AppleUniformTypeIdentifier.
Expects a String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI. | initialize | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def get_conforms_to_string
return "bad_uti" if bad_uti?
return "audio" if conforms_to_audio
return "document" if conforms_to_document
return "dynamic" if is_dynamic?
return "image" if conforms_to_image
return "inline" if conforms_to_inline_attachment
return "other public" if is_public?
return "video" if conforms_to_audiovisual
return "uti: #{@uti}"
end | #
This method returns a string indicating roughly how this UTI
should be treated. | get_conforms_to_string | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def bad_uti?
return false if @uti.is_a?(String)
return true
end | #
Checks for a UTI that shouldn't exist or won't behave nicely. | bad_uti? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def is_dynamic?
return false if bad_uti?
return @uti.start_with?("dyn.")
end | #
This method returns true if the UTI represented is dynamic. | is_dynamic? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def is_public?
return false if bad_uti?
return @uti.start_with?("public.")
end | #
This method returns true if the UTI represented is public. | is_public? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_audio
return false if bad_uti?
return true if @uti == "com.apple.m4a-audio"
return true if @uti == "com.microsoft.waveform-audio"
return true if @uti == "public.aiff-audio"
return true if @uti == "public.midi-audio"
return true if @uti == "public.mp3"
return true if @uti == "org.xiph.ogg-audio"
return false
end | #
This method returns true if the UTI conforms to public.audio | conforms_to_audio | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_audiovisual
return false if bad_uti?
return true if @uti == "com.apple.m4v-video"
return true if @uti == "com.apple.protected-mpeg-4-video"
return true if @uti == "com.apple.protected-mpeg-4-audio"
return true if @uti == "com.apple.quicktime-movie"
return true if @uti == "public.avi"
return true if @uti == "public.mpeg"
return true if @uti == "public.mpeg-2-video"
return true if @uti == "public.mpeg-2-transport-stream"
return true if @uti == "public.mpeg-4"
return true if @uti == "public.mpeg-4-audio"
return false
end | #
This method returns true if the UTI conforms to public.video
or public.movie. | conforms_to_audiovisual | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_document
return false if bad_uti?
return true if @uti == "com.apple.iwork.numbers.sffnumbers"
return true if @uti == "com.apple.log"
return true if @uti == "com.apple.rtfd"
return true if @uti == "com.microsoft.word.doc"
return true if @uti == "com.microsoft.excel.xls"
return true if @uti == "com.microsoft.powerpoint.ppt"
return true if @uti == "com.netscape.javascript-source"
return true if @uti == "net.openvpn.formats.ovpn"
return true if @uti == "org.idpf.epub-container"
return true if @uti == "org.oasis-open.opendocument.text"
return true if @uti == "org.openxmlformats.wordprocessingml.document"
return false
end | #
This method returns true if the UTI conforms to public.data objets that are likely documents | conforms_to_document | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_image
return false if bad_uti?
return true if @uti == "com.adobe.illustrator.ai-image"
return true if @uti == "com.adobe.photoshop-image"
return true if @uti == "com.adobe.raw-image"
return true if @uti == "com.apple.icns"
return true if @uti == "com.apple.macpaint-image"
return true if @uti == "com.apple.pict"
return true if @uti == "com.apple.quicktime-image"
return true if @uti == "com.apple.notes.sketch"
return true if @uti == "com.compuserve.gif"
return true if @uti == "com.ilm.openexr-image"
return true if @uti == "com.kodak.flashpix.image"
return true if @uti == "com.microsoft.bmp"
return true if @uti == "com.microsoft.ico"
return true if @uti == "com.sgi.sgi-image"
return true if @uti == "com.truevision.tga-image"
return true if @uti == "public.camera-raw-image"
return true if @uti == "public.fax"
return true if @uti == "public.heic"
return true if @uti == "public.jpeg"
return true if @uti == "public.jpeg-2000"
return true if @uti == "public.png"
return true if @uti == "public.svg-image"
return true if @uti == "public.tiff"
return true if @uti == "public.xbitmap-image"
return true if @uti == "org.webmproject.webp"
return false
end | #
This method returns true if the UTI conforms to public.image | conforms_to_image | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_inline_attachment
return false if bad_uti?
return true if @uti.start_with?("com.apple.notes.inlinetextattachment")
return false
end | #
This method returns true if the UTI represents Apple text enrichment. | conforms_to_inline_attachment | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def same_style_type?(other_attribute_run)
return false if !other_attribute_run
# We clearly aren't the same if one or the other lacks a style type completely
return false if (other_attribute_run.has_style_type and !has_style_type)
return false if (!other_attribute_run.has_style_type and has_style_type)
# If neither has a style type, that is the same
return true if (!other_attribute_run.has_style_type and !has_style_type)
# If the indent levels are different, then the styles are different.
return false if (other_attribute_run.paragraph_style.indent_amount != paragraph_style.indent_amount)
# If the block-quotedness are different, then the styles are different.
return false if (other_attribute_run.paragraph_style.block_quote != paragraph_style.block_quote)
# If both are checkboxes, but they belong to different checklist UUIDs,
# then the styles are different.
return false if (is_checkbox? && other_attribute_run.is_checkbox? && other_attribute_run.paragraph_style.checklist.uuid != paragraph_style.checklist.uuid)
# Compare our style_type to the other style_type and return the result
return (other_attribute_run.paragraph_style.style_type == paragraph_style.style_type)
end | #
This method compares the paragraph_style.style_type integer of two AttributeRun
objects to see if they have the same style_type. | same_style_type? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def same_font_weight?(other_attribute_run)
return false if !other_attribute_run
return (other_attribute_run.font_weight == font_weight)
end | #
Helper function to tell if a given AttributeRun has the same font weight as this one. | same_font_weight? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_checkbox?
return (has_style_type and paragraph_style.style_type == AppleNote::STYLE_TYPE_CHECKBOX)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_CHECKBOX. | is_checkbox? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_numbered_list?
return (has_style_type and paragraph_style.style_type == AppleNote::STYLE_TYPE_NUMBERED_LIST)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_NUMBERED_LIST. | is_numbered_list? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_dotted_list?
return (has_style_type and paragraph_style.style_type == AppleNote::STYLE_TYPE_DOTTED_LIST)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_DOTTED_LIST. | is_dotted_list? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_dashed_list?
return (has_style_type and paragraph_style.style_type == AppleNote::STYLE_TYPE_DASHED_LIST)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_DASHED_LIST. | is_dashed_list? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_block_quote?
return (has_style_type and paragraph_style.block_quote == AppleNote::STYLE_TYPE_BLOCK_QUOTE)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_BLOCK_QUOTE. | is_block_quote? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_any_list?
return (is_numbered_list? or is_dotted_list? or is_dashed_list? or is_checkbox?)
end | #
Helper function to tell if a given AttributeRun is any sort of AppleNote::STYLE_TYPE_X_LIST. | is_any_list? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def total_indent
return @indent if @indent
@indent = 0
# Determine what this AttributeRun's indent amount is on its own
my_indent = 0
if paragraph_style and paragraph_style.indent_amount
my_indent = paragraph_style.indent_amount
end
# If there is no previous AttributeRun, the answer is just this AttributeRun's indent amount
if !previous_run
@indent = my_indent
# If there is something previous, add our indent to its total indent
else
@indent = my_indent + previous_run.total_indent
end
return @indent
end | #
This method calculates the total indentation of a given AttributeRun. It caches the result since
it has to recursively check the previous AttributeRuns. | total_indent | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def generate_html(text_to_insert, root_node)
@active_html_node = root_node
@tag_is_open = !text_to_insert.end_with?("\n")
open_alignment_tag
open_block_tag
open_indent_tag
case @active_html_node.node_name
when "ol", "ul", "li"
add_list_text(text_to_insert)
else
add_html_text(text_to_insert)
end
return root_node
end | #
This method generates the HTML for a given AttributeRun. It expects a String as +text_to_insert+ | generate_html | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def initialize(context = {})
@context = Context.build(context)
end | Internal: Initialize an Interactor.
context - A Hash whose key/value pairs are used in initializing the
interactor's context. An existing Interactor::Context may also be
given. (default: {})
Examples
MyInteractor.new(foo: "bar")
# => #<MyInteractor @context=#<Interactor::Context foo="bar">>
MyInteractor.new
# => #<MyInteractor @context=#<Interactor::Context>> | initialize | ruby | collectiveidea/interactor | lib/interactor.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor.rb | MIT |
def run
run!
rescue Failure => e
if context.object_id != e.context.object_id
raise
end
end | Internal: Invoke an interactor instance along with all defined hooks. The
"run" method is used internally by the "call" class method. The following
are equivalent:
MyInteractor.call(foo: "bar")
# => #<Interactor::Context foo="bar">
interactor = MyInteractor.new(foo: "bar")
interactor.run
interactor.context
# => #<Interactor::Context foo="bar">
After successful invocation of the interactor, the instance is tracked
within the context. If the context is failed or any error is raised, the
context is rolled back.
Returns nothing. | run | ruby | collectiveidea/interactor | lib/interactor.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor.rb | MIT |
def run!
with_hooks do
call
context.called!(self)
end
rescue
context.rollback!
raise
end | Internal: Invoke an Interactor instance along with all defined hooks. The
"run!" method is used internally by the "call!" class method. The following
are equivalent:
MyInteractor.call!(foo: "bar")
# => #<Interactor::Context foo="bar">
interactor = MyInteractor.new(foo: "bar")
interactor.run!
interactor.context
# => #<Interactor::Context foo="bar">
After successful invocation of the interactor, the instance is tracked
within the context. If the context is failed or any error is raised, the
context is rolled back.
The "run!" method behaves identically to the "run" method with one notable
exception. If the context is failed during invocation of the interactor,
the Interactor::Failure is raised.
Returns nothing.
Raises Interactor::Failure if the context is failed. | run! | ruby | collectiveidea/interactor | lib/interactor.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor.rb | MIT |
def failure?
@failure || false
end | Public: Whether the Interactor::Context has failed. By default, a new
context is successful and only changes when explicitly failed.
The "failure?" method is the inverse of the "success?" method.
Examples
context = Interactor::Context.new
# => #<Interactor::Context>
context.failure?
# => false
context.fail!
# => Interactor::Failure: #<Interactor::Context>
context.failure?
# => true
Returns false by default or true if failed. | failure? | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def fail!(context = {})
context.each { |key, value| self[key.to_sym] = value }
@failure = true
raise Failure, self
end | Public: Fail the Interactor::Context. Failing a context raises an error
that may be rescued by the calling interactor. The context is also flagged
as having failed.
Optionally the caller may provide a hash of key/value pairs to be merged
into the context before failure.
context - A Hash whose key/value pairs are merged into the existing
Interactor::Context instance. (default: {})
Examples
context = Interactor::Context.new
# => #<Interactor::Context>
context.fail!
# => Interactor::Failure: #<Interactor::Context>
context.fail! rescue false
# => false
context.fail!(foo: "baz")
# => Interactor::Failure: #<Interactor::Context foo="baz">
Raises Interactor::Failure initialized with the Interactor::Context. | fail! | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def called!(interactor)
_called << interactor
end | Internal: Track that an Interactor has been called. The "called!" method
is used by the interactor being invoked with this context. After an
interactor is successfully called, the interactor instance is tracked in
the context for the purpose of potential future rollback.
interactor - An Interactor instance that has been successfully called.
Returns nothing. | called! | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def rollback!
return false if @rolled_back
_called.reverse_each(&:rollback)
@rolled_back = true
end | Public: Roll back the Interactor::Context. Any interactors to which this
context has been passed and which have been successfully called are asked
to roll themselves back by invoking their "rollback" instance methods.
Examples
context = MyInteractor.call(foo: "bar")
# => #<Interactor::Context foo="baz">
context.rollback!
# => true
context
# => #<Interactor::Context foo="bar">
Returns true if rolled back successfully or false if already rolled back. | rollback! | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def _called
@called ||= []
end | Internal: An Array of successfully called Interactor instances invoked
against this Interactor::Context instance.
Examples
context = Interactor::Context.new
# => #<Interactor::Context>
context._called
# => []
context = MyInteractor.call(foo: "bar")
# => #<Interactor::Context foo="baz">
context._called
# => [#<MyInteractor @context=#<Interactor::Context foo="baz">>]
Returns an Array of Interactor instances or an empty Array. | _called | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def deconstruct_keys(keys)
to_h.merge(
success: success?,
failure: failure?
)
end | Internal: Support for ruby 3.0 pattern matching
Examples
context = MyInteractor.call(foo: "bar")
# => #<Interactor::Context foo="bar">
context => { foo: }
foo == "bar"
# => true
case context
in success: true, result: { first:, second: }
do_stuff(first, second)
in failure: true, error_message:
log_error(message: error_message)
end
Returns the context as a hash, including success and failure | deconstruct_keys | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def initialize(context = nil)
@context = context
super
end | Internal: Initialize an Interactor::Failure.
context - An Interactor::Context to be stored within the
Interactor::Failure instance. (default: nil)
Examples
Interactor::Failure.new
# => #<Interactor::Failure: Interactor::Failure>
context = Interactor::Context.new(foo: "bar")
# => #<Interactor::Context foo="bar">
Interactor::Failure.new(context)
# => #<Interactor::Failure: #<Interactor::Context foo="bar">>
raise Interactor::Failure, context
# => Interactor::Failure: #<Interactor::Context foo="bar"> | initialize | ruby | collectiveidea/interactor | lib/interactor/error.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/error.rb | MIT |
def around(*hooks, &block)
hooks << block if block
hooks.each { |hook| around_hooks.push(hook) }
end | Public: Declare hooks to run around Interactor invocation. The around
method may be called multiple times; subsequent calls append declared
hooks to existing around hooks.
hooks - Zero or more Symbol method names representing instance methods
to be called around interactor invocation. Each instance method
invocation receives an argument representing the next link in
the around hook chain.
block - An optional block to be executed as a hook. If given, the block
is executed after methods corresponding to any given Symbols.
Examples
class MyInteractor
include Interactor
around :time_execution
around do |interactor|
puts "started"
interactor.call
puts "finished"
end
def call
puts "called"
end
private
def time_execution(interactor)
context.start_time = Time.now
interactor.call
context.finish_time = Time.now
end
end
Returns nothing. | around | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def before(*hooks, &block)
hooks << block if block
hooks.each { |hook| before_hooks.push(hook) }
end | Public: Declare hooks to run before Interactor invocation. The before
method may be called multiple times; subsequent calls append declared
hooks to existing before hooks.
hooks - Zero or more Symbol method names representing instance methods
to be called before interactor invocation.
block - An optional block to be executed as a hook. If given, the block
is executed after methods corresponding to any given Symbols.
Examples
class MyInteractor
include Interactor
before :set_start_time
before do
puts "started"
end
def call
puts "called"
end
private
def set_start_time
context.start_time = Time.now
end
end
Returns nothing. | before | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def after(*hooks, &block)
hooks << block if block
hooks.each { |hook| after_hooks.unshift(hook) }
end | Public: Declare hooks to run after Interactor invocation. The after
method may be called multiple times; subsequent calls prepend declared
hooks to existing after hooks.
hooks - Zero or more Symbol method names representing instance methods
to be called after interactor invocation.
block - An optional block to be executed as a hook. If given, the block
is executed before methods corresponding to any given Symbols.
Examples
class MyInteractor
include Interactor
after :set_finish_time
after do
puts "finished"
end
def call
puts "called"
end
private
def set_finish_time
context.finish_time = Time.now
end
end
Returns nothing. | after | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def around_hooks
@around_hooks ||= []
end | Internal: An Array of declared hooks to run around Interactor
invocation. The hooks appear in the order in which they will be run.
Examples
class MyInteractor
include Interactor
around :time_execution, :use_transaction
end
MyInteractor.around_hooks
# => [:time_execution, :use_transaction]
Returns an Array of Symbols and Procs. | around_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def before_hooks
@before_hooks ||= []
end | Internal: An Array of declared hooks to run before Interactor
invocation. The hooks appear in the order in which they will be run.
Examples
class MyInteractor
include Interactor
before :set_start_time, :say_hello
end
MyInteractor.before_hooks
# => [:set_start_time, :say_hello]
Returns an Array of Symbols and Procs. | before_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def after_hooks
@after_hooks ||= []
end | Internal: An Array of declared hooks to run before Interactor
invocation. The hooks appear in the order in which they will be run.
Examples
class MyInteractor
include Interactor
after :set_finish_time, :say_goodbye
end
MyInteractor.after_hooks
# => [:say_goodbye, :set_finish_time]
Returns an Array of Symbols and Procs. | after_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def with_hooks
run_around_hooks do
run_before_hooks
yield
run_after_hooks
end
end | Internal: Run around, before and after hooks around yielded execution. The
required block is surrounded with hooks and executed.
Examples
class MyProcessor
include Interactor::Hooks
def process_with_hooks
with_hooks do
process
end
end
def process
puts "processed!"
end
end
Returns nothing. | with_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def run_around_hooks(&block)
self.class.around_hooks.reverse.inject(block) { |chain, hook|
proc { run_hook(hook, chain) }
}.call
end | Internal: Run around hooks.
Returns nothing. | run_around_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def run_hooks(hooks)
hooks.each { |hook| run_hook(hook) }
end | Internal: Run a colection of hooks. The "run_hooks" method is the common
interface by which collections of either before or after hooks are run.
hooks - An Array of Symbol and Proc hooks.
Returns nothing. | run_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def run_hook(hook, *args)
hook.is_a?(Symbol) ? send(hook, *args) : instance_exec(*args, &hook)
end | Internal: Run an individual hook. The "run_hook" method is the common
interface by which an individual hook is run. If the given hook is a
symbol, the method is invoked whether public or private. If the hook is a
proc, the proc is evaluated in the context of the current instance.
hook - A Symbol or Proc hook.
args - Zero or more arguments to be passed as block arguments into the
given block or as arguments into the method described by the given
Symbol method name.
Returns nothing. | run_hook | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def organize(*interactors)
@organized = interactors.flatten
end | Public: Declare Interactors to be invoked as part of the
Interactor::Organizer's invocation. These interactors are invoked in
the order in which they are declared.
interactors - Zero or more (or an Array of) Interactor classes.
Examples
class MyFirstOrganizer
include Interactor::Organizer
organize InteractorOne, InteractorTwo
end
class MySecondOrganizer
include Interactor::Organizer
organize [InteractorThree, InteractorFour]
end
Returns nothing. | organize | ruby | collectiveidea/interactor | lib/interactor/organizer.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/organizer.rb | MIT |
def organized
@organized ||= []
end | Internal: An Array of declared Interactors to be invoked.
Examples
class MyOrganizer
include Interactor::Organizer
organize InteractorOne, InteractorTwo
end
MyOrganizer.organized
# => [InteractorOne, InteractorTwo]
Returns an Array of Interactor classes or an empty Array. | organized | ruby | collectiveidea/interactor | lib/interactor/organizer.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/organizer.rb | MIT |
def call
self.class.organized.each do |interactor|
interactor.call!(context)
end
end | Internal: Invoke the organized Interactors. An Interactor::Organizer is
expected not to define its own "#call" method in favor of this default
implementation.
Returns nothing. | call | ruby | collectiveidea/interactor | lib/interactor/organizer.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/organizer.rb | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.