Lots of cleanups to reduce the regressions in TCC ##refactor

* Cleanup crypto.aes and anal.arm_cs to make the latest tcc happy
* Dont pick latest tcc. as its broken (-30 commits for now)
* Dont pass multi-dimensional arrays as argument
* Don't assume TCC supports threads, because it doesnt
* Many intrinsics are missing still for tcc on darwin-arm64
* lz4 code crashes when compiled with latest tcc and needs a full rewrit
* Add more null checks here and there
* Remove unused code in the tcc parser
This commit is contained in:
pancake 2022-03-17 18:40:58 +01:00 committed by GitHub
parent 8089224302
commit 245babbf9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 128 additions and 222 deletions

View File

@ -16,6 +16,7 @@ jobs:
git clone https://github.com/mirror/tinycc.git
cd tinycc
git checkout mob
git reset --hard HEAD~30
- name: Compiling and installing TinyCC
working-directory: tinycc

View File

@ -9,6 +9,8 @@
#include <r_util/r_assert.h>
#include "./anal_arm_hacks.inc"
typedef char RStringShort[32];
/* arm64 */
#define IMM64(x) (ut64)(insn->detail->arm64.operands[x].imm)
#define INSOP64(x) insn->detail->arm64.operands[x]
@ -2368,14 +2370,14 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l
#define MATH32_NEG(opchar) arm32math(a, op, addr, buf, len, handle, insn, pcdelta, str, opchar, 1)
#define MATH32AS(opchar) arm32mathaddsub(a, op, addr, buf, len, handle, insn, pcdelta, str, opchar)
static void arm32math(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, int pcdelta, char(*str)[32], const char *opchar, int negate) {
static void arm32math(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, int pcdelta, RStringShort str[32], const char *opchar, int negate) {
const char *dest = ARG(0);
const char *op1;
const char *op2;
bool rotate_imm = OPCOUNT() > 3;
if (OPCOUNT() > 2) {
op1 = ARG(1);
op2 = ARG(2);
op1 = ARG(1);
op2 = ARG(2);
} else {
op1 = dest;
op2 = ARG(1);
@ -2406,7 +2408,7 @@ static void arm32math(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len,
}
}
static void arm32mathaddsub(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, int pcdelta, char(*str)[32], const char *opchar) {
static void arm32mathaddsub(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, int pcdelta, RStringShort str[32], const char *opchar) {
const char *dst = ARG (0);
const char *src;
bool noflags = false;
@ -2432,7 +2434,8 @@ static void arm32mathaddsub(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, in
static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, bool thumb) {
int i;
const char *postfix = NULL;
char str[32][32];
// char str[32][32];
RStringShort str[32] = {0};
int msr_flags;
int pcdelta = (thumb? 4: 8);
ut32 mask = UT32_MAX;

View File

@ -5,6 +5,11 @@
extern instructionInfo instructionSet[AVR_TOTAL_INSTRUCTIONS];
typedef struct {
char ens[3][MAX_TOKEN_SIZE];
} AvrToken;
static int search_instruction(RAsm *a, AvrToken *tok, int args);
// char instr[3][MAX_TOKEN_SIZE], int args);
/* the next few functions and structures uses for detecting
AVR special regs, like X+, -Y, Z+3 in st(d), ld(d) and
(e)lpm instructions */
@ -37,7 +42,7 @@ specialregs RegsTable[REGS_TABLE] = {
int avr_encode(RAsm *a, RAsmOp *ao, const char *str) {
char tokens[3][MAX_TOKEN_SIZE];
AvrToken tok;
char *token;
uint32_t coded = 0;
int len = 0;
@ -49,15 +54,15 @@ int avr_encode(RAsm *a, RAsmOp *ao, const char *str) {
// the delimiters are ' ' and ','
token = strtok ((char *)str, TOKEN_DELIM);
while (token && tokens_cnt < 3) {
memset (tokens[tokens_cnt], 0, MAX_TOKEN_SIZE);
strncpy (tokens[tokens_cnt], token, MAX_TOKEN_SIZE-1);
memset (tok.ens[tokens_cnt], 0, MAX_TOKEN_SIZE);
strncpy (tok.ens[tokens_cnt], token, MAX_TOKEN_SIZE-1);
token = strtok (NULL, TOKEN_DELIM);
tokens_cnt += 1;
}
if (tokens_cnt > 0) {
// find nearest instruction that looks like supplied
instr_idx = search_instruction (a, tokens, tokens_cnt - 1);
instr_idx = search_instruction (a, &tok, tokens_cnt - 1);
if (instr_idx >= 0) {
// no operands -- just return opcode mask
@ -73,7 +78,7 @@ int avr_encode(RAsm *a, RAsmOp *ao, const char *str) {
ORing with the last 16 bits(/2 for jmp/call) */
} else if (instructionSet[instr_idx].numOperands == 1 && tokens_cnt == 2) {
if (assemble_operand (a, tokens[1], instructionSet[instr_idx].operandTypes[0], &op1) >= 0) {
if (assemble_operand (a, tok.ens[1], instructionSet[instr_idx].operandTypes[0], &op1) >= 0) {
// jmp and call has 4-byte opcode
if (instructionSet[instr_idx].operandTypes[0] == OPERAND_LONG_ABSOLUTE_ADDRESS) {
op1 = op1/2;
@ -99,8 +104,8 @@ int avr_encode(RAsm *a, RAsmOp *ao, const char *str) {
}
} else if (instructionSet[instr_idx].numOperands == 2 && tokens_cnt == 3) {
if (assemble_operand(a, tokens[1], instructionSet[instr_idx].operandTypes[0], &op1) >= 0 &&
assemble_operand(a, tokens[2], instructionSet[instr_idx].operandTypes[1], &op2) >= 0) {
if (assemble_operand(a, tok.ens[1], instructionSet[instr_idx].operandTypes[0], &op1) >= 0 &&
assemble_operand(a, tok.ens[2], instructionSet[instr_idx].operandTypes[1], &op2) >= 0) {
coded = instructionSet[instr_idx].opcodeMask
| packDataByMask(op1, instructionSet[instr_idx].operandMasks[0])
@ -233,7 +238,7 @@ int assemble_operand(RAsm *a, const char *operand, int type, uint32_t *res) {
break;
case OPERAND_YPQ:
case OPERAND_ZPQ:
if (strlen(operand) > 2) {
if (strlen (operand) > 2) {
/* return argument after '+' sign
we've already checked presence of '+' in parse_specialreg */
*res = getnum (operand + 2);
@ -241,7 +246,7 @@ int assemble_operand(RAsm *a, const char *operand, int type, uint32_t *res) {
}
break;
case OPERAND_REGISTER:
if (strlen(operand) > 1) {
if (strlen (operand) > 1) {
// returns register number (r__)
*res = getnum (operand + 1);
if (*res <= 32) {
@ -250,7 +255,7 @@ int assemble_operand(RAsm *a, const char *operand, int type, uint32_t *res) {
}
break;
case OPERAND_REGISTER_STARTR16:
if (strlen(operand) > 1) {
if (strlen (operand) > 1) {
// returns register number (r__)
*res = getnum (operand + 1);
if (*res >= 16 && *res <= 32) {
@ -291,12 +296,12 @@ uint16_t packDataByMask(uint16_t data, uint16_t mask) {
/* this function searches from instruction in instructionSet table
(see avr_disasm.h for more info)
returns index of the instruction in the table */
int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args) {
static int search_instruction(RAsm *a, AvrToken *tok, int args) {
int i, op1 = 0, op2 = 0;
for (i = 0; i < AVR_TOTAL_INSTRUCTIONS - 1; i++) {
// check instruction mnemonic
if (!strncmp (instr[0], instructionSet[i].mnemonic, MAX_TOKEN_SIZE)) {
if (!strncmp (tok->ens[0], instructionSet[i].mnemonic, MAX_TOKEN_SIZE)) {
// in AVR instructions could have different opcodes based on number of arguments
if (instructionSet[i].numOperands == args) {
/* because st Z+ and st Z (and so on...) are instructions with DIFFERENT opcodes
@ -307,14 +312,14 @@ int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args) {
// handling (e)lpm instruction with 2 args
if (instructionSet[i].opcodeMask >= 0x9004 &&
instructionSet[i].opcodeMask <= 0x9007) {
if (instructionSet[i].operandTypes[1] == parse_specialreg (instr[2])) {
if (instructionSet[i].operandTypes[1] == parse_specialreg (tok->ens[2])) {
return i;
}
// handling ld & ldd instruction with 2 args
} else if (instructionSet[i].mnemonic[0] == 'l'
&& instructionSet[i].mnemonic[1] == 'd'
&& (instructionSet[i].mnemonic[2] == 'd' || instructionSet[i].mnemonic[2] == '\0')) {
if (instructionSet[i].operandTypes[1] == parse_specialreg (instr[2])) {
if (instructionSet[i].operandTypes[1] == parse_specialreg (tok->ens[2])) {
return i;
}
// handling lds command, distinguishing long from 16-bit version
@ -323,8 +328,8 @@ int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args) {
&& instructionSet[i].mnemonic[2] == 's'
&& instructionSet[i].operandTypes[1] == OPERAND_LONG_ABSOLUTE_ADDRESS) {
// ineffective, but needed for lds/sts and other cases
if (strlen(instr[2]) > 0) {
op2 = getnum (instr[2]);
if (strlen (tok->ens[2]) > 0) {
op2 = getnum (tok->ens[2]);
if (op2 > 127) {
return i;
}
@ -334,7 +339,7 @@ int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args) {
&& instructionSet[i].mnemonic[1] == 't'
&& (instructionSet[i].mnemonic[2] == 'd' || instructionSet[i].mnemonic[2] == '\0')) {
if (instructionSet[i].operandTypes[0] == parse_specialreg (instr[1])) {
if (instructionSet[i].operandTypes[0] == parse_specialreg (tok->ens[1])) {
return i;
}
// handling sts long command
@ -343,8 +348,8 @@ int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args) {
&& instructionSet[i].mnemonic[2] == 's'
&& instructionSet[i].operandTypes[0] == OPERAND_LONG_ABSOLUTE_ADDRESS) {
// same for 1st operand of sts
if (strlen(instr[1]) > 0) {
op1 = getnum (instr[1]);
if (strlen (tok->ens[1]) > 0) {
op1 = getnum (tok->ens[1]);
if (op1 > 127) {
return i;
}

View File

@ -11,10 +11,10 @@
#define MAX_TOKEN_SIZE 32
#define TOKEN_DELIM " ,\t"
int avr_encode (RAsm *a, RAsmOp *ao, const char *str);
int avr_encode(RAsm *a, RAsmOp *ao, const char *str);
int assemble_operand(RAsm *a, const char *operand, int type, uint32_t *res);
uint16_t packDataByMask(uint16_t data, uint16_t mask);
int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args);
// int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args);
int parse_specialreg(const char *reg);
#endif /* LIBR_ASM_ARCH_AVR_ASSEMBLE_H_ */

View File

@ -22,45 +22,41 @@ static const ut8 Rcon[30] = {
0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91
};
typedef struct {
// #define Nr_AES256 (16) /* st->rounds */
// #define Nr_AES256 (6 + ((256 / 8) / 4))
// ut32 key[2][Nr_AES256 + 1][Nb];
ut32 key[2][17][4];
} RCryptoAESExponent;
// Expand a user-supplied key material into a session key.
// key - The 128/192/256-bit user-key to use.
//expkey[2][Nr + 1][Nb]
//void aes_expkey (const struct aes_state *st, ut32 ***expkey) { //expkey[2][st->rounds + 1][Nb]) {
#if defined (__GNUC__)
void aes_expkey (const struct aes_state *st, ut32 expkey[2][st->rounds + 1][Nb])
#else
// XXX this is wrong, but at least it compiles
#ifdef _MSC_VER
#pragma message ("AES broken for non-gcc compilers")
#else
#warning AES broken for non-gcc compilers
#endif
#define Nr_AES256 (6 + ((256 / 8) / 4))
void aes_expkey (const struct aes_state *st, ut32 expkey[2][Nr_AES256 + 1][Nb])
#endif
{
void aes_expkey(const RCryptoAESState *st, RCryptoAESExponent *exp) {
if (!st) {
return;
}
// ut32 expkey[2][st->rounds + 1][Nb];
// memcpy (&expkey, _expkey, 2 * (st->rounds + 1) * Nb);
int ROUND_KEY_COUNT = 4 * (1 + st->rounds);
#ifdef _MSC_VER
ut32 *tk = (ut32*)malloc (sizeof (ut32) * st->columns);
#else
ut32 tk[st->columns];
#endif
const int ROUND_KEY_COUNT = 4 * (1 + st->rounds);
ut32 tt;
st32 idx = 0, t = 0;
const ut8 *key = st->key;
st32 i, j, r;
ut32 *tk = (ut32*)malloc (sizeof (ut32) * st->columns);
if (!tk) {
return;
}
for (i = 0; i <= st->rounds; i++) {
for (j = 0; j < Nb; j++) {
expkey[0][i][j] = 0;
exp->key[0][i][j] = 0;
}
}
for (i = 0; i <= st->rounds; i++) {
for (j = 0; j < Nb; j++) {
expkey[1][i][j] = 0;
exp->key[1][i][j] = 0;
}
}
@ -74,8 +70,8 @@ void aes_expkey (const struct aes_state *st, ut32 expkey[2][Nr_AES256 + 1][Nb])
// Copy values into round key arrays
for (j = 0; j < st->columns && t < ROUND_KEY_COUNT; j++, t++) {
expkey[0][t / Nb][t % Nb] = tk[j];
expkey[1][st->rounds - (t / Nb)][t % Nb] = tk[j];
exp->key[0][t / Nb][t % Nb] = tk[j];
exp->key[1][st->rounds - (t / Nb)][t % Nb] = tk[j];
}
while (t < ROUND_KEY_COUNT) {
@ -103,34 +99,28 @@ void aes_expkey (const struct aes_state *st, ut32 expkey[2][Nr_AES256 + 1][Nb])
// Copy values into round key arrays
for (j = 0; j < st->columns && t < ROUND_KEY_COUNT; j++, t++) {
expkey[0][t / Nb][t % Nb] = tk[j];
expkey[1][st->rounds - (t / Nb)][t % Nb] = tk[j];
exp->key[0][t / Nb][t % Nb] = tk[j];
exp->key[1][st->rounds - (t / Nb)][t % Nb] = tk[j];
}
}
// Inverse MixColumn where needed
for (r = 1; r < st->rounds; r++) {
for (j = 0; j < Nb; j++) {
tt = expkey[1][r][j];
expkey[1][r][j] = U0[(ut8)(tt >> 24)] ^ U1[(ut8)(tt >> 16)] ^
tt = exp->key[1][r][j];
exp->key[1][r][j] = U0[(ut8)(tt >> 24)] ^ U1[(ut8)(tt >> 16)] ^
U2[(ut8)(tt >> 8)] ^ U3[(ut8)tt];
}
}
#ifdef _MSC_VER
free (tk);
#endif
}
// Convenience method to encrypt exactly one block of plaintext, assuming
// Rijndael's default block size (128-bit).
// in - The plaintext
// result - The ciphertext generated from a plaintext using the key
void aes_encrypt (struct aes_state *st, ut8 *in, ut8 *result) {
#if defined(_MSC_VER) || defined(__TINYC__)
ut32 expkey[2][Nr_AES256 + 1][Nb];
#else
ut32 expkey[2][st->rounds + 1][Nb];
#endif
aes_expkey(st, expkey);
void aes_encrypt(RCryptoAESState *st, ut8 *in, ut8 *result) {
RCryptoAESExponent exp = {0};
aes_expkey (st, &exp);
ut32 t0, t1, t2, t3, tt;
ut32 a0, a1, a2, a3, r;
@ -139,25 +129,25 @@ void aes_encrypt (struct aes_state *st, ut8 *in, ut8 *result) {
t0 |= *in++ << 16;
t0 |= *in++ << 8;
t0 |= *in++;
t0 ^= expkey[0][0][0];
t0 ^= exp.key[0][0][0];
t1 = *in++ << 24;
t1 |= *in++ << 16;
t1 |= *in++ << 8;
t1 |= *in++;
t1 ^= expkey[0][0][1];
t1 ^= exp.key[0][0][1];
t2 = *in++ << 24;
t2 |= *in++ << 16;
t2 |= *in++ << 8;
t2 |= *in++;
t2 ^= expkey[0][0][2];
t2 ^= exp.key[0][0][2];
t3 = *in++ << 24;
t3 |= *in++ << 16;
t3 |= *in++ << 8;
t3 |= *in++;
t3 ^= expkey[0][0][3];
t3 ^= exp.key[0][0][3];
// Apply Round Transforms
for (r = 1; r < st->rounds; r++) {
@ -169,33 +159,33 @@ void aes_encrypt (struct aes_state *st, ut8 *in, ut8 *result) {
FT3[(ut8)t1]);
a3 = (FT0[(ut8)(t3 >> 24)] ^ FT1[(ut8)(t0 >> 16)] ^ FT2[(ut8)(t1 >> 8)] ^
FT3[(ut8)t2]);
t0 = a0 ^ expkey[0][r][0];
t1 = a1 ^ expkey[0][r][1];
t2 = a2 ^ expkey[0][r][2];
t3 = a3 ^ expkey[0][r][3];
t0 = a0 ^ exp.key[0][r][0];
t1 = a1 ^ exp.key[0][r][1];
t2 = a2 ^ exp.key[0][r][2];
t3 = a3 ^ exp.key[0][r][3];
}
// Last Round is special
tt = expkey[0][st->rounds][0];
tt = exp.key[0][st->rounds][0];
result[0] = Sbox[(ut8)(t0 >> 24)] ^ (ut8)(tt >> 24);
result[1] = Sbox[(ut8)(t1 >> 16)] ^ (ut8)(tt >> 16);
result[2] = Sbox[(ut8)(t2 >> 8)] ^ (ut8)(tt >> 8);
result[3] = Sbox[(ut8)t3] ^ (ut8)tt;
tt = expkey[0][st->rounds][1];
tt = exp.key[0][st->rounds][1];
result[4] = Sbox[(ut8)(t1 >> 24)] ^ (ut8)(tt >> 24);
result[5] = Sbox[(ut8)(t2 >> 16)] ^ (ut8)(tt >> 16);
result[6] = Sbox[(ut8)(t3 >> 8)] ^ (ut8)(tt >> 8);
result[7] = Sbox[(ut8)t0] ^ (ut8)tt;
tt = expkey[0][st->rounds][2];
tt = exp.key[0][st->rounds][2];
result[8] = Sbox[(ut8)(t2 >> 24)] ^ (ut8)(tt >> 24);
result[9] = Sbox[(ut8)(t3 >> 16)] ^ (ut8)(tt >> 16);
result[10] = Sbox[(ut8)(t0 >> 8)] ^ (ut8)(tt >> 8);
result[11] = Sbox[(ut8)t1] ^ (ut8)tt;
tt = expkey[0][st->rounds][3];
tt = exp.key[0][st->rounds][3];
result[12] = Sbox[(ut8)(t3 >> 24)] ^ (ut8)(tt >> 24);
result[13] = Sbox[(ut8)(t0 >> 16)] ^ (ut8)(tt >> 16);
result[14] = Sbox[(ut8)(t1 >> 8)] ^ (ut8)(tt >> 8);
@ -206,14 +196,10 @@ void aes_encrypt (struct aes_state *st, ut8 *in, ut8 *result) {
// Rijndael's default block size (128-bit).
// in - The ciphertext.
// result - The plaintext generated from a ciphertext using the session key.
void aes_decrypt (struct aes_state *st, ut8 *in, ut8 *result) {
#if defined(_MSC_VER) || defined(__TINYC__)
ut32 expkey[2][Nr_AES256 + 1][Nb];
#else
ut32 expkey[2][st->rounds + 1][Nb];
#endif
void aes_decrypt(RCryptoAESState *st, ut8 *in, ut8 *result) {
RCryptoAESExponent exp = {0};
aes_expkey(st, expkey);
aes_expkey (st, &exp);
ut32 t0, t1, t2, t3, tt;
ut32 a0, a1, a2, a3, r;
@ -222,25 +208,25 @@ void aes_decrypt (struct aes_state *st, ut8 *in, ut8 *result) {
t0 |= *in++ << 16;
t0 |= *in++ << 8;
t0 |= *in++;
t0 ^= expkey[1][0][0];
t0 ^= exp.key[1][0][0];
t1 = *in++ << 24;
t1 |= *in++ << 16;
t1 |= *in++ << 8;
t1 |= *in++;
t1 ^= expkey[1][0][1];
t1 ^= exp.key[1][0][1];
t2 = *in++ << 24;
t2 |= *in++ << 16;
t2 |= *in++ << 8;
t2 |= *in++;
t2 ^= expkey[1][0][2];
t2 ^= exp.key[1][0][2];
t3 = *in++ << 24;
t3 |= *in++ << 16;
t3 |= *in++ << 8;
t3 |= *in++;
t3 ^= expkey[1][0][3];
t3 ^= exp.key[1][0][3];
// Apply round transforms
for (r = 1; r < st->rounds; r++) {
@ -248,32 +234,32 @@ void aes_decrypt (struct aes_state *st, ut8 *in, ut8 *result) {
a1 = (RT0[(ut8)(t1 >> 24)] ^ RT1[(ut8)(t0 >> 16)] ^ RT2[(ut8)(t3 >> 8)] ^ RT3[(ut8)t2]);
a2 = (RT0[(ut8)(t2 >> 24)] ^ RT1[(ut8)(t1 >> 16)] ^ RT2[(ut8)(t0 >> 8)] ^ RT3[(ut8)t3]);
a3 = (RT0[(ut8)(t3 >> 24)] ^ RT1[(ut8)(t2 >> 16)] ^ RT2[(ut8)(t1 >> 8)] ^ RT3[(ut8)t0]);
t0 = a0 ^ expkey[1][r][0];
t1 = a1 ^ expkey[1][r][1];
t2 = a2 ^ expkey[1][r][2];
t3 = a3 ^ expkey[1][r][3];
t0 = a0 ^ exp.key[1][r][0];
t1 = a1 ^ exp.key[1][r][1];
t2 = a2 ^ exp.key[1][r][2];
t3 = a3 ^ exp.key[1][r][3];
}
// Last Round is special
tt = expkey[1][st->rounds][0];
tt = exp.key[1][st->rounds][0];
result[0] = InvSbox[(ut8)(t0 >> 24)] ^ (ut8)(tt >> 24);
result[1] = InvSbox[(ut8)(t3 >> 16)] ^ (ut8)(tt >> 16);
result[2] = InvSbox[(ut8)(t2 >> 8)] ^ (ut8)(tt >> 8);
result[3] = InvSbox[(ut8)t1] ^ (ut8)tt;
tt = expkey[1][st->rounds][1];
tt = exp.key[1][st->rounds][1];
result[4] = InvSbox[(ut8)(t1 >> 24)] ^ (ut8)(tt >> 24);
result[5] = InvSbox[(ut8)(t0 >> 16)] ^ (ut8)(tt >> 16);
result[6] = InvSbox[(ut8)(t3 >> 8)] ^ (ut8)(tt >> 8);
result[7] = InvSbox[(ut8)t2] ^ (ut8)tt;
tt = expkey[1][st->rounds][2];
tt = exp.key[1][st->rounds][2];
result[8] = InvSbox[(ut8)(t2 >> 24)] ^ (ut8)(tt >> 24);
result[9] = InvSbox[(ut8)(t1 >> 16)] ^ (ut8)(tt >> 16);
result[10] = InvSbox[(ut8)(t0 >> 8)] ^ (ut8)(tt >> 8);
result[11] = InvSbox[(ut8)t3] ^ (ut8)tt;
tt = expkey[1][st->rounds][3];
tt = exp.key[1][st->rounds][3];
result[12] = InvSbox[(ut8)(t3 >> 24)] ^ (ut8)(tt >> 24);
result[13] = InvSbox[(ut8)(t2 >> 16)] ^ (ut8)(tt >> 16);
result[14] = InvSbox[(ut8)(t1 >> 8)] ^ (ut8)(tt >> 8);

View File

@ -3,14 +3,13 @@
#include <r_crypto.h>
#include <r_crypto/r_aes.h>
#include <memory.h>
struct aes_state {
ut8 key[32];
int key_size;
int columns;
int rounds;
};
typedef struct aes_state {
ut8 key[32];
int key_size;
int columns;
int rounds;
} RCryptoAESState;
/* forward tables */
@ -267,7 +266,7 @@ static const ut32 U3[256] = { UT };
#undef V
#undef UT
void aes_encrypt (struct aes_state*, ut8*, ut8*);
void aes_decrypt (struct aes_state*, ut8*, ut8*);
void aes_encrypt(RCryptoAESState*, ut8*, ut8*);
void aes_decrypt(RCryptoAESState*, ut8*, ut8*);
#endif

View File

@ -1,9 +1,9 @@
#ifndef R2_CRYPTO_H
#define R2_CRYPTO_H
#include "r_types.h"
#include "r_list.h"
#include "r_crypto/r_des.h"
#include <r_types.h>
#include <r_list.h>
#include <r_crypto/r_des.h>
#ifdef __cplusplus
extern "C" {

View File

@ -15,8 +15,7 @@
#define WANT_THREADS 1
#endif
#ifdef __GNUC__
# define HAVE_TH_LOCAL 1
#if defined (__GNUC__) && !__TINYC__
# define R_TH_LOCAL __thread
# define HAVE_STDATOMIC_H 0

View File

@ -106,7 +106,7 @@ R_API bool r_sys_tts(const char *txt, bool bg);
#if __WINDOWS__
# define r_sys_breakpoint() { __debugbreak (); }
#else
#if __GNUC__
#if __GNUC__ && !defined(__TINYC__)
# define r_sys_breakpoint() __builtin_trap()
#elif __i386__ || __x86_64__
# define r_sys_breakpoint() __asm__ volatile ("int3");

View File

@ -34,9 +34,6 @@
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#ifndef _MSC_VER
#include <math.h>
#endif
#include <signal.h>
#include <fcntl.h>
#ifndef __wasi__
@ -79,21 +76,8 @@ typedef UINT_PTR uintptr_t;
# define O_BINARY 0
#endif
// #include "stab.h"
#include "libtcc.h"
#ifndef __WINDOWS__
#include <inttypes.h>
#else
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;
#ifdef _MSC_VER
typedef signed char int8_t;
typedef long long int int64_t;
#endif
#endif
// TODO: Make it dependable from the r2 asm/anal settings
#define LDOUBLE_SIZE 12
@ -101,78 +85,13 @@ typedef long long int int64_t;
#define MAX_ALIGN 8
#define PTR_SIZE 4
#if !defined (__HAIKU__)
typedef uint64_t addr_t;
#endif
/* parser debug */
/* #define PARSE_DEBUG */
/* preprocessor debug */
/* #define PP_DEBUG */
/* include file debug */
/* memory leak debug */
/* #define MEM_DEBUG */
/* assembler debug */
/* #define ASM_DEBUG */
/* ------------ path configuration ------------ */
#ifndef CONFIG_SYSROOT
# define CONFIG_SYSROOT ""
#endif
#ifndef CONFIG_TCCDIR
# define CONFIG_TCCDIR "."
#endif
#ifndef CONFIG_LDDIR
# define CONFIG_LDDIR "lib"
#endif
/* path to find crt1.o, crti.o and crtn.o */
#ifndef CONFIG_TCC_CRTPREFIX
# define CONFIG_TCC_CRTPREFIX CONFIG_SYSROOT "/usr/" CONFIG_LDDIR
#endif
/* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
/* system include paths */
#ifndef CONFIG_TCC_SYSINCLUDEPATHS
# ifdef TCC_TARGET_PE
# define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi"
# elif defined CONFIG_MULTIARCHDIR
# define CONFIG_TCC_SYSINCLUDEPATHS \
CONFIG_SYSROOT "/usr/local/include" \
":" CONFIG_SYSROOT "/usr/local/include/" CONFIG_MULTIARCHDIR \
":" CONFIG_SYSROOT "/usr/include" \
":" CONFIG_SYSROOT "/usr/include/" CONFIG_MULTIARCHDIR \
":" "{B}/include"
# else
# define CONFIG_TCC_SYSINCLUDEPATHS \
CONFIG_SYSROOT "/usr/local/include" \
":" CONFIG_SYSROOT "/usr/include" \
":" "{B}/include"
# endif
#endif
/* library search paths */
#ifndef CONFIG_TCC_LIBPATHS
# ifdef TCC_TARGET_PE
# define CONFIG_TCC_LIBPATHS "{B}/lib;{B}"
# else
# define CONFIG_TCC_LIBPATHS \
CONFIG_SYSROOT "/usr/" CONFIG_LDDIR \
":" CONFIG_SYSROOT "/" CONFIG_LDDIR \
":" CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR
# endif
#endif
/* -------------------------------------------- */
// TODO: Read this from the configuration variables in r2
#define STACK_NEW0(type, arg) \
type arg; \
ZERO_FILL(arg)
ZERO_FILL(arg)
#define INCLUDE_STACK_SIZE 32
#define IFDEF_STACK_SIZE 64
@ -196,11 +115,7 @@ typedef struct TokenSym {
char str[1];
} TokenSym;
#ifdef TCC_TARGET_PE
typedef unsigned short nwchar_t;
#else
typedef int nwchar_t;
#endif
typedef struct CString {
int size; /* size in bytes */

View File

@ -2522,14 +2522,8 @@ static void decl_initializer(TCCState *s1, CType *type, unsigned long c, int fir
/* only parse strings here if correct type (otherwise: handle
them as ((w)char *) expressions */
if ((s1->tok == TOK_LSTR &&
/* FIXME: Handle platform here ! */
#ifdef TCC_TARGET_PE
(t1->t & VT_BTYPE) == VT_INT16 && (t1->t & VT_UNSIGNED)
#else
(t1->t & VT_BTYPE) == VT_INT32
#endif
) || (s1->tok == TOK_STR && (t1->t & VT_BTYPE) == VT_INT8)) {
// TARGET_PE ?? (t1->t & VT_BTYPE) == VT_INT16 && (t1->t & VT_UNSIGNED)
if ((s1->tok == TOK_LSTR && (t1->t & VT_BTYPE) == VT_INT32) || (s1->tok == TOK_STR && (t1->t & VT_BTYPE) == VT_INT8)) {
while (tcc_nerr (s1) == 0 && (s1->tok == TOK_STR || s1->tok == TOK_LSTR)) {
CString *cstr = s1->tokc.cstr;
/* compute maximum number of chars wanted */
@ -3023,7 +3017,7 @@ static int decl0(TCCState *s1, int l, int is_for_loop_init) {
if (ad.weak) {
type.t |= VT_WEAK;
}
#ifdef TCC_TARGET_PE
#if 0
if (ad.func_import) {
type.t |= VT_IMPORT;
}

View File

@ -1937,7 +1937,7 @@ num_too_long:
s1->tokc.f = (float) d;
} else if (t == 'L') {
ch = *p++;
#ifdef TCC_TARGET_PE
#if 0 // TARGET_PE
s1->tok = TOK_CDOUBLE;
s1->tokc.d = d;
#else

View File

@ -1,7 +1,5 @@
/* radare2 - LGPL - Copyright 2009-2022 - nibble, pancake, maijin */
#include <stdio.h>
#include <r_types.h>
#include <r_parse.h>
#include <config.h>
@ -35,11 +33,14 @@ R_API RParse *r_parse_new(void) {
}
R_API void r_parse_free(RParse *p) {
r_list_free (p->parsers);
free (p);
if (p) {
r_list_free (p->parsers);
free (p);
}
}
R_API bool r_parse_add(RParse *p, RParsePlugin *foo) {
r_return_val_if_fail (p && foo, false);
bool itsFine = foo->init? foo->init (p, p->user): true;
if (itsFine) {
r_list_append (p->parsers, foo);
@ -85,6 +86,7 @@ R_API bool r_parse_use(RParse *p, const char *name) {
// this function is a bit confussing, assembles C code into wat?, whehres theh input and wheres the output
// and its unused. so imho it sshould be DEPRECATED this conflicts with rasm.assemble imhoh
R_API bool r_parse_assemble(RParse *p, char *data, char *str) {
r_return_val_if_fail (p && data && str, false);
char *in = strdup (str);
bool ret = false;
char *s, *o;
@ -152,7 +154,8 @@ R_API char *r_parse_immtrim(char *opstr) {
return opstr;
}
R_API bool r_parse_subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) {
R_API bool r_parse_subvar(RParse *p, R_NULLABLE RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) {
r_return_val_if_fail (p, false);
if (p->cur && p->cur->subvar) {
return p->cur->subvar (p, f, addr, oplen, data, str, len);
}
@ -161,5 +164,6 @@ R_API bool r_parse_subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, cha
/* setters */
R_API void r_parse_set_user_ptr(RParse *p, void *user) {
r_return_if_fail (p && user);
p->user = user;
}

View File

@ -1317,8 +1317,9 @@ R_API bool r_sys_tts(const char *txt, bool bg) {
return false;
}
static R_TH_LOCAL char *prefix = NULL;
R_API const char *r_sys_prefix(const char *pfx) {
static R_TH_LOCAL char *prefix = NULL;
if (!prefix) {
#if __WINDOWS__
prefix = r_sys_get_src_dir_w32 ();

View File

@ -33,7 +33,7 @@ static bool lock_init(RThreadLock *thl, bool recursive) {
static bool r_atomic_exchange(volatile R_ATOMIC_BOOL *data, bool v) {
#if HAVE_STDATOMIC_H
return atomic_exchange_explicit (data, v, memory_order_acquire);
#elif __GNUC__
#elif __GNUC__ && !__TINYC__
int orig;
int conv = (int)v;
__atomic_exchange (data, &conv, &orig, __ATOMIC_ACQUIRE);
@ -51,7 +51,7 @@ static bool r_atomic_exchange(volatile R_ATOMIC_BOOL *data, bool v) {
static void r_atomic_store(volatile R_ATOMIC_BOOL *data, bool v) {
#if HAVE_STDATOMIC_H
atomic_store_explicit (data, v, memory_order_release);
#elif __GNUC__
#elif __GNUC__ && !__TINYC__
int conv = (int)v;
__atomic_store (data, &conv, __ATOMIC_RELEASE);
#elif _MSC_VER

View File

@ -16,8 +16,7 @@ LD?=ld
ifeq ($(OSTYPE),darwin)
PARTIALLD=${LD} -r -all_load
LDFLAGS_LIB=-dynamiclib
LDFLAGS_SONAME=-soname
# LDFLAGS_SONAME=-Wl,-install_name,
LDFLAGS_SONAME=-soname,
else
PARTIALLD=${LD} -r --whole-archive
LDFLAGS_LIB=-shared

View File

@ -535,9 +535,9 @@ static unsigned LZ4_NbCommonBytes (reg_t val)
unsigned long r = 0;
_BitScanForward64(&r, (U64)val);
return (unsigned)r >> 3;
# elif (defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 3) || \
# elif (!__TINYC__ && (defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 3) || \
((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))) && \
!defined(LZ4_FORCE_SW_BITCOUNT)
!defined(LZ4_FORCE_SW_BITCOUNT))
return (unsigned)__builtin_ctzll((U64)val) >> 3;
# else
const U64 m = 0x0101010101010101ULL;
@ -560,7 +560,7 @@ static unsigned LZ4_NbCommonBytes (reg_t val)
}
} else /* Big Endian CPU */ {
if (sizeof(val)==8) {
# if (defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 3) || \
# if (!__TINYC__ && defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 3) || \
((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))) && \
!defined(__TINYC__) && !defined(LZ4_FORCE_SW_BITCOUNT)
return (unsigned)__builtin_clzll((U64)val) >> 3;
@ -596,9 +596,9 @@ static unsigned LZ4_NbCommonBytes (reg_t val)
#endif
# endif
} else /* 32 bits */ {
# if (defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 3) || \
# if (!__TINYC__ && (defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 3) || \
((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))) && \
!defined(LZ4_FORCE_SW_BITCOUNT)
!defined(LZ4_FORCE_SW_BITCOUNT))
return (unsigned)__builtin_clz((U32)val) >> 3;
# else
val >>= 8;

View File

@ -1,4 +1,4 @@
#!/bin/sh
export CC="tcc"
exec sys/install.sh $*
exec sys/install.sh --with-compiler=tcc $*