cpp-struct-byte-order-converter

⚒ A PowerShell script used to generate byte reversing functions for a C/C++ structure.(用于为C/C++结构体生成字节序翻转函数的PowerShell脚本。)

https://github.com/zhuagenborn/cpp-struct-byte-order-converter

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.2%) to scientific vocabulary

Keywords

big-endian byte-order endianness little-endian
Last synced: 6 months ago · JSON representation ·

Repository

⚒ A PowerShell script used to generate byte reversing functions for a C/C++ structure.(用于为C/C++结构体生成字节序翻转函数的PowerShell脚本。)

Basic Info
  • Host: GitHub
  • Owner: Zhuagenborn
  • License: mit
  • Language: PowerShell
  • Default Branch: main
  • Homepage:
  • Size: 7.81 KB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
big-endian byte-order endianness little-endian
Created over 1 year ago · Last pushed 10 months ago
Metadata Files
Readme License Citation

README.md

C/C++ Structure Byte Order Converter

PowerShell GitHub Actions License

Introduction

This script can read a C/C++ structure definition from the clipboard and generate byte reversing functions for the structure with ntoh or hton APIs.

Usage

Suppose we have a structure Foo:

c++ struct Foo { unsigned short us; int i8 : 8; int i24 : 24; signed long sl[4]; char c[12]; long long ll24 : 24; signed int si8 : 8; short s; };

Copy the structure definition to the clipboard and run the script. We can get two reversing functions:

```c++ void ReverseFooToLittleEndian(Foo const data) { data->us = ntohs(data->us); *(int)((unsigned char)(&data->us) + sizeof(data->us) + 0) = ntohl((int)((unsigned char)(&data->us) + sizeof(data->us) + 0)); for (size_t i = 0; i < sizeof(data->sl) / sizeof(data->sl[0]); i++) { data->sl[i] = ntohl(data->sl[i]); } (long long)((unsigned char)(&data->c) + sizeof(data->c) + 0) = ntohll((long long)((unsigned char)(&data->c) + sizeof(data->c) + 0)); (signed int)((unsigned char)(&data->c) + sizeof(data->c) + 8) = ntohl((signed int)((unsigned char)(&data->c) + sizeof(data->c) + 8)); data->s = ntohs(data->s); }

void ReverseFooToBigEndian(Foo const data) { data->us = htons(data->us); *(int)((unsigned char)(&data->us) + sizeof(data->us) + 0) = htonl((int)((unsigned char)(&data->us) + sizeof(data->us) + 0)); for (size_t i = 0; i < sizeof(data->sl) / sizeof(data->sl[0]); i++) { data->sl[i] = htonl(data->sl[i]); } (long long)((unsigned char)(&data->c) + sizeof(data->c) + 0) = htonll((long long)((unsigned char)(&data->c) + sizeof(data->c) + 0)); (signed int)((unsigned char)(&data->c) + sizeof(data->c) + 8) = htonl((signed int)((unsigned char)(&data->c) + sizeof(data->c) + 8)); data->s = htons(data->s); } ```

The output can be copied directly to the clipboard:

console PS> .\Build-ByteReverseFunctions.ps1 | Set-Clipboard

Warnings

  • The structure name can only be extracted from the struct statement.
  • The script can only detect single-line comments (//).
  • The following settings may differ from the script on some systems and compilers.
    • Endianness.
    • The sizes of fundamental C/C++ types.
    • The order of bit-fields.
    • Field alignment.

License

Distributed under the MIT License. See LICENSE for more information.

Owner

  • Name: Zhuagenborn
  • Login: Zhuagenborn
  • Kind: organization
  • Location: Ireland

Software Development | Artificial Intelligence | Reverse Engineering.

Citation (CITATION.cff)

cff-version: 1.2.0
authors:
- family-names: Chen
  given-names: Zhenshuo
  orcid: https://orcid.org/0000-0003-2091-4160
title: C/C++ Structure Byte Order Converter
date-released: 2024-08-02
url: https://github.com/Zhuagenborn/Cpp-Struct-Byte-Order-Converter

GitHub Events

Total
  • Push event: 1
Last Year
  • Push event: 1

Issues and Pull Requests

Last synced: 12 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/test.yaml actions
  • actions/checkout main composite