Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Zer0xFF committed Sep 11, 2018
1 parent 305aeae commit 8ed0a2d
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "sfo"]
path = sfo
url = https://github.com/Jasily/py.dataformat.sfo.git
66 changes: 66 additions & 0 deletions appinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
_appinfo = {}

_appinfo["#_access_index"] = "67"
_appinfo["#_last_access_time"] = "2018-07-27 15:04:39.822"
_appinfo["#_contents_status"] = "0"
_appinfo["#_mtime"] = "2018-07-27 15:04:40.635"
_appinfo["#_update_index"] = "74"
_appinfo["#exit_type"] = "0"
_appinfo["ATTRIBUTE_INTERNAL"] = "0"
_appinfo["DISP_LOCATION_1"] = "0"
_appinfo["DISP_LOCATION_2"] = "0"
_appinfo["DOWNLOAD_DATA_SIZE"] = "0"
_appinfo["FORMAT"] = "obs"
_appinfo["PARENTAL_LEVEL"] = "1"
_appinfo["SERVICE_ID_ADDCONT_ADD_1"] = "0"
_appinfo["SERVICE_ID_ADDCONT_ADD_2"] = "0"
_appinfo["SERVICE_ID_ADDCONT_ADD_3"] = "0"
_appinfo["SERVICE_ID_ADDCONT_ADD_4"] = "0"
_appinfo["SERVICE_ID_ADDCONT_ADD_5"] = "0"
_appinfo["SERVICE_ID_ADDCONT_ADD_6"] = "0"
_appinfo["SERVICE_ID_ADDCONT_ADD_7"] = "0"
_appinfo["SYSTEM_VER"] = "33751040"
_appinfo["USER_DEFINED_PARAM_1"] = "0"
_appinfo["USER_DEFINED_PARAM_2"] = "0"
_appinfo["USER_DEFINED_PARAM_3"] = "0"
_appinfo["USER_DEFINED_PARAM_4"] = "0"
_appinfo["_contents_ext_type"] = "0"
_appinfo["_contents_location"] = "0"
_appinfo["_current_slot"] = "0"
_appinfo["_disable_live_detail"] = "0"
_appinfo["_hdd_location"] = "0"
_appinfo["_path_info"] = "3113537756987392"
_appinfo["_path_info_2"] = "0"
_appinfo["_size_other_hdd"] = "0"
_appinfo["_sort_priority"] = "100"
_appinfo["_uninstallable"] = "1"
_appinfo["_view_category"] = "0"
_appinfo["_working_status"] = "0"

def get_pseudo_appinfo(sfo, size) :
copy__appinfo = _appinfo

copy__appinfo["#_size"] = "%d" % size
copy__appinfo["_org_path"] = "/user/app/%s" % sfo["TITLE_ID"]
copy__appinfo["_metadata_path"] = "/user/appmeta/%s" % sfo["TITLE_ID"]

copy__appinfo["APP_TYPE"] = sfo["APP_TYPE"]
copy__appinfo["APP_VER"] = sfo["APP_VER"]
copy__appinfo["ATTRIBUTE"] = sfo["ATTRIBUTE"]
copy__appinfo["CATEGORY"] = sfo["CATEGORY"]
copy__appinfo["CONTENT_ID"] = sfo["CONTENT_ID"]
copy__appinfo["TITLE"] = sfo["TITLE"]
copy__appinfo["TITLE_ID"] = sfo["TITLE_ID"]
copy__appinfo["VERSION"] = sfo["VERSION"]

if(False) :
print(" %s" % copy__appinfo["APP_TYPE"])
print(" %s" % copy__appinfo["APP_VER"])
print(" %s" % copy__appinfo["ATTRIBUTE"])
print(" %s" % copy__appinfo["CATEGORY"])
print(" %s" % copy__appinfo["CONTENT_ID"])
print(" %s" % copy__appinfo["TITLE"])
print(" %s" % copy__appinfo["TITLE_ID"])
print(" %s" % copy__appinfo["VERSION"])

return copy__appinfo
119 changes: 119 additions & 0 deletions fix_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
from ftplib import FTP
import sqlite3
import appinfo
import io
import os
from sfo.sfo import SfoFile as SfoFile
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("PS4_IP", help="PS4 ftp ip address")
args = parser.parse_args()
app_db = "tmp/app.db"
PS4_IP = args.PS4_IP

if not os.path.exists('tmp'):
os.makedirs('tmp')

class CUSA :
sfo = None
size = 10000000
is_usable = False

info = {}
files = []

def sort_files(file) :
if("CUSA" in file) :
files.append("'%s'" % file[-9:])

def get_game_info_by_id(GameID) :
if(GameID not in info) :
info[GameID] = CUSA()

buffer = io.BytesIO()
ftp.cwd('/system_data/priv/appmeta/%s/' % GameID)
ftp.retrbinary("RETR param.sfo" , buffer.write)
buffer.seek(0)
sfo = SfoFile.from_reader(buffer)
info[GameID].sfo = sfo
info[GameID].size = ftp.size("/user/app/%s/app.pkg" % GameID)
info[GameID].is_usable = True

return info[GameID]


ftp = FTP()
ftp.connect(PS4_IP, 1337, timeout=30)
ftp.login(user='username', passwd = 'password')
if(len(files) == 0) :
ftp.cwd('/user/app/')
ftp.dir(sort_files)
print(files)


ftp.cwd('/system_data/priv/mms/')
lf = open(app_db, "wb")
ftp.retrbinary("RETR app.db" , lf.write)
lf.close()

conn = sqlite3.connect(app_db)

cursor = conn.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'tbl_appbrowse_%%';")
tables = cursor.fetchall()

files_joined = "SELECT %s AS titleid " % ' AS titleid UNION SELECT '.join(files)
tbl_appbrowse = []
for tbl in tables :
tbl_appbrowse.append(tbl[0])
print("Processing table: %s" % tbl[0])
cursor.execute("SELECT T.titleid FROM (%s) T WHERE T.titleid NOT IN (SELECT titleid FROM %s);" % (files_joined, tbl[0]))
list_id = cursor.fetchall()
sql_list = []
for tmp_GameID in list_id :
GameID = tmp_GameID[0].replace("'", "")
print(" Processing GameID: %s... " % GameID, end='')
cusa = get_game_info_by_id(GameID)
if(cusa.is_usable == True) :
sql_list.append("""("%s", "%s", "%s", "/user/appmeta/%s", "2018-07-27 15:06:46.822", "0", "0", "5", "1", "100", "0", "151", "5", "1", "gd", "0", "0", "0", "0", NULL, NULL, NULL, "%d", "2018-07-27 15:06:46.802", "0", "game", NULL, "0", "0", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "0", NULL, NULL, NULL, NULL, NULL, "0", "0", NULL, "2018-07-27 15:06:46.757")"""
% (cusa.sfo['TITLE_ID'], cusa.sfo['CONTENT_ID'], cusa.sfo['TITLE'], cusa.sfo['TITLE_ID'], cusa.size))
print("Completed %d" % cusa.size)
else :
print("Skipped")

if(len(sql_list) > 0) :
cursor.execute("INSERT INTO %s VALUES %s;" % (tbl[0], ', '.join(sql_list)))

print('')
print('')
print('')

print("Processing table: tbl_appinfo")

cursor.execute("SELECT DISTINCT T.titleid FROM (SELECT titleid FROM %s) T WHERE T.titleid LIKE 'CUSA%%' AND T.titleid NOT IN (SELECT DISTINCT titleid FROM tbl_appinfo);" % (" UNION SELECT titleid FROM ".join(tbl_appbrowse)))
missing_appinfo_cusa_id = cursor.fetchall()
for tmp_cusa_id in missing_appinfo_cusa_id :
game_id = tmp_cusa_id[0]
print(" Processing GameID: %s... " % game_id, end='')
cusa = get_game_info_by_id(game_id)
if(cusa.is_usable == True) :
sql_items = appinfo.get_pseudo_appinfo(cusa.sfo, cusa.size)
for key, value in sql_items.items():
cursor.execute("INSERT INTO tbl_appinfo (titleid, key, val) VALUES (?, ?, ?);", [game_id, key, value])
print("Completed")
else :
print("Skipped")

conn.commit()

conn.close()

ftp.cwd('/system_data/priv/mms/')
file = open(app_db,'rb')
ftp.storbinary('STOR app.db', file)
file.close()
1 change: 1 addition & 0 deletions sfo
Submodule sfo added at 99b2ad

0 comments on commit 8ed0a2d

Please sign in to comment.