473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

disable reflection thru .NET reflector

Hi, anyone know how to disable reflection on sensitive code?

Here is specifically what I'm trying to do. I have one method in a class
within an assembly I'm trying to prevent using reflection to see the code.
The code contains a hardcoded key word that I do not want to be seen in any
way.

I've tried using ReflectionPermissionAttribute but don't know if this will
do what I want.

Any advice/answer greatly appreciated.

Thanks
Jun 8 '07 #1
12 12363
On Jun 8, 5:09 pm, m_gell <m_g...@discussions.microsoft.comwrote:
Hi, anyone know how to disable reflection on sensitive code?

Here is specifically what I'm trying to do. I have one method in a class
within an assembly I'm trying to prevent using reflection to see the code.
The code contains a hardcoded key word that I do not want to be seen in any
way.

I've tried using ReflectionPermissionAttribute but don't know if this will
do what I want.
Well, there are two things here:
1) Reflection in code
2) Decompilation in tools like Reflector

You can't really prevent either of them. Obfuscation will make it
harder to find stuff, but that's about it.

If you've got any hard coded sensitive data in your application,
that's a security flaw, basically.

See http://pobox.com/~skeet/csharp/obfuscation.html for more info.

Jon

Jun 8 '07 #2
Even if your assembly is obfuscated, anyone who is so inclined can run ILDASM
on it and get all the CIL sourcecode and find your "thing" with no difficulty.
If you need to keep a secret key, keep it out of the code.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"m_gell" wrote:
Hi, anyone know how to disable reflection on sensitive code?

Here is specifically what I'm trying to do. I have one method in a class
within an assembly I'm trying to prevent using reflection to see the code.
The code contains a hardcoded key word that I do not want to be seen in any
way.

I've tried using ReflectionPermissionAttribute but don't know if this will
do what I want.

Any advice/answer greatly appreciated.

Thanks
Jun 8 '07 #3
Where do you recommend keeping the secret key?

"Peter Bromberg [C# MVP]" wrote:
Even if your assembly is obfuscated, anyone who is so inclined can run ILDASM
on it and get all the CIL sourcecode and find your "thing" with no difficulty.
If you need to keep a secret key, keep it out of the code.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"m_gell" wrote:
Hi, anyone know how to disable reflection on sensitive code?

Here is specifically what I'm trying to do. I have one method in a class
within an assembly I'm trying to prevent using reflection to see the code.
The code contains a hardcoded key word that I do not want to be seen in any
way.

I've tried using ReflectionPermissionAttribute but don't know if this will
do what I want.

Any advice/answer greatly appreciated.

Thanks
Jun 8 '07 #4
When using CE of dotfuscator when I reference the obfuscated dll I can not
build my project as it does not recognize the former classes in the
namespace. Anyone know what I'm missing?

"Jon Skeet [C# MVP]" wrote:
On Jun 8, 5:09 pm, m_gell <m_g...@discussions.microsoft.comwrote:
Hi, anyone know how to disable reflection on sensitive code?

Here is specifically what I'm trying to do. I have one method in a class
within an assembly I'm trying to prevent using reflection to see the code.
The code contains a hardcoded key word that I do not want to be seen in any
way.

I've tried using ReflectionPermissionAttribute but don't know if this will
do what I want.

Well, there are two things here:
1) Reflection in code
2) Decompilation in tools like Reflector

You can't really prevent either of them. Obfuscation will make it
harder to find stuff, but that's about it.

If you've got any hard coded sensitive data in your application,
that's a security flaw, basically.

See http://pobox.com/~skeet/csharp/obfuscation.html for more info.

Jon

Jun 8 '07 #5
m_gell <mg***@discussions.microsoft.comwrote:
When using CE of dotfuscator when I reference the obfuscated dll I can not
build my project as it does not recognize the former classes in the
namespace. Anyone know what I'm missing?
Have you got it set to obfuscate public classes? Or are you referencing
internal classes with InternalsVisibleTo?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 8 '07 #6
I have the disable renaming property set to No which then I cannot reference
the classes in the namespace. When set to yes I can. I'm not referencing
any classes w/ InternalsVisibleTo and I'm not sure if I have it set to
obfuscate public classes. ??? Thoughts

"Jon Skeet [C# MVP]" wrote:
m_gell <mg***@discussions.microsoft.comwrote:
When using CE of dotfuscator when I reference the obfuscated dll I can not
build my project as it does not recognize the former classes in the
namespace. Anyone know what I'm missing?

Have you got it set to obfuscate public classes? Or are you referencing
internal classes with InternalsVisibleTo?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 8 '07 #7
m_gell <mg***@discussions.microsoft.comwrote:
I have the disable renaming property set to No which then I cannot reference
the classes in the namespace. When set to yes I can. I'm not referencing
any classes w/ InternalsVisibleTo and I'm not sure if I have it set to
obfuscate public classes. ??? Thoughts
Well, there are a few double negatives in there so I'm not sure what
you're doing, but if you've got something that works, why not just use
that?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 8 '07 #8
It does not fulfill what I want.

I can reference classes in the obfuscated dll with disable renaming=Yes
(which means enable renaming=no)but then the method names are not obfuscated
and the hardcoded key is visible in the constructor method when viewed thru
reflector.

As disable renaming = no (which means enable renaming=yes), then finding the
keyword is near impossible...doesn't show up w/ reflector, but then I cannot
reference any classes from the obfuscated dll in another assembly which is
what I need.

Bottomline, if I enable renaming to obfuscate the dll w/ the keyword, I
cannot use the dll. So do you know how to obfuscate w/ renaming yet still
reference the dll, or certain classes within the dll.

"Jon Skeet [C# MVP]" wrote:
m_gell <mg***@discussions.microsoft.comwrote:
I have the disable renaming property set to No which then I cannot reference
the classes in the namespace. When set to yes I can. I'm not referencing
any classes w/ InternalsVisibleTo and I'm not sure if I have it set to
obfuscate public classes. ??? Thoughts

Well, there are a few double negatives in there so I'm not sure what
you're doing, but if you've got something that works, why not just use
that?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 8 '07 #9
m_gell <mg***@discussions.microsoft.comwrote:
It does not fulfill what I want.

I can reference classes in the obfuscated dll with disable renaming=Yes
(which means enable renaming=no)but then the method names are not obfuscated
and the hardcoded key is visible in the constructor method when viewed thru
reflector.

As disable renaming = no (which means enable renaming=yes), then finding the
keyword is near impossible...doesn't show up w/ reflector, but then I cannot
reference any classes from the obfuscated dll in another assembly which is
what I need.

Bottomline, if I enable renaming to obfuscate the dll w/ the keyword, I
cannot use the dll. So do you know how to obfuscate w/ renaming yet still
reference the dll, or certain classes within the dll.
The bottom line is going to be that however you rename methods and
types, that hardcoded string is still going to be in there. The
solution is not to have the hard coded string in there in the first
place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 8 '07 #10
I did find the string in the obfuscated dll.

// Methods
public m(IProcessDto A_0) : this(A_0, new DestinationHistoryPersister(),
new DestinationDeterminerRepository(), new l())
{
if (Assembly.GetCallingAssembly().FullName != "mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
{
throw new Exception("Must instantiate on server!");
}
}

The obfuscated dll would still be sufficient for my purposes as security is
not of paramount concern. I would however like to know how to reference an
obfuscated dll w/ rename enabled or a different way to do this. Anyone have
any ideas? Any one ever referenced an obfuscated dll within VS and gotten it
to work? If so how. I notice if you obfuscate a specific exe that you can
still execute the exe fine. But you can not obfuscate a dll that the exe
uses or it will error. Again, you also cannot reference a obfuscated dll
from Visual Studio and see the obfuscated dll's types. Anyone know a
workaround?

"Jon Skeet [C# MVP]" wrote:
m_gell <mg***@discussions.microsoft.comwrote:
It does not fulfill what I want.

I can reference classes in the obfuscated dll with disable renaming=Yes
(which means enable renaming=no)but then the method names are not obfuscated
and the hardcoded key is visible in the constructor method when viewed thru
reflector.

As disable renaming = no (which means enable renaming=yes), then finding the
keyword is near impossible...doesn't show up w/ reflector, but then I cannot
reference any classes from the obfuscated dll in another assembly which is
what I need.

Bottomline, if I enable renaming to obfuscate the dll w/ the keyword, I
cannot use the dll. So do you know how to obfuscate w/ renaming yet still
reference the dll, or certain classes within the dll.

The bottom line is going to be that however you rename methods and
types, that hardcoded string is still going to be in there. The
solution is not to have the hard coded string in there in the first
place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 8 '07 #11
m_gell wrote:
Here is specifically what I'm trying to do. I have one method in a class
within an assembly I'm trying to prevent using reflection to see the code.
The code contains a hardcoded key word that I do not want to be seen in any
way.

I've tried using ReflectionPermissionAttribute but don't know if this will
do what I want.
Obfuscating will not work for this.

http://www.remotesoft.com/salamander/protector.html

claims to be more efficient.

But I would see if there were different approaches that could
remove the requirement for protecting against decompiling.

Arne
Jun 9 '07 #12
It depends on what the business logic is, you really haven't provided
sufficient information other than that you want to store some "secret" key in
your assembly.
There are all kinds of encryption methods, you have symmetric and
asymmetric. Once we have a better idea of what the business logic scenario
and the programmatic goal are, you can get some excellent recommendations.

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"m_gell" wrote:
Where do you recommend keeping the secret key?

"Peter Bromberg [C# MVP]" wrote:
Even if your assembly is obfuscated, anyone who is so inclined can run ILDASM
on it and get all the CIL sourcecode and find your "thing" with no difficulty.
If you need to keep a secret key, keep it out of the code.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"m_gell" wrote:
Hi, anyone know how to disable reflection on sensitive code?
>
Here is specifically what I'm trying to do. I have one method in a class
within an assembly I'm trying to prevent using reflection to see the code.
The code contains a hardcoded key word that I do not want to be seen in any
way.
>
I've tried using ReflectionPermissionAttribute but don't know if this will
do what I want.
>
Any advice/answer greatly appreciated.
>
Thanks
Jun 9 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Laser Lu | last post by:
HI, all, I just want to invoke an internal method named 'ResolveClientUrl', which is defined in class System.Web.UI.Control, using an instance object of a type that derives from Control. Let's...
3
by: Jozsef Bekes | last post by:
Hi All, I am trying to use reflection for getting all the classes from the dlls of a software written by my company. I am using this line: Assembly.LoadFile(s).GetTypes() Gettypes fails, I...
7
by: John | last post by:
I have a class the reads in a file and sets the values of the file into its properties. This class is used to populate the data onto a form. This form has controls created at runtime based on...
7
by: Mark Miller | last post by:
I am using Reflection.Emit to dynamically build a class. A method of the class to be built requires a Parameter of type "Type". But I don't know how to use Emit to pass a call of "typeof()" to the...
2
by: Test1000 | last post by:
Hello, I want to know how I can access the IL code using System.Reflection. I don't want to use any tools like reflector etc because I want to programmatically access the IL code. Thanks,
2
by: forvino | last post by:
Hi Geeks, Ihave a doubt in dotNet reflection. I m developing a tool which will returns set of public(access specifier) methods of the selected assembly. this works completely fine,...
1
by: nate | last post by:
hi :) i am having a strange problem. i have a plug-in system that i use to add support for various CAD file formats. i have a Maya plug-in that i have been running successfully for quite some...
9
by: Michael Sander | last post by:
Hello ng, anyone knowns how to add a reference to an assembly to System.Reflection.AssemblyBuilder? In System.Web.Compilation.AssemblyBuilder is a function like AddAssemblyReference, but not in...
6
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am slightly familiar with reflection but have never done the following I know how to find a class and call but I haven't done the following The Method return a List of Another Class And...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.