ray's Notes

Read The Fucking Source Code.

0%

Protobuf Java 混淆后逆向特征点查找

  1. 如下代码中的字符串可以定位 CodedOutputStream 类。

    1
    2
    3
    4
    5
    6
    7
    8
    public static class OutOfSpaceException extends IOException {
    private static final long serialVersionUID = -6947486886997889499L;

    OutOfSpaceException() {
    super("CodedOutputStream was writing to a flat byte array and ran " +
    "out of space.");
    }
    }
  2. CodedInputStream 的定位如下,依然根据字符串。然后可以从其 readString 的方法交叉引用查找生成的类,或者hook此方法也能看到实际相关生成类。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    // Here we should refill the buffer as many bytes as possible.
    int bytesRead =
    read(
    input,
    buffer,
    bufferSize,
    Math.min(
    // the size of allocated but unused bytes in the buffer
    buffer.length - bufferSize,
    // do not exceed the total bytes limit
    sizeLimit - totalBytesRetired - bufferSize));
    if (bytesRead == 0 || bytesRead < -1 || bytesRead > buffer.length) {
    throw new IllegalStateException(
    input.getClass()
    + "#read(byte[]) returned invalid result: "
    + bytesRead
    + "\nThe InputStream implementation is buggy.");
    }
    1
    2
    3
    4
    if (bytesRead == 0 || bytesRead < -1 || bytesRead > this.buffer.length) {
    throw new IllegalStateException("InputStream#read(byte[]) returned invalid result: " + bytesRead + "\nThe InputStream implementation is buggy.");
    }

  3. 如下代码中的字符串 "byte array" 定位 toByteArray 方法

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    @Override
    public byte[] toByteArray() {
    try {
    final byte[] result = new byte[getSerializedSize()];
    final CodedOutputStream output = CodedOutputStream.newInstance(result);
    writeTo(output);
    output.checkNoSpaceLeft();
    return result;
    } catch (IOException e) {
    throw new RuntimeException(getSerializingExceptionMessage("byte array"), e);
    }
    }