[PATCH] dixfonts: Deobfuscate GC ops calls.

Alex Deucher alexdeucher at gmail.com
Tue Jul 13 19:12:47 PDT 2010


On Tue, Jul 13, 2010 at 6:35 PM, Jamey Sharp <jamey at minilop.net> wrote:
> Signed-off-by: Jamey Sharp <jamey at minilop.net>
> ---
>  dix/dixfonts.c     |   54 ++++++++++++++++++++-------------------------------
>  include/closestr.h |   24 -----------------------
>  2 files changed, 21 insertions(+), 57 deletions(-)
>
> diff --git a/dix/dixfonts.c b/dix/dixfonts.c
> index 4a8f113..91092be 100644
> --- a/dix/dixfonts.c
> +++ b/dix/dixfonts.c
> @@ -1175,6 +1175,7 @@ doPolyText(ClientPtr client, PTclosurePtr c)
>     enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT;
>     FontPathElementPtr fpe;
>     GC *origGC = NULL;
> +    int itemSize = c->reqType == X_PolyText8 ? 1 : 2;
>
>     if (client->clientGone)
>     {
> @@ -1260,10 +1261,6 @@ doPolyText(ClientPtr client, PTclosurePtr c)
>                    val.ptr = pFont;
>                    ChangeGC(NullClient, c->pGC, GCFont, &val);
>                    ValidateGC(c->pDraw, c->pGC);
> -                   if (c->reqType == X_PolyText8)
> -                       c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8;
> -                   else
> -                       c->polyText = (PolyTextPtr) c->pGC->ops->PolyText16;
>                }
>
>                /* Undo the refcnt++ we performed when going to sleep */
> @@ -1275,7 +1272,7 @@ doPolyText(ClientPtr client, PTclosurePtr c)
>        else    /* print a string */
>        {
>            unsigned char *pNextElt;
> -           pNextElt = c->pElt + TextEltHeader + (*c->pElt)*c->itemSize;
> +           pNextElt = c->pElt + TextEltHeader + (*c->pElt) * itemSize;
>            if ( pNextElt > c->endReq)
>            {
>                err = BadLength;
> @@ -1288,7 +1285,7 @@ doPolyText(ClientPtr client, PTclosurePtr c)
>            }
>            if (c->pDraw)
>            {
> -               lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, c->itemSize,
> +               lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, itemSize,
>                                   c->pElt + TextEltHeader);
>            }
>            else lgerr = Successful;
> @@ -1387,8 +1384,12 @@ doPolyText(ClientPtr client, PTclosurePtr c)
>            if (c->pDraw)
>            {
>                c->xorg += *((INT8 *)(c->pElt + 1));    /* must be signed */
> -               c->xorg = (* c->polyText)(c->pDraw, c->pGC, c->xorg, c->yorg,
> -                   *c->pElt, c->pElt + TextEltHeader);
> +               if (c->reqType == X_PolyText8)
> +                   c->xorg = (* c->pGC->ops->PolyText8)(c->pDraw, c->pGC, c->xorg, c->yorg,
> +                       *c->pElt, (char *) (c->pElt + TextEltHeader));
> +               else
> +                   c->xorg = (* c->pGC->ops->PolyText16)(c->pDraw, c->pGC, c->xorg, c->yorg,
> +                       *c->pElt, (unsigned short *) (c->pElt + TextEltHeader));


What's going on here?  c->xorg += *((INT8 *)(c->pElt + 1)); followed
by c->xorg = ...
Can the += line be removed?

Alex

>            }
>            c->pElt = pNextElt;
>        }
> @@ -1447,16 +1448,7 @@ PolyText(ClientPtr client, DrawablePtr pDraw, GC *pGC, unsigned char *pElt,
>     local_closure.pDraw = pDraw;
>     local_closure.xorg = xorg;
>     local_closure.yorg = yorg;
> -    if ((local_closure.reqType = reqType) == X_PolyText8)
> -    {
> -       local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText8;
> -       local_closure.itemSize = 1;
> -    }
> -    else
> -    {
> -       local_closure.polyText =  (PolyTextPtr) pGC->ops->PolyText16;
> -       local_closure.itemSize = 2;
> -    }
> +    local_closure.reqType = reqType;
>     local_closure.pGC = pGC;
>     local_closure.did = did;
>     local_closure.err = Success;
> @@ -1475,6 +1467,7 @@ doImageText(ClientPtr client, ITclosurePtr c)
>  {
>     int err = Success, lgerr;  /* err is in X error, not font error, space */
>     FontPathElementPtr fpe;
> +    int itemSize = c->reqType == X_ImageText8 ? 1 : 2;
>
>     if (client->clientGone)
>     {
> @@ -1499,7 +1492,7 @@ doImageText(ClientPtr client, ITclosurePtr c)
>        }
>     }
>
> -    lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data);
> +    lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, itemSize, c->data);
>     if (lgerr == Suspended)
>     {
>         if (!c->slept) {
> @@ -1521,14 +1514,14 @@ doImageText(ClientPtr client, ITclosurePtr c)
>            *new_closure = *c;
>            c = new_closure;
>
> -           data = malloc(c->nChars * c->itemSize);
> +           data = malloc(c->nChars * itemSize);
>            if (!data)
>            {
>                free(c);
>                err = BadAlloc;
>                goto bail;
>            }
> -           memmove(data, c->data, c->nChars * c->itemSize);
> +           memmove(data, c->data, c->nChars * itemSize);
>            c->data = data;
>
>            pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen);
> @@ -1567,8 +1560,12 @@ doImageText(ClientPtr client, ITclosurePtr c)
>     }
>     if (c->pDraw)
>     {
> -       (* c->imageText)(c->pDraw, c->pGC, c->xorg, c->yorg,
> -           c->nChars, c->data);
> +       if (c->reqType == X_ImageText8)
> +           (* c->pGC->ops->ImageText8)(c->pDraw, c->pGC, c->xorg, c->yorg,
> +               c->nChars, (char *) c->data);
> +       else
> +           (* c->pGC->ops->ImageText16)(c->pDraw, c->pGC, c->xorg, c->yorg,
> +               c->nChars, (unsigned short *) c->data);
>     }
>
>  bail:
> @@ -1605,16 +1602,7 @@ ImageText(ClientPtr client, DrawablePtr pDraw, GC *pGC, int nChars,
>     local_closure.data = data;
>     local_closure.xorg = xorg;
>     local_closure.yorg = yorg;
> -    if ((local_closure.reqType = reqType) == X_ImageText8)
> -    {
> -       local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText8;
> -       local_closure.itemSize = 1;
> -    }
> -    else
> -    {
> -       local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText16;
> -       local_closure.itemSize = 2;
> -    }
> +    local_closure.reqType = reqType;
>     local_closure.did = did;
>     local_closure.slept = FALSE;
>
> diff --git a/include/closestr.h b/include/closestr.h
> index 2cd67b1..1660151 100644
> --- a/include/closestr.h
> +++ b/include/closestr.h
> @@ -100,16 +100,6 @@ typedef struct _LFclosure {
>
>  /* PolyText */
>
> -typedef
> -    int                        (* PolyTextPtr)(
> -                       DrawablePtr /* pDraw */,
> -                       GCPtr /* pGC */,
> -                       int /* x */,
> -                       int /* y */,
> -                       int /* count */,
> -                       void * /* chars or shorts */
> -                       );
> -
>  typedef struct _PTclosure {
>     ClientPtr          client;
>     DrawablePtr                pDraw;
> @@ -120,8 +110,6 @@ typedef struct _PTclosure {
>     int                        xorg;
>     int                        yorg;
>     CARD8              reqType;
> -    PolyTextPtr                polyText;
> -    int                        itemSize;
>     XID                        did;
>     int                        err;
>     Bool               slept;
> @@ -129,16 +117,6 @@ typedef struct _PTclosure {
>
>  /* ImageText */
>
> -typedef
> -    void               (* ImageTextPtr)(
> -                       DrawablePtr /* pDraw */,
> -                       GCPtr /* pGC */,
> -                       int /* x */,
> -                       int /* y */,
> -                       int /* count */,
> -                       void * /* chars or shorts */
> -                       );
> -
>  typedef struct _ITclosure {
>     ClientPtr          client;
>     DrawablePtr                pDraw;
> @@ -148,8 +126,6 @@ typedef struct _ITclosure {
>     int                        xorg;
>     int                        yorg;
>     CARD8              reqType;
> -    ImageTextPtr       imageText;
> -    int                        itemSize;
>     XID                        did;
>     Bool               slept;
>  } ITclosureRec;
> --
> 1.7.0
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>


More information about the xorg-devel mailing list