Skip to content

Instantly share code, notes, and snippets.

@maple3142
Last active April 26, 2018 14:06
Show Gist options
  • Select an option

  • Save maple3142/8ca43594299a92fbf2c3e81adfb09b82 to your computer and use it in GitHub Desktop.

Select an option

Save maple3142/8ca43594299a92fbf2c3e81adfb09b82 to your computer and use it in GitHub Desktop.
從 FushionApp 的 apk 中匯出 .fas 檔

從 FushionApp 的 apk 中匯出 .fas

需求

  • 安裝 node.js
  • 會使用指令介面 (cmd,bash,...)

步驟

  1. 把這個 gist 下載成一個 zip 檔後解壓縮
  2. 在裡面執行 npm i
  3. 把目標 apk 放到同個資料夾
  4. 執行 node index.js xxx.apk (假設目標是 xxx.apk)
  5. 會得到一個 xxx.fas 檔案,這就是成品了
const zipper = require('zip-local')
const fs = require('fs')
const path = require('path')
const rimraf = require('rimraf')
const file = process.argv[2] || ''
const TARGET = path.parse(file).name
const TARGETAPK = `${TARGET}.apk`
const TARGETPATH = path.join(process.cwd(), TARGET)
const ASSETS = path.join(TARGETPATH, 'assets')
const RESULT = path.join(process.cwd(), `${TARGET}.fas`)
if (!fs.existsSync(TARGETAPK)) {
console.error('沒有檔案')
process.exit(1)
}
if (fs.existsSync(TARGETPATH)) {
rimraf.sync(TARGETPATH)
}
fs.mkdirSync(TARGETPATH)
console.log('開始解開 apk')
zipper.sync.unzip(TARGETAPK).save(TARGETPATH)
console.log('解開 apk 完成')
function deleteNotFushion(curpath) {
for (const p of fs.readdirSync(curpath)) {
//console.log(p)
const pa = path.join(curpath, p)
const stat = fs.statSync(pa)
if (stat.isDirectory()) {
deleteNotFushion(pa)
} else if (!/(init\.lua|table|png|jpeg|jpg|mht)$/.test(p)) {
fs.unlinkSync(pa)
}
}
if (fs.readdirSync(curpath).length === 0) {
fs.rmdirSync(curpath)
}
}
console.log('開始刪除非 FushionApp 的檔案')
deleteNotFushion(ASSETS)
console.log('刪除非 FushionApp 的檔案完成')
console.log('開始壓縮 fas 檔')
zipper.sync.zip(ASSETS).save(RESULT)
console.log('壓縮 fas 檔完成')
console.log('開始清除暫存資料夾')
rimraf.sync(TARGETPATH)
console.log('清除暫存資料夾完成')
{
"name": "fa-extract",
"version": "1.0.0",
"main": "index.js",
"keywords": [],
"author": "maple3142",
"license": "MIT",
"dependencies": {
"rimraf": "^2.6.2",
"zip-local": "^0.3.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment