Creates a C array from a hex-string or a stream of binary data.

Overview

hex2array-c

Creates a C array from a hex-string.

Usage

Usage: python3 hex2array_c.py HEX_STRING [-h|--help]
Use '-' to read the hex string from STDIN.

Examples:
    python3 hex2array_c.py '0x9d35 0x3f19 0xcf12 0xcd72 0x7f4f 0xa035 0xb307 0x8f07'
    python3 hex2array_c.py '9d-3f-cf-cd-7f-a0-b3-8f' -w4
    python3 hex2array_c.py '538aedc060db31f2d708893526817f619d909526906c1c3a2dca7c242cd0e433' -n 'some_data' -w16
    cat ./afilewithbinarydata | python3 hex2array_c.py - -s4 -w4
    head -c 32 /dev/urandom | python3 hex2array_c.py -

Options:
    -n, --array-name NAME       The name to give to the generated array. The default is 'data'.
    -a, --array-type TYPE       The data type of the generated array. The default is 'const char'.
    -w, --array-width WIDTH     The number of array elements per row. The default is '8'.
    -s, --byte-length LENGTH    The byte length of each array element. The default is '1'.
    -t, --size SIZE             Trim the input to the specified size.
    -e, --swap-endianness       Swap the byte ordering of the generated array. The default is 'False'.

https://github.com/neosophaux

Examples

Pass '-' to the program to read the hex string from stdin.

$ python3 hex2array_c.py '8eb3a4eca0cf603086e9791ca8b1b4ee67038cb96243b18fe43b86dd9a20c18a' -n 'test' -w2 -s4 -e
const char test[8] = {
    0xeca4b38e, 0x3060cfa0, // 0x00000000
    0x1c79e986, 0xeeb4b1a8, // 0x00000008
    0xb98c0367, 0x8fb14362, // 0x00000010
    0xdd863be4, 0x8ac1209a  // 0x00000018
};
$ python3 hex2array_c.py '8eb3a4eca0cf603086e9791ca8b1b4ee67038cb96243b18fe43b86dd9a20c18a' -w4 -a 'uint32_t'
uint32_t data[8] = {
    0x8eb3a4ec, 0xa0cf6030, 0x86e9791c, 0xa8b1b4ee, // 0x00000000
    0x67038cb9, 0x6243b18f, 0xe43b86dd, 0x9a20c18a  // 0x00000010
};
$ echo '0x9e 6b' | python3 hex2array_c.py - -n 'test' -e -s2 -a 'const uint16_t'
const uint16_t test[1] = {
    0x6b9e // 0x00000000
};
$ head -c 32 /dev/urandom | python3 hex2array_c.py -
const char data[32] = {
    0xbb, 0x70, 0xa1, 0x06, 0x1a, 0xe3, 0x85, 0x25, // 0x00000000
    0x6d, 0xbd, 0xeb, 0x73, 0x4d, 0x4b, 0x36, 0x85, // 0x00000008
    0x13, 0xb0, 0x61, 0xbc, 0x5f, 0x33, 0x68, 0x47, // 0x00000010
    0x2f, 0x6f, 0x37, 0x98, 0xce, 0xe4, 0x1c, 0x2b  // 0x00000018
};
You might also like...
A collection of resources/tools and analyses for the angr binary analysis framework.

Awesome angr A collection of resources/tools and analyses for the angr binary analysis framework. This page does not only collect links and external r

Finger is a function symbol recognition engine for binary programs
Finger is a function symbol recognition engine for binary programs

Finger is a function symbol recognition engine for binary programs

A python program to find binary, octal and hexadecimal of a decimal.

decimal-converter This little python program can convert a decimal in to, Binary Octal Hexadecimal Needed Python 3 or later or a online python compile

🌲 A simple BST (Binary Search Tree) generator written in python
🌲 A simple BST (Binary Search Tree) generator written in python

Tree-Traversals (BST) 🌲 A simple BST (Binary Search Tree) generator written in python Installation Use the package manager pip to install BST. Usage

This tool analyzes the json files generated by stream-lnd-htlcs to find hidden channel demand.

analyze_lnd_htlc Introduction Rebalancing channels is an important part of running a Lightning Network node. While it would be great if all channels c

Aggregating gridded data (xarray) to polygons

A package to aggregate gridded data in xarray to polygons in geopandas using area-weighting from the relative area overlaps between pixels and polygons.

Raganarok X: Next Generation Data Dump

Raganarok X Data Dump Raganarok X: Next Generation Data Dump More interesting Files File Name Contains en_langs All the variables you need in English

Python based tool to extract forensic info from EventTranscript.db (Windows Diagnostic Data)
Python based tool to extract forensic info from EventTranscript.db (Windows Diagnostic Data)

EventTranscriptParser EventTranscriptParser is python based tool to extract forensically useful details from EventTranscript.db (Windows Diagnostic Da

A library for interacting with Path of Exile game and economy data, and a unique loot filter generation framework.

wraeblast A library for interfacing with Path of Exile game and economy data, and a set of item filters geared towards trade league players. Filter Ge

Owner
John Doe
John Doe
Tools for binary data on cassette

Micro Manchester Tape Storage Tools for storing binary data on cassette Includes: Python script for encoding Arduino sketch for decoding Eagle CAD fil

Zack Nelson 28 Dec 25, 2022
glip is a module for retrieve ip address like local-ip, global-ip, external-ip as string.

gle_ip_info glip is a module for retrieve ip address like local-ip, global-ip, external-ip as string.

Fatin Shadab 3 Nov 21, 2021
RapidFuzz is a fast string matching library for Python and C++

RapidFuzz is a fast string matching library for Python and C++, which is using the string similarity calculations from FuzzyWuzzy

Max Bachmann 1.7k Jan 4, 2023
A string extractor module for python

A string extractor module for python

Fayas Noushad 4 Jul 19, 2022
Package that allows for validate and sanitize of string values.

py.validator A library of string validators and sanitizers Insipired by validator.js Strings only This library validates and sanitizes strings only. P

Sanel Hadzini 22 Nov 8, 2022
A hashtag from string extract python module

A hashtag from string extract python module

Fayas Noushad 3 Aug 10, 2022
A string to hashtags module

A string to hashtags module

Fayas Noushad 4 Dec 1, 2021
A python lib for generate random string and digits and special characters or A combination of them

A python lib for generate random string and digits and special characters or A combination of them

Torham 4 Nov 15, 2022
A simple package for handling variables in string.

A simple package for handling string variables. Welcome! This is a simple package for handling variables in string, You can add or remove variables wi

null 1 Dec 31, 2021
A Python package for floating-point binary fractions. Do math in base 2!

An implementation of a floating-point binary fractions class and module in Python. Work with binary fractions and binary floats with ease!

null 10 Oct 29, 2022