/* wipepin.c */

/********************/
/* XDA PIN-WIPER    */
/* for MS-Windows   */
/********************/

/*------------*/
/*  INCLUDES  */
/*------------*/

#include "windows.h"
#include "resource.h"

/*-----------*/
/*  DEFINES  */
/*-----------*/

#define K_WIPEPIN_TIME  (180)
#define K_VALBUF_LEN    (256)

/*--------------*/
/*  STRUCTURES  */
/*--------------*/

/*--------------*/
/*  PROTOTYPES  */
/*--------------*/

static signed short wipe_valbuf (void);

/*-------------*/
/*  VARIABLEN  */
/*-------------*/

static unsigned char wipepin_valbuf[K_VALBUF_LEN];

/*--------------*/
/*  KONSTANTEN  */
/*--------------*/

/* Registry-Keys */
static const TCHAR wipepin_txt_regkey1[] = \
  TEXT ("ControlPanel\\PhoneExtendFunction");
static const TCHAR wipepin_txt_regkey2[] = \
  TEXT ("ExtendData");

/*============================================================================*/
/*                       W   I   P   E   -   P   I   N                        */
/*============================================================================*/

/*-----------------*/
/*  WINDOWS-ENTRY  */
/*-----------------*/
                                                               /* Entry-Point */
int APIENTRY WinMain (HINSTANCE inst, HINSTANCE pinst,
                      LPTSTR cmdline, int show)
{
  /* Wipe value-buffer */
  while (42)
  {
    wipe_valbuf ();
    Sleep (K_WIPEPIN_TIME * 1000);
  }
  return 0;
}

/*----*/

static signed short wipe_valbuf (void)                           /* Wipe Data */
{
  signed short n;
  DWORD type;
  DWORD len;
  HKEY key;
  LONG rc;

  /* Open key */
  rc = RegOpenKeyEx (HKEY_CURRENT_USER, wipepin_txt_regkey1, 0L, 0L, &key);
  if (rc)
    return 1;

  /* Read data */
  n = 0;
  rc = RegQueryValueEx (key, wipepin_txt_regkey2, NULL, &type, NULL, &len);
  if (rc)
    n = 2;
  else if (type != REG_BINARY)
    n = 3;
  else if (len != K_VALBUF_LEN)
    n = 4;
  if (!n)
  {
    rc = RegQueryValueEx (key, wipepin_txt_regkey2, NULL, &type, \
                          wipepin_valbuf, &len);
    if (rc)
      n = 5;
    else if (type != REG_BINARY)
      n = 6;
    else if (len != K_VALBUF_LEN)
      n = 7;
  }

  /* Write data */
  if (!n)
  {
    wipepin_valbuf[0] = 0x3F;
    wipepin_valbuf[1] = 0x3F;
    wipepin_valbuf[2] = 0x3F;
    wipepin_valbuf[3] = 0x3F;
    rc = RegSetValueEx (key, wipepin_txt_regkey2, 0L, type, wipepin_valbuf, \
                        len);
    if (rc)
      n = 8;
  }
  RegCloseKey (key);
  return n;
}


/*** EOF ***/

