Computing.Net > Forums > Programming > Perl : converting .elf (binary) to .txt file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Perl : converting .elf (binary) to .txt file

Reply to Message Icon

Name: Suba
Date: September 30, 2009 at 10:52:08 Pacific
OS: Windows XP
Subcategory: Opinions
Comment:

I am writing a Perl script to convert a .elf file to .txt (Hexadecimal file) file but It is failing in a initial state?
Actual program going to convert a .elf to .txt file format with 80 character in a line something like this

12345678 12345678 12345678 12345678 12345678 12345678 12345678 12345678

If the .txt would reach 1GB then stop the conversion and exit.
Can somebody help me? Am I using “pack” correctly?


#!/usr/bin/perl
use strict;


my @in;
my $out;
my $x;
my $y;
my $inputfile;
my $outputfile;

$inputfile = $ARGV[0];
$outputfile = $ARGV[1];
open(INPUT, "<$inputfile") || die "Error: unable to open $inputfile - $!\n";
@in = <INPUT>;
close(INPUT);
if (!@in) {
print("Error: no data in $inputfile\n");
exit(1);
}

open(OUTPUT, ">$outputfile") || die "Error: unable to open $outputfile - $!\n";
for($x=0; $x<=$#in; $x = $x + 32) {
for ($y = 0; $y < 32; $y++ ) {
$out = pack("a4", $in[$y]);
#$out = unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
print OUTPUT $out;
}
print(OUTPUT "\n");

}



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Perl : converting .elf (binary) to .txt file

Perl : converting .elf (binary) to .txt file www.computing.net/answers/programming/perl-converting-elf-binary-to-txt-file/20052.html

Webpage content to TXT file www.computing.net/answers/programming/webpage-content-to-txt-file/14510.html

Convert .dll to .lib file www.computing.net/answers/programming/convert-dll-to-lib-file/9755.html