/* Chrysalide - Outil d'analyse de fichiers binaires * bits.h - prototypes pour la manipulation d'un champ de bits quelconque * * Copyright (C) 2015 Cyrille Bagard * * This file is part of Chrysalide. * * Chrysalide is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Chrysalide is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Foobar. If not, see . */ #ifndef _COMMON_BITS_H #define _COMMON_BITS_H #include "../arch/vmpa.h" /* ----------------------------- CHAMPS DE BITS SIMPLES ----------------------------- */ /* Champ de bits simple */ typedef struct _bitfield_t bitfield_t; /* Crée un champ de bits initialisé. */ bitfield_t *create_bit_field(size_t, bool); /* Crée une copie de champ de bits initialisé à zéro. */ bitfield_t *create_bit_field_from(const bitfield_t *, bool); /* Supprime de la mémoire un champ de bits donné. */ void delete_bit_field(bitfield_t *); /* Copie un champ de bits dans un autre. */ void copy_bit_field(bitfield_t *, const bitfield_t *); /* Crée une copie d'un champ de bits classique. */ bitfield_t *dup_bit_field(const bitfield_t *); /* Bascule à 0 un champ de bits dans son intégralité. */ void reset_all_in_bit_field(bitfield_t *); /* Bascule à 1 un champ de bits dans son intégralité. */ void set_all_in_bit_field(bitfield_t *); /* Bascule à 1 une partie d'un champ de bits. */ void set_in_bit_field(bitfield_t *, size_t, size_t); /* Bascule à 1 de façon atomique une partie d'un champ de bits. */ bool set_atomic_in_bit_field(bitfield_t *, size_t, size_t); /* Réalise une opération ET logique entre deux champs de bits. */ void and_bit_field(bitfield_t *, const bitfield_t *); /* Réalise une opération OU logique entre deux champs de bits. */ void or_bit_field(bitfield_t *, const bitfield_t *); /* Détermine si un bit est à 1 dans un champ de bits. */ bool test_in_bit_field(const bitfield_t *, size_t, size_t); /* Indique si deux champs de bits sont identiques ou non. */ bool is_bit_field_equal_to(const bitfield_t *, const bitfield_t *); unsigned long gfw(const bitfield_t *); #if 0 /* ------------------------- CHAMPS LIES À UNE ZONE MEMOIRE ------------------------- */ /* Champ de bits couvrant une mémoire */ typedef struct _bitfield_t memfield_t; /* Crée un champ de bits couvrant une zone mémoire. */ memfield_t *create_mem_field(const mrange_t *, bool); /* Crée une copie de champ de bits couvrant une zone mémoire. */ memfield_t *create_mem_field_from(const memfield_t *); /* Supprime de la mémoire un champ de bits donné. */ void delete_mem_field(memfield_t *); /* Crée une copie d'un champ de bits couvrant une zone mémoire. */ memfield_t *dup_mem_field(const memfield_t *); /* Bascule à 1 un bit d'un champ de bits. */ void set_in_mem_field(memfield_t *, const vmpa2t *); /* Détermine si un bit est à 1 dans un champ de bits. */ bool test_in_mem_field(memfield_t *, const vmpa2t *); #define set_atomic_in_mem_field(f, range) false #endif #endif /* _COMMON_BITS_H */