class Java::Method
Constants
- ACC_ABSTRACT
- ACC_BRIDGE
- ACC_FINAL
- ACC_NATIVE
- ACC_PRIVATE
- ACC_PROTECTED
- ACC_PUBLIC
- ACC_STATIC
- ACC_STRICT
- ACC_SYNCHRONIZED
- ACC_SYNTHETIC
- ACC_VARARGS
Attributes
flags[R]
name[R]
vm_signature[R]
Public Class Methods
new(flags, name, vm_signature, annotations)
click to toggle source
Calls superclass method
Java::Annotatable::new
# File lib/java_dissassembler/method.rb, line 18 def initialize(flags, name, vm_signature, annotations) super(annotations) @flags = flags @name = name @vm_signature = vm_signature end
Public Instance Methods
is_abstract?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 61 def is_abstract? (@flags & ACC_ABSTRACT) != 0 end
is_bridge?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 49 def is_bridge? (@flags & ACC_BRIDGE) != 0 end
is_final?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 41 def is_final? (@flags & ACC_FINAL) != 0 end
is_native?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 57 def is_native? (@flags & ACC_NATIVE) != 0 end
is_private?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 29 def is_private? (@flags & ACC_PRIVATE) != 0 end
is_protected?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 33 def is_protected? (@flags & ACC_PROTECTED) != 0 end
is_public?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 25 def is_public? (@flags & ACC_PUBLIC) != 0 end
is_static?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 37 def is_static? (@flags & ACC_STATIC) != 0 end
is_strict?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 65 def is_strict? (@flags & ACC_STRICT) != 0 end
is_synchronized?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 45 def is_synchronized? (@flags & ACC_SYNCHRONIZED) != 0 end
is_synthetic?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 69 def is_synthetic? (@flags & ACC_SYNTHETIC) != 0 end
is_varargs?()
click to toggle source
# File lib/java_dissassembler/method.rb, line 53 def is_varargs? (@flags & ACC_VARARGS) != 0 end
java_params()
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 100 def java_params java_signature.drop(1) end
java_return_type()
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 104 def java_return_type java_signature.at(0) end
jni_c_parameters(prefix = "param")
click to toggle source
jni_c_return_type()
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 14 def jni_c_return_type java_to_c(java_return_type) end
jni_convert_c_to_jni(prefix = "param")
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 23 def jni_convert_c_to_jni(prefix = "param") conversions = Array.new java_params.each_with_index do |param, i| case param when "java.lang.String" conversions << "jstring jni#{prefix}#{i} = env->NewStringUTF(#{prefix}#{i})" end end conversions end
jni_convert_jni_to_c(prefix = "param")
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 61 def jni_convert_jni_to_c(prefix = "param") conversions = Array.new java_params.each_with_index do |param, i| case param when "java.lang.String" conversions << "const char* c#{prefix}#{i} = env->GetStringUTFChars(#{prefix}#{i}, nullptr /* iscopy */)" end end conversions end
jni_mangled_name(klass_name, is_override)
click to toggle source
JNI Call C from Java
¶ ↑
# File lib/java_dissassembler/erb_helper.rb, line 49 def jni_mangled_name(klass_name, is_override) mangled_name = mangle(name) mangled_name << "__#{mangle(vm_signature_params)}" if is_override and not vm_signature_params.empty? "Java_#{klass_name.gsub(".", "_")}_#{mangled_name}" end
jni_method_call()
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 34 def jni_method_call "Call#{is_static? ? "Static" : ""}#{java_return_type.capitalize}Method" end
jni_method_call_parameters(prefix = "param")
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 38 def jni_method_call_parameters(prefix = "param") java_params.enum_for(:each_with_index).map do |param, i| case param when "java.lang.String" then "jni#{prefix}#{i}" else "#{prefix}#{i}" end end end
jni_native_method_converted_parameters(prefix = "param")
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 72 def jni_native_method_converted_parameters(prefix = "param") conversions = Array.new java_params.each_with_index do |param, i| case param when "java.lang.String" conversions << "c#{prefix}#{i}" else conversions << "#{prefix}#{i}" end end conversions end
jni_native_method_parameters(prefix = "param")
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 55 def jni_native_method_parameters(prefix = "param") native_method_parameters = ["JNIEnv* env"] native_method_parameters << (is_static? ? "jobject caller" : "jclass klass") native_method_parameters + java_params.enum_for(:each_with_index).map { |param,i| "#{java_to_jni(param)} #{prefix}#{i}" } end
jni_params()
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 108 def jni_params java_params.map { |java_type| java_to_jni(java_type) } end
jni_release_converted_to_c(prefix = "param")
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 85 def jni_release_converted_to_c(prefix = "param") releases = Array.new java_params.each_with_index do |param, i| case param when "java.lang.String" releases << "env->ReleaseStringUTFChars(#{prefix}#{i}, c#{prefix}#{i})" end end releases end
jni_return_type()
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 18 def jni_return_type return "" if java_return_type == "void" java_to_jni(java_return_type) end
jni_return_value()
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 112 def jni_return_value java_to_jni(java_return_type) end
vm_signature_params()
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 96 def vm_signature_params vm_signature.match(/^\(([^\)]*)\)/)[1] end
Private Instance Methods
java_signature()
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 118 def java_signature types = vm_signature.scan(/(\[?([ZBCSIJFDV]|L[^;]*;))/).map do |match| is_array = match[0].start_with? "[" val = vm_to_java(match[0]) if is_array val << "[]" val[1..-1] else val end end back = types.pop types.unshift(back) end
java_to_c(java_type)
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 149 def java_to_c(java_type) case java_type when "boolean" then "bool" when "byte" then "byte" when "char" then "char" when "short" then "short" when "int" then "int" when "long" then "long" when "float" then "float" when "double" then "double" when "java.lang.String" then "const char*" when "void" then "void" else "jobject" end end
java_to_jni(java_type)
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 164 def java_to_jni(java_type) case java_type when "boolean" then "jboolean" when "byte" then "jbyte" when "char" then "jchar" when "short" then "jshort" when "int" then "jint" when "long" then "jlong" when "float" then "jfloat" when "double" then "jdouble" when "java.lang.String" then "jstring" when "void" then raise "Cannot convert `void' to JNI type" else "jobject" end end
mangle(str)
click to toggle source
See docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html Table 2-1)
# File lib/java_dissassembler/erb_helper.rb, line 180 def mangle(str) mangled_name = str.gsub("_", "_1") .gsub(";", "_2") .gsub("[", "_3") .gsub("/", "_") mangled_name.codepoints.map do |codepoint| case when codepoint <= 0xFF then codepoint.chr else "_0#{"%04x" % codepoint}" end end.join end
vm_to_java(vm_type)
click to toggle source
# File lib/java_dissassembler/erb_helper.rb, line 133 def vm_to_java(vm_type) case vm_type when "Z" then "boolean" when "B" then "byte" when "C" then "char" when "S" then "short" when "I" then "int" when "J" then "long" when "F" then "float" when "D" then "double" when "V" then "void" else vm_type.gsub("L", "").gsub(";", "").gsub("/", ".") end end