jruby 编译,再反编译+简单分析

阅读更多

something.rb内容:

puts "中文";

试运行:

jruby something.rb

编译

jruby -S  jrubyc  something.rb 

 这样就得到了

somthing.class

 

用java来运行这个  .class文件

java -cp ./jruby.jar;.  something

 表现正常!

 

用jad 反编译这个something.class

d:\Files\jad\jad.exe  something.class

 生成了  something.jad ,这是一个.java源文件:

// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Source File Name:   something.rb

import org.jruby.Ruby;
import org.jruby.RubyInstanceConfig;
import org.jruby.ast.executable.AbstractScript;
import org.jruby.ast.executable.RuntimeCache;
import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.runtime.*;
import org.jruby.runtime.builtin.IRubyObject;

public class something extends AbstractScript
{

    private static void setPosition(ThreadContext threadcontext, int i)
    {
        threadcontext.setFileAndLine("something.rb", i);
    }

    public something()
    {
        filename = "something.rb";
        super.runtimeCache = new RuntimeCache();
        initFromDescriptor("puts\uFFFFF\uFFFF\000\000\000\000\000\000\000\000\000\000\000\000\001\001");
        setEncoding(0, "ASCII-8BIT");
        setByteList(0, "\uFFD6\uFFD0\uFFCE\uFFC4", getEncoding0());
    }

    public static IRubyObject __file__(something something1, ThreadContext threadcontext, IRubyObject irubyobject, IRubyObject airubyobject[], Block block)
    {
        return something1.getCallSite0().call(threadcontext, irubyobject, irubyobject, something1.getString0(threadcontext.runtime, 64));
    }

    public IRubyObject __file__(ThreadContext threadcontext, IRubyObject irubyobject, IRubyObject airubyobject[], Block block)
    {
        return __file__(this, threadcontext, irubyobject, airubyobject, block);
    }

    public IRubyObject load(ThreadContext threadcontext, IRubyObject irubyobject, IRubyObject airubyobject[], Block block)
    {
        RuntimeHelpers.preLoad(threadcontext, ",0,0,-2");
        RuntimeHelpers.postLoad(threadcontext);
        return __file__(this, threadcontext, irubyobject, airubyobject, block);
        RuntimeHelpers.postLoad(threadcontext);
        throw ;
    }

    public static void main(String args[])
    {
        something something1;
        RubyInstanceConfig rubyinstanceconfig;
        something1 = new something();
        String s;
        something1.setFilename(s = something.getClassLoader().getResource("something.class").toString());
        rubyinstanceconfig = new RubyInstanceConfig();
        rubyinstanceconfig.setArgv(args);
        rubyinstanceconfig.setScriptFileName(s);
        Ruby ruby;
        something1.load((ruby = Ruby.newInstance(rubyinstanceconfig)).getCurrentContext(), ruby.getTopSelf(), IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
    }
}

 
jruby 编译,再反编译+简单分析_第1张图片

 

可以看出来,即使编译成.class文件 ,依然是解释执行的. 

puts "中文" 代码源文件都还在里面, 只是中文被编译转义了.

 

 

关于创业的好书: Rework中文版.pdf

 ##

  • jruby 编译,再反编译+简单分析_第2张图片
  • 大小: 10 KB
  • 查看图片附件

你可能感兴趣的:(jruby 编译,再反编译+简单分析)