-
Notifications
You must be signed in to change notification settings - Fork 2
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
14 changed files
with
125 additions
and
206 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
MachKit/MachVirtualMemory.swift → MachMemoryKit/MachVirtualMemory.swift
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,22 @@ | ||
// | ||
// PID+ProcessName.swift | ||
// MachMemoryKit | ||
// | ||
// Created by Pedro José Pereira Vieito on 7/5/17. | ||
// Copyright © 2017 Pedro José Pereira Vieito. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import FoundationKit | ||
|
||
extension pid_t { | ||
internal init?(processName: String) { | ||
guard let process = try? Process(executableName: "pgrep", arguments: ["-n", "-i", "-x", processName]), | ||
let output = try? process.runAndGetOutputString(), | ||
let output = output.trimmingWhitespacesAndNewlines().components(separatedBy: .newlines).first, | ||
let pid = pid_t(output) else { | ||
return nil | ||
} | ||
self = pid | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,68 @@ | ||
// | ||
// MachMemoryTool.swift | ||
// MachMemoryTool | ||
// Tool to patch the memory of a running process. | ||
// | ||
// Created by Pedro José Pereira Vieito on 7/5/17. | ||
// Copyright © 2017 Pedro José Pereira Vieito. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import FoundationKit | ||
import MachMemoryKit | ||
import ArgumentParser | ||
import LoggerKit | ||
|
||
@main | ||
struct MachMemoryTool: ParsableCommand { | ||
static var configuration: CommandConfiguration { | ||
return CommandConfiguration(commandName: String(describing: Self.self)) | ||
} | ||
|
||
@Option(name: .shortAndLong, help: "Input item.") | ||
var input: String | ||
|
||
@Option(name: .shortAndLong, help: "Memory offset to read (hex).") | ||
var offset: String | ||
|
||
@Option(name: [.customShort("z"), .long], help: "Memory size to read.") | ||
var size: Int | ||
|
||
@Flag(name: .shortAndLong, help: "Verbose mode.") | ||
var verbose: Bool = false | ||
|
||
func run() throws { | ||
Logger.logMode = .commandLine | ||
Logger.logLevel = verbose ? .debug : .info | ||
|
||
do { | ||
var process: MachProcess | ||
if input == "-" { | ||
try process = MachProcess(pid: ProcessInfo.processInfo.processIdentifier) | ||
} | ||
else if let pid = Int(input) { | ||
try process = MachProcess(pid: pid) | ||
} | ||
else { | ||
try process = MachProcess(processName: input) | ||
} | ||
|
||
Logger.log(important: "PID: \(process.pid)") | ||
|
||
Logger.log(info: "ASLR Offset: \(process.memory.aslrOffset.hexString)") | ||
Logger.log(info: "Base Address: \(process.memory.baseAddress.hexString)") | ||
|
||
guard let offsetAddress = MachVirtualMemory.Address(hexString: offset) else { | ||
throw NSError(description: "Input memory offset not valid.") | ||
} | ||
|
||
let addressRange = MachVirtualMemory.AddressRange(start: process.memory.baseAddress + offsetAddress, size: MachVirtualMemory.Size(size)) | ||
let data = try process.memory.readData(on: addressRange) | ||
Logger.log(success: "Memory correctly read: 0x\(data.hexString)") | ||
} | ||
catch { | ||
Logger.log(fatalError: error) | ||
} | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,42 +1,53 @@ | ||
// swift-tools-version:5.0 | ||
// swift-tools-version:5.9 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "MachKit", | ||
name: "MachMemoryKit", | ||
platforms: [ | ||
.macOS(.v13), | ||
], | ||
products: [ | ||
.executable( | ||
name: "MachMemoryTool", | ||
targets: ["MachMemoryTool"] | ||
), | ||
.library( | ||
name: "MachKit", | ||
targets: ["MachKit"] | ||
name: "MachMemoryKit", | ||
targets: ["MachMemoryKit"] | ||
) | ||
], | ||
dependencies: [ | ||
.package(url: "git@github.com:pvieito/CommandLineKit.git", .branch("master")), | ||
.package(url: "git@github.com:pvieito/LoggerKit.git", .branch("master")), | ||
.package(url: "git@github.com:pvieito/FoundationKit.git", .branch("master")) | ||
.package(url: "git@github.com:pvieito/LoggerKit.git", branch: "master"), | ||
.package(url: "git@github.com:pvieito/FoundationKit.git", branch: "master"), | ||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"), | ||
], | ||
targets: [ | ||
.target( | ||
.executableTarget( | ||
name: "MachMemoryTool", | ||
dependencies: ["MachKit", "LoggerKit", "CommandLineKit"], | ||
dependencies: [ | ||
"FoundationKit", | ||
"LoggerKit", | ||
"MachMemoryKit", | ||
.product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
], | ||
path: "MachMemoryTool" | ||
), | ||
.target( | ||
name: "MachKit", | ||
dependencies: ["MachAttach", "FoundationKit"], | ||
path: "MachKit" | ||
name: "MachMemoryKit", | ||
dependencies: [ | ||
"MachAttach", | ||
"FoundationKit" | ||
], | ||
path: "MachMemoryKit" | ||
), | ||
.target( | ||
name: "MachAttach", | ||
path: "MachAttach" | ||
), | ||
.testTarget( | ||
name: "MachKitTests", | ||
dependencies: ["MachKit"] | ||
name: "MachMemoryKitTests", | ||
dependencies: ["MachMemoryKit", "FoundationKit"] | ||
) | ||
] | ||
) |
Oops, something went wrong.