swf_ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/.gitignore +2 -0
- data/COPYING +340 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +15 -0
- data/README.md +52 -0
- data/Rakefile +2 -0
- data/bin/swf_dump +49 -0
- data/bin/swf_jpeg_replace +15 -0
- data/lib/swf_ruby/do_action_dumper.rb +39 -0
- data/lib/swf_ruby/replace_target.rb +29 -0
- data/lib/swf_ruby/sprite_dumper.rb +37 -0
- data/lib/swf_ruby/swf/action_push.rb +35 -0
- data/lib/swf_ruby/swf/action_record.rb +131 -0
- data/lib/swf_ruby/swf/header.rb +39 -0
- data/lib/swf_ruby/swf/rectangle.rb +24 -0
- data/lib/swf_ruby/swf/tag.rb +113 -0
- data/lib/swf_ruby/swf.rb +1 -0
- data/lib/swf_ruby/swf_dumper.rb +44 -0
- data/lib/swf_ruby/swf_tamperer.rb +93 -0
- data/lib/swf_ruby/version.rb +3 -0
- data/lib/swf_ruby.rb +1 -0
- data/samples/bg.jpg +0 -0
- data/samples/sample.swf +0 -0
- data/swf_ruby.gemspec +25 -0
- metadata +108 -0
data/.bundle/config
ADDED
data/.gitignore
ADDED
data/COPYING
ADDED
@@ -0,0 +1,340 @@
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
2
|
+
Version 2, June 1991
|
3
|
+
|
4
|
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
5
|
+
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies
|
7
|
+
of this license document, but changing it is not allowed.
|
8
|
+
|
9
|
+
Preamble
|
10
|
+
|
11
|
+
The licenses for most software are designed to take away your
|
12
|
+
freedom to share and change it. By contrast, the GNU General Public
|
13
|
+
License is intended to guarantee your freedom to share and change free
|
14
|
+
software--to make sure the software is free for all its users. This
|
15
|
+
General Public License applies to most of the Free Software
|
16
|
+
Foundation's software and to any other program whose authors commit to
|
17
|
+
using it. (Some other Free Software Foundation software is covered by
|
18
|
+
the GNU Library General Public License instead.) You can apply it to
|
19
|
+
your programs, too.
|
20
|
+
|
21
|
+
When we speak of free software, we are referring to freedom, not
|
22
|
+
price. Our General Public Licenses are designed to make sure that you
|
23
|
+
have the freedom to distribute copies of free software (and charge for
|
24
|
+
this service if you wish), that you receive source code or can get it
|
25
|
+
if you want it, that you can change the software or use pieces of it
|
26
|
+
in new free programs; and that you know you can do these things.
|
27
|
+
|
28
|
+
To protect your rights, we need to make restrictions that forbid
|
29
|
+
anyone to deny you these rights or to ask you to surrender the rights.
|
30
|
+
These restrictions translate to certain responsibilities for you if you
|
31
|
+
distribute copies of the software, or if you modify it.
|
32
|
+
|
33
|
+
For example, if you distribute copies of such a program, whether
|
34
|
+
gratis or for a fee, you must give the recipients all the rights that
|
35
|
+
you have. You must make sure that they, too, receive or can get the
|
36
|
+
source code. And you must show them these terms so they know their
|
37
|
+
rights.
|
38
|
+
|
39
|
+
We protect your rights with two steps: (1) copyright the software, and
|
40
|
+
(2) offer you this license which gives you legal permission to copy,
|
41
|
+
distribute and/or modify the software.
|
42
|
+
|
43
|
+
Also, for each author's protection and ours, we want to make certain
|
44
|
+
that everyone understands that there is no warranty for this free
|
45
|
+
software. If the software is modified by someone else and passed on, we
|
46
|
+
want its recipients to know that what they have is not the original, so
|
47
|
+
that any problems introduced by others will not reflect on the original
|
48
|
+
authors' reputations.
|
49
|
+
|
50
|
+
Finally, any free program is threatened constantly by software
|
51
|
+
patents. We wish to avoid the danger that redistributors of a free
|
52
|
+
program will individually obtain patent licenses, in effect making the
|
53
|
+
program proprietary. To prevent this, we have made it clear that any
|
54
|
+
patent must be licensed for everyone's free use or not licensed at all.
|
55
|
+
|
56
|
+
The precise terms and conditions for copying, distribution and
|
57
|
+
modification follow.
|
58
|
+
|
59
|
+
GNU GENERAL PUBLIC LICENSE
|
60
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
61
|
+
|
62
|
+
0. This License applies to any program or other work which contains
|
63
|
+
a notice placed by the copyright holder saying it may be distributed
|
64
|
+
under the terms of this General Public License. The "Program", below,
|
65
|
+
refers to any such program or work, and a "work based on the Program"
|
66
|
+
means either the Program or any derivative work under copyright law:
|
67
|
+
that is to say, a work containing the Program or a portion of it,
|
68
|
+
either verbatim or with modifications and/or translated into another
|
69
|
+
language. (Hereinafter, translation is included without limitation in
|
70
|
+
the term "modification".) Each licensee is addressed as "you".
|
71
|
+
|
72
|
+
Activities other than copying, distribution and modification are not
|
73
|
+
covered by this License; they are outside its scope. The act of
|
74
|
+
running the Program is not restricted, and the output from the Program
|
75
|
+
is covered only if its contents constitute a work based on the
|
76
|
+
Program (independent of having been made by running the Program).
|
77
|
+
Whether that is true depends on what the Program does.
|
78
|
+
|
79
|
+
1. You may copy and distribute verbatim copies of the Program's
|
80
|
+
source code as you receive it, in any medium, provided that you
|
81
|
+
conspicuously and appropriately publish on each copy an appropriate
|
82
|
+
copyright notice and disclaimer of warranty; keep intact all the
|
83
|
+
notices that refer to this License and to the absence of any warranty;
|
84
|
+
and give any other recipients of the Program a copy of this License
|
85
|
+
along with the Program.
|
86
|
+
|
87
|
+
You may charge a fee for the physical act of transferring a copy, and
|
88
|
+
you may at your option offer warranty protection in exchange for a fee.
|
89
|
+
|
90
|
+
2. You may modify your copy or copies of the Program or any portion
|
91
|
+
of it, thus forming a work based on the Program, and copy and
|
92
|
+
distribute such modifications or work under the terms of Section 1
|
93
|
+
above, provided that you also meet all of these conditions:
|
94
|
+
|
95
|
+
a) You must cause the modified files to carry prominent notices
|
96
|
+
stating that you changed the files and the date of any change.
|
97
|
+
|
98
|
+
b) You must cause any work that you distribute or publish, that in
|
99
|
+
whole or in part contains or is derived from the Program or any
|
100
|
+
part thereof, to be licensed as a whole at no charge to all third
|
101
|
+
parties under the terms of this License.
|
102
|
+
|
103
|
+
c) If the modified program normally reads commands interactively
|
104
|
+
when run, you must cause it, when started running for such
|
105
|
+
interactive use in the most ordinary way, to print or display an
|
106
|
+
announcement including an appropriate copyright notice and a
|
107
|
+
notice that there is no warranty (or else, saying that you provide
|
108
|
+
a warranty) and that users may redistribute the program under
|
109
|
+
these conditions, and telling the user how to view a copy of this
|
110
|
+
License. (Exception: if the Program itself is interactive but
|
111
|
+
does not normally print such an announcement, your work based on
|
112
|
+
the Program is not required to print an announcement.)
|
113
|
+
|
114
|
+
These requirements apply to the modified work as a whole. If
|
115
|
+
identifiable sections of that work are not derived from the Program,
|
116
|
+
and can be reasonably considered independent and separate works in
|
117
|
+
themselves, then this License, and its terms, do not apply to those
|
118
|
+
sections when you distribute them as separate works. But when you
|
119
|
+
distribute the same sections as part of a whole which is a work based
|
120
|
+
on the Program, the distribution of the whole must be on the terms of
|
121
|
+
this License, whose permissions for other licensees extend to the
|
122
|
+
entire whole, and thus to each and every part regardless of who wrote it.
|
123
|
+
|
124
|
+
Thus, it is not the intent of this section to claim rights or contest
|
125
|
+
your rights to work written entirely by you; rather, the intent is to
|
126
|
+
exercise the right to control the distribution of derivative or
|
127
|
+
collective works based on the Program.
|
128
|
+
|
129
|
+
In addition, mere aggregation of another work not based on the Program
|
130
|
+
with the Program (or with a work based on the Program) on a volume of
|
131
|
+
a storage or distribution medium does not bring the other work under
|
132
|
+
the scope of this License.
|
133
|
+
|
134
|
+
3. You may copy and distribute the Program (or a work based on it,
|
135
|
+
under Section 2) in object code or executable form under the terms of
|
136
|
+
Sections 1 and 2 above provided that you also do one of the following:
|
137
|
+
|
138
|
+
a) Accompany it with the complete corresponding machine-readable
|
139
|
+
source code, which must be distributed under the terms of Sections
|
140
|
+
1 and 2 above on a medium customarily used for software interchange; or,
|
141
|
+
|
142
|
+
b) Accompany it with a written offer, valid for at least three
|
143
|
+
years, to give any third party, for a charge no more than your
|
144
|
+
cost of physically performing source distribution, a complete
|
145
|
+
machine-readable copy of the corresponding source code, to be
|
146
|
+
distributed under the terms of Sections 1 and 2 above on a medium
|
147
|
+
customarily used for software interchange; or,
|
148
|
+
|
149
|
+
c) Accompany it with the information you received as to the offer
|
150
|
+
to distribute corresponding source code. (This alternative is
|
151
|
+
allowed only for noncommercial distribution and only if you
|
152
|
+
received the program in object code or executable form with such
|
153
|
+
an offer, in accord with Subsection b above.)
|
154
|
+
|
155
|
+
The source code for a work means the preferred form of the work for
|
156
|
+
making modifications to it. For an executable work, complete source
|
157
|
+
code means all the source code for all modules it contains, plus any
|
158
|
+
associated interface definition files, plus the scripts used to
|
159
|
+
control compilation and installation of the executable. However, as a
|
160
|
+
special exception, the source code distributed need not include
|
161
|
+
anything that is normally distributed (in either source or binary
|
162
|
+
form) with the major components (compiler, kernel, and so on) of the
|
163
|
+
operating system on which the executable runs, unless that component
|
164
|
+
itself accompanies the executable.
|
165
|
+
|
166
|
+
If distribution of executable or object code is made by offering
|
167
|
+
access to copy from a designated place, then offering equivalent
|
168
|
+
access to copy the source code from the same place counts as
|
169
|
+
distribution of the source code, even though third parties are not
|
170
|
+
compelled to copy the source along with the object code.
|
171
|
+
|
172
|
+
4. You may not copy, modify, sublicense, or distribute the Program
|
173
|
+
except as expressly provided under this License. Any attempt
|
174
|
+
otherwise to copy, modify, sublicense or distribute the Program is
|
175
|
+
void, and will automatically terminate your rights under this License.
|
176
|
+
However, parties who have received copies, or rights, from you under
|
177
|
+
this License will not have their licenses terminated so long as such
|
178
|
+
parties remain in full compliance.
|
179
|
+
|
180
|
+
5. You are not required to accept this License, since you have not
|
181
|
+
signed it. However, nothing else grants you permission to modify or
|
182
|
+
distribute the Program or its derivative works. These actions are
|
183
|
+
prohibited by law if you do not accept this License. Therefore, by
|
184
|
+
modifying or distributing the Program (or any work based on the
|
185
|
+
Program), you indicate your acceptance of this License to do so, and
|
186
|
+
all its terms and conditions for copying, distributing or modifying
|
187
|
+
the Program or works based on it.
|
188
|
+
|
189
|
+
6. Each time you redistribute the Program (or any work based on the
|
190
|
+
Program), the recipient automatically receives a license from the
|
191
|
+
original licensor to copy, distribute or modify the Program subject to
|
192
|
+
these terms and conditions. You may not impose any further
|
193
|
+
restrictions on the recipients' exercise of the rights granted herein.
|
194
|
+
You are not responsible for enforcing compliance by third parties to
|
195
|
+
this License.
|
196
|
+
|
197
|
+
7. If, as a consequence of a court judgment or allegation of patent
|
198
|
+
infringement or for any other reason (not limited to patent issues),
|
199
|
+
conditions are imposed on you (whether by court order, agreement or
|
200
|
+
otherwise) that contradict the conditions of this License, they do not
|
201
|
+
excuse you from the conditions of this License. If you cannot
|
202
|
+
distribute so as to satisfy simultaneously your obligations under this
|
203
|
+
License and any other pertinent obligations, then as a consequence you
|
204
|
+
may not distribute the Program at all. For example, if a patent
|
205
|
+
license would not permit royalty-free redistribution of the Program by
|
206
|
+
all those who receive copies directly or indirectly through you, then
|
207
|
+
the only way you could satisfy both it and this License would be to
|
208
|
+
refrain entirely from distribution of the Program.
|
209
|
+
|
210
|
+
If any portion of this section is held invalid or unenforceable under
|
211
|
+
any particular circumstance, the balance of the section is intended to
|
212
|
+
apply and the section as a whole is intended to apply in other
|
213
|
+
circumstances.
|
214
|
+
|
215
|
+
It is not the purpose of this section to induce you to infringe any
|
216
|
+
patents or other property right claims or to contest validity of any
|
217
|
+
such claims; this section has the sole purpose of protecting the
|
218
|
+
integrity of the free software distribution system, which is
|
219
|
+
implemented by public license practices. Many people have made
|
220
|
+
generous contributions to the wide range of software distributed
|
221
|
+
through that system in reliance on consistent application of that
|
222
|
+
system; it is up to the author/donor to decide if he or she is willing
|
223
|
+
to distribute software through any other system and a licensee cannot
|
224
|
+
impose that choice.
|
225
|
+
|
226
|
+
This section is intended to make thoroughly clear what is believed to
|
227
|
+
be a consequence of the rest of this License.
|
228
|
+
|
229
|
+
8. If the distribution and/or use of the Program is restricted in
|
230
|
+
certain countries either by patents or by copyrighted interfaces, the
|
231
|
+
original copyright holder who places the Program under this License
|
232
|
+
may add an explicit geographical distribution limitation excluding
|
233
|
+
those countries, so that distribution is permitted only in or among
|
234
|
+
countries not thus excluded. In such case, this License incorporates
|
235
|
+
the limitation as if written in the body of this License.
|
236
|
+
|
237
|
+
9. The Free Software Foundation may publish revised and/or new versions
|
238
|
+
of the General Public License from time to time. Such new versions will
|
239
|
+
be similar in spirit to the present version, but may differ in detail to
|
240
|
+
address new problems or concerns.
|
241
|
+
|
242
|
+
Each version is given a distinguishing version number. If the Program
|
243
|
+
specifies a version number of this License which applies to it and "any
|
244
|
+
later version", you have the option of following the terms and conditions
|
245
|
+
either of that version or of any later version published by the Free
|
246
|
+
Software Foundation. If the Program does not specify a version number of
|
247
|
+
this License, you may choose any version ever published by the Free Software
|
248
|
+
Foundation.
|
249
|
+
|
250
|
+
10. If you wish to incorporate parts of the Program into other free
|
251
|
+
programs whose distribution conditions are different, write to the author
|
252
|
+
to ask for permission. For software which is copyrighted by the Free
|
253
|
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
254
|
+
make exceptions for this. Our decision will be guided by the two goals
|
255
|
+
of preserving the free status of all derivatives of our free software and
|
256
|
+
of promoting the sharing and reuse of software generally.
|
257
|
+
|
258
|
+
NO WARRANTY
|
259
|
+
|
260
|
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261
|
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262
|
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263
|
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264
|
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266
|
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267
|
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268
|
+
REPAIR OR CORRECTION.
|
269
|
+
|
270
|
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271
|
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272
|
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273
|
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274
|
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275
|
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276
|
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277
|
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278
|
+
POSSIBILITY OF SUCH DAMAGES.
|
279
|
+
|
280
|
+
END OF TERMS AND CONDITIONS
|
281
|
+
|
282
|
+
How to Apply These Terms to Your New Programs
|
283
|
+
|
284
|
+
If you develop a new program, and you want it to be of the greatest
|
285
|
+
possible use to the public, the best way to achieve this is to make it
|
286
|
+
free software which everyone can redistribute and change under these terms.
|
287
|
+
|
288
|
+
To do so, attach the following notices to the program. It is safest
|
289
|
+
to attach them to the start of each source file to most effectively
|
290
|
+
convey the exclusion of warranty; and each file should have at least
|
291
|
+
the "copyright" line and a pointer to where the full notice is found.
|
292
|
+
|
293
|
+
<one line to give the program's name and a brief idea of what it does.>
|
294
|
+
Copyright (C) <year> <name of author>
|
295
|
+
|
296
|
+
This program is free software; you can redistribute it and/or modify
|
297
|
+
it under the terms of the GNU General Public License as published by
|
298
|
+
the Free Software Foundation; either version 2 of the License, or
|
299
|
+
(at your option) any later version.
|
300
|
+
|
301
|
+
This program is distributed in the hope that it will be useful,
|
302
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
303
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
304
|
+
GNU General Public License for more details.
|
305
|
+
|
306
|
+
You should have received a copy of the GNU General Public License
|
307
|
+
along with this program; if not, write to the Free Software
|
308
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
309
|
+
|
310
|
+
|
311
|
+
Also add information on how to contact you by electronic and paper mail.
|
312
|
+
|
313
|
+
If the program is interactive, make it output a short notice like this
|
314
|
+
when it starts in an interactive mode:
|
315
|
+
|
316
|
+
Gnomovision version 69, Copyright (C) year name of author
|
317
|
+
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
318
|
+
This is free software, and you are welcome to redistribute it
|
319
|
+
under certain conditions; type `show c' for details.
|
320
|
+
|
321
|
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
322
|
+
parts of the General Public License. Of course, the commands you use may
|
323
|
+
be called something other than `show w' and `show c'; they could even be
|
324
|
+
mouse-clicks or menu items--whatever suits your program.
|
325
|
+
|
326
|
+
You should also get your employer (if you work as a programmer) or your
|
327
|
+
school, if any, to sign a "copyright disclaimer" for the program, if
|
328
|
+
necessary. Here is a sample; alter the names:
|
329
|
+
|
330
|
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
331
|
+
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
332
|
+
|
333
|
+
<signature of Ty Coon>, 1 April 1989
|
334
|
+
Ty Coon, President of Vice
|
335
|
+
|
336
|
+
This General Public License does not permit incorporating your program into
|
337
|
+
proprietary programs. If your program is a subroutine library, you may
|
338
|
+
consider it more useful to permit linking proprietary applications with the
|
339
|
+
library. If this is what you want to do, use the GNU Library General
|
340
|
+
Public License instead of this License.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
SwfRuby
|
2
|
+
=======
|
3
|
+
|
4
|
+
SwfRuby is a utilities to dump or manipulate a SWF with Ruby.
|
5
|
+
|
6
|
+
* features
|
7
|
+
* SwfRuby::SwfDumper
|
8
|
+
* Analysing the structure of specified SWF.
|
9
|
+
* Used from 'swf_dump' command.
|
10
|
+
* SwfRuby::SwfTamperer
|
11
|
+
* Manipulating(replagcing) resources in SWF.
|
12
|
+
* Used from 'swf_jpeg_replace' command.
|
13
|
+
* compatible on ruby-1.8.7 and ruby-1.9.2.
|
14
|
+
|
15
|
+
Installation
|
16
|
+
============
|
17
|
+
|
18
|
+
$ git clone git://github.com/tmtysk/swf_ruby.git
|
19
|
+
$ cd swf_ruby
|
20
|
+
$ rake install
|
21
|
+
|
22
|
+
Command-Line Tool Usage
|
23
|
+
=======================
|
24
|
+
|
25
|
+
Analysing the structure of SWF
|
26
|
+
------------------------------
|
27
|
+
|
28
|
+
$ swf_dump samples/sample.swf
|
29
|
+
SetBackgroundColor, offset: 20, length: 5
|
30
|
+
DefineFont2, offset: 25, length: 34
|
31
|
+
DefineEditText, offset: 59, length: 50
|
32
|
+
PlaceObject2, offset: 109, length: 11
|
33
|
+
DefineBitsLossless2, offset: 120, length: 178
|
34
|
+
DefineShape, offset: 298, length: 55
|
35
|
+
:
|
36
|
+
DefineBitsJPEG2, offset: 623, length: 10986
|
37
|
+
:
|
38
|
+
|
39
|
+
Replacing Jpeg in SWF
|
40
|
+
---------------------
|
41
|
+
|
42
|
+
$ swf_jpeg_replace samples/sample.swf 623 samples/bg.jpg > samples/sample2.swf
|
43
|
+
# <623> is offset to Jpeg resource getting by 'swf_dump'.
|
44
|
+
|
45
|
+
Thanks
|
46
|
+
======
|
47
|
+
|
48
|
+
* Sample GIF image is provided by ICHIGO-APORO.
|
49
|
+
|
50
|
+
Copyright (c) 2011 tmtysk.
|
51
|
+
released under the GNU GENERAL PUBLIC LICENSE Version 2.
|
52
|
+
See COPYING for details.
|
data/Rakefile
ADDED
data/bin/swf_dump
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
3
|
+
# SWF構造をダンプし、タグ群情報を出力する. DefineSpriteとDoActionに対しては、さらに潜ってダンプする.
|
4
|
+
|
5
|
+
require 'swf_ruby'
|
6
|
+
|
7
|
+
print "Specify swf file path to dump for argument." if ARGV.size != 1
|
8
|
+
swf = SwfRuby::SwfDumper.new
|
9
|
+
swf.open(ARGV[0])
|
10
|
+
swf.tags.each_with_index do |tag, i|
|
11
|
+
print "#{SwfRuby::Swf::TAG_TYPE[tag.code]}, offset: #{swf.tags_addresses[i]}, length: #{tag.length}\n"
|
12
|
+
if tag.code == 39
|
13
|
+
# DefineSprite
|
14
|
+
sd = SwfRuby::SpriteDumper.new
|
15
|
+
sd.dump(tag)
|
16
|
+
print " Sprite ID: #{sd.sprite_id}, Frame Count: #{sd.frame_count}\n"
|
17
|
+
sd.tags.each_with_index do |tag2, k|
|
18
|
+
print " #{SwfRuby::Swf::TAG_TYPE[tag2.code]}, offset: #{sd.tags_addresses[k]}, length: #{tag2.length}\n"
|
19
|
+
if tag2.code == 12
|
20
|
+
# DoAction
|
21
|
+
dad = SwfRuby::DoActionDumper.new
|
22
|
+
dad.dump(swf.swf[swf.tags_addresses[i] + sd.tags_addresses[k], tag2.length])
|
23
|
+
dad.actions.each_with_index do |ar, l|
|
24
|
+
print " #{SwfRuby::Swf::ACTION_RECORDS[ar.code]}, offset: #{dad.actions_addresses[l]}, length: #{ar.length}\n"
|
25
|
+
if ar.code == 150
|
26
|
+
# ActionPush
|
27
|
+
ap = SwfRuby::Swf::ActionPush.new(ar)
|
28
|
+
print " type: #{ap.data_type}, offset: #{dad.actions_addresses[l]}, data: #{ap.data}\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
if tag.code == 12
|
35
|
+
# DoAction
|
36
|
+
dad = SwfRuby::DoActionDumper.new
|
37
|
+
dad.dump(swf.swf[swf.tags_addresses[i], tag.length])
|
38
|
+
dad.actions.each_with_index do |ar, j|
|
39
|
+
print " #{SwfRuby::Swf::ACTION_RECORDS[ar.code]}, offset: #{dad.actions_addresses[j]}, length: #{ar.length}\n"
|
40
|
+
if ar.code == 150
|
41
|
+
# ActionPush
|
42
|
+
ap = SwfRuby::Swf::ActionPush.new(ar)
|
43
|
+
print " type: #{ap.data_type}, offset: #{dad.actions_addresses[j]}, data: #{ap.data}\n"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
print "\n"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
3
|
+
# SWF中のJpeg(DefineBitsJpeg2)イメージを差し替える.
|
4
|
+
require 'swf_ruby'
|
5
|
+
|
6
|
+
print "Specify target swf path, offset to jpeg, new jpeg path for arguments." if ARGV.size != 3
|
7
|
+
|
8
|
+
swf = File.open(ARGV[0], "rb").read
|
9
|
+
st = SwfRuby::SwfTamperer.new
|
10
|
+
jpeg = File.open(ARGV[2], "rb").read
|
11
|
+
repl_targets = [
|
12
|
+
SwfRuby::Jpeg2ReplaceTarget.new(ARGV[1].to_i, jpeg)
|
13
|
+
]
|
14
|
+
|
15
|
+
print st.replace(swf, repl_targets)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
|
3
|
+
module SwfRuby
|
4
|
+
class DoActionDumper
|
5
|
+
|
6
|
+
attr_accessor :tag
|
7
|
+
attr_accessor :actions
|
8
|
+
attr_accessor :actions_addresses
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@actions = nil
|
12
|
+
@actions_addresses = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def dump(tag)
|
16
|
+
@tag = tag
|
17
|
+
@tag = @tag.force_encoding("ASCII-8BIT") if @tag.respond_to? :force_encoding
|
18
|
+
record_header = @tag[0, 2].unpack("v").first
|
19
|
+
t = Swf::Tag.new(@tag)
|
20
|
+
# tag check
|
21
|
+
raise NotDoActionTagError if t.code != 12
|
22
|
+
# length check
|
23
|
+
raise InvalidTagLengthError if t.length != @tag.length
|
24
|
+
|
25
|
+
@actions = []
|
26
|
+
@actions_addresses = []
|
27
|
+
tags_index = (t.long_header) ? 6 : 2
|
28
|
+
while tags_index < t.length
|
29
|
+
@actions_addresses << tags_index
|
30
|
+
ar = Swf::ActionRecord.new(@tag[tags_index..-1])
|
31
|
+
tags_index += ar.length
|
32
|
+
@actions << ar
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class NotDoActionTagError < StandardError; end
|
38
|
+
class InvalidTagLengthError < StandardError; end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
|
3
|
+
module SwfRuby
|
4
|
+
class ReplaceTarget
|
5
|
+
attr_accessor :offset
|
6
|
+
end
|
7
|
+
|
8
|
+
class Jpeg2ReplaceTarget < ReplaceTarget
|
9
|
+
attr_accessor :jpeg
|
10
|
+
|
11
|
+
def initialize(offset, jpeg)
|
12
|
+
@offset = offset
|
13
|
+
@jpeg = jpeg
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class AsVarReplaceTarget < ReplaceTarget
|
18
|
+
attr_accessor :do_action_offset
|
19
|
+
attr_accessor :str
|
20
|
+
attr_accessor :parent_sprite_offsets
|
21
|
+
|
22
|
+
def initialize(action_push_offset, do_action_offset, str, parent_sprite_offsets = [])
|
23
|
+
@offset = action_push_offset
|
24
|
+
@do_action_offset = do_action_offset
|
25
|
+
@str = str
|
26
|
+
@parent_sprite_offsets = parent_sprite_offsets
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
|
3
|
+
module SwfRuby
|
4
|
+
# DefineSpriteをダンプするクラス.
|
5
|
+
class SpriteDumper
|
6
|
+
attr_reader :sprite_id
|
7
|
+
attr_reader :frame_count
|
8
|
+
attr_reader :tags
|
9
|
+
attr_reader :tags_addresses
|
10
|
+
|
11
|
+
# 初期化.
|
12
|
+
def initialize
|
13
|
+
@sprite_id = nil
|
14
|
+
@frame_count = nil
|
15
|
+
@tag = nil
|
16
|
+
@tags_addresses = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
# ダンプして構造をインスタンス変数に格納.
|
20
|
+
def dump(tag)
|
21
|
+
data = tag.data
|
22
|
+
@sprite_id = data[0, 2].unpack("v").first
|
23
|
+
@frame_count = data[2, 2].unpack("v").first
|
24
|
+
@tags = []
|
25
|
+
@tags_addresses = []
|
26
|
+
sprite_header_length = (tag.long_header) ? 6 : 2
|
27
|
+
tag_index = 4
|
28
|
+
while tag_index < data.length
|
29
|
+
@tags_addresses << tag_index + sprite_header_length
|
30
|
+
tag = Swf::Tag.new(data[tag_index..-1])
|
31
|
+
tag_index += tag.length
|
32
|
+
@tags << tag
|
33
|
+
end
|
34
|
+
self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
|
3
|
+
module SwfRuby
|
4
|
+
module Swf
|
5
|
+
# ActionPushタグ.
|
6
|
+
class ActionPush
|
7
|
+
attr_reader :data_type
|
8
|
+
attr_reader :data
|
9
|
+
|
10
|
+
def initialize(action_record)
|
11
|
+
raise NotActionPushError if action_record.code != 0x96
|
12
|
+
ad = action_record.data
|
13
|
+
@data_type = ad[0].chr.unpack("C").first
|
14
|
+
@data = nil
|
15
|
+
d = ad[1..-1]
|
16
|
+
case @data_type
|
17
|
+
when 0
|
18
|
+
@data = d
|
19
|
+
when 1
|
20
|
+
@data = d.unpack("e")
|
21
|
+
when 4,5,8
|
22
|
+
@data = d.unpack("C")
|
23
|
+
when 6
|
24
|
+
@data = d.unpack("E")
|
25
|
+
when 7
|
26
|
+
@data = d.unpack("V")
|
27
|
+
when 9
|
28
|
+
@data = d.unpack("v")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class NotActionPushError < StandardError; end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
|
3
|
+
module SwfRuby
|
4
|
+
module Swf
|
5
|
+
class ActionRecord
|
6
|
+
attr_reader :code
|
7
|
+
attr_reader :length
|
8
|
+
attr_reader :data
|
9
|
+
|
10
|
+
def initialize(tag)
|
11
|
+
tag.force_encoding("ASCII-8BIT") if tag.respond_to? :force_encoding
|
12
|
+
# action code
|
13
|
+
@code = tag[0].chr.unpack("C").first
|
14
|
+
# length (including action record header) and data
|
15
|
+
@length = 1
|
16
|
+
@data = nil
|
17
|
+
if @code >= 0x80
|
18
|
+
len = tag[1,2].unpack("v").first
|
19
|
+
@length += len + 2
|
20
|
+
@data = tag[3,len]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
ACTION_RECORDS = {
|
26
|
+
71=>"Add (typed)",
|
27
|
+
10=>"Add",
|
28
|
+
96=>"And",
|
29
|
+
153=>"Branch Always",
|
30
|
+
157=>"Branch If True",
|
31
|
+
158=>"Call Frame",
|
32
|
+
61=>"Call Function",
|
33
|
+
82=>"Call Method",
|
34
|
+
43=>"Cast Object",
|
35
|
+
55=>"Chr (multi-byte)",
|
36
|
+
51=>"Chr",
|
37
|
+
33=>"Concatenate Strings",
|
38
|
+
66=>"Declare Array",
|
39
|
+
136=>"Declare Dictionary",
|
40
|
+
142=>"Declare Function (V7)",
|
41
|
+
155=>"Declare Function",
|
42
|
+
65=>"Declare Local Variable",
|
43
|
+
67=>"Declare Object",
|
44
|
+
81=>"Decrement",
|
45
|
+
58=>"Delete",
|
46
|
+
59=>"Delete All",
|
47
|
+
13=>"Divide",
|
48
|
+
76=>"Duplicate",
|
49
|
+
36=>"Duplicate Sprite",
|
50
|
+
0=>"End (action)",
|
51
|
+
70=>"Enumerate",
|
52
|
+
85=>"Enumerate Object",
|
53
|
+
73=>"Equal (typed)",
|
54
|
+
14=>"Equal",
|
55
|
+
105=>"Extends",
|
56
|
+
45=>"FSCommand2",
|
57
|
+
78=>"Get Member",
|
58
|
+
34=>"Get Property",
|
59
|
+
69=>"Get Target",
|
60
|
+
52=>"Get Timer",
|
61
|
+
131=>"Get URL",
|
62
|
+
154=>"Get URL2",
|
63
|
+
28=>"Get Variable",
|
64
|
+
159=>"Goto Expression",
|
65
|
+
129=>"Goto Frame",
|
66
|
+
140=>"Goto Label",
|
67
|
+
103=>"Greater Than (typed)",
|
68
|
+
44=>"Implements",
|
69
|
+
80=>"Increment",
|
70
|
+
84=>"Instance Of",
|
71
|
+
24=>"Integral Part",
|
72
|
+
72=>"Less Than (typed)",
|
73
|
+
15=>"Less Than",
|
74
|
+
16=>"Logical And",
|
75
|
+
18=>"Logical Not",
|
76
|
+
17=>"Logical Or",
|
77
|
+
63=>"Modulo",
|
78
|
+
12=>"Multiply",
|
79
|
+
64=>"New",
|
80
|
+
83=>"New Method",
|
81
|
+
4=>"Next Frame",
|
82
|
+
74=>"Number",
|
83
|
+
97=>"Or",
|
84
|
+
54=>"Ord (multi-byte)",
|
85
|
+
50=>"Ord",
|
86
|
+
6=>"Play",
|
87
|
+
23=>"Pop",
|
88
|
+
5=>"Previous Frame",
|
89
|
+
150=>"Push Data",
|
90
|
+
48=>"Random",
|
91
|
+
37=>"Remove Sprite",
|
92
|
+
62=>"Return",
|
93
|
+
60=>"Set Local Variable",
|
94
|
+
79=>"Set Member",
|
95
|
+
35=>"Set Property",
|
96
|
+
32=>"Set Target (dynamic)",
|
97
|
+
139=>"Set Target",
|
98
|
+
29=>"Set Variable",
|
99
|
+
99=>"Shift Left",
|
100
|
+
100=>"Shift Right",
|
101
|
+
101=>"Shift Right Unsigned",
|
102
|
+
39=>"Start Drag",
|
103
|
+
7=>"Stop",
|
104
|
+
40=>"Stop Drag",
|
105
|
+
9=>"Stop Sound",
|
106
|
+
135=>"Store Register",
|
107
|
+
102=>"Strict Equal",
|
108
|
+
137=>"Strict Mode",
|
109
|
+
75=>"String",
|
110
|
+
19=>"String Equal",
|
111
|
+
104=>"String Greater Than",
|
112
|
+
49=>"String Length (multi-byte)",
|
113
|
+
20=>"String Length",
|
114
|
+
41=>"String Less Than",
|
115
|
+
53=>"SubString (multi-byte)",
|
116
|
+
21=>"SubString",
|
117
|
+
11=>"Subtract",
|
118
|
+
77=>"Swap",
|
119
|
+
42=>"Throw",
|
120
|
+
8=>"Toggle Quality",
|
121
|
+
38=>"Trace",
|
122
|
+
143=>"Try",
|
123
|
+
68=>"Type Of",
|
124
|
+
141=>"Wait For Frame (dynamic)",
|
125
|
+
138=>"Wait For Frame",
|
126
|
+
148=>"With",
|
127
|
+
98=>"XOr"
|
128
|
+
}
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
|
3
|
+
module SwfRuby
|
4
|
+
module Swf
|
5
|
+
class Header
|
6
|
+
attr_accessor :compressed
|
7
|
+
attr_accessor :version
|
8
|
+
attr_accessor :file_length
|
9
|
+
attr_accessor :frame_size
|
10
|
+
attr_accessor :frame_rate
|
11
|
+
attr_accessor :frame_count
|
12
|
+
attr_reader :length
|
13
|
+
|
14
|
+
def initialize(swf)
|
15
|
+
# check if compressed
|
16
|
+
if swf[1].chr == "W" and swf[2].chr == "S"
|
17
|
+
if swf[0].chr == "F"
|
18
|
+
@compressed = false
|
19
|
+
elsif swf[0].chr == "C"
|
20
|
+
@compressed = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
# version
|
24
|
+
@version = swf[3].chr.unpack("C").first
|
25
|
+
# file size
|
26
|
+
@file_length = swf[4, 4].unpack("V").first
|
27
|
+
# frame size
|
28
|
+
@frame_size = Rectangle.new(swf[8..-1])
|
29
|
+
# frame rate
|
30
|
+
@frame_rate = (swf[8+@frame_size.length].chr.unpack("C").first).to_f / 0x100
|
31
|
+
@frame_rate += swf[9+@frame_size.length].chr.unpack("C").first
|
32
|
+
# frame count
|
33
|
+
@frame_count = swf[10+@frame_size.length, 2].unpack("v").first
|
34
|
+
# header length
|
35
|
+
@length = 12+@frame_size.length
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
|
3
|
+
module SwfRuby
|
4
|
+
module Swf
|
5
|
+
class Rectangle
|
6
|
+
attr_accessor :bits
|
7
|
+
attr_accessor :xmin
|
8
|
+
attr_accessor :xmax
|
9
|
+
attr_accessor :ymin
|
10
|
+
attr_accessor :ymax
|
11
|
+
attr_reader :length
|
12
|
+
|
13
|
+
def initialize(bytearray)
|
14
|
+
@bits = bytearray[0].chr.unpack("B5").first.to_i(2)
|
15
|
+
rect_bitstr = bytearray[0..((self.bits/2)+1)].unpack("B*").first
|
16
|
+
@xmin = rect_bitstr[5, self.bits].to_i(2)
|
17
|
+
@xmax = rect_bitstr[5+self.bits, self.bits].to_i(2)
|
18
|
+
@ymin = rect_bitstr[5+2*self.bits, self.bits].to_i(2)
|
19
|
+
@ymax = rect_bitstr[5+3*self.bits, self.bits].to_i(2)
|
20
|
+
@length = (5+self.bits*4)/8+1 # including padded byte
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
|
3
|
+
module SwfRuby
|
4
|
+
module Swf
|
5
|
+
class Tag
|
6
|
+
attr_reader :code
|
7
|
+
attr_reader :length
|
8
|
+
attr_reader :long_header
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def initialize(swf)
|
12
|
+
swf.force_encoding("ASCII-8BIT") if swf.respond_to? :force_encoding
|
13
|
+
record_header = swf[0, 2].unpack("v").first
|
14
|
+
# tag type
|
15
|
+
@code = (record_header >> 6) & 1023
|
16
|
+
# tag length (including record header)
|
17
|
+
@length = record_header & 63
|
18
|
+
@long_header = false
|
19
|
+
@data = nil
|
20
|
+
if @length == 63
|
21
|
+
len = swf[2, 4].unpack("i").first
|
22
|
+
@data = swf[6, len]
|
23
|
+
@length = len + 6
|
24
|
+
@long_header = true
|
25
|
+
else
|
26
|
+
@data = swf[2, @length]
|
27
|
+
@length += 2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
TAG_TYPE = {
|
33
|
+
0=>"End",
|
34
|
+
1=>"ShowFrame",
|
35
|
+
2=>"DefineShape",
|
36
|
+
3=>"FreeCharacter",
|
37
|
+
4=>"PlaceObject",
|
38
|
+
5=>"RemoveObject",
|
39
|
+
6=>"DefineBitsJPEG",
|
40
|
+
7=>"DefineButton",
|
41
|
+
8=>"JPEGTables",
|
42
|
+
9=>"SetBackgroundColor",
|
43
|
+
10=>"DefineFont",
|
44
|
+
11=>"DefineText",
|
45
|
+
12=>"DoAction",
|
46
|
+
13=>"DefineFontInfo",
|
47
|
+
14=>"DefineSound",
|
48
|
+
15=>"StopSound",
|
49
|
+
17=>"DefineButtonSound",
|
50
|
+
18=>"SoundStreamHead",
|
51
|
+
19=>"SoundStreamBlock",
|
52
|
+
20=>"DefineBitsLossless",
|
53
|
+
21=>"DefineBitsJPEG2",
|
54
|
+
22=>"DefineShape2",
|
55
|
+
23=>"DefineButtonCxform",
|
56
|
+
24=>"Protect",
|
57
|
+
25=>"PathsArePostscript",
|
58
|
+
26=>"PlaceObject2",
|
59
|
+
28=>"RemoveObject2",
|
60
|
+
29=>"SyncFrame",
|
61
|
+
31=>"FreeAll",
|
62
|
+
32=>"DefineShape3",
|
63
|
+
33=>"DefineText2",
|
64
|
+
34=>"DefineButton2",
|
65
|
+
35=>"DefineBitsJPEG3",
|
66
|
+
36=>"DefineBitsLossless2",
|
67
|
+
37=>"DefineEditText",
|
68
|
+
38=>"DefineVideo",
|
69
|
+
39=>"DefineSprite",
|
70
|
+
40=>"NameCharacter",
|
71
|
+
41=>"ProductInfo",
|
72
|
+
42=>"DefineTextFormat",
|
73
|
+
43=>"FrameLabel",
|
74
|
+
45=>"SoundStreamHead2",
|
75
|
+
46=>"DefineMorphShape",
|
76
|
+
47=>"GenerateFrame",
|
77
|
+
48=>"DefineFont2",
|
78
|
+
49=>"GeneratorCommand",
|
79
|
+
50=>"DefineCommandObject",
|
80
|
+
51=>"CharacterSet",
|
81
|
+
52=>"ExternalFont",
|
82
|
+
56=>"Export",
|
83
|
+
57=>"Import",
|
84
|
+
58=>"ProtectDebug",
|
85
|
+
59=>"DoInitAction",
|
86
|
+
60=>"DefineVideoStream",
|
87
|
+
61=>"VideoFrame",
|
88
|
+
62=>"DefineFontInfo2",
|
89
|
+
63=>"DebugID",
|
90
|
+
64=>"ProtectDebug2",
|
91
|
+
65=>"ScriptLimits",
|
92
|
+
66=>"SetTabIndex",
|
93
|
+
69=>"FileAttributes",
|
94
|
+
70=>"PlaceObject3",
|
95
|
+
71=>"Import2",
|
96
|
+
72=>"DoABC",
|
97
|
+
73=>"DefineFontAlignZones",
|
98
|
+
74=>"CSMTextSettings",
|
99
|
+
75=>"DefineFont3",
|
100
|
+
76=>"SymbolClass",
|
101
|
+
77=>"Metadata",
|
102
|
+
78=>"DefineScalingGrid",
|
103
|
+
82=>"DoABCDefine",
|
104
|
+
83=>"DefineShape4",
|
105
|
+
84=>"DefineMorphShape2",
|
106
|
+
86=>"DefineSceneAndFrameData",
|
107
|
+
87=>"DefineBinaryData",
|
108
|
+
88=>"DefineFontName",
|
109
|
+
90=>"DefineBitsJPEG4"
|
110
|
+
}
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
data/lib/swf_ruby/swf.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'swf', '*.rb')].sort.each { |f| require f }
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
|
3
|
+
module SwfRuby
|
4
|
+
# Swf構造をダンプするクラス.
|
5
|
+
class SwfDumper
|
6
|
+
attr_reader :swf
|
7
|
+
attr_reader :header
|
8
|
+
attr_reader :tags
|
9
|
+
attr_reader :tags_addresses
|
10
|
+
|
11
|
+
# 初期化.
|
12
|
+
def initialize
|
13
|
+
@swf = nil
|
14
|
+
@header = nil
|
15
|
+
@tags = nil
|
16
|
+
@tags_addresses = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
# ファイルをバイナリモードで読み込み.
|
20
|
+
# 1.9環境の場合はエンコーディング指定.
|
21
|
+
def open(file)
|
22
|
+
f = File.open(file, "rb").read
|
23
|
+
f.force_encoding("ASCII-8BIT") if f.respond_to? :force_encoding
|
24
|
+
dump(f)
|
25
|
+
end
|
26
|
+
|
27
|
+
# ダンプして構造をインスタンス変数に格納.
|
28
|
+
def dump(swf)
|
29
|
+
@swf = swf
|
30
|
+
@header = Swf::Header.new(@swf)
|
31
|
+
@tags = []
|
32
|
+
@tags_addresses = []
|
33
|
+
tags_length = 0
|
34
|
+
while @header.length + tags_length < @header.file_length
|
35
|
+
addr = @header.length + tags_length
|
36
|
+
@tags_addresses << addr
|
37
|
+
tag = Swf::Tag.new(@swf[addr..-1])
|
38
|
+
tags_length += tag.length
|
39
|
+
@tags << tag
|
40
|
+
end
|
41
|
+
self
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
|
2
|
+
module SwfRuby
|
3
|
+
# Swfに含まれるリソースを置換するクラス.
|
4
|
+
class SwfTamperer
|
5
|
+
|
6
|
+
# 対象Swf(バイナリ)のリソースを置換.
|
7
|
+
# 置換対象はReplaceTargetオブジェクトの配列で渡す.
|
8
|
+
def replace(swf, replace_targets)
|
9
|
+
replace_targets.sort_by { |a| a.offset }.reverse.each do |rt|
|
10
|
+
case rt
|
11
|
+
when Jpeg2ReplaceTarget
|
12
|
+
swf = self.repl_jpeg2(swf, rt.offset, rt.jpeg)
|
13
|
+
when AsVarReplaceTarget
|
14
|
+
swf = self.repl_action_push_string(swf, rt.do_action_offset, rt.offset, rt.str, rt.parent_sprite_offsets)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
swf
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
# ActionScriptに含まれる文字列を置換.
|
23
|
+
def repl_action_push_string(swf, do_action_offset, action_push_offset, str, parent_sprite_offsets = [])
|
24
|
+
swf.force_encoding("ASCII-8BIT") if swf.respond_to? :force_encoding
|
25
|
+
str.force_encoding("ASCII-8BIT") if str.respond_to? :force_encoding
|
26
|
+
record_header = swf[do_action_offset, 2].unpack("v").first
|
27
|
+
# tag check
|
28
|
+
raise ReplaceTargetError if (record_header >> 6) & 1023 != 12
|
29
|
+
# action check
|
30
|
+
raise ReplaceTargetError if swf[action_push_offset].chr.unpack("C").first != 0x96
|
31
|
+
raise ReplaceTargetError if swf[action_push_offset + 3].chr.unpack("C").first != 0
|
32
|
+
# error on short header
|
33
|
+
raise ReplaceTargetError if record_header & 63 < 63
|
34
|
+
# calc length
|
35
|
+
do_action_len = swf[do_action_offset+2, 4].unpack("i").first
|
36
|
+
action_push_len = swf[action_push_offset+1, 2].unpack("v").first
|
37
|
+
org_str_length = action_push_len - 2 # data type & terminated null
|
38
|
+
delta_str_length = str.length - org_str_length
|
39
|
+
# replace string and rewrite length
|
40
|
+
swf[action_push_offset+4, org_str_length] = str
|
41
|
+
swf[action_push_offset+1, 2] = [action_push_len + delta_str_length].pack("v")
|
42
|
+
swf[do_action_offset+2, 4] = [do_action_len + delta_str_length].pack("V")
|
43
|
+
parent_sprite_offsets.sort.reverse.each do |parent_sprite_offset|
|
44
|
+
swf[parent_sprite_offset+2, 4] = [swf[parent_sprite_offset+2, 4].unpack("V").first + delta_str_length].pack("V")
|
45
|
+
end
|
46
|
+
swf[4, 4] = [swf[4, 4].unpack("V").first + delta_str_length].pack("V")
|
47
|
+
swf
|
48
|
+
end
|
49
|
+
|
50
|
+
# DefineBitsJpeg2のイメージバイナリを置換.
|
51
|
+
def repl_jpeg2(swf, offset, jpeg)
|
52
|
+
swf.force_encoding("ASCII-8BIT") if swf.respond_to? :force_encoding
|
53
|
+
jpeg.force_encoding("ASCII-8BIT") if jpeg.respond_to? :force_encoding
|
54
|
+
record_header = swf[offset, 2].unpack("v").first
|
55
|
+
# tag check (対象がSWF全体なので、効率の面からTagインスタンスを作らないでチェック)
|
56
|
+
raise ReplaceTargetError if (record_header >> 6) & 1023 != 21
|
57
|
+
# calc length
|
58
|
+
org_jpeg_length = record_header & 63 - 2
|
59
|
+
before_long_header = false
|
60
|
+
after_long_header = false
|
61
|
+
if org_jpeg_length == 61
|
62
|
+
before_long_header = true
|
63
|
+
org_jpeg_length = swf[offset+2, 4].unpack("i").first - 2
|
64
|
+
end
|
65
|
+
target_jpeg_length = jpeg.length + 4
|
66
|
+
delta_jpeg_length = target_jpeg_length - org_jpeg_length
|
67
|
+
after_long_header = true if target_jpeg_length + 2 >= 63
|
68
|
+
# replace jpeg and rewrite length
|
69
|
+
# タグのヘッダ長さが入れ替え前後で変化する場合があるので場合分けする
|
70
|
+
if before_long_header and after_long_header
|
71
|
+
swf[offset+8, org_jpeg_length] = [0xff, 0xd9, 0xff, 0xd8].pack("C*") + jpeg
|
72
|
+
swf[offset+2, 4] = [target_jpeg_length + 2].pack("i")
|
73
|
+
swf[4, 4] = [swf[4, 4].unpack("V").first + delta_jpeg_length].pack("V")
|
74
|
+
elsif before_long_header and !after_long_header
|
75
|
+
swf[offset+8, org_jpeg_length] = [0xff, 0xd9, 0xff, 0xd8].pack("C*") + jpeg
|
76
|
+
swf[offset, 4] = [(((record_header >> 6) & 1023) << 6) + target_jpeg_length + 2].pack("v")
|
77
|
+
swf[4, 4] = [swf[4, 4].unpack("V").first + delta_jpeg_length - 4].pack("V")
|
78
|
+
elsif !before_long_header and after_long_header
|
79
|
+
swf[offset+4, org_jpeg_length] = [0xff, 0xd9, 0xff, 0xd8].pack("C*") + jpeg
|
80
|
+
swf[offset, 2] = [(((record_header >> 6) & 1023) << 6) + 63].pack("v") + [target_jpeg_length + 2].pack("i")
|
81
|
+
swf[4, 4] = [swf[4, 4].unpack("V").first + delta_jpeg_length + 4].pack("V")
|
82
|
+
elsif !before_long_header and !after_long_header
|
83
|
+
swf[offset+4, org_jpeg_length] = [0xff, 0xd9, 0xff, 0xd8].pack("C*") + jpeg
|
84
|
+
swf[offset, 2] = [(((record_header >> 6) & 1023) << 6) + target_jpeg_length + 2].pack("v")
|
85
|
+
swf[4, 4] = [swf[4, 4].unpack("V").first + delta_jpeg_length].pack("V")
|
86
|
+
end
|
87
|
+
swf
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# 置換対象指定エラー.
|
92
|
+
class ReplaceTargetError < StandardError; end
|
93
|
+
end
|
data/lib/swf_ruby.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'swf_ruby', '*.rb')].sort.each { |f| require f }
|
data/samples/bg.jpg
ADDED
Binary file
|
data/samples/sample.swf
ADDED
Binary file
|
data/swf_ruby.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
3
|
+
require 'swf_ruby/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "swf_ruby"
|
7
|
+
s.version = SwfRuby::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = []
|
10
|
+
s.email = []
|
11
|
+
s.homepage = "http://github.com/tmtysk/swf_ruby"
|
12
|
+
s.summary = "Utilities to dump or manipulate Swf binary file."
|
13
|
+
s.description = "SwfRuby is utilities to dump or manipulate Swf binary file."
|
14
|
+
|
15
|
+
s.required_rubygems_version = ">= 1.3.6"
|
16
|
+
s.rubyforge_project = "swf_ruby"
|
17
|
+
|
18
|
+
s.add_development_dependency "bundler", ">= 1.0.0.rc.5"
|
19
|
+
|
20
|
+
s.bindir = 'bin'
|
21
|
+
s.executables = ['swf_dump', 'swf_jpeg_replace']
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.require_path = 'lib'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swf_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors: []
|
12
|
+
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-12 00:00:00 +09:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- rc
|
33
|
+
- 5
|
34
|
+
version: 1.0.0.rc.5
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: SwfRuby is utilities to dump or manipulate Swf binary file.
|
38
|
+
email: []
|
39
|
+
|
40
|
+
executables:
|
41
|
+
- swf_dump
|
42
|
+
- swf_jpeg_replace
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- .bundle/config
|
49
|
+
- .gitignore
|
50
|
+
- COPYING
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/swf_dump
|
56
|
+
- bin/swf_jpeg_replace
|
57
|
+
- lib/swf_ruby.rb
|
58
|
+
- lib/swf_ruby/do_action_dumper.rb
|
59
|
+
- lib/swf_ruby/replace_target.rb
|
60
|
+
- lib/swf_ruby/sprite_dumper.rb
|
61
|
+
- lib/swf_ruby/swf.rb
|
62
|
+
- lib/swf_ruby/swf/action_push.rb
|
63
|
+
- lib/swf_ruby/swf/action_record.rb
|
64
|
+
- lib/swf_ruby/swf/header.rb
|
65
|
+
- lib/swf_ruby/swf/rectangle.rb
|
66
|
+
- lib/swf_ruby/swf/tag.rb
|
67
|
+
- lib/swf_ruby/swf_dumper.rb
|
68
|
+
- lib/swf_ruby/swf_tamperer.rb
|
69
|
+
- lib/swf_ruby/version.rb
|
70
|
+
- samples/bg.jpg
|
71
|
+
- samples/sample.swf
|
72
|
+
- swf_ruby.gemspec
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/tmtysk/swf_ruby
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 1
|
97
|
+
- 3
|
98
|
+
- 6
|
99
|
+
version: 1.3.6
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project: swf_ruby
|
103
|
+
rubygems_version: 1.3.7
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Utilities to dump or manipulate Swf binary file.
|
107
|
+
test_files: []
|
108
|
+
|