Merge pull request #251 from merlokk/reorg_includes

added PACKED attribute for structures and reorganize include folder
This commit is contained in:
Philippe Teuwen
2019-07-16 14:52:14 +02:00
committed by GitHub
19 changed files with 216 additions and 183 deletions

View File

@@ -15,10 +15,11 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "pmflash.h"
#include "common.h"
#include "proxmark3.h"
#include "ui.h"
#include "cmdparser.h"
#include "common.h"
#include "util.h"
#include "util_posix.h" // msclock
#include "loclass/fileutils.h" //saveFile

View File

@@ -9,6 +9,8 @@
#ifndef __ELF_H__
#define __ELF_H__
#include "proxmark3.h"
typedef struct {
uint32_t p_type;
uint32_t p_offset;
@@ -18,7 +20,7 @@ typedef struct {
uint32_t p_memsz;
uint32_t p_flags;
uint32_t p_align;
} __attribute__((__packed__)) Elf32_Phdr;
} PACKED Elf32_Phdr;
#define EI_NIDENT 16
@@ -37,7 +39,7 @@ typedef struct {
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shtrndx;
} __attribute__((__packed__)) Elf32_Ehdr;
} PACKED Elf32_Ehdr;
#define PT_NULL 0
#define PT_LOAD 1

View File

@@ -14,4 +14,16 @@
#define PROXPROMPT "proxmark3> "
#ifdef _MSC_VER
typedef DWORD uint32_t;
typedef BYTE uint8_t;
#define PACKED
// stuff
#else
#include <stdint.h>
#include <stdbool.h>
#define PACKED __attribute__((packed))
#endif
#endif

View File

@@ -12,16 +12,8 @@
#ifndef __USB_CMD_H
#define __USB_CMD_H
#ifdef _MSC_VER
typedef DWORD uint32_t;
typedef BYTE uint8_t;
#define PACKED
// stuff
#else
#include <stdint.h>
#include <stdbool.h>
#define PACKED __attribute__((packed))
#endif
#include "proxmark3.h"
typedef struct {
uint32_t cmd;

View File

@@ -9,6 +9,8 @@
#ifndef __ELF_H__
#define __ELF_H__
#include "common.h"
typedef struct {
uint32_t p_type;
uint32_t p_offset;
@@ -18,7 +20,7 @@ typedef struct {
uint32_t p_memsz;
uint32_t p_flags;
uint32_t p_align;
} __attribute__((__packed__)) Elf32_Phdr;
} PACKED Elf32_Phdr;
#define EI_NIDENT 16
@@ -37,7 +39,7 @@ typedef struct {
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shtrndx;
} __attribute__((__packed__)) Elf32_Ehdr;
} PACKED Elf32_Ehdr;
#define PT_NULL 0
#define PT_LOAD 1

View File

@@ -60,7 +60,7 @@ local function parse14443a(data)
uint8_t sak;
uint8_t ats_len;
uint8_t ats[256];
} __attribute__((__packed__)) iso14a_card_select_t;
} PACKED iso14a_card_select_t;
--]]
local count, uid, uidlen, atqa, sak, ats_len, ats = bin.unpack('H10CH2CCH', data)

View File

@@ -39,7 +39,7 @@ local function parse1443b(data)
uint8_t atqb[7];
uint8_t chipid;
uint8_t cid;
} __attribute__((__packed__)) iso14b_card_select_t;
} PACKED iso14b_card_select_t;
--]]

View File

@@ -20,100 +20,12 @@
#include <time.h>
#include "ui.h" // PrintAndLog
#include "commonutil.h"
#ifdef _MSC_VER
#define PACKED
#else
#define PACKED __attribute__((packed))
#endif
#include "common.h"
#ifdef ANDROID
#include <endian.h>
#endif
#ifndef ROTR
# define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
#endif
#ifndef ROTL
# define ROTL(x,n) (((uintmax_t)(x) << (n)) | ((uintmax_t)(x) >> ((sizeof(x) * 8) - (n))))
#endif
#ifndef MIN
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
// endian change for 64bit
#ifdef __GNUC__
#ifndef BSWAP_64
#define BSWAP_64(x) __builtin_bswap64(x)
#endif
#else
#ifdef _MSC_VER
#ifndef BSWAP_64
#define BSWAP_64(x) _byteswap_uint64(x)
#endif
#else
#ifndef BSWAP_64
#define BSWAP_64(x) \
(((uint64_t)(x) << 56) | \
(((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
(((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
(((uint64_t)(x) << 8) & 0xff00000000ULL) | \
(((uint64_t)(x) >> 8) & 0xff000000ULL) | \
(((uint64_t)(x) >> 24) & 0xff0000ULL) | \
(((uint64_t)(x) >> 40) & 0xff00ULL) | \
((uint64_t)(x) >> 56))
#endif
#endif
#endif
// endian change for 32bit
#ifdef __GNUC__
#ifndef BSWAP_32
#define BSWAP_32(x) __builtin_bswap32(x)
#endif
#else
#ifdef _MSC_VER
#ifndef BSWAP_32
#define BSWAP_32(x) _byteswap_ulong(x)
#endif
#else
#ifndef BSWAP_32
# define BSWAP_32(x) \
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
#endif
#endif
#endif
#define EVEN 0
#define ODD 1
// Nibble logic
#ifndef NIBBLE_HIGH
# define NIBBLE_HIGH(b) ( (b & 0xF0) >> 4 )
#endif
#ifndef NIBBLE_LOW
# define NIBBLE_LOW(b) ( b & 0x0F )
#endif
#ifndef CRUMB
# define CRUMB(b,p) (((b & (0x3 << p) ) >> p ) & 0xF)
#endif
#ifndef SWAP_NIBBLE
# define SWAP_NIBBLE(b) ( (NIBBLE_LOW(b)<< 4) | NIBBLE_HIGH(b))
#endif
// Binary Encoded Digit
#ifndef BCD2DEC
# define BCD2DEC(bcd) HornerScheme(bcd, 0x10, 10)
#endif
#ifndef DEC2BCD
# define DEC2BCD(dec) HornerScheme(dec, 10, 0x10)
#endif
// used for save/load files
#ifndef FILE_PATH_SIZE
# define FILE_PATH_SIZE 1000