笔者周末在家逆向jdk源码,得到以下方法

    public static void main(String[] args){
        System.out.println(native2ascii("hh汉字"));
    }

    static String native2ascii(String originalText)
    {
        final StringBuffer stringBuffer = new StringBuffer();

        char[] array = originalText.toCharArray();
        int n2 = array.length;
        for (int i = 0; i < n2; ++i) {
            if (array[i] > '\u007f') {

                stringBuffer.append((char) 92);
                stringBuffer.append((char)117);
                final StringBuffer sb = new StringBuffer(Integer.toHexString(array[i]));
                sb.reverse();
                for (int n3 = 4 - sb.length(), j = 0; j < n3; ++j) {
                    sb.append('0');
                }
                for (int k = 0; k < 4; ++k) {
                    stringBuffer.append(sb.charAt(3 - k));
                }
            }
            else {
                stringBuffer.append(array[i]);
            }
        }
        return stringBuffer.toString();
    }

输出结果等同于 native2ascii.exe里面执行命令

posted on 2020-07-27 10:50  你不知道的浪漫  阅读(195)  评论(0编辑  收藏  举报