forked from d3m3vilurr/vita-savemgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappdb.c
72 lines (67 loc) · 2.16 KB
/
appdb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdlib.h>
#include <string.h>
#include "sqlite3/sqlite3.h"
#include "appdb.h"
#define APP_DB "ur0:shell/db/app.db"
static int get_applist_callback(void *data, int argc, char **argv, char **cols) {
applist *list = (applist*)data;
appinfo *info = malloc(sizeof(appinfo));
memset(info, 0, sizeof(appinfo));
if (list->count == 0) {
list->items = info;
} else {
appinfo *tmp = list->items;
while(tmp->next != NULL) {
tmp = tmp->next;
}
tmp->next = info;
info->prev = tmp;
}
list->count += 1;
strcpy(info->title_id, argv[0]);
strcpy(info->real_id, argv[1]);
strcpy(info->title, argv[2]);
strcpy(info->eboot, argv[3]);
strcpy(info->dev, argv[4]);
for (int i = 0; i < 256; i++) {
if (info->title_id[i] == '\n') {
info->title_id[i] = ' ';
}
}
return 0;
}
int get_applist(applist *list) {
char *query = "select a.titleid, b.realid, c.title, d.ebootbin,"
" rtrim(substr(d.ebootbin, 0, 5), ':') as dev"
" from (select titleid"
" from tbl_appinfo"
" where key = 566916785"
" and titleid like 'PCS%'"
" order by titleid) a,"
" (select titleid, val as realid"
" from tbl_appinfo"
" where key = 278217076) b,"
" tbl_appinfo_icon c,"
" (select titleid, val as ebootbin"
" from tbl_appinfo"
" where key = 3022202214) d"
" where a.titleid = b.titleid"
" and a.titleid = c.titleid"
" and a.titleid = d.titleid";
sqlite3 *db;
int ret = sqlite3_open(APP_DB, &db);
if (ret) {
return -1;
}
char *errMsg;
ret = sqlite3_exec(db, query, get_applist_callback, (void *)list, &errMsg);
if (ret != SQLITE_OK) {
sqlite3_close(db);
return -2;
}
sqlite3_close(db);
if (list->count <= 0) {
return -3;
}
return 0;
}