LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-27-2011, 05:54 PM   #1
boxerfangg
LQ Newbie
 
Registered: Jul 2011
Posts: 1

Rep: Reputation: Disabled
Is it possible to execute a raw binary file on linux?


I want to know if it is possible to execute a raw binary file in linux. By raw binary I mean binary that the processor executes. Not ELF.

Here is the code in asm:
Code:
org 100h

; set video mode    
mov ax, 3     ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3)
int 10h       ; do it!

; cancel blinking and enable all 16 colors:
mov ax, 1003h
mov bx, 0
int 10h


; set segment register:
mov     ax, 0b800h
mov     ds, ax

; print "hello world"
; first byte is ascii code, second byte is color code.

mov BYTE [02h], 'H'

mov BYTE [04h], 'e'

mov BYTE [06h], 'l'

mov BYTE [08h], 'l'

mov BYTE [0ah], 'o'

mov BYTE [0ch], ','

mov BYTE [0eh], 'W'
 
mov BYTE [10h], 'o'

mov BYTE [12h], 'r'

mov BYTE [14h], 'l'

mov BYTE [16h], 'd'

mov BYTE [18h], '!'




; color all characters:
mov cx, 12  ; number of characters.
mov di, 03h ; start from byte after 'h'

c:  mov BYTE [di], 11101100b   ; light red(1100) on yellow(1110)
    add di, 2 ; skip over next ascii code in vga memory.
    loop c

; wait for any key press:
mov ah, 0
int 16h

ret
And here it the compile:
Code:
brandon@brandon-NC686AA-ABA-a6700y:~/Desktop$ nasm test -f bin -o test.bin
brandon@brandon-NC686AA-ABA-a6700y:~/Desktop$ chmod +x test.bin
brandon@brandon-NC686AA-ABA-a6700y:~/Desktop$ ./test.bin
bash: ./test.bin: cannot execute binary file
 
Old 07-27-2011, 07:15 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I recommend using the Report button to ask the Mods to move this to Programming for faster/better responses.
 
Old 07-27-2011, 07:42 PM   #3
dragos240
Member
 
Registered: Apr 2009
Posts: 64

Rep: Reputation: 15
You'll need a machine code parser I think.
 
Old 07-27-2011, 10:15 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
This is a bit dated, but may give you some insight

http://www.linux.it/~rubini/docs/binfmt/binfmt.html

Last edited by Tinkster; 07-27-2011 at 11:06 PM. Reason: network based duplication
 
Old 07-28-2011, 02:15 AM   #5
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
OK, Tinkster's article went over my head a little, but whatever it is, it deals with hacking the *kernel* to add more facilities to it. On a *standard* kernel, IMHO, you'll need your file to be in ELF format before the Linux program loader can make sense of it.
And, again, if I remember my details correctly, you cannot call the ROM in protected mode, so those "int 10"s won't work ANYWAY. Also, your "wait for a keypress" code - is that a DOS interrupt it's calling? That OBVIOUSLY won't work.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
./egather2-2.09.linux :cannot execute binary file brazinho Linux - General 2 09-07-2006 01:00 AM
Cannot execute binary file pbagda Linux - General 4 01-19-2004 01:13 AM
cannot execute binary file.... ttaylor Linux - General 4 10-02-2001 01:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration