int param_sfo_app_ver(char * path, char *app_ver) { s32 fd; u64 bytes; u64 position = 0LL; unsigned char *mem = NULL; if(!sysLv2FsOpen(path, 0, &fd, S_IRWXU | S_IRWXG | S_IRWXO, NULL, 0)) { unsigned len, pos, str; sysLv2FsLSeek64(fd, 0, 2, &position); len = (u32) position; mem = (unsigned char *) malloc(len+16); if(!mem) {sysLv2FsClose(fd); return -2;} memset(mem, 0, len+16); sysLv2FsLSeek64(fd, 0, 0, &position); if(sysLv2FsRead(fd, mem, len, &bytes)!=0) bytes =0LL; len = (u32) bytes; sysLv2FsClose(fd); str= (mem[8]+(mem[9]<<8)); pos= (mem[0xc]+(mem[0xd]<<8)); int indx=0; while(str<len) { if(mem[str]==0) break; if(!strcmp((char *) &mem[str], "APP_VER")) { strncpy(app_ver, (char *) &mem[pos], 5); app_ver[5] = 0; break; } while(mem[str]) str++;str++; pos+=(mem[0x1c+indx]+(mem[0x1d+indx]<<8)); indx+=16; } if(mem) free(mem); return 0; } return -1; }
int CopyFile(const char *source, const char *dest){ s32 src = -1; s32 dst = -1; sysFSStat stats; char buffer[BLOCK_SIZE]; u64 i; s32 ret; ret = sysLv2FsOpen(source, SYS_O_RDONLY, &src, 0, NULL, 0); if (ret) goto out; ret = sysLv2FsOpen(dest, SYS_O_WRONLY | SYS_O_CREAT | SYS_O_TRUNC, &dst, 0, NULL, 0); if (ret) goto out; sysLv2FsChmod(dest, S_IFMT | 0777); sysLv2FsFStat(src, &stats); for (i = 0; i < stats.st_size;) { u64 pos, read, written; sysLv2FsLSeek64(src, i, 0, &pos); sysLv2FsLSeek64(dst, i, 0, &pos); ret = sysLv2FsRead(src, buffer, sizeof(buffer), &read); if (ret || !read) break; ret = sysLv2FsWrite(dst, buffer, read, &written); if (ret || !written) break; i += written; } out: if (src >= 0) sysLv2FsClose(src); if (dst >= 0) sysLv2FsClose(dst); return ret; }
u8* bdemu_payload(s32 fd, u64 offset, u64 size) { //Payload memory. u8* payload = (u8*) malloc(size); //Go to payload position. u64 pos; sysLv2FsLSeek64(fd, offset, SEEK_SET, &pos); //Read payload. u64 read; sysLv2FsRead(fd, payload, size, &read); //Close descriptor. sysLv2FsClose(fd); return payload; }
#include <sys/types.h> #include <sys/lv2errno.h> #include <sys/file.h> _off_t _DEFUN(__librt_lseek_r,(r,fd,pos,dir), struct _reent *r _AND int fd _AND _off_t pos _AND int dir) { s32 ret = 0; u64 position = 0; ret = sysLv2FsLSeek64(fd,pos,dir,&position); if(ret) return (_off_t)lv2errno_r(r,ret); return (_off_t)position; } _off64_t _DEFUN(__librt_lseek64_r,(r,fd,pos,dir), struct _reent *r _AND int fd _AND _off64_t pos _AND int dir) { s32 ret = 0; u64 position = 0;