C++ 各种操作

2018-03-07  本文已影响13人  that_is_this

1. 文件读写

 fseek(fp, Elf32SectionHeader.sh_offset, SEEK_SET);
    fread(lpStringTable, Elf32SectionHeader.sh_size, 1, fp);
    fseek(fp, Elf32Header.e_shoff, SEEK_SET);

2. 字符数组

unsigned char data[1] = {0x01}
unsigned  off;
st_st32(&off, sizeof(data));



    unsigned char data[24] = {
        0xC0, 0x46, 0xFF, 0xB5, 0x79, 0x46, 0x14, 0x39, 0x0A, 0x1C, 0x13, 0x68,
        0xD5, 0x1A, 0x04, 0x3A, 0x16, 0x68, 0x76, 0x19, 0x01, 0x3E, 0xB7, 0x46
    };
    
    upx_byte *p = getLoader();
    lsize = getLoaderSize();
    unsigned raw_lsize = lsize;
    lsize = lsize + sizeof(data) + 8;
    updateLoader(fo);
    patchLoaderChecksum();
    printf("----- print hex loader  --------");
    for (int i = 0; i < lsize; i++) {
        if(i%16 == 0) {
       printf(" \n");
    }
    printf(" %02x", p[i]);
    }
    //hex_print(p, lsize);
    printf("----- loader size : %d , raw_size: %d \n,", lsize, raw_lsize);
    fo->write(p, raw_lsize);
    
    unsigned lwrite;
    set_te32(&lwrite, loader_off);
    fo->write(&lwrite, sizeof(lwrite));
    
    unsigned cur_off = fo->st_size();
    unsigned cur;
    set_te32(&cur, cur_off);
    fo->write(&cur, sizeof(cur));
    cur_off = fo->st_size();
    printf("cur_off : %d, fo->size : %d \n", cur, cur_off);
    entry_off = fo->st_size();

    fo->write(data, sizeof(data));
上一篇下一篇

猜你喜欢

热点阅读