jeanny 0.8 → 0.85

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.
data/README CHANGED
@@ -3,6 +3,23 @@ Jeanny GEM
3
3
 
4
4
  Usage:
5
5
 
6
+ #!/usr/bin/env ruby
7
+
8
+ require 'rubygems'
6
9
  require 'jeanny'
7
-
8
- # blah blah blah
10
+
11
+ include Jeanny::Sugar
12
+
13
+ analyze('serp/css/_*.css', :compare_with => 'classes.saved') and save
14
+
15
+ group :css, :title => 'replacing in stylesheets' do
16
+ replace :include => ['serp/css/_*.css', 'serp/block/*/*.css']
17
+ end
18
+
19
+ group :js, :title => 'replacing in scripts' do
20
+ replace :in => 'serp/js/_serp.js'
21
+ end
22
+
23
+ group :html, :title => 'replacing in template files' do
24
+ replace :in => 'serp/static/*.html'
25
+ end
@@ -1,7 +1,7 @@
1
1
 
2
2
  #
3
3
  # jeanny.rb
4
- # jeanny
4
+ # Obfuscation for web applications
5
5
  #
6
6
  # Created by seriously drunken on 2009-09-16.
7
7
  # Copyright 2009 Yandex. All rights reserved.
@@ -11,7 +11,7 @@ $:.unshift File.dirname(__FILE__) unless $:.include? File.dirname(__FILE__)
11
11
 
12
12
  module Jeanny
13
13
 
14
- JEANNY_VERSION = '0.8'
14
+ JEANNY_VERSION = '0.85'
15
15
 
16
16
  end
17
17
 
@@ -1,5 +1,7 @@
1
1
 
2
2
  module Jeanny
3
+
4
+ require 'strscan'
3
5
 
4
6
  # Класс который выполнят всю основную работу.
5
7
  # Парсит и заменяет классы, сохраняет и сравнивает их.
@@ -209,25 +211,110 @@ module Jeanny
209
211
  class JSCode < Code
210
212
 
211
213
  def replace classes
212
-
213
- # Находим все строки и регулярные выражения
214
- @code.gsub(/(("|'|\/)((\\\2|.)*?)\2)/m) do |string|
215
214
 
216
- string_before, string_after = $3, $3
215
+ data = []
216
+ each_string do |value, quote|
217
+
218
+ next unless value.length > 4
219
+
220
+ value_after = value.dup
221
+ classes.each do |full_class, short_class|
222
+ while (pos = value_after =~ /#{full_class}(?=[^a-z0-9\-_]|$)/)
223
+ value_after[pos, full_class.length] = short_class
224
+ end
225
+ end
217
226
 
218
- # Проходимся по всем классам
219
- classes.each do |full_name, short_name|
227
+ next if value.eql? value_after
220
228
 
221
- # И заменяем старый класс, на новый
222
- string_after = string_after.gsub(full_name, short_name)
223
- end
224
229
 
225
- string.gsub(string_before, string_after.gsub(/(\\+)("|')/, "\\1\\1\\2"))
230
+ data << [value, value_after]
226
231
 
227
232
  end
228
233
 
234
+ data.sort_by { |x| x[0].length }.reverse.each do |x|
235
+ while (pos = @code =~ /#{Regexp::escape(x[0])}(?=[^a-z0-9\-_]|$)/)
236
+ @code[pos, x[0].length] = x[1]
237
+ end
238
+ end
239
+
240
+ @code
241
+
242
+ end
243
+
244
+ def each_string
245
+
246
+ @status = :in_code
247
+
248
+ @char, @last_char, @start_char, @value = '', '', '', ''
249
+
250
+ scanner = StringScanner.new @code.dup
251
+
252
+ until scanner.eos?
253
+
254
+ scanner.getch or next
255
+ @char = scanner.matched
256
+
257
+ case @status
258
+
259
+
260
+ when :in_code
261
+ # Если мы в коде, а текущий символ один из тех что нам надо
262
+ # значит запоминаем, этот символ и переходим в режим "в строке"
263
+ if %w(" ').include? @char
264
+ @start_char = @char
265
+ @status = :in_string
266
+ end
267
+
268
+ # Если мы в коде, текущий символ слеш, а следующий не звездочка,
269
+ # значит мы в регулярном выражении
270
+ if @char.eql? '/' and @last_char =~ /=|\(|:/ and not %w(* /).include? scanner.post_match[0, 1]
271
+ @start_char = @char
272
+ @status = :in_regexp
273
+ end
274
+
275
+ # Если мы в коде, текущий символ звездочка, а предыдущий — слеш,
276
+ # значит это начала комментария. Перехоим в режим "в комментарии"
277
+ @status = :in_full_comment if @char.eql? '*' and @last_char.eql? '/'
278
+
279
+ @status = :in_line_comment if @char.eql? '/' and @last_char.eql? '/'
280
+
281
+ when :in_string, :in_regexp
282
+ # Если мы в строке (или регулярке), текущий символ такой же как и начальный,
283
+ # а предыдущий не экранирует его, значит строка законченна.
284
+ # Переходим в режим "в коде"
285
+ # if @char.eql? @start_char and scanner.pre_match !~ /[^\\]\\$/
286
+ if @char.eql? @start_char and not @last_char.eql? '\\'
287
+ if block_given?
288
+ # yield "#{@start_char}#{@value}#{@start_char}", @value
289
+ # yield @value
290
+ yield @value, @start_char
291
+ end
292
+
293
+ @status, @start_char, @value = :in_code, '', ''
294
+ # Иначе, прибавляем текущий символ к уже полученной строке
295
+ else
296
+ @value = @value + @char
297
+ end
298
+
299
+ when :in_full_comment
300
+ # Если мы в комментарии, текущий символ слеш, а предыдущий
301
+ # звездочка, значит комментарий закончился, переходим в режим "в коде"
302
+ @status = :in_code if @char.eql? '/' and @last_char.eql? '*'
303
+
304
+ when :in_line_comment
305
+ @status = :in_code if @char.eql? "\n"
306
+
307
+ end
308
+
309
+ @last_char = @char unless @char.nil? or @char =~ /\s/
310
+
311
+ end
229
312
  end
230
313
 
314
+ private
315
+
316
+ attr_accessor :status, :char, :last_char, :start_char, :value
317
+
231
318
  end
232
319
 
233
320
  class CSSCode < Code
@@ -174,6 +174,5 @@ end
174
174
  module Jeanny
175
175
 
176
176
  %w(FileNotFound CompareFileFormatError ClassesNotFound).each { |error| eval "class Jeanny#{error} < RuntimeError; end" }
177
- # %w(CompareFileNotFound SaveError).each { |error| eval "class Jeanny#{error} < SystemCallError; end" }
178
177
 
179
178
  end
@@ -151,19 +151,20 @@ module Jeanny
151
151
  break if exclude
152
152
  end
153
153
 
154
- # next if exclude
155
154
  if exclude
156
155
  puts file.yellow
157
156
  next
158
157
  end
159
158
 
160
159
  begin
160
+
161
+ puts file.green
162
+
161
163
  data = File.open_file file
162
164
  data = @engine.replace data, type
163
-
165
+
164
166
  File.save_file file, data
165
167
 
166
- puts file.green
167
168
  rescue Exception => e
168
169
  puts e.message + "\n#{$@}"
169
170
  exit 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeanny
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.8"
4
+ version: "0.85"
5
5
  platform: ruby
6
6
  authors:
7
7
  - gfranco
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-28 00:00:00 +03:00
12
+ date: 2009-09-30 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15