-
Notifications
You must be signed in to change notification settings - Fork 4
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
7 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ dataclasses; python_version<"3.7" | |
pygments | ||
objc_types_decoder | ||
pycrashreport>=0.0.8 | ||
lief |
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,31 @@ | ||
import plistlib | ||
import struct | ||
from typing import Mapping | ||
|
||
import lief | ||
|
||
from rpcclient.common import path_to_str | ||
from rpcclient.darwin.consts import kSecCodeMagicEntitlement | ||
from rpcclient.exceptions import NoEntitlementsError | ||
from rpcclient.lief import Lief | ||
|
||
|
||
class DarwinLief(Lief): | ||
@path_to_str('path') | ||
def get_entitlements(self, path: str) -> Mapping: | ||
with self._client.fs.open(path, 'r') as f: | ||
buf = f.readall() | ||
parsed = lief.parse(buf) | ||
code_signature = buf[parsed.code_signature.data_offset: | ||
parsed.code_signature.data_offset + parsed.code_signature.data_size] | ||
|
||
ent_magic = struct.pack('>I', kSecCodeMagicEntitlement) | ||
ent_magic_offset = code_signature.find(ent_magic) | ||
|
||
if ent_magic_offset == -1: | ||
raise NoEntitlementsError() | ||
|
||
ent_buf = code_signature[ent_magic_offset + len(ent_magic) + 4:] | ||
end_plist_magic = b'</plist>' | ||
ent_buf = ent_buf[:ent_buf.find(end_plist_magic) + len(end_plist_magic)] | ||
return plistlib.loads(ent_buf) |
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,28 @@ | ||
from collections import namedtuple | ||
from typing import Mapping | ||
|
||
import lief | ||
|
||
from rpcclient.common import path_to_str | ||
|
||
Symbol = namedtuple('Symbol', 'origin value') | ||
|
||
|
||
class Lief: | ||
"""" parse and patch executable files """ | ||
|
||
def __init__(self, client): | ||
self._client = client | ||
|
||
@path_to_str('path') | ||
def parse(self, path: str): | ||
with self._client.fs.open(path, 'r') as f: | ||
return lief.parse(f.readall()) | ||
|
||
@path_to_str('path') | ||
def get_symbols(self, path: str) -> Mapping[str, Symbol]: | ||
result = {} | ||
parsed = self.parse(path) | ||
for s in parsed.symbols: | ||
result[s.name] = Symbol(origin=s.origin, value=s.value) | ||
return result |