uint32 read_swf_matrix(linput_t *li, SWFMATRIX *matrix) { SWFMATRIX m; int32 position; if (matrix == NULL) matrix = &m; //save read position position = qltell(li); uint8 fByte = qlgetc(li); uint8 offset = 1; if (fByte & 0x80 /* hasScale */) { uint8 nScaleBits = (fByte & 0x7F) >> 2; offset = 6; if ( offset ) qlseek(li, -1, SEEK_CUR); matrix->scaleX = read_bits(li, offset, nScaleBits); offset = (offset + nScaleBits) % 8; //rewind input if needed if ( offset ) qlseek(li, -1, SEEK_CUR); matrix->scaleY = read_bits(li, offset, nScaleBits); offset = (offset + nScaleBits) % 8; //don't rewind, keep alignment //if ( offset ) qlseek(li, -1, SEEK_CUR); }
uint32 read_swf_rect(linput_t *li, SWFRECT *rect) { SWFRECT r; int32 position; if (rect == NULL) rect = &r; //save read position position = qltell(li); uchar nBits = ((uchar)qlgetc(li)) >> 3; uint32 rect_size_bits = nBits*4 + 5; uint32 rect_size_bytes = rect_size_bits / 8; if(rect_size_bits % 8) rect_size_bytes++; //TODO: fill rect here return rect_size_bytes; }
//-------------------------------------------------------------------------- static bool load_name2(ushort index, ulong offset) { uint64 off, size; if ( index == ushort(-1) ) { off = dynstr_off; size = dynstr_size; } else { off = elf64 ? shdr64[index].sh_offset : shdr32[index].sh_offset; size = elf64 ? shdr64[index].sh_size : shdr32[index].sh_size; } if ( offset >= size ) { qsnprintf(name, sizeof(name), "bad offset %08lx", low(offset+off)); return false; } ulong pos = qltell(li); offset = low(offset + off); qlseek(li, offset); register char *p; register int i, j; bool ok = true; for(i = 0, p = name; i < sizeof(name)-1; i++, p++) if((j = qlgetc(li)) == EOF) { qstrncpy(p, "{truncated name}", sizeof(name)-(p-name)); ok = false; break; } else if((*p = (char)j) == '\0') break; if(i == sizeof(name)-1) { qstrncpy(p-5, "...", 5); ok = false; } qlseek(li, pos); return ok; }
uint32 read_bits(linput_t *li, uint8 bitOffset, uint8 lenght) { if ( (lenght == 0) || (lenght > 32) || (bitOffset > 7) ) return 0; uint8 mask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; uint32 result = 0; uint8 b; do { b = qlgetc(li); for (uint i = bitOffset; i < 8 && lenght > 0; i++) { result += ((b & mask[i])? 1 : 0) << (--lenght); } bitOffset = 0; } while ( lenght ); //we need another byte return result; }