Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some good resources for learning binary and using PHP with binary?

Tags:

binary

I want to learn to parse certain files (such as MPQ) and I need to learn binary and how to handle it with PHP. Could you guys please kindly suggest me resources for learning such things ( books, anything)?

Edit: I have tried unpacking the file before, but all the numbers just looks like gibberish to me and I do not know how to comprehend it and move forward.

like image 857
Strawberry Avatar asked Aug 07 '26 23:08

Strawberry


2 Answers

  1. The first thing you need to do before working on any binary format is to read format specification (eg MPQ). Because every binary format has different structure and there is no tools to read them all.
    1a. If it closed format there may be not specification at all, so you need to reverse-engineer it on your own. It's complicated, but you may try to read some public course.

  2. Some of them are compressed, so you need to learn how to decompress it, in most cases, some public available compression format used and you only need to find proper extension for your language.

  3. Then you should create structures in your language, that matching packed structures in binary format (open file in binary mode b and use pack/unpack functions).

  4. And the last one is to release your tools in community, so no one needs to make the same work twice :)

like image 85
Andrew Avatar answered Aug 11 '26 09:08

Andrew


If you are opening the binary file in what is known as a "Hex Editor", you will need to understand hexadecimal. The wikipedia page is very good at explaining it, and there is a wonderful conversion chart.

http://en.wikipedia.org/wiki/Hexadecimal

From the wikipedia page:

0hex    =   0dec    =   0oct        0   0   0   0   
1hex    =   1dec    =   1oct        0   0   0   1   
2hex    =   2dec    =   2oct        0   0   1   0   
3hex    =   3dec    =   3oct        0   0   1   1   
4hex    =   4dec    =   4oct        0   1   0   0   
5hex    =   5dec    =   5oct        0   1   0   1   
6hex    =   6dec    =   6oct        0   1   1   0   
7hex    =   7dec    =   7oct        0   1   1   1   
8hex    =   8dec    =   10oct       1   0   0   0   
9hex    =   9dec    =   11oct       1   0   0   1   
Ahex    =   10dec   =   12oct       1   0   1   0   
Bhex    =   11dec   =   13oct       1   0   1   1   
Chex    =   12dec   =   14oct       1   1   0   0   
Dhex    =   13dec   =   15oct       1   1   0   1   
Ehex    =   14dec   =   16oct       1   1   1   0   
Fhex    =   15dec   =   17oct       1   1   1   1
like image 21
Dlongnecker Avatar answered Aug 11 '26 09:08

Dlongnecker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!