getkeys

decompiled_code:
__int64 __fastcall sbbs_t::getkeys(sbbs_t *this, char *a2, unsigned __int64 a3)
{
__int64 result; // rax
char dest[95]; // [rsp+20h] [rbp-70h] BYREF
unsigned __int8 v6; // [rsp+7Fh] [rbp-11h]
unsigned __int64 v7; // [rsp+80h] [rbp-10h]
char v8; // [rsp+8Eh] [rbp-2h]
char v9; // [rsp+8Fh] [rbp-1h]

v9 = 0;
v8 = 0;
v7 = 0LL;
strncpy(dest, a2, 0x51uLL);
dest[80] = 0;
strupr(dest);
while ( 1 )
{
while ( 1 )
{
do
{
if ( !*((_QWORD *)this + 6413) )
return -1LL;
v6 = sbbs_t::getkey(this, 1LL);
}
while ( a3 && (v6 & 0x80u) != 0 );
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
{
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return -1LL;
}
if ( !v6 || v9 || !strchr(dest, v6) )
break;
sbbs_t::outchar(this, v6);
if ( (*((_QWORD *)this + 3362) & 0x40000LL) == 0 || v6 <= 0x20u )
goto LABEL_22;
do
{
if ( !*((_QWORD *)this + 6413) )
break;
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
break;
v8 = sbbs_t::getkey(this, 0LL);
if ( v8 == 13 )
break;
}
while ( v8 != 8 && v8 != 127 );
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
return -1LL;
}
if ( v8 != 8 && v8 != 127 )
{
LABEL_22:
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v6;
}
sbbs_t::backspace(this);
}
if ( v6 == 13 && a3 )
break;
if ( (v6 == 8 || v6 == 127) && v9 )
{
sbbs_t::backspace(this);
v7 /= 0xAuLL;
--v9;
}
else if ( a3 && (unsigned int)v6 - 48 <= 9 && a3 >= 10 * v7 + (v6 & 0xF) && (v6 != 48 || v9) )
{
v7 *= 10LL;
++v9;
v7 += v6 & 0xF;
sbbs_t::outchar(this, v6);
if ( a3 < 10 * v7 && (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
{
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v7 | 0x80000000;
}
}
}
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
if ( v9 )
result = v7 | 0x80000000;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func4(sbbs_t *this, char *a2, unsigned __int64 a3)
{
__int64 result; // rax
char dest[95]; // [rsp+20h] [rbp-70h] BYREF
unsigned __int8 v6; // [rsp+7Fh] [rbp-11h]
unsigned __int64 v7; // [rsp+80h] [rbp-10h]
char v8; // [rsp+8Eh] [rbp-2h]
char v9; // [rsp+8Fh] [rbp-1h]

v9 = 0;
v8 = 0;
v7 = 0LL;
strncpy(dest, a2, 0x51uLL);
dest[80] = 0;
strupr(dest);
while ( 1 )
{
while ( 1 )
{
do
{
if ( !*((_QWORD *)this + 6413) )
return -1LL;
v6 = sbbs_t::func0(this, 1LL);
}
while ( a3 && (v6 & 0x80u) != 0 );
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
{
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return -1LL;
}
if ( !v6 || v9 || !strchr(dest, v6) )
break;
sbbs_t::outchar(this, v6);
if ( (*((_QWORD *)this + 3362) & 0x40000LL) == 0 || v6 <= 0x20u )
goto LABEL_22;
do
{
if ( !*((_QWORD *)this + 6413) )
break;
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
break;
v8 = sbbs_t::func0(this, 0LL);
if ( v8 == 13 )
break;
}
while ( v8 != 8 && v8 != 127 );
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
{
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
return -1LL;
}
if ( v8 != 8 && v8 != 127 )
{
LABEL_22:
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v6;
}
sbbs_t::backspace(this);
}
if ( v6 == 13 && a3 )
break;
if ( (v6 == 8 || v6 == 127) && v9 )
{
sbbs_t::backspace(this);
v7 /= 0xAuLL;
--v9;
}
else if ( a3 && (unsigned int)v6 - 48 <= 9 && a3 >= 10 * v7 + (v6 & 0xF) && (v6 != 48 || v9) )
{
v7 *= 10LL;
++v9;
v7 += v6 & 0xF;
sbbs_t::outchar(this, v6);
if ( a3 < 10 * v7 && (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
{
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v7 | 0x80000000;
}
}
}
sbbs_t::attr(this, 7);
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
if ( v9 )
result = v7 | 0x80000000;
else
result = 0LL;
return result;
}

original_code:
int getkeys(char *instr,int max)
{
 char str[256];
 unsigned char ch,n=0;
 int i=0;
 sprintf(str,"%.*s",sizeof(str)-1,instr);
 strupr(str);
 while(!aborted) {
  ch=getkey((1<<0));
  if(max && ch>0x7f)
   continue;
  if(ch && !n && (strchr(str,ch))) {
   outchar(ch);
   attr(LIGHTGRAY);
   { outchar('\r'); outchar('\n'); };
   return(ch);
  }
  if(ch=='\r' && max) {
   attr(LIGHTGRAY);
   { outchar('\r'); outchar('\n'); };
   if(n)
    return(i|0x8000);
   return(0);
  }
  if(ch=='\b' && n) {
   bputs("\b \b");
   i/=10;
   n--;
  }
  else if(max && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit) && (i*10)+(ch&0xf)<=max && (ch!='0' || n)) {
   i*=10;
   n++;
   i+=ch&0xf;
   outchar(ch);
   if(i*10>max) {
    attr(LIGHTGRAY);
    { outchar('\r'); outchar('\n'); };
    return(i|0x8000);
   }
  }
 }
 return(0);
}

canonical_original_code:
int getkeys(char *instr, int max)
{
 char str[256];
 unsigned char ch; unsigned char n = 0;
 int i = 0;
 sprintf(str,"%.*s",sizeof(str)-1,instr);
 strupr(str);
 while(!aborted) {
  ch=getkey((1<<0));
  if(max && ch>0x7f)
   continue;
  if(ch && !n && (strchr(str,ch))) {
   outchar(ch);
   attr(LIGHTGRAY);
   { outchar('\r'); outchar('\n'); };
   return(ch);
  }
  if(ch=='\r' && max) {
   attr(LIGHTGRAY);
   { outchar('\r'); outchar('\n'); };
   if(n)
    return(i|0x8000);
   return(0);
  }
  if(ch=='\b' && n) {
   bputs("\b \b");
   i/=10;
   n--;
  }
  else if(max && ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit) && (i*10)+(ch&0xf)<=max && (ch!='0' || n)) {
   i*=10;
   n++;
   i+=ch&0xf;
   outchar(ch);
   if(i*10>max) {
    attr(LIGHTGRAY);
    { outchar('\r'); outchar('\n'); };
    return(i|0x8000);
   }
  }
 }
 return(0);
}

variable_types:
instr
char *

variable_types: max int

variable_types:
str
char [256]

variable_types:
ch
unsigned char

variable_types:
n
unsigned char

variable_types: i int


repo: ftnapps/pkg-sbbs

decompiled_code:
__int64 js_sprintf_free()
{
return xp_asprintf_free();
}

canonical_decompiled_code:
__int64 func1()
{
return xp_asprintf_free();
}

original_code:
void
js_sprintf_free(char* p)
{
 xp_asprintf_free(p);
}

canonical_original_code:
void js_sprintf_free(char *p)
{
 xp_asprintf_free(p);
}

variable_types:
p
char *

return_type: void


uudecode

original_code:
int uudecode(char *target, size_t tlen, const char *source, size_t slen)
{
 int i;
 char ch;
 size_t rd=0;
 size_t wr=0;
 size_t block;
 size_t len;
 unsigned char cell[4];
 if(slen==0)
  slen=strlen(source);
 while(rd<slen && wr<tlen) {
  ch=source[rd++];
  if(ch<' ')
   continue;
  len=(ch-' ')&0x3f;
  if(len<=0 || rd>=slen)
   break;
  block=0;
  while(block<len && wr<tlen && rd<slen) {
   memset(cell,0,sizeof(cell));
   for(i=0;i<sizeof(cell) && rd<slen;i++) {
    cell[i]=source[rd++];
    if(cell[i]>=' ') cell[i]-=' ';
   }
   target[wr]=(cell[0]&0x3f)<<2;
   target[wr++]|=(cell[1]&0x30)>>4;
   target[wr]=(cell[1]&0x0f)<<4;
   target[wr++]|=(cell[2]&0x3c)>>2;
   target[wr]=(cell[2]&0x03)<<6;
   target[wr++]|=cell[3]&0x3f;
   block+=3;
  }
  while(rd<slen && source[rd]>' ')
   rd++;
  while(rd<slen && source[rd]!=0 && source[rd]<=' ')
   rd++;
 }
 return(wr);
}

canonical_original_code:
int uudecode(char *target, unsigned long tlen, char *source, unsigned long slen)
{
 int i;
 char ch;
 unsigned long rd = 0;
 unsigned long wr = 0;
 unsigned long block;
 unsigned long len;
 unsigned char cell[4];
 if(slen==0)
  slen=strlen(source);
 while(rd<slen && wr<tlen) {
  ch=source[rd++];
  if(ch<' ')
   continue;
  len=(ch-' ')&0x3f;
  if(len<=0 || rd>=slen)
   break;
  block=0;
  while(block<len && wr<tlen && rd<slen) {
   memset(cell,0,sizeof(cell));
   for(i=0;i<sizeof(cell) && rd<slen;i++) {
    cell[i]=source[rd++];
    if(cell[i]>=' ') cell[i]-=' ';
   }
   target[wr]=(cell[0]&0x3f)<<2;
   target[wr++]|=(cell[1]&0x30)>>4;
   target[wr]=(cell[1]&0x0f)<<4;
   target[wr++]|=(cell[2]&0x3c)>>2;
   target[wr]=(cell[2]&0x03)<<6;
   target[wr++]|=cell[3]&0x3f;
   block+=3;
  }
  while(rd<slen && source[rd]>' ')
   rd++;
  while(rd<slen && source[rd]!=0 && source[rd]<=' ')
   rd++;
 }
 return(wr);
}

variable_types:
target
char *

variable_types:
tlen
unsigned long

variable_types:
source
char *

variable_types:
slen
unsigned long

variable_types: ch char

variable_types:
rd
unsigned long

variable_types:
wr
unsigned long

variable_types:
block
unsigned long

variable_types:
len
unsigned long

variable_types:
cell
unsigned char [4]

return_type: int


uuencode

original_code:
int uuencode(char *target, size_t tlen, const char *source, size_t slen)
{
 size_t rd=0;
 size_t wr=0;
 size_t block;
 size_t len;
 if(slen==0)
  slen=strlen(source);
 if(tlen<3)
  return(-1);
 tlen-=3;
 while(rd<=slen && wr<tlen) {
  len=45;
  if(rd+len>slen)
   len=slen-rd;
  if((len)==0) (len)='`'; else (len)+=' ';;
  target[wr++]=len;
  block=0;
  while(block<len && wr<tlen && rd<slen) {
   target[wr]=source[rd]>>2;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=(source[rd++]&0x03)<<4;
   target[wr]|=source[rd]>>4;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=(source[rd++]&0x0f)<<2;
   target[wr]|=source[rd]>>6;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=source[rd++]&0x3f;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   block+=3;
  }
  if(wr<tlen) {
   target[wr++]='\r';
   target[wr++]='\n';
  }
  if(rd>=slen)
   break;
 }
 if(wr<tlen)
  target[wr++]=0;
 return(wr);
}

canonical_original_code:
int uuencode(char *target, unsigned long tlen, char *source, unsigned long slen)
{
 unsigned long rd = 0;
 unsigned long wr = 0;
 unsigned long block;
 unsigned long len;
 if(slen==0)
  slen=strlen(source);
 if(tlen<3)
  return(-1);
 tlen-=3;
 while(rd<=slen && wr<tlen) {
  len=45;
  if(rd+len>slen)
   len=slen-rd;
  if((len)==0) (len)='`'; else (len)+=' ';;
  target[wr++]=len;
  block=0;
  while(block<len && wr<tlen && rd<slen) {
   target[wr]=source[rd]>>2;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=(source[rd++]&0x03)<<4;
   target[wr]|=source[rd]>>4;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=(source[rd++]&0x0f)<<2;
   target[wr]|=source[rd]>>6;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   target[wr]=source[rd++]&0x3f;
   if((target[wr])==0) (target[wr])='`'; else (target[wr])+=' ';; wr++;
   block+=3;
  }
  if(wr<tlen) {
   target[wr++]='\r';
   target[wr++]='\n';
  }
  if(rd>=slen)
   break;
 }
 if(wr<tlen)
  target[wr++]=0;
 return(wr);
}


SetEvent

decompiled_code:
__int64 __fastcall SetEvent(__int64 a1)
{
__int64 result; // rax

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)(a1 + 96) = 1;
if ( *(_QWORD *)(a1 + 104) )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)(a1 + 96) = 1;
if ( *(_QWORD *)(a1 + 104) )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
SetEvent(xpevent_t event)
{
 if (event==((void *)0) || (event->magic != ((u_int32_t) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 event->value=1;
 if (event->nwaiters > 0) {
  pthread_cond_broadcast(&event->gtzero);
 }
 pthread_mutex_unlock(&event->lock);
 return(1);
}

canonical_original_code:
int SetEvent(struct xpevent *event)
{
 if (event==((void *)0) || (event->magic != ((unsigned int) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 event->value=1;
 if (event->nwaiters > 0) {
  pthread_cond_broadcast(&event->gtzero);
 }
 pthread_mutex_unlock(&event->lock);
 return(1);
}

variable_types: struct xpevent { unsigned int magic; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; int value; int mreset; unsigned long nwaiters; } *

user_defined_types: struct xpevent { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t gtzero; int value; int mreset; unsigned long nwaiters; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


ResetEvent

decompiled_code:
__int64 __fastcall ResetEvent(__int64 a1)
{
__int64 result; // rax

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)(a1 + 96) = 0;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)(a1 + 96) = 0;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ResetEvent(xpevent_t event)
{
 if (event==((void *)0) || (event->magic != ((u_int32_t) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 event->value=0;
 pthread_mutex_unlock(&event->lock);
 return(1);
}

canonical_original_code:
int ResetEvent(struct xpevent *event)
{
 if (event==((void *)0) || (event->magic != ((unsigned int) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 event->value=0;
 pthread_mutex_unlock(&event->lock);
 return(1);
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


CloseEvent

decompiled_code:
__int64 __fastcall CloseEvent(void *ptr)
{
__int64 result; // rax
pthread_mutex_t *v2; // rbp
struct timeval v3[2]; // [rsp+0h] [rbp-28h] BYREF

if ( ptr && *(_DWORD *)ptr == 167395348 )
{
v2 = (pthread_mutex_t *)((char *)ptr + 8);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 8));
if ( *((_QWORD *)ptr + 13) )
{
pthread_mutex_unlock(v2);
*_errno_location() = 16;
result = 0LL;
}
else
{
pthread_mutex_unlock(v2);
while ( pthread_mutex_destroy(v2) == 16 )
{
v3[0].tv_sec = 0LL;
v3[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v3);
}
while ( pthread_cond_destroy((pthread_cond_t *)ptr + 1) == 16 )
{
v3[0].tv_sec = 0LL;
v3[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v3);
}
free(ptr);
result = 1LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
__int64 result; // rax
pthread_mutex_t *v2; // rbp
struct timeval v3[2]; // [rsp+0h] [rbp-28h] BYREF

if ( ptr && *(_DWORD *)ptr == 167395348 )
{
v2 = (pthread_mutex_t *)((char *)ptr + 8);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 8));
if ( *((_QWORD *)ptr + 13) )
{
pthread_mutex_unlock(v2);
*_errno_location() = 16;
result = 0LL;
}
else
{
pthread_mutex_unlock(v2);
while ( pthread_mutex_destroy(v2) == 16 )
{
v3[0].tv_sec = 0LL;
v3[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v3);
}
while ( pthread_cond_destroy((pthread_cond_t *)ptr + 1) == 16 )
{
v3[0].tv_sec = 0LL;
v3[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v3);
}
free(ptr);
result = 1LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
CloseEvent(xpevent_t event)
{
 if (event==((void *)0) || (event->magic != ((u_int32_t) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 if (event->nwaiters > 0) {
  pthread_mutex_unlock(&event->lock);
  (*__errno_location ()) = 16;
  return(0);
 }
 pthread_mutex_unlock(&event->lock);
 while(pthread_mutex_destroy(&event->lock)==16)
  ({ int sleep_msecs=1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 while(pthread_cond_destroy(&event->gtzero)==16)
  ({ int sleep_msecs=1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 event->magic = 0;
 free(event);
 return(1);
}

canonical_original_code:
int CloseEvent(struct xpevent *event)
{
 if (event==((void *)0) || (event->magic != ((unsigned int) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(0);
 }
 pthread_mutex_lock(&event->lock);
 if (event->nwaiters > 0) {
  pthread_mutex_unlock(&event->lock);
  (*__errno_location ()) = 16;
  return(0);
 }
 pthread_mutex_unlock(&event->lock);
 while(pthread_mutex_destroy(&event->lock)==16)
  ({ int sleep_msecs = 1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 while(pthread_cond_destroy(&event->gtzero)==16)
  ({ int sleep_msecs = 1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 event->magic = 0;
 free(event);
 return(1);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


WaitForEvent

decompiled_code:
__int64 __fastcall WaitForEvent(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // eax
struct timeval v5; // [rsp+0h] [rbp-48h] BYREF
struct timespec abstime; // [rsp+10h] [rbp-38h] BYREF

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
if ( (unsigned __int64)(a2 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
{
gettimeofday(&v5, 0LL);
abstime.tv_sec = v5.tv_sec + (a2 + v5.tv_usec / 1000) / 0x3E8uLL;
abstime.tv_nsec = (1000000 * a2 + 1000 * v5.tv_usec) % 0x3B9ACA00uLL;
}
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( *(_DWORD *)(a1 + 96) )
{
v2 = 2LL;
}
else
{
do
{
++*(_QWORD *)(a1 + 104);
if ( !a2 )
{
v2 = 1LL;
goto LABEL_19;
}
if ( a2 == -1 )
{
v2 = pthread_cond_wait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8));
}
else
{
v3 = pthread_cond_timedwait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8), &abstime);
v2 = v3;
if ( v3 )
{
if ( v3 == 110LL )
{
v2 = 1LL;
}
else
{
*_errno_location() = v3;
v2 = 2LL;
}
goto LABEL_19;
}
}
--*(_QWORD *)(a1 + 104);
}
while ( !*(_DWORD *)(a1 + 96) );
if ( !v2 && !*(_DWORD *)(a1 + 100) )
*(_DWORD *)(a1 + 96) = 0;
}
LABEL_19:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}
else
{
*_errno_location() = 22;
v2 = 2LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v3; // eax
struct timeval v5; // [rsp+0h] [rbp-48h] BYREF
struct timespec abstime; // [rsp+10h] [rbp-38h] BYREF

if ( a1 && *(_DWORD *)a1 == 167395348 )
{
if ( (unsigned __int64)(a2 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
{
gettimeofday(&v5, 0LL);
abstime.tv_sec = v5.tv_sec + (a2 + v5.tv_usec / 1000) / 0x3E8uLL;
abstime.tv_nsec = (1000000 * a2 + 1000 * v5.tv_usec) % 0x3B9ACA00uLL;
}
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( *(_DWORD *)(a1 + 96) )
{
v2 = 2LL;
}
else
{
do
{
++*(_QWORD *)(a1 + 104);
if ( !a2 )
{
v2 = 1LL;
goto LABEL_19;
}
if ( a2 == -1 )
{
v2 = pthread_cond_wait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8));
}
else
{
v3 = pthread_cond_timedwait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8), &abstime);
v2 = v3;
if ( v3 )
{
if ( v3 == 110LL )
{
v2 = 1LL;
}
else
{
*_errno_location() = v3;
v2 = 2LL;
}
goto LABEL_19;
}
}
--*(_QWORD *)(a1 + 104);
}
while ( !*(_DWORD *)(a1 + 96) );
if ( !v2 && !*(_DWORD *)(a1 + 100) )
*(_DWORD *)(a1 + 96) = 0;
}
LABEL_19:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}
else
{
*_errno_location() = 22;
v2 = 2LL;
}
return v2;
}

original_code:
ulong
WaitForEvent(xpevent_t event, ulong ms)
{
 ulong retval=WAIT_FAILED;
 struct timespec abstime;
 struct timeval currtime;
 if (event==((void *)0) || (event->magic != ((u_int32_t) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(WAIT_FAILED);
 }
 if(ms && ms!=((ulong)(-1))) {
  gettimeofday(&currtime,((void *)0));
  abstime.tv_sec=currtime.tv_sec + (currtime.tv_usec/1000 + ms)/1000;
  abstime.tv_nsec=(currtime.tv_usec*1000 + ms*1000000)%1000000000;
 }
 pthread_mutex_lock(&event->lock);
 while (!(event->value)) {
  event->nwaiters++;
  switch(ms) {
   case 0:
    if(event->value)
     retval=0;
    else
     retval=WAIT_TIMEOUT;
    goto DONE;
    break;
   case ((ulong)(-1)):
    retval=pthread_cond_wait(&event->gtzero, &event->lock);
    break;
   default:
    retval=pthread_cond_timedwait(&event->gtzero, &event->lock, &abstime);
    if(retval) {
     if(retval==110)
      retval=WAIT_TIMEOUT;
     else {
      (*__errno_location ())=retval;
      retval=WAIT_FAILED;
     }
     goto DONE;
    }
  }
  event->nwaiters--;
 }
  DONE:
 if(retval==0) {
  retval=WAIT_OBJECT_0;
  if(!event->mreset)
   event->value=0;
 }
 pthread_mutex_unlock(&event->lock);
 return retval;
}

canonical_original_code:
unsigned long WaitForEvent(struct xpevent *event, unsigned long ms)
{
 unsigned long retval = WAIT_FAILED;
 struct timespec abstime;
 struct timeval currtime;
 if (event==((void *)0) || (event->magic != ((unsigned int) 0x09fa4014))) {
  (*__errno_location ()) = 22;
  return(WAIT_FAILED);
 }
 if(ms && ms!=((ulong)(-1))) {
  gettimeofday(&currtime,((void *)0));
  abstime.tv_sec=currtime.tv_sec + (currtime.tv_usec/1000 + ms)/1000;
  abstime.tv_nsec=(currtime.tv_usec*1000 + ms*1000000)%1000000000;
 }
 pthread_mutex_lock(&event->lock);
 while (!(event->value)) {
  event->nwaiters++;
  switch(ms) {
   case 0:
    if(event->value)
     retval=0;
    else
     retval=WAIT_TIMEOUT;
    goto DONE;
    break;
   case ((ulong)(-1)):
    retval=pthread_cond_wait(&event->gtzero, &event->lock);
    break;
   default:
    retval=pthread_cond_timedwait(&event->gtzero, &event->lock, &abstime);
    if(retval) {
     if(retval==110)
      retval=WAIT_TIMEOUT;
     else {
      (*__errno_location ())=retval;
      retval=WAIT_FAILED;
     }
     goto DONE;
    }
  }
  event->nwaiters--;
 }
  DONE:
 if(retval==0) {
  retval=WAIT_OBJECT_0;
  if(!event->mreset)
   event->value=0;
 }
 pthread_mutex_unlock(&event->lock);
 return retval;
}

variable_types:
ms
unsigned long

variable_types:
retval
unsigned long

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: unsigned long

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


ftouch

decompiled_code:
__int64 __fastcall ftouch(__int64 a1)
{
int v1; // edi
__int64 result; // rax

v1 = nopen(a1, 65);
result = 0LL;
if ( v1 >= 0 )
{
close(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // edi
__int64 result; // rax

v1 = func0(a1, 65);
result = 0LL;
if ( v1 >= 0 )
{
close(v1);
result = 1LL;
}
return result;
}

original_code:
int ftouch(const char* fname)
{
 int file;
 if((file=nopen(fname,01|0100))<0)
  return(0);
 close(file);
 return(1);
}

canonical_original_code:
int ftouch(char *fname)
{
 int file;
 if((file=nopen(fname,01|0100))<0)
  return(0);
 close(file);
 return(1);
}

variable_types:
fname
char *

variable_types: file int


fmutex

decompiled_code:
__int64 __fastcall fmutex(char *filename, void *buf, time_t a3)
{
const char *v3; // rbx
__int64 v5; // r13
int v6; // ebp
__int64 result; // rax
size_t v8; // rax
int v9; // edx
char v10[168]; // [rsp+0h] [rbp-A8h] BYREF

v3 = (const char *)buf;
if ( !buf && !gethostname(v10, 0x80uLL) )
v3 = v10;
if ( !a3 || (v5 = fdate(filename), v5 < 0) || time(0LL) - v5 <= a3 || (v9 = remove(filename), result = 0LL, !v9) )
{
v6 = open(filename, 193, 384LL);
result = 0LL;
if ( v6 >= 0 )
{
if ( v3 )
{
v8 = strlen(v3);
write(v6, v3, v8);
}
close(v6);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *filename, void *buf, time_t a3)
{
const char *v3; // rbx
__int64 v5; // r13
int v6; // ebp
__int64 result; // rax
size_t v8; // rax
int v9; // edx
char v10[168]; // [rsp+0h] [rbp-A8h] BYREF

v3 = (const char *)buf;
if ( !buf && !gethostname(v10, 0x80uLL) )
v3 = v10;
if ( !a3 || (v5 = fdate(filename), v5 < 0) || time(0LL) - v5 <= a3 || (v9 = remove(filename), result = 0LL, !v9) )
{
v6 = open(filename, 193, 384LL);
result = 0LL;
if ( v6 >= 0 )
{
if ( v3 )
{
v8 = strlen(v3);
write(v6, v3, v8);
}
close(v6);
result = 1LL;
}
}
return result;
}

original_code:
int fmutex(const char* fname, const char* text, long max_age)
{
 int file;
 long t;
 char hostname[128];
 if(text==((void *)0) && gethostname(hostname,sizeof(hostname))==0)
  text=hostname;
 if(max_age && (t=fdate(fname)) >= 0 && (time(((void *)0))-t) > max_age) {
  if(remove(fname)!=0)
   return(0);
 }
 if((file=open(fname,0100|01|0200,0400|0200))<0)
  return(0);
 if(text!=((void *)0))
  write(file,text,strlen(text));
 close(file);
 return(1);
}

canonical_original_code:
int fmutex(char *fname, char *text, long max_age)
{
 int file;
 long t;
 char hostname[128];
 if(text==((void *)0) && gethostname(hostname,sizeof(hostname))==0)
  text=hostname;
 if(max_age && (t=fdate(fname)) >= 0 && (time(((void *)0))-t) > max_age) {
  if(remove(fname)!=0)
   return(0);
 }
 if((file=open(fname,0100|01|0200,0400|0200))<0)
  return(0);
 if(text!=((void *)0))
  write(file,text,strlen(text));
 close(file);
 return(1);
}

variable_types:
text
char *

variable_types: t long

variable_types:
hostname
char [128]


decompiled_code:
__int64 __fastcall find_vmode(int a1)
{
__int64 result; // rax

result = 0LL;
while ( vparams[8 * result] != a1 )
{
if ( ++result == 36 )
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax

result = 0LL;
while ( vparams[8 * result] != a1 )
{
if ( ++result == 36 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int find_vmode(int mode)
{
    unsigned i;
 for (i = 0; i < (sizeof(vparams) / sizeof(struct video_params)); i++)
  if (vparams[i].mode == mode)
   return i;
 return -1;
}

canonical_original_code:
int find_vmode(int mode)
{
    unsigned int i;
 for (i = 0; i < (sizeof(vparams) / sizeof(struct video_params)); i++)
  if (vparams[i].mode == mode)
   return i;
 return -1;
}

variable_types: mode int

variable_types:
i
unsigned int

user_defined_types: struct video_params { int mode; int palette; int cols; int rows; int curs_start; int curs_end; int charheight; int charwidth; }


original_code:
int load_vmode(struct video_stats *vs, int mode)
{
 int i;
 unsigned short *newvmem;
 i=find_vmode(mode);
 if(i==-1)
  return(-1);
 newvmem=(unsigned short *)realloc(vs->vmem, vparams[i].cols*vparams[i].rows*sizeof(unsigned short));
 if(newvmem==((void *)0))
  return(-1);
 vs->vmem=newvmem;
 vs->rows=vparams[i].rows;
 vs->cols=vparams[i].cols;
 vs->curs_start=vparams[i].curs_start;
 vs->curs_end=vparams[i].curs_end;
 vs->default_curs_start=vparams[i].curs_start;
 vs->default_curs_end=vparams[i].curs_end;
 if(vs->curs_row < 0)
  vs->curs_row=0;
 if(vs->curs_row >= vparams[i].rows)
  vs->curs_row=vparams[i].rows-1;
 if(vs->curs_col < 0)
  vs->curs_col=0;
 if(vs->curs_col >= vparams[i].cols)
  vs->curs_col=vparams[i].cols-1;
 vs->palette=palettes[vparams[i].palette];
 vs->charheight=vparams[i].charheight;
 vs->charwidth=vparams[i].charwidth;
 vs->mode=mode;
 return(0);
}

variable_types: struct video_stats { int rows; int cols; int curs_row; int curs_col; int curs_start; int curs_end; int default_curs_start; int default_curs_end; int mode; int charheight; int charwidth; int blink; int currattr; int scaling; unsigned char *palette; unsigned short *vmem; } *

variable_types: i int

variable_types:
newvmem
unsigned short *


delfattach

decompiled_code:
int __fastcall delfattach(__int64 a1, unsigned __int16 *a2)
{
char *v2; // rbp
const char *v3; // r12
const char *v4; // rax
int result; // eax
char *v6; // rax
char *v7; // rbx
char *v8; // rax
char v9[4112]; // [rsp+0h] [rbp-2048h] BYREF
char dest[4152]; // [rsp+1010h] [rbp-1038h] BYREF

if ( *a2 )
{
strcpy(dest, *((const char **)a2 + 39));
v2 = dest;
v3 = (const char *)(a1 + 6036);
while ( 1 )
{
v6 = strchr(v2, 32);
v7 = v6;
if ( v6 )
*v6 = 0;
v8 = strrchr(v2, 47);
if ( v8 || (v8 = strrchr(v2, 92)) != 0LL )
v2 = v8 + 1;
sprintf(v9, "%sfile/%04u.in/%s", v3, *a2, v2);
remove(v9);
if ( !v7 )
break;
v2 = v7 + 1;
}
sprintf(dest, "%sfile/%04u.in", v3, *a2);
result = rmdir(dest);
}
else
{
v4 = (const char *)getfname(*((_QWORD *)a2 + 39));
sprintf(dest, "%sfile/%04u.out/%s", (const char *)(a1 + 6036), a2[1], v4);
remove(dest);
sprintf(dest, "%sfile/%04u.out", (const char *)(a1 + 6036), a2[1]);
result = rmdir(dest);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, unsigned __int16 *a2)
{
char *v2; // rbp
const char *v3; // r12
const char *v4; // rax
int result; // eax
char *v6; // rax
char *v7; // rbx
char *v8; // rax
char v9[4112]; // [rsp+0h] [rbp-2048h] BYREF
char dest[4152]; // [rsp+1010h] [rbp-1038h] BYREF

if ( *a2 )
{
strcpy(dest, *((const char **)a2 + 39));
v2 = dest;
v3 = (const char *)(a1 + 6036);
while ( 1 )
{
v6 = strchr(v2, 32);
v7 = v6;
if ( v6 )
*v6 = 0;
v8 = strrchr(v2, 47);
if ( v8 || (v8 = strrchr(v2, 92)) != 0LL )
v2 = v8 + 1;
sprintf(v9, "%sfile/%04u.in/%s", v3, *a2, v2);
remove(v9);
if ( !v7 )
break;
v2 = v7 + 1;
}
sprintf(dest, "%sfile/%04u.in", v3, *a2);
result = rmdir(dest);
}
else
{
v4 = (const char *)getfname(*((_QWORD *)a2 + 39));
sprintf(dest, "%sfile/%04u.out/%s", (const char *)(a1 + 6036), a2[1], v4);
remove(dest);
sprintf(dest, "%sfile/%04u.out", (const char *)(a1 + 6036), a2[1]);
result = rmdir(dest);
}
return result;
}

original_code:
void delfattach(scfg_t* cfg, smbmsg_t* msg)
{
    char str[4096 +1];
 char str2[4096 +1];
 char *tp,*sp,*p;
 if(msg->idx.to==0) {
  sprintf(str,"%sfile/%04u.out/%s"
   ,cfg->data_dir,msg->idx.from,getfname(msg->subj));
  remove(str);
  sprintf(str,"%sfile/%04u.out"
   ,cfg->data_dir,msg->idx.from);
  rmdir(str);
  return;
 }
 strcpy(str,msg->subj);
 tp=str;
 while(1) {
  p=strchr(tp,' ');
  if(p) *p=0;
  sp=strrchr(tp,'/');
  if(!sp) sp=strrchr(tp,'\\');
  if(sp) tp=sp+1;
  sprintf(str2,"%sfile/%04u.in/%s"
   ,cfg->data_dir,msg->idx.to,tp);
  remove(str2);
  if(!p)
   break;
  tp=p+1; }
 sprintf(str,"%sfile/%04u.in",cfg->data_dir,msg->idx.to);
 rmdir(str);
}

canonical_original_code:
void delfattach(struct scfg_t *cfg, struct smbmsg_t *msg)
{
    char str[-1];
 char str2[-1];
 char *tp; char *sp; char *p;
 if(msg->idx.to==0) {
  sprintf(str,"%sfile/%04u.out/%s"
   ,cfg->data_dir,msg->idx.from,getfname(msg->subj));
  remove(str);
  sprintf(str,"%sfile/%04u.out"
   ,cfg->data_dir,msg->idx.from);
  rmdir(str);
  return;
 }
 strcpy(str,msg->subj);
 tp=str;
 while(1) {
  p=strchr(tp,' ');
  if(p) *p=0;
  sp=strrchr(tp,'/');
  if(!sp) sp=strrchr(tp,'\\');
  if(sp) tp=sp+1;
  sprintf(str2,"%sfile/%04u.in/%s"
   ,cfg->data_dir,msg->idx.to,tp);
  remove(str2);
  if(!p)
   break;
  tp=p+1; }
 sprintf(str,"%sfile/%04u.in",cfg->data_dir,msg->idx.to);
 rmdir(str);
}

variable_types: struct scfg_t { unsigned long size; int prepped; struct grp_t { char lname[-1]; unsigned char *ar; } **grp; unsigned short total_grps; struct sub_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short grp; unsigned long misc; struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; } faddr; } **sub; unsigned short total_subs; struct lib_t { char lname[-1]; unsigned char *ar; unsigned short offline_dir; } **lib; unsigned short total_libs; struct dir_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short maxfiles; unsigned long misc; } **dir; unsigned short total_dirs; struct txtsec_t { char code[-1]; char name[41]; unsigned char *ar; } **txtsec; unsigned short total_txtsecs; struct xtrnsec_t { char code[-1]; char name[41]; unsigned char *ar; } **xtrnsec; unsigned short total_xtrnsecs; struct xtrn_t { char code[-1]; char name[41]; unsigned char *ar; unsigned char type; unsigned short sec; unsigned long cost; } **xtrn; unsigned short total_xtrns; struct mdm_result_t { unsigned short code; char str[-1]; } *mdm_result; unsigned short mdm_results; struct prot_t { char mnemonic; char name[26]; unsigned char *ar; unsigned long misc; } **prot; unsigned short total_prots; struct fextr_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **fextr; unsigned short total_fextrs; struct fcomp_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **fcomp; unsigned short total_fcomps; struct fview_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **fview; unsigned short total_fviews; struct ftest_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **ftest; unsigned short total_ftests; struct xedit_t { char code[-1]; unsigned char *ar; unsigned long misc; unsigned char type; } **xedit; unsigned short total_xedits; struct qhub_t { char id[-1]; unsigned short time; long last; } **qhub; unsigned short total_qhubs; struct phub_t { char days; unsigned short time; long last; } **phub; unsigned short total_phubs; struct chan_t { char code[-1]; char name[26]; char arstr[-1]; unsigned char *ar; unsigned short actset; unsigned long cost; } **chan; unsigned short total_chans; struct chatact_t { char cmd[-1]; unsigned short actset; } **chatact; unsigned short total_chatacts; struct actset_t { char name[26]; } **actset; unsigned short total_actsets; struct page_t { char cmd[-1]; unsigned char *ar; unsigned long misc; } **page; unsigned short total_pages; struct event_t { char code[-1]; unsigned short node; unsigned long misc; long last; } **event; unsigned short total_events; struct dlevent_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **dlevent; unsigned short total_dlevents; struct fidoaddr_t *faddr; unsigned short total_faddrs; struct swap_t { char cmd[-1]; } **swap; unsigned short total_swaps; struct natvpgm_t { char name[13]; unsigned long misc; } **natvpgm; unsigned short total_natvpgms; struct guru_t { char code[-1]; char name[26]; unsigned char *ar; } **guru; unsigned short total_gurus; struct shell_t { char code[-1]; char name[41]; unsigned char *ar; unsigned long misc; } **shell; unsigned short total_shells; struct hotkey_t { unsigned char key; char cmd[-1]; } **hotkey; unsigned short total_hotkeys; unsigned short com_base; unsigned long com_rate; char com_port; char mdm_init[64]; unsigned long mdm_misc; unsigned short mdm_reinit; unsigned short mdm_ansdelay; unsigned char mdm_rings; long sys_misc; char sys_pass[41]; char sys_name[41]; char sys_id[-1]; char sys_psname[13]; unsigned long sys_psnum; char sys_inetaddr[128]; char sys_location[41]; short sys_timezone; char sys_daily[-1]; char sys_logon[-1]; char sys_logout[-1]; unsigned short sys_pwdays; unsigned short sys_deldays; unsigned short sys_autodel; unsigned short sys_nodes; char sys_op[41]; char sys_guru[41]; unsigned char sys_exp_warn; char sys_def_stat; char sys_phonefmt[-1]; unsigned short sys_lastnode; unsigned short sys_autonode; char sys_chat_arstr[-1]; unsigned char *sys_chat_ar; long msg_misc; long file_misc; long xtrn_misc; char node_comspec[-1]; char node_editor[-1]; char node_viewer[-1]; char node_daily[-1]; unsigned char node_scrnlen; unsigned char node_scrnblank; unsigned long node_misc; unsigned short node_valuser; unsigned short node_ivt; unsigned char node_swap; char node_swapdir[-1]; unsigned short node_minbps; unsigned short node_num; char node_phone[13]; char node_arstr[-1]; unsigned char *node_ar; unsigned long node_cost; unsigned char node_dollars_per_call; unsigned short node_sem_check; unsigned short node_stat_check; char new_install; char new_pass[41]; char new_magic[21]; char new_sif[-1]; char new_sof[-1]; char new_level; unsigned long new_flags1; unsigned long new_flags2; unsigned long new_flags3; unsigned long new_flags4; unsigned long new_exempt; unsigned long new_rest; unsigned long new_cdt; unsigned long new_min; char new_xedit[-1]; unsigned short new_shell; unsigned long new_misc; unsigned short new_expire; unsigned char new_prot; char val_level[10]; unsigned long val_flags1[10]; unsigned long val_flags2[10]; unsigned long val_flags3[10]; unsigned long val_flags4[10]; unsigned long val_exempt[10]; unsigned long val_rest[10]; unsigned long val_cdt[10]; unsigned short val_expire[10]; unsigned char level_expireto[100]; unsigned short level_timepercall[100]; long level_freecdtperday[100]; long level_misc[100]; char expired_level; unsigned long expired_flags1; unsigned long expired_flags2; unsigned long expired_flags3; unsigned long expired_flags4; unsigned long expired_exempt; unsigned long expired_rest; unsigned short min_dspace; unsigned short max_batup; unsigned short max_batdn; unsigned short max_userxfer; unsigned long max_minutes; unsigned long max_qwkmsgs; char preqwk_arstr[-1]; unsigned char *preqwk_ar; unsigned short cdt_min_value; unsigned long cdt_per_dollar; unsigned short cdt_up_pct; unsigned short cdt_dn_pct; char node_dir[-1]; char ctrl_dir[-1]; char data_dir[-1]; char text_dir[-1]; char exec_dir[-1]; char temp_dir[-1]; char mods_dir[-1]; char logs_dir[-1]; char node_path[250][-1]; unsigned short sysop_dir; unsigned short user_dir; unsigned short upload_dir; char **altpath; unsigned short altpaths; unsigned short leech_pct; unsigned short leech_sec; unsigned long netmail_cost; char netmail_dir[-1]; unsigned short netmail_misc; unsigned long inetmail_misc; unsigned long inetmail_cost; char smtpmail_sem[-1]; char inetmail_sem[-1]; char echomail_dir[-1]; char fidofile_dir[-1]; char netmail_sem[-1]; char echomail_sem[-1]; char origline[51]; char qnet_tagline[128]; long uq; unsigned long mail_maxcrcs; unsigned short mail_maxage; struct fidoaddr_t dflt_faddr; char logon_mod[-1]; char logoff_mod[-1]; char newuser_mod[-1]; char login_mod[-1]; char logout_mod[-1]; char sync_mod[-1]; char expire_mod[-1]; char scfg_cmd[-1]; unsigned char smb_retry_time; unsigned short sec_warn; unsigned short sec_hangup; char *color; unsigned long total_colors; unsigned long ctrlkey_passthru; char wfc_cmd[10][-1]; char wfc_scmd[12][-1]; unsigned short user_backup_level; unsigned short mail_backup_level; } *

variable_types: struct smbmsg_t { struct idxrec_t { unsigned short to; unsigned short from; unsigned short subj; unsigned short attr; unsigned long offset; unsigned long number; unsigned long time; } idx; struct msghdr_t { unsigned char id[4]; unsigned short type; unsigned short version; unsigned short length; unsigned short attr; unsigned long auxattr; unsigned long netattr; struct when_t { unsigned long time; short zone; } when_written; struct when_t when_imported; unsigned long number; unsigned long thread_back; unsigned long thread_next; unsigned long thread_first; unsigned short delivery_attempts; unsigned long times_downloaded; unsigned long last_downloaded; unsigned char reserved[6]; unsigned long offset; unsigned short total_dfields; } hdr; char *to; char *summary; char *subj; unsigned short to_agent; struct net_t { unsigned short type; void *addr; } to_net; unsigned short total_hfields; struct hfield_t { unsigned short type; unsigned short length; } *hfield; void **hfield_dat; struct dfield_t { unsigned short type; unsigned long offset; unsigned long length; } *dfield; long offset; int forwarded; unsigned long expiration; unsigned long priority; unsigned long cost; unsigned long flags; } *

variable_types:
str
char [-1]

variable_types:
tp
char *

variable_types:
sp
char *

variable_types:
p
char *

user_defined_types: struct scfg_t { unsigned long size; int prepped; struct grp_t **grp; unsigned short total_grps; struct sub_t **sub; unsigned short total_subs; struct lib_t **lib; unsigned short total_libs; struct dir_t **dir; unsigned short total_dirs; struct txtsec_t **txtsec; unsigned short total_txtsecs; struct xtrnsec_t **xtrnsec; unsigned short total_xtrnsecs; struct xtrn_t **xtrn; unsigned short total_xtrns; struct mdm_result_t *mdm_result; unsigned short mdm_results; struct prot_t **prot; unsigned short total_prots; struct fextr_t **fextr; unsigned short total_fextrs; struct fcomp_t **fcomp; unsigned short total_fcomps; struct fview_t **fview; unsigned short total_fviews; struct ftest_t **ftest; unsigned short total_ftests; struct xedit_t **xedit; unsigned short total_xedits; struct qhub_t **qhub; unsigned short total_qhubs; struct phub_t **phub; unsigned short total_phubs; struct chan_t **chan; unsigned short total_chans; struct chatact_t **chatact; unsigned short total_chatacts; struct actset_t **actset; unsigned short total_actsets; struct page_t **page; unsigned short total_pages; struct event_t **event; unsigned short total_events; struct dlevent_t **dlevent; unsigned short total_dlevents; struct fidoaddr_t *faddr; unsigned short total_faddrs; struct swap_t **swap; unsigned short total_swaps; struct natvpgm_t **natvpgm; unsigned short total_natvpgms; struct guru_t **guru; unsigned short total_gurus; struct shell_t **shell; unsigned short total_shells; struct hotkey_t **hotkey; unsigned short total_hotkeys; unsigned short com_base; unsigned long com_rate; char com_port; char mdm_init[64]; unsigned long mdm_misc; unsigned short mdm_reinit; unsigned short mdm_ansdelay; unsigned char mdm_rings; long sys_misc; char sys_pass[41]; char sys_name[41]; char sys_id[-1]; char sys_psname[13]; unsigned long sys_psnum; char sys_inetaddr[128]; char sys_location[41]; short sys_timezone; char sys_daily[-1]; char sys_logon[-1]; char sys_logout[-1]; unsigned short sys_pwdays; unsigned short sys_deldays; unsigned short sys_autodel; unsigned short sys_nodes; char sys_op[41]; char sys_guru[41]; unsigned char sys_exp_warn; char sys_def_stat; char sys_phonefmt[-1]; unsigned short sys_lastnode; unsigned short sys_autonode; char sys_chat_arstr[-1]; unsigned char *sys_chat_ar; long msg_misc; long file_misc; long xtrn_misc; char node_comspec[-1]; char node_editor[-1]; char node_viewer[-1]; char node_daily[-1]; unsigned char node_scrnlen; unsigned char node_scrnblank; unsigned long node_misc; unsigned short node_valuser; unsigned short node_ivt; unsigned char node_swap; char node_swapdir[-1]; unsigned short node_minbps; unsigned short node_num; char node_phone[13]; char node_arstr[-1]; unsigned char *node_ar; unsigned long node_cost; unsigned char node_dollars_per_call; unsigned short node_sem_check; unsigned short node_stat_check; char new_install; char new_pass[41]; char new_magic[21]; char new_sif[-1]; char new_sof[-1]; char new_level; unsigned long new_flags1; unsigned long new_flags2; unsigned long new_flags3; unsigned long new_flags4; unsigned long new_exempt; unsigned long new_rest; unsigned long new_cdt; unsigned long new_min; char new_xedit[-1]; unsigned short new_shell; unsigned long new_misc; unsigned short new_expire; unsigned char new_prot; char val_level[10]; unsigned long val_flags1[10]; unsigned long val_flags2[10]; unsigned long val_flags3[10]; unsigned long val_flags4[10]; unsigned long val_exempt[10]; unsigned long val_rest[10]; unsigned long val_cdt[10]; unsigned short val_expire[10]; unsigned char level_expireto[100]; unsigned short level_timepercall[100]; long level_freecdtperday[100]; long level_misc[100]; char expired_level; unsigned long expired_flags1; unsigned long expired_flags2; unsigned long expired_flags3; unsigned long expired_flags4; unsigned long expired_exempt; unsigned long expired_rest; unsigned short min_dspace; unsigned short max_batup; unsigned short max_batdn; unsigned short max_userxfer; unsigned long max_minutes; unsigned long max_qwkmsgs; char preqwk_arstr[-1]; unsigned char *preqwk_ar; unsigned short cdt_min_value; unsigned long cdt_per_dollar; unsigned short cdt_up_pct; unsigned short cdt_dn_pct; char node_dir[-1]; char ctrl_dir[-1]; char data_dir[-1]; char text_dir[-1]; char exec_dir[-1]; char temp_dir[-1]; char mods_dir[-1]; char logs_dir[-1]; char node_path[250][-1]; unsigned short sysop_dir; unsigned short user_dir; unsigned short upload_dir; char **altpath; unsigned short altpaths; unsigned short leech_pct; unsigned short leech_sec; unsigned long netmail_cost; char netmail_dir[-1]; unsigned short netmail_misc; unsigned long inetmail_misc; unsigned long inetmail_cost; char smtpmail_sem[-1]; char inetmail_sem[-1]; char echomail_dir[-1]; char fidofile_dir[-1]; char netmail_sem[-1]; char echomail_sem[-1]; char origline[51]; char qnet_tagline[128]; long uq; unsigned long mail_maxcrcs; unsigned short mail_maxage; struct fidoaddr_t dflt_faddr; char logon_mod[-1]; char logoff_mod[-1]; char newuser_mod[-1]; char login_mod[-1]; char logout_mod[-1]; char sync_mod[-1]; char expire_mod[-1]; char scfg_cmd[-1]; unsigned char smb_retry_time; unsigned short sec_warn; unsigned short sec_hangup; char *color; unsigned long total_colors; unsigned long ctrlkey_passthru; char wfc_cmd[10][-1]; char wfc_scmd[12][-1]; unsigned short user_backup_level; unsigned short mail_backup_level; }

user_defined_types: struct smbmsg_t { struct idxrec_t idx; struct msghdr_t hdr; char *to; char *summary; char *subj; unsigned short to_agent; struct net_t to_net; unsigned short total_hfields; struct hfield_t *hfield; void **hfield_dat; struct dfield_t *dfield; long offset; int forwarded; unsigned long expiration; unsigned long priority; unsigned long cost; unsigned long flags; }

user_defined_types: struct msghdr_t { unsigned char id[4]; unsigned short type; unsigned short version; unsigned short length; unsigned short attr; unsigned long auxattr; unsigned long netattr; struct when_t when_written; struct when_t when_imported; unsigned long number; unsigned long thread_back; unsigned long thread_next; unsigned long thread_first; unsigned short delivery_attempts; unsigned long times_downloaded; unsigned long last_downloaded; unsigned char reserved[6]; unsigned long offset; unsigned short total_dfields; }

user_defined_types: struct sub_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short grp; unsigned long misc; struct fidoaddr_t faddr; }


freemail

decompiled_code:
void __fastcall freemail(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void freemail(mail_t* mail)
{
 if(mail!=((void *)0))
  free(mail);
}

canonical_original_code:
void freemail(struct idxrec_t *mail)
{
 if(mail!=((void *)0))
  free(mail);
}

variable_types: struct idxrec_t { unsigned short to; unsigned short from; unsigned short subj; unsigned short attr; unsigned long offset; unsigned long number; unsigned long time; } *


decompiled_code:
unsigned __int64 __fastcall crc32i(unsigned __int64 a1, const char *a2, size_t a3)
{
size_t v4; // rax
const char *v5; // rdx
const char *v6; // rax

v4 = a3;
if ( !a3 && a2 )
v4 = strlen(a2);
if ( v4 )
{
v5 = a2;
v6 = &a2[v4];
do
a1 = crc32tbl[(unsigned __int8)(*v5++ ^ a1)] ^ (a1 >> 8);
while ( v5 != v6 );
}
return ~a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1, const char *a2, size_t a3)
{
size_t v4; // rax
const char *v5; // rdx
const char *v6; // rax

v4 = a3;
if ( !a3 && a2 )
v4 = strlen(a2);
if ( v4 )
{
v5 = a2;
v6 = &a2[v4];
do
a1 = crc32tbl[(unsigned __int8)(*v5++ ^ a1)] ^ (a1 >> 8);
while ( v5 != v6 );
}
return ~a1;
}

original_code:
unsigned long crc32i(unsigned long crc, char *buf, unsigned long len)
{
 unsigned long l;
 if(len==0 && buf!=((void *)0))
  len=strlen(buf);
 for(l=0;l<len;l++)
  crc=(crc32tbl[(crc^(buf[l]))&0xff]^(crc>>8));
 return(~crc);
}

variable_types:
crc
unsigned long

variable_types:
buf
char *

variable_types:
len
unsigned long

variable_types:
l
unsigned long


original_code:
static int ar_exp(scfg_t* cfg, unsigned char **ptrptr, user_t* user)
{
 int result,not,or,equal;
 uint i,n,artype=AR_LEVEL,age;
 ulong l;
 time_t now;
 struct tm tm;
 result = 1;
 for(;(**ptrptr);(*ptrptr)++) {
  if((**ptrptr)==AR_ENDNEST)
   break;
  not=or=equal = 0;
  if((**ptrptr)==AR_OR) {
   or=1;
   (*ptrptr)++;
  }
  if((**ptrptr)==AR_NOT) {
   not=1;
   (*ptrptr)++;
  }
  if((**ptrptr)==AR_EQUAL) {
   equal=1;
   (*ptrptr)++;
  }
  if((result && or) || (!result && !or))
   break;
  if((**ptrptr)==AR_BEGNEST) {
   (*ptrptr)++;
   if(ar_exp(cfg,ptrptr,user))
    result=!not;
   else
    result=not;
   while((**ptrptr)!=AR_ENDNEST && (**ptrptr))
    (*ptrptr)++;
   if(!(**ptrptr))
    break;
   continue;
  }
  artype=(**ptrptr);
  switch(artype) {
   case AR_ANSI:
   case AR_RIP:
   case AR_WIP:
   case AR_LOCAL:
   case AR_EXPERT:
   case AR_SYSOP:
   case AR_GUEST:
   case AR_QNODE:
   case AR_QUIET:
   case AR_OS2:
   case AR_DOS:
    break;
   default:
    (*ptrptr)++;
    break;
  }
  n=(**ptrptr);
  i=(*(short *)*ptrptr);
  switch(artype) {
   case AR_LEVEL:
    if(user==((void *)0)
     || (equal && user->level!=n)
     || (!equal && user->level<n))
     result=not;
    else
     result=!not;
    break;
   case AR_AGE:
    if(user==((void *)0))
     result=not;
    else {
     age=getage(cfg,user->birth);
     if((equal && age!=n) || (!equal && age<n))
      result=not;
     else
      result=!not;
    }
    break;
   case AR_BPS:
    result=!not;
    (*ptrptr)++;
    break;
   case AR_ANSI:
    if(user==((void *)0) || !(user->misc&(1L<<1)))
     result=not;
    else result=!not;
    break;
   case AR_RIP:
    if(user==((void *)0) || !(user->misc&(1L<<3)))
     result=not;
    else result=!not;
    break;
   case AR_WIP:
    if(user==((void *)0) || !(user->misc&(1L<<21)))
     result=not;
    else result=!not;
    break;
   case AR_OS2:
     result=not;
    break;
   case AR_DOS:
    result=not;
    break;
   case AR_WIN32:
     result=not;
    break;
   case AR_UNIX:
     result=!not;
    break;
   case AR_LINUX:
     result=!not;
    break;
   case AR_ACTIVE:
    if(user==((void *)0) || user->misc&((1L<<0)|(1L<<6)))
     result=not;
    else result=!not;
    break;
   case AR_INACTIVE:
    if(user==((void *)0) || !(user->misc&(1L<<6)))
     result=not;
    else result=!not;
    break;
   case AR_DELETED:
    if(user==((void *)0) || !(user->misc&(1L<<0)))
     result=not;
    else result=!not;
    break;
   case AR_EXPERT:
    if(user==((void *)0) || !(user->misc&(1L<<7)))
     result=not;
    else result=!not;
    break;
   case AR_SYSOP:
    if(user==((void *)0) || user->level<90)
     result=not;
    else result=!not;
    break;
   case AR_GUEST:
    if(user==((void *)0) || !(user->rest&(ulong)(1UL<<('G'-'A'))))
     result=not;
    else result=!not;
    break;
   case AR_QNODE:
    if(user==((void *)0) || !(user->rest&(ulong)(1UL<<('Q'-'A'))))
     result=not;
    else result=!not;
    break;
   case AR_QUIET:
    result=not;
    break;
   case AR_LOCAL:
    result=not;
    break;
   case AR_DAY:
    now=time(((void *)0));
    localtime_r(&now,&tm);
    if((equal && tm.tm_wday!=(int)n)
     || (!equal && tm.tm_wday<(int)n))
     result=not;
    else
     result=!not;
    break;
   case AR_CREDIT:
    l=(ulong)i*1024UL;
    if(user==((void *)0)
     || (equal && user->cdt+user->freecdt!=l)
     || (!equal && user->cdt+user->freecdt<l))
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_NODE:
    if((equal && cfg->node_num!=n) || (!equal && cfg->node_num<n))
     result=not;
    else
     result=!not;
    break;
   case AR_USER:
    if(user==((void *)0)
     || (equal && user->number!=i)
     || (!equal && user->number<i))
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_GROUP:
    if(user==((void *)0))
     result=not;
    else {
     l=getgrpnum(cfg,user->cursub);
     if((equal && l!=i) || (!equal && l<i))
      result=not;
     else
      result=!not;
    }
    (*ptrptr)++;
    break;
   case AR_SUB:
    if(user==((void *)0))
     result=not;
    else {
     l=getsubnum(cfg,user->cursub);
     if((equal && l!=i) || (!equal && l<i))
      result=not;
     else
      result=!not;
    }
    (*ptrptr)++;
    break;
   case AR_SUBCODE:
    if(user!=((void *)0) && strcasecmp(user->cursub,(char *)*ptrptr)==0)
     result=!not;
    else
     result=not;
    result=not;
    while(*(*ptrptr))
     (*ptrptr)++;
    break;
   case AR_LIB:
    if(user==((void *)0))
     result=not;
    else {
     l=getlibnum(cfg,user->curdir);
     if((equal && l!=i) || (!equal && l<i))
      result=not;
     else
      result=!not;
    }
    (*ptrptr)++;
    break;
   case AR_DIR:
    if(user==((void *)0))
     result=not;
    else {
     l=getdirnum(cfg,user->curdir);
     if((equal && l!=i) || (!equal && l<i))
      result=not;
     else
      result=!not;
    }
    (*ptrptr)++;
    break;
   case AR_DIRCODE:
    if(user!=((void *)0) && strcasecmp(user->curdir,(char *)*ptrptr)==0)
     result=!not;
    else
     result=not;
    while(*(*ptrptr))
     (*ptrptr)++;
    break;
   case AR_EXPIRE:
    now=time(((void *)0));
    if(user==((void *)0)
     || user->expire==0
     || now+((long)i*24L*60L*60L)>user->expire)
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_RANDOM:
    n=xp_random(i+1);
    if((equal && n!=i) || (!equal && n<i))
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_LASTON:
    now=time(((void *)0));
    if(user==((void *)0) || (now-user->laston)/(24L*60L*60L)<(long)i)
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_LOGONS:
    if(user==((void *)0)
     || (equal && user->logons!=i)
     || (!equal && user->logons<i))
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_MAIN_CMDS:
    result=not;
    (*ptrptr)++;
    break;
   case AR_FILE_CMDS:
    result=not;
    (*ptrptr)++;
    break;
   case AR_TLEFT:
    result=not;
    break;
   case AR_TUSED:
    result=not;
    break;
   case AR_TIME:
    now=time(((void *)0));
    localtime_r(&now,&tm);
    if((tm.tm_hour*60)+tm.tm_min<(int)i)
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_PCR:
    if(user==((void *)0))
     result=not;
    else if(user->logons>user->posts
     && (!user->posts || 100/((float)user->logons/user->posts)<(long)n))
     result=not;
    else
     result=!not;
    break;
   case AR_UDR:
    if(user==((void *)0))
     result=not;
    else {
     l=user->dlb;
     if(!l) l=1;
     if(user->dlb>user->ulb
      && (!user->ulb || 100/((float)l/user->ulb)<n))
      result=not;
     else
      result=!not;
    }
    break;
   case AR_UDFR:
    if(user==((void *)0))
     result=not;
    else {
     i=user->dls;
     if(!i) i=1;
     if(user->dls>user->uls
      && (!user->uls || 100/((float)i/user->uls)<n))
      result=not;
     else
      result=!not;
    }
    break;
   case AR_FLAG1:
    if(user==((void *)0)
     || (!equal && !(user->flags1&(ulong)(1UL<<(n-'A'))))
     || (equal && user->flags1!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_FLAG2:
    if(user==((void *)0)
     || (!equal && !(user->flags2&(ulong)(1UL<<(n-'A'))))
     || (equal && user->flags2!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_FLAG3:
    if(user==((void *)0)
     || (!equal && !(user->flags3&(ulong)(1UL<<(n-'A'))))
     || (equal && user->flags3!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_FLAG4:
    if(user==((void *)0)
     || (!equal && !(user->flags4&(ulong)(1UL<<(n-'A'))))
     || (equal && user->flags4!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_REST:
    if(user==((void *)0)
     || (!equal && !(user->rest&(ulong)(1UL<<(n-'A'))))
     || (equal && user->rest!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_EXEMPT:
    if(user==((void *)0)
     || (!equal && !(user->exempt&(ulong)(1UL<<(n-'A'))))
     || (equal && user->exempt!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_SEX:
    if(user==((void *)0) || user->sex!=n)
     result=not;
    else
     result=!not;
    break;
   case AR_SHELL:
    if(user==((void *)0)
     || user->shell>=cfg->total_shells
     || strcasecmp(cfg->shell[user->shell]->code,(char*)*ptrptr))
     result=not;
    else
     result=!not;
    while(*(*ptrptr))
     (*ptrptr)++;
    break;
   case AR_PROT:
    if(user==((void *)0)
     || strcasecmp(user->modem,(char*)*ptrptr))
     result=not;
    else
     result=!not;
    while(*(*ptrptr))
     (*ptrptr)++;
    break;
  }
 }
 return(result);
}

canonical_original_code:
static int ar_exp(struct scfg_t *cfg, unsigned char **ptrptr, struct user_t *user)
{
 int result; int not; int or; int equal;
 unsigned int i; unsigned int n; unsigned int artype = AR_LEVEL; unsigned int age;
 unsigned long l;
 long now;
 struct tm tm;
 result = 1;
 for(;(**ptrptr);(*ptrptr)++) {
  if((**ptrptr)==AR_ENDNEST)
   break;
  not=or=equal = 0;
  if((**ptrptr)==AR_OR) {
   or=1;
   (*ptrptr)++;
  }
  if((**ptrptr)==AR_NOT) {
   not=1;
   (*ptrptr)++;
  }
  if((**ptrptr)==AR_EQUAL) {
   equal=1;
   (*ptrptr)++;
  }
  if((result && or) || (!result && !or))
   break;
  if((**ptrptr)==AR_BEGNEST) {
   (*ptrptr)++;
   if(ar_exp(cfg,ptrptr,user))
    result=!not;
   else
    result=not;
   while((**ptrptr)!=AR_ENDNEST && (**ptrptr))
    (*ptrptr)++;
   if(!(**ptrptr))
    break;
   continue;
  }
  artype=(**ptrptr);
  switch(artype) {
   case AR_ANSI:
   case AR_RIP:
   case AR_WIP:
   case AR_LOCAL:
   case AR_EXPERT:
   case AR_SYSOP:
   case AR_GUEST:
   case AR_QNODE:
   case AR_QUIET:
   case AR_OS2:
   case AR_DOS:
    break;
   default:
    (*ptrptr)++;
    break;
  }
  n=(**ptrptr);
  i=(*(short *)*ptrptr);
  switch(artype) {
   case AR_LEVEL:
    if(user==((void *)0)
     || (equal && user->level!=n)
     || (!equal && user->level<n))
     result=not;
    else
     result=!not;
    break;
   case AR_AGE:
    if(user==((void *)0))
     result=not;
    else {
     age=getage(cfg,user->birth);
     if((equal && age!=n) || (!equal && age<n))
      result=not;
     else
      result=!not;
    }
    break;
   case AR_BPS:
    result=!not;
    (*ptrptr)++;
    break;
   case AR_ANSI:
    if(user==((void *)0) || !(user->misc&(1L<<1)))
     result=not;
    else result=!not;
    break;
   case AR_RIP:
    if(user==((void *)0) || !(user->misc&(1L<<3)))
     result=not;
    else result=!not;
    break;
   case AR_WIP:
    if(user==((void *)0) || !(user->misc&(1L<<21)))
     result=not;
    else result=!not;
    break;
   case AR_OS2:
     result=not;
    break;
   case AR_DOS:
    result=not;
    break;
   case AR_WIN32:
     result=not;
    break;
   case AR_UNIX:
     result=!not;
    break;
   case AR_LINUX:
     result=!not;
    break;
   case AR_ACTIVE:
    if(user==((void *)0) || user->misc&((1L<<0)|(1L<<6)))
     result=not;
    else result=!not;
    break;
   case AR_INACTIVE:
    if(user==((void *)0) || !(user->misc&(1L<<6)))
     result=not;
    else result=!not;
    break;
   case AR_DELETED:
    if(user==((void *)0) || !(user->misc&(1L<<0)))
     result=not;
    else result=!not;
    break;
   case AR_EXPERT:
    if(user==((void *)0) || !(user->misc&(1L<<7)))
     result=not;
    else result=!not;
    break;
   case AR_SYSOP:
    if(user==((void *)0) || user->level<90)
     result=not;
    else result=!not;
    break;
   case AR_GUEST:
    if(user==((void *)0) || !(user->rest&(ulong)(1UL<<('G'-'A'))))
     result=not;
    else result=!not;
    break;
   case AR_QNODE:
    if(user==((void *)0) || !(user->rest&(ulong)(1UL<<('Q'-'A'))))
     result=not;
    else result=!not;
    break;
   case AR_QUIET:
    result=not;
    break;
   case AR_LOCAL:
    result=not;
    break;
   case AR_DAY:
    now=time(((void *)0));
    localtime_r(&now,&tm);
    if((equal && tm.tm_wday!=(int)n)
     || (!equal && tm.tm_wday<(int)n))
     result=not;
    else
     result=!not;
    break;
   case AR_CREDIT:
    l=(unsigned long)i*1024UL;
    if(user==((void *)0)
     || (equal && user->cdt+user->freecdt!=l)
     || (!equal && user->cdt+user->freecdt<l))
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_NODE:
    if((equal && cfg->node_num!=n) || (!equal && cfg->node_num<n))
     result=not;
    else
     result=!not;
    break;
   case AR_USER:
    if(user==((void *)0)
     || (equal && user->number!=i)
     || (!equal && user->number<i))
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_GROUP:
    if(user==((void *)0))
     result=not;
    else {
     l=getgrpnum(cfg,user->cursub);
     if((equal && l!=i) || (!equal && l<i))
      result=not;
     else
      result=!not;
    }
    (*ptrptr)++;
    break;
   case AR_SUB:
    if(user==((void *)0))
     result=not;
    else {
     l=getsubnum(cfg,user->cursub);
     if((equal && l!=i) || (!equal && l<i))
      result=not;
     else
      result=!not;
    }
    (*ptrptr)++;
    break;
   case AR_SUBCODE:
    if(user!=((void *)0) && strcasecmp(user->cursub,(char *)*ptrptr)==0)
     result=!not;
    else
     result=not;
    result=not;
    while(*(*ptrptr))
     (*ptrptr)++;
    break;
   case AR_LIB:
    if(user==((void *)0))
     result=not;
    else {
     l=getlibnum(cfg,user->curdir);
     if((equal && l!=i) || (!equal && l<i))
      result=not;
     else
      result=!not;
    }
    (*ptrptr)++;
    break;
   case AR_DIR:
    if(user==((void *)0))
     result=not;
    else {
     l=getdirnum(cfg,user->curdir);
     if((equal && l!=i) || (!equal && l<i))
      result=not;
     else
      result=!not;
    }
    (*ptrptr)++;
    break;
   case AR_DIRCODE:
    if(user!=((void *)0) && strcasecmp(user->curdir,(char *)*ptrptr)==0)
     result=!not;
    else
     result=not;
    while(*(*ptrptr))
     (*ptrptr)++;
    break;
   case AR_EXPIRE:
    now=time(((void *)0));
    if(user==((void *)0)
     || user->expire==0
     || now+((long)i*24L*60L*60L)>user->expire)
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_RANDOM:
    n=xp_random(i+1);
    if((equal && n!=i) || (!equal && n<i))
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_LASTON:
    now=time(((void *)0));
    if(user==((void *)0) || (now-user->laston)/(24L*60L*60L)<(long)i)
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_LOGONS:
    if(user==((void *)0)
     || (equal && user->logons!=i)
     || (!equal && user->logons<i))
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_MAIN_CMDS:
    result=not;
    (*ptrptr)++;
    break;
   case AR_FILE_CMDS:
    result=not;
    (*ptrptr)++;
    break;
   case AR_TLEFT:
    result=not;
    break;
   case AR_TUSED:
    result=not;
    break;
   case AR_TIME:
    now=time(((void *)0));
    localtime_r(&now,&tm);
    if((tm.tm_hour*60)+tm.tm_min<(int)i)
     result=not;
    else
     result=!not;
    (*ptrptr)++;
    break;
   case AR_PCR:
    if(user==((void *)0))
     result=not;
    else if(user->logons>user->posts
     && (!user->posts || 100/((float)user->logons/user->posts)<(long)n))
     result=not;
    else
     result=!not;
    break;
   case AR_UDR:
    if(user==((void *)0))
     result=not;
    else {
     l=user->dlb;
     if(!l) l=1;
     if(user->dlb>user->ulb
      && (!user->ulb || 100/((float)l/user->ulb)<n))
      result=not;
     else
      result=!not;
    }
    break;
   case AR_UDFR:
    if(user==((void *)0))
     result=not;
    else {
     i=user->dls;
     if(!i) i=1;
     if(user->dls>user->uls
      && (!user->uls || 100/((float)i/user->uls)<n))
      result=not;
     else
      result=!not;
    }
    break;
   case AR_FLAG1:
    if(user==((void *)0)
     || (!equal && !(user->flags1&(ulong)(1UL<<(n-'A'))))
     || (equal && user->flags1!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_FLAG2:
    if(user==((void *)0)
     || (!equal && !(user->flags2&(ulong)(1UL<<(n-'A'))))
     || (equal && user->flags2!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_FLAG3:
    if(user==((void *)0)
     || (!equal && !(user->flags3&(ulong)(1UL<<(n-'A'))))
     || (equal && user->flags3!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_FLAG4:
    if(user==((void *)0)
     || (!equal && !(user->flags4&(ulong)(1UL<<(n-'A'))))
     || (equal && user->flags4!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_REST:
    if(user==((void *)0)
     || (!equal && !(user->rest&(ulong)(1UL<<(n-'A'))))
     || (equal && user->rest!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_EXEMPT:
    if(user==((void *)0)
     || (!equal && !(user->exempt&(ulong)(1UL<<(n-'A'))))
     || (equal && user->exempt!=(ulong)(1UL<<(n-'A'))))
     result=not;
    else
     result=!not;
    break;
   case AR_SEX:
    if(user==((void *)0) || user->sex!=n)
     result=not;
    else
     result=!not;
    break;
   case AR_SHELL:
    if(user==((void *)0)
     || user->shell>=cfg->total_shells
     || strcasecmp(cfg->shell[user->shell]->code,(char *)*ptrptr))
     result=not;
    else
     result=!not;
    while(*(*ptrptr))
     (*ptrptr)++;
    break;
   case AR_PROT:
    if(user==((void *)0)
     || strcasecmp(user->modem,(char *)*ptrptr))
     result=not;
    else
     result=!not;
    while(*(*ptrptr))
     (*ptrptr)++;
    break;
  }
 }
 return(result);
}

variable_types:
ptrptr
unsigned char **

variable_types: struct user_t { unsigned short number; char alias[-1]; unsigned char level; unsigned long misc; long firston; } *

variable_types: result int

variable_types: not int

variable_types: or int

variable_types: equal int

variable_types:
n
unsigned int

variable_types:
artype
unsigned int

variable_types:
age
unsigned int

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

user_defined_types: struct mdm_result_t { unsigned short code; char str[-1]; }

user_defined_types: struct grp_t { char lname[-1]; unsigned char *ar; }

user_defined_types: struct lib_t { char lname[-1]; unsigned char *ar; unsigned short offline_dir; }

user_defined_types: struct dir_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short maxfiles; unsigned long misc; }

user_defined_types: struct txtsec_t { char code[-1]; char name[41]; unsigned char *ar; }

user_defined_types: struct xtrnsec_t { char code[-1]; char name[41]; unsigned char *ar; }

user_defined_types: struct xtrn_t { char code[-1]; char name[41]; unsigned char *ar; unsigned char type; unsigned short sec; unsigned long cost; }

user_defined_types: struct prot_t { char mnemonic; char name[26]; unsigned char *ar; unsigned long misc; }

user_defined_types: struct fextr_t { char ext[4]; char arstr[-1]; unsigned char *ar; }

user_defined_types: struct fcomp_t { char ext[4]; char arstr[-1]; unsigned char *ar; }

user_defined_types: struct fview_t { char ext[4]; char arstr[-1]; unsigned char *ar; }

user_defined_types: struct ftest_t { char ext[4]; char arstr[-1]; unsigned char *ar; }

user_defined_types: struct xedit_t { char code[-1]; unsigned char *ar; unsigned long misc; unsigned char type; }

user_defined_types: struct qhub_t { char id[-1]; unsigned short time; long last; }

user_defined_types: struct phub_t { char days; unsigned short time; long last; }

user_defined_types: struct chan_t { char code[-1]; char name[26]; char arstr[-1]; unsigned char *ar; unsigned short actset; unsigned long cost; }

user_defined_types: struct chatact_t { char cmd[-1]; unsigned short actset; }

user_defined_types: struct page_t { char cmd[-1]; unsigned char *ar; unsigned long misc; }

user_defined_types: struct event_t { char code[-1]; unsigned short node; unsigned long misc; long last; }

user_defined_types: struct dlevent_t { char ext[4]; char arstr[-1]; unsigned char *ar; }

user_defined_types: struct natvpgm_t { char name[13]; unsigned long misc; }

user_defined_types: struct guru_t { char code[-1]; char name[26]; unsigned char *ar; }

user_defined_types: struct shell_t { char code[-1]; char name[41]; unsigned char *ar; unsigned long misc; }

user_defined_types: struct hotkey_t { unsigned char key; char cmd[-1]; }

user_defined_types: struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; }


decompiled_code:
__int64 __fastcall sbbs_t::chk_ar(__int64 a1, const char *a2, unsigned __int16 *a3)
{
const char *v4; // [rsp+28h] [rbp-8h] BYREF

if ( !a2 )
return 1LL;
v4 = a2;
return sbbs_t::ar_exp(a1, &v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func1(__int64 a1, const char *a2, unsigned __int16 *a3)
{
const char *v4; // [rsp+28h] [rbp-8h] BYREF

if ( !a2 )
return 1LL;
v4 = a2;
return sbbs_t::func0(a1, &v4, a3);
}

original_code:
int chk_ar(scfg_t* cfg, unsigned char *ar, user_t* user)
{
 unsigned char *p;
 if(ar==((void *)0))
  return(1);
 if(!(cfg!=((void *)0) && cfg->size==sizeof(scfg_t)))
  return(0);
 p=ar;
 return(ar_exp(cfg,&p,user));
}

canonical_original_code:
int chk_ar(struct scfg_t *cfg, unsigned char *ar, struct user_t *user)
{
 unsigned char *p;
 if(ar==((void *)0))
  return(1);
 if(!(cfg!=((void *)0) && cfg->size==sizeof(scfg_t)))
  return(0);
 p=ar;
 return(ar_exp(cfg,&p,user));
}

variable_types: struct scfg_t { unsigned long size; int prepped; struct grp_t { char lname[-1]; unsigned char *ar; } **grp; unsigned short total_grps; struct sub_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short grp; unsigned long misc; struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; } faddr; } **sub; unsigned short total_subs; struct lib_t { char lname[-1]; unsigned char *ar; unsigned short offline_dir; } **lib; unsigned short total_libs; struct dir_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short maxfiles; unsigned long misc; } **dir; unsigned short total_dirs; struct txtsec_t { char code[-1]; char name[41]; unsigned char *ar; } **txtsec; unsigned short total_txtsecs; struct xtrnsec_t { char code[-1]; char name[41]; unsigned char *ar; } **xtrnsec; unsigned short total_xtrnsecs; struct xtrn_t { char code[-1]; char name[41]; unsigned char *ar; unsigned char type; unsigned short sec; unsigned long cost; } **xtrn; unsigned short total_xtrns; struct mdm_result_t { unsigned short code; char str[-1]; } *mdm_result; unsigned short mdm_results; struct prot_t { char mnemonic; char name[26]; unsigned char *ar; unsigned long misc; } **prot; unsigned short total_prots; struct fextr_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **fextr; unsigned short total_fextrs; struct fcomp_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **fcomp; unsigned short total_fcomps; struct fview_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **fview; unsigned short total_fviews; struct ftest_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **ftest; unsigned short total_ftests; struct xedit_t { char code[-1]; unsigned char *ar; unsigned long misc; unsigned char type; } **xedit; unsigned short total_xedits; struct qhub_t { char id[-1]; unsigned short time; long last; } **qhub; unsigned short total_qhubs; struct phub_t { char days; unsigned short time; long last; } **phub; unsigned short total_phubs; struct chan_t { char code[-1]; char name[26]; char arstr[-1]; unsigned char *ar; unsigned short actset; unsigned long cost; } **chan; unsigned short total_chans; struct chatact_t { char cmd[-1]; unsigned short actset; } **chatact; unsigned short total_chatacts; struct actset_t { char name[26]; } **actset; unsigned short total_actsets; struct page_t { char cmd[-1]; unsigned char *ar; unsigned long misc; } **page; unsigned short total_pages; struct event_t { char code[-1]; unsigned short node; unsigned long misc; long last; } **event; unsigned short total_events; struct dlevent_t { char ext[4]; char arstr[-1]; unsigned char *ar; } **dlevent; unsigned short total_dlevents; struct fidoaddr_t *faddr; unsigned short total_faddrs; struct swap_t { char cmd[-1]; } **swap; unsigned short total_swaps; struct natvpgm_t { char name[13]; unsigned long misc; } **natvpgm; unsigned short total_natvpgms; struct guru_t { char code[-1]; char name[26]; unsigned char *ar; } **guru; unsigned short total_gurus; struct shell_t { char code[-1]; char name[41]; unsigned char *ar; unsigned long misc; } **shell; unsigned short total_shells; struct hotkey_t { unsigned char key; char cmd[-1]; } **hotkey; unsigned short total_hotkeys; unsigned short com_base; unsigned long com_rate; char com_port; char mdm_init[64]; unsigned long mdm_misc; unsigned short mdm_reinit; unsigned short mdm_ansdelay; unsigned char mdm_rings; long sys_misc; char sys_pass[41]; char sys_name[41]; char sys_id[-1]; char sys_psname[13]; unsigned long sys_psnum; char sys_inetaddr[128]; char sys_location[41]; short sys_timezone; char sys_daily[-1]; char sys_logon[-1]; char sys_logout[-1]; unsigned short sys_pwdays; unsigned short sys_deldays; unsigned short sys_autodel; unsigned short sys_nodes; char sys_op[41]; char sys_guru[41]; unsigned char sys_exp_warn; char sys_def_stat; char sys_phonefmt[-1]; unsigned short sys_lastnode; unsigned short sys_autonode; char sys_chat_arstr[-1]; unsigned char *sys_chat_ar; long msg_misc; long file_misc; long xtrn_misc; char node_comspec[-1]; char node_editor[-1]; char node_viewer[-1]; char node_daily[-1]; unsigned char node_scrnlen; unsigned char node_scrnblank; unsigned long node_misc; unsigned short node_valuser; unsigned short node_ivt; unsigned char node_swap; char node_swapdir[-1]; unsigned short node_minbps; unsigned short node_num; char node_phone[13]; char node_arstr[-1]; unsigned char *node_ar; unsigned long node_cost; unsigned char node_dollars_per_call; unsigned short node_sem_check; unsigned short node_stat_check; char new_install; char new_pass[41]; char new_magic[21]; char new_sif[-1]; char new_sof[-1]; char new_level; unsigned long new_flags1; unsigned long new_flags2; unsigned long new_flags3; unsigned long new_flags4; unsigned long new_exempt; unsigned long new_rest; unsigned long new_cdt; unsigned long new_min; char new_xedit[-1]; unsigned short new_shell; unsigned long new_misc; unsigned short new_expire; unsigned char new_prot; char val_level[10]; unsigned long val_flags1[10]; unsigned long val_flags2[10]; unsigned long val_flags3[10]; unsigned long val_flags4[10]; unsigned long val_exempt[10]; unsigned long val_rest[10]; unsigned long val_cdt[10]; unsigned short val_expire[10]; unsigned char level_expireto[100]; unsigned short level_timepercall[100]; long level_freecdtperday[100]; long level_misc[100]; char expired_level; unsigned long expired_flags1; unsigned long expired_flags2; unsigned long expired_flags3; unsigned long expired_flags4; unsigned long expired_exempt; unsigned long expired_rest; unsigned short min_dspace; unsigned short max_batup; unsigned short max_batdn; unsigned short max_userxfer; unsigned long max_minutes; unsigned long max_qwkmsgs; char preqwk_arstr[-1]; unsigned char *preqwk_ar; unsigned short cdt_min_value; unsigned long cdt_per_dollar; unsigned short cdt_up_pct; unsigned short cdt_dn_pct; char node_dir[-1]; char ctrl_dir[-1]; char data_dir[-1]; char text_dir[-1]; char exec_dir[-1]; char temp_dir[-1]; char mods_dir[-1]; char logs_dir[-1]; char node_path[250][-1]; unsigned short sysop_dir; unsigned short user_dir; unsigned short upload_dir; char **altpath; unsigned short altpaths; unsigned short leech_pct; unsigned short leech_sec; unsigned long netmail_cost; char netmail_dir[-1]; unsigned short netmail_misc; unsigned long inetmail_misc; unsigned long inetmail_cost; char smtpmail_sem[-1]; char inetmail_sem[-1]; char echomail_dir[-1]; char fidofile_dir[-1]; char netmail_sem[-1]; char echomail_sem[-1]; char origline[51]; char qnet_tagline[128]; long uq; unsigned long mail_maxcrcs; unsigned short mail_maxage; struct fidoaddr_t dflt_faddr; char logon_mod[-1]; char logoff_mod[-1]; char newuser_mod[-1]; char login_mod[-1]; char logout_mod[-1]; char sync_mod[-1]; char expire_mod[-1]; char scfg_cmd[-1]; unsigned char smb_retry_time; unsigned short sec_warn; unsigned short sec_hangup; char *color; unsigned long total_colors; unsigned long ctrlkey_passthru; char wfc_cmd[10][-1]; char wfc_scmd[12][-1]; unsigned short user_backup_level; unsigned short mail_backup_level; } *

variable_types:
ar
unsigned char *

variable_types:
p
unsigned char *

user_defined_types: struct scfg_t { unsigned long size; int prepped; struct grp_t **grp; unsigned short total_grps; struct sub_t **sub; unsigned short total_subs; struct lib_t **lib; unsigned short total_libs; struct dir_t **dir; unsigned short total_dirs; struct txtsec_t **txtsec; unsigned short total_txtsecs; struct xtrnsec_t **xtrnsec; unsigned short total_xtrnsecs; struct xtrn_t **xtrn; unsigned short total_xtrns; struct mdm_result_t *mdm_result; unsigned short mdm_results; struct prot_t **prot; unsigned short total_prots; struct fextr_t **fextr; unsigned short total_fextrs; struct fcomp_t **fcomp; unsigned short total_fcomps; struct fview_t **fview; unsigned short total_fviews; struct ftest_t **ftest; unsigned short total_ftests; struct xedit_t **xedit; unsigned short total_xedits; struct qhub_t **qhub; unsigned short total_qhubs; struct phub_t **phub; unsigned short total_phubs; struct chan_t **chan; unsigned short total_chans; struct chatact_t **chatact; unsigned short total_chatacts; struct actset_t **actset; unsigned short total_actsets; struct page_t **page; unsigned short total_pages; struct event_t **event; unsigned short total_events; struct dlevent_t **dlevent; unsigned short total_dlevents; struct fidoaddr_t *faddr; unsigned short total_faddrs; struct swap_t **swap; unsigned short total_swaps; struct natvpgm_t **natvpgm; unsigned short total_natvpgms; struct guru_t **guru; unsigned short total_gurus; struct shell_t **shell; unsigned short total_shells; struct hotkey_t **hotkey; unsigned short total_hotkeys; unsigned short com_base; unsigned long com_rate; char com_port; char mdm_init[64]; unsigned long mdm_misc; unsigned short mdm_reinit; unsigned short mdm_ansdelay; unsigned char mdm_rings; long sys_misc; char sys_pass[41]; char sys_name[41]; char sys_id[-1]; char sys_psname[13]; unsigned long sys_psnum; char sys_inetaddr[128]; char sys_location[41]; short sys_timezone; char sys_daily[-1]; char sys_logon[-1]; char sys_logout[-1]; unsigned short sys_pwdays; unsigned short sys_deldays; unsigned short sys_autodel; unsigned short sys_nodes; char sys_op[41]; char sys_guru[41]; unsigned char sys_exp_warn; char sys_def_stat; char sys_phonefmt[-1]; unsigned short sys_lastnode; unsigned short sys_autonode; char sys_chat_arstr[-1]; unsigned char *sys_chat_ar; long msg_misc; long file_misc; long xtrn_misc; char node_comspec[-1]; char node_editor[-1]; char node_viewer[-1]; char node_daily[-1]; unsigned char node_scrnlen; unsigned char node_scrnblank; unsigned long node_misc; unsigned short node_valuser; unsigned short node_ivt; unsigned char node_swap; char node_swapdir[-1]; unsigned short node_minbps; unsigned short node_num; char node_phone[13]; char node_arstr[-1]; unsigned char *node_ar; unsigned long node_cost; unsigned char node_dollars_per_call; unsigned short node_sem_check; unsigned short node_stat_check; char new_install; char new_pass[41]; char new_magic[21]; char new_sif[-1]; char new_sof[-1]; char new_level; unsigned long new_flags1; unsigned long new_flags2; unsigned long new_flags3; unsigned long new_flags4; unsigned long new_exempt; unsigned long new_rest; unsigned long new_cdt; unsigned long new_min; char new_xedit[-1]; unsigned short new_shell; unsigned long new_misc; unsigned short new_expire; unsigned char new_prot; char val_level[10]; unsigned long val_flags1[10]; unsigned long val_flags2[10]; unsigned long val_flags3[10]; unsigned long val_flags4[10]; unsigned long val_exempt[10]; unsigned long val_rest[10]; unsigned long val_cdt[10]; unsigned short val_expire[10]; unsigned char level_expireto[100]; unsigned short level_timepercall[100]; long level_freecdtperday[100]; long level_misc[100]; char expired_level; unsigned long expired_flags1; unsigned long expired_flags2; unsigned long expired_flags3; unsigned long expired_flags4; unsigned long expired_exempt; unsigned long expired_rest; unsigned short min_dspace; unsigned short max_batup; unsigned short max_batdn; unsigned short max_userxfer; unsigned long max_minutes; unsigned long max_qwkmsgs; char preqwk_arstr[-1]; unsigned char *preqwk_ar; unsigned short cdt_min_value; unsigned long cdt_per_dollar; unsigned short cdt_up_pct; unsigned short cdt_dn_pct; char node_dir[-1]; char ctrl_dir[-1]; char data_dir[-1]; char text_dir[-1]; char exec_dir[-1]; char temp_dir[-1]; char mods_dir[-1]; char logs_dir[-1]; char node_path[250][-1]; unsigned short sysop_dir; unsigned short user_dir; unsigned short upload_dir; char **altpath; unsigned short altpaths; unsigned short leech_pct; unsigned short leech_sec; unsigned long netmail_cost; char netmail_dir[-1]; unsigned short netmail_misc; unsigned long inetmail_misc; unsigned long inetmail_cost; char smtpmail_sem[-1]; char inetmail_sem[-1]; char echomail_dir[-1]; char fidofile_dir[-1]; char netmail_sem[-1]; char echomail_sem[-1]; char origline[51]; char qnet_tagline[128]; long uq; unsigned long mail_maxcrcs; unsigned short mail_maxage; struct fidoaddr_t dflt_faddr; char logon_mod[-1]; char logoff_mod[-1]; char newuser_mod[-1]; char login_mod[-1]; char logout_mod[-1]; char sync_mod[-1]; char expire_mod[-1]; char scfg_cmd[-1]; unsigned char smb_retry_time; unsigned short sec_warn; unsigned short sec_hangup; char *color; unsigned long total_colors; unsigned long ctrlkey_passthru; char wfc_cmd[10][-1]; char wfc_scmd[12][-1]; unsigned short user_backup_level; unsigned short mail_backup_level; }

user_defined_types: struct user_t { unsigned short number; char alias[-1]; unsigned char level; unsigned long misc; long firston; }

user_defined_types: struct sub_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short grp; unsigned long misc; struct fidoaddr_t faddr; }


decompiled_code:
__int64 __fastcall sbbs_t::dir_op(sbbs_t *this, unsigned int a2)
{
__int64 result; // rax

LOBYTE(result) = *((_BYTE *)this + 26885) > 0x59u
|| (*((_QWORD *)this + 6414) & 4LL) != 0
|| **(_BYTE **)(*(_QWORD *)(*((_QWORD *)this + 66) + 8LL * a2) + 568LL)
&& (unsigned __int8)sbbs_t::chk_ar(
(__int64)this,
*(const char **)(*(_QWORD *)(*((_QWORD *)this + 66) + 8LL * a2) + 568LL),
(unsigned __int16 *)this + 13224);
return (unsigned __int8)result;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func5(sbbs_t *this, unsigned int a2)
{
__int64 result; // rax

LOBYTE(result) = *((_BYTE *)this + 26885) > 0x59u
|| (*((_QWORD *)this + 6414) & 4LL) != 0
|| **(_BYTE **)(*(_QWORD *)(*((_QWORD *)this + 66) + 8LL * a2) + 568LL)
&& (unsigned __int8)sbbs_t::func1(
(__int64)this,
*(const char **)(*(_QWORD *)(*((_QWORD *)this + 66) + 8LL * a2) + 568LL),
(unsigned __int16 *)this + 13224);
return (unsigned __int8)result;
}

original_code:
int dir_op(scfg_t* cfg, user_t* user, uint dirnum)
{
 return(user->level>=90 || user->exempt&(ulong)(1UL<<('R'-'A'))
  || (cfg->dir[dirnum]->op_ar[0] && chk_ar(cfg,cfg->dir[dirnum]->op_ar,user)));
}

canonical_original_code:
int dir_op(struct scfg_t *cfg, struct user_t *user, unsigned int dirnum)
{
 return(user->level>=90 || user->exempt&(ulong)(1UL<<('R'-'A'))
  || (cfg->dir[dirnum]->op_ar[0] && chk_ar(cfg,cfg->dir[dirnum]->op_ar,user)));
}

variable_types:
dirnum
unsigned int

user_defined_types: struct mdm_result_t { unsigned short code; char str[-1]; }

user_defined_types: struct grp_t { char lname[-1]; unsigned char *ar; }

user_defined_types: struct lib_t { char lname[-1]; unsigned char *ar; unsigned short offline_dir; }

user_defined_types: struct dir_t { char code[-1]; char code_suffix[-1]; char lname[-1]; unsigned char *ar; unsigned short maxfiles; unsigned long misc; }

user_defined_types: struct txtsec_t { char code[-1]; char name[41]; unsigned char *ar; }

user_defined_types: struct xtrnsec_t { char code[-1]; char name[41]; unsigned char *ar; }

user_defined_types: struct xtrn_t { char code[-1]; char name[41]; unsigned char *ar; unsigned char type; unsigned short sec; unsigned long cost; }

user_defined_types: struct prot_t { char mnemonic; char name[26]; unsigned char *ar; unsigned long misc; }

user_defined_types: struct fextr_t { char ext[4]; char arstr[-1]; unsigned char *ar; }

user_defined_types: struct fcomp_t { char ext[4]; char arstr[-1]; unsigned char *ar; }

user_defined_types: struct fview_t { char ext[4]; char arstr[-1]; unsigned char *ar; }

user_defined_types: struct ftest_t { char ext[4]; char arstr[-1]; unsigned char *ar; }


decompiled_code:
__int64 __fastcall msgid_serialno(__int64 a1)
{
int v1; // ebp

v1 = msg_time(a1);
return (int)(v1 + msg_number(a1) - 1000000000);
}

original_code:
static ulong msgid_serialno(smbmsg_t* msg)
{
 return (msg_time(msg)-1000000000) + msg_number(msg);
}

canonical_original_code:
static unsigned long msgid_serialno(struct smbmsg_t *msg)
{
 return (msg_time(msg)-1000000000) + msg_number(msg);
}

variable_types: struct smbmsg_t { struct idxrec_t { unsigned short to; unsigned short from; unsigned short subj; unsigned short attr; unsigned long offset; unsigned long number; unsigned long time; } idx; struct msghdr_t { unsigned char id[4]; unsigned short type; unsigned short version; unsigned short length; unsigned short attr; unsigned long auxattr; unsigned long netattr; struct when_t { unsigned long time; short zone; } when_written; struct when_t when_imported; unsigned long number; unsigned long thread_back; unsigned long thread_next; unsigned long thread_first; unsigned short delivery_attempts; unsigned long times_downloaded; unsigned long last_downloaded; unsigned char reserved[6]; unsigned long offset; unsigned short total_dfields; } hdr; char *to; char *summary; char *subj; unsigned short to_agent; struct net_t { unsigned short type; void *addr; } to_net; unsigned short total_hfields; struct hfield_t { unsigned short type; unsigned short length; } *hfield; void **hfield_dat; struct dfield_t { unsigned short type; unsigned long offset; unsigned long length; } *dfield; long offset; int forwarded; unsigned long expiration; unsigned long priority; unsigned long cost; unsigned long flags; } *

user_defined_types: struct smbmsg_t { struct idxrec_t idx; struct msghdr_t hdr; char *to; char *summary; char *subj; unsigned short to_agent; struct net_t to_net; unsigned short total_hfields; struct hfield_t *hfield; void **hfield_dat; struct dfield_t *dfield; long offset; int forwarded; unsigned long expiration; unsigned long priority; unsigned long cost; unsigned long flags; }

user_defined_types: struct msghdr_t { unsigned char id[4]; unsigned short type; unsigned short version; unsigned short length; unsigned short attr; unsigned long auxattr; unsigned long netattr; struct when_t when_written; struct when_t when_imported; unsigned long number; unsigned long thread_back; unsigned long thread_next; unsigned long thread_first; unsigned short delivery_attempts; unsigned long times_downloaded; unsigned long last_downloaded; unsigned char reserved[6]; unsigned long offset; unsigned short total_dfields; }


decompiled_code:
__int64 __fastcall add_char(_BYTE *a1, char a2, int a3, unsigned __int64 a4)
{
__int64 result; // rax

result = 1LL;
if ( (unsigned __int64)a1 < a4 )
{
if ( a3 )
*a1 = 61;
else
*a1 = *(&s + a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, char a2, int a3, unsigned __int64 a4)
{
__int64 result; // rax

result = 1LL;
if ( (unsigned __int64)a1 < a4 )
{
if ( a3 )
*a1 = 61;
else
*a1 = *(&s + a2);
result = 0LL;
}
return result;
}

original_code:
static int add_char(char *pos, char ch, int done, char *end)
{
 if(pos>=end) {
  return(1);
 }
 if(done)
  *pos=base64alphabet[64];
 else
  *pos=base64alphabet[(int)ch];
 return(0);
}

variable_types:
pos
char *

variable_types: ch char

variable_types: done int

variable_types:
end
char *


decompiled_code:
__int64 __fastcall b64_decode(_BYTE *a1, __int64 a2, const char *a3, size_t a4)
{
const char *v4; // rbx
_BYTE *v5; // r15
char *v6; // r14
_BYTE *v7; // r12
int v8; // er13
int v9; // ebp
__int64 result; // rax
int v11; // er13
char *v12; // rax

v4 = a3;
if ( !a4 )
a4 = strlen(a3);
v5 = &a1[a2];
v6 = (char *)&v4[a4];
if ( a1 >= &a1[a2] || v4 >= v6 )
{
v7 = a1;
LABEL_7:
if ( v5 == v7 )
{
*(v7 - 1) = 0;
result = 0xFFFFFFFFLL;
}
else
{
*v7 = 0;
result = (unsigned int)((_DWORD)v7 - (_DWORD)a1);
}
}
else
{
v7 = a1;
v8 = 0;
v9 = 0;
while ( 1 )
{
v11 = v8 << 6;
v12 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", *v4);
if ( !v12 )
return 0xFFFFFFFFLL;
if ( *v12 == 61 )
break;
v8 = (v12 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=") | v11;
if ( v9 + 6 <= 7 )
{
v9 += 6;
}
else
{
v9 -= 2;
*v7++ = (v8 & (255 << v9)) >> v9;
}
++v4;
if ( v7 >= v5 || v6 <= v4 )
goto LABEL_7;
}
if ( !(_BYTE)v11 )
goto LABEL_7;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, __int64 a2, const char *a3, size_t a4)
{
const char *v4; // rbx
_BYTE *v5; // r15
char *v6; // r14
_BYTE *v7; // r12
int v8; // er13
int v9; // ebp
__int64 result; // rax
int v11; // er13
char *v12; // rax

v4 = a3;
if ( !a4 )
a4 = strlen(a3);
v5 = &a1[a2];
v6 = (char *)&v4[a4];
if ( a1 >= &a1[a2] || v4 >= v6 )
{
v7 = a1;
LABEL_7:
if ( v5 == v7 )
{
*(v7 - 1) = 0;
result = 0xFFFFFFFFLL;
}
else
{
*v7 = 0;
result = (unsigned int)((_DWORD)v7 - (_DWORD)a1);
}
}
else
{
v7 = a1;
v8 = 0;
v9 = 0;
while ( 1 )
{
v11 = v8 << 6;
v12 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", *v4);
if ( !v12 )
return 0xFFFFFFFFLL;
if ( *v12 == 61 )
break;
v8 = (v12 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=") | v11;
if ( v9 + 6 <= 7 )
{
v9 += 6;
}
else
{
v9 -= 2;
*v7++ = (v8 & (255 << v9)) >> v9;
}
++v4;
if ( v7 >= v5 || v6 <= v4 )
goto LABEL_7;
}
if ( !(_BYTE)v11 )
goto LABEL_7;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int b64_decode(char *target, size_t tlen, const char *source, size_t slen)
{
 const char *inp;
 char *outp;
 char *outend;
 const char *inend;
 int bits=0;
 int working=0;
 char * i;
 if(slen==0)
  slen=strlen(source);
 outp=target;
 inp=source;
 outend=target+tlen;
 inend=source+slen;
 for(;outp<outend && inp<inend;inp++) {
  working<<=6;
  i=strchr(base64alphabet,(char)*inp);
  if(i==((void *)0)) {
   return(-1);
  }
  if(*i=='=') {
   if((working&0xFF) != 0)
    return(-1);
   break;
  }
  bits+=6;
  working |= (i-base64alphabet);
  if(bits>=8) {
   *(outp++)=(char)((working&(0xFF<<(bits-8)))>>(bits-8));
   bits-=8;
  }
 }
 if(outp == outend) {
  *(--outp)=0;
  return(-1);
 }
 *outp=0;
 return(outp-target);
}

canonical_original_code:
int b64_decode(char *target, unsigned long tlen, char *source, unsigned long slen)
{
 char *inp;
 char *outp;
 char *outend;
 char *inend;
 int bits = 0;
 int working = 0;
 char *i;
 if(slen==0)
  slen=strlen(source);
 outp=target;
 inp=source;
 outend=target+tlen;
 inend=source+slen;
 for(;outp<outend && inp<inend;inp++) {
  working<<=6;
  i=strchr(base64alphabet,(char)*inp);
  if(i==((void *)0)) {
   return(-1);
  }
  if(*i=='=') {
   if((working&0xFF) != 0)
    return(-1);
   break;
  }
  bits+=6;
  working |= (i-base64alphabet);
  if(bits>=8) {
   *(outp++)=(char)((working&(0xFF<<(bits-8)))>>(bits-8));
   bits-=8;
  }
 }
 if(outp == outend) {
  *(--outp)=0;
  return(-1);
 }
 *outp=0;
 return(outp-target);
}

variable_types:
target
char *

variable_types:
tlen
unsigned long

variable_types:
source
char *

variable_types:
slen
unsigned long

variable_types:
inp
char *

variable_types:
outp
char *

variable_types:
outend
char *

variable_types:
inend
char *

variable_types: bits int

variable_types: working int

variable_types:
i
char *