1+ using dnlib . DotNet ;
2+ using Microsoft . Win32 ;
3+ using System . Collections ;
4+ using System . Windows ;
5+
6+ namespace DotNetFileInfo
7+ {
8+ /// <summary>
9+ /// Interaction logic for MainWindow.xaml
10+ /// </summary>
11+ public partial class MainWindow : Window
12+ {
13+ public MainWindow ( )
14+ {
15+ InitializeComponent ( ) ;
16+ }
17+
18+ private void btnFile_Click ( object sender , RoutedEventArgs e )
19+ {
20+ var dlg = new OpenFileDialog ( ) { Filter = "*.exe;*.dll|*.exe;*.dll" } ;
21+ if ( dlg . ShowDialog ( ) == true )
22+ {
23+ LoadFile ( dlg . FileName ) ;
24+ }
25+ }
26+
27+ private void Grid_DragOver ( object sender , DragEventArgs e )
28+ {
29+ e . Effects = DragDropEffects . Copy ;
30+ }
31+
32+ private void Grid_Drop ( object sender , DragEventArgs e )
33+ {
34+ string [ ] fileList = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop , false ) ;
35+ if ( fileList != null && fileList . Length > 0 )
36+ {
37+ LoadFile ( fileList [ 0 ] ) ;
38+ }
39+ }
40+
41+ private void LoadFile ( string file )
42+ {
43+ try
44+ {
45+ grdAssembly . ItemsSource = null ;
46+ grdModule . ItemsSource = null ;
47+ this . Title = "DotNetFileInfo - " + file ;
48+ ModuleContext modCtx = ModuleDef . CreateModuleContext ( ) ;
49+ using ( ModuleDefMD module = ModuleDefMD . Load ( file , modCtx ) )
50+ {
51+ grdAssembly . ItemsSource = GetPropertiesAsList ( module . Assembly ) ;
52+ grdModule . ItemsSource = GetPropertiesAsList ( module . Assembly . Modules [ 0 ] ) ;
53+ }
54+ }
55+ catch ( Exception ex )
56+ {
57+ MessageBox . Show ( ex . Message , "Error" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
58+ }
59+ }
60+
61+ private IEnumerable GetPropertiesAsList ( Object obj )
62+ {
63+ return obj . GetType ( ) . GetProperties ( ) . Select ( x => new PropInfo { Name = x . Name , Value = x . GetValue ( obj ) ? . ToString ( ) ?? "null" } ) ;
64+ }
65+
66+ public class PropInfo
67+ {
68+ public string Name { get ; set ; }
69+ public string Value { get ; set ; }
70+ }
71+ }
72+ }
0 commit comments