Coder Social home page Coder Social 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

ryansturmer avatar gfsmith avatar jmwilson avatar mithro avatar

Watchers

James Cloos avatar Moon 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.