// 670
int cso_open(SceUID fd)
{
	int ret;
	u32 *magic;

	g_CISO_hdr.magic[0] = '\0';
	g_ciso_dec_buf_offset = (u32)-1;
	g_ciso_dec_buf_size = 0;

	sceIoLseek(fd, 0, PSP_SEEK_SET);
	ret = sceIoRead(fd, &g_CISO_hdr, sizeof(g_CISO_hdr));

	if(ret != sizeof(g_CISO_hdr)) {
		ret = -1;
		printk("%s: -> %d\n", __func__, ret);
		goto exit;
	}

	magic = (u32*)g_CISO_hdr.magic;

	if(*magic == 0x4F534943) { // CISO
		g_CISO_cur_idx = -1;
		ciso_total_block = g_CISO_hdr.total_bytes / g_CISO_hdr.block_size;
		printk("%s: total block %d\n", __func__, (int)ciso_total_block);

		if(g_ciso_dec_buf == NULL) {
			g_ciso_dec_buf = oe_malloc(CISO_DEC_BUFFER_SIZE + (1 << g_CISO_hdr.align) + 64);

			if(g_ciso_dec_buf == NULL) {
				ret = -2;
				printk("%s: -> %d\n", __func__, ret);
				goto exit;
			}

			if((u32)g_ciso_dec_buf & 63)
				g_ciso_dec_buf = (void*)(((u32)g_ciso_dec_buf & (~63)) + 64);
		}

		if(g_ciso_block_buf == NULL) {
			g_ciso_block_buf = oe_malloc(ISO_SECTOR_SIZE);

			if(g_ciso_block_buf == NULL) {
				ret = -3;
				printk("%s: -> %d\n", __func__, ret);
				goto exit;
			}
		}

		ret = 0;
	} else {
		ret = 0x8002012F;
	}

exit:
	return ret;
}
Example #2
0
int vpbp_init(void)
{
    if (g_sema >= 0) {
        sceKernelDeleteSema(g_sema);
    }

    g_sema = sceKernelCreateSema("VPBPSema", 0, 1, 1, NULL);

    if (g_caches != NULL) {
        oe_free(g_caches);
        g_caches_cnt = 0;
    }

    g_caches_cnt = CACHE_MAX_SIZE;
    g_caches = oe_malloc(sizeof(g_caches[0]) * g_caches_cnt);

    if (g_caches == NULL) {
        g_caches_cnt = 0;
        printk("%s: g_cache cannot allocate\n", __func__);

        return -27;
    }

    memset(g_caches, 0, sizeof(g_caches[0]) * g_caches_cnt);

    return 0;
}
Example #3
0
static int add_nodrm_fd(SceUID fd)
{
	struct NoDrmFd *slot;

	if (fd < 0)
		return -1;

	lock();
	slot = (struct NoDrmFd*)oe_malloc(sizeof(*slot));

	if(slot == NULL) {
		unlock();

		return -2;
	}

	slot->fd = fd;
	slot->asyncKeySetup = 0;
	
	g_tail->next = slot;
	g_tail = slot;
	slot->next = NULL;

	unlock();

	return slot->fd;
}
Example #4
0
int dirent_add(SceUID dfd, SceUID iso_dfd, const char *path)
{
	struct IoDirentEntry *p;
   
	p = oe_malloc(sizeof(*p));

	if(p == NULL) {
		return -1;
	}

	p->dfd = dfd;
	p->iso_dfd = iso_dfd;
	p->path = oe_strdup(path);

	if(p->path == NULL) {
		oe_free(p);

		return -2;
	}

	lock();
	g_tail->next = p;
	g_tail = p;
	g_tail->next = NULL;
	unlock();

	return 0;
}
Example #5
0
static int get_sfo_section(VirtualPBP *vpbp, u32 remaining, void *data)
{
    int re, ret;
    void *buf, *buf_64;
    char sfotitle[64];
    char disc_id[12];
    u32 parental_level = 1;

    buf = oe_malloc(SECTOR_SIZE+64);

    if (buf == NULL) {
        printk("%s: buf cannot allocate\n", __func__);

        return -13;
    }

    buf_64 = PTR_ALIGN_64(buf);
    ret = isoRead(buf_64, vpbp->sects[0].lba, 0, SECTOR_SIZE);

    if (ret < 0) {
        printk("%s: isoRead -> 0x%08X\n", __func__, ret);
        oe_free(buf);

        return -37;
    }

    ret = get_sfo_string(buf_64, "TITLE", sfotitle, sizeof(sfotitle));

    if (ret < 0) {
        oe_free(buf);

        return ret;
    }

    ret = get_sfo_string(buf_64, "DISC_ID", disc_id, sizeof(disc_id));

    if (ret < 0) {
        oe_free(buf);

        return ret;
    }

    get_sfo_u32(buf_64, "PARENTAL_LEVEL", &parental_level);

    oe_free(buf);
    memcpy(virtualsfo+0x118, sfotitle, 64);
    memcpy(virtualsfo+0xf0, disc_id, 12);
    memcpy(virtualsfo+0x108, &parental_level, sizeof(parental_level));
    re = MIN(remaining, sizeof(virtualsfo) - (vpbp->file_pointer - vpbp->header[2]));
    memcpy(data, virtualsfo+vpbp->file_pointer-vpbp->header[2], re);

    return re;
}
Example #6
0
void *oe_realloc(void *ptr, int size)
{
    void *p;

    p = oe_malloc(size);

    if(p != NULL && ptr != NULL) {
        memcpy(p, ptr, size);
        oe_free(ptr);
    }

    return p;
}
Example #7
0
static char *oe_strdup(const char *str)
{
	int len;
	char *p;

	len = strlen(str) + 1;
	p = oe_malloc(len);

	if(p == NULL) {
		return p;
	}

	strcpy(p, str);

	return p;
}
Example #8
0
static void load_plugin(char * path, int wait)
{
	char linebuf[256];
	int fd;
	char *read_alloc_buf;

	if (path == NULL)
		return;

	if(wait && 0 == strncmp(path, "ms", 2)) {
		wait_memory_stick_ready_timeout(wait);
	}

	fd = sceIoOpen(path, PSP_O_RDONLY, 0777);

	if(fd < 0) {
		printk("%s: open %s failed 0x%08X\n", __func__, path, fd);

		return;
	}

	read_alloc_buf = oe_malloc(READ_BUF_SIZE + 64);

	if(read_alloc_buf == NULL) {
		sceIoClose(fd);
		return;
	}

	read_buf = (void*)(((u32)read_alloc_buf & (~(64-1))) + 64);
	linebuf[sizeof(linebuf)-1] = '\0';

	while(read_lines(fd, linebuf, sizeof(linebuf)-1) >= 0) {
		parse_plugin(linebuf);
	}

	sceIoClose(fd);
	oe_free(read_alloc_buf);
}
Example #9
0
int versionspoofer(u8 *buf, u32 size, u32* newsize)
{
	int result = sceResmgr_driver_9DC14891(buf, size, newsize);

	if(!rebootex_conf.recovery_mode && conf.useversion && strstr((const char*)buf, "release:")) {
		char *tmpbuf;
		int tmpsize;
		u32 k1;

		k1 = pspSdkSetK1(0);
		tmpsize = 164;
		tmpbuf = oe_malloc(tmpsize);

		if(tmpbuf == NULL) {
			goto out;
		}

		tmpsize = load_version_txt(tmpbuf, tmpsize);

		if(tmpsize > 0 && check_valid_version_txt(tmpbuf, tmpsize) == 0) {
			printk("%s: custom version.txt loaded\n", __func__);
			memcpy(buf, tmpbuf, tmpsize);
			*newsize = tmpsize;
			result = 0;
		}

out:
		if(tmpbuf != NULL) {
			oe_free(tmpbuf);
		}

		pspSdkSetK1(k1);
	}

	return result;
}
Example #10
0
static int get_ISO_shortname(char *s_name, u32 size, const char *l_name)
{
    const char *p;
    SceUID fd;
    char *prefix = NULL;
    int result = -7;
    pspMsPrivateDirent *pri_dirent = NULL;
    SceIoDirent *dirent = NULL;

    if (s_name == NULL || l_name == NULL) {
        result = -1;
        goto exit;
    }

    p = strrchr(l_name, '/');

    if (p == NULL) {
        result = -2;
        goto exit;
    }

    prefix = oe_malloc(512);
    pri_dirent = oe_malloc(sizeof(*pri_dirent));
    dirent = oe_malloc(sizeof(*dirent));

    if(prefix == NULL) {
        result = -3;
        goto exit;
    }

    if(pri_dirent == NULL) {
        result = -4;
        goto exit;
    }

    if(dirent == NULL) {
        result = -5;
        goto exit;
    }

    strncpy_s(prefix, 512, l_name, p + 1 - l_name);
    prefix[MIN(p + 1 - l_name, 512-1)] = '\0';
    printk("%s: prefix %s\n", __func__, prefix);
    fd = sceIoDopen(prefix);

    if (fd >= 0) {
        int ret;

        do {
            memset(dirent, 0, sizeof(*dirent));
            memset(pri_dirent, 0, sizeof(*pri_dirent));
            pri_dirent->size = sizeof(*pri_dirent);
            dirent->d_private = (void*)pri_dirent;
            ret = sceIoDread(fd, dirent);

            if (ret >= 0) {
                if (!strcmp(dirent->d_name, p+1)) {
                    strncpy(s_name, l_name, MIN(p + 1 - l_name, size));
                    s_name[MIN(p + 1 - l_name, size-1)] = '\0';
                    strcat(s_name, pri_dirent->s_name);
                    printk("%s: final %s\n", __func__, s_name);
                    result = 0;

                    break;
                }
            }
        } while (ret > 0);

        sceIoDclose(fd);
    } else {
        printk("%s: sceIoDopen %s -> 0x%08X\n", __func__, prefix, fd);
        result = -6;
        goto exit;
    }

exit:
    oe_free(prefix);
    oe_free(pri_dirent);
    oe_free(dirent);

    return result;
}
Example #11
0
static int get_pbp_section(VirtualPBP *vpbp, u32 remaining, int idx, void *data)
{
    void *buf, *buf_64;
    int rest, pos_section, re, total_re, buf_size = 8 * SECTOR_SIZE;
    int pos;

    total_re = re = 0;
    pos = vpbp->file_pointer;

    if(remaining == 0) {
        goto out;
    }

    if(!pbp_entries[idx].enabled) {
        goto out;
    }

    if (pos < vpbp->header[2]) {
        return get_header_section(vpbp, remaining, data);
    }

    if (pos >= vpbp->header[2] && pos < vpbp->header[3]) {
        return get_sfo_section(vpbp, remaining, data);
    }

    if(!(pos >= vpbp->header[2+idx] && pos < vpbp->header[2+1+idx])) {
        goto out;
    }

    buf = oe_malloc(buf_size + 64);

    if(buf == NULL) {
        printk("%s: buf(2) cannot allocate\n", __func__);

        return -5;
    }

    pos_section = pos - vpbp->header[2+idx];
    rest = MIN(remaining, vpbp->sects[idx].size - pos_section);
    buf_64 = PTR_ALIGN_64(buf);

    while (rest > 0) {
        int ret;

        re = MIN(rest, buf_size);
        ret = isoRead(buf_64, vpbp->sects[idx].lba, pos_section, re);

        if (ret < 0) {
            printk("%s: isoRead -> 0x%08X\n", __func__, ret);

            return -38;
        }

        memcpy(data, buf_64, re);
        rest -= re;
        pos_section += re;
        data += re;
        remaining -= re;
        total_re += re;
        pos += re;
    }

    oe_free(buf);

out:
    return total_re;
}