//online parser:
https://www.bccn.net/run/
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
#define STUB
#define public typedef
#define class struct
#define private STUB
static uint32_t db[2][25] = {
{//DB.LOW[STANDARD]
#define name(ed, n) ed##n
//0xbe2f0a80227583a8,//82
#define L_82 0
#define H_82 L_82 + 1
[name(L, _82)] = 0x08a0f222,//[name(L, _82)] = 0x227583a8,
[name(H, _82)] = 0x8a3857eb,//[name(H, _82)] = 0xbe2f0a80,
//0xd49811000d9a6f10,//72
#define L_72 L_82 + 2
#define H_72 L_72 + 1
[name(L, _72)] = 0x001189d0,//[name(L, _72)] = 0x0d9a6f10,
[name(H, _72)] = 0x01f6a94d,//[name(H, _72)] = 0xd4981100,
//0x806231807d64d818,//48
#define L_48 L_72 + 2
#define H_48 L_48 + 1
[name(L, _48)] = 0x081326d7,//[name(L, _48)] = 0x7d64d818,
[name(H, _48)] = 0x818d4608,//[name(H, _48)] = 0x80623180,
//0x2bac058096230d58,//137
#define L_137 L_48 + 2
#define H_137 L_137 + 1
[name(L, _137)] = 0x0850ca69,//[name(L, _137)] = 0x96230d58,
[name(H, _137)] = 0x85d032b2,//[name(H, _137)] = 0x2bac0580,
#define L_229 L_137 + 2
#define H_229 L_229 + 1
//0x7c42590023650390,//229
[name(L, _229)] = 0x00952432,//[name(L, _229)] = 0x23650390,
[name(H, _229)] = 0x093056c7,//[name(H, _229)] = 0x7c425900,
//0x98cf200004e0b200,//83
#define L_83 L_229 + 2
#define H_83 L_83 + 1
[name(L, _83)] = 0x0002fc40,//[name(L, _83)] = 0x04e0b200,
[name(H, _83)] = 0x002b0e89,//[name(H, _83)] = 0x98cf2000,
//0x4fed6a80b3faa9a8,//102
#define L_102 L_83 + 2
#define H_102 L_102 + 1
[name(L, _102)] = 0x08a6de3b,//[name(L, _102)] = 0xb3faa9a8,
[name(H, _102)] = 0x8a9aaff4,//[name(H, _102)] = 0x4fed6a80,
//0x9df309807d29b598,//65
#define L_65 L_102 + 2
#define H_65 L_65 + 1
[name(L, _65)] = 0x08903fd7,//[name(L, _65)] = 0x7d29b598,
[name(H, _65)] = 0x895b92d9,//[name(H, _65)] = 0x9df30980,
//0xe4efc600036bd060,//131
#define L_131 L_65 + 2
#define H_131 L_131 + 1
[name(L, _131)] = 0x006cfe30,//[name(L, _131)] = 0x036bd060,
[name(H, _131)] = 0x060db64e,//[name(H, _131)] = 0xe4efc600,
//0x98b24c80334b53c8,//236
#define L_236 L_131 + 2
#define H_236 L_236 + 1
[name(L, _236)] = 0x08c42b33,//[name(L, _236)] = 0x334b53c8,
[name(H, _236)] = 0x8c35b489,//[name(H, _236)] = 0x98b24c80,
//0x97687500012ced50,//125
#define L_125 L_236 + 2
#define H_125 L_125 + 1
[name(L, _125)] = 0x00578610,//[name(L, _125)] = 0x012ced50,
[name(H, _125)] = 0x05dec279,//[name(H, _125)] = 0x97687500,
},
{//DB.MED[LEAP YEAR]
//scalable designing [db.descriptor] 2/3/2/1
//pattern REV(1-3) | REV(3-1) //LH1:HL3/HH1:LL3
//0x49d85c009e728dc0,//ADV-82
#define L_ADV_82 0
#define H_ADV_82 L_ADV_82 + 1
[name(L_ADV, _82)] = 0x00c58de9,//[name(L_ADV, _82)] = 0x9e728dc0,
[name(H_ADV, _82)] = 0x0cd82794,//[name(H_ADV, _82)] = 0x49d85c00,
//0x76549280f0054c28,//ADV-72
#define L_ADV_72 L_ADV_82 + 2
#define H_ADV_72 L_ADV_72 + 1
[name(L_ADV, _72)] = 0x0829450f,//[name(L_ADV, _72)] = 0xf0054c28,
[name(H_ADV, _72)] = 0x82c45067,//[name(H_ADV, _72)] = 0x76549280,
//0xe6f33d802fbc90d8,//ADV-137
#define L_ADV_137 L_ADV_72 + 2
#define H_ADV_137 L_ADV_137 + 1
[name(L_ADV, _137)] = 0x08d33ff2,//[name(L_ADV, _137)] = 0x2fbc90d8,
[name(H_ADV, _137)] = 0x8d09cb6e,//[name(H_ADV, _137)] = 0xe6f33d80,
//0xc1d87a80e5f43aa8,//ADV-229
#define L_ADV_229 L_ADV_137 + 2
#define H_ADV_229 L_ADV_229 + 1
[name(L_ADV, _229)] = 0x08a78d5e,//[name(L_ADV, _229)] = 0xe5f43aa8,
[name(H_ADV, _229)] = 0x8aa34f1c,//[name(H_ADV, _229)] = 0xc1d87a80,
}
};
public class db {
private uint32_t *db;
private int dptr;
private int secure;
}cdb, *pdb;
pdb vdb;
void* gen_mini_md5(void *vash)
{
int i;
uint64_t j;
//#define PRINT_ON
#ifdef PRINT_ON
printf("vash double = %.15lf\n", ((double *)vash)[0]);
for (i = 0; i < sizeof(double); i++)
printf("vash[%d] = 0x%x\n", i, ((uint8_t *)vash)[i]);
#endif
#define MAGIC_A 0x76543210
#define MAGIC_B 0xFEDCBA98
j = ((long int)MAGIC_B << 32 | MAGIC_A);
#ifdef PRINT_ON
printf("MAGIC_AB = 0x%lx\n", j);
#endif
for (i = 0; i < sizeof(double); i++) {
//i + 1 boundary exceeded
#define swap_nhl(_b) _b[i] = (_b[i] & 0x0f) << 4 | (_b[i + 1] >> 4)
swap_nhl(((uint8_t *)vash));
((uint8_t *)vash)[i] += ((uint8_t *)&j)[i];
#ifdef PRINT_ON
printf("vash[%d] = 0x%x\n", i, ((uint8_t *)vash)[i]);
#endif
}
#define UN_USED 0
#define HEAD (UN_USED + 1)
#define multi(a, b) (a * b)
((int *)vash)[UN_USED] = multi(((int *)vash)[HEAD], MAGIC_B);
((int *)vash)[HEAD] = multi(((int *)vash)[UN_USED], MAGIC_A);
#ifdef PRINT_ON
printf("vash double = %.15lf\n", ((double *)vash)[0]);
for (i = 0; i < sizeof(double); i++)
printf("vash[%d] = 0x%x\n", i, ((uint8_t *)vash)[i]);
#endif
return vash;
}
uint8_t* rev_bits(uint8_t *byte, int len);
uint64_t recover_data(uint32_t *raw);
int auth_stream(void *stream)
{
int i;
uint32_t a[2];
uint64_t checksum;
checksum = (unsigned long int)gen_mini_md5(stream);
#ifdef PRINT_ON
for (i = 0; i < sizeof(double); i++)
printf("csum[%d] = 0x%x\n", i, ((uint8_t *)checksum)[i]);
#endif
#define v8memcmp(src, dst) (src == dst)
#define alen(a) (sizeof(a) / sizeof(a[0]))
#define step_4w(_i) _i += ((4 + 4) / sizeof(db[0][0]))
for(i = 0, vdb->db = db[vdb->secure]; i < alen(db[vdb->secure]); step_4w(i)) {
a[0] = vdb->db[i]; a[1] = vdb->db[i + 1];
rev_bits((uint8_t *)&a[0], sizeof(uint32_t));
rev_bits((uint8_t *)&a[1], sizeof(uint32_t));
#ifdef PRINT_ON
printf("in auth[%d] = 0x%x\n", i, a[0]);
printf("in auth[%d] = 0x%x\n", i, a[1]);
#endif
if (v8memcmp(*((uint64_t *)checksum), recover_data(a))) {
vdb->dptr = i; return 1;
} else {
#ifdef PRINT_ON
#define MIS_INFO "mismatch DB record[%d]: "
printf(MIS_INFO"[0x%lx]\n", (i >> 1), *((uint64_t *)checksum));
#endif
}
}
return 0;
}
void db_update(void)
{
uint32_t t;
if (vdb->dptr) {
#define arg(ar, idx) ar[idx]
#define db_off(_of) arg(vdb->db, vdb->dptr + _of)
#define swap(a, b) { \
t = a; \
a = b; \
b = t; \
}
#ifdef PRINT_ON
printf("arg_a = 0x%x, %d\n", arg(vdb->db, vdb->dptr), vdb->dptr);
#endif
swap(arg(vdb->db, vdb->dptr), db_off(-2));
swap(arg(vdb->db, (vdb->dptr + 1)), db_off(-1));
#ifdef PRINT_ON
printf("arg_a = 0x%x, %d\n", arg(vdb->db, vdb->dptr), vdb->dptr);
#endif
}
}
int _main(int argc, char *argv)
{
#define new(_obj) malloc(sizeof(_obj))
//new_db_instance
vdb = new(cdb);
//secure level I II III
#define SECURE_LOW 0x0
#define SECURE_MEDIUM 0x1
#define SECURE_HIGH 0x02
vdb->secure = SECURE_LOW;
vdb->db = db[vdb->secure];
vdb->dptr = 0;
return 0;
}
void Apply_4_access_priv(int *dp)
{
#define PULL_UP_PRIV +1
#define PUSH_DN_PRIV -1
#define is_low_priv(_p) !(_p)
if (is_low_priv(*dp)) *dp += PULL_UP_PRIV;
}
uint8_t* rev_bits(uint8_t *byte, int len)
{
if (1 == len) {
#define __swap_bits(_b) (_b << 4) | (_b >> 4)
#define assign_b(_b) (_b) = __swap_bits(_b)
assign_b(byte[0]); return byte;
}
return (assign_b(byte[0]), rev_bits(byte + 1, len - 1));
}
uint64_t recover_data(uint32_t *raw)
{
static uint8_t strategy_tbl[] = {
7, 6, 5, 0, 3, 2, 1, 4
};
uint64_t rdata = 0;
int i;
for (i = 0; i < sizeof(uint64_t); i++)
((uint8_t *)&rdata)[i] = ((uint8_t *)raw)[strategy_tbl[i]];
#ifdef PRINT_ON
printf("rdata = %lx\n", rdata);
#endif
return rdata;
}
int main(int argc, char *argv[])
{
int i;
#define YEAR_FM "年龄[%d]对应的秒数为:%g\n"
#define REC_D "---------------------\n"
#define year ((unsigned char *)main)[i]
#define SEC year * YEAR_SEC
#define YEAR_SEC 3.156e7
#define LEAP_YEAR_MP ((year >> 2) * 24 * 3600)
#define MED_SEC SEC + LEAP_YEAR_MP
/*3.1415926 0x4a 0xd8 0x12 0x4d 0xfb 0x21 0x9 0x40*/
double sec;
_main(0, "Module: Init db instance");
#define TST_ADV
#ifndef TST_ADV
for (i = 0, sec = SEC; i < 10; i++, sec = SEC) {
#else
for (i = 0, sec = MED_SEC; i < 5; i++, sec = MED_SEC) {
#endif
#ifdef PRINT_ON
printf("main = 0x%x\n", ((unsigned char *)main)[i]);
#endif
//default level I Authentication
if (auth_stream(&sec)) {
#define _SEP_(MA, MB) MA MB
printf(_SEP_(YEAR_FM, REC_D), year, SEC);
//hit-up
db_update();
} else if (!vdb->secure) {
//switch 2 a higher priv-DB
#ifdef PRINT_ON
puts("ready to switch db...");
#endif
Apply_4_access_priv(&vdb->secure);
#define roll_back() --i
roll_back();
}
}
//scalable coding v_free 4 Garbage Collection
free(vdb);
return 0;
}