Skip to content

Instantly share code, notes, and snippets.

@andreyvit
Created June 18, 2020 10:51
Show Gist options
  • Save andreyvit/5f4654be5b94ac9e364cf82a9bf0d4f9 to your computer and use it in GitHub Desktop.
Save andreyvit/5f4654be5b94ac9e364cf82a9bf0d4f9 to your computer and use it in GitHub Desktop.
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