as3commons-bytecode 获取所有类的一个BUG

下载了这个swc,号称可以反射出所有加载的类。已经用在了spring。

可是一运行就报错,说bytearray.uncompress出错。操。

下载整个源码,单独加载as3commons-bytecode, 又发现边用不了,依赖了一个logging,还用了CONFIG::debug这种,估计和编译器参数绑定了。

删除所有的logging之后,调试,发现以下代码:

ReflectionDeserializer

		public function read(typeCache:ByteCodeTypeCache, input:ByteArray, applicationDomain:ApplicationDomain=null, isLoaderBytes:Boolean=true):void {
			_applicationDomain = applicationDomain ||= Type.currentApplicationDomain;
			_byteStream = AbcSpec.newByteArray();
			input.endian = Endian.LITTLE_ENDIAN;
			var swfIdentifier:String = input.readUTFBytes(3);
			var compressed:Boolean = (swfIdentifier == SWFWeaverFileIO.SWF_SIGNATURE_COMPRESSED);
			var version:uint = input.readByte();
			var filesize:uint = input.readUnsignedInt();

			input.readBytes(_byteStream);
			if (isLoaderBytes) {
				_byteStream.length -= 8;
			}

			if (compressed) {
				_byteStream.uncompress();
			}
			_byteStream.position = 0;
			readHeader(_byteStream);
			while (_byteStream.bytesAvailable) {
				readTags(typeCache, _byteStream);
			}
		}

  可以看到 uncompress之前,做了一个length -= 8

这里是过滤掉头的3个byte = swfid, 1个byte的version,4个byte的filesize。

但是你码为什么修改length。直接导致解压出错。这玩意到底有没有人用过的。于是我修改源码:

			input.readBytes(_byteStream);
			if (isLoaderBytes) {
//				_byteStream.length -= 8;
			}

			if (compressed) {
				_byteStream.position = 0;
				_byteStream.uncompress();
			}

  注释掉length,同时修改position=0.

一切正常了。

的确可以反射出所有的类,是读bytecode获得的,比bytearray得SwfExplorer好。就是这个地方不知道作者怎么搞的。

原文地址:https://www.cnblogs.com/zc22/p/3481802.html