mirror of
https://github.com/Sunnyyoung/WeChatTweak-macOS.git
synced 2026-01-17 15:35:39 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19f1c446a6 | ||
|
|
c51ccc8ac9 |
1
.ruby-version
Normal file
1
.ruby-version
Normal file
|
|
@ -0,0 +1 @@
|
|||
2.7.8
|
||||
5
CONTRIBUTING.md
Normal file
5
CONTRIBUTING.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Contributing
|
||||
|
||||
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
||||
|
||||
[](https://github.com/Sunnyyoung/WeChatTweak-macOS/graphs/contributors)
|
||||
|
|
@ -1,15 +1,25 @@
|
|||
{
|
||||
"originHash" : "fc7f739a75c4c771c736e9ff1f765bbd53fb1f3c5beaa621fbc867f0d71964c4",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "swift-argument-parser",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-argument-parser",
|
||||
"state" : {
|
||||
"revision" : "cdd0ef3755280949551dc26dee5de9ddeda89f54",
|
||||
"version" : "1.6.2"
|
||||
"object": {
|
||||
"pins": [
|
||||
{
|
||||
"package": "PromiseKit",
|
||||
"repositoryURL": "https://github.com/mxcl/PromiseKit",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "2bc44395edb4f8391902a9ff7c220471882a4d07",
|
||||
"version": "8.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-argument-parser",
|
||||
"repositoryURL": "https://github.com/apple/swift-argument-parser",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "cdd0ef3755280949551dc26dee5de9ddeda89f54",
|
||||
"version": "1.6.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 3
|
||||
]
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,14 @@ let package = Package(
|
|||
)
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.6.0")
|
||||
.package(url: "https://github.com/mxcl/PromiseKit", from: "8.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0")
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "WeChatTweak",
|
||||
dependencies: [
|
||||
"PromiseKit",
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser")
|
||||
]
|
||||
)
|
||||
|
|
|
|||
28
README.md
28
README.md
|
|
@ -1,31 +1,17 @@
|
|||
# WeChatTweak
|
||||
|
||||
[](https://github.com/sunnyyoung/WeChatTweak)
|
||||
[](https://t.me/wechattweak)
|
||||
[](https://github.com/sunnyyoung/WeChatTweak/wiki/FAQ)
|
||||
|
||||
A command-line tool for tweaking WeChat.
|
||||
[](LICENSE)
|
||||
[](https://t.me/wechattweak)
|
||||
|
||||
## 功能
|
||||
|
||||
- 阻止消息撤回
|
||||
- 阻止自动更新
|
||||
- 客户端多开
|
||||
- [x] 阻止消息撤回
|
||||
- [ ] 客户端无限多开
|
||||
|
||||
## 安装&使用
|
||||
## 使用
|
||||
|
||||
```bash
|
||||
# 安装
|
||||
brew install sunnyyoung/tap/wechattweak
|
||||
|
||||
# 更新
|
||||
brew upgrade wechattweak
|
||||
|
||||
# 执行 Patch
|
||||
wechattweak patch
|
||||
|
||||
# 查看所有支持的 WeChat 版本
|
||||
wechattweak versions
|
||||
```
|
||||
|
||||
## 参考
|
||||
|
|
@ -36,9 +22,9 @@ wechattweak versions
|
|||
|
||||
## 贡献者
|
||||
|
||||
This project exists thanks to all the people who contribute.
|
||||
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
||||
|
||||
[](https://github.com/sunnyyoung/WeChatTweak/graphs/contributors)
|
||||
[](https://github.com/Sunnyyoung/WeChatTweak-macOS/graphs/contributors)
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import PromiseKit
|
||||
import ArgumentParser
|
||||
|
||||
struct Command {
|
||||
|
|
@ -14,44 +15,46 @@ struct Command {
|
|||
var errorDescription: String? {
|
||||
switch self {
|
||||
case let .executing(command, error):
|
||||
return "executing: \(command) error: \(error)"
|
||||
return "Execute command: \(command) failed: \(error)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func version(app: URL) async throws -> String? {
|
||||
try await Command.execute(command: "defaults read \(app.appendingPathComponent("Contents/Info.plist").path) CFBundleVersion")
|
||||
}
|
||||
|
||||
static func patch(app: URL, config: Config) async throws {
|
||||
try Patcher.patch(binary: app.appendingPathComponent("Contents/MacOS/WeChat"), config: config)
|
||||
}
|
||||
|
||||
static func resign(app: URL) async throws {
|
||||
try await Command.execute(command: "codesign --remove-sign \(app.path)")
|
||||
try await Command.execute(command: "codesign --force --deep --sign - \(app.path)")
|
||||
try await Command.execute(command: "xattr -cr \(app.path)")
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
private static func execute(command: String) async throws -> String? {
|
||||
guard let script = NSAppleScript(source: "do shell script \"\(command)\"") else {
|
||||
throw Error.executing(
|
||||
command: command,
|
||||
error: ["error": "Create script failed."]
|
||||
)
|
||||
static func patch(app: URL, config: Config) -> Promise<Void> {
|
||||
print("------ Path ------")
|
||||
return Promise { seal in
|
||||
do {
|
||||
seal.fulfill(try Patcher.patch(binary: app.appendingPathComponent("Contents/MacOS/WeChat"), config: config))
|
||||
} catch {
|
||||
seal.reject(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var error: NSDictionary?
|
||||
let descriptor = script.executeAndReturnError(&error)
|
||||
static func resign(app: URL) -> Promise<Void> {
|
||||
print("------ Resign ------")
|
||||
return firstly {
|
||||
Command.execute(command: "codesign --remove-sign \(app.path)")
|
||||
}.then {
|
||||
Command.execute(command: "codesign --force --deep --sign - \(app.path)")
|
||||
}.then {
|
||||
Command.execute(command: "xattr -cr \(app.path)")
|
||||
}
|
||||
}
|
||||
|
||||
if let error = error {
|
||||
throw Error.executing(
|
||||
command: command,
|
||||
error: error
|
||||
)
|
||||
} else {
|
||||
return descriptor.stringValue
|
||||
private static func execute(command: String) -> Promise<Void> {
|
||||
return Promise { seal in
|
||||
print("Execute command: \(command)")
|
||||
var error: NSDictionary?
|
||||
guard let script = NSAppleScript(source: "do shell script \"\(command)\"") else {
|
||||
return seal.reject(Error.executing(command: command, error: ["error": "Create script failed."]))
|
||||
}
|
||||
script.executeAndReturnError(&error)
|
||||
if let error = error {
|
||||
seal.reject(Error.executing(command: command, error: error))
|
||||
} else {
|
||||
seal.fulfill(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,20 +80,6 @@ struct Config: Decodable {
|
|||
|
||||
let version: String
|
||||
let targets: [Target]
|
||||
|
||||
static func load(url: URL) async throws -> [Config] {
|
||||
if url.isFileURL {
|
||||
return try JSONDecoder().decode(
|
||||
[Config].self,
|
||||
from: Data(contentsOf: url)
|
||||
)
|
||||
} else {
|
||||
return try JSONDecoder().decode(
|
||||
[Config].self,
|
||||
from: try await URLSession.shared.data(from: url).0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
|
|
|
|||
|
|
@ -5,71 +5,13 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import Dispatch
|
||||
import PromiseKit
|
||||
import ArgumentParser
|
||||
|
||||
// MARK: Versions
|
||||
extension Tweak {
|
||||
struct Versions: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(abstract: "List all supported WeChat versions")
|
||||
|
||||
@OptionGroup
|
||||
var options: Tweak.Options
|
||||
|
||||
mutating func run() async throws {
|
||||
print("------ Current version ------")
|
||||
print(try await Command.version(app: options.app) ?? "unknown")
|
||||
print("------ Supported versions ------")
|
||||
try await Config.load(url: options.config).forEach({ print($0.version) })
|
||||
Darwin.exit(EXIT_SUCCESS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Patch
|
||||
extension Tweak {
|
||||
struct Patch: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(abstract: "Patch WeChat.app")
|
||||
|
||||
@OptionGroup
|
||||
var options: Tweak.Options
|
||||
|
||||
mutating func run() async throws {
|
||||
print("------ Version ------")
|
||||
let version = try await Command.version(app: options.app)
|
||||
print("WeChat version: \(version ?? "unknown")")
|
||||
|
||||
print("------ Config ------")
|
||||
guard let config = (try await Config.load(url: options.config)).first(where: { $0.version == version }) else {
|
||||
throw Error.unsupportedVersion
|
||||
}
|
||||
print("Matched config: \(config)")
|
||||
|
||||
print("------ Patch ------")
|
||||
try await Command.patch(
|
||||
app: options.app,
|
||||
config: config
|
||||
)
|
||||
print("Done!")
|
||||
|
||||
print("------ Resign ------")
|
||||
try await Command.resign(
|
||||
app: options.app
|
||||
)
|
||||
print("Done!")
|
||||
|
||||
Darwin.exit(EXIT_SUCCESS)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Tweak
|
||||
struct Tweak: AsyncParsableCommand {
|
||||
struct Patch: ParsableCommand {
|
||||
enum Error: LocalizedError {
|
||||
case invalidApp
|
||||
case invalidConfig
|
||||
case invalidVersion
|
||||
case unsupportedVersion
|
||||
|
||||
var errorDescription: String? {
|
||||
|
|
@ -78,61 +20,86 @@ struct Tweak: AsyncParsableCommand {
|
|||
return "Invalid app path"
|
||||
case .invalidConfig:
|
||||
return "Invalid patch config"
|
||||
case .invalidVersion:
|
||||
return "Invalid app version"
|
||||
case .unsupportedVersion:
|
||||
return "Unsupported WeChat version"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Options: ParsableArguments {
|
||||
@Option(
|
||||
name: .shortAndLong,
|
||||
help: "Path of WeChat.app",
|
||||
transform: {
|
||||
guard FileManager.default.fileExists(atPath: $0) else {
|
||||
throw Error.invalidApp
|
||||
}
|
||||
return URL(fileURLWithPath: $0)
|
||||
}
|
||||
)
|
||||
var app: URL = URL(fileURLWithPath: "/Applications/WeChat.app", isDirectory: true)
|
||||
static let configuration = CommandConfiguration(abstract: "Patch WeChat.app")
|
||||
|
||||
@Option(
|
||||
name: .shortAndLong,
|
||||
help: "Local path or Remote URL of config.json",
|
||||
transform: {
|
||||
if FileManager.default.fileExists(atPath: $0) {
|
||||
return URL(fileURLWithPath: $0)
|
||||
} else {
|
||||
guard let url = URL(string: $0) else {
|
||||
throw Error.invalidConfig
|
||||
}
|
||||
return url
|
||||
}
|
||||
@Option(
|
||||
name: .shortAndLong,
|
||||
help: "Default: /Applications/WeChat.app",
|
||||
transform: {
|
||||
guard FileManager.default.fileExists(atPath: $0) else {
|
||||
throw Error.invalidApp
|
||||
}
|
||||
)
|
||||
var config: URL = URL(string:"https://raw.githubusercontent.com/sunnyyoung/WeChatTweak/refs/heads/master/config.json")!
|
||||
return URL(fileURLWithPath: $0)
|
||||
}
|
||||
)
|
||||
var app: URL = URL(fileURLWithPath: "/Applications/WeChat.app", isDirectory: true)
|
||||
|
||||
@Option(
|
||||
name: .shortAndLong,
|
||||
help: "Default: ./config.json",
|
||||
transform: {
|
||||
guard FileManager.default.fileExists(atPath: $0) else {
|
||||
throw Error.invalidConfig
|
||||
}
|
||||
return URL(fileURLWithPath: $0)
|
||||
}
|
||||
)
|
||||
var config: URL = {
|
||||
var size: UInt32 = 0
|
||||
_NSGetExecutablePath(nil, &size)
|
||||
var buffer = [CChar](repeating: 0, count: Int(size))
|
||||
guard _NSGetExecutablePath(&buffer, &size) == 0, let path = String(utf8String: buffer) else {
|
||||
return URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
|
||||
}
|
||||
return URL(fileURLWithPath: path).resolvingSymlinksInPath().deletingLastPathComponent().appendingPathComponent("config.json")
|
||||
}()
|
||||
|
||||
func run() throws {
|
||||
let configs = try JSONDecoder().decode([Config].self, from: Data(contentsOf: self.config))
|
||||
|
||||
guard
|
||||
let info = NSDictionary(contentsOf: self.app.appendingPathComponent("Contents/Info.plist")),
|
||||
let version = info["CFBundleVersion"] as? String,
|
||||
let config = configs.first(where: { $0.version == version })
|
||||
else {
|
||||
throw Error.unsupportedVersion
|
||||
}
|
||||
|
||||
firstly {
|
||||
Command.patch(
|
||||
app: self.app,
|
||||
config: config
|
||||
)
|
||||
}.then {
|
||||
Command.resign(app: self.app)
|
||||
}.ensure {
|
||||
print("")
|
||||
}.done {
|
||||
print("🎉 Done!")
|
||||
Darwin.exit(EXIT_SUCCESS)
|
||||
}.catch { error in
|
||||
print("🚨 \(error.localizedDescription)", stderr)
|
||||
Darwin.exit(EXIT_FAILURE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Tweak: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "wechattweak",
|
||||
abstract: "A command-line tool for tweaking WeChat.",
|
||||
subcommands: [
|
||||
Versions.self,
|
||||
Patch.self
|
||||
]
|
||||
],
|
||||
defaultSubcommand: Self.self
|
||||
)
|
||||
|
||||
mutating func run() async throws {
|
||||
print(Tweak.helpMessage())
|
||||
Darwin.exit(EXIT_SUCCESS)
|
||||
}
|
||||
}
|
||||
|
||||
Task {
|
||||
await Tweak.main()
|
||||
}
|
||||
|
||||
Dispatch.dispatchMain()
|
||||
Tweak.main()
|
||||
CFRunLoopRun()
|
||||
|
|
|
|||
205
config.json
205
config.json
|
|
@ -71,211 +71,6 @@
|
|||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "multiInstance",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001e1c10",
|
||||
"asm": "20008052C0035FD6"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "32281",
|
||||
"targets": [
|
||||
{
|
||||
"identifier": "revoke",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "103db33e0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "startUpdater",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001e9ed0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "startBackgroundUpdatesCheck",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001ecb10",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "checkForUpdates",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001ec73c",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "enableAutoUpdate",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001ecfc0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "automaticallyDownloadsUpdates",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001f59e0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "canCheckForUpdate",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001f59e0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "multiInstance",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001e1a74",
|
||||
"asm": "20008052C0035FD6"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "32288",
|
||||
"targets": [
|
||||
{
|
||||
"identifier": "revoke",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "103db34c0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "startUpdater",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001e9ed0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "startBackgroundUpdatesCheck",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001ecb10",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "checkForUpdates",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001ec73c",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "enableAutoUpdate",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001ecfc0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "automaticallyDownloadsUpdates",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001f59e0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "canCheckForUpdate",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001f59e0",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "multiInstance",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001e1a74",
|
||||
"asm": "20008052C0035FD6"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "31960",
|
||||
"targets": [
|
||||
{
|
||||
"identifier": "revoke",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "10408a408",
|
||||
"asm": "00008052C0035FD6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"identifier": "multiInstance",
|
||||
"entries": [
|
||||
{
|
||||
"arch": "arm64",
|
||||
"addr": "1001e4a38",
|
||||
"asm": "20008052C0035FD6"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user