Exemple #1
0
func main() {
	Input := flag.String("input", "", "Uncompressed SWF as input file.")
	Output := flag.String("output", *Input+"-ascii.swf", "Filename for the output generated SWF.")
	flag.Parse()

	if len(*Input) == 0 || len(*Output) == 0 {
		fmt.Println("You have to specify an input file (--input) and an output file (--output).\n")
		fmt.Println("Example usage:")
		fmt.Println("./rosettaflash --input X.swf --output X-ascii.swf")
		return
	}

	allowed_charset := charset.New(ALLOWED_CHARSET)

	data, err := ioutil.ReadFile(*Input)
	utils.Panic(err)

	// Check if original SWF is uncompressed (FWS)
	if data[0] != 'F' {
		utils.Panic(errors.New("Input SWF is not uncompressed (first bytes: FWS). Uncompress it and try again."))
	}

	body := data[8:]
	checksum := adler32_mod.Checksum(body)

	fmt.Printf("ADLER32 checksum of uncompressed data: %x\n", checksum)

	if adler32_mod.Checksum_allowed(checksum, allowed_charset) {
		fmt.Println("Checksum of original file allowed.")
	} else {
		fmt.Println("Checksum of original contains forbidden characters.")
		bytes_to_append := adler32_fuzzer.Get_appended_bytes(checksum, allowed_charset)
		body = append(body, bytes_to_append...)
		checksum = adler32_mod.Update(checksum, bytes_to_append)

		fmt.Printf("ADLER32 checksum %x is valid, appended %v bytes.\n", checksum, len(bytes_to_append))
	}

	if adler32_mod.Checksum_allowed(checksum, allowed_charset) {
		fmt.Println("Generating zlib stream.")
	} else {
		panic("Checksum still contains forbidden characters. Exiting.")
		return
	}

	// Initialize and write the zlib/DEFLATE stream
	stream := zlibStream.InitializeZlibStream()
	stream.Start(body, allowed_charset)

	// Wrap the stream
	stream.WriteFullByteStream(checksum)

	// Generate a zlib-compressed SWF file that satisfies the charset constraints
	SWFFile.WriteFile(stream)

	// Finally write the file on disk
	err = ioutil.WriteFile(*Output, SWFFile.GetBytes(), 0644)
	utils.Panic(err)
}
Exemple #2
0
func (d *ZlibStream) WriteBytes() bytes.Buffer {
	var bytes bytes.Buffer
	bytes.Grow(1024 * 128)

	//fmt.Printf("W BEGIN WriteBytes - len(bits) = %v\n", d.bits.Len())

	/*
		if d.ByteDisalignment() > 0 {
			fmt.Println("Byte disalignment detected. Compensating.")
			pad := make([]byte, d.ByteDisalignment())
			d.bits.Write(pad)
		}
	*/

	for d.bits.Len() > 0 {
		current_byte := make([]byte, 8)
		_, err := d.bits.Read(current_byte)
		utils.Panic(err)

		new_byte := make([]byte, 8)

		for j := 7; j >= 0; j-- {
			bit := current_byte[j]
			new_byte[7-j] = byte(bit)
		}
		b := utils.Bits_to_byte(new_byte)
		bytes.WriteByte(b)
	}

	//fmt.Printf("W END WriteBytes - len(bytes) = %v\n", bytes.Len())
	return bytes
}