shwenzhang/AndResGuard · error · java.io.IOException

Expected: 0x%08x, got: 0x%08x

Error message

Expected: 0x%08x, got: 0x%08x

What it means

ExtDataOutput.writeCheckInt writes a 4-byte int then throws IOException if it differs from expected. Used when re-serializing the resource table (writeSpecNameStringBlock, writeTableNameStringBlock): if the value the writer computes is not what the schema dictates, the resource table would be malformed, so it aborts.

Solutions

  1. Report/reproduce with the failing APK; try the latest AndResGuard version where such writer bugs may be fixed
  2. Reduce resource table complexity (rename problematic resources) to see if a specific entry triggers it
  3. Disable resource shrinking (whiteList adjustments) to isolate which resources trigger the mismatch
  4. Compare the written value vs expected in the message to locate the diverging field
Defensive patterns

Strategy: try-catch

Try / catch

try {
    output.writeCheckInt(value, expected);
} catch (IOException e) {
    if (e.getMessage().startsWith("Expected:")) {
        throw new IOException("Writer invariant violated while building string block: " + e.getMessage(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Writing the string/spec-name table where a computed value (count, offset, index) does not equal the expected constant — usually a bug or data-dependent mismatch during resource shrinking/rewriting.

Common situations: Resource names containing unusual characters or extremely large tables pushing computed offsets out of sync; AndResGuard bugs with certain resource table layouts.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of shwenzhang/AndResGuard@e4df245d82 (2026-09-12). Data as JSON: /api/errors/ef29283501ea50a2. Report an issue: GitHub.

Appendix: source

Thrown at AndResGuard-core/src/main/java/com/tencent/mm/util/ExtDataOutput.java:29

  }

  public void writeIntArray(int[] array) throws IOException {
    int length = array.length;
    for (int i = 0; i < length; i++) {
      writeInt(array[i]);
    }
  }

  public void writeBytes(ExtDataInput in, int length) throws IOException {
    byte[] data = new byte[length];
    in.readFully(data);
    write(data);
  }

  public void writeCheckInt(int value, int expected) throws IOException {
    writeInt(value);
    if (value != expected) {
      throw new IOException(String.format("Expected: 0x%08x, got: 0x%08x", expected, value));
    }
  }

  public void writeCheckChunkTypeInt(ExtDataInput reader, int expected, int possible) throws IOException {
    int value = reader.readInt();
    writeInt(value);
    if (value == possible) {
      writeCheckChunkTypeInt(reader, expected, -1);
    } else if (value != expected) {
      throw new IOException(String.format("Expected: 0x%08x, got: 0x%08x", expected, value));
    }
  }

  public void writeCheckShort(short value, short expected) throws IOException {
    writeShort(value);
    if (value != expected) {
      throw new IOException(String.format("Expected: 0x%08x, got: 0x%08x", expected, value));
    }

View on GitHub (pinned to e4df245d82)