//([B)Ljava/lang/String; //String getHostByAddr(byte[] var1) throws UnknownHostException func i6di_getHostByAddr(frame *rtda.Frame) { vars := frame.LocalVars() t := vars.GetRef(1) buf := t.GoBytes() address := fmt.Sprintf("%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3]) if name, err := net.LookupAddr(address); err == nil { frame.OperandStack().PushRef(rtda.JString(name[0])) } else { panic("not found from lookupAllHostAddr") frame.OperandStack().PushRef(rtda.JString("")) } }
// private native String getUTF8At0(Object o, int i); // (Ljava/lang/Object;I)Ljava/lang/String; func getUTF8At0(frame *rtda.Frame) { cp, index := _getPop(frame) kUtf8 := cp.GetConstant(index).(*rtc.ConstantUtf8) goStr := kUtf8.Str() jStr := rtda.JString(goStr) frame.OperandStack().PushRef(jStr) }
// private static native String getSystemTimeZoneID(String javaHome, String country); // (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; func getSystemTimeZoneID(frame *rtda.Frame) { vars := frame.LocalVars() //javaHomeObj := vars.GetRef(0) countryObj := vars.GetRef(1) //for osx read system timezone file, err := os.Open("/usr/share/zoneinfo/zone.tab") if err != nil { panic(err) } scanner := bufio.NewScanner(file) var timezone string for scanner.Scan() { line := scanner.Text() if line[0] == '#' { continue } zone := strings.Split(line, "\t") if zone[0] == rtda.GoString(countryObj) { timezone = zone[2] break } } location, _ := time.LoadLocation(timezone) zoneID := rtda.JString(location.String()) stack := frame.OperandStack() stack.PushRef(zoneID) }
func mainThreadNotReady(thread *rtda.Thread) bool { stack := thread.CurrentFrame().OperandStack() if _mainThreadGroup == nil { undoExec(thread) threadGroupClass := _classLoader.LoadClass("java/lang/ThreadGroup") _mainThreadGroup = threadGroupClass.NewObj() initMethod := threadGroupClass.GetConstructor("()V") stack.PushRef(_mainThreadGroup) // this thread.InvokeMethod(initMethod) return true } if thread.JThread() == nil { undoExec(thread) threadClass := _classLoader.LoadClass("java/lang/Thread") mainThreadObj := threadClass.NewObjWithExtra(thread) mainThreadObj.SetFieldValue("priority", "I", int32(1)) thread.HackSetJThread(mainThreadObj) initMethod := threadClass.GetConstructor("(Ljava/lang/ThreadGroup;Ljava/lang/String;)V") stack.PushRef(mainThreadObj) // this stack.PushRef(_mainThreadGroup) // group stack.PushRef(rtda.JString("main")) // name thread.InvokeMethod(initMethod) return true } return false }
// private static native String getVersion0(); // ()Ljava/lang/String; func getVersion0(frame *rtda.Frame) { // todo version := rtda.JString("0") stack := frame.OperandStack() stack.PushRef(version) }
// private native String getName0(); // ()Ljava/lang/String; func getName0(frame *rtda.Frame) { class := _popClass(frame) name := class.NameJlsFormat() nameObj := rtda.JString(name) stack := frame.OperandStack() stack.PushRef(nameObj) }
// private static native Properties initProperties(Properties props); // (Ljava/util/Properties;)Ljava/util/Properties; func initProperties(frame *rtda.Frame) { vars := frame.LocalVars() props := vars.GetRef(0) stack := frame.OperandStack() stack.PushRef(props) // public synchronized Object setProperty(String key, String value) setPropMethod := props.Class().GetInstanceMethod("setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;") thread := frame.Thread() for key, val := range _sysProps() { jKey := rtda.JString(key) jVal := rtda.JString(val) args := []interface{}{props, jKey, jVal} thread.InvokeMethodWithShim(setPropMethod, args) } }
func createArgs() *heap.Object { jArgs := make([]*heap.Object, len(_args)) for i, arg := range _args { jArgs[i] = rtda.JString(arg) } return heap.NewRefArray2(_classLoader.JLStringClass(), jArgs) }
func _createEnclosintMethodInfo(classLoader *rtc.ClassLoader, emInfo *rtc.EnclosingMethod) *rtc.Obj { if emInfo == nil { return nil } enclosingClass := classLoader.LoadClass(emInfo.ClassName()) enclosingClassObj := enclosingClass.JClass() var methodNameObj, methodDescriptorObj *rtc.Obj if emInfo.MethodName() != "" { methodNameObj = rtda.JString(emInfo.MethodName()) methodDescriptorObj = rtda.JString(emInfo.MethodDescriptor()) } else { methodNameObj, methodDescriptorObj = nil, nil } objs := []*rtc.Obj{enclosingClassObj, methodNameObj, methodDescriptorObj} return rtc.NewRefArray2(classLoader.JLObjectClass(), objs) // Object[] }
// private static native String getSystemPackage0(String name); // (Ljava/lang/String;)Ljava/lang/String; func getSystemPackage0(frame *rtda.Frame) { // vars := frame.LocalVars() // name := vars.GetRef(0) sysPkg := frame.ClassLoader().JLObjectClass().LoadedFrom().String() sysPkgObj := rtda.JString(sysPkg) stack := frame.OperandStack() stack.PushRef(sysPkgObj) }
func createStackTraceElementObj(ste *StackTraceElement, frame *rtda.Frame) *heap.Object { declaringClass := rtda.JString(ste.declaringClass) methodName := rtda.JString(ste.methodName) fileName := rtda.JString(ste.fileName) lineNumber := int32(ste.lineNumber) /* public StackTraceElement(String declaringClass, String methodName, String fileName, int lineNumber) */ steClass := frame.ClassLoader().LoadClass("java/lang/StackTraceElement") steObj := steClass.NewObj() // todo: call <init> steObj.SetFieldValue("declaringClass", "Ljava/lang/String;", declaringClass) steObj.SetFieldValue("methodName", "Ljava/lang/String;", methodName) steObj.SetFieldValue("fileName", "Ljava/lang/String;", fileName) steObj.SetFieldValue("lineNumber", "I", lineNumber) return steObj }
// private native String canonicalize0(String path) throws IOException; // (Ljava/lang/String;)Ljava/lang/String; func canonicalize0(frame *rtda.Frame) { vars := frame.LocalVars() pathStr := vars.GetRef(1) // todo path := rtda.GoString(pathStr) path2 := filepath.Clean(path) if path2 != path { pathStr = rtda.JString(path2) } stack := frame.OperandStack() stack.PushRef(pathStr) }
// private native String getGenericSignature0(); // ()Ljava/lang/String; func getGenericSignature0(frame *rtda.Frame) { class := _popClass(frame) if class == nil { panic("illegal class") } // Return null for arrays and primatives if !class.IsPrimitive() { signature := class.Signature() if signature == "" { frame.OperandStack().PushNull() } else { frame.OperandStack().PushRef(rtda.JString(signature)) } return } frame.OperandStack().PushNull() }
// private native Method[] getDeclaredMethods0(boolean publicOnly); // (Z)[Ljava/lang/reflect/Method; func getDeclaredMethods0(frame *rtda.Frame) { vars := frame.LocalVars() classObj := vars.GetThis() publicOnly := vars.GetBoolean(1) class := classObj.Extra().(*rtc.Class) methods := class.GetMethods(publicOnly) methodCount := uint(len(methods)) methodClass := rtc.BootLoader().LoadClass("java/lang/reflect/Method") methodArr := methodClass.NewArray(methodCount) stack := frame.OperandStack() stack.PushRef(methodArr) // create method objs if methodCount > 0 { thread := frame.Thread() methodObjs := methodArr.Refs() methodConstructor := methodClass.GetConstructor(_methodConstructorDescriptor) for i, method := range methods { methodObj := methodClass.NewObjWithExtra(method) methodObjs[i] = methodObj // init methodObj thread.InvokeMethodWithShim(methodConstructor, []interface{}{ methodObj, // this classObj, // declaringClass rtda.JString(method.Name()), // name getParameterTypeArr(method), // parameterTypes getReturnType(method), // returnType getExceptionTypeArr(method), // checkedExceptions int32(method.GetAccessFlags()), // modifiers int32(method.Slot()), // slot getSignatureStr(method.Signature()), // signature getAnnotationByteArr(method.AnnotationData()), // annotations getAnnotationByteArr(method.ParameterAnnotationData()), // parameterAnnotations getAnnotationByteArr(method.AnnotationDefaultData()), // annotationDefault }) } } }
func _ldc(frame *rtda.Frame, index uint) { stack := frame.OperandStack() cp := frame.ConstantPool() c := cp.GetConstant(index) switch c.(type) { case int32: stack.PushInt(c.(int32)) case float32: stack.PushFloat(c.(float32)) case string: internedStr := rtda.JString(c.(string)) stack.PushRef(internedStr) case *heap.ConstantClass: kClass := c.(*heap.ConstantClass) classObj := kClass.Class().JClass() stack.PushRef(classObj) default: // todo // ref to MethodType or MethodHandle jutil.Panicf("todo: ldc! %v", c) } }
// private native Field[] getDeclaredFields0(boolean publicOnly); // (Z)[Ljava/lang/reflect/Field; func getDeclaredFields0(frame *rtda.Frame) { vars := frame.LocalVars() classObj := vars.GetThis() publicOnly := vars.GetBoolean(1) class := classObj.Extra().(*heap.Class) fields := class.GetFields(publicOnly) fieldCount := uint(len(fields)) fieldClass := heap.BootLoader().LoadClass("java/lang/reflect/Field") fieldArr := heap.NewRefArray(fieldClass, fieldCount) stack := frame.OperandStack() stack.PushRef(fieldArr) if fieldCount > 0 { thread := frame.Thread() fieldObjs := fieldArr.Refs() fieldConstructor := fieldClass.GetConstructor(_fieldConstructorDescriptor) for i, goField := range fields { fieldObj := fieldClass.NewObjWithExtra(goField) fieldObjs[i] = fieldObj // init fieldObj thread.InvokeMethodWithShim(fieldConstructor, []interface{}{ fieldObj, // this classObj, // declaringClass rtda.JString(goField.Name()), // name goField.Type().JClass(), // type int32(goField.GetAccessFlags()), // modifiers int32(goField.SlotId()), // slot getSignatureStr(goField.Signature()), // signature getAnnotationByteArr(goField.AnnotationData()), // annotations }) } } }
func getSignatureStr(signature string) *heap.Object { if signature != "" { return rtda.JString(signature) } return nil }
func getSignatureStr(signature string) *rtc.Obj { if signature != "" { return rtda.JString(signature) } return nil }