imsg-grep 0.1.4-darwin → 0.1.6.pre-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e9003c398da31639dbfde03aaec593b2f165940563851b5e6941d4a55a3ac7d
4
- data.tar.gz: 98155da94f986fc1a3455f368d40c2b418d2e077980d9fbb536d375f1e3fffd4
3
+ metadata.gz: 40b1912c5695bdf6be658c8d149f5ff994b779116d3005e8e8efa53e8eb4f299
4
+ data.tar.gz: d01d37b5ec34c20eaaaaa013a3175ffd4eff37313379fdcda2b39944ca74f827
5
5
  SHA512:
6
- metadata.gz: 4992137950786e7a8e3040f50378a8d8b285d6894913ae7aa8ec6c7b539048bf11be519cd5db8f3cd10fd888438a2707d1ba2b77f2de5ed387c788b317c76a4e
7
- data.tar.gz: 319ef0da83aa8c21b8bc71f934744604def1b6b8e28b2ff361cdb34710e4d8a04787f9cc14a63fa1270fda60bc0f30adfbc96fef2fe2e489da5b8b3f0c64e5cf
6
+ metadata.gz: ba85f02f8e8b742387049b381a042caa136da0cea1f78b622ee1fa5916e81c6be0a6755173e880276a692fd8b1c8ab17975759067b16c713090baf120c9b9ea9
7
+ data.tar.gz: 23df2fbe2ea59d443f7346faeb66dc805724ef65aacf29a79c86d8612bba84d590f7b00af4d32ed51f0bfefd98f926f07014b1986ebb824eeab1abfa89045fb5
data/bin/imsg-grep CHANGED
@@ -2,7 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
  # Search and filter iMessage database entries with regex patterns, date ranges, and participant filters
4
4
 
5
- require "bundler/setup"
6
5
 
7
6
  require "date"
8
7
  require "json"
@@ -373,9 +372,13 @@ begin
373
372
 
374
373
  begin
375
374
  Messages.init_fs
376
- rescue Errno::EPERM, Errno::EACCES
377
- $stderr.print "You must grant #{ENV['TERM_PROGRAM']} Full Disk Access so #{PROG} can access the chat database. Open System Settings pane? [y/N] "
378
- $stdin.gets.to_s.strip.downcase == "y" and system 'open "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"'
375
+ rescue Errno::EPERM, Errno::EACCES => e
376
+ if $stdout.tty? && $stdin.tty?
377
+ $stderr.print "You must grant #{ENV['TERM_PROGRAM']} Full Disk Access so #{PROG} can access the chat database. Open System Settings pane? [y/N] "
378
+ $stdin.gets.to_s.strip.downcase == ?y and system 'open "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"'
379
+ else
380
+ err! "full disk access required (#{e.message})"
381
+ end
379
382
  exit 1
380
383
  rescue => e
381
384
  err! e.message
@@ -578,7 +581,9 @@ begin
578
581
  @link_images[link] = Concurrent::Promises.future_on(POOL, msg) do |msg|
579
582
  ix = link[:image_idx] or next
580
583
  file = msg.dig(:files, ix) or next
581
- path = File.expand_path file[:filename]
584
+ path = file[:filename] or next
585
+ path = File.expand_path path
586
+ File.exist?(path) or next
582
587
  img = Imaginator::Image.new(path).load or next
583
588
  fit, fits = img.fit @link_preview_cols, @link_preview_min_rows
584
589
  png = img.png_transform w:fit.w, h:fit.h, pad_w:fits[:cfit].pad_w
@@ -592,7 +597,9 @@ begin
592
597
  msg[:images] = msg[:files].select{ it[:mime_type]&.start_with?('image/') }
593
598
  preview?(:images) and msg[:images].each do |im|
594
599
  @images[im] = Concurrent::Promises.future_on(POOL, im) do |im|
595
- path = File.expand_path im[:filename]
600
+ path = im[:filename] or next
601
+ path = File.expand_path path
602
+ File.exist?(path) or next
596
603
  img = Imaginator::Image.new(path).load or next
597
604
  fit, = img.fit 25, @img_rows
598
605
  png = img.png_transform w:fit.w, h:fit.h
@@ -694,7 +701,7 @@ begin
694
701
  if img_rows != @link_preview_min_rows
695
702
  img = Imaginator::Image.new(img).load if img.is_a? String # it's a path, original img released
696
703
  fit1, fits = img.fit @link_preview_cols, img_rows
697
- # if the backround render image is different from what we need now that we know the text size, do it again
704
+ # if the promise-rendered image is different from what we need now that we know the text size, do it again
698
705
  if fit1 != fit
699
706
  fit = fit1
700
707
  png = img.png_transform w:fit.w, h:fit.h, pad_w:fits[:cfit].pad_w
@@ -704,7 +711,7 @@ begin
704
711
  print " "
705
712
  Imaginator.print_image(data: png, c: @link_preview_cols)
706
713
  puts
707
- print "\e[#{fit.r}A" # go up by image rows
714
+ print "\e[#{fit.r}A" # go up by image rows to print padded buf next to it
708
715
  end
709
716
 
710
717
  print buf
@@ -712,7 +719,7 @@ begin
712
719
 
713
720
  if @list_files
714
721
  for file in files.reject{ it[:mime_type].nil? }
715
- path, _, name = file[:filename].rpartition %r_(?<=/)_
722
+ path, _, name = file[:filename].to_s.rpartition %r_(?<=/)_
716
723
  p, q, r = path.rpartition %r_/\KTemporaryItems(?=/)_
717
724
  path = c.file_path(p) + c.file_path_bad(q) + c.file_path(r)
718
725
  puts " " + path + c.file_name(name) + ?\n
data/bin/msg-info CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Display detailed information about a specific message by ID from the iMessage database
3
3
 
4
- require "bundler/setup"
5
-
6
4
  require_relative '../lib/imsg-grep/dev/print_query'
7
5
  require_relative '../lib/imsg-grep/messages'
8
6
 
data/bin/sql-shell CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Interactive SQL shell for querying the iMessage database with readline history
3
3
 
4
- require "bundler/setup"
5
-
6
4
  require_relative '../lib/imsg-grep/messages'
7
5
  require_relative '../lib/imsg-grep/dev/print_query'
8
6
  require 'readline'
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.6.pre
@@ -1,20 +1,22 @@
1
- require "ffi"
1
+ require "fiddle"
2
+ require "fiddle/import"
2
3
 
3
4
  module Img2png
4
- extend FFI::Library
5
- ffi_lib "#{__dir__}/img2png.dylib"
5
+ extend Fiddle::Importer
6
6
 
7
- attach_function :img2png_load_path, [:string, :pointer, :pointer], :pointer, blocking: true
8
- attach_function :img2png_load, [:pointer, :int, :pointer, :pointer], :pointer, blocking: true
9
- attach_function :img2png_convert, [:pointer, :int, :int, :int, :int, :pointer, :pointer], :bool, blocking: true
10
- attach_function :img2png_release, [:pointer], :void
11
- attach_function :img2png_free, [:pointer], :void
7
+ dlload "#{__dir__}/img2png.dylib"
8
+
9
+ extern "void* img2png_load_path(char*, int*, int*)"
10
+ extern "void* img2png_load(void*, int, int*, int*)"
11
+ extern "int img2png_convert(void*, int, int, int, int, void**, int*)"
12
+ extern "void img2png_release(void*)"
13
+ extern "void img2png_free(void*)"
12
14
 
13
15
  class Image
14
- def initialize(path:nil, data:nil)
16
+ def initialize(path: nil, data: nil)
15
17
  [path, data].compact.size == 1 or raise ArgumentError, "One of path: or data: must be specified"
16
- out_w = FFI::MemoryPointer.new(:int)
17
- out_h = FFI::MemoryPointer.new(:int)
18
+ out_w = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
19
+ out_h = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
18
20
 
19
21
  @handle = case
20
22
  when data then Img2png.img2png_load(data, data.bytesize, out_w, out_h)
@@ -22,15 +24,15 @@ module Img2png
22
24
  end
23
25
  raise "Failed to load image" if @handle.null?
24
26
 
25
- @width = out_w.read_int
26
- @height = out_h.read_int
27
+ @width = out_w[0, Fiddle::SIZEOF_INT].unpack1("i")
28
+ @height = out_h[0, Fiddle::SIZEOF_INT].unpack1("i")
27
29
  end
28
30
 
29
31
  def dimensions = [@width, @height]
30
32
 
31
33
  def convert(fit_w: nil, fit_h: nil, box_w: nil, box_h: nil)
32
- out_data = FFI::MemoryPointer.new(:pointer)
33
- out_len = FFI::MemoryPointer.new(:int)
34
+ out_data = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
35
+ out_len = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
34
36
 
35
37
  success = Img2png.img2png_convert(
36
38
  @handle,
@@ -39,18 +41,18 @@ module Img2png
39
41
  out_data, out_len
40
42
  )
41
43
 
42
- return nil unless success
44
+ return nil if success == 0
43
45
 
44
- ptr = out_data.read_pointer
45
- len = out_len.read_int
46
- result = ptr.read_bytes(len)
46
+ ptr = Fiddle::Pointer.new(out_data[0, Fiddle::SIZEOF_VOIDP].unpack1("J"))
47
+ len = out_len[0, Fiddle::SIZEOF_INT].unpack1("i")
48
+ result = ptr[0, len]
47
49
  Img2png.img2png_free(ptr)
48
50
  result
49
51
  end
50
52
 
51
53
  def release
52
54
  Img2png.img2png_release(@handle) unless @handle.null?
53
- @handle = FFI::Pointer::NULL
55
+ @handle = Fiddle::NULL
54
56
  end
55
57
 
56
58
  def self.finalize(handle)
@@ -63,7 +65,7 @@ end
63
65
  # input = File.binread("x.heic")
64
66
 
65
67
  # # Load once, use multiple times
66
- # img = Img2png::Image.new(input)
68
+ # img = Img2png::Image.new(data: input)
67
69
 
68
70
  # # Get dimensions
69
71
  # p img.dimensions # => [4032, 3024]
@@ -189,7 +189,7 @@ module Messages
189
189
  summary = rich_link&.dig "summary"
190
190
  image = rich_link&.dig "imageMetadata", "URL"
191
191
  image_idx = rich_link&.dig "image", "richLinkImageAttachmentSubstituteIndex"
192
- ci_idx = rich_link&.dig("contentImages")&.at(0)&.dig("richLinkImageAttachmentSubstituteIndex")
192
+ ci_idx = rich_link&.dig "contentImages", 0, "richLinkImageAttachmentSubstituteIndex"
193
193
  image_idx = ci_idx if ci_idx
194
194
  url = rich_url || orig_url || found_url
195
195
  # i'm not sure the mapping richLinkImageAttachmentSubstituteIndex to
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imsg-grep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6.pre
5
5
  platform: darwin
6
6
  authors:
7
7
  - Caio Chassot
@@ -10,19 +10,61 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: ffi
13
+ name: base64
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '1.17'
18
+ version: '0.3'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '1.17'
25
+ version: '0.3'
26
+ - !ruby/object:Gem::Dependency
27
+ name: fiddle
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 1.1.8
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 1.1.8
40
+ - !ruby/object:Gem::Dependency
41
+ name: io-console
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.8'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.8'
54
+ - !ruby/object:Gem::Dependency
55
+ name: json
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.17'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.17'
26
68
  - !ruby/object:Gem::Dependency
27
69
  name: sqlite3
28
70
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +121,20 @@ dependencies:
79
121
  - - "~>"
80
122
  - !ruby/object:Gem::Version
81
123
  version: '1.3'
124
+ - !ruby/object:Gem::Dependency
125
+ name: debug
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.11'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '1.11'
82
138
  - !ruby/object:Gem::Dependency
83
139
  name: minitest
84
140
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +173,6 @@ extra_rdoc_files: []
117
173
  files:
118
174
  - LICENSE
119
175
  - README.md
120
- - bin/img2png
121
176
  - bin/imsg-grep
122
177
  - bin/msg-info
123
178
  - bin/sql-shell
data/bin/img2png DELETED
Binary file