Skip to content

Commit

Permalink
Add zhihu example (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
sledgeh4w authored Dec 16, 2024
1 parent 1192fff commit fcae761
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 65 deletions.
49 changes: 26 additions & 23 deletions examples/example_ios_ali_vmp_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,32 @@
level=logging.INFO,
)

logger = logging.getLogger(__name__)
logger = logging.getLogger()


def download_file(url: str, filepath: str):
def download_sample_file(binary_path: str) -> str:
filepath = os.path.join(base_path, "..", binary_path)

path = Path(filepath).resolve()
if path.exists():
return
return filepath

if not path.parent.exists():
path.parent.mkdir(parents=True)
print(f"Downloading file: {url}")

url = "https://sourceforge.net/projects/chomper-emu/files/%s/download" % binary_path

print(f"Downloading sample file: {url}")
urllib.request.urlretrieve(url, path)
return filepath


def main():
binary_path = "binaries/ios/com.csair.MBP/CSMBP-AppStore-Package"
binary_path = "examples/binaries/ios/com.csair.MBP/CSMBP-AppStore-Package"

# Download example binary file from the Internet
download_file(
url=f"https://sourceforge.net/projects/chomper-emu/files/examples/{binary_path}/download",
filepath=os.path.join(base_path, binary_path),
)
download_file(
url=f"https://sourceforge.net/projects/chomper-emu/files/examples/{binary_path}/../Info.plist/download",
filepath=os.path.join(base_path, binary_path, "../Info.plist"),
)
# Download sample file from SourceForge
download_sample_file(binary_path)
download_sample_file(f"{binary_path}/../Info.plist")

emu = Chomper(
arch=ARCH_ARM64,
Expand All @@ -50,19 +51,21 @@ def main():
)
objc = ObjC(emu)

emu.load_module(os.path.join(base_path, binary_path))
emu.load_module(os.path.join(base_path, "..", binary_path))

ali_tiger_tally_instance = objc.msg_send("AliTigerTally", "sharedInstance")
with objc.autorelease_pool():
# Initialize
ali_tiger_tally_instance = objc.msg_send("AliTigerTally", "sharedInstance")

app_key = "xPEj7uv0KuziQnXUyPIBNUjnDvvHuW09VOYFuLYBcY-jV6fgqmfy5B1y75_iSuRM5U2zNq7MRoR9N1F-UthTEgv-QBWk68gr95BrAySzWuDzt08FrkeBZWQCGyZ0iAybalYLOJEF7nkKBtmDGLewcw=="
objc.msg_send(ali_tiger_tally_instance, "initialize:", pyobj2nsobj(emu, app_key))
app_key = pyobj2nsobj(emu, "xPEj7uv0KuziQnXUyPIBNUjnDvvHuW09VOYFuLYBcY-jV6fgqmfy5B1y75_iSuRM5U2zNq7MRoR9N1F-UthTEgv-QBWk68gr95BrAySzWuDzt08FrkeBZWQCGyZ0iAybalYLOJEF7nkKBtmDGLewcw==")
objc.msg_send(ali_tiger_tally_instance, "initialize:", app_key)

with objc.autorelease_pool():
encrypt_str = '{"biClassId":["2","3","4"]}'
encrypt_bytes = objc.msg_send(pyobj2nsobj(emu, encrypt_str), "dataUsingEncoding:", 1)
# vmpSign
data = pyobj2nsobj(emu, b'{"biClassId":["2","3","4"]}')
vmp_sign = objc.msg_send(ali_tiger_tally_instance, "vmpSign:", data)
vmp_sign_str = emu.read_string(objc.msg_send(vmp_sign, "cStringUsingEncoding:", 4))

vmp_sign = objc.msg_send(ali_tiger_tally_instance, "vmpSign:", encrypt_bytes)
logger.info("vmpSign: %s", emu.read_string(objc.msg_send(vmp_sign, "cStringUsingEncoding:", 4)))
logger.info("AliTigerTally vmpSign: %s", vmp_sign_str)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit fcae761

Please sign in to comment.