-1

The function to determine if an exe file has been compressed (written by RRUZ) is excellent except I found a problem with the code. If the function IsUPXCompressed is called then you try to run upx, UPX can not save the file it modifies. There is something not sharing rights correctly in the function. I have tested this for several hours. If I do not call the method then UPX can write the files with no problem. If you call it then try to run UPX it will not save the file. UPX reports an IOException Permission denied error when trying to write the file.

Can anyone spot something wrong in the code that would cause this problem?

I posted this again because after 24 hours no one seem to see my posts about it at its original locastion: Method to determine if an exe file has been compressed with UPX

Thank-you

Community
  • 1
  • 1
Bill
  • 2,993
  • 5
  • 37
  • 71
  • 1
    I really don't see the point to create a new question on this subject... you can post this as a comment on the original RRUIZ answer. – jachguate Mar 01 '11 at 22:40
  • Bill, i apologize, the problem was caused because the handles was not closed, check the code now. – RRUZ Mar 01 '11 at 22:59
  • @jachguate, this is actually OK either way. Bill posted his reason for a separate question (in this question), and it could be considered a separate question ("Why can't I open the file after testing with IsUPXCompressed function?"). – Ken White Mar 01 '11 at 23:12

1 Answers1

1

@RRUZ's code doesn't close either the file mapping or the file handle used to create it.

After the end of the for.. loop in the code, add the following two three lines:

UnmapViewOfFile(pBaseAddress);
CloseHandle(hFileMap);
CloseHandle(hFile);

No need to test them first, as the prior code exited if either of the function calls to open the handles doesn't succeed. (There should probably be try..finally protection of the two opening calls, but I'll leave that to RRUZ to correct in his original post.)

Community
  • 1
  • 1
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • @RRUZ: Updated my code here as well, to add the UnmapViewOfFile I missed. (See my comments on your modifications on the other post.) – Ken White Mar 01 '11 at 23:06