get-voodoo 0.0.11 → 0.0.12

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: 965c3f91b6855d9b381e18ced1bfee172e5273d3180d50ef7a2892a66adbd30d
4
- data.tar.gz: e20ea428ba96e9c5f82ab31a5bab21761c189cd451d05b31bbc38ec0f857b56d
3
+ metadata.gz: 6906a5bfd817cfdb86c525ffc86677ef7185991a70d0c678df07e41ee2394a81
4
+ data.tar.gz: 8adb2abcc70fe837e0c5c92cfc306d61a4e14c844bdf50009f0765b458bcc479
5
5
  SHA512:
6
- metadata.gz: a8a34ddd9b063f44353195203f633f16e9fcdb872cbab1b52662b2e9582a9af5ba4ced78c708cafebd9408196a5dfd7034296b141acc11b13bdc9a05b27920b9
7
- data.tar.gz: 03c5e0884a62321e2053b93a3f8d606252bb127aded3748a997f33002d56070720e9a63a835ab96abbf2e70c1c99b8d0fb4550e11348c4ccd2cdc6921cfe4d2e
6
+ metadata.gz: 2021b65dc3154a76238cb3cb2015911cda5ddd3aff056814857670925d67ad471d0d8bf4ee4d812940a070819dbc35ac1899c654af82dedfbf4af8eb68727674
7
+ data.tar.gz: 2febeb01c329895e3313d309e32ce7db3b247f0ea092a4ed0502bfe0d7f97c5050041f62b42e4a7236871869e114e56d8458bdf9188201eb9eeb4582c4d64131
@@ -49,11 +49,15 @@ module VOODOO
49
49
  @extension.manifest[:permissions] += permissions
50
50
  end
51
51
 
52
- def hijack(urls = [], flags: '')
52
+ def close_browser
53
53
  # kill the browser process twise, to bypass close warning
54
54
  `pkill -a -i "#{@process_name}"`
55
55
  `pkill -a -i "#{@process_name}"`
56
56
  sleep 0.2
57
+ end
58
+
59
+ def hijack(urls = [], flags: '')
60
+ close_browser()
57
61
 
58
62
  urls = [urls] unless urls.kind_of? Array
59
63
  urls = urls.uniq
@@ -92,7 +96,7 @@ module VOODOO
92
96
  self.new(bundle: 'org.chromium.Chromium', process_name: 'Chromium')
93
97
  end
94
98
 
95
- def add_script(content: nil, file: nil, matches: nil, options: {}, background: false, max_events: nil)
99
+ def add_script(content: nil, file: nil, matches: nil, options: {}, background: false, max_events: nil, communication: true)
96
100
  if matches != nil && background != false
97
101
  puts 'WARNING: matches is ignored when background is set to true.'
98
102
  end
@@ -107,8 +111,8 @@ module VOODOO
107
111
 
108
112
  event_count = 0
109
113
 
110
- if block_given?
111
- collector = Collector.new
114
+ if block_given? && communication == true
115
+ collector = Collector.new(close_browser: method(:close_browser))
112
116
  collector.on_json {|jsond|
113
117
  yield jsond
114
118
  if (max_events != nil)
@@ -158,15 +162,6 @@ module VOODOO
158
162
  return @extension.add_content_script(matches, js: [content])
159
163
  end
160
164
  end
161
-
162
- protected
163
-
164
- def make_collector
165
- collector = Collector.new
166
- collector.on_json {|jsond| yield jsond }
167
- @collector_threads.push(collector.thread)
168
- return collector
169
- end
170
165
  end
171
166
 
172
167
  end
data/lib/voodoo/cli.rb CHANGED
@@ -6,7 +6,7 @@ require 'voodoo/browser'
6
6
 
7
7
  module VOODOO
8
8
 
9
- VERSION = 'v0.0.11'
9
+ VERSION = 'v0.0.12'
10
10
 
11
11
  class CLI < Thor
12
12
 
@@ -108,7 +108,7 @@ module VOODOO
108
108
  end
109
109
 
110
110
  browser_inst = template['browser'] || {}
111
- browser = get_browser(options[:browser] || browser_inst['name'] || 'chrome')
111
+ browser = get_browser(options[:browser] || browser_inst['name'] || browser_inst['default'] || 'chrome')
112
112
 
113
113
  if template['permissions']
114
114
  browser.add_permissions template['permissions']
@@ -128,9 +128,14 @@ module VOODOO
128
128
  content = script['content']
129
129
  matches = script['matches']
130
130
  background = script['background'] || false
131
-
131
+ communication = true
132
+
133
+ if script.keys.include? 'communication'
134
+ communication = script['communication']
135
+ end
136
+
132
137
  if output_handler.writable
133
- browser.add_script(max_events: options[:max_events], matches: matches, file: file, content: content, options: options[:params], background: background) do |event|
138
+ browser.add_script(max_events: options[:max_events], matches: matches, file: file, content: content, options: options[:params], background: background, communication: communication) do |event|
134
139
  output_handler.handle(event)
135
140
  end
136
141
  else
@@ -9,7 +9,9 @@ module VOODOO
9
9
  attr_reader :thread
10
10
  attr_reader :token
11
11
 
12
- def initialize(port = 0)
12
+ def initialize(port = 0, close_browser: nil)
13
+ @chunks = []
14
+ @close_browser = close_browser
13
15
  if port == 0
14
16
  tmp_server = TCPServer.open('127.0.0.1', 0)
15
17
  @port = tmp_server.addr[1]
@@ -50,6 +52,31 @@ module VOODOO
50
52
  socket.close
51
53
 
52
54
  jsonData = JSON.parse(post_body, {:symbolize_names => true})
55
+
56
+ if jsonData[:log]
57
+ puts jsonData[:log]
58
+ end
59
+
60
+ if jsonData[:chunk]
61
+ @chunks << jsonData[:payload][1]
62
+ if jsonData[:payload][0] == @chunks.length
63
+ payload = {
64
+ payload: @chunks.join('')
65
+ }
66
+ @chunks = []
67
+ yield payload
68
+ end
69
+ return
70
+ end
71
+
72
+ if jsonData[:kill] == true
73
+ if jsonData[:close_browser] && @close_browser != nil
74
+ @close_browser.call()
75
+ end
76
+ self.thread.kill
77
+ return
78
+ end
79
+
53
80
  yield jsonData
54
81
  rescue
55
82
  end
@@ -4,25 +4,64 @@ if (!sessionStorage.tab_uuid) {
4
4
 
5
5
  const VOODOO = {
6
6
  options: { collector_url: "%{collector_url}" },
7
- send(payload) {
8
- if (!VOODOO.options.collector_url) {
7
+ utils: {
8
+ sleep(ms) {
9
+ return new Promise(resolve => setTimeout(resolve, ms));
10
+ },
11
+ chunk_string(str, length) {
12
+ return str.match(new RegExp('.{1,' + length + '}', 'g'));
13
+ },
14
+ is_bg_script: window.location.href.indexOf("_generated_background_page.html") !== -1,
15
+ send(body) {
16
+ if (!VOODOO.options.collector_url) {
17
+ return;
18
+ }
19
+
20
+ body = JSON.stringify(body);
21
+
22
+ if (VOODOO.utils.is_bg_script) {
23
+ return navigator.sendBeacon(VOODOO.options.collector_url, body);
24
+ }
25
+
26
+ chrome.runtime.sendMessage({
27
+ collector_url: VOODOO.options.collector_url, body
28
+ });
29
+ }
30
+ },
31
+ log(msg) {
32
+ VOODOO.utils.send({ log: msg.toString() });
33
+ return VOODOO;
34
+ },
35
+ kill(options = {}) {
36
+ VOODOO.utils.send({ ...options, kill: true });
37
+ return VOODOO;
38
+ },
39
+ async send(payload) {
40
+ let chunks = [];
41
+
42
+ if (typeof payload === "string" && payload.length > 10000) {
43
+ chunks = VOODOO.utils.chunk_string(payload, 10000);
44
+ }
45
+
46
+ if (chunks.length > 0) {
47
+ for (let i in chunks) {
48
+ VOODOO.utils.send({
49
+ chunk: i,
50
+ payload: [chunks.length, chunks[i]]
51
+ });
52
+ await VOODOO.utils.sleep(1);
53
+ }
9
54
  return;
10
55
  }
11
56
 
12
- const body = JSON.stringify({
57
+ VOODOO.utils.send({
13
58
  time: new Date().getTime(),
14
59
  tab_uuid: sessionStorage.tab_uuid,
15
60
  origin: window.location.origin,
16
61
  payload
17
62
  });
18
63
 
19
- if (window.location.href.indexOf("_generated_background_page.html") !== -1) {
20
- return navigator.sendBeacon(VOODOO.options.collector_url, body);
21
- }
22
-
23
- chrome.runtime.sendMessage({
24
- collector_url: VOODOO.options.collector_url, body
25
- });
64
+ return VOODOO;
26
65
  }
27
66
  };
28
67
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get-voodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ron Masas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-14 00:00:00.000000000 Z
11
+ date: 2022-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor