【问题标题】:__ctype_b table and its usage__ctype_b 表及其用法
【发布时间】:2018-11-23 12:45:15
【问题描述】:

我有这段使用 __ctype_b 数组的 asm 代码,我试图了解它是什么,有人知道它在做什么吗?

ps:我知道 __ctype_b_loc() 是什么,这是不同的。

mov     eax, [rbp+counter]
cdqe
add     rax, [rbp+server_received_buffer]
movzx   eax, byte ptr [rax]
movsx   rax, al
add     rax, rax
mov     rdx, rax
mov     rax, cs:__ctype_b
lea     rax, [rdx+rax]
movzx   eax, word ptr [rax]
movzx   eax, ax
and     eax, 20h
test    eax, eax

【问题讨论】:

    标签: reverse-engineering glibc


    【解决方案1】:

    我找到了答案。 __ctype_b 是“__isctype_l”宏中使用的数组:

    #  define __isctype_l(c, type, locale) \
      ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
    

    在这里使用:

    #  define __isalnum_l(c,l)  __isctype_l((c), _ISalnum, (l))
    #  define __isalpha_l(c,l)  __isctype_l((c), _ISalpha, (l))
    #  define __iscntrl_l(c,l)  __isctype_l((c), _IScntrl, (l))
    #  define __isdigit_l(c,l)  __isctype_l((c), _ISdigit, (l))
    #  define __islower_l(c,l)  __isctype_l((c), _ISlower, (l))
    #  define __isgraph_l(c,l)  __isctype_l((c), _ISgraph, (l))
    #  define __isprint_l(c,l)  __isctype_l((c), _ISprint, (l))
    #  define __ispunct_l(c,l)  __isctype_l((c), _ISpunct, (l))
    #  define __isspace_l(c,l)  __isctype_l((c), _ISspace, (l))
    #  define __isupper_l(c,l)  __isctype_l((c), _ISupper, (l))
    #  define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l))
    #  define __isblank_l(c,l)  __isctype_l((c), _ISblank, (l))
    

    然后我们将到达这个枚举

    enum
    {
      _ISupper = _ISbit (0),    /* UPPERCASE.  */
      _ISlower = _ISbit (1),    /* lowercase.  */
      _ISalpha = _ISbit (2),    /* Alphabetic.  */
      _ISdigit = _ISbit (3),    /* Numeric.  */
      _ISxdigit = _ISbit (4),   /* Hexadecimal numeric.  */
      _ISspace = _ISbit (5),    /* Whitespace.  */
      _ISprint = _ISbit (6),    /* Printing.  */
      _ISgraph = _ISbit (7),    /* Graphical.  */
      _ISblank = _ISbit (8),    /* Blank (usually SPC and TAB).  */
      _IScntrl = _ISbit (9),    /* Control character.  */
      _ISpunct = _ISbit (10),   /* Punctuation.  */
      _ISalnum = _ISbit (11)    /* Alphanumeric.  */
    };
    

    现在我们需要了解 _ISbit 定义中的 0x20 代表什么

    # if __BYTE_ORDER == __BIG_ENDIAN
    #  define _ISbit(bit)   (1 << (bit))
    # else /* __BYTE_ORDER == __LITTLE_ENDIAN */
    #  define _ISbit(bit)   ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8))
    # endif
    

    0x20 : 0010 0000

    从 asm 代码我知道它是大端。所以班次数应该是 5 并且是 Whitespace。

    结论:asm 代码从 server_received_buffer 中找到 Whitespace

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-01
      • 2018-07-16
      • 1970-01-01
      • 2011-10-15
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多