Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting all static (interned) strings from a .NET assembly (dll)

I wish to get a list of all strings that are used in a .NET assembly including the “static” values that local variables are set to, parameters passed to methods, fields at set to, etc.

I recall from something I read a long time ago that a .NET assembly contains a tables of all strings it uses (or they can be "interned")– or am I just dreaming?

Using .NET Reflector is a good ideal (thanks thijs), I will also have a look at its API if no one comes up with an already written tool.

(This is so I can write a tool to check we have not missed any strings that should be translated. I could process the C# source code, however I will then have to cope with Strings that are split over many lines, etc.)

I have just thought, I wish to exclude strings passed into CodeFlowException(), etc., so this is already getting more complex.

PS: if you can think of a better set of tags, please retag this question.

like image 965
Ian Ringrose Avatar asked Jun 02 '09 11:06

Ian Ringrose


4 Answers

You can use SysInternals Strings tool to view the strings in executables and object files.

like image 112
Mitch Wheat Avatar answered Nov 09 '22 11:11

Mitch Wheat


You should be able to do this using reflection, take a look at this:

http://msdn.microsoft.com/en-us/library/system.reflection.fieldinfo.isliteral.aspx

and

http://msdn.microsoft.com/en-us/library/system.reflection.fieldinfo.aspx

like image 20
thijs Avatar answered Nov 09 '22 12:11

thijs


For those who want to extract all user strings from a .NET assembly (.exe or .dll) I wrote a simple utility which can do that (file ExtractExeNetStrings2.zip). The utility is written in C#.

like image 26
vladob Avatar answered Nov 09 '22 12:11

vladob


Simple C# utility that extracts all user strings from a .NET assembly (.exe or .dll) by examining bits of a binary file.

The source code from vladob's answer can now be found on github here. The link from the original answer has been broken. vladob gave consent to this repost. Actually I gave consent to me.

like image 2
vbelcik Avatar answered Nov 09 '22 12:11

vbelcik