Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.

bkotos/php-hexdump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ DEPRECATED

This repository is deprecated. Please see bkotos/hexdump instead.


php-hexdump

A PHP utility for dumping the bytes of a file or stream in hexadecimal, octal, or binary.

Usage

php-hexdump accepts a path argument representing the file it should read from. By default, the application dumps the data in base 16 (hexadecimal). However, flags exist for dumping data in base 2 (binary) and base 8 (octal).

php hexdump.php [-b,-o] <path>

-b
    Show data in binary

-o
    Show data in octal

Alternatively, php-hexdump can accept a binary stream from stdin:

cat <path> | php hexdump.php [-b,-o]

Example output

Hexadecimal:

$ php hexdump.php test.png
00000000: 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52  .PNG........IHDR
00000010: 00 00 00 19 00 00 00 19 08 06 00 00 00 c4 e9 85  ................
00000020: 63 00 00 01 85 69 43 43 50 49 43 43 20 70 72 6f  c....iCCPICC pro
00000030: 66 69 6c 65 00 00 28 91 7d 91 3d 48 c3 40 1c c5  file..(.}.=H.@..
00000040: 5f d3 96 8a 54 1c 2c 28 e2 90 a1 3a 59 10 15 11  _...T.,(...:Y...
00000050: 27 ad 42 11 2a 84 5a a1 55 07 93 4b bf a0 49 43  '.B.*.Z.U..K..IC
00000060: 92 e2 e2 28 b8 16 1c fc 58 ac 3a b8 38 eb ea e0  ...(....X.:.8...
00000070: 2a 08 82 1f 20 2e ae 4e 8a 2e 52 e2 ff d2 42 8b  *... ..N..R...B.
00000080: 18 0f 8e fb f1 ee de e3 ee 1d 20 d4 cb 4c b3 02  .......... ..L..
00000090: 63 80 a6 db 66 2a 11 17 33 d9 55 31 f4 8a 20 fa  c...f*..3.U1.. .
000000a0: 11 c0 0c 42 32 b3 8c 39 49 4a c2 73 7c dd c3 c7  ...B2..9IJ.s|...
000000b0: d7 bb 18 cf f2 3e f7 e7 e8 51 73 16 03 7c 22 f1  .....>...Qs..|".
000000c0: 2c 33 4c 9b 78 83 78 6a d3 36 38 ef 13 47 58 51  ,3L.x.xj.68..GXQ
000000d0: 56 89 cf 89 47 4d ba 20 f1 23 d7 95 26 bf 71 2e  V...GM. .#..&.q.
000000e0: b8 2c f0 cc 88 99 4e cd 13 47 88 c5 42 07 2b 1d  .,....N..G..B.+.
000000f0: cc 8a a6 46 3c 49 1c 55 35 9d f2 85 4c 93 55 ce  ...F<I.U5...L.U.
00000100: 5b 9c b5 72 95 b5 ee c9 5f 18 ce e9 2b cb 5c a7  [..r...._...+.\.
00000110: 39 84 04 16 b1 04 09 22 14 54 51 42 19 36 62 b4  9......".TQB.6b.
00000120: ea a4 58 48 d1 7e dc c3 3f e8 fa 25 72 29 e4 2a  ..XH.~..?..%r).*
00000130: 81 91 63 01 15 68 90 5d 3f f8 1f fc ee d6 ca 4f  ..c..h.]?......O
00000140: 8c 37 93 c2 71 20 f8 e2 38 1f c3 40 68 17 68 d4  .7..q ..8..@h.h.
00000150: 1c e7 fb d8 71 1a 27 80 ff 19 b8 d2 db fe 4a 1d  ....q.'.......J.
00000160: 98 fe 24 bd d6 d6 a2 47 40 ef 36 70 71 dd d6 94  ..$....G@.6pq...
00000170: 3d e0 72 07 18 78 32 64 53 76 25 3f 4d 21 9f 07  =.r..x2dSv%?M!..
00000180: de cf e8 9b b2 40 df 2d d0 bd d6 ec ad b5 8f d3  .....@.-........
00000190: 07 20 4d 5d 25 6f 80 83 43 60 a4 40 d9 eb 1e ef  . M]%o..C`.@....
000001a0: ee ea ec ed df 33 ad fe 7e 00 5a 2b 72 9d 56 0c  .....3..~.Z+r.V.
000001b0: 8a b3 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff  ......bKGD......
000001c0: a0 bd a7 93 00 00 00 09 70 48 59 73 00 00 2e 23  ........pHYs...#
000001d0: 00 00 2e 23 01 78 a5 3f 76 00 00 00 07 74 49 4d  ...#.x.?v....tIM
000001e0: 45 07 e3 05 17 05 03 35 22 7f 76 d1 00 00 00 19  E......5".v.....
000001f0: 74 45 58 74 43 6f 6d 6d 65 6e 74 00 43 72 65 61  tEXtComment.Crea
00000200: 74 65 64 20 77 69 74 68 20 47 49 4d 50 57 81 0e  ted with GIMPW..
00000210: 17 00 00 00 42 49 44 41 54 48 c7 63 60 a0 03 60  ....BIDATH.c`..`
00000220: 84 31 fe 33 30 fc c7 29 49 2c f8 8f d5 06 46 26  .1.30..)I,....F&
00000230: 7a f8 64 d4 12 f2 22 1e 67 b4 51 21 ea 47 e3 64  z.d...".g.Q!.G.d
00000240: d4 92 51 4b 46 2d 19 8a 96 b0 10 28 db fe 8f 06  ..QKF-.....(....
00000250: d7 f0 b4 84 2e 00 00 21 66 07 2e 6c e1 0c 22 00  .......!f..l..".
00000260: 00 00 00 49 45 4e 44 ae 42 60 82 00              ...IEND.B`..

Octal:

$ php hexdump.php -o test.png
00000000: 211 120 116 107 015 012 032 012 000 000 000 015  .PNG........
0000000c: 111 110 104 122 000 000 000 031 000 000 000 031  IHDR........
00000018: 010 006 000 000 000 304 351 205 143 000 000 001  ........c...
00000024: 205 151 103 103 120 111 103 103 040 160 162 157  .iCCPICC pro
00000030: 146 151 154 145 000 000 050 221 175 221 075 110  file..(.}.=H
0000003c: 303 100 034 305 137 323 226 212 124 034 054 050  .@.._...T.,(
00000048: 342 220 241 072 131 020 025 021 047 255 102 021  ...:Y...'.B.
00000054: 052 204 132 241 125 007 223 113 277 240 111 103  *.Z.U..K..IC
00000060: 222 342 342 050 270 026 034 374 130 254 072 270  ...(....X.:.
0000006c: 070 353 352 340 052 010 202 037 040 056 256 116  8...*... ..N
00000078: 212 056 122 342 377 322 102 213 030 017 216 373  ..R...B.....
00000084: 361 356 336 343 356 035 040 324 313 114 263 002  ...... ..L..
00000090: 143 200 246 333 146 052 021 027 063 331 125 061  c...f*..3.U1
0000009c: 364 212 040 372 021 300 014 102 062 263 214 071  .. ....B2..9
000000a8: 111 112 302 163 174 335 303 307 327 273 030 317  IJ.s|.......
000000b4: 362 076 367 347 350 121 163 026 003 174 042 361  .>...Qs..|".
000000c0: 054 063 114 233 170 203 170 152 323 066 070 357  ,3L.x.xj.68.
000000cc: 023 107 130 121 126 211 317 211 107 115 272 040  .GXQV...GM. 
000000d8: 361 043 327 225 046 277 161 056 270 054 360 314  .#..&.q..,..
000000e4: 210 231 116 315 023 107 210 305 102 007 053 035  ..N..G..B.+.
000000f0: 314 212 246 106 074 111 034 125 065 235 362 205  ...F<I.U5...
000000fc: 114 223 125 316 133 234 265 162 225 265 356 311  L.U.[..r....
00000108: 137 030 316 351 053 313 134 247 071 204 004 026  _...+.\.9...
00000114: 261 004 011 042 024 124 121 102 031 066 142 264  ...".TQB.6b.
00000120: 352 244 130 110 321 176 334 303 077 350 372 045  ..XH.~..?..%
0000012c: 162 051 344 052 201 221 143 001 025 150 220 135  r).*..c..h.]
00000138: 077 370 037 374 356 326 312 117 214 067 223 302  ?......O.7..
00000144: 161 040 370 342 070 037 303 100 150 027 150 324  q ..8..@h.h.
00000150: 034 347 373 330 161 032 047 200 377 031 270 322  ....q.'.....
0000015c: 333 376 112 035 230 376 044 275 326 326 242 107  ..J...$....G
00000168: 100 357 066 160 161 335 326 224 075 340 162 007  @.6pq...=.r.
00000174: 030 170 062 144 123 166 045 077 115 041 237 007  .x2dSv%?M!..
00000180: 336 317 350 233 262 100 337 055 320 275 326 354  .....@.-....
0000018c: 255 265 217 323 007 040 115 135 045 157 200 203  ..... M]%o..
00000198: 103 140 244 100 331 353 036 357 356 352 354 355  C`.@........
000001a4: 337 063 255 376 176 000 132 053 162 235 126 014  .3..~.Z+r.V.
000001b0: 212 263 000 000 000 006 142 113 107 104 000 377  ......bKGD..
000001bc: 000 377 000 377 240 275 247 223 000 000 000 011  ............
000001c8: 160 110 131 163 000 000 056 043 000 000 056 043  pHYs...#...#
000001d4: 001 170 245 077 166 000 000 000 007 164 111 115  .x.?v....tIM
000001e0: 105 007 343 005 027 005 003 065 042 177 166 321  E......5".v.
000001ec: 000 000 000 031 164 105 130 164 103 157 155 155  ....tEXtComm
000001f8: 145 156 164 000 103 162 145 141 164 145 144 040  ent.Created 
00000204: 167 151 164 150 040 107 111 115 120 127 201 016  with GIMPW..
00000210: 027 000 000 000 102 111 104 101 124 110 307 143  ....BIDATH.c
0000021c: 140 240 003 140 204 061 376 063 060 374 307 051  `..`.1.30..)
00000228: 111 054 370 217 325 006 106 046 172 370 144 324  I,....F&z.d.
00000234: 022 362 042 036 147 264 121 041 352 107 343 144  ..".g.Q!.G.d
00000240: 324 222 121 113 106 055 031 212 226 260 020 050  ..QKF-.....(
0000024c: 333 376 217 006 327 360 264 204 056 000 000 041  ...........!
00000258: 146 007 056 154 341 014 042 000 000 000 000 111  f..l.."....I
00000264: 105 116 104 256 102 140 202 000                  END.B`..

Binary:

$ php hexdump.php -b test.png
00000000: 10001001 01010000 01001110 01000111 00001101 00001010  .PNG..
00000006: 00011010 00001010 00000000 00000000 00000000 00001101  ......
0000000c: 01001001 01001000 01000100 01010010 00000000 00000000  IHDR..
00000012: 00000000 00011001 00000000 00000000 00000000 00011001  ......
00000018: 00001000 00000110 00000000 00000000 00000000 11000100  ......
0000001e: 11101001 10000101 01100011 00000000 00000000 00000001  ..c...
00000024: 10000101 01101001 01000011 01000011 01010000 01001001  .iCCPI
0000002a: 01000011 01000011 00100000 01110000 01110010 01101111  CC pro
00000030: 01100110 01101001 01101100 01100101 00000000 00000000  file..
00000036: 00101000 10010001 01111101 10010001 00111101 01001000  (.}.=H
0000003c: 11000011 01000000 00011100 11000101 01011111 11010011  .@.._.
00000042: 10010110 10001010 01010100 00011100 00101100 00101000  ..T.,(
00000048: 11100010 10010000 10100001 00111010 01011001 00010000  ...:Y.
0000004e: 00010101 00010001 00100111 10101101 01000010 00010001  ..'.B.
00000054: 00101010 10000100 01011010 10100001 01010101 00000111  *.Z.U.
0000005a: 10010011 01001011 10111111 10100000 01001001 01000011  .K..IC
00000060: 10010010 11100010 11100010 00101000 10111000 00010110  ...(..
00000066: 00011100 11111100 01011000 10101100 00111010 10111000  ..X.:.
0000006c: 00111000 11101011 11101010 11100000 00101010 00001000  8...*.
00000072: 10000010 00011111 00100000 00101110 10101110 01001110  .. ..N
00000078: 10001010 00101110 01010010 11100010 11111111 11010010  ..R...
0000007e: 01000010 10001011 00011000 00001111 10001110 11111011  B.....
00000084: 11110001 11101110 11011110 11100011 11101110 00011101  ......
0000008a: 00100000 11010100 11001011 01001100 10110011 00000010   ..L..
00000090: 01100011 10000000 10100110 11011011 01100110 00101010  c...f*
00000096: 00010001 00010111 00110011 11011001 01010101 00110001  ..3.U1
0000009c: 11110100 10001010 00100000 11111010 00010001 11000000  .. ...
000000a2: 00001100 01000010 00110010 10110011 10001100 00111001  .B2..9
000000a8: 01001001 01001010 11000010 01110011 01111100 11011101  IJ.s|.
000000ae: 11000011 11000111 11010111 10111011 00011000 11001111  ......
000000b4: 11110010 00111110 11110111 11100111 11101000 01010001  .>...Q
000000ba: 01110011 00010110 00000011 01111100 00100010 11110001  s..|".
000000c0: 00101100 00110011 01001100 10011011 01111000 10000011  ,3L.x.
000000c6: 01111000 01101010 11010011 00110110 00111000 11101111  xj.68.
000000cc: 00010011 01000111 01011000 01010001 01010110 10001001  .GXQV.
000000d2: 11001111 10001001 01000111 01001101 10111010 00100000  ..GM. 
000000d8: 11110001 00100011 11010111 10010101 00100110 10111111  .#..&.
000000de: 01110001 00101110 10111000 00101100 11110000 11001100  q..,..
000000e4: 10001000 10011001 01001110 11001101 00010011 01000111  ..N..G
000000ea: 10001000 11000101 01000010 00000111 00101011 00011101  ..B.+.
000000f0: 11001100 10001010 10100110 01000110 00111100 01001001  ...F<I
000000f6: 00011100 01010101 00110101 10011101 11110010 10000101  .U5...
000000fc: 01001100 10010011 01010101 11001110 01011011 10011100  L.U.[.
00000102: 10110101 01110010 10010101 10110101 11101110 11001001  .r....
00000108: 01011111 00011000 11001110 11101001 00101011 11001011  _...+.
0000010e: 01011100 10100111 00111001 10000100 00000100 00010110  \.9...
00000114: 10110001 00000100 00001001 00100010 00010100 01010100  ...".T
0000011a: 01010001 01000010 00011001 00110110 01100010 10110100  QB.6b.
00000120: 11101010 10100100 01011000 01001000 11010001 01111110  ..XH.~
00000126: 11011100 11000011 00111111 11101000 11111010 00100101  ..?..%
0000012c: 01110010 00101001 11100100 00101010 10000001 10010001  r).*..
00000132: 01100011 00000001 00010101 01101000 10010000 01011101  c..h.]
00000138: 00111111 11111000 00011111 11111100 11101110 11010110  ?.....
0000013e: 11001010 01001111 10001100 00110111 10010011 11000010  .O.7..
00000144: 01110001 00100000 11111000 11100010 00111000 00011111  q ..8.
0000014a: 11000011 01000000 01101000 00010111 01101000 11010100  .@h.h.
00000150: 00011100 11100111 11111011 11011000 01110001 00011010  ....q.
00000156: 00100111 10000000 11111111 00011001 10111000 11010010  '.....
0000015c: 11011011 11111110 01001010 00011101 10011000 11111110  ..J...
00000162: 00100100 10111101 11010110 11010110 10100010 01000111  $....G
00000168: 01000000 11101111 00110110 01110000 01110001 11011101  @.6pq.
0000016e: 11010110 10010100 00111101 11100000 01110010 00000111  ..=.r.
00000174: 00011000 01111000 00110010 01100100 01010011 01110110  .x2dSv
0000017a: 00100101 00111111 01001101 00100001 10011111 00000111  %?M!..
00000180: 11011110 11001111 11101000 10011011 10110010 01000000  .....@
00000186: 11011111 00101101 11010000 10111101 11010110 11101100  .-....
0000018c: 10101101 10110101 10001111 11010011 00000111 00100000  ..... 
00000192: 01001101 01011101 00100101 01101111 10000000 10000011  M]%o..
00000198: 01000011 01100000 10100100 01000000 11011001 11101011  C`.@..
0000019e: 00011110 11101111 11101110 11101010 11101100 11101101  ......
000001a4: 11011111 00110011 10101101 11111110 01111110 00000000  .3..~.
000001aa: 01011010 00101011 01110010 10011101 01010110 00001100  Z+r.V.
000001b0: 10001010 10110011 00000000 00000000 00000000 00000110  ......
000001b6: 01100010 01001011 01000111 01000100 00000000 11111111  bKGD..
000001bc: 00000000 11111111 00000000 11111111 10100000 10111101  ......
000001c2: 10100111 10010011 00000000 00000000 00000000 00001001  ......
000001c8: 01110000 01001000 01011001 01110011 00000000 00000000  pHYs..
000001ce: 00101110 00100011 00000000 00000000 00101110 00100011  .#...#
000001d4: 00000001 01111000 10100101 00111111 01110110 00000000  .x.?v.
000001da: 00000000 00000000 00000111 01110100 01001001 01001101  ...tIM
000001e0: 01000101 00000111 11100011 00000101 00010111 00000101  E.....
000001e6: 00000011 00110101 00100010 01111111 01110110 11010001  .5".v.
000001ec: 00000000 00000000 00000000 00011001 01110100 01000101  ....tE
000001f2: 01011000 01110100 01000011 01101111 01101101 01101101  XtComm
000001f8: 01100101 01101110 01110100 00000000 01000011 01110010  ent.Cr
000001fe: 01100101 01100001 01110100 01100101 01100100 00100000  eated 
00000204: 01110111 01101001 01110100 01101000 00100000 01000111  with G
0000020a: 01001001 01001101 01010000 01010111 10000001 00001110  IMPW..
00000210: 00010111 00000000 00000000 00000000 01000010 01001001  ....BI
00000216: 01000100 01000001 01010100 01001000 11000111 01100011  DATH.c
0000021c: 01100000 10100000 00000011 01100000 10000100 00110001  `..`.1
00000222: 11111110 00110011 00110000 11111100 11000111 00101001  .30..)
00000228: 01001001 00101100 11111000 10001111 11010101 00000110  I,....
0000022e: 01000110 00100110 01111010 11111000 01100100 11010100  F&z.d.
00000234: 00010010 11110010 00100010 00011110 01100111 10110100  ..".g.
0000023a: 01010001 00100001 11101010 01000111 11100011 01100100  Q!.G.d
00000240: 11010100 10010010 01010001 01001011 01000110 00101101  ..QKF-
00000246: 00011001 10001010 10010110 10110000 00010000 00101000  .....(
0000024c: 11011011 11111110 10001111 00000110 11010111 11110000  ......
00000252: 10110100 10000100 00101110 00000000 00000000 00100001  .....!
00000258: 01100110 00000111 00101110 01101100 11100001 00001100  f..l..
0000025e: 00100010 00000000 00000000 00000000 00000000 01001001  "....I
00000264: 01000101 01001110 01000100 10101110 01000010 01100000  END.B`
0000026a: 10000010 00000000                                      ..

About

A PHP utility for dumping the bytes of a file or stream in hexadecimal, octal, or binary.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages