-
Notifications
You must be signed in to change notification settings - Fork 911
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
588 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package config | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/Ackites/KillWxapkg/internal/enum" | ||
) | ||
|
||
// Parser 接口 | ||
type Parser interface { | ||
Parse(option WxapkgInfo) error | ||
} | ||
|
||
// WxapkgOption 微信小程序解包选项 | ||
type WxapkgOption struct { | ||
ViewSource string | ||
AppConfigSource string | ||
ServiceSource string | ||
SetAppConfig bool | ||
} | ||
|
||
// WxapkgInfo 保存包的信息 | ||
type WxapkgInfo struct { | ||
WxAppId string | ||
WxapkgType enum.WxapkgType | ||
SourcePath string | ||
IsExtracted bool | ||
Option *WxapkgOption | ||
Parsers []Parser // 添加解析器列表 | ||
} | ||
|
||
// WxapkgManager 管理多个微信小程序包 | ||
type WxapkgManager struct { | ||
Packages map[string]*WxapkgInfo | ||
} | ||
|
||
var managerInstance *WxapkgManager | ||
var wxapkgOnce sync.Once | ||
|
||
// GetWxapkgManager 获取单例的 WxapkgManager 实例 | ||
func GetWxapkgManager() *WxapkgManager { | ||
wxapkgOnce.Do(func() { | ||
managerInstance = &WxapkgManager{ | ||
Packages: make(map[string]*WxapkgInfo), | ||
} | ||
}) | ||
return managerInstance | ||
} | ||
|
||
// AddPackage 添加包信息 | ||
func (manager *WxapkgManager) AddPackage(id string, info *WxapkgInfo) { | ||
manager.Packages[id] = info | ||
} | ||
|
||
// GetPackage 获取包信息 | ||
func (manager *WxapkgManager) GetPackage(id string) (*WxapkgInfo, bool) { | ||
info, exists := manager.Packages[id] | ||
return info, exists | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package enum | ||
|
||
// 定义微信小程序包的文件名常量 | ||
const ( | ||
App_Config = "app-config.json" // 应用配置文件 | ||
App_Service = "app-service.js" // 应用服务文件 | ||
PageFrameHtml = "page-frame.html" // 页面框架HTML文件 | ||
AppWxss = "app-wxss.js" // 应用样式文件 | ||
CommonApp = "common.app.js" // 通用应用文件 | ||
AppJson = "app.json" // 应用JSON文件 | ||
Workers = "workers.js" // 工作者脚本文件 | ||
Page_Frame = "page-frame.js" // 页面框架JS文件 | ||
AppService = "appservice.js" // 应用服务文件 | ||
PageFrame = "pageframe.js" // 页面框架JS文件 | ||
Game = "game.js" // 游戏脚本文件 | ||
GameJson = "game.json" // 游戏JSON文件 | ||
SubContext = "subContext.js" // 子上下文脚本文件 | ||
Plugin = "plugin.js" // 插件脚本文件 | ||
PluginJson = "plugin.json" // 插件JSON文件 | ||
) | ||
|
||
// WxapkgType 定义微信小程序包的类型 | ||
type WxapkgType string | ||
|
||
// 定义微信小程序包的类型常量 | ||
const ( | ||
App_V1 WxapkgType = "APP_V1" // 应用类型 V1 | ||
App_V2 WxapkgType = "APP_V2" // 应用类型 V2 | ||
App_V3 WxapkgType = "APP_V3" // 应用类型 V3 | ||
App_V4 WxapkgType = "APP_V4" // 应用类型 V4 | ||
|
||
APP_SUBPACKAGE_V1 WxapkgType = "APP_SUBPACKAGE_V1" // 应用子包类型 V1 | ||
APP_SUBPACKAGE_V2 WxapkgType = "APP_SUBPACKAGE_V2" // 应用子包类型 V2 | ||
|
||
APP_PLUGIN_V1 WxapkgType = "APP_PLUGIN_V1" // 应用插件类型 V1 | ||
|
||
GAME WxapkgType = "GAME" // 游戏类型 | ||
GAME_SUBPACKAGE WxapkgType = "GAME_SUBPACKAGE" // 游戏子包类型 | ||
GAME_PLUGIN WxapkgType = "GAME_PLUGIN" // 游戏插件类型 | ||
|
||
FRAMEWORK WxapkgType = "FRAMEWORK" // 框架类型 | ||
) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package restore | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"path/filepath" | ||
|
||
"github.com/Ackites/KillWxapkg/internal/unpack" | ||
|
||
"github.com/Ackites/KillWxapkg/internal/util" | ||
|
||
"github.com/Ackites/KillWxapkg/internal/config" | ||
"github.com/Ackites/KillWxapkg/internal/enum" | ||
) | ||
|
||
type WxapkgDecompiler struct { | ||
} | ||
|
||
func isParserV1(wxapkg *config.WxapkgInfo) bool { | ||
switch wxapkg.WxapkgType { | ||
case enum.App_V1, enum.App_V2, enum.APP_SUBPACKAGE_V1: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
func isParserV3(wxapkg *config.WxapkgInfo) bool { | ||
switch wxapkg.WxapkgType { | ||
case enum.App_V3, enum.App_V4, enum.APP_SUBPACKAGE_V2, enum.APP_PLUGIN_V1: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// IsMainPackage 是否主包 | ||
func IsMainPackage(wxapkg *config.WxapkgInfo) bool { | ||
switch wxapkg.WxapkgType { | ||
case enum.App_V1, enum.App_V2, enum.App_V3, enum.App_V4, enum.GAME: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// IsSubpackage 是否分包 | ||
func IsSubpackage(wxapkg *config.WxapkgInfo) bool { | ||
switch wxapkg.WxapkgType { | ||
case enum.APP_SUBPACKAGE_V1, enum.APP_SUBPACKAGE_V2, enum.GAME_SUBPACKAGE: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// 是否小程序插件 | ||
func isAppPlugin(wxapkg *config.WxapkgInfo) bool { | ||
switch wxapkg.WxapkgType { | ||
case enum.APP_PLUGIN_V1: | ||
return true | ||
default: | ||
return false | ||
} | ||
|
||
} | ||
|
||
// 是否游戏插件 | ||
func isGamePlugin(wxapkg *config.WxapkgInfo) bool { | ||
switch wxapkg.WxapkgType { | ||
case enum.GAME_PLUGIN: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// 是否插件 | ||
func isPlugin(wxapkg *config.WxapkgInfo) bool { | ||
return isAppPlugin(wxapkg) || isGamePlugin(wxapkg) | ||
} | ||
|
||
// OutputDir 输出目录 | ||
var OutputDir string | ||
|
||
func (d *WxapkgDecompiler) Decompile(outputDir string) { | ||
// 设置输出目录 | ||
OutputDir = outputDir | ||
|
||
wxapkgManager := config.GetWxapkgManager() | ||
for _, wxapkg := range wxapkgManager.Packages { | ||
switch wxapkg.WxapkgType { | ||
case enum.App_V1, enum.App_V4: | ||
wxapkg.Option = &config.WxapkgOption{ | ||
ViewSource: filepath.Join(wxapkg.SourcePath, enum.PageFrameHtml), | ||
SetAppConfig: true, | ||
} | ||
setApp(wxapkg) | ||
case enum.App_V2, enum.App_V3: | ||
wxapkg.Option = &config.WxapkgOption{ | ||
SetAppConfig: true, | ||
} | ||
setApp(wxapkg) | ||
case enum.APP_SUBPACKAGE_V1, enum.APP_SUBPACKAGE_V2: | ||
wxapkg.Option = &config.WxapkgOption{ | ||
ViewSource: filepath.Join(wxapkg.SourcePath, enum.Page_Frame), | ||
SetAppConfig: false, | ||
} | ||
setApp(wxapkg) | ||
case enum.APP_PLUGIN_V1: | ||
wxapkg.Option = &config.WxapkgOption{ | ||
ViewSource: filepath.Join(wxapkg.SourcePath, enum.PageFrame), | ||
ServiceSource: filepath.Join(wxapkg.SourcePath, enum.AppService), | ||
SetAppConfig: false, | ||
} | ||
setApp(wxapkg) | ||
case enum.GAME: | ||
case enum.GAME_SUBPACKAGE: | ||
case enum.GAME_PLUGIN: | ||
} | ||
} | ||
} | ||
|
||
func setApp(wxapkg *config.WxapkgInfo) { | ||
// 如果未解压,则不进行解析 | ||
if !wxapkg.IsExtracted { | ||
return | ||
} | ||
|
||
if wxapkg.Option == nil { | ||
wxapkg.Option = &config.WxapkgOption{} | ||
} | ||
|
||
if wxapkg.Option.ServiceSource == "" { | ||
wxapkg.Option.ServiceSource = filepath.Join(wxapkg.SourcePath, enum.App_Service) | ||
} | ||
|
||
if wxapkg.Option.ViewSource == "" { | ||
wxapkg.Option.ViewSource = filepath.Join(wxapkg.SourcePath, enum.AppWxss) | ||
} | ||
|
||
wccVersion := util.GetWccVersion(wxapkg.Option.ViewSource) | ||
if wccVersion != "" { | ||
log.Printf(fmt.Sprintf("The package %s wcc version is: [%s]", wxapkg.SourcePath, wccVersion)) | ||
} | ||
|
||
if wxapkg.Option.SetAppConfig { | ||
if wxapkg.Option.AppConfigSource == "" { | ||
wxapkg.Option.AppConfigSource = filepath.Join(wxapkg.SourcePath, enum.App_Config) | ||
} | ||
wxapkg.Parsers = append(wxapkg.Parsers, &unpack.ConfigParser{}) | ||
} | ||
|
||
wxapkg.Parsers = append(wxapkg.Parsers, &unpack.JavaScriptParser{OutputDir: OutputDir}) | ||
} | ||
|
||
func cleanApp() { | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.