Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extract .iraw files that some Flash videoconferencing systems use
package main
import (
"log"
"os"
"io/ioutil"
"encoding/binary"
"net/http"
"mime"
"fmt"
)
func main() {
fn := "/path/to/file.ppt.iraw"
outdir := fn + ".parts"
err := os.MkdirAll(outdir, 0777)
if err != nil {
log.Fatal(err)
}
data, err := ioutil.ReadFile(fn)
if err != nil {
log.Fatal(err)
}
o := 0
n := int(binary.BigEndian.Uint32(data[o:o+4]))
o += 4
log.Printf("n = %d, len(data) = %d", n, len(data))
for i := 0; i < n; i++ {
size := int(binary.BigEndian.Uint32(data[o:o+4]))
o += 4
item := data[o:o+size]
o += size
ctype := http.DetectContentType(item)
var ext string
if ctype != "" {
exts, err := mime.ExtensionsByType(ctype)
if err != nil {
log.Fatal(err)
}
if len(exts) > 0 {
ext = exts[0]
}
}
if ext == "" {
ext = ".bin"
}
log.Printf("#%03d len = %d, ctype = %q, ext = %q", i+1, size, ctype, ext)
ofn := outdir + "/" + fmt.Sprintf("part%04d%s", i+1, ext)
err := ioutil.WriteFile(ofn, item, 0666)
if err != nil {
log.Fatal(err)
}
}
log.Printf("offset = %d, len(data) = %d", o, len(data))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment