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
};
Owner
John Doe
John Doe
A multipurpose python module

pysherlock pysherlock is a Python library for dealing with web scraping using images, it's a Python application of the rendertron headless browser API

Sachit 2 Nov 11, 2021
A simple python implementation of Decision Tree.

DecisionTree A simple python implementation of Decision Tree, using Gini index. Usage: import DecisionTree node = DecisionTree.trainDecisionTree(lab

1 Nov 12, 2021
A utility tool to create .env files

A utility tool to create .env files dump-env takes an .env.template file and some optional environmental variables to create a new .env file from thes

wemake.services 89 Dec 08, 2022
We provide useful util functions. When adding a util function, please add a description of the util function.

Utils Collection Motivation When we implement codes, we often search for util functions that are already implemented. Here, we are going to share util

6 Sep 09, 2021
Python module and its web equivalent, to hide text within text by manipulating bits

cacherdutexte.github.io This project contains : Python modules (binary and decimal system 6) with a dedicated tkinter program to use it. A web version

2 Sep 04, 2022
Genart - Generate random art to sell as nfts

Genart - Generate random art to sell as nfts Usage git clone

Will 13 Mar 17, 2022
iOS Snapchat parser for chats and cached files

ParseSnapchat iOS Snapchat parser for chats and cached files Tested on Windows and Linux install required libraries: pip install -r requirements.txt c

11 Dec 05, 2022
Keval allows you to call arbitrary Windows kernel-mode functions from user mode, even (and primarily) on another machine.

Keval Keval allows you to call arbitrary Windows kernel-mode functions from user mode, even (and primarily) on another machine. The user mode portion

42 Dec 17, 2022
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

105 Jan 02, 2023
Python program for analyzing the output files of phonopy.

PhononTools Description Python program to analyze the results generated by phonopy. Using the .yaml and .dat files that phonopy generates one can plot

Harry LaBollita 8 Nov 27, 2022
Simple yet flexible natural sorting in Python.

natsort Simple yet flexible natural sorting in Python. Source Code: https://github.com/SethMMorton/natsort Downloads: https://pypi.org/project/natsort

Seth Morton 712 Dec 23, 2022
Trying to replicate (albeit unsuccessfully) the phenomenon of boids using Ursina in a naive manner.

Boids_Boi Trying to replicate (albeit unsuccessfully) the phenomenon of boids using Ursina in a naive manner. Please install the Ursina module before

2 Oct 19, 2021
Python Random Number Genrator

This Genrates Random Numbers. This Random Number Generator was made using python. This software uses Time and Random extension. Download the EXE file and run it to get your answer.

Krish Sethi 2 Feb 03, 2022
A Tool that provides automatic kerning for ligature based OpenType fonts in Microsoft Volt

Kerning A Tool that provides automatic kerning for ligature based OpenType fonts in Microsoft Volt There are three stages of the algorithm. The first

Sayed Zeeshan Asghar 6 Aug 01, 2022
A random cats photos python module

A random cats photos python module

Fayas Noushad 6 Dec 01, 2021
Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.

Lark - Parsing Library & Toolkit 3.5k Jan 05, 2023
Pass arguments by reference—in Python!

byref Pass arguments by reference—in Python! byrefis a decorator that allows Python functions to declare reference parameters, with similar semantics

9 Feb 10, 2022
Homebase Name Changer for Fortnite: Save the World.

Homebase Name Changer This program allows you to change the Homebase name in Fortnite: Save the World. How to use it? After starting the HomebaseNameC

PRO100KatYT 7 May 21, 2022
Casefy (/keɪsfaɪ/) is a lightweight Python package to convert the casing of strings

Casefy (/keɪsfaɪ/) is a lightweight Python package to convert the casing of strings. It has no third-party dependencies and supports Unicode.

Diego Miguel Lozano 12 Jan 08, 2023
A tiny Python library for generating public IDs from integers

pids Create short public identifiers based on integer IDs. Installation pip install pids Usage from pids import pid public_id = pid.from_int(1234) #

Simon Willison 7 Nov 11, 2021