惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - smalldust

NTT大规模网络故障 关于园子里讨论的软件的追求的杂谈 Reflector保护方法初探 .Net 2.0 原汁原味读取注册表 为什么我不用IE7和FireFox 给.Net程序员的PInvoke Tips [2]: Are Strings Immutable? 除了Exception,你还能throw什么? 给.Net程序员的PInvoke Tips [1]: String is Sometimes an Integer CLR Team程序员出的难题,有兴趣的朋友不妨挑战一下 - smalldust - 博客园 Google Trends发布 也谈用反射实现Enum→String映射:一种重视性能的方法 针对个例的、社区性的维基系统设想(草稿) 数学的思考方式 VS 程序的思考方式 WinForm程序启动时不显示主窗体的实现方法 C#程序模拟鼠标操作 [Simulate Mouse Movement and Click Programmatically] 如何在C#中获取“当前目录” Windows Vista将推迟到2007年1月发布 .Net 2.0实例学习:WebBrowser页面与WinForm交互技巧 使用关键字作为自定义标识符
亲手焙制一个极其简单但却极其实用的Reflector插件
smalldust · 2006-08-30 · via 博客园 - smalldust

大家在使用Reflector浏览,分析各种.Net Assembly的时候,尤其是在分析EXE文件的时候,面对成百上千个Class不知所措时,我们总希望尽快抓住主线,知道这个程序是怎样一步步执行的。这个时候,我们通常要“从头抓起”——找到程序的EntryPoint,也即入口函数(通常为Main函数)。

且不用说那些经过混淆,把Main函数改了名字的,就算是没有经过混淆,要从数十个Namespace,成百上千个Class当中找到Main函数也不是一件容易的事情。我们多么希望找到Main函数是Reflector本身带有的一项功能啊!可惜的是,我找了好久没有找到(其实,的确是有这项功能的……就在Assembly上点右键出现的菜单中)。

但是我突然想到,有找这个功能的时间,不如自己来做一个插件——做这个插件,只需要3分钟即可,远比翻来翻去轻松得多。

说做就做,下面就是本插件的焙制方法。

首先,对于不熟悉Reflector的插件的朋友需要知道的是,Reflector的插件就是一个实现了Reflector.IPackage接口的Assembly。首先我们把Reflector.exe加入Reference,然后使用下面的语句:

using Reflector;
using Reflector.CodeModel;

即可使用其提供的各种功能了。然后,通过ICommandBarManager在"Tools"下添加一个菜单项"Go to EntryPoint",以及设置好快捷键(Ctrl + E),最后再为该菜单项添加对应的EventHandler即可。(注意,必须先选择一个Assembly之后才能跳转到其EntryPoint,选择了Assembly下面的类型、成员等等则会报错)

完整代码如下:

using System;
using System.Windows.Forms;using Reflector;
using Reflector.CodeModel;namespace EntryPointLookup
{
    
public class PluginPackage : IPackage
    {
        
private IWindowManager m_WindowsManager;
        
private ICommandBarManager m_CommandBarManager;
        
private IAssemblyBrowser m_assemblyBrowser;
        
private ICommandBarButton m_gotoEntryPointBtn;public void Load(IServiceProvider serviceProvider)
        {
            m_WindowsManager 
= (IWindowManager)serviceProvider.GetService(typeof(IWindowManager));
            m_CommandBarManager 
= (ICommandBarManager)serviceProvider.GetService(typeof(ICommandBarManager));
            m_assemblyBrowser 
= (IAssemblyBrowser)serviceProvider.GetService(typeof(IAssemblyBrowser));foreach (ICommandBarMenu item in m_CommandBarManager.CommandBars["MenuBar"].Items)
            {
                
if (item.Identifier == "Tools")
                {
                    m_gotoEntryPointBtn 
= item.Items.AddButton("Go to EntryPoint"new EventHandler(MenuEntryPoint_Click), Keys.Control | Keys.E);
                }
            }
        }
private void MenuEntryPoint_Click(object sender, EventArgs e)
        {
            
if (m_assemblyBrowser != null && m_assemblyBrowser.ActiveItem != null)
            {
                IAssembly assembly 
= m_assemblyBrowser.ActiveItem as IAssembly;
                
if (assembly != null)
                {
                    
if (assembly.EntryPoint != null)
                    {
                        m_assemblyBrowser.ActiveItem 
= assembly.EntryPoint;
                    }
                    
else
                    {
                        m_WindowsManager.ShowMessage(
"We cannot find an entrypoint inside the current assembly.");
                    }
                }
                
else
                {
                    m_WindowsManager.ShowMessage(
"Please click the top node of the assembly first.");
                }
            }
        }
public void Unload()
        {
            
if (m_gotoEntryPointBtn != null)
            {
                
foreach (ICommandBarMenu item in m_CommandBarManager.CommandBars["MenuBar"].Items)
                {
                    
if (item.Identifier == "Tools")
                    {
                        item.Items.Remove(m_gotoEntryPointBtn);
                    }
                }
            }
        }
    }
}