Skip to content

Commit

Permalink
feat: allows disabling of code beautification with global flag '--dis…
Browse files Browse the repository at this point in the history
…able-beautify'
  • Loading branch information
wux1an committed Jun 26, 2023
1 parent 9176db0 commit 6ce2b40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Expand Up @@ -22,4 +22,5 @@ func Execute() {
}

func init() {
RootCmd.Flags().Bool("disable-beautify", false, "disable js,html,json beautify")
}
11 changes: 7 additions & 4 deletions cmd/unpack.go
Expand Up @@ -33,6 +33,7 @@ var unpackCmd = &cobra.Command{
root, _ := cmd.Flags().GetString("root")
output, _ := cmd.Flags().GetString("output")
thread, _ := cmd.Flags().GetInt("thread")
disableBeautify, _ := cmd.Flags().GetBool("disable-beautify")

wxid, err := parseWxid(root)
util.Fatal(err)
Expand All @@ -51,7 +52,7 @@ var unpackCmd = &cobra.Command{

for _, file := range files {
var decryptedData = decryptFile(wxid, file)
fileCount, err := unpack(decryptedData, subOutput, thread)
fileCount, err := unpack(decryptedData, subOutput, thread, !disableBeautify)
util.Fatal(err)
allFileCount += fileCount

Expand Down Expand Up @@ -89,7 +90,7 @@ type wxapkgFile struct {
size uint32
}

func unpack(decryptedData []byte, unpackRoot string, thread int) (int, error) {
func unpack(decryptedData []byte, unpackRoot string, thread int, beautify bool) (int, error) {
var f = bytes.NewReader(decryptedData)

// Read header
Expand Down Expand Up @@ -162,8 +163,10 @@ func unpack(decryptedData []byte, unpackRoot string, thread int) (int, error) {

data := decryptedData[d.offset : d.offset+d.size]

beautify := fileBeautify(outputFilePath, data)
err = os.WriteFile(outputFilePath, beautify, 0600)
if beautify {
data = fileBeautify(outputFilePath, data)
}
err = os.WriteFile(outputFilePath, data, 0600)
util.Fatal(err)

locker.Lock()
Expand Down

0 comments on commit 6ce2b40

Please sign in to comment.