School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,368 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,443 people online right now. Registration is fast and FREE... Join Now!




binmode input problem!

 

binmode input problem!, cant figure how to put hex in file!

evolivid

28 Jun, 2009 - 06:39 PM
Post #1

New D.I.C Head
*

Joined: 24 Jul, 2008
Posts: 35


My Contributions
I have been using the binmode and it works
good at printing hex out from the buffer

but when i try to put hex in it doesnt work?

How can I use perl to dump hex code into
a file with out the lengthy debug hell that awaits
all failed attempts ....

i want to put this

CODE

6678689887a8b7baba9c53a548c6776c78a6834c99 2 3d 4
76789e95e98a9b8baba5c63a649c7887c89a7363c5 5 1c 2
a56789495998a9b883ba5c63a549c7887c89a7933c 2 ad 6
c66784dac65a9bac9c8cb6573b74a5899859ab8373 3 1b 4
d67789abdb7bbacb3a373c7685c84b59aa96abc955 4 7c 8
4567759aeb67bbac73a3c4c2685d87d69aa96abce5 1 1d 3
75567789abab7bbacb3a3c3c7685c84b69ae96abc9 8 84 10


into the D:/testing.dat so that when i look at debug
it looks just like that !

heres what I have tried

CODE


open(FILE, ">D:/testing.dat");
$_ = select(FILE);
binmode(FILE);

while (this) { printstuff }
close FILE;




CODE


open(FILE, ">D:/testing.dat");
$_ = select(FILE);
binmode(FILE, ":raw");

while (this) { printstuff }
close FILE;





that prints it to the file but not correctly...
it doesn't put the hex in like you get from
the output binmode!

do I have to format it and use a buffer to put into the
file ... and how could i do that correctly
i haven't seen any thing like that
and I have about 30 perl books!


please help!

This post has been edited by evolivid: 28 Jun, 2009 - 08:08 PM

User is offlineProfile CardPM
+Quote Post


KevinADC

RE: Binmode Input Problem!

28 Jun, 2009 - 06:50 PM
Post #2

D.I.C Regular
Group Icon

Joined: 23 Jan, 2007
Posts: 401



Thanked: 25 times
Dream Kudos: 50
My Contributions
I'm not sure how to do what you are asking. If you get no replies here try asking on www.stackoverflow.com using a perl tag. You can also try www.perlmonks.com
User is offlineProfile CardPM
+Quote Post

evolivid

RE: Binmode Input Problem!

28 Jun, 2009 - 07:02 PM
Post #3

New D.I.C Head
*

Joined: 24 Jul, 2008
Posts: 35


My Contributions
im thinking I coulds use chr($_) to change most of the information
into characters but i need to use all 256 hex types
and perl lets you use only 127

This post has been edited by evolivid: 28 Jun, 2009 - 07:13 PM
User is offlineProfile CardPM
+Quote Post

evolivid

RE: Binmode Input Problem!

28 Jun, 2009 - 10:19 PM
Post #4

New D.I.C Head
*

Joined: 24 Jul, 2008
Posts: 35


My Contributions


well i did the coding to use the utf-8 to put the hex in the but guess what
when you go to look at debug the hex that you had is not the same
now there are a bunch of zeros and i didnt even use a zero or a one
its like the characters a effecting each other and changing each other
or there is some kind of wired obfuscating going on?

User is offlineProfile CardPM
+Quote Post

dsherohman

RE: Binmode Input Problem!

29 Jun, 2009 - 03:18 AM
Post #5

D.I.C Head
**

Joined: 29 Mar, 2009
Posts: 184



Thanked: 35 times
My Contributions
The code you've written is writing out the data to the file in raw binary format, giving you a file whose contents are exactly the same as its in-memory representation.

If I understand correctly, you're saying that what you want to do is write the data out as formatted text with each byte of the raw data represented by the pair of hexadecimal digits corresponding to the actual value of the byte. (e.g., For the letter "A" you want the file to contain "41" rather than "A".)

To do this conversion, you'll probably want to use the 'unpack' command. A quick CPAN search also turned up Data::HexDump and Data::Translate, which look like they may provide an easier way of doing it.
User is offlineProfile CardPM
+Quote Post

evolivid

RE: Binmode Input Problem!

11 Jul, 2009 - 10:37 PM
Post #6

New D.I.C Head
*

Joined: 24 Jul, 2008
Posts: 35


My Contributions
NO what im trying to do is this

if the text says af231424ac then when I save it to a file I want the hex to look like this

1301:0100 af 23 14 24 ac
1301:0110

in debug "get the picture" ! the only way I see to do this is to
have perl use
CODE

system("debug < file")


and have the file formatted so that it works with debug ... the only thing is I feel there should be a better way to do this besides using debug to do it ...

This post has been edited by evolivid: 11 Jul, 2009 - 10:59 PM
User is offlineProfile CardPM
+Quote Post

dsherohman

RE: Binmode Input Problem!

12 Jul, 2009 - 02:34 AM
Post #7

D.I.C Head
**

Joined: 29 Mar, 2009
Posts: 184



Thanked: 35 times
My Contributions
QUOTE(evolivid @ 12 Jul, 2009 - 06:37 AM) *

NO what im trying to do is this

if the text says af231424ac then when I save it to a file I want the hex to look like this

1301:0100 af 23 14 24 ac
1301:0110


So I had your intention backwards, and (to use my earlier example) you want the input "41" to result in an "A" being written to the output file, which will then be displayed as the original "41" when viewed in a hex dump? (I'm not familiar with the "debug" program you're referring to, but this example of its output looks like a typical hex dump.)

In that case, you'd use "pack" to convert the hexadecimal representations to their corresponding byte values:
CODE
$ perl -e 'print pack "H*", "af231424ac"' > test.bin
$ cat test.bin; echo
Ø#$¨
$ hexdump test.bin
0000000 af23 1424 ac00                        
0000005

User is offlineProfile CardPM
+Quote Post

evolivid

RE: Binmode Input Problem!

12 Jul, 2009 - 08:39 PM
Post #8

New D.I.C Head
*

Joined: 24 Jul, 2008
Posts: 35


My Contributions
Debug is a windows .exe program to look at registers and hex dumps and assemble.

Much Thankx Bro , and from the command line too, your too cool!

How do I give you kudos points let me know and consider it done?

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 08:55PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month