从 .NET 程序集 (dll) 获取所有静态(内部)字符串
我希望获得 .NET 程序集中使用的所有字符串的列表,包括局部变量设置为的“静态”值、传递给方法的参数、设置为的字段等。
我记得我读过一篇很长的文章。不久前,.NET 程序集包含它使用的所有字符串的表(或者它们可以被“保留”)——或者我只是在做梦?
使用 .NET Reflector 是一个很好的理想选择(感谢 thijs),我也会看看如果没有人提出一个已经编写好的工具,那么它的API。
(这样我就可以编写一个工具来检查我们没有错过任何应该翻译的字符串。我可以处理 C# 源代码,但是我将不得不处理 分成多行的字符串等)
我只是想,我希望排除传递到 CodeFlowException() 等的字符串,所以这已经变得更加复杂。
PS:如果您能想到一组更好的标签,请重新标记这个问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 SysInternals Strings 工具查看可执行文件和目标文件中的字符串。
You can use SysInternals Strings tool to view the strings in executables and object files.
对于那些想要从 .NET 程序集(.exe 或 .dll)中提取所有用户字符串的人,我编写了 简单实用程序可以做到这一点(文件
ExtractExeNetStrings2.zip
)。该实用程序是用 C# 编写的。
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#.
您应该能够使用反射来做到这一点,看看这个:
http://msdn.microsoft.com/en-us/library/system.reflection.fieldinfo.isliteral.aspx
和
http://msdn.microsoft.com/en-us/library/system.reflection.fieldinfo.aspx
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
简单的 C# 实用程序,通过检查二进制文件的位从 .NET 程序集(.exe 或 .dll)中提取所有用户字符串。
现在可以找到 vladob 答案的源代码 在 github 上。 原始答案的链接已损坏。 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.
最后我写了一个非常简单的 C# 解析器,它在源代码中找到了字符串。 这解决了我遇到的问题,并让我向字符串添加“注释”以帮助翻译人员。
这些注释只是以“神奇格式”从 C# 注释中读取的
(抱歉,解析器不够好,无法允许其他人使用它,它只适用于我的 C# 代码库)
In the end I wrote a very simple C# parser that found the strings in the source code. This solved the problem I had and let me add “comments” to the strings to help the translators.
The comments were just read from C# comments in a “magic format”
(Sorry the parser is not good enough to allow anyone else to use it, it only just about works on my C# code base)