[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 34 KB, 639x529, hex.jpg [View same] [iqdb] [saucenao] [google]
2423149 No.2423149 [Reply] [Original]

How do I take a file that's in ASCII and turn it into hex? For example, let's say I have a file like this:

\x00\x00\x00\x00\x00\x00\x00\x00

The problem is the '\', 'x', and '0' chars are just that: chars, and not hex. How can I fix this?

>> No.2423168

>>2423149

you realize that inside the thinking portion of the computer all the ascii characters are already in binary/hexidecimal/octal...

right?

I mean, you knew that, didn't you?

>> No.2423175

durr, encode them into their ASCII number counterparts. Then convert those into hex numbers.

http://en.wikipedia.org/wiki/File:ASCII_Code_Chart.svg

Matter of fact, just skip the conversion, the chart is in hex.

>> No.2423192

>>2423175
>>2423168
Perhaps I wasn't clear in my original post. What I had was basically a huge file of escaped hex sequences in ASCII form (though not necessarily human readable -- it's a binary). I wanted to disassemble this to look at its assembly, but the escaped hex sequences weren't actually hex -- they were ASCII chars, which made disassembly impossible.

>> No.2423202

>>2423192
So you're asking how to parse \xXX hex sequences? This is so simple that if you have to ask, you're not ready. It can't get any simpler than that. (Protip: every hex sequence in your case is four characters long.)

>> No.2423213

>>2423202
Well, in the time since posting this question and my first reply, I had already figured it out :\ Also, based on your hint, I'm pretty sure you have no idea what I'm actually trying to do.

>> No.2423229

>>2423213
Then perhaps you should explain yourself better.

>> No.2423245

Obviously, this is easy to do if you know any programming language or scripting language. But I feel like there's a way to do this with tools that use regular expressions or something to parse and manipulate files. Maybe I'm wrong.

>> No.2423256

>>2423245
yeah, i decided to write up a script in python. basically, you just have to read in the entire file, then take each hex substring, convert to int, then print chr'ed result to the file. pretty simple.

>> No.2423257

>>2423192

you want to disassemble a program?

there's a really old program for reverse engineering assembled programs - it doesn't (can't) retrieve the original nametags but it DOES mark where the nametags/calls are so that you can see the original intent of the program's flow.

I think it was called mastrkey.com (or something close). it'll disassemble any program. I had a copy on 5.25" floppy (remember those?) but i looked for it about a year ago on the net and was told that it's illegal now because it is a tool that allows for reverse engineering.

damn them. take the fun out of this stuff...

besides, you might want to check on /g/ - that should be where the programmers hang.

>> No.2423371

>>2423202
Actually, having written the script, I see what you're talking about now. I had misinterpreted your statement to mean that each line of hex, which is clearly 8 chars, is 4 chars. Guess I'm just having a bad day today :\

>> No.2423463

Goddammit. So I converted it to hex and now I'm looking at it in a hex editor. But it still won't disassemble, I guess because it's missing headers or something. If anyone's curious, I'm basically looking at this:

http://www.jwz.org/

You'll notice the first word starts at address 0x0024640. Apparently there's some secret hidden in the hex, but I'm too much of a noob to figure it out myself :\

>> No.2423773
File: 281 KB, 747x748, sshot-57.jpg [View same] [iqdb] [saucenao] [google]
2423773

>>2423463
Now I'm even more confused. Where are you getting the \x00\x00\x00 from? Isn't the pic what you're trying to decode?

>> No.2423787
File: 400 KB, 958x964, sshot-58.jpg [View same] [iqdb] [saucenao] [google]
2423787

Now I'm even more confused? Isn't this what you're trying to decode? Where do you get the \x00\x00\x00?

>> No.2423825

>>2423787
Some interpreters throw in a \x, 0x or something similar between hex defined bytes, just to make clear that the data is in hex.

>> No.2423832

>>2423463
no idea why you use the word disassemble, but I guess you should use IDA for what you are trying to do.

>> No.2423841

>>2423773
i cleaned up the file before parsing it by regex replacing a bunch of shit, including html tags, &ampltgt; bullshit. then i wrote a python script trying to replace all spaces with '\x', but it gave me some bullshit invalid modifier error, so i replaced them instead with r'\x', hoping that by piping it to the file (instead of just directly writing the string), the hex shit would sort itself out. it didn't, and i had to write up another script that converted each 2 byte hex string to an int, then to a char before printing it back to the file.

still have no idea how to disassemble it though.

>> No.2423845

>>2423832
well, it's binary data, and i want to pull the assembly out of it. i don't know the proper word for that (decompile?)

>> No.2423858

>>2423845
disassemble =into assembly
decompile=into src
maybe post original file and tell us what exactly you need ?

>> No.2423859
File: 40 KB, 435x480, skeptical.jpg [View same] [iqdb] [saucenao] [google]
2423859

>>2423845

>> No.2423874

>>2423859
you know what i fucking mean. binary data is just machine code. assembly is compiled into machine code via an assembler. hence, i disassemble.

>> No.2423888
File: 16 KB, 612x550, instruction_set.gif [View same] [iqdb] [saucenao] [google]
2423888

>>2423874 binary data is just machine code

No. Binary data is any type of computer data for storing any type of information unless you've got a rare trit based system. It doesn't stop being binary when you choose to interpret it as letters or coded decimals.

Right now you've got a hex file you want to convert to assembly.

Look up the instruction set opcodes for whatever processor this hex file was written for and convert it back to asm.

>> No.2423905

>>2423888
>It doesn't stop being binary when you choose to interpret it as letters or coded decimals.
Yeah, but for executables, binary essentially means machine code.

>Look up the instruction set opcodes for whatever processor this hex file was written for and convert it back to asm.
But that's extremely tedious. Isn't there an easier way? Can't I just modify the first couple of bytes of the file to make it look like machine code, then use objdump?

>> No.2423913

>>2423905
If it's a unix executable then yes. You didn't specify what this hex file was created for and every architecture has its own personal instruction set.

>> No.2423917

>>2423845
How do you even know that it's an executable? It could be image data or a compressed archive or any number of things.

>> No.2423935

>>2423917
My posts aren't showing up, but this. Why do you think it's an executable? Could be pic or audio. It looks like data to me. Lots of FF FF FF's.