flat assembler
Message board for the users of flat assembler.

flat assembler > Heap > How do I use plain text binaries to convert to real files?

Author
Thread Post new topic Reply to topic
special-U



Joined: 26 Jul 2018
Posts: 12
Hi.

I have a .txt with 0 and 1, these binaries form a jpg image, how do I do it?
Post 25 Aug 2018, 22:57
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16128
Location: Hyperborea
Please show us some sample data. It is hard to know what you have.
Post 25 Aug 2018, 23:32
View user's profile Send private message Visit poster's website Reply with quote
Coty



Joined: 17 May 2010
Posts: 545
Location: ␀
Well I guess you could just take ASCII 0 and 1s and put them into 8bit groups, fill them into a buffer and write them out as a JPEG... Of course that's assuming that the header and everything is still there and that it is just ASCII representation of binary numbers...

If it's physically still binary thanI guess you could rename it to .JPG?

_________________
http://codercat.info/
http://codercat.org/
Post 26 Aug 2018, 21:14
View user's profile Send private message Send e-mail Visit poster's website AIM Address Reply with quote
special-U



Joined: 26 Jul 2018
Posts: 12
Coty wrote:
Well I guess you could just take ASCII 0 and 1s and put them into 8bit groups, fill them into a buffer and write them out as a JPEG... Of course that's assuming that the header and everything is still there and that it is just ASCII representation of binary numbers...

If it's physically still binary thanI guess you could rename it to .JPG?


That's what I've done and it worked, but I don't understand, exist to software that extracts 0 and 1 in plain text? or do you think it was a manual process?

If you know, please tell me how to do it.
Post 31 Aug 2018, 01:41
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7001
Location: Kraków, Poland
You can even do it with fasm or fasmg, with a script like:
Code:
format binary as 'jpg'

virtual at 0
        Text:: file 'input.txt'
        .length = $
end virtual

BIG_ENDIAN_BYTES = 1

CURRENT_BYTE = 0
BIT_COUNT = 0

repeat Text.length
        load CHAR byte from Text:%-1
        if CHAR = '1' | CHAR = '0'
                if BIG_ENDIAN_BYTES
                        CURRENT_BYTE = CURRENT_BYTE shl 1 + CHAR and 1
                else
                        CURRENT_BYTE = CURRENT_BYTE + (CHAR and 1) shl BIT_COUNT
                end if
                BIT_COUNT = BIT_COUNT + 1
        end if
        if BIT_COUNT = 8
                db CURRENT_BYTE
                CURRENT_BYTE = 0
                BIT_COUNT = 0
        end if
end repeat    
The details of a script would depend on the format of text. You gave no sample, so I made a guess that it might be a big endian byte-unit format. There is a constant that you could switch in the script to use corresponding little-endian format.
Post 31 Aug 2018, 13:27
View user's profile Send private message Visit poster's website Reply with quote
Coty



Joined: 17 May 2010
Posts: 545
Location: ␀
special-U wrote:
That's what I've done and it worked, but I don't understand, exist to software that extracts 0 and 1 in plain text? or do you think it was a manual process?

If you know, please tell me how to do it.


I've used hex editors in the past that would display binary as well and would even let you export plain text of the hex and/or binary, I'd imagine it was created like that. I can't recall what specific editor it was, but I think it could have been a command line utility.

_________________
http://codercat.info/
http://codercat.org/
Post 31 Aug 2018, 15:49
View user's profile Send private message Send e-mail Visit poster's website AIM Address Reply with quote
special-U



Joined: 26 Jul 2018
Posts: 12
Tomasz Grysztar wrote:
The details of a script would depend on the format of text. You gave no sample, so I made a guess that it might be a big endian byte-unit format. There is a constant that you could switch in the script to use corresponding little-endian format.

Thank you very much your program was very useful.

Who might be interested in this, I upload my .txt with the plain text binaries.
https://mega.nz/#!2pADDILb!Xmp-DhCN_tvOThvqfys-XG2cI6Q2Jph8VVBOFWgqnYA
Coty wrote:
I've used hex editors in the past that would display binary as well and would even let you export plain text of the hex and/or binary, I'd imagine it was created like that. I can't recall what specific editor it was, but I think it could have been a command line utility.

Well I didn't have any automatic option to Binary, I used Winhex and saved the Hexadecimal in a .txt then I made a program in Python and converted the Hexadecimal text to Binary.
But Winhex didn't convert to Binary, at least I didn't find that option but it doesn't matter anymore.

I have a question, for fun, if everything is 0 and 1 how could I make the PC interpret an .mp3 as a .jpg? it would be interesting to see what appears.
Post 31 Aug 2018, 19:14
View user's profile Send private message Reply with quote
special-U



Joined: 26 Jul 2018
Posts: 12
Tomasz Grysztar wrote:
You can even do it with fasm or fasmg, with a script like:


Hi.

Sorry to bother you again but could you please help me with a FASM code to convert from hexadecimal to the original file?

I would be very grateful.
Post 19 Nov 2018, 21:07
View user's profile Send private message Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 133
subtract ascii 30h then sum each 8bit and convert them to hex, write to it a buffer then simple create a file and write buffer contents.
(remember its binary-in-hex form ... so its must be converted to real hex)

_________________
Asm For Wise Humans
Post 22 Nov 2018, 00:04
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.