Nginx log escape

java
阅读 36 收藏 0 点赞 0 评论 0

import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.List;
class Main {
	public static void main(String[] args) {
        //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
		String var = "{\\x22pageNum\\x22:1,\\x22pageSize\\x22:1,\\x22activityState\\x2220}";
        System.out.println(convertRequestBody(var));
	}
    public static String convertRequestBody(String requestBody) {

    requestBody = requestBody.replace("\\x22", "\"");

    char[] radix16Array = new char[2];

    int index = 0;

    List<Byte> listByte = new LinkedList<>();

    char[] newRequestBody = requestBody.toCharArray();

    char s = ' ';

    while (index < newRequestBody.length) {

        s = newRequestBody[index];

        if(s == '\\' && newRequestBody[index + 1] == 'x') {

            radix16Array[0] = newRequestBody[index + 2];

            radix16Array[1] = newRequestBody[index + 3];

            listByte.add((byte)Integer.parseInt(new String(radix16Array), 16));

            index = index + 4;

        } else {

            index ++;

            listByte.add((byte)s);

        }

    }

    byte [] array = new byte[listByte.size()];

    for(int i = 0; i < listByte.size(); i ++) {

        array[i] = listByte.get(i);

    }

    return new String(array);

   }
}
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号