| 1 | #!/usr/local/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | binmode STDOUT, ':utf8'; | ||
| 6 | |||
| 7 | use Parse::Win32Registry 0.60; | ||
| 8 | |||
| 9 | |||
| 10 | package BlockListCtrl; | ||
| 11 | |||
| 12 | use Wx qw(:everything); | ||
| 13 | |||
| 14 | use base qw(Wx::ListCtrl); | ||
| 15 | |||
| 16 | sub new { | ||
| 17 | my ($class, $parent) = @_; | ||
| 18 | |||
| 19 | my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_VIRTUAL|wxBORDER_SUNKEN); | ||
| 20 | bless $self, $class; | ||
| 21 | |||
| 22 | $self->InsertColumn(0, "Block"); | ||
| 23 | $self->InsertColumn(1, "Length"); | ||
| 24 | $self->InsertColumn(2, "Tag"); | ||
| 25 | |||
| 26 | $self->SetColumnWidth(0, 100); | ||
| 27 | $self->SetColumnWidth(2, 100); | ||
| 28 | |||
| 29 | return $self; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub Clear { | ||
| 33 | my ($self) = @_; | ||
| 34 | |||
| 35 | $self->{_blocks} = []; | ||
| 36 | $self->SetItemCount(0); | ||
| 37 | $self->Refresh; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub OnGetItemText { | ||
| 41 | my ($self, $index, $column) = @_; | ||
| 42 | |||
| 43 | my $block = $self->{_blocks}[$index]; | ||
| 44 | return if !defined $block; | ||
| 45 | if ($column == 0) { | ||
| 46 | return sprintf '0x%x', $block->get_offset; | ||
| 47 | } | ||
| 48 | elsif ($column == 1) { | ||
| 49 | return sprintf '0x%x', $block->get_length; | ||
| 50 | } | ||
| 51 | elsif ($column == 2) { | ||
| 52 | return sprintf '%s', $block->get_tag; | ||
| 53 | } | ||
| 54 | else { | ||
| 55 | return "?"; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | sub SetRegistry { | ||
| 60 | my ($self, $registry) = @_; | ||
| 61 | |||
| 62 | $self->{_blocks} = []; | ||
| 63 | my $block_iter = $registry->get_block_iterator; | ||
| 64 | while (my $block = $block_iter->get_next) { | ||
| 65 | push @{$self->{_blocks}}, $block; | ||
| 66 | } | ||
| 67 | $self->SetItemCount(scalar @{$self->{_blocks}}); | ||
| 68 | $self->Refresh; | ||
| 69 | $self->SetItemState(0, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); | ||
| 70 | } | ||
| 71 | |||
| 72 | sub GetBlock { | ||
| 73 | my ($self, $index) = @_; | ||
| 74 | |||
| 75 | return $self->{_blocks}[$index]; | ||
| 76 | } | ||
| 77 | |||
| 78 | sub GoToBlock { | ||
| 79 | my ($self, $offset) = @_; | ||
| 80 | |||
| 81 | my $index = 0; | ||
| 82 | foreach my $block (@{$self->{_blocks}}) { | ||
| 83 | my $block_start = $block->get_offset; | ||
| 84 | my $block_end = $block_start + $block->get_length; | ||
| 85 | if ($offset >= $block_start && $offset < $block_end) { | ||
| 86 | $self->EnsureVisible($index); | ||
| 87 | $self->SetItemState($index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | $index++; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | package EntryListCtrl; | ||
| 96 | |||
| 97 | use Wx qw(:everything); | ||
| 98 | |||
| 99 | use base qw(Wx::ListCtrl); | ||
| 100 | |||
| 101 | use constant ATTR_KEY => | ||
| 102 | Wx::ListItemAttr->new(Wx::Colour->new('#000000'), | ||
| 103 | Wx::Colour->new('#ffb0b0'), wxNullFont); | ||
| 104 | use constant ATTR_VALUE => | ||
| 105 | Wx::ListItemAttr->new(Wx::Colour->new('#000000'), | ||
| 106 | Wx::Colour->new('#b0ffb0'), wxNullFont); | ||
| 107 | use constant ATTR_SECURITY => | ||
| 108 | Wx::ListItemAttr->new(Wx::Colour->new('#000000'), | ||
| 109 | Wx::Colour->new('#b0ffff'), wxNullFont); | ||
| 110 | use constant ATTR_SUBKEY_LIST => | ||
| 111 | Wx::ListItemAttr->new(Wx::Colour->new('#000000'), | ||
| 112 | Wx::Colour->new('#ffb0ff'), wxNullFont); | ||
| 113 | use constant ATTR_OTHER => | ||
| 114 | Wx::ListItemAttr->new(Wx::Colour->new('#000000'), | ||
| 115 | Wx::Colour->new('#f0f0f0'), wxNullFont); | ||
| 116 | #use constant ATTR_OTHER => | ||
| 117 | # Wx::ListItemAttr->new(wxNullColour, wxNullColour, wxNullFont); | ||
| 118 | |||
| 119 | sub new { | ||
| 120 | my ($class, $parent) = @_; | ||
| 121 | |||
| 122 | my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_VIRTUAL|wxBORDER_SUNKEN); | ||
| 123 | bless $self, $class; | ||
| 124 | |||
| 125 | $self->InsertColumn(0, "Entry"); | ||
| 126 | $self->InsertColumn(1, "Length"); | ||
| 127 | $self->InsertColumn(2, "Alloc."); | ||
| 128 | $self->InsertColumn(3, "Tag"); | ||
| 129 | $self->InsertColumn(4, "Name"); | ||
| 130 | |||
| 131 | $self->SetColumnWidth(0, 100); | ||
| 132 | $self->SetColumnWidth(3, 100); | ||
| 133 | $self->SetColumnWidth(4, 200); | ||
| 134 | |||
| 135 | return $self; | ||
| 136 | } | ||
| 137 | |||
| 138 | sub Clear { | ||
| 139 | my ($self) = @_; | ||
| 140 | |||
| 141 | $self->{_entries} = []; | ||
| 142 | $self->SetItemCount(0); | ||
| 143 | $self->Refresh; | ||
| 144 | } | ||
| 145 | |||
| 146 | sub OnGetItemText { | ||
| 147 | my ($self, $index, $column) = @_; | ||
| 148 | |||
| 149 | my $entry = $self->{_entries}[$index]; | ||
| 150 | return if !defined $entry; | ||
| 151 | if ($column == 0) { | ||
| 152 | return sprintf '0x%x', $entry->get_offset; | ||
| 153 | } | ||
| 154 | elsif ($column == 1) { | ||
| 155 | return sprintf '0x%x', $entry->get_length; | ||
| 156 | } | ||
| 157 | elsif ($column == 2) { | ||
| 158 | return $entry->is_allocated; | ||
| 159 | } | ||
| 160 | elsif ($column == 3) { | ||
| 161 | return $entry->get_tag; | ||
| 162 | } | ||
| 163 | elsif ($column == 4) { | ||
| 164 | my $name = ''; | ||
| 165 | if ($entry->can('get_name')) { | ||
| 166 | $name = $entry->get_name; | ||
| 167 | $name =~ s/\0/[NUL]/g; | ||
| 168 | $name =~ s/\n/[LF]/g; | ||
| 169 | $name =~ s/\r/[CR]/g; | ||
| 170 | } | ||
| 171 | return $name; | ||
| 172 | } | ||
| 173 | else { | ||
| 174 | return "?"; | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | sub OnGetItemAttr { | ||
| 179 | my ($self, $index) = @_; | ||
| 180 | |||
| 181 | my $entry = $self->{_entries}[$index]; | ||
| 182 | return if !defined $entry; | ||
| 183 | my $tag = $entry->get_tag; | ||
| 184 | if ($tag eq 'nk' || $tag eq 'rgkn key' || $tag eq 'rgdb key') { | ||
| 185 | return ATTR_KEY; | ||
| 186 | } | ||
| 187 | elsif ($tag eq 'vk' || $tag eq 'rgdb value') { | ||
| 188 | return ATTR_VALUE; | ||
| 189 | } | ||
| 190 | elsif ($tag eq 'sk') { | ||
| 191 | return ATTR_SECURITY; | ||
| 192 | } | ||
| 193 | elsif ($tag eq 'lh' || $tag eq 'lf' || $tag eq 'li' || $tag eq 'ri') { | ||
| 194 | return ATTR_SUBKEY_LIST; | ||
| 195 | } | ||
| 196 | else { | ||
| 197 | return ATTR_OTHER; | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | sub SetBlock { | ||
| 202 | my ($self, $block) = @_; | ||
| 203 | |||
| 204 | $self->{_entries} = []; | ||
| 205 | my $entry_iter = $block->get_entry_iterator; | ||
| 206 | while (my $entry = $entry_iter->get_next) { | ||
| 207 | push @{$self->{_entries}}, $entry; | ||
| 208 | } | ||
| 209 | $self->SetItemCount(scalar @{$self->{_entries}}); | ||
| 210 | $self->Refresh; | ||
| 211 | $self->SetItemState(0, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); | ||
| 212 | } | ||
| 213 | |||
| 214 | sub GetEntry { | ||
| 215 | my ($self, $index) = @_; | ||
| 216 | |||
| 217 | return $self->{_entries}[$index]; | ||
| 218 | } | ||
| 219 | |||
| 220 | sub GoToEntry { | ||
| 221 | my ($self, $offset) = @_; | ||
| 222 | |||
| 223 | my $index = 0; | ||
| 224 | foreach my $entry (@{$self->{_entries}}) { | ||
| 225 | my $entry_start = $entry->get_offset; | ||
| 226 | my $entry_end = $entry_start + $entry->get_length; | ||
| 227 | if ($offset >= $entry_start && $offset < $entry_end) { | ||
| 228 | $self->EnsureVisible($index); | ||
| 229 | $self->SetItemState($index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); | ||
| 230 | return; | ||
| 231 | } | ||
| 232 | $index++; | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | |||
| 237 | package FindDialog; | ||
| 238 | |||
| 239 | use Wx qw(:everything); | ||
| 240 | use Wx::Event qw(:everything); | ||
| 241 | |||
| 242 | use base qw(Wx::Dialog); | ||
| 243 | |||
| 244 | sub new { | ||
| 245 | my ($class, $parent) = @_; | ||
| 246 | |||
| 247 | my $self = $class->SUPER::new($parent, -1, "Find", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE); | ||
| 248 | bless $self, $class; | ||
| 249 | |||
| 250 | my $static = Wx::StaticText->new($self, -1, 'Enter text to &search for:'); | ||
| 251 | my $text = Wx::TextCtrl->new($self, -1, ''); | ||
| 252 | |||
| 253 | my $sizer = Wx::BoxSizer->new(wxVERTICAL); | ||
| 254 | $sizer->Add($static, 0, wxEXPAND|wxALL, 5); | ||
| 255 | $sizer->Add($text, 0, wxEXPAND|wxALL, 5); | ||
| 256 | |||
| 257 | my $button_sizer = $self->CreateSeparatedButtonSizer(wxOK|wxCANCEL); | ||
| 258 | |||
| 259 | $sizer->Add($button_sizer, 0, wxEXPAND|wxALL, 5); | ||
| 260 | |||
| 261 | $self->SetSizer($sizer); | ||
| 262 | |||
| 263 | $self->{_text} = $text; | ||
| 264 | |||
| 265 | $self->Fit; # resizes dialog to best fit child windows | ||
| 266 | |||
| 267 | $self->{_text}->SetFocus; | ||
| 268 | $self->SetFocus; | ||
| 269 | |||
| 270 | return $self; | ||
| 271 | } | ||
| 272 | |||
| 273 | sub GetText { | ||
| 274 | my ($self) = @_; | ||
| 275 | |||
| 276 | return $self->{_text}->GetValue; | ||
| 277 | } | ||
| 278 | |||
| 279 | sub SetText { | ||
| 280 | my ($self, $value) = @_; | ||
| 281 | |||
| 282 | $value = '' if !defined $value; | ||
| 283 | $self->{_text}->ChangeValue($value); | ||
| 284 | $self->{_text}->SetSelection(-1, -1); | ||
| 285 | } | ||
| 286 | |||
| 287 | |||
| 288 | package ScopeFrame; | ||
| 289 | |||
| 290 | use Encode; | ||
| 291 | use File::Basename; | ||
| 292 | use FindBin; | ||
| 293 | use Parse::Win32Registry; | ||
| 294 | use Wx qw(:everything); | ||
| 295 | use Wx::Event qw(:everything); | ||
| 296 | |||
| 297 | use base qw(Wx::Frame); | ||
| 298 | |||
| 299 | use constant ID_FIND_NEXT => Wx::NewId; | ||
| 300 | use constant ID_SELECT_FONT => Wx::NewId; | ||
| 301 | use constant ID_GO_TO => Wx::NewId; | ||
| 302 | |||
| 303 | sub new { | ||
| 304 | my ($class, $parent) = @_; | ||
| 305 | |||
| 306 | my $self = $class->SUPER::new($parent, -1, "Registry Scope", wxDefaultPosition, [600, 400]); | ||
| 307 | bless $self, $class; | ||
| 308 | |||
| 309 | $self->SetMinSize([600, 400]); | ||
| 310 | |||
| 311 | my $menu1 = Wx::Menu->new; | ||
| 312 | $menu1->Append(wxID_OPEN, "&Open...\tCtrl+O"); | ||
| 313 | $menu1->Append(wxID_CLOSE, "&Close\tCtrl+W"); | ||
| 314 | $menu1->AppendSeparator; | ||
| 315 | $menu1->Append(wxID_EXIT, "E&xit\tAlt+F4"); | ||
| 316 | |||
| 317 | my $menu2 = Wx::Menu->new; | ||
| 318 | $menu2->Append(wxID_FIND, "&Find...\tCtrl+F"); | ||
| 319 | $menu2->Append(ID_FIND_NEXT, "Find &Next\tF3"); | ||
| 320 | $menu2->AppendSeparator; | ||
| 321 | $menu2->Append(ID_GO_TO, "&Go To Offset...\tCtrl+G"); | ||
| 322 | |||
| 323 | my $menu3 = Wx::Menu->new; | ||
| 324 | $menu3->Append(ID_SELECT_FONT, "Select &Font..."); | ||
| 325 | |||
| 326 | my $menu4 = Wx::Menu->new; | ||
| 327 | $menu4->Append(wxID_ABOUT, "&About..."); | ||
| 328 | |||
| 329 | my $menubar = Wx::MenuBar->new; | ||
| 330 | $menubar->Append($menu1, "&File"); | ||
| 331 | $menubar->Append($menu2, "&Search"); | ||
| 332 | $menubar->Append($menu3, "&View"); | ||
| 333 | $menubar->Append($menu4, "&Help"); | ||
| 334 | |||
| 335 | $self->SetMenuBar($menubar); | ||
| 336 | |||
| 337 | my $statusbar = Wx::StatusBar->new($self, -1); | ||
| 338 | $self->SetStatusBar($statusbar); | ||
| 339 | |||
| 340 | EVT_MENU($self, wxID_OPEN, \&OnOpenFile); | ||
| 341 | EVT_MENU($self, wxID_CLOSE, \&OnCloseFile); | ||
| 342 | EVT_MENU($self, wxID_EXIT, \&OnQuit); | ||
| 343 | EVT_MENU($self, wxID_FIND, \&OnFind); | ||
| 344 | EVT_MENU($self, ID_FIND_NEXT, \&FindNext); | ||
| 345 | EVT_MENU($self, ID_GO_TO, \&GoToOffset); | ||
| 346 | EVT_MENU($self, wxID_ABOUT, \&OnAbout); | ||
| 347 | EVT_MENU($self, ID_SELECT_FONT, \&OnSelectFont); | ||
| 348 | |||
| 349 | my $vsplitter = Wx::SplitterWindow->new($self, -1, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER); | ||
| 350 | |||
| 351 | my $text = Wx::TextCtrl->new($vsplitter, -1, '', wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_DONTWRAP|wxTE_READONLY); | ||
| 352 | $text->SetFont(Wx::Font->new(10, wxMODERN, wxNORMAL, wxNORMAL)); | ||
| 353 | |||
| 354 | my $hsplitter = Wx::SplitterWindow->new($vsplitter, -1, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER); | ||
| 355 | |||
| 356 | $vsplitter->SplitHorizontally($hsplitter, $text); | ||
| 357 | $vsplitter->SetMinimumPaneSize(10); | ||
| 358 | |||
| 359 | my $list1 = BlockListCtrl->new($hsplitter); | ||
| 360 | |||
| 361 | my $list2 = EntryListCtrl->new($hsplitter); | ||
| 362 | |||
| 363 | $hsplitter->SplitVertically($list1, $list2); | ||
| 364 | $hsplitter->SetMinimumPaneSize(10); | ||
| 365 | |||
| 366 | $self->{_list1} = $list1; | ||
| 367 | $self->{_list2} = $list2; | ||
| 368 | $self->{_vsplitter} = $vsplitter; | ||
| 369 | $self->{_text} = $text; | ||
| 370 | $self->{_statusbar} = $statusbar; | ||
| 371 | |||
| 372 | EVT_SPLITTER_DCLICK($self, $hsplitter, \&OnSplitterDClick); | ||
| 373 | EVT_SPLITTER_DCLICK($self, $vsplitter, \&OnSplitterDClick); | ||
| 374 | |||
| 375 | EVT_LIST_ITEM_SELECTED($self, $list1, \&OnBlockSelected); | ||
| 376 | EVT_LIST_ITEM_SELECTED($self, $list2, \&OnEntrySelected); | ||
| 377 | |||
| 378 | $self->SetIcon(Wx::GetWxPerlIcon()); | ||
| 379 | |||
| 380 | my $accelerators = Wx::AcceleratorTable->new( | ||
| 381 | [wxACCEL_CTRL, ord('Q'), wxID_EXIT], | ||
| 382 | ); | ||
| 383 | $self->SetAcceleratorTable($accelerators); | ||
| 384 | |||
| 385 | my $filename = shift @ARGV; | ||
| 386 | if (defined $filename) { | ||
| 387 | $self->LoadFile($filename); | ||
| 388 | } | ||
| 389 | |||
| 390 | return $self; | ||
| 391 | } | ||
| 392 | |||
| 393 | sub GoToOffset { | ||
| 394 | my ($self, $event) = @_; | ||
| 395 | |||
| 396 | return if !defined $self->{_registry}; | ||
| 397 | |||
| 398 | my $dialog = Wx::TextEntryDialog->new($self, 'Enter the offset below:', 'Go To Offset', '0x'); | ||
| 399 | if ($dialog->ShowModal != wxID_OK) { | ||
| 400 | return; | ||
| 401 | } | ||
| 402 | |||
| 403 | my $offset; | ||
| 404 | eval { | ||
| 405 | my $answer = $dialog->GetValue; | ||
| 406 | if ($answer =~ m/^\s*0x[\da-fA-F]+\s*$/ || $answer =~ m/^\s*\d+\s*$/) { | ||
| 407 | $offset = int(eval $answer); | ||
| 408 | } | ||
| 409 | }; | ||
| 410 | |||
| 411 | $dialog->Destroy; | ||
| 412 | |||
| 413 | if (defined $offset) { | ||
| 414 | $self->{_list1}->GoToBlock($offset); | ||
| 415 | $self->{_list2}->GoToEntry($offset); | ||
| 416 | } | ||
| 417 | |||
| 418 | $self->{_list2}->SetFocus; | ||
| 419 | $self->SetFocus; | ||
| 420 | } | ||
| 421 | |||
| 422 | sub OnSelectFont { | ||
| 423 | my ($self, $event) = @_; | ||
| 424 | |||
| 425 | my $text = $self->{_text}; | ||
| 426 | my $font = $text->GetFont; | ||
| 427 | $font = Wx::GetFontFromUser($self, $font); | ||
| 428 | if ($font->IsOk) { | ||
| 429 | $text->SetFont($font); | ||
| 430 | } | ||
| 431 | } | ||
| 432 | |||
| 433 | sub OnSplitterDClick { | ||
| 434 | my ($self, $event) = @_; | ||
| 435 | |||
| 436 | $event->Veto; | ||
| 437 | } | ||
| 438 | |||
| 439 | sub OnBlockSelected { | ||
| 440 | my ($self, $event) = @_; | ||
| 441 | |||
| 442 | my $index = $event->GetIndex; | ||
| 443 | my $block = $self->{_list1}->GetBlock($index); | ||
| 444 | |||
| 445 | $self->{_list2}->SetBlock($block); | ||
| 446 | |||
| 447 | my $parse_info = $block->parse_info; | ||
| 448 | $parse_info =~ s/\0/[NUL]/g; | ||
| 449 | $parse_info =~ s/\n/[LF]/g; | ||
| 450 | $parse_info =~ s/\r/[CR]/g; | ||
| 451 | my $details = $parse_info . "\n" . $block->unparsed; | ||
| 452 | |||
| 453 | $self->{_text}->ChangeValue($details); | ||
| 454 | |||
| 455 | my $status = sprintf "Block Offset: 0x%x", $block->get_offset; | ||
| 456 | $self->{_statusbar}->SetStatusText($status); | ||
| 457 | } | ||
| 458 | |||
| 459 | sub OnEntrySelected { | ||
| 460 | my ($self, $event) = @_; | ||
| 461 | |||
| 462 | my $index = $event->GetIndex; | ||
| 463 | my $entry = $self->{_list2}->GetEntry($index); | ||
| 464 | |||
| 465 | my $parse_info = $entry->parse_info; | ||
| 466 | $parse_info =~ s/\0/[NUL]/g; | ||
| 467 | $parse_info =~ s/\n/[LF]/g; | ||
| 468 | $parse_info =~ s/\r/[CR]/g; | ||
| 469 | my $details = $parse_info . "\n" . $entry->unparsed; | ||
| 470 | |||
| 471 | $self->{_text}->ChangeValue($details); | ||
| 472 | |||
| 473 | my $status = sprintf "Entry Offset: 0x%x", $entry->get_offset; | ||
| 474 | $self->{_statusbar}->SetStatusText($status); | ||
| 475 | } | ||
| 476 | |||
| 477 | sub OnAbout { | ||
| 478 | my ($self, $event) = @_; | ||
| 479 | |||
| 480 | my $info = Wx::AboutDialogInfo->new; | ||
| 481 | $info->SetName($FindBin::Script); | ||
| 482 | $info->SetVersion($Parse::Win32Registry::VERSION); | ||
| 483 | $info->SetCopyright('Copyright (c) 2010-2012 James Macfarlane'); | ||
| 484 | $info->SetDescription('wxWidgets Registry Scope for the Parse::Win32Registry module'); | ||
| 485 | Wx::AboutBox($info); | ||
| 486 | } | ||
| 487 | |||
| 488 | sub OnFind { | ||
| 489 | my ($self, $event) = @_; | ||
| 490 | |||
| 491 | return if !defined $self->{_registry}; | ||
| 492 | |||
| 493 | my $dialog = FindDialog->new($self); | ||
| 494 | $dialog->SetText($self->{_find_param}); | ||
| 495 | if ($dialog->ShowModal == wxID_OK) { | ||
| 496 | my $registry = $self->{_registry}; | ||
| 497 | my $find_iter = $registry->get_entry_iterator; | ||
| 498 | $self->{_find_param} = $dialog->GetText; | ||
| 499 | $self->{_find_iter} = $find_iter; | ||
| 500 | $self->FindNext; | ||
| 501 | } | ||
| 502 | $dialog->Destroy; | ||
| 503 | } | ||
| 504 | |||
| 505 | sub FindNext { | ||
| 506 | my ($self) = @_; | ||
| 507 | |||
| 508 | my $find_param = $self->{_find_param}; | ||
| 509 | my $find_iter = $self->{_find_iter}; | ||
| 510 | |||
| 511 | return if !defined $find_param || $find_param eq ''; | ||
| 512 | return if !defined $find_iter; | ||
| 513 | |||
| 514 | my $start = time; | ||
| 515 | |||
| 516 | my $max = 0; | ||
| 517 | my $progress_dialog; | ||
| 518 | |||
| 519 | my $iter_finished = 1; | ||
| 520 | |||
| 521 | while (my $entry = $find_iter->get_next) { | ||
| 522 | my $found = 0; | ||
| 523 | if (index(lc $entry->get_raw_bytes, lc $find_param) > -1) { | ||
| 524 | $found = 1; | ||
| 525 | } | ||
| 526 | else { | ||
| 527 | my $uni_find_param = encode("UCS-2LE", $find_param); | ||
| 528 | if (index(lc $entry->get_raw_bytes, lc $uni_find_param) > -1) { | ||
| 529 | $found = 1; | ||
| 530 | } | ||
| 531 | } | ||
| 532 | if ($found) { | ||
| 533 | $self->{_list1}->GoToBlock($entry->get_offset); | ||
| 534 | $self->{_list2}->GoToEntry($entry->get_offset); | ||
| 535 | $iter_finished = 0; | ||
| 536 | last; | ||
| 537 | } | ||
| 538 | |||
| 539 | if (defined $progress_dialog) { | ||
| 540 | if (!$progress_dialog->Update) { | ||
| 541 | # Cancelled! | ||
| 542 | $iter_finished = 0; | ||
| 543 | last; | ||
| 544 | } | ||
| 545 | } | ||
| 546 | else { | ||
| 547 | if (time - $start >= 1) { | ||
| 548 | $progress_dialog = Wx::ProgressDialog->new('Find', | ||
| 549 | 'Searching registry...', $max, $self, | ||
| 550 | wxPD_CAN_ABORT|wxPD_AUTO_HIDE); | ||
| 551 | } | ||
| 552 | } | ||
| 553 | } | ||
| 554 | |||
| 555 | if (defined $progress_dialog) { | ||
| 556 | $progress_dialog->Destroy; | ||
| 557 | } | ||
| 558 | |||
| 559 | if ($iter_finished) { | ||
| 560 | my $dialog = Wx::MessageDialog->new($self, | ||
| 561 | 'Finished searching', 'Find', wxICON_EXCLAMATION|wxOK); | ||
| 562 | $dialog->ShowModal; | ||
| 563 | $dialog->Destroy; | ||
| 564 | } | ||
| 565 | $self->{_list1}->SetFocus; | ||
| 566 | $self->SetFocus; | ||
| 567 | } | ||
| 568 | |||
| 569 | sub LoadFile { | ||
| 570 | my ($self, $filename) = @_; | ||
| 571 | |||
| 572 | if (!-r $filename) { | ||
| 573 | my $dialog = Wx::MessageDialog->new($self, | ||
| 574 | "'$filename' cannot be read", 'Error', wxICON_ERROR|wxOK); | ||
| 575 | $dialog->ShowModal; | ||
| 576 | $dialog->Destroy; | ||
| 577 | return | ||
| 578 | } | ||
| 579 | |||
| 580 | my $basename = basename($filename); | ||
| 581 | |||
| 582 | my $registry = Parse::Win32Registry->new($filename); | ||
| 583 | if (!defined $registry) { | ||
| 584 | my $dialog = Wx::MessageDialog->new($self, | ||
| 585 | "'$basename' is not a registry file", 'Error', wxICON_ERROR|wxOK); | ||
| 586 | $dialog->ShowModal; | ||
| 587 | $dialog->Destroy; | ||
| 588 | return | ||
| 589 | } | ||
| 590 | |||
| 591 | # clear | ||
| 592 | $self->OnCloseFile; | ||
| 593 | |||
| 594 | # set up | ||
| 595 | $self->{_registry} = $registry; | ||
| 596 | $self->{_list1}->SetRegistry($registry); | ||
| 597 | $self->{_list1}->SetFocus; | ||
| 598 | $self->SetTitle("$basename - Registry Scope"); | ||
| 599 | } | ||
| 600 | |||
| 601 | sub OnOpenFile { | ||
| 602 | my ($self, $event) = @_; | ||
| 603 | |||
| 604 | my $dialog = Wx::FileDialog->new($self, 'Select Registry File', $self->{_directory} || ''); | ||
| 605 | |||
| 606 | if ($dialog->ShowModal != wxID_OK) { | ||
| 607 | return; | ||
| 608 | } | ||
| 609 | |||
| 610 | my $filename = $dialog->GetPath; | ||
| 611 | $self->{_directory} = $dialog->GetDirectory; | ||
| 612 | |||
| 613 | $self->LoadFile($filename); | ||
| 614 | } | ||
| 615 | |||
| 616 | sub OnCloseFile { | ||
| 617 | my ($self, $event) = @_; | ||
| 618 | |||
| 619 | $self->{_list1}->Clear; | ||
| 620 | $self->{_list2}->Clear; | ||
| 621 | $self->{_text}->Clear; | ||
| 622 | $self->{_registry} = undef; | ||
| 623 | $self->{_find_iter} = undef; | ||
| 624 | $self->SetTitle("Registry Scope"); | ||
| 625 | } | ||
| 626 | |||
| 627 | sub OnQuit { | ||
| 628 | my ($self) = @_; | ||
| 629 | |||
| 630 | $self->Close; | ||
| 631 | } | ||
| 632 | |||
| 633 | |||
| 634 | package ScopeApp; | ||
| 635 | |||
| 636 | use Wx qw(:everything); | ||
| 637 | |||
| 638 | use base qw(Wx::App); | ||
| 639 | |||
| 640 | sub OnInit { | ||
| 641 | my ($self) = @_; | ||
| 642 | |||
| 643 | my $frame = ScopeFrame->new(undef); | ||
| 644 | $frame->Show; | ||
| 645 | |||
| 646 | return 1; | ||
| 647 | } | ||
| 648 | |||
| 649 | |||
| 650 | package main; | ||
| 651 | |||
| 652 | my $app = ScopeApp->new; | ||
| 653 | $app->MainLoop; |