Nmap Development mailing list archives
Re: Detecting/parsing a hex string
From: Brandon Enright <bmenrigh () ucsd edu>
Date: Wed, 8 Oct 2008 16:20:04 +0000
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, 08 Oct 2008 06:25:03 -0500 or thereabouts Ron <ron () skullsecurity net> wrote:
Hi all, I need to detect whether or not a string is an ascii representation of a hex string (eg, "12ab3d1a3badabeea1...."), and, if it is, to convert it to a binary string. Is there an easy way to do that (maybe with bin.pack/bin.unpack)? Thanks, Ron
You'll want to use a regex first to make sure the string is well formed. You can then use the 'H*' format string to unpack. It isn't Lua but here is the regex and unpack: $hex_string =~ /(?:[0-9A-Fa-f]{2})+/ $raw = unpack('H*', $hex_string); # If there is a B* format to pack we can convert our string to 0101... $bin_string = pack('B*', $hex_string); I hope that at least gets you started. Brandon -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAkjs3boACgkQqaGPzAsl94JknQCbBIKG+VpE8YAxYB6cIsyMrMSu tVcAnRocVa9n7aRB0u5gBppJe7s46daf =g7TK -----END PGP SIGNATURE----- _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- Detecting/parsing a hex string Ron (Oct 08)
- Re: Detecting/parsing a hex string Brandon Enright (Oct 08)
- Re: Detecting/parsing a hex string Brandon Enright (Oct 08)
- Re: Detecting/parsing a hex string Patrick Donnelly (Oct 08)
- Re: Detecting/parsing a hex string David Fifield (Oct 08)
- Re: Detecting/parsing a hex string David Fifield (Oct 08)
- Re: Detecting/parsing a hex string Patrick Donnelly (Oct 08)
- Re: Detecting/parsing a hex string David Fifield (Oct 08)
- Re: Detecting/parsing a hex string David Fifield (Oct 08)
- Re: Detecting/parsing a hex string Brandon Enright (Oct 08)
- Re: Detecting/parsing a hex string Ron (Oct 08)
- Re: Detecting/parsing a hex string David Fifield (Oct 08)
- Re: Detecting/parsing a hex string Ron (Oct 08)
- Re: Detecting/parsing a hex string Brandon Enright (Oct 08)
- Re: Detecting/parsing a hex string David Fifield (Oct 08)