Perl script to read Hex from files
I"m trying to pull certain data out of a hex file using perl. And I am so hoping there is a shortcut or two.
What I would love to do is read certain data for example: address: 0x00000022 Address: 0x00000024 address: 0x00000261 to 0x00000264 address: 0x00000265 to 0x00000268 address: 0x00000269 to 0x00000272 and turn those into vars that are outputted. Is there a subroutine where I can send it the address(es) and it would return the value from it? |
Please take a look at the output of
Quote:
Quote:
Code:
#!/usr/bin/perl |
Thanks for the reply, I'm not sure I quite understand what you are doing for me to make sense of it.
What I tried doing was opening a file, converting to hex and using substr to pull the location, but pulling the location isn't working and I'm not sure how to make it work. I had thought this would be as easy or would have a toon of code doing what I was looking for as it is used often. And people seam to always refence hex code w/ locations values based 0x0. This is a subset of opening file, converting to hex, then attempting to get the addresses. Code:
$hexfile=&HEX_VIEW(); |
think I have the location part working, I just find it odd that I have to do this, rather than there being an easier way to deal with hex.
Code:
sub HEX_ADDY{ |
Quote:
Quote:
that you meant to extract some hex digits, as indicated by an offset value (relative to the beginning of the not-yet-encoded bytes read from the input file). I am getting the Impression that You are learning Perl from some seriously outdated tutorials/documentation. This is hurting You!! Please consider to use the Book "Modern Perl" by chromatic, which can had for free as a PDF file. Always use strict; in your perl code (except perhaps for one-liners). Also try to get help from Perl::Critic. Okay, back to Your code. I have tried to refactor it into something I could debug, then I have added an alternative code path and some comments explaining what I think Your codes problem is. Please read and run this, both code paths: Code:
#!/usr/bin/perl perl file_hex_extract.pl file_hex_extract.pl I hope I understood Your intentions right this time. |
All times are GMT -5. The time now is 02:26 AM. |