Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3648401
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Java

2021-06-21 17:21:09

package com.lession6;

import java.nio.charset.StandardCharsets;

import java.util.Map;

import java.util.SortedMap;

import java.util.TreeMap;

public class utils {

    private static final char[] f14934c = "0123456789ABCDEF".toCharArray();

    public static final String KEY_VALUE_DELIMITER = "=";

    public static final String FIELD_DELIMITER = "&";

    private static boolean a(char c2, String str) {

        return (c2 >= 'A' && c2 <= 'Z') || (c2 >= 'a' && c2 <= 'z') || !((c2 < '0' || c2 > '9') && "-_.~".indexOf(c2) == -1 && (str == null || str.indexOf(c2) == -1));

    }

    static String r(Map map) {

        String str;

        if (!(map instanceof SortedMap)) {

            map = new TreeMap(map);

        }

        StringBuilder sb = new StringBuilder(256);

        for (Map.Entry entry : map.entrySet()) {

            String key = entry.getKey();

            if (!key.isEmpty()) {

                sb.append(b(key));

                sb.append(KEY_VALUE_DELIMITER);

                String value = entry.getValue();

                if (value == null) {

                    str = "";

                } else {

                    str = b(value);

                }

                sb.append(str);

                sb.append(FIELD_DELIMITER);

            }

        }

        int length = sb.length();

        if (length > 0) {

            sb.deleteCharAt(length - 1);

        }

        if (length == 0) {

            return null;

        }

        return sb.toString();

    }

    static String b(String str) {

        return c(str, null);

    }

    static String c(String str, String str2) {

        StringBuilder sb = null;

        if (str == null) {

            return null;

        }

        int length = str.length();

        int i2 = 0;

        while (i2 < length) {

            int i3 = i2;

            while (i3 < length && a(str.charAt(i3), str2)) {

                i3++;

            }

            if (i3 != length) {

                if (sb == null) {

                    sb = new StringBuilder();

                }

                if (i3 > i2) {

                    sb.append((CharSequence) str, i2, i3);

                }

                i2 = i3 + 1;

                while (i2 < length && !a(str.charAt(i2), str2)) {

                    i2++;

                }

                byte[] bytes = str.substring(i3, i2).getBytes(StandardCharsets.UTF_8);

                int length2 = bytes.length;

                for (int i4 = 0; i4 < length2; i4++) {

                    sb.append('%');

                    sb.append(f14934c[(bytes[i4] & 240) >> 4]);

                    sb.append(f14934c[bytes[i4] & 15]);

                }

            } else if (i2 == 0) {

                return str;

            } else {

                sb.append((CharSequence) str, i2, length);

                return sb.toString();

            }

        }

        return sb == null ? str : sb.toString();

    }

}

补其实现

    @Override

    public DvmObject callStaticObjectMethod(BaseVM vm, DvmClass dvmClass, String signature, VarArg varArg) {

        switch (signature){

            case "com/bilibili/nativelibrary/SignedQuery->r(Ljava/util/Map;)Ljava/lang/String;":{

                DvmObject mapObject = varArg.getObjectArg(0);

                TreeMap mymap = (TreeMap) mapObject.getValue();

                String result = utils.r(mymap);

                return new StringObject(vm, result);

            }

        }

        return super.callStaticObjectMethod(vm, dvmClass, signature, varArg);

    }

阅读(985) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~