0

I use Krakatau to edit java code.

class test{

public boolean Func2(String text)
{
    if(text=="aaaaaa")
        return true;
    return false;

}
}

When I compile it I get this java bytecode

.version 53 0 
.class super [3] 
.super [4] 

.method [5] : [6] 
    .attribute [7] .code stack 1 locals 1 
L0:     aload_0 
L1:     invokespecial [1] 
L4:     return 
L5:     
        .attribute [8] .linenumbertable 
            L0 1 
        .end linenumbertable 
    .end code 
.end method 

.method public [9] : [10] 
    .attribute [7] .code stack 2 locals 2 
**L0:     aload_1 
L1:     ldc [2] 
L3:     if_acmpne L8 
L6:     iconst_1 
L7:     ireturn** 

        .stack same 
L8:     iconst_0 
L9:     ireturn 
L10:    
        .attribute [8] .linenumbertable 
            L0 5 
            L6 6 
            L8 7 
        .end linenumbertable 
        .attribute [11] .stackmaptable 
    .end code 
.end method 
.attribute [12] .sourcefile [13] 
.const [1] = Method [4] [14] 
.const [2] = String [15] 
.const [3] = Class [16] 
.const [4] = Class [17] 
.const [5] = Utf8 <init> 
.const [6] = Utf8 ()V 
.const [7] = Utf8 Code 
.const [8] = Utf8 LineNumberTable 
.const [9] = Utf8 Func2 
.const [10] = Utf8 (Ljava/lang/String;)Z 
.const [11] = Utf8 StackMapTable 
.const [12] = Utf8 SourceFile 
.const [13] = Utf8 'test.java' 
.const [14] = NameAndType [5] [6] 
.const [15] = Utf8 aaaaaa 
.const [16] = Utf8 test 
.const [17] = Utf8 java/lang/Object 
.end class 

Now I want to replace text=="aaaaaa" with text.equals("ABCD") I know I need to reaplce

L3:     if_acmpne L8 

with

invokevirtual java/lang/String/equals(Ljava/lang/Object;)Z
ifeq (the line I want to jump)

But Krakatau not get this line

invokevirtual java/lang/String/equals(Ljava/lang/Object;)Z

what is the right and easy way to replace == with equals with Krakatau? I dont want to recompile my code .

1 Answer 1

1

You need to put spaces between the class name, method name, and method descriptor. Also, you should prefix it with the constant pool type (Method in this case). The correct way to write the method call would be

invokevirtual Method java/lang/String equals (Ljava/lang/Object;)Z

Krakatau will currently accept it if you leave out the Method part, but that's not guaranteed to work in the future. Also, for future reference, please post the error you get when asking for help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.