Skip to content

Commit

Permalink
simplify disassembling exports
Browse files Browse the repository at this point in the history
  • Loading branch information
zodiacon committed Feb 12, 2017
1 parent 425d7dc commit 8aa50d1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 57 deletions.
100 changes: 55 additions & 45 deletions PEExplorer/ViewModels/Tabs/ExportsTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,68 @@
using Zodiacon.WPF;

namespace PEExplorer.ViewModels.Tabs {
[Export, PartCreationPolicy(CreationPolicy.NonShared)]
class ExportsTabViewModel : TabViewModelBase {
[ImportingConstructor]
public ExportsTabViewModel(MainViewModel vm) : base(vm) {
}
[Export, PartCreationPolicy(CreationPolicy.NonShared)]
class ExportsTabViewModel : TabViewModelBase {
[ImportingConstructor]
public ExportsTabViewModel(MainViewModel mainViewModel) : base(mainViewModel) {
DisassembleCommand = new DelegateCommand(() => {
var symbol = SelectedItem;
var vm = DialogService.CreateDialog<DisassemblyViewModel, DisassemblyView>(symbol.Name);
var address = (int)symbol.Address;
MainViewModel.Accessor.ReadArray(MainViewModel.PEHeader.RvaToFileOffset(address), _bytes, 0, _bytes.Length);
vm.Disassemble(_bytes, address, MainViewModel.PEHeader.IsPE64);
vm.Show();
}, () => SelectedItem != null && string.IsNullOrEmpty(SelectedItem.ForwardName)).ObservesProperty(() => SelectedItem);
}

public override string Icon => "/icons/export1.ico";
public override string Icon => "/icons/export1.ico";

public override string Text => "Exports";
public override string Text => "Exports";

IEnumerable<ExportedSymbol> _exports;
IEnumerable<ExportedSymbol> _exports;

public unsafe IEnumerable<ExportedSymbol> Exports {
get {
if(_exports == null) {
_exports = MainViewModel.PEParser.GetExports();
}
return _exports;
}
}
public unsafe IEnumerable<ExportedSymbol> Exports {
get {
if(_exports == null) {
_exports = MainViewModel.PEParser.GetExports();
}
return _exports;
}
}

private string _searchText;
private string _searchText;

public string SearchText {
get { return _searchText; }
set {
if(SetProperty(ref _searchText, value)) {
var view = CollectionViewSource.GetDefaultView(Exports);
if(string.IsNullOrWhiteSpace(value))
view.Filter = null;
else {
var lower = value.ToLower();
view.Filter = o => {
var symbol = (ExportedSymbol)o;
return symbol.Name.ToLower().Contains(lower) || (symbol.ForwardName != null && symbol.ForwardName.ToLower().Contains(lower));
};
}
}
}
}
public string SearchText {
get { return _searchText; }
set {
if(SetProperty(ref _searchText, value)) {
var view = CollectionViewSource.GetDefaultView(Exports);
if(string.IsNullOrWhiteSpace(value))
view.Filter = null;
else {
var lower = value.ToLower();
view.Filter = o => {
var symbol = (ExportedSymbol)o;
return symbol.Name.ToLower().Contains(lower) || (symbol.ForwardName != null && symbol.ForwardName.ToLower().Contains(lower));
};
}
}
}
}

[Import]
IDialogService DialogService;
[Import]
IDialogService DialogService;

static byte[] _bytes = new byte[1 << 12];
static byte[] _bytes = new byte[1 << 12];

public ICommand DisassembleCommand => new DelegateCommand<ExportedSymbol>(symbol => {
var vm = DialogService.CreateDialog<DisassemblyViewModel, DisassemblyView>(symbol.Name);
var address = (int)symbol.Address;
MainViewModel.Accessor.ReadArray(MainViewModel.PEHeader.RvaToFileOffset(address), _bytes, 0, _bytes.Length);
vm.Disassemble(_bytes, address, MainViewModel.PEHeader.IsPE64);
vm.Show();
});
}
public ICommand DisassembleCommand { get; }

private ExportedSymbol _selectedItem;

public ExportedSymbol SelectedItem {
get { return _selectedItem; }
set { SetProperty(ref _selectedItem, value); }
}

}
}
33 changes: 21 additions & 12 deletions PEExplorer/Views/Tabs/ExportsTabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,30 @@
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox Text="{Binding SearchText, Mode=TwoWay, Delay=300, UpdateSourceTrigger=PropertyChanged}" Width="300" metro:TextBoxHelper.ClearTextButton="True"
<StackPanel Orientation="Horizontal">
<Button Command="{Binding DisassembleCommand}" CommandParameter="{Binding Source={StaticResource proxy}, Path=Data.SelectedItem}" >
<StackPanel Orientation="Horizontal">
<Image Source="/icons/cpu.ico" Width="20" Height="20" />
<TextBlock Text="Disassemble" Margin="4,0,0,0" FontSize="12" VerticalAlignment="Center" />
</StackPanel>
</Button>
<TextBox Margin="8,0,0,0" VerticalAlignment="Center" Text="{Binding SearchText, Mode=TwoWay, Delay=300, UpdateSourceTrigger=PropertyChanged}" Width="300" metro:TextBoxHelper.ClearTextButton="True"
metro:TextBoxHelper.Watermark="Search Exports" HorizontalAlignment="Left">
<i:Interaction.Triggers>
<ie:KeyTrigger Key="Esc">
<ie:ChangePropertyAction PropertyName="Text" Value="" />
</ie:KeyTrigger>
</i:Interaction.Triggers>
</TextBox>
<DataGrid Grid.Row="2" ItemsSource="{Binding Exports}" IsReadOnly="True" AutoGenerateColumns="False" x:Name="_grid" SelectionMode="Single" RenderTransformOrigin="-3.534,0.32">
<DataGrid.ContextMenu>
<i:Interaction.Triggers>
<ie:KeyTrigger Key="Esc">
<ie:ChangePropertyAction PropertyName="Text" Value="" />
</ie:KeyTrigger>
</i:Interaction.Triggers>
</TextBox>
</StackPanel>
<DataGrid Grid.Row="2" ItemsSource="{Binding Exports}" IsReadOnly="True" AutoGenerateColumns="False" x:Name="_grid" SelectionMode="Single"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
<!--<DataGrid.ContextMenu>
<ContextMenu >
<MenuItem Header="Disassemble" Command="{Binding DisassembleCommand}" CommandParameter="{Binding Source={StaticResource proxy}, Path=Data.SelectedItem}"
Icon="{ext:Image /icons/cpu.ico, Width=24, Height=24}" />
<MenuItem Header="Disassemble" Command="{Binding DisassembleCommand}"
Icon="{ext:Image /icons/cpu.ico, Width=20, Height=20}" />
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid.ContextMenu>-->
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}" FontWeight="Bold" FontFamily="Consolas"/>
<DataGridTextColumn Header="Ordinal" Binding="{Binding Ordinal}" />
Expand Down

0 comments on commit 8aa50d1

Please sign in to comment.