swf_embed 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 miyucy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,22 @@
1
+ = swf_embed
2
+
3
+ require 'swf_embed'
4
+
5
+ Swf.embed(File.read("/path/to/swf"), { "variable_name" => "value" })
6
+ # => String
7
+
8
+ see http://www.flash-jp.com/modules/newbb/viewtopic.php?viewmode=flat&order=DESC&topic_id=3414&forum=18
9
+
10
+ == Note on Patches/Pull Requests
11
+
12
+ * Fork the project.
13
+ * Make your feature addition or bug fix.
14
+ * Add tests for it. This is important so I don't break it in a
15
+ future version unintentionally.
16
+ * Commit, do not mess with rakefile, version, or history.
17
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
18
+ * Send me a pull request. Bonus points for topic branches.
19
+
20
+ == Copyright
21
+
22
+ Copyright (c) 2010 miyucy. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "swf_embed"
8
+ gem.summary = %Q{Parameter Injector for Flash Lite}
9
+ gem.description = %Q{Parameter Injector for Flash Lite}
10
+ gem.email = "miyucy@gmail.com"
11
+ gem.homepage = "http://github.com/miyucy/swf_embed"
12
+ gem.authors = ["miyucy"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "swf_embed #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/ext/extconf.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "mkmf"
2
+ have_header("stdint.h")
3
+ have_header("endian.h")
4
+ create_makefile("swf_embed")
data/ext/swf_embed.c ADDED
@@ -0,0 +1,126 @@
1
+ #include <ruby.h>
2
+ #ifdef HAVE_RUBY_ST_H
3
+ #include <ruby/st.h>
4
+ #else
5
+ #include <st.h>
6
+ #endif
7
+ #include <stdint.h>
8
+ #include <endian.h>
9
+
10
+ static void
11
+ h16(VALUE str, int value)
12
+ {
13
+ uint16_t val = htole16((uint16_t)value);
14
+ char *chr = (char*)&val;
15
+ rb_str_cat(str, chr, 2);
16
+ }
17
+
18
+ static void
19
+ h32(VALUE str, int value)
20
+ {
21
+ uint32_t val = htole32((uint32_t)value);
22
+ char *chr = (char*)&val;
23
+ rb_str_cat(str, chr, 4);
24
+ }
25
+
26
+ static void
27
+ h32_repl(char* str, int value)
28
+ {
29
+ uint32_t val = htole32((uint32_t)value);
30
+ char *chr = (char*)&val;
31
+ str[0] = chr[0];
32
+ str[1] = chr[1];
33
+ str[2] = chr[2];
34
+ str[3] = chr[3];
35
+ }
36
+
37
+ static int
38
+ sum_i(VALUE key, VALUE value, VALUE *sum)
39
+ {
40
+ *sum = INT2FIX(FIX2INT(*sum) + RSTRING_LEN(key) + RSTRING_LEN(value) + 11);
41
+ return ST_CONTINUE;
42
+ }
43
+
44
+ static int
45
+ store_i(VALUE key, VALUE value, VALUE str)
46
+ {
47
+ rb_str_cat(str, "\x96", 1);
48
+ h16(str, RSTRING_LEN(key) + 2);
49
+ rb_str_cat(str, "\x00", 1);
50
+ rb_str_cat(str, RSTRING_PTR(key), RSTRING_LEN(key));
51
+ rb_str_cat(str, "\x00", 1);
52
+
53
+ rb_str_cat(str, "\x96", 1);
54
+ h16(str, RSTRING_LEN(value) + 2);
55
+ rb_str_cat(str, "\x00", 1);
56
+ rb_str_cat(str, RSTRING_PTR(value), RSTRING_LEN(value));
57
+ rb_str_cat(str, "\x00", 1);
58
+
59
+ rb_str_cat(str, "\x1D", 1);
60
+ return ST_CONTINUE;
61
+ }
62
+
63
+ static VALUE
64
+ create_doaction_tag(VALUE params)
65
+ {
66
+ struct buffer_capsule *cap;
67
+ char *buf;
68
+ long buf_size;
69
+ VALUE str, sum;
70
+
71
+ sum = INT2FIX(0);
72
+ rb_hash_foreach(params, sum_i, (st_data_t)&sum);
73
+ buf_size = 2 + 4 + FIX2INT(sum) + 1;
74
+ str = rb_str_buf_new(buf_size);
75
+
76
+ rb_str_cat(str, "\x3F\x03", 2);
77
+ h32(str, FIX2INT(sum) + 1);
78
+ rb_hash_foreach(params, store_i, str);
79
+ rb_str_cat(str, "\x00", 1);
80
+
81
+ return str;
82
+ }
83
+
84
+ static VALUE
85
+ calc_header_size(VALUE swf)
86
+ {
87
+ int nbits = (RSTRING_PTR(swf)[8] >> 3) & 0x1F;
88
+ int rect = 5 + nbits * 4;
89
+ int rect_size = (rect / 8) + (rect % 8 ? 1 : 0);
90
+ return 3 + 1 + 4 + rect_size + 2 + 2 + 5;
91
+ }
92
+
93
+ static VALUE
94
+ swf_embed(VALUE self, VALUE swf, VALUE params)
95
+ {
96
+ VALUE result, doaction_tag;
97
+ char* buf;
98
+ long buf_size, hdr_size, tag_size, swf_size;
99
+
100
+ Check_Type(swf, T_STRING);
101
+ Check_Type(params, T_HASH);
102
+
103
+ swf_size = RSTRING_LEN(swf);
104
+
105
+ doaction_tag = create_doaction_tag(params);
106
+ tag_size = RSTRING_LEN(doaction_tag);
107
+
108
+ buf_size = swf_size + tag_size;
109
+ result = rb_str_buf_new(buf_size);
110
+ buf = RSTRING_PTR(result);
111
+
112
+ hdr_size = calc_header_size(swf);
113
+ rb_str_cat(result, RSTRING_PTR(swf), hdr_size);
114
+ h32_repl(RSTRING_PTR(result) + 4, buf_size);
115
+
116
+ rb_str_cat(result, RSTRING_PTR(doaction_tag), tag_size);
117
+ rb_str_cat(result, RSTRING_PTR(swf) + hdr_size, swf_size - hdr_size);
118
+
119
+ return result;
120
+ }
121
+
122
+ void Init_swf_embed(void)
123
+ {
124
+ VALUE rb_mSwf = rb_define_module("Swf");
125
+ rb_define_singleton_method(rb_mSwf, "embed", swf_embed, 2);
126
+ }
data/lib/swf_embed.rb ADDED
File without changes
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'swf_embed'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SwfEmbed" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swf_embed
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - miyucy
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-09 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Parameter Injector for Flash Lite
38
+ email: miyucy@gmail.com
39
+ executables: []
40
+
41
+ extensions:
42
+ - ext/extconf.rb
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - ext/extconf.rb
54
+ - ext/swf_embed.c
55
+ - lib/swf_embed.rb
56
+ - spec/spec.opts
57
+ - spec/spec_helper.rb
58
+ - spec/swf_embed_spec.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/miyucy/swf_embed
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Parameter Injector for Flash Lite
93
+ test_files:
94
+ - spec/swf_embed_spec.rb
95
+ - spec/spec_helper.rb