Giter Club home page Giter Club logo

hexfile's Introduction

hexfile

This is a simple library for parsing hex files. Currently only intel hex files are supported.

Installation

You can use the included setup.py or use your pip to install it from PyPI

Usage

To create a HexFile object use hexfile.load:

import hexfile

f = hexfile.load('memory.hex')

The HexFile object is composed of one or more memory segments, which may be discontinuous. You can access the contents of the hex file as though it were an array of bytes:

print f.size       # Total number of bytes in the hexfile (NOT the total span of all addresses)

byte = f[16]       # Returns the byte at address 16 (as an int)

bytes = f[256:512] # Returns 256 bytes as a list

print f.segments   # Display all the segments in the hex file

The HexFile object also supports iteration, but rather than iterating over byte values as if it were a list, it includes the byte addresses, as if it were enumerated. This is because the file might be discontinuous, so addresses are frequently needed during iteration.

for addr, data in f:
    print '0x%08x : 0x%02x' % (addr, data) # Print every byte in the hex file and its 32-bit address

hexfile's People

Contributors

gfsmith avatar jmwilson avatar mithro avatar ryansturmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

hexfile's Issues

Fails to install under Python 3

hexfile seems to be compatible with Python 3 but you can't install it via pip, instead you get the following error;

pip install hexfile
Collecting hexfile
  Using cached hexfile-0.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-lhegh4st/hexfile/setup.py", line 1, in <module>
        import hexfile
      File "/tmp/pip-build-lhegh4st/hexfile/hexfile/__init__.py", line 8, in <module>
        from core import load, HexFile, Segment
    ImportError: No module named 'core'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-lhegh4st/hexfile

If I do the following it all seems to work;

wget https://raw.githubusercontent.com/ryansturmer/hexfile/master/hexfile/core.py -O hexfile.py
python3 hexfile.py

Unexpected start_address returned when creating a segment slice

Looking at this line
start_address = address.start + self.start_address

I think the below would make more sense.
start_address = self.start_address

As of now, I get this behavior something like this:

>>> seg
<2048 byte segment @ 0x90000000>
>>> seg[0x90000000:0x90000010]
<16 byte segment @ 120000000>

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.