Created
March 26, 2016 10:02
-
-
Save psxdev/63c8c06c8337aea95fad to your computer and use it in GitHub Desktop.
problem with close after payload execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ps4LinkCmdExecShowDir(ps4link_pkt_exec_cmd *pkg) | |
{ | |
debugNetPrintf(DEBUG,"[PS4LINK] Received command execshowdir\n"); | |
char *buffer; | |
struct dirent *dent; | |
struct stat stats; | |
int dfd; | |
int i; | |
if(UID==0 && GID==0 && pkg->argv!=NULL) | |
{ | |
dfd = open(pkg->argv, O_RDONLY, 0); | |
if(dfd < 0) { | |
debugNetPrintf(DEBUG, "Invalid directory.\n"); | |
return; | |
} | |
int err=fstat(dfd, &stats); | |
if(err<0) | |
{ | |
debugNetPrintf(DEBUG, "fstat error return 0x%08X \n",err); | |
return; | |
} | |
buffer=mmap(NULL, stats.st_blksize+sizeof(struct dirent), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); | |
if (buffer) | |
{ | |
// Make sure we will have a null terminated entry at the end.Thanks people leaving CryEngine code for orbis on github :) | |
for(i=0;i<stats.st_blksize+sizeof(struct dirent);i++) | |
{ | |
buffer[i]=0; | |
} | |
err=getdents(dfd, buffer, stats.st_blksize); | |
int nOffset = err; | |
while (err > 0 && err < stats.st_blksize) | |
{ | |
err = getdents(dfd, buffer + nOffset, stats.st_blksize-nOffset); | |
nOffset += err; | |
} | |
if (err>0) | |
err=0; | |
dent = (struct dirent *)buffer; | |
while(dent->d_fileno ) { | |
debugNetPrintf(DEBUG, "[%s]: %s\n", entryName(dent->d_type), dent->d_name); | |
dent = (struct dirent *)((void *)dent + dent->d_reclen); | |
} | |
} | |
munmap(buffer,stats.st_blksize+sizeof(struct dirent)); | |
debugNetPrintf(DEBUG,"[PS4LINK] closing dfd\n"); | |
/*err=close(dfd); //close is crashing i don't know why, i suppose that after knote_fdclose something is wrong and don't let close | |
if(err<0) | |
{ | |
debugNetPrintf(DEBUG, "fstat error return 0x%08X \n",err); | |
return; | |
}*/ | |
} | |
else | |
{ | |
if(pkg->argv!=NULL) | |
{ | |
debugNetPrintf(DEBUG,"Sorry you are not root , you must be root to run this...\n"); | |
} | |
else | |
{ | |
debugNetPrintf(DEBUG,"Sorry you must provide a ps4 directory path...\n"); | |
} | |
} | |
debugNetPrintf(DEBUG,"[PS4LINK] end command execshowdir\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment