我已经从AndroidProjector逆向工程了 jar 文件。我正在尝试修改 AndroidProjector 以适应不同的屏幕尺寸,但我遇到了 org.eclipse.swt.graphics.ImageData.blit() - ArrayOutOfBoundsException 的问题。
该项目还使用此文件 (RawData)作为解决方案的一部分。
我的 Android 投影仪通话:
private void getFramebufferHeader(SocketChannel paramSocketChannel)
throws IOException
{
ByteBuffer localByteBuffer = ByteBuffer.wrap(new byte[4]);
readAdbChannel(paramSocketChannel, localByteBuffer);
localByteBuffer.rewind();
localByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
int i = localByteBuffer.getInt();
int j = RawImage.getHeaderSize(i);
localByteBuffer = ByteBuffer.wrap(new byte[j * 4]);
readAdbChannel(paramSocketChannel, localByteBuffer);
localByteBuffer.rewind();
localByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
this.mRawImage = new RawImage();
this.mRawImage.readHeader(i, localByteBuffer,percentSize);
}
ArrayOutOfBounds 异常在这里:
private void updateDeviceImage(Shell paramShell, RawImage paramRawImage)
{
PaletteData localPaletteData = new PaletteData(paramRawImage.getRedMask(), paramRawImage.getGreenMask(), paramRawImage.getBlueMask());
//paramRawImage.getRedMask() = -16777216
//paramRawImage.getRedMask() = 16711680
//paramRawImage.getBlueMask() = 65289
ImageData localImageData = null;
//ArrayOutOfBounds Exception Here////////////////
//paramRawImage.width = 800
//paramRawImage.height = 1280
//paramRawImage.bpp = 32
//
localImageData = new ImageData(paramRawImage.width, paramRawImage.height, paramRawImage.bpp, localPaletteData, 1, paramRawImage.data);
Image localImage = new Image(paramShell.getDisplay(), localImageData);
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/////////////////////////////////////////
this.mImageLabel.setImage(localImage);
this.mImageLabel.pack();
paramShell.pack();
}
我修改后的 RawData 方法调用(percentSize 小于 100 时出现 outofbounds 异常):
public boolean readHeader(int version, ByteBuffer buf, int percentSize) {
this.version = version;
if (version == 16) {
// compatibility mode with original protocol
this.bpp = 16;
// read actual values.
this.size = buf.getInt() * percentSize/100;
this.width = buf.getInt() * percentSize/100;
this.height = buf.getInt() * percentSize/100;
// create default values for the rest. Format is 565
this.red_offset = 11 * percentSize/100;
this.red_length = 5 * percentSize/100;
this.green_offset = 5 * percentSize/100;
this.green_length = 6 * percentSize/100;
this.blue_offset = 0 ;
this.blue_length = 5 * percentSize/100;
this.alpha_offset = 0;
this.alpha_length = 0;
} else if (version == 1) {
this.bpp = buf.getInt();
this.size = buf.getInt() * percentSize/100;
this.width = buf.getInt() * percentSize/100;
this.height = buf.getInt() * percentSize/100;
if (percentSize < 100) {
this.red_offset = 11;
this.red_length = 5;
this.green_offset = 5;
this.green_length = 6;
this.blue_offset = buf.getInt() ;
this.blue_length = 5;
this.alpha_offset = buf.getInt();
this.alpha_length = buf.getInt();
} else {
this.red_offset = buf.getInt() ;
this.red_length = buf.getInt();
this.blue_offset = buf.getInt();
this.blue_length = buf.getInt();
this.green_offset = buf.getInt();
this.green_length = buf.getInt();
this.alpha_offset = buf.getInt();
this.alpha_length = buf.getInt();
}
/*
*/
} else {
// unsupported protocol!
return false;
}
return true;
}
这是我的例外:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 16390
at org.eclipse.swt.graphics.ImageData.blit(Unknown Source)
at org.eclipse.swt.graphics.Image.init(Unknown Source)
at org.eclipse.swt.graphics.Image.init(Unknown Source)
at org.eclipse.swt.graphics.Image.<init>(Unknown Source)
at com.google.android.AndroidProjector.updateDeviceImage(AndroidProjector.java:262)
at com.google.android.AndroidProjector.open(AndroidProjector.java:56)
at com.google.android.AndroidProjector.main(AndroidProjector.java:273)