int set_registry_value(const char *dir, const char *name, unsigned int val) { int ret = 0; struct RegParam reg; REGHANDLE h; memset(®, 0, sizeof(reg)); reg.regtype = 1; reg.namelen = strlen("/system"); reg.unk2 = 1; reg.unk3 = 1; strcpy(reg.name, "/system"); if(sceRegOpenRegistry(®, 2, &h) == 0) { REGHANDLE hd; if(!sceRegOpenCategory(h, dir, 2, &hd)) { if(!sceRegSetKeyValue(hd, name, &val, 4)) { printf("Set registry value\n"); ret = 1; sceRegFlushCategory(hd); } sceRegCloseCategory(hd); } sceRegFlushRegistry(h); sceRegCloseRegistry(h); } return ret; }
int check_dir(const char *dir) { struct RegParam reg; REGHANDLE h; int ret = 0; dir = strchr(&dir[1], '/'); if(dir == NULL) { return 0; } memset(®, 0, sizeof(reg)); reg.regtype = 1; reg.namelen = strlen("/system"); reg.unk2 = 1; reg.unk3 = 1; strcpy(reg.name, "/system"); if(sceRegOpenRegistry(®, 2, &h) == 0) { REGHANDLE hd; if(!sceRegOpenCategory(h, dir, 2, &hd)) { sceRegCloseCategory(hd); ret = 1; } sceRegCloseRegistry(h); } else { printf("ERROR: Could not open registry\n"); } return ret; }
int get_registry_value(const char *dir, const char *name, u32 *val) { int ret = 0; struct RegParam reg; REGHANDLE h; memset(®, 0, sizeof(reg)); reg.regtype = 1; reg.namelen = strlen("/system"); reg.unk2 = 1; reg.unk3 = 1; strcpy(reg.name, "/system"); if(sceRegOpenRegistry(®, 2, &h) == 0) { REGHANDLE hd; if(!sceRegOpenCategory(h, dir, 2, &hd)) { REGHANDLE hk; unsigned int type, size; if(!sceRegGetKeyInfo(hd, name, &hk, &type, &size)) { if(!sceRegGetKeyValue(hd, hk, val, 4)) { ret = 1; sceRegFlushCategory(hd); } } sceRegCloseCategory(hd); } sceRegFlushRegistry(h); sceRegCloseRegistry(h); } return ret; }
int LPP_UtilsSetSystemReg(const char *dir, const char *name, u32 val) { struct RegParam reg; REGHANDLE handle; memset(®, 0, sizeof(struct RegParam)); reg.regtype = 1; reg.namelen = 7; reg.unk2 = 1; reg.unk3 = 1; memcpy(reg.name, "/system", reg.namelen); int ret = -1; if(sceRegOpenRegistry(®, 2, &handle) == 0) { REGHANDLE hd; if(sceRegOpenCategory(handle, dir, 2, &hd) == 0) { if(sceRegSetKeyValue(hd, name, &val, 4)) { ret = 0; sceRegFlushCategory(hd); } else { sceRegCreateKey(hd, name, REG_TYPE_INT, 4); sceRegSetKeyValue(hd, name, &val, 4); ret = 0; sceRegFlushCategory(hd); } sceRegCloseCategory(hd); } sceRegFlushRegistry(handle); sceRegCloseRegistry(handle); } return ret; }
int LPP_UtilsGetSystemReg(const char *dir, const char *name, u32 *val) { struct RegParam reg; REGHANDLE handle = 0; memset(®, 0, sizeof(struct RegParam)); reg.regtype = 1; reg.namelen = 7; reg.unk2 = 1; reg.unk3 = 1; memcpy(reg.name, "/system", reg.namelen); int ret = -1; if(sceRegOpenRegistry(®, 1, &handle) == 0) { REGHANDLE hd; if(sceRegOpenCategory(handle, dir, 2, &hd) == 0) { REGHANDLE hk; u32 type, size; if(sceRegGetKeyInfo(hd, name, &hk, &type, &size) == 0) { if(sceRegGetKeyValue(hd, hk, val, 4) == 0) { ret = 0; sceRegFlushCategory(hd); } } sceRegCloseCategory(hd); } sceRegFlushRegistry(handle); sceRegCloseRegistry(handle); } return ret; }
//Registry int SetRegistryValue(const char *dir, const char *name, u32 val) { int ret = 0; struct RegParam reg; REGHANDLE h; memset(®, 0, sizeof(reg)); reg.regtype = 1; reg.namelen = strlen("/system"); reg.unk2 = 1; reg.unk3 = 1; strcpy(reg.name, "/system"); if(sceRegOpenRegistry(®, 2, &h) == 0) { REGHANDLE hd; if(!sceRegOpenCategory(h, dir, 2, &hd)) { if(!sceRegSetKeyValue(hd, name, &val, 4)) { ret = 1; sceRegFlushCategory(hd); } else { sceRegCreateKey(hd, name, REG_TYPE_INT, 4); sceRegSetKeyValue(hd, name, &val, 4); ret = 1; sceRegFlushCategory(hd); } sceRegCloseCategory(hd); } sceRegFlushRegistry(h); sceRegCloseRegistry(h); } return ret; }
/* Print out a directory key */ void print_key(const char *dir) { struct RegParam reg; REGHANDLE h; if(strcmp(dir, ROOT_DIR) == 0) { print_key_root(); return; } dir = strchr(&dir[1], '/'); if(dir == NULL) { return; } memset(®, 0, sizeof(reg)); reg.regtype = 1; reg.namelen = strlen("/system"); reg.unk2 = 1; reg.unk3 = 1; strcpy(reg.name, "/system"); if(sceRegOpenRegistry(®, 2, &h) == 0) { REGHANDLE hd; if(!sceRegOpenCategory(h, dir, 2, &hd)) { int num; if(!sceRegGetKeysNum(hd, &num)) { char *data; printf("Key Entries: %d\n", num); data = malloc(num*27); if(data) { if(!sceRegGetKeys(hd, data, num)) { int i; for(i = 0; i < num; i++) { print_key_info(hd, &data[i*27]); } free(data); } else { printf("Could not get key values\n"); } } else { printf("Could not allocate key data\n"); } } else { printf("Could not get number of keys\n"); } sceRegCloseCategory(hd); } else { printf("Could not open directory\n"); } sceRegCloseRegistry(h); } else { printf("Could not open registry\n"); } }
void *orpGetValue(char *key, SceSize *key_size) { void *value = NULL; REGHANDLE rh; struct RegParam reg = { .regtype = 1, .namelen = strlen(SYSTEM_REGISTRY), .unk2 = 1, .unk3 = 1, }; strcpy(reg.name, SYSTEM_REGISTRY); int rc; if ((rc = sceRegOpenRegistry(®, 1, &rh)) < 0) { printf("Error opening registry.\n"); return value; } REGHANDLE cat; if ((rc = sceRegOpenCategory(rh, "/CONFIG/PREMO", 1, &cat)) < 0) { printf("Error opening: /CONFIG/PREMO\n"); goto _orpGetValue_exit1; } unsigned int key_type; if ((rc = sceRegGetKeyInfoByName(cat, key, &key_type, key_size)) < 0) printf("Key info failed: %s: %d\n", key, rc); else { // printf("%s: type: %d, size: %d\n", key, key_type, *key_size); value = malloc(*key_size); if ((rc = sceRegGetKeyValueByName(cat, key, value, *key_size)) < 0) { free(value); value = NULL; printf("Key look-up failed: %s\n", key); goto _orpGetValue_exit2; } } _orpGetValue_exit2: sceRegCloseCategory(cat); _orpGetValue_exit1: sceRegCloseRegistry(rh); return value; } int main() { pspDebugScreenInit(); SetupCallbacks(); printf("Open Remote Play Exporter!\n\n"); int rc; struct orpConfigRecord_t record; memset(&record, 0, sizeof(struct orpConfigRecord_t)); record.ps3_port = ORP_PORT; strcpy((char *)record.ps3_hostname, "0.0.0.0"); SceSize key_size; unsigned char *value; if ((value = orpGetValue("ps3_name", &key_size)) != NULL) { printf("%16s: %s\n", "Name", value); strncpy((char *)record.ps3_nickname, (const char *)value, ORP_NICKNAME_LEN); free(value); } else { printf("This PSP has not been registered for Remote Play!\n"); printf("\nPress HOME to quit.\n"); sceKernelSleepThread(); return 0; } if ((rc = sceUtilityGetSystemParamString(PSP_SYSTEMPARAM_ID_STRING_NICKNAME, (char *)record.psp_owner, ORP_NICKNAME_LEN)) == 0) { printf("%16s: %s\n", "PSP Owner", record.psp_owner); } if ((value = orpGetValue("ps3_mac", &key_size)) != NULL) { printf("%16s: ", "PS3 MAC Address"); int i; for (i = 0; i < key_size - 1; i++) printf("%02x:", value[i]); printf("%02x\n", value[key_size - 1]); memcpy(record.ps3_mac, value, ORP_MAC_LEN); free(value); } u8 mac[8]; if ((rc = sceWlanGetEtherAddr(mac)) == 0) { printf("%16s: ", "PSP MAC Address"); int i; memcpy(record.psp_mac, mac, ORP_MAC_LEN); for (i = 0; i < ORP_MAC_LEN - 1; i++) printf("%02x:", record.psp_mac[i]); printf("%02x\n", record.psp_mac[ORP_MAC_LEN - 1]); } PspOpenPSID psid; memset(&psid, 0, sizeof(psid)); if ((rc = sceOpenPSIDGetOpenPSID(&psid) == 0)) { printf("%16s: ", "PSP ID"); int i; for (i = 0; i < sizeof(psid.data) - 1; i++) printf("%02x", psid.data[i]); printf("%02x\n", psid.data[sizeof(psid.data) - 1]); memcpy(record.psp_id, psid.data, ORP_KEY_LEN); } if ((value = orpGetValue("ps3_key", &key_size)) != NULL) { printf("%16s: ", "Private Key"); int i; for (i = 0; i < key_size; i++) printf("%02x", value[i]); printf("\n"); memcpy(record.pkey, value, ORP_KEY_LEN); free(value); } char path[] = { "ms0:/export.orp" }; sceIoRemove(path); SceUID fd = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT, 0777); if (fd < 0) printf("\nUnable to open: %s\n", path); else { struct orpConfigHeader_t header; memset(&header, 0, sizeof(struct orpConfigHeader_t)); header.magic[0] = 'O'; header.magic[1] = 'R'; header.magic[2] = 'P'; header.version = ORP_CONFIG_VER; header.flags = ORP_CONFIG_EXPORT; sceIoWrite(fd, &header, sizeof(struct orpConfigHeader_t)); sceIoWrite(fd, &record, sizeof(struct orpConfigRecord_t)); sceIoClose(fd); printf("\nConfiguration saved to: %s\n", path); } printf("\nPress HOME to quit.\n"); sceKernelSleepThread(); return 0; }