Skip to content

Instantly share code, notes, and snippets.

@Lichtso
Created July 15, 2021 14:48
Show Gist options
  • Save Lichtso/cd0e5da3acdc1cffe627bd911ad0fc28 to your computer and use it in GitHub Desktop.
Save Lichtso/cd0e5da3acdc1cffe627bd911ad0fc28 to your computer and use it in GitHub Desktop.
QuickBMS script to extract UnityFS files, the new asset bundle format introduced in Unity 5
# Script for quickbms: https://aluigi.altervista.org/quickbms.htm
# Extracts *.unity3d files
# (c) 2021-07-21 by Lichtso
endian big
# Header
idstring "UnityFS"
Padding 5
get FILE_VERSION byte
get MIN_PLAYER_VERSION string
get FILE_ENGINE_VERSION string
get TOTAL_SIZE longlong
get ZSIZE long
get SIZE long
get FLAGS long
set COMPRESSION_TYPE FLAGS
math COMPRESSION_TYPE & 0x3F
if COMPRESSION_TYPE == 1
# Not tested
comtype lzma
else if COMPRESSION_TYPE == 2
# Not tested
comtype lz4hc
else if COMPRESSION_TYPE == 3
comtype lz4
endif
if FLAGS & 0x40
# The bundle has directory info
endif
if FLAGS & 0x80
# Not supported: The block and directory list is at the end of this bundle file
endif
SavePos OFFSET
clog MEMORY_FILE OFFSET ZSIZE SIZE
math OFFSET + ZSIZE
GoTo 16 MEMORY_FILE
get BLOCK_COUNT long MEMORY_FILE
# Decompress Blocks
append
for i = 0 < BLOCK_COUNT
get SIZE long MEMORY_FILE
get ZSIZE long MEMORY_FILE
get FLAGS short MEMORY_FILE
if SIZE != ZSIZE
clog "decompressed_stream.dat" OFFSET ZSIZE SIZE
math OFFSET + ZSIZE
else
log "decompressed_stream.dat" OFFSET SIZE
math OFFSET + SIZE
endif
next i
append
# Extract Files from Bundle
set EXISTS 2
open "." "decompressed_stream.dat" DECOPRESSED_STREAM EXISTS
get FILE_COUNT long MEMORY_FILE
for i = 0 < FILE_COUNT
get OFFSET longlong MEMORY_FILE
get SIZE longlong MEMORY_FILE
get FLAGS long MEMORY_FILE
get NAME STRING MEMORY_FILE
log NAME OFFSET SIZE DECOPRESSED_STREAM
next i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment