Regex 在Perl中从ELF文件读取数据
我需要从ELF文件或AXF文件读取数据,并在该文件中搜索数据并返回其地址。 在Linux中,我尝试了Regex 在Perl中从ELF文件读取数据,regex,perl,elf,Regex,Perl,Elf,我需要从ELF文件或AXF文件读取数据,并在该文件中搜索数据并返回其地址。 在Linux中,我尝试了objdump-t filename.axf | grep search_string,得到了结果 如何在Perl中实现这一点。我也尝试过Parse::Readelf,但没有成功。 提前感谢。您可以使用 你好,c: #include <stdio.h> int main() { printf("Hello world!\n"); } gcc -g hello.c -o he
objdump-t filename.axf | grep search_string
,得到了结果
如何在Perl中实现这一点。我也尝试过Parse::Readelf,但没有成功。
提前感谢。您可以使用
你好,c:
#include <stdio.h>
int main() {
printf("Hello world!\n");
}
gcc -g hello.c -o hello
use feature qw(say);
use strict;
use warnings;
use Binutils::Objdump (); # Seems like this module is missing Exporter interface!??
my $search_string = 'hello.c';
Binutils::Objdump::objdumpopt('-t');
Binutils::Objdump::objdumpwrap("SYMBOL TABLE" => sub { mysymtab( $search_string, @_ ) });
Binutils::Objdump::objdump('hello');
sub mysymtab {
my ($search_string, @lines) = @_;
for my $line (@lines) {
say $line if $line =~ /\Q$search_string\E/;
}
}
objdump.pl:
#include <stdio.h>
int main() {
printf("Hello world!\n");
}
gcc -g hello.c -o hello
use feature qw(say);
use strict;
use warnings;
use Binutils::Objdump (); # Seems like this module is missing Exporter interface!??
my $search_string = 'hello.c';
Binutils::Objdump::objdumpopt('-t');
Binutils::Objdump::objdumpwrap("SYMBOL TABLE" => sub { mysymtab( $search_string, @_ ) });
Binutils::Objdump::objdump('hello');
sub mysymtab {
my ($search_string, @lines) = @_;
for my $line (@lines) {
say $line if $line =~ /\Q$search_string\E/;
}
}
对于临时脚本,您可以简单地执行以下操作
my $search_str = 'minor';
for (grep {chop; s/.*(0x[0-9a-f]+\s+\S*$search_str\S*)$/$1/x} `objdump -t a.exe`) {
my ($addr, $name) = split / +/;
print "$name: $addr\n";
}