BitMono icon indicating copy to clipboard operation
BitMono copied to clipboard

Using BitMono + publishing application using AOT

Open coyotezin opened this issue 10 months ago • 8 comments

Hello!

My application uses net8 and is currently published with AOT, i would like to somehow implement BitMono obfuscation in the process of publishing the app. What im currently attempting is running it with just a few protection options enabled or one at a time for testing and i did managed to get it to compile and publish but the application end up not running anymore, doesnt matter what protection option i try, any of them end up in not being able to run the application after its published, if i enable the protections and just compile it works fine, but after the AOT publish it seems to be breaking the app.

Is there anything i could try to achieve this?

Thanks

(.csproj)

 <Target Name="ObfuscateBeforeAOT" BeforeTargets="IlcCompile" Condition="'$(PublishAot)' == 'true'">
	<Exec Command="BitMono.CLI -f $(IntermediateOutputPath)$(AssemblyName).dll -l $(OutputPath) -o $(IntermediateOutputPath)obfuscated" />
	<Move SourceFiles="$(IntermediateOutputPath)obfuscated\$(AssemblyName).dll" DestinationFiles="$(IntermediateOutputPath)$(AssemblyName).dll" />
</Target>

coyotezin avatar Mar 07 '25 23:03 coyotezin

Hi.

That's a very interesting topic, which I think would be nice to describe in docs if we find a way how to do that.

I don't know how to do this, however @GazziFX if I remember correctly, was trying to do obfuscation before AOT, if I'm right, did that worked for you?

Need to look into how the AOT works, maybe there's no way to edit the file at all, and it will be compiled directly to AOT, no IL step?! I also tried to do obfuscation before AOT, just like you, but without success.

If I'll have any info, I'll let you know.

sunnamed434 avatar Mar 08 '25 07:03 sunnamed434

I don't know how to do this, however @GazziFX if I remember correctly, was trying to do obfuscation before AOT, if I'm right, did that worked for you?

I did not tried that yet

GazziFX avatar Mar 08 '25 09:03 GazziFX

Need to look into how the AOT works, maybe there's no way to edit the file at all, and it will be compiled directly to AOT, no IL step?! I also tried to do obfuscation before AOT, just like you, but without success.

It is possible to edit the file before AOT, adding this to the .csproj makes it run the obfuscation before it compiles into AOT (considering you already have PublishAot enabled)

 <Target Name="ObfuscateBeforeAOT" BeforeTargets="IlcCompile" Condition="'$(PublishAot)' == 'true'">
	<Exec Command="BitMono.CLI -f $(IntermediateOutputPath)$(AssemblyName).dll -l $(OutputPath) -o $(IntermediateOutputPath)obfuscated" />
	<Move SourceFiles="$(IntermediateOutputPath)obfuscated\$(AssemblyName).dll" DestinationFiles="$(IntermediateOutputPath)$(AssemblyName).dll" />
</Target>

I was just doing some doublechecking and i did manage to obfuscate with BitMethodDotnet before AOT and the application still runs. The protection im more interested in using would be the FullRenamer but its making the application not run anymore, im trying to debug it and figure out where its stopping and so far it seems like its having issues to instantiate something from a dependency but cant 100% confirm yet.

coyotezin avatar Mar 08 '25 10:03 coyotezin

Need to look into how the AOT works, maybe there's no way to edit the file at all, and it will be compiled directly to AOT, no IL step?! I also tried to do obfuscation before AOT, just like you, but without success.

It is possible to edit the file before AOT, adding this to the .csproj makes it run the obfuscation before it compiles into AOT (considering you already have PublishAot enabled)

 <Target Name="ObfuscateBeforeAOT" BeforeTargets="IlcCompile" Condition="'$(PublishAot)' == 'true'">
	<Exec Command="BitMono.CLI -f $(IntermediateOutputPath)$(AssemblyName).dll -l $(OutputPath) -o $(IntermediateOutputPath)obfuscated" />
	<Move SourceFiles="$(IntermediateOutputPath)obfuscated\$(AssemblyName).dll" DestinationFiles="$(IntermediateOutputPath)$(AssemblyName).dll" />
</Target>

I was just doing some doublechecking and i did manage to obfuscate with BitMethodDotnet before AOT and the application still runs. The protection im more interested in using would be the FullRenamer but its making the application not run anymore, im trying to debug it and figure out where its stopping and so far it seems like its having issues to instantiate something from a dependency but cant 100% confirm yet.

Oh I see, makes sense now. Probably FullRenamer breaks something, for now disable it, and if possible, try to find out why and what breaks it. I'll also double check what's wrong in the protection code.

sunnamed434 avatar Mar 08 '25 10:03 sunnamed434

Hi. Looks like @GazziFX found the problem (he sent me that in DM, thanks a lot to him), it's about we don't rename Methods correctly, we also need to handle MethodRef's too, not only MethodDef's, maybe integrate BAML from ConfuserEx, will see, probably I'll take care of it on weekend or later.

sunnamed434 avatar Mar 10 '25 17:03 sunnamed434

Hi. Looks like @GazziFX found the problem (he sent me that in DM, thanks a lot to him), it's about we don't rename Methods correctly, we also need to handle MethodRef's too, not only MethodDef's, maybe integrate BAML from ConfuserEx, will see, probably I'll take care of it on weekend or later.

Thats great news! Excited about it, really wanted to use BitMono and being able to use FullRenamer will be really important to me and would probably be helpful for a lot more people aswell, if u have any other news please let me know!

coyotezin avatar Mar 10 '25 20:03 coyotezin

Hey, im sorry to bump this but is there any news about this issue? Looking forward for a fix to make this possible, couldnt find an usable alternative anywhere as good as BitMono yet

Thanks

coyotezin avatar Mar 27 '25 19:03 coyotezin

Hey, im sorry to bump this but is there any news about this issue? Looking forward for a fix to make this possible, couldnt find an usable alternative anywhere as good as BitMono yet

Thanks

Hey, I haven't had a chance to look into it yet, I'll try to fix this as soon as possible. Also I'm going to be AFK 3-16 Aprill, will see when I'll have time for that.

If possible, don't use FullRenamer for now.

sunnamed434 avatar Mar 29 '25 09:03 sunnamed434