LCF-AT Posted April 30, 2017 Posted April 30, 2017 Hi guys, I haveĀ a question again.I wanna create a new file via CreateFile + WriteFile which I then wanna execute via CreateProcess API.The problem I have that I dont get it work and always get a Sharing Violation Error on CreateProcess API.I would like to use the flag FILE_FLAG_DELETE_ON_CLOSE so that file gets deleted after handle is closed so that I dont need to handle it by myself anymore.But as I said,CreateProcess API does fail if I dont close the handle from CreateFile before but if I close the handle then the file gets deleted of course.So does anyone know whether there is way to handle it right with using FILE_FLAG_DELETE_ON_CLOSE + CreateProcess after?CreateFile / WriteFile & CreateProcess. Thank you
evlncrn8 Posted April 30, 2017 Posted April 30, 2017 (edited) what sharing rights have you given it ? FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ? Edited April 30, 2017 by evlncrn8
LCF-AT Posted April 30, 2017 Author Posted April 30, 2017 Hi, yes I tried the flags too invoke CreateFile,chr$("1232323.exe"),GENERIC_READ + GENERIC_WRITE,FILE_SHARE_READ + FILE_SHARE_WRITE + FILE_SHARE_DELETE,NULL,CREATE_ALWAYS,FILE_FLAG_DELETE_ON_CLOSE ,NULL invoke WriteFile .... mov startupinfo1.cb,sizeof STARTUPINFO invoke GetStartupInfo,addr startupinfo1 invoke CreateProcess,chr$("1232323.exe"),0,0,0,NULL,0,0,0,addr startupinfo1,addr pinfo but dont get it work.So it seems I have to close that handle before using CreateProcess.Hhhm.Do you see whats wrong here?Or canĀ you post a example of the right using API flags in that case which are also working for you. greetz
evlncrn8 Posted May 1, 2017 Posted May 1, 2017 have createprocess inherit the handle ? (in the security attributes part).. then launch and exit, then once the launchee process exits it should do the job, might work
Teddy Rogers Posted May 1, 2017 Posted May 1, 2017 Not sure exactly what you are trying to accomplish, are you trying to patch it first? Perhaps instead use... hFile = CreateFile_(Filename.s, #GENERIC_READ | #GENERIC_WRITE, 0, #Null, #OPEN_EXISTING, 0, #Null) If hFile <> #INVALID_HANDLE_VALUE hFileMappingObject = CreateFileMapping_(hFile, #Null, #PAGE_READWRITE, 0, 0, #Null) If hFileMappingObject *lpBaseAddress = MapViewOfFile_(hFileMappingObject, #FILE_MAP_WRITE, 0, 0, 0) If *lpBaseAddress ; Do stuff... UnmapViewOfFile_(*lpBaseAddress) EndIf CloseHandle_(hFileMappingObject) EndIf CloseHandle_(hFile) EndIf Ted.
LCF-AT Posted May 1, 2017 Author Posted May 1, 2017 Hi guys, so I did also try to enable inherit etc but also didnt work.Just need any example how it would work from createfile (FILE_FLAG_DELETE_ON_CLOSE) - createprocess. So I just try to create a new file where I writes bytes into (small new exe) and then I just wanna start it and if its not used anymore then system should delete it.Thats all so far.Of course I could do it without using FILE_FLAG_DELETE_ON_CLOSE and delete file by myself but if there is already a option / flag like this then I would also try to use / test it out you know.Just wanted to get it work with using that flag. greetz
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now