Red Gate forums :: View topic - Code to determine if running obfuscated?
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 6
SmartAssembly 6 forum

Code to determine if running obfuscated?

Search in SmartAssembly 6 forum
Post new topic   Reply to topic
Jump to:  
Author Message
eric-914



Joined: 30 Nov 2012
Posts: 28

PostPosted: Mon Dec 10, 2012 8:44 pm    Post subject: Code to determine if running obfuscated? Reply with quote

Hello, odd question here...

Is there a way, w/in my code itself, to determine if it has been processed by SmartAssembly?

Basically, I want to prevent accidental deployment w/out it being obfuscated first, so I'd like to add some code to indicate if it hasn't been 'processed' yet.

If not directly w/in S/A, I'm thinking since S/A can embed libraries into the .exe itself, maybe determine if a particular library has been embedded or not. If so, then yes, it's been processed. If no, then it hasn't.

Anyway, wonder if anyone has any ideas about this.

Thanks in advance...
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6677

PostPosted: Tue Dec 11, 2012 12:18 pm    Post subject: Reply with quote

You can use Reflection to find the "PoweredBy" attribute of the assembly and that will give you the version of SmartAssembly it had been processed with. Please see:

http://sdk.red-gate.com/index.php/Check_SA_Version

As for getting a list of embedded assemblies - I don't know how you'd go about that as it is unsupported and for the sake of protecting the IP I'm not sure if it should be externally documented.
Back to top
View user's profile Send private message
eric-914



Joined: 30 Nov 2012
Posts: 28

PostPosted: Wed Dec 12, 2012 5:26 pm    Post subject: Reply with quote

Unfortunately, your link indicates it requires a Mono dll library attached to work.

I found I could do it by the following:

Using the Assembly object from the .exe, get referenced assemblies via:
Code:
assembly.GetReferencedAssemblies()


Then w/in one of my library .dll's that I know will be merged via S/A, I get it's assembly name:
Code:
Assembly.GetExecutingAssembly().GetName().FullName


I have noticed that this name will show up in the reference list when the app has NOT been obfuscated. But this name will disappear AFTER obfuscation (because it's no longer an external library, it's been merged w/ the .exe).

I use this fact to differentiate between the two states.
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6677

PostPosted: Wed Dec 12, 2012 5:59 pm    Post subject: Reply with quote

Yeah, .NET Reflection is missing the gubbins to read assembly-level attributes. Mono Cecil has a metadata reader that can do this. Believe me, I tried with plain .NET Reflection and it doesn't get the attributes.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group