Ruby method to process NSMutableAttributedString blob values from iMessage chat.db.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parse attributedBody blob values into ASCII text. | |
# Grab HEX(attributedBody) from chat.db and unfark it | |
def unfark_imessage_attributed_body(hex_string) | |
wtf_string = [hex_string].pack("H*").encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: ' ') | |
wtf_string.gsub!(/\s+/, ' ') | |
if wtf_string.include? 'NSNumber' | |
wtf_string = wtf_string.split('NSNumber')[0] | |
if wtf_string.include? 'NSString' | |
wtf_string = wtf_string.split('NSString')[1] | |
if wtf_string.include? 'NSDictionary' | |
wtf_string = wtf_string.split('NSDictionary')[0] | |
# highly suspect and brittle code to clean up the last bit of blob flotsam | |
if wtf_string.include? "\u0001+ \u0000" | |
wtf_string = wtf_string.split("\u0001+ \u0000")[1] | |
end | |
if wtf_string.include? "\u0001 \u0001+" | |
wtf_string = wtf_string.split("\u0001 \u0001")[1][2..] | |
end | |
if wtf_string.include? "\u0002iI\u0001" | |
wtf_string = wtf_string.split("\u0002iI\u0001")[0] | |
end | |
end | |
end | |
end | |
return wtf_string | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment