文章出處

下載了這個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好。就是這個地方不知道作者怎么搞的。


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()