# 星落解包方法

**URL:** <https://live2dhub.com/t/topic/3380>\
**Category:** 讨论\
**Created:** [2024 年7 月 22 日 07:01 UTC](https://live2dhub.com/t/topic/3380 "2024-07-22T07:01:41Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

作者： ![AXiX\_Official](https://live2dhub.com/user_avatar/live2dhub.com/axix_official/32/1844_2.png) [@AXiX\_Official](https://live2dhub.com/u/AXiX_Official)\
发布日期： [2024 年7 月 22 日 12:46 UTC](https://live2dhub.com/t/topic/3380/4 "2024-07-22T12:46:24Z")

</div>

```python
import os
import sys
import json

def extract(file_obj, offset, output_path, name):
    file_obj.seek(offset + 32)
    size = int.from_bytes(file_obj.read(8), byteorder="big")
    file_obj.seek(offset)
    data = file_obj.read(size)
    with open(os.path.join(output_path, name), "wb") as f:
        f.write(data)

if __name__ == " __main__":
    if len(sys.argv) != 4:
        print("Usage: python extract.py <asset_path> <json_path> <output_path>")
        sys.exit(1)
    asset_path = sys.argv[1]
    json_path = sys.argv[2]
    output_path = sys.argv[3]
    with open(asset_path, "rb") as asset_file:
        with open(json_path, "r") as f:
            jsonData = f.read()
        data = json.loads(jsonData)["data"]
        if not os.path.exists(output_path):
            os.makedirs(output_path)
        for item in data:
            key, offset = item["key"], item["offset"]
            if offset != 0:
                extract(asset_file, offset, output_path, key)

```

---

_[View the full topic](https://live2dhub.com/t/topic/3380)._
