java代码反编译问题怎么修改

import java.io.UnsupportedEncodingException;

public class Base64 {
abstract class Coder {
public int op;
public byte[] output;

    Coder() {
        super();
    }

    public abstract int maxOutputSize(int arg1);

    public abstract boolean process(byte[] arg1, int arg2, int arg3, boolean arg4);
}

class Decoder extends Coder {
    private static final int[] DECODE = null;
    private static final int[] DECODE_WEBSAFE = null;
    private static final int EQUALS = -2;
    private static final int SKIP = -1;
    private final int[] alphabet;
    private int state;
    private int value;

    static {
        // Method was not decompiled
    }

    public Decoder(int arg3, byte[] arg4) {
        super();
        this.output = arg4;
        int[] v0 = (arg3 & 8) == 0 ? Decoder.DECODE : Decoder.DECODE_WEBSAFE;
        this.alphabet = v0;
        this.state = 0;
        this.value = 0;
    }

    public int maxOutputSize(int arg2) {
        return arg2 * 3 / 4 + 10;
    }

    public boolean process(byte[] arg12, int arg13, int arg14, boolean arg15) {
        int v3;
        if(this.state == 6) {
            return 0;
        }

        int v5 = arg13;
        arg14 += arg13;
        int v7 = this.state;
        int v8 = this.value;
        int v2 = 0;
        byte[] v4 = this.output;
        int[] v0 = this.alphabet;
        while(v5 < arg14) {
            if(v7 == 0) {
                while(v5 + 4 <= arg14) {
                    v8 = v0[arg12[v5] & 255] << 18 | v0[arg12[v5 + 1] & 255] << 12 | v0[arg12[v5 + 2] & 255] << 6 | v0[arg12[v5 + 3] & 255];
                    if(v8 < 0) {
                        break;
                    }

                    v4[v2 + 2] = ((byte)v8);
                    v4[v2 + 1] = ((byte)(v8 >> 8));
                    v4[v2] = ((byte)(v8 >> 16));
                    v2 += 3;
                    v5 += 4;
                }

                if(v5 < arg14) {
                    goto label_59;
                }

                v3 = v2;
                goto label_53;
            }

        label_59:
            int v6 = v5 + 1;
            int v1 = v0[arg12[v5] & 255];
            switch(v7) {
                case 0: {
                    if(v1 >= 0) {
                        v8 = v1;
                        ++v7;
                        goto label_64;
                    }

                    if(v1 == -1) {
                        goto label_64;
                    }

                    this.state = 6;
                    return 0;
                }
                case 1: {
                    if(v1 >= 0) {
                        v8 = v8 << 6 | v1;
                        ++v7;
                        goto label_64;
                    }

                    if(v1 == -1) {
                        goto label_64;
                    }

                    this.state = 6;
                    return 0;
                }
                case 2: {
                    if(v1 >= 0) {
                        v8 = v8 << 6 | v1;
                        ++v7;
                        goto label_64;
                    }

                    if(v1 == -2) {
                        v4[v2] = ((byte)(v8 >> 4));
                        v7 = 4;
                        ++v2;
                        goto label_64;
                    }

                    if(v1 == -1) {
                        goto label_64;
                    }

                    this.state = 6;
                    return 0;
                }
                case 3: {
                    if(v1 >= 0) {
                        v8 = v8 << 6 | v1;
                        v4[v2 + 2] = ((byte)v8);
                        v4[v2 + 1] = ((byte)(v8 >> 8));
                        v4[v2] = ((byte)(v8 >> 16));
                        v2 += 3;
                        v7 = 0;
                        goto label_64;
                    }

                    if(v1 == -2) {
                        v4[v2 + 1] = ((byte)(v8 >> 2));
                        v4[v2] = ((byte)(v8 >> 10));
                        v2 += 2;
                        v7 = 5;
                        goto label_64;
                    }

                    if(v1 == -1) {
                        goto label_64;
                    }

                    this.state = 6;
                    return 0;
                }
                case 4: {
                    if(v1 == -2) {
                        ++v7;
                        goto label_64;
                    }

                    if(v1 == -1) {
                        goto label_64;
                    }

                    this.state = 6;
                    return 0;
                }
                case 5: {
                    if(v1 == -1) {
                        goto label_64;
                    }

                    this.state = 6;
                    return 0;
                }
            }

        label_64:
            v5 = v6;
        }

        v3 = v2;
    label_53:
        if(!arg15) {
            this.state = v7;
            this.value = v8;
            this.op = v3;
            return 1;
        }

        switch(v7) {
            case 0: {
                goto label_163;
            }
            case 1: {
                goto label_165;
            }
            case 2: {
                goto label_169;
            }
            case 3: {
                goto label_174;
            }
            case 4: {
                goto label_184;
            }
            case 5: {
                goto label_188;
            }
        }

        v2 = v3;
        goto label_159;
    label_163:
        v2 = v3;
        goto label_159;
    label_165:
        this.state = 6;
        return 0;
    label_184:
        this.state = 6;
        return 0;
    label_169:
        v2 = v3 + 1;
        v4[v3] = ((byte)(v8 >> 4));
        goto label_159;
    label_188:
        v2 = v3;
        goto label_159;
    label_174:
        v2 = v3 + 1;
        v4[v3] = ((byte)(v8 >> 10));
        v4[v2] = ((byte)(v8 >> 2));
        ++v2;
    label_159:
        this.state = v7;
        this.op = v2;
        return 1;
    }
}

class Encoder extends Coder {
    private static final byte[] ENCODE = null;
    private static final byte[] ENCODE_WEBSAFE = null;
    public static final int LINE_GROUPS = 19;
    private final byte[] alphabet;
    private int count;
    public final boolean do_cr;
    public final boolean do_newline;
    public final boolean do_padding;
    private final byte[] tail;
    int tailLen;

    static {
        // Method was not decompiled
    }

    public Encoder(int arg4, byte[] arg5) {
        boolean v1 = true;
        super();
        this.output = arg5;
        boolean v0 = (arg4 & 1) == 0 ? true : false;
        this.do_padding = v0;
        v0 = (arg4 & 2) == 0 ? true : false;
        this.do_newline = v0;
        if((arg4 & 4) == 0) {
            v1 = false;
        }

        this.do_cr = v1;
        byte[] v0_1 = (arg4 & 8) == 0 ? Encoder.ENCODE : Encoder.ENCODE_WEBSAFE;
        this.alphabet = v0_1;
        this.tail = new byte[2];
        this.tailLen = 0;
        int v0_2 = this.do_newline ? 19 : -1;
        this.count = v0_2;
    }

    public int maxOutputSize(int arg2) {
        return arg2 * 8 / 5 + 10;
    }

    public boolean process(byte[] arg15, int arg16, int arg17, boolean arg18) {
        int v11;
        int v8;
        int v12;
        byte[] v11_1;
        int v7;
        int v4;
        byte[] v1 = this.alphabet;
        byte[] v5 = this.output;
        int v3 = 0;
        int v2 = this.count;
        int v6 = arg16;
        arg17 += arg16;
        int v10 = -1;
        switch(this.tailLen) {
            case 1: {
                if(arg16 + 2 > arg17) {
                    goto label_9;
                }

                v6 = arg16 + 1;
                v10 = (this.tail[0] & 255) << 16 | (arg15[arg16] & 255) << 8 | arg15[v6] & 255;
                this.tailLen = 0;
                ++v6;
                break;
            }
            case 2: {
                if(arg16 + 1 > arg17) {
                    goto label_9;
                }

                v6 = arg16 + 1;
                v10 = (this.tail[0] & 255) << 16 | (this.tail[1] & 255) << 8 | arg15[arg16] & 255;
                this.tailLen = 0;
                break;
            }
        }

    label_9:
        if(v10 != -1) {
            v5[0] = v1[v10 >> 18 & 63];
            v4 = 2;
            v5[1] = v1[v10 >> 12 & 63];
            v3 = v4 + 1;
            v5[v4] = v1[v10 >> 6 & 63];
            v4 = v3 + 1;
            v5[v3] = v1[v10 & 63];
            --v2;
            if(v2 == 0) {
                if(this.do_cr) {
                    v3 = v4 + 1;
                    v5[v4] = 13;
                }
                else {
                    v3 = v4;
                }

                goto label_38;
            }
            else {
                v7 = v6;
                goto label_43;
            label_38:
                v4 = v3 + 1;
                v5[v3] = 10;
                v2 = 19;
                v7 = v6;
            }
        }
        else {
        label_91:
            v7 = v6;
            v4 = v3;
        }

    label_43:
        if(v7 + 3 <= arg17) {
            v10 = (arg15[v7] & 255) << 16 | (arg15[v7 + 1] & 255) << 8 | arg15[v7 + 2] & 255;
            v5[v4] = v1[v10 >> 18 & 63];
            v5[v4 + 1] = v1[v10 >> 12 & 63];
            v5[v4 + 2] = v1[v10 >> 6 & 63];
            v5[v4 + 3] = v1[v10 & 63];
            v6 = v7 + 3;
            v3 = v4 + 4;
            --v2;
            if(v2 != 0) {
                goto label_91;
            }

            if(this.do_cr) {
                v5[v3] = 13;
                ++v3;
            }

            v5[v3] = 10;
            v2 = 19;
            ++v3;
            goto label_91;
        }

        if(!arg18) {
            if(v7 == arg17 - 1) {
                v11_1 = this.tail;
                v12 = this.tailLen;
                this.tailLen = v12 + 1;
                v11_1[v12] = arg15[v7];
                v3 = v4;
                goto label_305;
            }

            if(v7 == arg17 - 2) {
                v11_1 = this.tail;
                v12 = this.tailLen;
                this.tailLen = v12 + 1;
                v11_1[v12] = arg15[v7];
                v11_1 = this.tail;
                v12 = this.tailLen;
                this.tailLen = v12 + 1;
                v11_1[v12] = arg15[v7 + 1];
                v3 = v4;
                goto label_305;
            }

            v3 = v4;
            goto label_305;
        label_330:
            v3 = v4;
            goto label_273;
        label_149:
            v10 = (v11 & 255) << 4;
            this.tailLen -= v8;
            v3 = v4 + 1;
            v5[v4] = v1[v10 >> 6 & 63];
            v4 = v3 + 1;
            v5[v3] = v1[v10 & 63];
            if(this.do_padding) {
                v3 = v4 + 1;
                v5[v4] = 61;
                v5[v3] = 61;
                ++v3;
                goto label_172;
            label_209:
                v12 = (v11 & 255) << 10;
                if(this.tailLen > 0) {
                    v11 = this.tail[v8];
                    ++v8;
                }
                else {
                    v11 = arg15[v6];
                    ++v6;
                    goto label_217;
                label_273:
                    v5[v3] = 10;
                    v6 = v7;
                    ++v3;
                    goto label_184;
                }

                goto label_217;
            }
            else {
                v3 = v4;
            }

        label_172:
            if(!this.do_newline) {
                goto label_184;
            }

            if(this.do_cr) {
                v5[v3] = 13;
                ++v3;
            }

            v5[v3] = 10;
            ++v3;
            goto label_184;
        label_217:
            v10 = v12 | (v11 & 255) << 2;
            this.tailLen -= v8;
            v3 = v4 + 1;
            v5[v4] = v1[v10 >> 12 & 63];
            v4 = v3 + 1;
            v5[v3] = v1[v10 >> 6 & 63];
            v3 = v4 + 1;
            v5[v4] = v1[v10 & 63];
            if(this.do_padding) {
                v5[v3] = 61;
                ++v3;
            }

            if(this.do_newline) {
                if(this.do_cr) {
                    v5[v3] = 13;
                    ++v3;
                }

                v5[v3] = 10;
                ++v3;
            }

        label_184:
            if(!Encoder.-assertionsDisabled) {
                v11 = this.tailLen == 0 ? 1 : 0;
                if(v11 != 0) {
                    goto label_284;
                }

                throw new AssertionError();
            }

        label_284:
            if(Encoder.-assertionsDisabled) {
                goto label_305;
            }

            v11 = v6 == arg17 ? 1 : 0;
            if(v11 != 0) {
                goto label_305;
            }

            throw new AssertionError();
        }
        else if(v7 - this.tailLen == arg17 - 1) {
            v8 = 0;
            if(this.tailLen > 0) {
                v8 = 1;
                v11 = this.tail[0];
                v6 = v7;
            }
            else {
                v6 = v7 + 1;
                v11 = arg15[v7];
            }

            goto label_149;
        }
        else {
            if(v7 - this.tailLen != arg17 - 2) {
                goto label_263;
            }

            v8 = 0;
            if(this.tailLen > 1) {
                v8 = 1;
                v11 = this.tail[0];
                v6 = v7;
            }
            else {
                v6 = v7 + 1;
                v11 = arg15[v7];
                goto label_209;
            label_263:
                if((this.do_newline) && v4 > 0 && v2 != 19) {
                    if(this.do_cr) {
                        v3 = v4 + 1;
                        v5[v4] = 13;
                    }
                    else {
                        goto label_330;
                    }

                    goto label_273;
                }

                v6 = v7;
                v3 = v4;
                goto label_184;
            }

            goto label_209;
        }

    label_305:
        this.op = v3;
        this.count = v2;
        return 1;
    }
}

public static final int CRLF = 4;
public static final int DEFAULT = 0;
public static final int NO_CLOSE = 16;
public static final int NO_PADDING = 1;
public static final int NO_WRAP = 2;
public static final int URL_SAFE = 8;

static {
    // Method was not decompiled
}

private Base64() {
    super();
}

public static byte[] decode(String arg1, int arg2) {
    return Base64.decode(arg1.getBytes(), arg2);
}

public static byte[] decode(byte[] arg2, int arg3) {
    return Base64.decode(arg2, 0, arg2.length, arg3);
}

public static byte[] decode(byte[] arg5, int arg6, int arg7, int arg8) {
    Decoder v0 = new Decoder(arg8, new byte[arg7 * 3 / 4]);
    if(!v0.process(arg5, arg6, arg7, true)) {
        throw new IllegalArgumentException("bad base-64");
    }

    if(v0.op == v0.output.length) {
        return v0.output;
    }

    byte[] v1 = new byte[v0.op];
    System.arraycopy(v0.output, 0, v1, 0, v0.op);
    return v1;
}

public static byte[] encode(byte[] arg2, int arg3) {
    return Base64.encode(arg2, 0, arg2.length, arg3);
}

public static byte[] encode(byte[] arg6, int arg7, int arg8, int arg9) {
    int v3 = 1;
    Encoder v0 = new Encoder(arg9, null);
    int v1 = arg8 / 3 * 4;
    if(!v0.do_padding) {
        switch(arg8 % 3) {
            case 1: {
                goto label_37;
            }
            case 2: {
                goto label_39;
            }
        }

        goto label_12;
    label_37:
        v1 += 2;
        goto label_12;
    label_39:
        v1 += 3;
    }
    else if(arg8 % 3 > 0) {
        v1 += 4;
    }

label_12:
    if((v0.do_newline) && arg8 > 0) {
        int v5 = (arg8 - 1) / 57 + 1;
        int v2 = v0.do_cr ? 2 : 1;
        v1 += v2 * v5;
    }

    v0.output = new byte[v1];
    v0.process(arg6, arg7, arg8, true);
    if(!Base64.-assertionsDisabled) {
        if(v0.op != v1) {
            v3 = 0;
        }

        if(v3 != 0) {
            goto label_45;
        }

        throw new AssertionError();
    }

label_45:
    return v0.output;
}

public static String encodeToString(byte[] arg4, int arg5) {
    try {
        return new String(Base64.encode(arg4, arg5), "US-ASCII");
    }
    catch(UnsupportedEncodingException v0) {
        throw new AssertionError(v0);
    }
}

public static String encodeToString(byte[] arg4, int arg5, int arg6, int arg7) {
    try {
        return new String(Base64.encode(arg4, arg5, arg6, arg7), "US-ASCII");
    }
    catch(UnsupportedEncodingException v0) {
        throw new AssertionError(v0);
    }
}

}

可以帮忙改成可运行的java代码吗

代码需要实现什么?
所有的类都在这个Base64类中?
而且还有很多语法问题。。
比如:返回boolean类型,你返回0

img

这两天公司有一个需求就是有一个来自于别人的项目,只有tomcat下部署的war包和一个配合程序使用的jar包,额。。。。于是狼来了(问题来了。。呵呵),我需要将class文件反编译成java文件,这样一看,很简单啊,找个编译软件不就行了,但是等等,真正难点如下:

批量编译时大多数文件或者内容可能都相对准确,但是有些内容不一定是对的,比如:我这边有一个类传入的参数是枚举类型,但是编译后。。。呵呵,成了整形的一个数值。
为了降低出错率,我选择了只反编译自己要修改的类,额。。。但是又出问题了,每个类之间相互是有引用的,这导致了类与类之间的相互依赖,如果我使用javac进行单文件编译,然后。。。然后就报错了。。。。因为当你单个文件进行编译时找不到这个java文件被引用的类
这个还好解决,我创建了一个项目,在项目中引入了原先的jar 包项目,并创建了与该类相同的包路径,将该类放在该路径下,然后进行编译就会发现编译成功。可以具体操作可以查看这个链接https://blog.csdn.net/tomcat_zhu/article/details/79240011
但是,在tomcat下面有个web 项目仍需要进行反编译并进行修改,由于war包部署的项目并不像jar包项目可以直接将项目引入,这样又回到了原点,要修改的java文件无法找到引入的类,怎么办呢,经过本人不断跋山涉水,历尽艰辛的查找,终于想到一个办法,就是将所有的war包项目下的class文件通过命令打成jar包后再进行引入,发现编译成功。
解决方式
首先必须下载相关的反编译软件,可以使用jda,jdax,Luyten等等,如下所示:

个人测试过,建议使用Luyten这个软件反编译的准确率相对较高一些,但是如果是中文显示的是:Unicode编码格式的字符串。而,jad,jadx可以完全编译中文内容。

第二步:解压jar包,并获取要修改的class文件,由于比较简单我就不多说了

第三步:创建maven项目工程,并将获取到的文件放入项目中。这里要注意一个地方,如果直接将文件放入项目会是这个样子

而且也会出现以下报错:

所以要创建相同的包路径,或者修改包路径,正确的应该是这个样子:

第四步:引入jar包

如果你的项目是jar包项目可以在Eclipse中直接: 右键项目 —— Build Path —— Add External Archives... 将原项目导入到创建的项目中。

如果是war包方式,则可以将xxx.war文件后缀修改为xxx.zip进行解压,如果是已经部署在tomcat则需要找到所有的java文件,并将该文件打包成jar包,注意:只需要java文件,而且一定要注意包的路径,打包方式请查看:https://blog.csdn.net/qq_40929531/article/details/99310180 当打包完成后按照下方步骤将jar包引入项目中

第五步:修改代码并且将项目重新打包成jar包或者war包,通过解压jar包或war获取class文件,并替换原来项目中的class文件。
————————————————
版权声明:本文为CSDN博主「SXJR」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40929531/article/details/99298121