Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Extraction #4

Closed
freeload101 opened this issue Oct 2, 2022 · 2 comments
Closed

Simple Extraction #4

freeload101 opened this issue Oct 2, 2022 · 2 comments
Labels
question Further information is requested

Comments

@freeload101
Copy link

freeload101 commented Oct 2, 2022

Sorry I'm building a portable Android Pen testing Powershell script for Windows and I can't for the life of me get frida-server-15.2.2-android-x86.xz extracted... 7zip can extract it but I'm not looking to download yet another binary blob just for this xz file... Extracted it's a single ELF binary "frida-server-15.2.2-android-x86" Plz help...I can't find anything but this Python mod. My environment has Android Emulator running with Host running Java and Python. Everything else I can figure out but how to extract this xz file without installing 7zip....

import xz

with xz.open('frida-server-15.2.2-android-x86.xz') as f:
    print(f)
python 1.py
<XZFile object at 0x1044ab7aec>

Here is the project so far:
https://github.com/freeload101/Java-Android-Magisk-Burp-Objection-Root-Emulator-Easy

@Rogdham
Copy link
Owner

Rogdham commented Oct 2, 2022

Hello @freeload101,

The f variable you get is a file-like object, so to get the data you should use the .read method:

with xz.open('frida-server-15.2.2-android-x86.xz') as f:
    print(f.read(4))  # get the first 4 bytes, will print b'\x7fELF'

If you want to read it all into a variable, you can use .read() without specifying the number of bytes to read:

with xz.open('frida-server-15.2.2-android-x86.xz') as f:
    data = f.read()

print(len(data))  # 46387888 (so 46MB)

If you want to decompress it into an other file, open the other file for writing (in binary mode) and use shutil.copyfileobj:

import shutil

with xz.open('frida-server-15.2.2-android-x86.xz') as f:
    with open('frida-server.elf', 'wb') as fout:
        shutil.copyfileobj(f, fout)

Tell me if that works for you, or if you need more precise help achieving something please describe your use-case more precisely!


Also, I must mention that this library aims at filling the gaps in the XZ support of the standard library; if you are only interested in reading all data in one pass of that file, you may use the standard library directly by using lzma instead of xz in all my examples above.

@freeload101
Copy link
Author

OMG THANK YOU SO MUCH!

@Rogdham Rogdham added the question Further information is requested label Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants