Skip to content

Commit d2adab0

Browse files
committed
Added value compare type and Undo scan features
1 parent 9bbf382 commit d2adab0

17 files changed

Lines changed: 557 additions & 303 deletions

StructureSpiderAdvanced/MainViewModel.cs

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public MainViewModel()
1515
{
1616
Instance = this;
1717
DataTypes.AddRange(Enum.GetValues(typeof(DataType)) as IEnumerable<DataType>);
18+
DataCompareTypes.AddRange(Enum.GetValues(typeof(DataCompareType)) as IEnumerable<DataCompareType>);
1819
StringCompareTypes.AddRange(Enum.GetValues(typeof(StringCompareType)) as IEnumerable<StringCompareType>);
1920
}
2021

@@ -103,6 +104,17 @@ public int ValuesScanned
103104
RaisePropertyChanged(nameof(ValuesScanned));
104105
}
105106
}
107+
108+
private bool canUndoScan;
109+
public bool CanUndoScan
110+
{
111+
get => canUndoScan;
112+
set
113+
{
114+
canUndoScan = value;
115+
RaisePropertyChanged(nameof(CanUndoScan));
116+
}
117+
}
106118
////////////////////////////////////////////////
107119
public ObservableCollection<VisibleResult> VisibleResults { get; set; } = new AsyncObservableCollection<VisibleResult>();
108120
public void AddRezultAsync(VisibleResult rezult)
@@ -138,17 +150,28 @@ public ushort Alignment
138150
}
139151
}
140152

141-
private DataType selectedDataType = DataType.Pointer;
153+
private DataType _selectedDataType = DataType.Pointer;
142154
public DataType SelectedDataType
143155
{
144-
get { return selectedDataType; }
156+
get => _selectedDataType;
145157
set
146158
{
147-
selectedDataType = value;
159+
_selectedDataType = value;
148160
RaisePropertyChanged(nameof(SelectedDataType));
149161
}
150162
}
151163

164+
private DataCompareType _compareType = DataCompareType.Equal;
165+
public DataCompareType CompareType
166+
{
167+
get => _compareType;
168+
set
169+
{
170+
_compareType = value;
171+
RaisePropertyChanged(nameof(CompareType));
172+
}
173+
}
174+
152175
public long StartSearchAddress { get; set; } = 0x0;
153176

154177

@@ -210,6 +233,7 @@ public bool UseEndOffsets
210233
////////////////////////////////////////////////
211234
public List<int> MaxLevels { get; set; } = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
212235
public List<DataType> DataTypes { get; set; } = new List<DataType>();
236+
public List<DataCompareType> DataCompareTypes { get; set; } = new List<DataCompareType>();
213237
public List<ushort> Alignments { get; set; } = new List<ushort>() { 1, 2, 4, 8 };
214238
public List<StringCompareType> StringCompareTypes { get; set; } = new List<StringCompareType>();
215239
}
@@ -222,20 +246,30 @@ public enum StringCompareType
222246
EndsWith
223247
}
224248

225-
public enum DataType
226-
{
249+
public enum DataType
250+
{
227251
Pointer,
228-
Int,
229-
UInt,
230-
Short,
231-
UShort,
232-
Byte,
233-
Long,
234-
Float,
235-
String,
252+
Int,
253+
UInt,
254+
Short,
255+
UShort,
256+
Byte,
257+
Long,
258+
Float,
259+
String,
236260
StringU,
237261
}
238262

263+
public enum DataCompareType
264+
{
265+
Equal,
266+
Bigger,
267+
BiggerOrEqual,
268+
Less,
269+
LessOrEqual,
270+
NotEqual
271+
}
272+
239273
public class VisibleResult : BindableBase
240274
{
241275
public int Level { get; set; }
@@ -252,6 +286,8 @@ public string Address
252286
}
253287
}
254288

289+
public IComparable ComparableValue { get; set; }
290+
255291
private string value;
256292
public string Value
257293
{

StructureSpiderAdvanced/MainWindow.xaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@
8282
</Binding>
8383
</TextBox.Text>
8484
</TextBox>
85-
85+
8686
<ComboBox materialDesign:HintAssist.Hint="Alignment" ToolTip="Scan step. For x32 bit process pointers and strings recommended alignment value is 4, for x64 recommended value is 8" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
8787
ItemsSource="{Binding Path=ViewModel.Alignments}" SelectedValue="{Binding Path=ViewModel.Alignment}" IsEnabled="{Binding Path=ViewModel.InterfaceEnabled}"
8888
MinWidth="50" Margin="5" Foreground="#FFC8C8C8"/>
8989

90+
<ComboBox materialDesign:HintAssist.Hint="Compare type" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
91+
ItemsSource="{Binding Path=ViewModel.DataCompareTypes}" SelectedValue="{Binding Path=ViewModel.CompareType}"
92+
MinWidth="80" Margin="5" Foreground="#FFC8C8C8" SelectionChanged="OnSearchTypeChanged" IsEnabled="{Binding Path=ViewModel.InterfaceEnabled}"
93+
Visibility="{Binding Path=ViewModel.SelectedDataType, Converter={StaticResource ScanTypeToVisibilityConverter}, ConverterParameter=NotString}"/>
94+
9095
<TextBox materialDesign:HintAssist.Hint="String Length" ToolTip="Maximum length of string bytes to read" Style="{StaticResource MaterialDesignFloatingHintTextBox}"
9196
VerticalContentAlignment="Center" Margin="5" MinWidth="50" Foreground="#FFC8C8C8"
9297
IsEnabled="{Binding Path=ViewModel.InterfaceEnabled}"
@@ -108,6 +113,7 @@
108113
Foreground="#FFC8C8C8" Visibility="{Binding Path=ViewModel.SelectedDataType, Converter={StaticResource ScanTypeToVisibilityConverter}, ConverterParameter=StringLength}"/>
109114

110115
<Button Name="SearchButton" Content="Search" HorizontalAlignment="Left" VerticalAlignment="Top" Width="80" Margin="5" Click="SearchButtonClick"/>
116+
<Button Name="UndoScanButton" Content="Undo Scan" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Margin="5" Click="UndoScan" IsEnabled="{Binding Path=ViewModel.CanUndoScan}"/>
111117

112118
</StackPanel>
113119
<GridSplitter Grid.Row="3" HorizontalAlignment="Stretch" Height="10"></GridSplitter>

StructureSpiderAdvanced/MainWindow.xaml.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ private void UpdateListOfProcesses()
141141
}
142142

143143
/// GUI buttons ////////////////////////////////////////////////
144+
144145
private void SearchButtonClick(object sender, RoutedEventArgs e)
145146
{
146147
if (!ViewModel.InterfaceEnabled)
@@ -168,12 +169,34 @@ private void SearchButtonClick(object sender, RoutedEventArgs e)
168169
SearchButton.Content = "Cancel";
169170
ViewModel.InterfaceEnabled = false;
170171

172+
BackupLastScan();
171173
ViewModel.VisibleResults.Clear();
172174

173175
SearchThread = new Thread(SearchAsync);
174176
SearchThread.Start();
175177
}
176178

179+
private Stack<AsyncObservableCollection<VisibleResult>> PrevScanBackup = new Stack<AsyncObservableCollection<VisibleResult>>();
180+
181+
private void BackupLastScan()
182+
{
183+
if (ViewModel.VisibleResults.Count > 0)
184+
{
185+
PrevScanBackup.Push(new AsyncObservableCollection<VisibleResult>(ViewModel.VisibleResults));
186+
}
187+
ViewModel.CanUndoScan = PrevScanBackup.Count > 0;
188+
}
189+
190+
private void UndoScan(object sender, RoutedEventArgs e)
191+
{
192+
if (PrevScanBackup.Count > 0)
193+
{
194+
ViewModel.VisibleResults = PrevScanBackup.Pop();
195+
}
196+
197+
ViewModel.CanUndoScan = PrevScanBackup.Count > 0;
198+
}
199+
177200
private void RefreshProcesses(object sender, RoutedEventArgs e)
178201
{
179202
UpdateListOfProcesses();
@@ -203,6 +226,7 @@ private void DeleteBrokenPointers(object sender, RoutedEventArgs e)
203226

204227
private void FilterValues(object sender, RoutedEventArgs e)
205228
{
229+
BackupLastScan();
206230
RefreshTable(RezultRefreshType.FilterValues);
207231
}
208232

@@ -216,7 +240,7 @@ private void RefreshTable(RezultRefreshType refreshType)
216240

217241
var startPointer = new IntPtr(ViewModel.StartSearchAddress);
218242

219-
var convertedCompareValue = comparer.ConvertCompareValue(ViewModel.ScanValue);
243+
var convertedCompareValue = comparer.ConvertToComparableValue(ViewModel.ScanValue);
220244

221245
foreach (var pointer in ViewModel.VisibleResults.ToList())
222246
{

StructureSpiderAdvanced/Memory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public byte[] ReadBytes(IntPtr addr, int length)
3333
return ReadMem(addr, length);
3434
}
3535

36-
public int ReadByte(IntPtr addr)
36+
public byte ReadByte(IntPtr addr)
3737
{
3838
var bytes = ReadMem(addr, 1);
3939
return bytes[0];

StructureSpiderAdvanced/Scanner.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Windows.Forms;
4+
using StructureSpiderAdvanced.ValueReaders;
5+
using StructureSpiderAdvanced.ValueReaders.Base;
46

57
namespace StructureSpiderAdvanced
68
{
@@ -22,36 +24,36 @@ public Scanner(MainViewModel viewModel, Memory m)
2224
MVM.PointersEvaluated = 0;
2325
MVM.ValuesScanned = 0;
2426

25-
var pLength = (ushort)M.PointerLength;
27+
var pLength = (ushort) M.PointerLength;
2628

2729
if (viewModel.SelectedDataType == DataType.Pointer ||
2830
viewModel.SelectedDataType == DataType.String ||
2931
viewModel.SelectedDataType == DataType.StringU
30-
)
32+
)
3133
{
32-
if(MVM.Alignment != pLength)
34+
if (MVM.Alignment != pLength)
3335
{
3436
var bits = m.Is64Bit ? "x64" : "x32";
3537

3638
var result = MessageBox.Show($"Do you really want to scan with alignment {MVM.Alignment} " +
37-
$"(For {bits} process structure alignment is {pLength})? " + Environment.NewLine +
38-
$"For this scan type recommended value is {pLength}" + Environment.NewLine +
39-
$"Yes - continue using {MVM.Alignment}" + Environment.NewLine +
40-
$"No - set to {pLength} (Recommended)", "Alighnment", MessageBoxButtons.YesNo);
39+
$"(For {bits} process structure alignment is {pLength})? " + Environment.NewLine +
40+
$"For this scan type recommended value is {pLength}" + Environment.NewLine +
41+
$"Yes - continue using {MVM.Alignment}" + Environment.NewLine +
42+
$"No - set to {pLength} (Recommended)", "Alighnment", MessageBoxButtons.YesNo);
4143

4244
if (result == DialogResult.No)
4345
MVM.Alignment = pLength;
4446
}
4547
}
4648

4749
var scansCount = MVM.MaxScanLength / MVM.Alignment;
48-
MVM.MaxScanLength = (ushort)(scansCount * MVM.Alignment);
50+
MVM.MaxScanLength = (ushort) (scansCount * MVM.Alignment);
4951

5052
ValueReader = GetValueReaderByDataType(viewModel.SelectedDataType, M, MVM);
5153
ValueReader.SetCompareValue(MVM.ScanValue);
5254

5355
var startPointer = new IntPtr(MVM.StartSearchAddress);
54-
PossibleSubPointers.Enqueue(new SubClassScan() { Address = startPointer });
56+
PossibleSubPointers.Enqueue(new SubClassScan() {Address = startPointer});
5557
MVM.PointersFound = 1;
5658

5759
while (PossibleSubPointers.Count > 0)
@@ -89,7 +91,7 @@ public static BaseValueReader GetValueReaderByDataType(DataType dataType, Memory
8991
return new UStringValueReader(m, mvm);
9092
default:
9193
throw new NotImplementedException($"Scan type is not defined in code: {dataType}");
92-
}
94+
}
9395
}
9496

9597
private void DoScan(SubClassScan subScan)
@@ -109,29 +111,41 @@ private void DoScan(SubClassScan subScan)
109111
{
110112
var longPointer = ValueReader.LastReadPointer.ToInt64();
111113
allowAdd = !ProcessedPointers.Contains(longPointer);
114+
112115
if (allowAdd)
113116
ProcessedPointers.Add(longPointer);
114117
}
115118

116119
if (allowAdd)
117120
{
118-
var newPointer = new SubClassScan() { Address = ValueReader.LastReadPointer, Level = subScan.Level + 1, };
121+
var newPointer = new SubClassScan() {Address = ValueReader.LastReadPointer, Level = subScan.Level + 1,};
122+
119123
newPointer.Offsets = new List<int>(subScan.Offsets)
120124
{
121125
offset
122126
};
127+
123128
PossibleSubPointers.Enqueue(newPointer);
124129
MVM.CurrentEntries = PossibleSubPointers.Count;
125130
MVM.PointersFound++;
126131
}
127132
}
128133

129134
var readCompareRezult = ValueReader.ReadCompareValue(scanAddress);
130-
if (readCompareRezult.IsEqual)
135+
136+
if (readCompareRezult.IsSatisfying)
131137
{
132-
var newScanResult = new VisibleResult() { Offsets = new List<int>(subScan.Offsets) { offset }, Address = scanAddress.ToString("x"), Level = subScan.Level, Value = readCompareRezult.DisplayValue};
138+
var newScanResult = new VisibleResult()
139+
{
140+
Offsets = new List<int>(subScan.Offsets) {offset},
141+
Address = scanAddress.ToString("x"),
142+
Level = subScan.Level,
143+
Value = readCompareRezult.DisplayValue,
144+
ComparableValue = readCompareRezult.ComparableValue,
145+
};
133146
MVM.AddRezultAsync(newScanResult);
134147
}
148+
135149
MVM.ValuesScanned++;
136150
}
137151
}

0 commit comments

Comments
 (0)