yck1509 / ConfuserEx

An open-source, free protector for .NET applications
http://yck1509.github.io/ConfuserEx/
Other
3.56k stars 1.61k forks source link

Ability to obfuscate and replace input file #76

Closed icnocop closed 9 years ago

icnocop commented 10 years ago

Hi.

Thank you for ConfuserEx v0.2.3.

I would like to request the ability to obfuscate an assembly whose output directory is the same as the input directory, causing the original file to be overwritten.

For example, the following configuration will fail with the following error because the input and output files are the same:

<?xml version="1.0" encoding="utf-8"?>
<project baseDir="." outputDir="..\..\..\bin\x86\Release" xmlns="http://confuser.codeplex.com">
    <rule preset="none" pattern="true">
        <protection id="anti debug" />
        <protection id="anti dump" />
        <protection id="anti ildasm" />
        <protection id="anti tamper" />
        <protection id="constants" />
        <protection id="ctrl flow" />
        <protection id="invalid metadata" />
        <protection id="ref proxy" />
        <protection id="rename" />
        <protection id="resources" />
    </rule>
    <module path="..\..\..\MyProject\bin\x86\Release\MyAssembly.exe" snKey="..\..\..\StrongName.snk" />
</project>
[ERROR] An IO error occurred, check if all input/output locations are read/writable.
Exception: System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at System.IO.File.WriteAllBytes(String path, Byte[] bytes)
    at Confuser.Core.ConfuserEngine.SaveModules(ConfuserContext context) in e:\Source\Public\Confuser2\Confuser.Core\ConfuserEngine.cs:line 388
    at Confuser.Core.ProtectionPipeline.ExecuteStage(PipelineStage stage, Action`1 func, Func`1 targets, ConfuserContext context) in e:\Source\Public\Confuser2\Confuser.Core\ProtectionPipeline.cs:line 134
    at Confuser.Core.ConfuserEngine.RunPipeline(ProtectionPipeline pipeline, ConfuserContext context) in e:\Source\Public\Confuser2\Confuser.Core\ConfuserEngine.cs:line 234
    at Confuser.Core.ConfuserEngine.RunInternal(ConfuserParameters parameters, CancellationToken token) in e:\Source\Public\Confuser2\Confuser.Core\ConfuserEngine.cs:line 159

Thank you.

CptObviousDuh commented 10 years ago

+1 Just wanted to let you know that I also tried to do that when I first used ConfuserEx, seems like a good feature to me. Without knowing the source code: maybe it's fixable if ConfuserEx copies the binary file to a temporary directory first?