Giter Club home page Giter Club logo

hex2raw's Introduction

hex2raw

This little and useful tool parses firmwares code in .hex format into a dump and readable format for futures manipulation.

Why ?

When you compile a firmware for some microcontrollers, like AVR board, a .hex file with the code in string format will be generated for softwares like avrdude be able to read and flash correctly in the board, but we can't manipulate this .hex file in disassemblies tools.

.hex example

:100000000C9434000C9451000C9451000C94510049
:100010000C9451000C9451000C9451000C9451001C
:100020000C9451000C9451000C9451000C9451000C
:100030000C9451000C9451000C9451000C945100FC
:100040000C9451000C9451000C9451000C945100EC
:100050000C9451000C9451000C9451000C945100DC

This is a piece of an .hex file that will be flashed inside an ATMEGA328p (AKA Arduino), you can use this tool to convert this .hex back to his blob representation.

$ python3 hex_to_asm.py matrix.hex --board atmega328p
Parsing matrix.hex
Written as matrix.hex.dump

With this dumped file you can use in your favorite binary analysis tool, take a look in the radare2 output.

~/.../python/hex_to_asm >>> rabin2 -I matrix.hex.dump                                                                                                                                                      
arch     avr
baddr    0xffffffffffffffff
binsz    2636
bits     8
canary   false
retguard false
crypto   false
endian   little
havecode true
laddr    0x0
linenum  false
lsyms    false
machine  ATmel
maxopsz  16
minopsz  1
nx       false
os       avr
pcalign  0
pic      false
relocs   false
sanitiz  false
static   true
stripped false
va       false

Going further

Loading with Cutter:

Expanding this

You can help expading this tool parsing capabilites by adding new entries in the prefix_address_size.yml file, this tool loads that config files to know where the addressing starts and ends.

Example: ATMEGA328P

The atmega328p has an 32k memory addressing/size, so the first 8 digits is the address part (10004000 for example) and we have the ":" mark that indicate that a new line started, so we need supply to our configuration file a address size of 9.

boards:
    atmega328p: 9 #:<address>

You can help this project by adding news entries in this file and creating a pull request for each one :)

TODO

  • Convert dump files into a .hex files

Thanks!

hex2raw's People

Contributors

buzzer-re avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.