Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -15,6 +15,24 @@ BASE_URL = "https://gabefromsimplebit-simplebit-signer.hf.space"
|
|
| 15 |
def home():
|
| 16 |
return "SimpleBit Signer is Online!"
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
@app.route('/sign', methods=['POST'])
|
| 19 |
def sign():
|
| 20 |
job_id = str(uuid.uuid4())[:8]
|
|
@@ -34,33 +52,10 @@ def sign():
|
|
| 34 |
p12.save(p12_path)
|
| 35 |
prov.save(prov_path)
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
raw_plist = subprocess.run(
|
| 40 |
-
f"unzip -p {ipa_path} Payload/*.app/Info.plist",
|
| 41 |
-
shell=True, capture_output=True
|
| 42 |
-
).stdout
|
| 43 |
-
|
| 44 |
-
# Decode using latin-1 or ignore errors to handle binary bloat around the strings
|
| 45 |
-
plist_content = raw_plist.decode('utf-8', errors='ignore')
|
| 46 |
-
|
| 47 |
-
# Extract Bundle ID
|
| 48 |
-
# We use a more relaxed regex because binary plists might have null bytes between characters
|
| 49 |
-
id_match = re.search(r"CFBundleIdentifier.*?<string>(.*?)</string>", plist_content, re.DOTALL)
|
| 50 |
-
bundle_id = id_match.group(1).strip() if id_match else "com.simplebit.dynamic"
|
| 51 |
-
|
| 52 |
-
# Extract App Name
|
| 53 |
-
name_match = re.search(r"CFBundleDisplayName.*?<string>(.*?)</string>", plist_content, re.DOTALL)
|
| 54 |
-
if not name_match:
|
| 55 |
-
name_match = re.search(r"CFBundleName.*?<string>(.*?)</string>", plist_content, re.DOTALL)
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# Clean up any potential XML tags left in strings
|
| 60 |
-
bundle_id = re.sub('<[^<]+?>', '', bundle_id)
|
| 61 |
-
app_name = re.sub('<[^<]+?>', '', app_name)
|
| 62 |
-
|
| 63 |
-
# Sign the app
|
| 64 |
command = [
|
| 65 |
"zsign",
|
| 66 |
"-k", p12_path,
|
|
@@ -72,11 +67,17 @@ def sign():
|
|
| 72 |
]
|
| 73 |
|
| 74 |
try:
|
| 75 |
-
subprocess.run(command, capture_output=True, text=True, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
#
|
| 78 |
-
with open(os.path.join(job_id, "
|
| 79 |
-
f.write(
|
| 80 |
|
| 81 |
plist_url = f"{BASE_URL}/plist/{job_id}"
|
| 82 |
return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
|
|
@@ -87,13 +88,10 @@ def sign():
|
|
| 87 |
@app.route('/plist/<job_id>')
|
| 88 |
def serve_plist(job_id):
|
| 89 |
try:
|
| 90 |
-
with open(os.path.join(job_id, "
|
| 91 |
-
|
| 92 |
-
bundle_id = lines[0].strip()
|
| 93 |
-
app_name = lines[1].strip()
|
| 94 |
except:
|
| 95 |
bundle_id = "com.simplebit.dynamic"
|
| 96 |
-
app_name = "SimpleBit App"
|
| 97 |
|
| 98 |
ipa_direct_url = f"{BASE_URL}/download/{job_id}"
|
| 99 |
|
|
@@ -122,7 +120,7 @@ def serve_plist(job_id):
|
|
| 122 |
<key>kind</key>
|
| 123 |
<string>software</string>
|
| 124 |
<key>title</key>
|
| 125 |
-
<string>
|
| 126 |
</dict>
|
| 127 |
</dict>
|
| 128 |
</array>
|
|
|
|
| 15 |
def home():
|
| 16 |
return "SimpleBit Signer is Online!"
|
| 17 |
|
| 18 |
+
def get_actual_bundle_id(ipa_path):
|
| 19 |
+
""" Extracts the actual Bundle ID from the IPA's Info.plist """
|
| 20 |
+
try:
|
| 21 |
+
# Use unzip to peek at the Info.plist and grep for the ID
|
| 22 |
+
# This is more reliable than parsing zsign logs
|
| 23 |
+
cmd = f"unzip -p {ipa_path} Payload/*.app/Info.plist | grep -A1 'CFBundleIdentifier' | grep 'string' | sed 's/<[^>]*>//g' | str.strip()"
|
| 24 |
+
# Using a more robust subprocess call for the same logic:
|
| 25 |
+
result = subprocess.run(
|
| 26 |
+
f"unzip -p {ipa_path} Payload/*.app/Info.plist | grep -A1 'CFBundleIdentifier'",
|
| 27 |
+
shell=True, capture_output=True, text=True
|
| 28 |
+
)
|
| 29 |
+
match = re.search(r"<string>(.*)</string>", result.stdout)
|
| 30 |
+
if match:
|
| 31 |
+
return match.group(1).strip()
|
| 32 |
+
except Exception:
|
| 33 |
+
pass
|
| 34 |
+
return None
|
| 35 |
+
|
| 36 |
@app.route('/sign', methods=['POST'])
|
| 37 |
def sign():
|
| 38 |
job_id = str(uuid.uuid4())[:8]
|
|
|
|
| 52 |
p12.save(p12_path)
|
| 53 |
prov.save(prov_path)
|
| 54 |
|
| 55 |
+
# STEP 1: Get the REAL Bundle ID first
|
| 56 |
+
bundle_id = get_actual_bundle_id(ipa_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
# STEP 2: Sign the app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
command = [
|
| 60 |
"zsign",
|
| 61 |
"-k", p12_path,
|
|
|
|
| 67 |
]
|
| 68 |
|
| 69 |
try:
|
| 70 |
+
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
| 71 |
+
|
| 72 |
+
# If extraction failed earlier, try one last time from zsign logs
|
| 73 |
+
if not bundle_id:
|
| 74 |
+
combined_output = result.stdout + result.stderr
|
| 75 |
+
match = re.search(r"Bundle\s?Id:\s+([a-zA-Z0-9\.-]+)", combined_output, re.IGNORECASE)
|
| 76 |
+
bundle_id = match.group(1).strip() if match else "com.simplebit.dynamic"
|
| 77 |
|
| 78 |
+
# Save the confirmed ID for the /plist route
|
| 79 |
+
with open(os.path.join(job_id, "bundle_id.txt"), "w") as f:
|
| 80 |
+
f.write(bundle_id)
|
| 81 |
|
| 82 |
plist_url = f"{BASE_URL}/plist/{job_id}"
|
| 83 |
return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
|
|
|
|
| 88 |
@app.route('/plist/<job_id>')
|
| 89 |
def serve_plist(job_id):
|
| 90 |
try:
|
| 91 |
+
with open(os.path.join(job_id, "bundle_id.txt"), "r") as f:
|
| 92 |
+
bundle_id = f.read().strip()
|
|
|
|
|
|
|
| 93 |
except:
|
| 94 |
bundle_id = "com.simplebit.dynamic"
|
|
|
|
| 95 |
|
| 96 |
ipa_direct_url = f"{BASE_URL}/download/{job_id}"
|
| 97 |
|
|
|
|
| 120 |
<key>kind</key>
|
| 121 |
<string>software</string>
|
| 122 |
<key>title</key>
|
| 123 |
+
<string>SimpleBit Signed App</string>
|
| 124 |
</dict>
|
| 125 |
</dict>
|
| 126 |
</array>
|