Skip to content

Instantly share code, notes, and snippets.

@CReimer
Created September 11, 2016 12:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CReimer/d8de01aa1bf2a0e097fc021829976730 to your computer and use it in GitHub Desktop.
Save CReimer/d8de01aa1bf2a0e097fc021829976730 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
open (my $fh, "<", "Win10_USB-BT400_Driver_Package/64/bcbtums-win8x64-brcm.inf");
my $data;
while (<$fh>) {
$data .= $_;
}
$data =~ s/\r//g;
my %index;
foreach my $line ($data =~ /(^.*?USB\\VID.*?$)/gm) {
# print Dumper($line);
my ($link, $vid, $pid) = $line =~ /%=(.*?),.*?USB\\VID_(.*?)&PID_(.*?) /;
next unless $link;
$index{$link} = { } unless $index{$link};
$index{$link}{"$vid:$pid"} = 1;
}
my %copylist;
foreach my $link (keys(%index)) {
(my $block) = $data =~ /\[$link.NTamd64\]\n(.*?)\n\n\[/s;
(my @temp) = $block =~ /^CopyFiles=(.*?)$/gm;
$copylist{$link} = \@temp;
}
my %final;
foreach my $key (keys(%copylist)) {
foreach my $single (@{$copylist{$key}}) {
(my $block) = $data =~ /\[$single\]\n(.*?)\n\n\[/s;
next unless $block;
(my $hex) = $block =~ /^(.*?\.hex)$/m;
next unless $hex;
my @temp = keys(%{$index{$key}});
$final{$temp[0]} = $hex;
}
}
foreach my $key (keys(%final)) {
print "$key: $final{$key}\n";
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment