//online parser: 
https://www.bccn.net/run/

程序代码:
#define iostream <stdio.h>
#include iostream
#include <stdlib.h>
//#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
//#pragma GCC diagnostic ignored "-Wint-conversion"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
#define X64_ABI
#define PRINT_ON 1
void fill_vector(void *vx, ...)
{
    //X64 using a new system-V ABI totally different from old x86-platform
    //rdi,rsi,rdx,rcx,r8,r9
    register int pid asm("%rsi");
    register int vid asm("%rdx");
    int i;
    static int p, v;
#define VA_PID 0
#define VB_PID VA_PID + 1
#define VC_PID VA_PID + 2
#define VD_PID VA_PID + 3
#define VA_VID main
#define VB_VID VA_VID + 0x1000
#define VA_LEN 511
#define SYM 0x0C3
#define CAST2A(a, v) ((unsigned char *)(a))[v]
typedef unsigned char(*vt)[VA_LEN + 1];
#define CAST2AE(x, p, v) ((vt)(x))[p][v]
#ifndef X64_ABI
    //old x86 ABI abandoned!!
    //bypass local variables
    //local [+0x28]i 
    //__asm__("popq %rax");//skip i
    //__asm__("popq %rax");//skip i x64 specified
    //[+0x20]v->[0x18]p->[0x10]vx->[0x8]pid->[0x0]vid
    //__asm__("popq %rax");//skip vid random reg
    //__asm__("popq %rax");//skip pid random reg
    //__asm__("popq %rax");//skip vx
    //arg1
    //__asm__("popq %rax");//get arg_p
    //arg2
    //__asm__("popq %rdx");//get arg_v
#endif
#define SAV(_s, _id) (_s) = (_id)
    SAV(p, pid);
    SAV(v, vid);
    for(i = 0; CAST2A(v, i) != SYM; i++) {
#define name(_s) #_s
        //bug fixed cause of X64 ABI
#define BUG_ON_PRINTF_NOW_ITS_OKAY
#if(0 == PRINT_ON)
        printf("%02d: %s[%02d] = 0x%x\n", i, name(main), i, CAST2A(v, i));
#endif
        CAST2AE(vx, p, i) = CAST2A(v, i);
        if(0xff == CAST2AE(vx, p, VA_LEN)++)
        CAST2AE(vx, p, (VA_LEN - 1))++;
    }
}
void compile_x86_abi(void)
{
#ifndef X64_ABI
    //online parser have no root to play, 2333
    system("sudo apt-get install libc6-dev-i386");
    system("gcc -m32 *.c -o v.out");
    system("ls");
#endif
}
int main(int argc, char *argv[])
{
    unsigned char vector[4][VA_LEN + 1];
    int i, j;
    
#define PID(_p) V##_p##_PID
#define VID(_v) V##_v##_VID
    fill_vector(vector,  PID(A), VID(A));
#define vsa vector[VA_PID]
#define vlen(_v) _v[VA_LEN] + _v[VA_LEN - 1] * 0x100
#if(0 == PRINT_ON)
    printf("len = %d, ret = 0x%x\n", vlen(vsa), CAST2A(VID(A), vlen(vsa)));
#endif
#define cout puts(
#define endl )
#if(0 == PRINT_ON)
    for(i = 0, j = vlen(vsa); i < j; i++, j--) {
        if(vsa[i] != vsa[j]) cout"case1: no"endl;
        else cout"case1: yes"endl;
    }
#else
    cout"PRINT_ON(0)/OFF(1)"endl;
#endif
    compile_x86_abi();
    return 0;
}
[此贴子已经被作者于2021-9-10 16:15编辑过]