furnace-avm2 0.0.2 → 0.0.3

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.
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- furnace-avm2 (0.0.1)
5
- furnace
4
+ furnace-avm2 (0.0.2)
5
+ furnace (>= 0.0.4)
6
6
  trollop
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- furnace (0.0.3)
11
+ furnace (0.0.4)
12
12
  trollop (1.16.2)
13
13
 
14
14
  PLATFORMS
@@ -24,6 +24,10 @@ module AVM2::ABC
24
24
 
25
25
  abc_array_of :trait, :nested, :class => TraitInfo
26
26
 
27
+ def klass
28
+ root.klasses[root.instances.index(self)]
29
+ end
30
+
27
31
  def to_astlet
28
32
  if interface?
29
33
  root = AST::Node.new(:interface)
@@ -1,7 +1,19 @@
1
1
  module AVM2::ABC
2
2
  class KlassInfo < Record
3
+ include RecordWithTraits
4
+
3
5
  root_ref :initializer, :method
4
6
 
5
7
  abc_array_of :trait, :nested, :class => TraitInfo
8
+
9
+ def to_astlet
10
+ root = AST::Node.new(:klass)
11
+
12
+ if traits.any?
13
+ root.children << AST::Node.new(:traits, traits.map(&:to_astlet))
14
+ end
15
+
16
+ root.normalize_hierarchy!
17
+ end
6
18
  end
7
19
  end
@@ -27,9 +27,8 @@ module AVM2::ABC
27
27
 
28
28
  def to_astlet(index, name=nil)
29
29
  root = AST::Node.new(:method)
30
- root.metadata = { origin: self }
30
+ root.metadata = { method: self, label: index }
31
31
 
32
- root.children << index
33
32
  root.children << name || self.name
34
33
 
35
34
  if return_type
@@ -1,26 +1,6 @@
1
1
  module AVM2::ABC
2
2
  class OptionDetail < Record
3
- XlatTable = {
4
- :Int => 0x03,
5
- :UInt => 0x04,
6
- :Double => 0x06,
7
- :Utf8 => 0x01,
8
- :True => 0x0B,
9
- :False => 0x0A,
10
- :Null => 0x0C,
11
- :Undefined => 0x00,
12
- :Namespace => 0x08,
13
- :PackageNamespace => 0x16,
14
- :PackageInternalNs => 0x17,
15
- :ProtectedNamespace => 0x18,
16
- :ExplicitNamespace => 0x19,
17
- :StaticProtectedNs => 0x1A,
18
- :PrivateNs => 0x05,
19
- }
20
-
21
- vuint30 :val
22
-
23
- uint8 :kind_raw
24
- xlat_field :kind
3
+ vuint30 :value_idx
4
+ uint8 :value_kind_raw
25
5
  end
26
6
  end
@@ -1,9 +1,27 @@
1
1
  module AVM2::ABC
2
2
  module RecordWithTraits
3
3
  TraitInfo::XlatTable.keys.each do |trait_type|
4
- define_method :"#{trait_type.to_s.downcase}_traits" do
4
+ basename = trait_type.to_s.downcase
5
+
6
+ define_method :"#{basename}_traits" do
5
7
  traits.select { |trait| trait.kind == trait_type }
6
8
  end
9
+
10
+ define_method :"#{basename}_trait" do |name|
11
+ case name
12
+ when String
13
+ traits.find { |trait| trait.name.to_s == name }
14
+ when AST::Node
15
+ traits.find { |trait| trait.name.to_astlet == name }
16
+ else
17
+ traits.find { |trait| trait.name == name }
18
+ end
19
+ end
20
+
21
+ define_method :"#{basename}_trait!" do |name|
22
+ send(:"#{basename}_trait", name) or
23
+ raise "trait #{name} not found"
24
+ end
7
25
  end
8
26
 
9
27
  def codes_to_ast
@@ -1,13 +1,71 @@
1
1
  module AVM2::ABC
2
2
  class TraitSlot < Record
3
- vuint30 :idx
4
- const_ref :type, :multiname
3
+ XlatTable = {
4
+ :Int => 0x03,
5
+ :UInt => 0x04,
6
+ :Double => 0x06,
7
+ :Utf8 => 0x01,
8
+ :True => 0x0B,
9
+ :False => 0x0A,
10
+ :Null => 0x0C,
11
+ :Undefined => 0x00,
12
+ :Namespace => 0x08,
13
+ :PackageNamespace => 0x16,
14
+ :PackageInternalNs => 0x17,
15
+ :ProtectedNamespace => 0x18,
16
+ :ExplicitNamespace => 0x19,
17
+ :StaticProtectedNs => 0x1A,
18
+ :PrivateNs => 0x05,
19
+ }
5
20
 
6
- vuint30 :value_idx
7
- uint8 :value_kind, :if => lambda { value_idx != 0 }
21
+ vuint30 :idx
22
+ const_ref :type, :multiname
23
+
24
+ vuint30 :value_idx
25
+
26
+ uint8 :value_kind_raw, :if => lambda { value_idx != 0 }
27
+ xlat_field :value_kind
8
28
 
9
29
  def to_astlet(trait)
10
- AST::Node.new(:slot, [ trait.name.to_astlet, type.to_astlet, idx ])
30
+ AST::Node.new(:slot, [ (trait.name ? trait.name.to_astlet : nil), (type ? type.to_astlet : nil), value, idx ])
31
+ end
32
+
33
+ def value
34
+ if value_idx > 0
35
+ case value_kind
36
+ when :Int
37
+ AST::Node.new(:integer, [ root.constant_pool.ints[value_idx - 1] ])
38
+ when :UInt
39
+ AST::Node.new(:integer, [ root.constant_pool.uints[value_idx - 1] ])
40
+ when :Double
41
+ AST::Node.new(:integer, [ root.constant_pool.doubles[value_idx - 1] ])
42
+ when :Utf8
43
+ AST::Node.new(:integer, [ root.constant_pool.strings[value_idx - 1] ])
44
+ when :True
45
+ AST::Node.new(:true)
46
+ when :False
47
+ AST::Node.new(:false)
48
+ when :Null
49
+ AST::Node.new(:null)
50
+ when :Undefined
51
+ AST::Node.new(:undefined)
52
+ else
53
+ raise "unknown value kind #{value_kind}"
54
+ end
55
+ else
56
+ nil
57
+ end
58
+ end
59
+
60
+ def ruby_value
61
+ astlet_value = self.value
62
+ if astlet_value
63
+ if astlet_value.children.count > 0
64
+ astlet_value.children.first
65
+ else
66
+ astlet_value.name
67
+ end
68
+ end
11
69
  end
12
70
  end
13
71
  end
@@ -1,6 +1,7 @@
1
1
  module AVM2::ABC
2
2
  class AS3Equals < ArithmeticOpcode
3
3
  instruction 0xab
4
+ ast_type :==
4
5
 
5
6
  consume 2
6
7
  produce 1
@@ -1,6 +1,7 @@
1
1
  module AVM2::ABC
2
2
  class AS3GreaterEquals < ArithmeticOpcode
3
3
  instruction 0xb0
4
+ ast_type :>=
4
5
 
5
6
  consume 2
6
7
  produce 1
@@ -1,6 +1,7 @@
1
1
  module AVM2::ABC
2
2
  class AS3GreaterThan < ArithmeticOpcode
3
3
  instruction 0xaf
4
+ ast_type :>
4
5
 
5
6
  consume 2
6
7
  produce 1
@@ -1,6 +1,7 @@
1
1
  module AVM2::ABC
2
2
  class AS3LessEquals < ArithmeticOpcode
3
3
  instruction 0xae
4
+ ast_type :<=
4
5
 
5
6
  consume 2
6
7
  produce 1
@@ -1,6 +1,7 @@
1
1
  module AVM2::ABC
2
2
  class AS3LessThan < ArithmeticOpcode
3
3
  instruction 0xad
4
+ ast_type :<
4
5
 
5
6
  consume 2
6
7
  produce 1
@@ -1,6 +1,7 @@
1
1
  module AVM2::ABC
2
2
  class AS3Not < ArithmeticOpcode
3
3
  instruction 0x96
4
+ ast_type :!
4
5
 
5
6
  consume 1
6
7
  produce 1
@@ -1,6 +1,7 @@
1
1
  module AVM2::ABC
2
2
  class AS3StrictEquals < ArithmeticOpcode
3
3
  instruction 0xac
4
+ ast_type :===
4
5
 
5
6
  consume 2
6
7
  produce 1
@@ -47,6 +47,8 @@ module AVM2::ABC
47
47
  MAP[encoding] = self
48
48
  end
49
49
 
50
+ define_property :ast_type
51
+
50
52
  define_property :consume_context, :accessor => :consumes_context
51
53
  define_property :consume, :accessor => :consumes
52
54
  define_property :produce, :accessor => :produces
@@ -31,8 +31,20 @@ module AVM2
31
31
 
32
32
  # (if-* a b) -> (*' a b)
33
33
  IF_MAPPING = {
34
- :eq => [false, :equals],
35
- :nge => [true, :greaterequals],
34
+ :eq => [false, :==],
35
+ :ne => [true, :==],
36
+ :ge => [false, :>=],
37
+ :nge => [true, :>=],
38
+ :gt => [false, :>],
39
+ :ngt => [true, :>],
40
+ :le => [false, :<=],
41
+ :nle => [true, :<=],
42
+ :lt => [false, :<],
43
+ :nlt => [true, :<],
44
+ :stricteq => [false, :===],
45
+ :strictne => [true, :===],
46
+ :true => [false, :expand],
47
+ :false => [true, :expand],
36
48
  }
37
49
  IF_MAPPING.each do |cond, (reverse, comp)|
38
50
  define_method :"on_if_#{cond}" do |node|
@@ -1,3 +1,3 @@
1
1
  module AVM2
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: furnace-avm2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-28 00:00:00.000000000 Z
12
+ date: 2012-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: furnace
16
- requirement: &84387770 !ruby/object:Gem::Requirement
16
+ requirement: &79918900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84387770
24
+ version_requirements: *79918900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: trollop
27
- requirement: &84385470 !ruby/object:Gem::Requirement
27
+ requirement: &79918360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *84385470
35
+ version_requirements: *79918360
36
36
  description: furnace-avm2 allows one to load, modify and write backFlash ActionScript3
37
37
  bytecode. It can also decompile it.
38
38
  email: