Resource for binary programming

I searched all over the Internet for programming in Binary, and the only answers that I think are ready to give are: "Why do you need to program in Binary?" "This is stupid, use assembly." "There you could not get out of this, it makes no sense to learn."

If you are one of these people, I appreciate your opinion, but it does not answer my question.

As long as I don't intend to actually try to program in binary, my reasons to know:

  • I have an interest in knowing binary instructions for build commands.

  • I am developing an experiment in which random binary instructions are generated. I want them to be valid binary commands, and I want to be able to interpret what these commands will do at startup.

With that said, does anyone know of a resource where you could learn binary programming?

+4
source share
5 answers

In general, there is a one-to-one mapping between assembly instructions and machine code (which you call binary). These mappings can be found in the documentation for the instruction set architecture for any machine you care about. Popular examples:

You can find a similar document for any architecture you want to work with. You can use the information in the manuals, for example, to decode the machine instructions for a given program and determine how they were created from the build source, or perhaps manually build your own program if you want.

+6
source

Here is what I did to find out the binary: 1. Open a command prompt and enter "debug" as a command.

  • enter "a" after "-".
  • start programming in the assembly (make sure that the commands you use are quite general, for example, moving registers that only execute one command.)
  • type in nothing and press enter when done.
  • type 'd' to find out what binary files are, and cross-reference several programs.

note that for programming in a real binary you will need a hex editor. Here is the one I'm using:

http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm

Another idea that I am doing to learn more complex languages ​​(like C ++) does the same thing as assembly, but open it in a hex editor.

+2
source

Instructions for a set of instructions are very useful and require a certain degree of knowledge about the architecture of computer hardware. Here are some sample documents:

ARM: http://simplemachines.it/doc/arm_inst.pdf

Intel: http://www.intel.com/content/dam/doc/manual/64-ia-32-architectures-software-developer-vol-1-2a-2b-3a-3b-manual.pdf

SPARC V9: http://www.sparc.com/standards/SPARCV9.pdf

+1
source

Good, like an old hack that has been doing this since binary days :-)

Let me try to make it more readable.

Binary, as you describe, is what is called machine code.

To do this further, the CPU is hardcoded to answer some instructions, for example (please keep in mind that at the moment I have no hand references)

A9 value in machine code 6502 means LDA (on other architectures, this may mean something else)

therefore, if you are running on a 6502 processor, then the sequence A920 will mean loading the battery with a hex value of 0f 0x20.

Depending on the CPU in question and how the instruction set is encoded, different bits in number will cause the CPU (which is pure logic deep down) to perform different operations.

And, depending on manufacturers specifications, different bit positions determine what each operation is.

For example, in the processor of the manipulator, bits 30 and 31 are the branch specifier, where, as in 6502, they are a zero-page memory indicator.

In fact, the binary instructions relate to the processor in question and are usually not transferred to another CPU (or, for that matter, any other intelligent silicon device), as a result, the transfer and recording software is generally a very difficult task if You do not have a deep knowledge of the chips in your programming.

If you are not working with a company such as Intel or a chip producer, then these days there is no need to know this material. However, if your fast addict wants to hit metal and squeeze every last drop of productivity, you can still get the tools to do this kind of programming.

+1
source

Great answers. I just wanted to add a simple script for those using linux that shows a binary representation of any command. You need a copy of NASM (but you can easily edit it to use GAS or any other assembler) and objdump:

echo "$1" > testProgram.asm nasm testProgram.asm -o testProgram.out -f elf -g chmod 744 testProgram.out objdump ./testProgram.out -d -M intel | grep ' 0:' rm testProgram.out testProgram.asm 

Here are some examples:

 blackbear@blackbear-laptop :~$ ./viewOpcode.sh "add ecx, 5" 0: 81 c1 05 00 00 00 add ecx,0x5 blackbear@blackbear-laptop :~$ ./viewOpcode.sh "int 0x80" 0: cd 80 int 0x80 blackbear@blackbear-laptop :~$ ./viewOpcode.sh "fmul st0, st1" 0: d8 c9 fmul st,st(1) blackbear@blackbear-laptop :~$ ./viewOpcode.sh "andps xmm0, xmm1" 0: 0f 54 c1 andps xmm0,xmm1 blackbear@blackbear-laptop :~$ ./viewOpcode.sh "movntq [edi], mm0" 0: 0f e7 07 movntq QWORD PTR [edi],mm0 blackbear@blackbear-laptop :~$ 
+1
source

Source: https://habr.com/ru/post/1379709/


All Articles