swf_ruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -51,8 +51,8 @@ Replacing Jpeg in SWF
51
51
  $ swf_jpeg_replace samples/sample.swf 623 samples/bg.jpg > samples/sample2.swf
52
52
  # <623> is offset to DefineBitsJPEG2 resource getting by 'swf_dump'.
53
53
 
54
- Replacing Jpeg in SWF
55
- ---------------------
54
+ Replacing GIF/PNG in SWF
55
+ ------------------------
56
56
 
57
57
  $ swf_lossless_replace samples/sample.swf 120 samples/icon.gif > samples/sample3.swf
58
58
  # <120> is offset to DefineBitsLossless2 resource getting by 'swf_dump'.
data/bin/swf_dump CHANGED
@@ -4,7 +4,11 @@
4
4
 
5
5
  require 'swf_ruby'
6
6
 
7
- print "Specify swf file path to dump for argument." if ARGV.size != 1
7
+ if ARGV.size != 1
8
+ print "Specify swf file path to dump for argument.\n"
9
+ exit
10
+ end
11
+
8
12
  swf = SwfRuby::SwfDumper.new
9
13
  swf.open(ARGV[0])
10
14
  swf.tags.each_with_index do |tag, i|
data/bin/swf_jpeg_replace CHANGED
@@ -3,7 +3,10 @@
3
3
  # SWF中のJpeg(DefineBitsJpeg2)イメージを差し替える.
4
4
  require 'swf_ruby'
5
5
 
6
- print "Specify target swf path, offset to jpeg, new jpeg path for arguments." if ARGV.size != 3
6
+ if ARGV.size != 3
7
+ print "Specify target swf path, offset to jpeg, new jpeg path for arguments.\n"
8
+ exit
9
+ end
7
10
 
8
11
  swf = File.open(ARGV[0], "rb").read
9
12
  st = SwfRuby::SwfTamperer.new
@@ -3,7 +3,10 @@
3
3
  # SWF中のLossless(DefineBitsLossless2)イメージを差し替える.
4
4
  require 'swf_ruby'
5
5
 
6
- print "Specify target swf path, offset to image, new image(png,gif) path for arguments." if ARGV.size != 3
6
+ if ARGV.size != 3
7
+ print "Specify target swf path, offset to image, new image(png,gif) path for arguments.\n"
8
+ exit
9
+ end
7
10
 
8
11
  swf = File.open(ARGV[0], "rb").read
9
12
  st = SwfRuby::SwfTamperer.new
@@ -18,20 +18,20 @@ module SwfRuby
18
18
  image.get_pixels(0, 0, image.columns, image.rows).each_with_index do |pixel,i|
19
19
  break if colormap.length > 255
20
20
  idx = colormap.index(pixel)
21
- if idx then
21
+ if idx
22
22
  data << [idx].pack("C")
23
23
  else
24
24
  colormap << pixel
25
25
  data << [colormap.length-1].pack("C")
26
26
  end
27
- if (i+1) % image.rows == 0 then
27
+ if (i+1) % image.columns == 0
28
28
  # padding
29
29
  data += [0].pack("C") * (4-image.columns&3)
30
30
  end
31
31
  end
32
32
 
33
33
  # checking image format by size of colormap
34
- if colormap.length > 255 then
34
+ if colormap.length > 255
35
35
  # format=5
36
36
  # reset and re-build data_stream without colopmap
37
37
  data = ""
@@ -48,7 +48,7 @@ module SwfRuby
48
48
  # added colormap before data_stream
49
49
  data = colormap.inject("") { |r,c|
50
50
  opacity = (MaxRGB-c.opacity) >> ShiftDepth
51
- if opacity == 0 then
51
+ if opacity == 0
52
52
  r +=
53
53
  [0].pack("C") +
54
54
  [0].pack("C") +
@@ -92,26 +92,53 @@ module SwfRuby
92
92
  def repl_lossless2(swf, offset, lossless)
93
93
  swf.force_encoding("ASCII-8BIT") if swf.respond_to? :force_encoding
94
94
 
95
+ org_format = swf[offset+8, 1].unpack("C").first
95
96
  # replace lossless2 data
96
97
  if lossless.format == 3
97
- org_image_length = swf[offset+2, 4].unpack("i").first - 8
98
- swf[offset+14, org_image_length] = lossless.zlib_bitmap_data
99
- swf[offset+13, 1] = [lossless.color_table_size].pack("C")
100
- swf[offset+11, 2] = [lossless.width].pack("v")
101
- swf[offset+9, 2] = [lossless.height].pack("v")
102
- swf[offset+8, 1] = [lossless.format].pack("C")
103
- swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 8].pack("i")
98
+ if org_format == 3
99
+ org_image_length = swf[offset+2, 4].unpack("i").first - 8
100
+ delta_length = lossless.zlib_bitmap_data.size - org_image_length
101
+ swf[offset+14, org_image_length] = lossless.zlib_bitmap_data
102
+ swf[offset+13, 1] = [lossless.color_table_size].pack("C")
103
+ swf[offset+11, 2] = [lossless.height].pack("v")
104
+ swf[offset+9, 2] = [lossless.width].pack("v")
105
+ swf[offset+8, 1] = [lossless.format].pack("C")
106
+ swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 8].pack("i")
107
+ elsif org_format == 5
108
+ org_image_length = swf[offset+2, 4].unpack("i").first - 7
109
+ delta_length = lossless.zlib_bitmap_data.size - org_image_length + 1
110
+ swf[offset+13, org_image_length] = [lossless.color_table_size].pack("C") + lossless.zlib_bitmap_data
111
+ swf[offset+11, 2] = [lossless.height].pack("v")
112
+ swf[offset+9, 2] = [lossless.width].pack("v")
113
+ swf[offset+8, 1] = [lossless.format].pack("C")
114
+ swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 8].pack("i")
115
+ else
116
+ raise ReplaceTargetError
117
+ end
104
118
  elsif format == 5
105
- org_image_length = swf[offset+2, 4].unpack("i").first - 7
106
- swf[offset+13, org_image_length] = lossless.zlib_bitmap_data
107
- swf[offset+11, 2] = [lossless.width].pack("v")
108
- swf[offset+9, 2] = [lossless.height].pack("v")
109
- swf[offset+8, 1] = [lossless.format].pack("C")
110
- swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 7].pack("i")
119
+ if org_format == 3
120
+ org_image_length = swf[offset+2, 4].unpack("i").first - 8
121
+ delta_length = lossless.zlib_bitmap_data.size - org_image_length - 1
122
+ swf[offset+13, org_image_length+1] = lossless.zlib_bitmap_data
123
+ swf[offset+11, 2] = [lossless.height].pack("v")
124
+ swf[offset+9, 2] = [lossless.width].pack("v")
125
+ swf[offset+8, 1] = [lossless.format].pack("C")
126
+ swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 7].pack("i")
127
+ elsif org_format == 5
128
+ org_image_length = swf[offset+2, 4].unpack("i").first - 7
129
+ delta_length = lossless.zlib_bitmap_data.size - org_image_length
130
+ swf[offset+13, org_image_length] = lossless.zlib_bitmap_data
131
+ swf[offset+11, 2] = [lossless.height].pack("v")
132
+ swf[offset+9, 2] = [lossless.width].pack("v")
133
+ swf[offset+8, 1] = [lossless.format].pack("C")
134
+ swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 7].pack("i")
135
+ else
136
+ raise ReplaceTargetError
137
+ end
111
138
  else
112
139
  raise ReplaceTargetError
113
140
  end
114
-
141
+ swf[4, 4] = [swf[4, 4].unpack("V").first + delta_length].pack("V")
115
142
  swf
116
143
  end
117
144
  end
@@ -1,3 +1,3 @@
1
1
  module SwfRuby
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors: []
12
12