Remember to use the bytecode modification method to solve java. lang. NoSuchMethodError, bytecode

Source: Internet
Author: User

Remember to use the bytecode modification method to solve java. lang. NoSuchMethodError, bytecode

Rabbit International sdk ane

The recharge interface will crash when you select rabbit currency recharge,

Observe logcat, NoSuchMethodError: com. tutu. common. a. B. getContext because there is no way to find it

04-19 10:10:54.224: E/AndroidRuntime(20315): FATAL EXCEPTION: main04-19 10:10:54.224: E/AndroidRuntime(20315): Process: com.tutusdk.global.demo, PID: 2031504-19 10:10:54.224: E/AndroidRuntime(20315): java.lang.NoSuchMethodError: com.tutu.common.a.b.getContext04-19 10:10:54.224: E/AndroidRuntime(20315):     at com.tutu.common.a.b.a(TutuAlertDialog.java:78)04-19 10:10:54.224: E/AndroidRuntime(20315):     at com.tutu.common.a.b.onCreateView(TutuAlertDialog.java:66)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.os.Handler.handleCallback(Handler.java:733)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.os.Handler.dispatchMessage(Handler.java:95)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.os.Looper.loop(Looper.java:136)04-19 10:10:54.224: E/AndroidRuntime(20315):     at android.app.ActivityThread.main(ActivityThread.java:5113)04-19 10:10:54.224: E/AndroidRuntime(20315):     at java.lang.reflect.Method.invokeNative(Native Method)04-19 10:10:54.224: E/AndroidRuntime(20315):     at java.lang.reflect.Method.invoke(Method.java:515)04-19 10:10:54.224: E/AndroidRuntime(20315):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)04-19 10:10:54.224: E/AndroidRuntime(20315):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)04-19 10:10:54.224: E/AndroidRuntime(20315):     at dalvik.system.NativeStart.main(Native Method)

You can use the jar package in the attachment to practice. Download the jar package after zip extraction. Find B class with jd-gui decompilation, introduce a more useful decompilation tool: apktoolbox, download: http://www.52pojie.cn/thread-429318-1-1.html

package com.tutu.common.a;import android.graphics.drawable.ColorDrawable;import android.os.Bundle;import android.support.v4.app.DialogFragment;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.widget.Button;import android.widget.TextView;import com.feng.android.i.e;import com.feng.android.i.f;/* compiled from: TutuAlertDialog */public class b extends DialogFragment {    private TextView a;    private Button b;    private Button c;    private String d;    private String e;    private String f;    private String g;    private a h;    /* compiled from: TutuAlertDialog */    public interface a {        void c(String str);        void c_(String str);    }    public void onCreate(Bundle bundle) {        super.onCreate(bundle);    }    public static b a(String str, String str2, String str3, String str4, a aVar) {        b bVar = new b();        Bundle bundle = new Bundle();        bundle.putString("left_text", str);        bundle.putString("right_text", str2);        bundle.putString("dialog_tips", str3);        bundle.putString("dialog_tag", str4);        bVar.setArguments(bundle);        bVar.a(aVar);        return bVar;    }    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {        getDialog().requestWindowFeature(1);        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));        View inflate = layoutInflater.inflate(e.c(getActivity(), "tutu_alert_dialog_layout"), viewGroup, false);        getDialog().getWindow().setGravity(17);        if (getArguments() != null) {            this.d = getArguments().getString("left_text");            this.e = getArguments().getString("right_text");            this.f = getArguments().getString("dialog_tips");            this.g = getArguments().getString("dialog_tag");        }        a(inflate);        setCancelable(false);        return inflate;    }    public void a(a aVar) {        this.h = aVar;    }    private void a(View view) {        this.b = (Button) view.findViewById(e.a(getActivity(), "tutu_alert_dialog_ignore_btn"));        this.c = (Button) view.findViewById(e.a(getActivity(), "tutu_alert_dialog_recharge_btn"));        this.a = (TextView) view.findViewById(e.a(getContext(), "tutu_alert_dialog_tips"));        if (!f.c(this.d)) {            this.b.setText(this.d);        }        if (!f.c(this.e)) {            this.c.setText(this.e);        }        if (!f.c(this.f)) {            this.a.setText(this.f);        }        this.b.setOnClickListener(new OnClickListener(this) {            final /* synthetic */ b a;            {                this.a = r1;            }            public void onClick(View view) {                if (this.a.h != null) {                    this.a.h.c_(this.a.g);                }                this.a.dismiss();            }        });        this.c.setOnClickListener(new OnClickListener(this) {            final /* synthetic */ b a;            {                this.a = r1;            }            public void onClick(View view) {                if (this.a.h != null) {                    this.a.h.c(this.a.g);                }                this.a.dismiss();            }        });    }}

 

The problem lies in the marked red.

Http://stackoverflow.com/questions/36116606/nosuchmethoderrorcom-android-app-fragment-getcontext-in-android

You know, the new sdk only supports the getContext method, but the adobe air sdk is slow to follow up. If you do not have this method, you need to change it to getActivity.

Because this is a third-party sdk and has no source code, you can only modify the class file.

Google explains how to modify bytecode and find several articles. Put it at the end.

 

Download and install jclasslib. Open jclasslib bytecode viewer to view the bytecode of the B. class File

Decompress the jar package and drag the B. class file in the com/tutu/common/a folder into the bytecode viewer.

 

According to the decompiled source code above, we need to modify the location in the private void a (View view) method, expand the Methods on the left, one by one, see the method named a in the figure, observe the Access flags on the right. If it is not private, skip it quickly. If yes, observe the Descriptor on the right, which is the parameter list. Show the image, select [0] Code, and observe the byte code on the right.

 

 

 

In the figure, Row 22 is the getContext to be searched. Click #56 in front of the mouse to jump to the following figure.

 

 

The REDLINE part used is #80 and then returns to bytecode. When you look at the location of the 13 rows of getActivity #54, click it and jump to the figure below.

 

The red line part is #78. sliding the list on the left side shows that this item is under the Constant Pool category. Edit the code below to modify the bytecode and change the point to #80 to point to #78.

Create a new java project in eclipse.

Go to the jclasslib installation directory, enter modules/data/src/main/java, copy org and its content to the src directory of the java project.

 

Create an App class and put the main method

Import java. io. dataInput; import java. io. dataInputStream; import java. io. file; import java. io. fileInputStream; import java. io. IOException; import org. gjt. jclasslib. io. classFileWriter; import org. gjt. jclasslib. structures. CPInfo; import org. gjt. jclasslib. structures. classFile; import org. gjt. jclasslib. structures. invalidByteCodeException; import org. gjt. jclasslib. structures. methodInfo; import org. gjt. jclasslib. s Tructures. constants. constantMethodrefInfo; import org. gjt. jclasslib. structures. constants. constantNameAndTypeInfo; public class App {public static void main (String [] args) throws InvalidByteCodeException, IOException {String filePath = "C: /Users/fp/Documents/goalPlatformClientV1/ANE/tutu/package/Android-ARM/B. class "; FileInputStream FD = new FileInputStream (filePath); DataInput di = new DataInputS Tream (FS); ClassFile cf = new ClassFile (); cf. read (di); CPInfo [] infos = cf. getConstantPool (); MethodInfo [] MS = cf. getMethods (); MethodInfo m = MS [5]; // System. out. println (m. getAccessFlags (); // System. out. println (m. getAccessFlagsVerbose (); // System. out. println (m. getName (); // System. out. println (m. getNameIndex (); // System. out. println (m. getDescriptor (); // System. out. println (m. getDescriptorInd Ex (); // AttributeInfo [] getAttributes = m. getAttributes (); // System. out. println (m. getAttributes (); ConstantMethodrefInfo uInfo = (ConstantMethodrefInfo) infos [56]; // you just used CONSTANT_Methodref_info. getNameAndTypeInfo (); String s = String. format ("% s \ n % s", nt. getName (), nt. getTag (), nt. getTagVerbose (), nt. getVerbose (); System. out. println (s); uInfo. SetNameAndTypeIndex (78); infos [56] = uInfo; // int count = infos. length; // for (int I = 0; I <count; I ++) {// if (infos [I]! = Null) {// System. out. print (I); // System. out. print ("="); // System. out. print (infos [I]. getVerbose (); // System. out. print ("="); // System. out. println (infos [I]. getTagVerbose (); // if (I = 160) {// The location you just found is 21 // ConstantUtf8Info uInfo = (ConstantUtf8Info) infos [I]; // just there is a CONSTANT_Utf-8_info so here to use this /// System. out. println ("xxxxxxxxxxxxxxxxxxxx"); // uInfo. setString ("getActivity"); // if this method is used Modify the string directly. No, the Type after Name and type is Landroid/content/Context // infos [I] = uInfo; ///} // This method can also be used. The same/* if (infos [count]! = Null) {ConstantUtf8Info uInfo = (ConstantUtf8Info) infos [I]; // just there is a CONSTANT_Utf-8_info so here we will use this uInfo. setBytes ("baidu ". getBytes (); infos [count] = uInfo;} */cf. setConstantPool (infos); FCM. close (); File f = new File (filePath); ClassFileWriter. writeToFile (f, cf );}}

 

Accessories for hand training:

Http://files.cnblogs.com/files/lonkiss/java.library.tutu.zip

After decompression, there is a jar package. Blog does not allow direct upload of jar packages

References:

Directly modify other jar package class file tools: jclasslib-hexin373 column-blog channel-CSDN. NET http://blog.csdn.net/hexin373/article/details/6669813

How to Use JClassLib to modify the. class file-"Yang Xi" column-blog channel-CSDN. NET http://blog.csdn.net/betterandroid/article/details/14520667

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.