如何编辑已编译的Java字节码?

时间:2021-08-28 16:53:37

I used a decompiler to find the following function in compiled code:

我使用反编译器在编译代码中找到以下函数:

public static void sub_e5b()
    {
        var_972 = null;
        System.gc();
        vservConfigHashTable = new Hashtable();
        vservConfigHashTable.put("appId_end", "498");
        vservConfigHashTable.put("showAt", "both");
        vservConfigHashTable.put("categoryId", "22");
        vservConfigHashTable.put("viewMandatory_end", "true");
        (new VSERV_BCI_CLASS_000(var_93a, vservConfigHashTable)).showAtEnd();
    }

Now I want to change the "true" value to "false".

现在我想将“true”值更改为“false”。

What tools and/or techniques could be used to make this change?

可以使用哪些工具和/或技术进行此更改?

2 个解决方案

#1


1  

This can easily be done using a disassembler like Krakatau (disclosure, I wrote it).

这可以使用像Krakatau这样的反汇编程序轻松完成(披露,我写了)。

The advantage of using a disassembler over a decompiler is that it's guaranteed to work. Not all code can be decompiled, but it can always be disassembled.

在反编译器上使用反汇编程序的优点是它可以保证工作。并非所有代码都可以反编译,但始终可以反汇编。

For example, take a class like this.

例如,参加这样的课程。

public class A{
    public static void main(String[] args)
    {
        System.out.println("true");
    }
}

After disassembling it with Krakatau, you'll get something like this.

在与Krakatau拆解后,你会得到类似的东西。

.version 51 0
.class super public A
.super java/lang/Object


.method public <init> : ()V
    .limit stack 1
    .limit locals 1
    aload_0
    invokespecial java/lang/Object <init> ()V
    return
.end method

.method static public main : ([Ljava/lang/String;)V
    .limit stack 2
    .limit locals 1
    getstatic java/lang/System out Ljava/io/PrintStream;
    ldc 'true'
    invokevirtual java/io/PrintStream println (Ljava/lang/String;)V
    return
.end method

Change the line ldc 'true' to ldc 'false', reassemble it, and it will now print false instead of true.

将行ldc'true'更改为ldc'false',重新组合它,现在它将打印false而不是true。

#2


-1  

Take the decompiled code, edit it, compile it and use that instead.

获取反编译的代码,编辑它,编译它并使用它。

I would seriously consider removing the System.gc();

我会认真考虑删除System.gc();

#1


1  

This can easily be done using a disassembler like Krakatau (disclosure, I wrote it).

这可以使用像Krakatau这样的反汇编程序轻松完成(披露,我写了)。

The advantage of using a disassembler over a decompiler is that it's guaranteed to work. Not all code can be decompiled, but it can always be disassembled.

在反编译器上使用反汇编程序的优点是它可以保证工作。并非所有代码都可以反编译,但始终可以反汇编。

For example, take a class like this.

例如,参加这样的课程。

public class A{
    public static void main(String[] args)
    {
        System.out.println("true");
    }
}

After disassembling it with Krakatau, you'll get something like this.

在与Krakatau拆解后,你会得到类似的东西。

.version 51 0
.class super public A
.super java/lang/Object


.method public <init> : ()V
    .limit stack 1
    .limit locals 1
    aload_0
    invokespecial java/lang/Object <init> ()V
    return
.end method

.method static public main : ([Ljava/lang/String;)V
    .limit stack 2
    .limit locals 1
    getstatic java/lang/System out Ljava/io/PrintStream;
    ldc 'true'
    invokevirtual java/io/PrintStream println (Ljava/lang/String;)V
    return
.end method

Change the line ldc 'true' to ldc 'false', reassemble it, and it will now print false instead of true.

将行ldc'true'更改为ldc'false',重新组合它,现在它将打印false而不是true。

#2


-1  

Take the decompiled code, edit it, compile it and use that instead.

获取反编译的代码,编辑它,编译它并使用它。

I would seriously consider removing the System.gc();

我会认真考虑删除System.gc();