ruby-internal 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'pp'
4
+ require 'internal/node/pp'
5
+ require 'optparse'
6
+
7
+ dash_e = []
8
+
9
+ args = ARGV
10
+
11
+ opts = OptionParser.new do |opts|
12
+ opts.banner = "Usage: #{$0} [switches] [--] [programfile] [arguments]"
13
+ opts.summary_width = 15
14
+ opts.summary_indent = ' '
15
+
16
+ opts.on(
17
+ "-e line",
18
+ "one line of script. Several -e's allowed. Omit [programfile]") do |line|
19
+ dash_e << line
20
+ end
21
+
22
+ opts.order!(args) do |arg|
23
+ args.unshift arg
24
+ opts.terminate
25
+ end
26
+ end
27
+
28
+ if dash_e.size > 0 then
29
+ str = dash_e.join("\n")
30
+ else
31
+ filename = ARGV[0]
32
+ str = File.read(filename)
33
+ end
34
+
35
+ node = Node.compile_string(str)
36
+
37
+ pp node
38
+
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'internal/node/obfusc'
4
+
5
+ filename = ARGV[0]
6
+
7
+ if not filename then
8
+ puts "Usage: #{$0} <filename>"
9
+ exit 1
10
+ fi
11
+
12
+ str = File.read(filename)
13
+
14
+ node = Node.compile_string(str)
15
+
16
+ # TODO: Should the whole program be obfuscated or just this module?
17
+ str = node.obfusc()
18
+
19
+ puts str
20
+
@@ -2847,6 +2847,9 @@ static VALUE node_vid(VALUE self)
2847
2847
  }
2848
2848
 
2849
2849
  /*
2850
+ * call-seq:
2851
+ * Node.members => Array
2852
+ *
2850
2853
  * Return an array of strings containing the names of the node class's
2851
2854
  * members.
2852
2855
  */
@@ -2873,6 +2873,9 @@ static VALUE node_vid(VALUE self)
2873
2873
  }
2874
2874
 
2875
2875
  /*
2876
+ * call-seq:
2877
+ * Node.members => Array
2878
+ *
2876
2879
  * Return an array of strings containing the names of the node class's
2877
2880
  * members.
2878
2881
  */
@@ -2873,6 +2873,9 @@ static VALUE node_vid(VALUE self)
2873
2873
  }
2874
2874
 
2875
2875
  /*
2876
+ * call-seq:
2877
+ * Node.members => Array
2878
+ *
2876
2879
  * Return an array of strings containing the names of the node class's
2877
2880
  * members.
2878
2881
  */
@@ -2873,6 +2873,9 @@ static VALUE node_vid(VALUE self)
2873
2873
  }
2874
2874
 
2875
2875
  /*
2876
+ * call-seq:
2877
+ * Node.members => Array
2878
+ *
2876
2879
  * Return an array of strings containing the names of the node class's
2877
2880
  * members.
2878
2881
  */
@@ -2873,6 +2873,9 @@ static VALUE node_vid(VALUE self)
2873
2873
  }
2874
2874
 
2875
2875
  /*
2876
+ * call-seq:
2877
+ * Node.members => Array
2878
+ *
2876
2879
  * Return an array of strings containing the names of the node class's
2877
2880
  * members.
2878
2881
  */
@@ -2873,6 +2873,9 @@ static VALUE node_vid(VALUE self)
2873
2873
  }
2874
2874
 
2875
2875
  /*
2876
+ * call-seq:
2877
+ * Node.members => Array
2878
+ *
2876
2879
  * Return an array of strings containing the names of the node class's
2877
2880
  * members.
2878
2881
  */
@@ -2872,6 +2872,9 @@ static VALUE node_vid(VALUE self)
2872
2872
  }
2873
2873
 
2874
2874
  /*
2875
+ * call-seq:
2876
+ * Node.members => Array
2877
+ *
2875
2878
  * Return an array of strings containing the names of the node class's
2876
2879
  * members.
2877
2880
  */
@@ -2872,6 +2872,9 @@ static VALUE node_vid(VALUE self)
2872
2872
  }
2873
2873
 
2874
2874
  /*
2875
+ * call-seq:
2876
+ * Node.members => Array
2877
+ *
2875
2878
  * Return an array of strings containing the names of the node class's
2876
2879
  * members.
2877
2880
  */
@@ -2872,6 +2872,9 @@ static VALUE node_vid(VALUE self)
2872
2872
  }
2873
2873
 
2874
2874
  /*
2875
+ * call-seq:
2876
+ * Node.members => Array
2877
+ *
2875
2878
  * Return an array of strings containing the names of the node class's
2876
2879
  * members.
2877
2880
  */
@@ -2827,6 +2827,9 @@ static VALUE node_vid(VALUE self)
2827
2827
  }
2828
2828
 
2829
2829
  /*
2830
+ * call-seq:
2831
+ * Node.members => Array
2832
+ *
2830
2833
  * Return an array of strings containing the names of the node class's
2831
2834
  * members.
2832
2835
  */
@@ -2827,6 +2827,9 @@ static VALUE node_vid(VALUE self)
2827
2827
  }
2828
2828
 
2829
2829
  /*
2830
+ * call-seq:
2831
+ * Node.members => Array
2832
+ *
2830
2833
  * Return an array of strings containing the names of the node class's
2831
2834
  * members.
2832
2835
  */
@@ -491,6 +491,9 @@ static VALUE node_#{node_elem_name}(VALUE self)
491
491
  END
492
492
 
493
493
  /*
494
+ * call-seq:
495
+ * Node.members => Array
496
+ *
494
497
  * Return an array of strings containing the names of the node class's
495
498
  * members.
496
499
  */
@@ -0,0 +1,25 @@
1
+ require 'internal/node'
2
+
3
+ class Node
4
+ def obfusc(begin_nodes=[])
5
+ n = self
6
+
7
+ # The outputted code must do the following:
8
+ # 1. Evaluate each of the begin nodes (BEGIN {...}).
9
+ # 2. Evaluate the main node.
10
+ return <<-END
11
+ require 'internal/node'
12
+ if RUBY_VERSION != "#{RUBY_VERSION}" then
13
+ $stderr.puts "Wrong Ruby version; please use #{RUBY_VERSION}"
14
+ exit 1
15
+ end
16
+ begin_nodes = Marshal.load(#{Marshal.dump(begin_nodes).inspect})
17
+ n = Marshal.load(#{Marshal.dump(n).inspect})
18
+ begin_nodes.each do |node|
19
+ node.eval(self)
20
+ end
21
+ n.eval(self)
22
+ END
23
+ end
24
+ end
25
+
@@ -20,26 +20,7 @@
20
20
  # $ ruby test2.rb
21
21
  # 2
22
22
 
23
- require 'internal/node'
24
-
25
- def obfusc(begin_nodes, n)
26
- # The outputted code must do the following:
27
- # 1. Evaluate each of the begin nodes (BEGIN {...}).
28
- # 2. Evaluate the main node.
29
- puts <<-END
30
- require 'internal/node'
31
- if RUBY_VERSION != "#{RUBY_VERSION}" then
32
- $stderr.puts "Wrong Ruby version; please use #{RUBY_VERSION}"
33
- exit 1
34
- end
35
- begin_nodes = Marshal.load(#{Marshal.dump(begin_nodes).inspect})
36
- n = Marshal.load(#{Marshal.dump(n).inspect})
37
- begin_nodes.each do |node|
38
- node.eval(self)
39
- end
40
- n.eval(self)
41
- END
42
- end
23
+ require 'internal/node/obfusc'
43
24
 
44
25
  begin_nodes = []
45
26
  set_trace_func proc {
@@ -50,7 +31,8 @@ set_trace_func proc {
50
31
  end
51
32
  if n then
52
33
  # TODO: Do I need to include ruby_dyna_vars?
53
- obfusc(begin_nodes, n)
34
+ str = n.obfusc(begin_nodes)
35
+ puts str
54
36
  exit
55
37
  end
56
38
  }
data/pre-setup.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  alias generate_files_dir_lib noop
2
+ alias generate_files_dir_bin noop
2
3
 
3
4
  def generate_files_dir_ext(rel)
4
5
  return unless extdir?(curr_srcdir())
@@ -0,0 +1,9 @@
1
+ require 'internal/node'
2
+
3
+ class Foo
4
+ def foo; puts "this is a test..."; end
5
+ end
6
+
7
+ s = Marshal.dump(Foo)
8
+ p Marshal.load(s) #=> Foo
9
+
data/sample/irbrc ADDED
@@ -0,0 +1,4 @@
1
+ require 'pp'
2
+ require 'internal/node/pp'
3
+ require 'internal/classtree'
4
+ require 'internal/method/signature'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-internal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Brannan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-05 00:00:00 -05:00
12
+ date: 2009-12-06 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -18,8 +18,9 @@ description: |
18
18
  internal data structures.
19
19
 
20
20
  email: curlypaul924@gmail.com
21
- executables: []
22
-
21
+ executables:
22
+ - ruby-internal-node-dump
23
+ - ruby-internal-obfuscate
23
24
  extensions:
24
25
  - Rakefile
25
26
  extra_rdoc_files:
@@ -43,6 +44,7 @@ files:
43
44
  - lib/internal/node/as_expression.rb
44
45
  - lib/internal/node/as_code.rb
45
46
  - lib/internal/node/pp.rb
47
+ - lib/internal/node/obfusc.rb
46
48
  - lib/internal/node/to_a.rb
47
49
  - lib/internal/binding.rb
48
50
  - lib/internal/method.rb
@@ -384,6 +386,10 @@ files:
384
386
  - TODO
385
387
  - metaconfig
386
388
  - Rakefile
389
+ - bin/ruby-internal-node-dump
390
+ - bin/ruby-internal-obfuscate
391
+ - sample/dump_class.rb
392
+ - sample/irbrc
387
393
  has_rdoc: true
388
394
  homepage: http://rubystuff.org/nodewrap/
389
395
  licenses: []