Click here to Skip to main content
11,642,658 members (68,064 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# testing
Hi,

I am not able to access private variable value using PrivateObject if my library is obfuscated. i know the variable name and other information are changed when we do obfuscation but is there any workaround for that ?

if i am accessing private variable of the serialized class then it is working fine but non-serialized class's private variables are not accessible using PrivateObject.

can anyone suggest any other solution to get private variable value ?

Thanks
-Amit.
Posted 30-May-12 23:32pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Does your obfuscator generate a log file which tells you what each method/field was translated to? If so, you might be able to use that to reverse the mappings in your test harness and look up the post-obfuscation value.

Note that if you're using reflection looking for known class/method/property names in your actual code (as opposed to the tests), you will need to exclude the targets of that reflection from obfuscation.
  Permalink  
Comments
amitgajjar at 31-May-12 6:51am
   
i only have obfuscated library,even i don't know which tool is used to obfuscate :)
BobJanova at 31-May-12 9:36am
   
Then you're pretty much screwed, the whole purpose of obfuscation is to remove meaning from the compiled code (IL in this case) so if you're looking for particular meaningful names you will not succeed.
amitgajjar at 1-Jun-12 0:31am
   
actually i have created lots of test cases for checking private variable. but till date we are checking on non-obfuscated library. now client have requirement to check our all test cases on obfuscated library. so stuck there... :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 254
1 Sergey Alexandrovich Kryukov 204
2 OriginalGriff 160
3 Afzaal Ahmad Zeeshan 129
4 Mika Wendelius 85
0 Mika Wendelius 485
1 DamithSL 457
2 OriginalGriff 365
3 Afzaal Ahmad Zeeshan 258
4 Sergey Alexandrovich Kryukov 254


Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 31 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100