initWorldMutex

decompiled_code:
int __fastcall initWorldMutex(__int64 a1)
{
return pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
return pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL);
}

original_code:
void initWorldMutex(struct World *world)
{
 pthread_mutex_init(&world->platformData.mutex, ((void *)0));
}

variable_types: struct World { struct Session { struct DCirList { struct DCirList *next; struct DCirList *prev; } list; struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; } sessionID; struct InetConnection { struct DCirList list; struct Session *member; struct World *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter { unsigned int count; unsigned int mask; } recvStatSN; unsigned int statSN; struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList { struct DCirList list; struct PDU { struct { struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 { unsigned char b[3]; } dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; } bhs; union { unsigned int headerDigest; struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; } ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer { struct DCirList list; struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; } ap; } *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; } *dataSeg; }; unsigned char *data; } pdu; } *pdus; struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; } r2t; struct Counter dataSN; struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T *r2tRes; struct ResponseTask *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer *readBuffer; struct Buffer *imWriteBuffer; struct R2T *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session *ses; void *targetHandle; void *classHandle; } cmd; } *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; } *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; } readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; } *params; } *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param *params; struct Counter cmdSN; struct Task *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; } *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); } cclass; unsigned int pendingCommands; int maxfd; struct fd_set { long __fds_bits[-1]; } rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; } *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux { 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; } mutex; } platformData; struct confElement { struct confElemList { struct confElement *next; struct confElement *prev; } list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; } *trgs; struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; } cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; } *

user_defined_types: struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux platformData; struct confElement *trgs; struct configuration cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; }

user_defined_types: struct _spec_world_linux { union pthread_mutex_t mutex; }

user_defined_types: struct Session { struct DCirList list; struct ISID_TSIH sessionID; struct InetConnection *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param *params; struct Counter cmdSN; struct Task *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass cclass; unsigned int pendingCommands; int maxfd; struct fd_set rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; }

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

user_defined_types: struct confElement { struct confElemList list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; }

user_defined_types: struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); }

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; }

user_defined_types: struct InetConnection { struct DCirList list; struct Session *member; struct World *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter recvStatSN; unsigned int statSN; struct ResponseTask *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param *params; }

user_defined_types: struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList *pdus; struct R2T r2t; struct Counter dataSN; struct Task *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; }

user_defined_types: struct PDUList { struct DCirList list; struct PDU pdu; }

user_defined_types: struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T *r2tRes; struct ResponseTask *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand cmd; }

user_defined_types: struct PDU { struct { struct bhsBase bhs; union { unsigned int headerDigest; struct AHS ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer *dataSeg; }; unsigned char *data; }

user_defined_types: struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; }

user_defined_types: struct Buffer { struct DCirList list; struct BufferAllocator *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; }

user_defined_types: struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam ap; }


lockWorld

repo: sergforce/iscsi

decompiled_code:
__int64 __fastcall lockWorld(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
return 0LL;
}

original_code:
int lockWorld(struct World *world)
{
 pthread_mutex_lock(&world->platformData.mutex);
 return 0;
}

return_type: int

user_defined_types: struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; }

user_defined_types: struct DCirList { struct DCirList *next; struct DCirList *prev; }

user_defined_types: struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; }

user_defined_types: struct confElemList { struct confElement *next; struct confElement *prev; }

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

user_defined_types: struct Counter { unsigned int count; unsigned int mask; }

user_defined_types: struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; }

user_defined_types: struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; }

user_defined_types: struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; }

user_defined_types: struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; }

user_defined_types: struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer *readBuffer; struct Buffer *imWriteBuffer; struct R2T *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session *ses; void *targetHandle; void *classHandle; }

user_defined_types: struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; }

user_defined_types: struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; }


releaseWorld

decompiled_code:
__int64 __fastcall releaseWorld(__int64 a1)
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return 0LL;
}

original_code:
int releaseWorld(struct World *world)
{
 pthread_mutex_unlock(&world->platformData.mutex);
 return 0;
}

user_defined_types: struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux platformData; struct confElement *trgs; struct configuration cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; }

user_defined_types: struct _spec_world_linux { union pthread_mutex_t mutex; }

user_defined_types: struct Session { struct DCirList list; struct ISID_TSIH sessionID; struct InetConnection *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param *params; struct Counter cmdSN; struct Task *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass cclass; unsigned int pendingCommands; int maxfd; struct fd_set rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; }

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

user_defined_types: struct confElement { struct confElemList list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; }

user_defined_types: struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); }

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; }

user_defined_types: struct InetConnection { struct DCirList list; struct Session *member; struct World *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter recvStatSN; unsigned int statSN; struct ResponseTask *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param *params; }

user_defined_types: struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList *pdus; struct R2T r2t; struct Counter dataSN; struct Task *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; }

user_defined_types: struct PDUList { struct DCirList list; struct PDU pdu; }

user_defined_types: struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T *r2tRes; struct ResponseTask *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand cmd; }

user_defined_types: struct PDU { struct { struct bhsBase bhs; union { unsigned int headerDigest; struct AHS ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer *dataSeg; }; unsigned char *data; }


freeWorldMutex

decompiled_code:
void freeWorldMutex()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void freeWorldMutex(struct World *world)
{
}

return_type: void

user_defined_types: struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; }

user_defined_types: struct DCirList { struct DCirList *next; struct DCirList *prev; }

user_defined_types: struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; }

user_defined_types: struct confElemList { struct confElement *next; struct confElement *prev; }

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

user_defined_types: struct Counter { unsigned int count; unsigned int mask; }

user_defined_types: struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; }

user_defined_types: struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; }

user_defined_types: struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; }

user_defined_types: struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; }

user_defined_types: struct Buffer { struct DCirList list; struct BufferAllocator *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; }

user_defined_types: struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam ap; }


beginigAcceptConnections

decompiled_code:
__int64 beginigAcceptConnections()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 0LL;
}

original_code:
int beginigAcceptConnections(struct World *world)
{
 return 0;
}

user_defined_types: struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux platformData; struct confElement *trgs; struct configuration cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; }

user_defined_types: struct _spec_world_linux { union pthread_mutex_t mutex; }

user_defined_types: struct Session { struct DCirList list; struct ISID_TSIH sessionID; struct InetConnection *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param *params; struct Counter cmdSN; struct Task *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass cclass; unsigned int pendingCommands; int maxfd; struct fd_set rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; }

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

user_defined_types: struct confElement { struct confElemList list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; }

user_defined_types: struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); }

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; }

user_defined_types: struct InetConnection { struct DCirList list; struct Session *member; struct World *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter recvStatSN; unsigned int statSN; struct ResponseTask *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param *params; }

user_defined_types: struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; }

user_defined_types: struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer *readBuffer; struct Buffer *imWriteBuffer; struct R2T *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session *ses; void *targetHandle; void *classHandle; }

user_defined_types: struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; }

user_defined_types: struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; }


initConfiguration

decompiled_code:
__int64 __fastcall initConfiguration(__int64 a1)
{
return initConfigurationFromINI(a1, &inifile);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return initConfigurationFromINI(a1, &inifile);
}

original_code:
int initConfiguration(struct configuration *cnf)
{
 return initConfigurationFromINI(cnf, inifile);
}

variable_types: struct configuration { struct confElement { struct confElemList { struct confElement *next; struct confElement *prev; } list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; } *head; struct confElement *free; struct confElement pool[128]; } *

user_defined_types: struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; }


original_code:
static int sglinux_readSCSIStatus(int fd)
{
 struct tfCommand *cmd;
 sg_io_hdr_t io_hd;
 int res = read(fd, &io_hd, sizeof(sg_io_hdr_t));
 if (res != -1) {
  cmd = (struct tfCommand *)io_hd.usr_ptr;
  cmd->senseLen = io_hd.sb_len_wr;
  cmd->status = io_hd.masked_status;
  if ((io_hd.info & 0x1) != 0x0) {
   if (io_hd.sb_len_wr > 0) {
    cmd->response = 0;
   } else {
    cmd->response = 1;
   }
   cmd->writeCount = 0;
   cmd->readedCount = 0;
  } else {
   cmd->response = 0;
   if ((cmd->writeCount > 0)) {
    cmd->writedCount = cmd->writeCount;
    cmd->readedCount = 0;
   } else if (cmd->residualReadCount > 0) {
    cmd->readedCount = cmd->residualReadCount;
    cmd->writeCount = 0;
   } else {
    cmd->writeCount = 0;
    cmd->readedCount = 0;
   }
  }
 } else {
  ;
  perror("");
  return -1;
 }
 return sesSCSIQueuedResponse(cmd);
}

canonical_original_code:
static int sglinux_readSCSIStatus(int fd)
{
 struct tfCommand *cmd;
 struct sg_io_hdr io_hd;
 int res = read(fd, &io_hd, sizeof(sg_io_hdr_t));
 if (res != -1) {
  cmd = (struct tfCommand *)io_hd.usr_ptr;
  cmd->senseLen = io_hd.sb_len_wr;
  cmd->status = io_hd.masked_status;
  if ((io_hd.info & 0x1) != 0x0) {
   if (io_hd.sb_len_wr > 0) {
    cmd->response = 0;
   } else {
    cmd->response = 1;
   }
   cmd->writeCount = 0;
   cmd->readedCount = 0;
  } else {
   cmd->response = 0;
   if ((cmd->writeCount > 0)) {
    cmd->writedCount = cmd->writeCount;
    cmd->readedCount = 0;
   } else if (cmd->residualReadCount > 0) {
    cmd->readedCount = cmd->residualReadCount;
    cmd->writeCount = 0;
   } else {
    cmd->writeCount = 0;
    cmd->readedCount = 0;
   }
  }
 } else {
  ;
  perror("");
  return -1;
 }
 return sesSCSIQueuedResponse(cmd);
}

variable_types: fd int

variable_types: struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer { struct DCirList { struct DCirList *next; struct DCirList *prev; } list; struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; } ap; } *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; } *readBuffer; struct Buffer *imWriteBuffer; struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; } *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session { struct DCirList list; struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; } sessionID; struct InetConnection { struct DCirList list; struct Session *member; struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux { 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; } mutex; } platformData; struct confElement { struct confElemList { struct confElement *next; struct confElement *prev; } list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; } *trgs; struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; } cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; } *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); } apis[4]; } *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter { unsigned int count; unsigned int mask; } recvStatSN; unsigned int statSN; struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList { struct DCirList list; struct PDU { struct { struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 { unsigned char b[3]; } dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; } bhs; union { unsigned int headerDigest; struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; } ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer *dataSeg; }; unsigned char *data; } pdu; } *pdus; struct R2T r2t; struct Counter dataSN; struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T *r2tRes; struct ResponseTask *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand cmd; } *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; } *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; } readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; } *params; } *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param *params; struct Counter cmdSN; struct Task *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass cclass; unsigned int pendingCommands; int maxfd; struct fd_set { long __fds_bits[-1]; } rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; } *ses; void *targetHandle; void *classHandle; } *

variable_types: struct sg_io_hdr { int interface_id; int dxfer_direction; unsigned char cmd_len; unsigned char mx_sb_len; unsigned short iovec_count; unsigned int dxfer_len; void *dxferp; unsigned char *cmdp; unsigned char *sbp; unsigned int timeout; unsigned int flags; int pack_id; void *usr_ptr; unsigned char status; unsigned char masked_status; unsigned char msg_status; unsigned char sb_len_wr; unsigned short host_status; unsigned short driver_status; int resid; unsigned int duration; unsigned int info; }

variable_types: res int

user_defined_types: struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList *pdus; struct R2T r2t; struct Counter dataSN; struct Task *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; }

user_defined_types: struct PDUList { struct DCirList list; struct PDU pdu; }

user_defined_types: struct PDU { struct { struct bhsBase bhs; union { unsigned int headerDigest; struct AHS ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer *dataSeg; }; unsigned char *data; }


decompiled_code:
__int64 sglinux_tfInit()
{
int v0; // edi
__int64 result; // rax

v0 = open("/proc/scsi/sg/devices", 0);
result = 0LL;
if ( v0 >= 0 )
{
close(v0);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // edi
__int64 result; // rax

v0 = open("/proc/scsi/sg/devices", 0);
result = 0LL;
if ( v0 >= 0 )
{
close(v0);
result = 1LL;
}
return result;
}

original_code:
void *sglinux_tfInit()
{
 int fd = open("/proc/scsi/sg/devices", 00);
 if (fd < 0) {
  ;
  return ((void *)0);
 }
 close(fd);
 return (void *)1;
}

return_type: void *


decompiled_code:
void sglinux_tfCleanup()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void sglinux_tfCleanup(void *handle)
{
}

variable_types:
handle
void *


decompiled_code:
__int64 __fastcall sglinux_tfAttach(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // ebx
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
result = findElement(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a2 + 56) + 40LL) + 24LL), "DeviceName");
if ( result )
{
v3 = open((const char *)(result + 150), 2050);
result = 0LL;
if ( v3 >= 0 )
{
if ( ioctl(v3, 0x2282uLL, v4) < 0 || (result = v3, v4[0] <= 29999) )
{
close(v3);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // ebx
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
result = findElement(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a2 + 56) + 40LL) + 24LL), "DeviceName");
if ( result )
{
v3 = open((const char *)(result + 150), 2050);
result = 0LL;
if ( v3 >= 0 )
{
if ( ioctl(v3, 0x2282uLL, v4) < 0 || (result = v3, v4[0] <= 29999) )
{
close(v3);
result = 0LL;
}
}
}
return result;
}

original_code:
void *sglinux_tfAttach(void *handle, struct Session *ses)
{
 sglinux_data_t sd;
 int ver = 0;
 struct confElement *targetInfo = (struct confElement *)ses->params[2].pvalue;
 struct confElement *devName = findElement(targetInfo->childs, "DeviceName");
 if (!devName) {
  return ((void *)0);
 }
 sd.fd = open(devName->value, 02 | 04000 );
 if (sd.fd < 0) {
  ;
  return ((void *)0);
 }
 if ((ioctl(sd.fd, 0x2282, &ver) < 0) || (ver < 30000)) {
  ;
  close(sd.fd);
  return ((void *)0);
 }
 return (void *)sd.fd;
}

canonical_original_code:
void *sglinux_tfAttach(void *handle, struct Session *ses)
{
 struct _sg_linux sd;
 int ver = 0;
 struct confElement *targetInfo = (struct confElement *)ses->params[2].pvalue;
 struct confElement *devName = findElement(targetInfo->childs, "DeviceName");
 if (!devName) {
  return ((void *)0);
 }
 sd.fd = open(devName->value, 02 | 04000 );
 if (sd.fd < 0) {
  ;
  return ((void *)0);
 }
 if ((ioctl(sd.fd, 0x2282, &ver) < 0) || (ver < 30000)) {
  ;
  close(sd.fd);
  return ((void *)0);
 }
 return (void *)sd.fd;
}

variable_types: struct Session { struct DCirList { struct DCirList *next; struct DCirList *prev; } list; struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; } sessionID; struct InetConnection { struct DCirList list; struct Session *member; struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux { 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; } mutex; } platformData; struct confElement { struct confElemList { struct confElement *next; struct confElement *prev; } list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; } *trgs; struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; } cnf; struct BufferAllocator { struct DCirList list; struct Buffer { struct DCirList list; struct BufferAllocator *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; } *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; } ap; } buffAlloc[2]; int nApis; struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer *readBuffer; struct Buffer *imWriteBuffer; struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; } *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session *ses; void *targetHandle; void *classHandle; } *cmd); int (*tfSCSIManagement)(struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; } *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); } apis[4]; } *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter { unsigned int count; unsigned int mask; } recvStatSN; unsigned int statSN; struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList { struct DCirList list; struct PDU { struct { struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 { unsigned char b[3]; } dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; } bhs; union { unsigned int headerDigest; struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; } ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer *dataSeg; }; unsigned char *data; } pdu; } *pdus; struct R2T r2t; struct Counter dataSN; struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T *r2tRes; struct ResponseTask *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand cmd; } *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; } *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; } readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; } *params; } *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param *params; struct Counter cmdSN; struct Task *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass cclass; unsigned int pendingCommands; int maxfd; struct fd_set { long __fds_bits[-1]; } rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; } *

variable_types:
sd
struct _sg_linux { int fd; }

variable_types: ver int

user_defined_types: struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam ap; }

user_defined_types: struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; }


decompiled_code:
int __fastcall sglinux_tfDetach(__int64 a1, int a2)
{
return close(a2);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2)
{
return close(a2);
}

original_code:
void sglinux_tfDetach(void *handle, void *prot)
{
 close(((int)prot));
}

variable_types:
prot
void *


original_code:
int sglinux_tfSCSICommand(struct tfCommand *cmd)
{
 sg_io_hdr_t io_hd;
 int res;
 int fd = (int)cmd->targetHandle;
 memset(&io_hd, 0, sizeof(sg_io_hdr_t));
 io_hd.interface_id = 'S';
 io_hd.cmd_len = getCommandLength(cmd->cdbBytes);
 io_hd.mx_sb_len = cmd->senseLen;
 io_hd.sbp = cmd->sense;
 io_hd.cmdp = cmd->cdbBytes;
 io_hd.timeout = 20000;
 io_hd.iovec_count = 0;
 io_hd.flags = 0;
 io_hd.usr_ptr = (void *)cmd;
 if (cmd->writeCount > 0) {
  io_hd.dxfer_direction = -2;
  io_hd.dxferp = cmd->imWriteBuffer->data;
  io_hd.dxfer_len = cmd->writeCount;
 } else if (cmd->residualReadCount > 0) {
  io_hd.dxfer_direction = -3;
  io_hd.dxferp = cmd->readBuffer->data;
  io_hd.dxfer_len = cmd->residualReadCount;
 } else {
  io_hd.dxfer_direction = -1;
  io_hd.dxferp = ((void *)0);
  io_hd.dxfer_len = 0;
 }
 if (cmd->cdbBytes[0] == 0xa0) {
  cmd->response = 0;
  cmd->status = 0;
  cmd->readedCount = cmd->residualReadCount;
  cmd->writedCount = 0;
  cmd->senseLen = 0;
  memset(cmd->readBuffer->data, 0, cmd->residualReadCount);
  cmd->readBuffer->data[3] = 8;
  cmd->readBuffer->data[9] = 0x00;
  return sesSCSICmdResponse(cmd);
 }
 res = write(fd, &io_hd, sizeof(sg_io_hdr_t));
 if (res != -1) {
  return sesSCSIQueue(cmd);
 } else {
  ;
  perror("");
  cmd->response = 1;
  cmd->readedCount = 0;
  cmd->writedCount = 0;
  cmd->senseLen = 0;
  return sesSCSICmdResponse(cmd);
 }
}

canonical_original_code:
int sglinux_tfSCSICommand(struct tfCommand *cmd)
{
 struct sg_io_hdr io_hd;
 int res;
 int fd = (int)cmd->targetHandle;
 memset(&io_hd, 0, sizeof(sg_io_hdr_t));
 io_hd.interface_id = 'S';
 io_hd.cmd_len = getCommandLength(cmd->cdbBytes);
 io_hd.mx_sb_len = cmd->senseLen;
 io_hd.sbp = cmd->sense;
 io_hd.cmdp = cmd->cdbBytes;
 io_hd.timeout = 20000;
 io_hd.iovec_count = 0;
 io_hd.flags = 0;
 io_hd.usr_ptr = (void *)cmd;
 if (cmd->writeCount > 0) {
  io_hd.dxfer_direction = -2;
  io_hd.dxferp = cmd->imWriteBuffer->data;
  io_hd.dxfer_len = cmd->writeCount;
 } else if (cmd->residualReadCount > 0) {
  io_hd.dxfer_direction = -3;
  io_hd.dxferp = cmd->readBuffer->data;
  io_hd.dxfer_len = cmd->residualReadCount;
 } else {
  io_hd.dxfer_direction = -1;
  io_hd.dxferp = ((void *)0);
  io_hd.dxfer_len = 0;
 }
 if (cmd->cdbBytes[0] == 0xa0) {
  cmd->response = 0;
  cmd->status = 0;
  cmd->readedCount = cmd->residualReadCount;
  cmd->writedCount = 0;
  cmd->senseLen = 0;
  memset(cmd->readBuffer->data, 0, cmd->residualReadCount);
  cmd->readBuffer->data[3] = 8;
  cmd->readBuffer->data[9] = 0x00;
  return sesSCSICmdResponse(cmd);
 }
 res = write(fd, &io_hd, sizeof(sg_io_hdr_t));
 if (res != -1) {
  return sesSCSIQueue(cmd);
 } else {
  ;
  perror("");
  cmd->response = 1;
  cmd->readedCount = 0;
  cmd->writedCount = 0;
  cmd->senseLen = 0;
  return sesSCSICmdResponse(cmd);
 }
}

user_defined_types: struct sg_io_hdr { int interface_id; int dxfer_direction; unsigned char cmd_len; unsigned char mx_sb_len; unsigned short iovec_count; unsigned int dxfer_len; void *dxferp; unsigned char *cmdp; unsigned char *sbp; unsigned int timeout; unsigned int flags; int pack_id; void *usr_ptr; unsigned char status; unsigned char masked_status; unsigned char msg_status; unsigned char sb_len_wr; unsigned short host_status; unsigned short driver_status; int resid; unsigned int duration; unsigned int info; }

user_defined_types: struct Buffer { struct DCirList list; struct BufferAllocator *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; }

user_defined_types: struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; }

user_defined_types: struct DCirList { struct DCirList *next; struct DCirList *prev; }

user_defined_types: struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; }

user_defined_types: struct Counter { unsigned int count; unsigned int mask; }

user_defined_types: struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; }

user_defined_types: struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux platformData; struct confElement *trgs; struct configuration cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; }

user_defined_types: struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; }

user_defined_types: struct _spec_world_linux { union pthread_mutex_t mutex; }

user_defined_types: struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T *r2tRes; struct ResponseTask *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand cmd; }

user_defined_types: struct confElemList { struct confElement *next; struct confElement *prev; }

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


decompiled_code:
__int64 __fastcall sglinux_tfSetPollingDes(__int64 a1)
{
setWaitigFd(a1, *(unsigned int *)(a1 + 48), 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
setWaitigFd(a1, *(unsigned int *)(a1 + 48), 0LL);
return 0LL;
}

original_code:
int sglinux_tfSetPollingDes(struct Session *ses)
{
 void *attachedHandle = ses->tfHandle;
 int fd = (int)attachedHandle;
 setWaitigFd(ses, fd, 0);
 return 0;
}

variable_types:
attachedHandle
void *

user_defined_types: struct Session { struct DCirList list; struct ISID_TSIH sessionID; struct InetConnection *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param *params; struct Counter cmdSN; struct Task *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass cclass; unsigned int pendingCommands; int maxfd; struct fd_set rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; }

user_defined_types: struct InetConnection { struct DCirList list; struct Session *member; struct World *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter recvStatSN; unsigned int statSN; struct ResponseTask *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param *params; }

user_defined_types: struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList *pdus; struct R2T r2t; struct Counter dataSN; struct Task *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; }

user_defined_types: struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; }

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

user_defined_types: struct confElement { struct confElemList list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; }

user_defined_types: struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); }

user_defined_types: struct PDUList { struct DCirList list; struct PDU pdu; }

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; }

user_defined_types: struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; }

user_defined_types: struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer *readBuffer; struct Buffer *imWriteBuffer; struct R2T *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session *ses; void *targetHandle; void *classHandle; }

user_defined_types: struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; }

user_defined_types: struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; }


decompiled_code:
__int64 __fastcall sglinux_tfCheckPollingDes(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 48);
result = isSetWaitigFd(a1, (unsigned int)v1, 0LL);
if ( (_DWORD)result )
result = sglinux_readSCSIStatus(v1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 48);
result = isSetWaitigFd(a1, (unsigned int)v1, 0LL);
if ( (_DWORD)result )
result = func1(v1);
return result;
}

original_code:
int sglinux_tfCheckPollingDes(struct Session *ses)
{
 void *attachedHandle = ses->tfHandle;
 int fd = (int)attachedHandle;
 if (isSetWaitigFd(ses, fd, 0)) {
  return sglinux_readSCSIStatus(fd);
 }
 return 0;
}

user_defined_types: struct DCirList { struct DCirList *next; struct DCirList *prev; }

user_defined_types: struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; }

user_defined_types: struct Counter { unsigned int count; unsigned int mask; }

user_defined_types: struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; }

user_defined_types: struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux platformData; struct confElement *trgs; struct configuration cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; }

user_defined_types: struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; }

user_defined_types: struct _spec_world_linux { union pthread_mutex_t mutex; }

user_defined_types: struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam ap; }

user_defined_types: struct PDU { struct { struct bhsBase bhs; union { unsigned int headerDigest; struct AHS ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer *dataSeg; }; unsigned char *data; }

user_defined_types: struct Buffer { struct DCirList list; struct BufferAllocator *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; }

user_defined_types: struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; }

user_defined_types: struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; }


parseAuthParam

decompiled_code:
__int64 __fastcall parseAuthParam(__int64 *a1, int a2, const char *a3)
{
__int64 v4; // rbp
char *v5; // rax
signed __int64 v6; // rdx

if ( a2 )
return 0LL;
v4 = *a1;
do
{
v5 = strchr(a3, 44);
if ( !v5 )
v5 = (char *)&a3[strlen(a3)];
v6 = v5 - a3;
if ( v5 - a3 == 4 )
{
if ( !memcmp("None", a3, 4uLL) )
{
*(_DWORD *)(v4 + 4) |= 1u;
}
else if ( !memcmp("CHAP", a3, 4uLL) )
{
*(_DWORD *)(v4 + 4) |= 2u;
}
else if ( !memcmp("KRB5", a3, 4uLL) )
{
*(_DWORD *)(v4 + 4) |= 0x20u;
}
}
else if ( v6 == 5 )
{
if ( !memcmp("SPKM1", a3, 5uLL) )
{
*(_DWORD *)(v4 + 4) |= 8u;
}
else if ( !memcmp("SPKM2", a3, 5uLL) )
{
*(_DWORD *)(v4 + 4) |= 0x10u;
}
}
else if ( v6 == 3 && !memcmp(&unk_E01, a3, 3uLL) )
{
*(_DWORD *)(v4 + 4) |= 4u;
}
a3 = v5 + 1;
}
while ( *v5 );
return 0LL;
}

original_code:
static int parseAuthParam(struct ParseParams *prms, int index, const char *value)
{
 struct AuthProc *auth = prms->ap;
 const char *ptr, *ptr1;
 ;
 switch (index) {
 case 0:
  {
   ptr = value;
   do {
    ptr1 = strchr(ptr, ',');
    if (ptr1 == ((void *)0)) {
     ptr1 = ptr + strlen(ptr);
    }
    switch (ptr1 - ptr) {
    case 3:
     if (strncmp("SRP", ptr, 3) == 0) {
      auth->availAuthTypes |= 0x04;
     }
     break;
    case 4:
     if (strncmp("None", ptr, 4) == 0) {
      auth->availAuthTypes |= 0x01; break;
     }
     if (strncmp("CHAP", ptr, 4) == 0) {
      auth->availAuthTypes |= 0x02; break;
     }
     if (strncmp("KRB5", ptr, 4) == 0) {
      auth->availAuthTypes |= 0x20;
     }
     break;
    case 5:
     if (strncmp("SPKM1", ptr, 5) == 0) {
      auth->availAuthTypes |= 0x08; break;
     }
     if (strncmp("SPKM2", ptr, 5) == 0) {
      auth->availAuthTypes |= 0x10;
     }
     break;
    }
    ptr = ptr1 + 1;
   } while (*ptr1 != 0);
  }
 }
 return 0;
}

canonical_original_code:
static int parseAuthParam(struct ParseParams *prms, int index, char *value)
{
 struct AuthProc *auth = prms->ap;
 char *ptr; char *ptr1;
 ;
 switch (index) {
 case 0:
  {
   ptr = value;
   do {
    ptr1 = strchr(ptr, ',');
    if (ptr1 == ((void *)0)) {
     ptr1 = ptr + strlen(ptr);
    }
    switch (ptr1 - ptr) {
    case 3:
     if (strncmp("SRP", ptr, 3) == 0) {
      auth->availAuthTypes |= 0x04;
     }
     break;
    case 4:
     if (strncmp("None", ptr, 4) == 0) {
      auth->availAuthTypes |= 0x01; break;
     }
     if (strncmp("CHAP", ptr, 4) == 0) {
      auth->availAuthTypes |= 0x02; break;
     }
     if (strncmp("KRB5", ptr, 4) == 0) {
      auth->availAuthTypes |= 0x20;
     }
     break;
    case 5:
     if (strncmp("SPKM1", ptr, 5) == 0) {
      auth->availAuthTypes |= 0x08; break;
     }
     if (strncmp("SPKM2", ptr, 5) == 0) {
      auth->availAuthTypes |= 0x10;
     }
     break;
    }
    ptr = ptr1 + 1;
   } while (*ptr1 != 0);
  }
 }
 return 0;
}

variable_types: struct ParseParams { struct AuthProc { int authType; int availAuthTypes; unsigned int CSG; unsigned int NSG; int transit; int firstPDU; unsigned int cmdSN; unsigned int statSN; unsigned int CID; unsigned int initiatorTaskTag; struct PDUList { struct DCirList { struct DCirList *next; struct DCirList *prev; } list; struct PDU { struct { struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 { unsigned char b[3]; } dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; } bhs; union { unsigned int headerDigest; struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; } ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer { struct DCirList list; struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; } ap; } *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; } *dataSeg; }; unsigned char *data; } pdu; } *pending; struct PDUList *wpending; unsigned int nFreePDUs; struct PDUList *freePDUs; struct PDUList freePDU[10]; } *ap; struct InetConnection { struct DCirList list; struct Session { struct DCirList list; struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; } sessionID; struct InetConnection *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; } *params; struct Counter { unsigned int count; unsigned int mask; } cmdSN; struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; } *r2tRes; struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList *pdus; struct R2T r2t; struct Counter dataSN; struct Task *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; } *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer *readBuffer; struct Buffer *imWriteBuffer; struct R2T *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session *ses; void *targetHandle; void *classHandle; } cmd; } *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; } *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); } cclass; unsigned int pendingCommands; int maxfd; struct fd_set { long __fds_bits[-1]; } rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; } *member; struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux { 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; } mutex; } platformData; struct confElement { struct confElemList { struct confElement *next; struct confElement *prev; } list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; } *trgs; struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; } cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; } *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter recvStatSN; unsigned int statSN; struct ResponseTask *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; } readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param *params; } *ic; struct Param *param; struct Buffer *inBuff; struct Buffer *outBuff; } *

variable_types: index int

variable_types:
value
char *

variable_types:
ptr
char *

user_defined_types: struct ParseParams { struct AuthProc *ap; struct InetConnection *ic; struct Param *param; struct Buffer *inBuff; struct Buffer *outBuff; }

user_defined_types: struct AuthProc { int authType; int availAuthTypes; unsigned int CSG; unsigned int NSG; int transit; int firstPDU; unsigned int cmdSN; unsigned int statSN; unsigned int CID; unsigned int initiatorTaskTag; struct PDUList *pending; struct PDUList *wpending; unsigned int nFreePDUs; struct PDUList *freePDUs; struct PDUList freePDU[10]; }

user_defined_types: struct InetConnection { struct DCirList list; struct Session *member; struct World *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter recvStatSN; unsigned int statSN; struct ResponseTask *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param *params; }

user_defined_types: struct PDUList { struct DCirList list; struct PDU pdu; }

user_defined_types: struct Session { struct DCirList list; struct ISID_TSIH sessionID; struct InetConnection *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param *params; struct Counter cmdSN; struct Task *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass cclass; unsigned int pendingCommands; int maxfd; struct fd_set rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; }

user_defined_types: struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); }

user_defined_types: struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T *r2tRes; struct ResponseTask *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand cmd; }

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

user_defined_types: struct confElement { struct confElemList list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; }

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; }


paramcmp

decompiled_code:
int __fastcall paramcmp(char *s1, char *s2)
{
size_t v2; // rbp
int result; // eax

v2 = strlen(s1);
result = strncmp(s1, s2, v2);
if ( result )
return 0;
if ( s2[v2] == 61 )
result = v2 + 1;
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1, char *s2)
{
size_t v2; // rbp
int result; // eax

v2 = strlen(s1);
result = strncmp(s1, s2, v2);
if ( result )
return 0;
if ( s2[v2] == 61 )
result = v2 + 1;
return result;
}

original_code:
int paramcmp(const char *value, const char *x) {
 size_t len = strlen(value);
 if ((strncmp(value, x, len)==0) && ( *(x + len) == '=' ))
  return (int)(len + 1);
 return 0;
}

canonical_original_code:
int paramcmp(char *value, char *x) {
 unsigned long len = strlen(value);
 if ((strncmp(value, x, len)==0) && ( *(x + len) == '=' ))
  return (int)(len + 1);
 return 0;
}

variable_types:
x
char *

variable_types:
len
unsigned long


addParam

decompiled_code:
int __fastcall addParam(__int64 a1, const char *a2, const char *a3)
{
int result; // eax
unsigned int v4; // esi

result = snprintf(
(char *)(a1 + *(unsigned int *)(a1 + 28) + 80),
(unsigned int)(*(_DWORD *)(a1 + 24) - *(_DWORD *)(a1 + 28)),
"%s=%s",
a2,
a3);
if ( result > 0 )
{
v4 = *(_DWORD *)(a1 + 28) + result;
*(_DWORD *)(a1 + 28) = v4;
if ( *(_DWORD *)(a1 + 24) - v4 <= 1 )
{
result = -1;
}
else
{
*(_BYTE *)(a1 + v4 + 80) = 0;
++*(_DWORD *)(a1 + 28);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2, const char *a3)
{
int result; // eax
unsigned int v4; // esi

result = snprintf(
(char *)(a1 + *(unsigned int *)(a1 + 28) + 80),
(unsigned int)(*(_DWORD *)(a1 + 24) - *(_DWORD *)(a1 + 28)),
"%s=%s",
a2,
a3);
if ( result > 0 )
{
v4 = *(_DWORD *)(a1 + 28) + result;
*(_DWORD *)(a1 + 28) = v4;
if ( *(_DWORD *)(a1 + 24) - v4 <= 1 )
{
result = -1;
}
else
{
*(_BYTE *)(a1 + v4 + 80) = 0;
++*(_DWORD *)(a1 + 28);
}
}
return result;
}

original_code:
int addParam(struct Buffer *buff, const char *param_name, const char *paran_value)
{
 int res = snprintf(buff->data + buff->length, buff->maxLength - buff->length,
  "%s=%s", param_name, paran_value);
 if (res > 0) {
  buff->length += res;
  if (buff->maxLength - buff->length > 1) {
   *(buff->data + buff->length) = 0;
   buff->length++;
  } else {
   return -1;
  }
 }
 return res;
}

canonical_original_code:
int addParam(struct Buffer *buff, char *param_name, char *paran_value)
{
 int res = snprintf(buff->data + buff->length, buff->maxLength - buff->length,
  "%s=%s", param_name, paran_value);
 if (res > 0) {
  buff->length += res;
  if (buff->maxLength - buff->length > 1) {
   *(buff->data + buff->length) = 0;
   buff->length++;
  } else {
   return -1;
  }
 }
 return res;
}

variable_types: struct Buffer { struct DCirList { struct DCirList *next; struct DCirList *prev; } list; struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; } ap; } *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; } *


sendTargets

original_code:
static int sendTargets(struct ParseParams *prms, const char *value)
{
 int tmp;
 struct World *wrld = prms->ic->world;
 struct confElement *elem, *el;
 lockWorld(wrld);
 el = wrld->trgs;
 tmp = strcmp(value, "All");
 if (tmp == 0) {
  elem = el;
  do {
   addParam(prms->outBuff, "TargetName", elem->name);
   elem = elem->list.next;
  } while (elem != el);
 } else {
  ;
 }
 releaseWorld(wrld);
 return 0;
}

canonical_original_code:
static int sendTargets(struct ParseParams *prms, char *value)
{
 int tmp;
 struct World *wrld = prms->ic->world;
 struct confElement *elem; struct confElement *el;
 lockWorld(wrld);
 el = wrld->trgs;
 tmp = strcmp(value, "All");
 if (tmp == 0) {
  elem = el;
  do {
   addParam(prms->outBuff, "TargetName", elem->name);
   elem = elem->list.next;
  } while (elem != el);
 } else {
  ;
 }
 releaseWorld(wrld);
 return 0;
}

variable_types: tmp int

variable_types: struct World { struct Session { struct DCirList { struct DCirList *next; struct DCirList *prev; } list; struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; } sessionID; struct InetConnection { struct DCirList list; struct Session *member; struct World *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter { unsigned int count; unsigned int mask; } recvStatSN; unsigned int statSN; struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList { struct DCirList list; struct PDU { struct { struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 { unsigned char b[3]; } dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; } bhs; union { unsigned int headerDigest; struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; } ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer { struct DCirList list; struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; } ap; } *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; } *dataSeg; }; unsigned char *data; } pdu; } *pdus; struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; } r2t; struct Counter dataSN; struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T *r2tRes; struct ResponseTask *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer *readBuffer; struct Buffer *imWriteBuffer; struct R2T *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session *ses; void *targetHandle; void *classHandle; } cmd; } *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; } *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; } readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; } *params; } *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param *params; struct Counter cmdSN; struct Task *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; } *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); } cclass; unsigned int pendingCommands; int maxfd; struct fd_set { long __fds_bits[-1]; } rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; } *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux { 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; } mutex; } platformData; struct confElement { struct confElemList { struct confElement *next; struct confElement *prev; } list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; } *trgs; struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; } cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; } *

user_defined_types: struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux platformData; struct confElement *trgs; struct configuration cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; }

user_defined_types: struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList *pdus; struct R2T r2t; struct Counter dataSN; struct Task *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; }


parseConnParam

original_code:
static int parseConnParam(struct ParseParams *prms, int index, const char *value)
{
 struct InetConnection *conn = prms->ic;
 int headerMask = 0, useCRC, tmp;
 const char *ptr, *ptr1;
 switch (index) {
 case 0:
 case 1:
  if (prms->ap->CSG > 1) {
   ;
   return 0;
  }
  ptr = value;
  do {
   ptr1 = strchr(ptr, ',');
   if (ptr1 == ((void *)0)) {
    ptr1 = ptr + strlen(ptr);
   }
   switch (ptr1 - ptr) {
   case 4:
    if (strncmp("None", ptr, 4) == 0) {
     headerMask |= 0x10;
    }
    break;
   case 6:
    if (strncmp("CRC32C", ptr, 6) == 0) {
     headerMask |= 0x20;
    }
   }
   ptr = ptr1 + 1;
  } while (*ptr1 != 0);
  if (index == 0) {
   if ((headerMask & 0x30) == (0x10 | 0x20)) {
    useCRC = ! 1;
   } else if ((headerMask & 0x20) == 0x20) {
    useCRC = 1;
   } else {
    useCRC = 0;
   }
  } else {
   if ((headerMask & 0x30) == (0x10 | 0x20)) {
    useCRC = ! 1;
   } else if ((headerMask & 0x20) == 0x20) {
    useCRC = 1;
   } else {
    useCRC = 0;
   }
  }
  if (index == 0) {
   if (useCRC) {
    addParam(prms->outBuff, "HeaderDigest", "CRC32C");
    conn->headerDigest = 0x01;
   } else {
    addParam(prms->outBuff, "HeaderDigest", "None");
    conn->headerDigest = 0x00;
   }
  } else {
   if (useCRC) {
    addParam(prms->outBuff, "DataDigest", "CRC32C");
    conn->dataDigest = 0x01;
   } else {
    addParam(prms->outBuff, "DataDigest", "None");
    conn->dataDigest = 0x00;
   }
  }
  return 0;
 case 2:
  tmp = atoi(value);
  if ((tmp < 512) || (tmp > ((2<<24) - 1))) {
   ;
   return 0;
  }
  conn->initiatorMaxRcvDataSegment = tmp;
  return 0;
 default:
  ;
 }
 return 0;
}

canonical_original_code:
static int parseConnParam(struct ParseParams *prms, int index, char *value)
{
 struct InetConnection *conn = prms->ic;
 int headerMask = 0; int useCRC; int tmp;
 char *ptr; char *ptr1;
 switch (index) {
 case 0:
 case 1:
  if (prms->ap->CSG > 1) {
   ;
   return 0;
  }
  ptr = value;
  do {
   ptr1 = strchr(ptr, ',');
   if (ptr1 == ((void *)0)) {
    ptr1 = ptr + strlen(ptr);
   }
   switch (ptr1 - ptr) {
   case 4:
    if (strncmp("None", ptr, 4) == 0) {
     headerMask |= 0x10;
    }
    break;
   case 6:
    if (strncmp("CRC32C", ptr, 6) == 0) {
     headerMask |= 0x20;
    }
   }
   ptr = ptr1 + 1;
  } while (*ptr1 != 0);
  if (index == 0) {
   if ((headerMask & 0x30) == (0x10 | 0x20)) {
    useCRC = ! 1;
   } else if ((headerMask & 0x20) == 0x20) {
    useCRC = 1;
   } else {
    useCRC = 0;
   }
  } else {
   if ((headerMask & 0x30) == (0x10 | 0x20)) {
    useCRC = ! 1;
   } else if ((headerMask & 0x20) == 0x20) {
    useCRC = 1;
   } else {
    useCRC = 0;
   }
  }
  if (index == 0) {
   if (useCRC) {
    addParam(prms->outBuff, "HeaderDigest", "CRC32C");
    conn->headerDigest = 0x01;
   } else {
    addParam(prms->outBuff, "HeaderDigest", "None");
    conn->headerDigest = 0x00;
   }
  } else {
   if (useCRC) {
    addParam(prms->outBuff, "DataDigest", "CRC32C");
    conn->dataDigest = 0x01;
   } else {
    addParam(prms->outBuff, "DataDigest", "None");
    conn->dataDigest = 0x00;
   }
  }
  return 0;
 case 2:
  tmp = atoi(value);
  if ((tmp < 512) || (tmp > ((2<<24) - 1))) {
   ;
   return 0;
  }
  conn->initiatorMaxRcvDataSegment = tmp;
  return 0;
 default:
  ;
 }
 return 0;
}

variable_types: struct InetConnection { struct DCirList { struct DCirList *next; struct DCirList *prev; } list; struct Session { struct DCirList list; struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; } sessionID; struct InetConnection *connections; int nConnections; unsigned int errorRecoveryLevel; unsigned int intialR2T; unsigned int immediateData; void *tfHandle; struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; } *params; struct Counter { unsigned int count; unsigned int mask; } cmdSN; struct Task { struct DCirList list; unsigned int cmdSN; unsigned int initiatorTaskTag; unsigned long lun; unsigned int nPDU; struct PDUList { struct DCirList list; struct PDU { struct { struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 { unsigned char b[3]; } dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; } bhs; union { unsigned int headerDigest; struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; } ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer { struct DCirList list; struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; } ap; } *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; } *dataSeg; }; unsigned char *data; } pdu; } *pdus; struct Buffer *dataSegment; struct Counter unsolDataSN; unsigned int dataSNr2tSN; struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; } *r2tRes; struct ResponseTask { struct DCirList list; unsigned int statSN; unsigned int targetTransferTag; unsigned int refITT; unsigned long lun; unsigned int iFlags; struct PDUList *pdus; struct R2T r2t; struct Counter dataSN; struct Task *origTask; struct ResponseTask *ackTasks; struct Buffer *dataSegment; } *intialRes; unsigned int immediate; unsigned int nR2t; struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer *readBuffer; struct Buffer *imWriteBuffer; struct R2T *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session *ses; void *targetHandle; void *classHandle; } cmd; } *notAllRecived; struct Task *tasks; struct Task *immediateTasks; struct Task *freeTasks; struct Task *perfTasks; struct Task *perfImTasks; struct PDUList *freePDUs; struct ResponseTask *freeResTasks; struct ResponseTask *resTasks; struct ResponseTask *sended; unsigned int minMaxRcvDataSegment; unsigned int nFreeTasks; unsigned int nFreeResTasks; unsigned int nFreePDUs; struct BufferAllocator buffAlloc[16]; struct Task taskPool[64]; struct ResponseTask resp[64]; struct PDUList pdus[128]; unsigned int targetTaskTag; unsigned int unAckSize; struct tfClass { char *className; void *handle; void *(*tfInit)(); void (*tfCleanup)(void *handle); void *(*tfAttach)(void *handle, struct Session *ses); void (*tfDetach)(void *handle, void *attachedHandle); int (*tfSCSICommand)(struct tfCommand *cmd); int (*tfSCSIManagement)(struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; } *tfmc); char *(*tfGetModuleInfo)(int what); unsigned int flags; int (*tfSetPollingDes)(struct Session *ses); int (*tfCheckPollingDes)(struct Session *ses); } cclass; unsigned int pendingCommands; int maxfd; struct fd_set { long __fds_bits[-1]; } rop; struct fd_set wop; int connChanged; long bytes_read; long bytes_write; long pdus_sent; long pdus_recv; } *member; struct World { struct Session *sesions; unsigned int nSessions; unsigned int nTotalConnections; struct _spec_world_linux { 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; } mutex; } platformData; struct confElement { struct confElemList { struct confElement *next; struct confElement *prev; } list; struct confElement *parent; struct confElement *childs; int cbName; int cbValue; char name[110]; char value[120]; } *trgs; struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; } cnf; struct BufferAllocator buffAlloc[2]; int nApis; struct tfClass apis[4]; } *world; unsigned int connectionID; unsigned int currentITT; int scli; int currentStage; struct Counter recvStatSN; unsigned int statSN; struct ResponseTask *sending; struct PDUList *sendedPDUs; struct PDUList *pending; struct PDUList *wpending; struct Task *pndTask; unsigned int targetMaxRcvDataSegment; int headerDigest; int dataDigest; unsigned int initiatorMaxRcvDataSegment; unsigned int headerSize; struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; } readOP; struct ReadWriteOP writeOP; int sockNeedToWrite; struct Param *params; } *

variable_types: headerMask int

variable_types: useCRC int

user_defined_types: struct _spec_world_linux { union pthread_mutex_t mutex; }

user_defined_types: struct BufferAllocator { struct DCirList list; struct Buffer *buffFree; struct Buffer *buffUsed; unsigned int useds; unsigned int frees; struct BufferAllocator *parnetAllocator; int (*parentLock)(struct BufferAllocator *parentAlloc); int (*parentFree)(struct BufferAllocator *parentAlloc); struct AllocParam ap; }


addParamNum

decompiled_code:
int __fastcall addParamNum(__int64 a1, const char *a2, unsigned int a3)
{
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

snprintf(v4, 0x10uLL, "%d", a3);
return addParam(a1, a2, v4);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, const char *a2, unsigned int a3)
{
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

snprintf(v4, 0x10uLL, "%d", a3);
return func3(a1, a2, v4);
}

original_code:
int addParamNum(struct Buffer *buff, const char *param_name, uint32_t value)
{
 char buffer[16];
 snprintf(buffer, 16, "%d", value);
 return addParam(buff, param_name, buffer);
}

canonical_original_code:
int addParamNum(struct Buffer *buff, char *param_name, unsigned int value)
{
 char buffer[16];
 snprintf(buffer, 16, "%d", value);
 return addParam(buff, param_name, buffer);
}

variable_types:
value
unsigned int

variable_types:
buffer
char [16]

user_defined_types: struct Buffer { struct DCirList list; struct BufferAllocator *belong; unsigned int maxLength; unsigned int length; unsigned char _data[-1]; unsigned char data[1]; }

user_defined_types: struct DCirList { struct DCirList *next; struct DCirList *prev; }

user_defined_types: struct AllocParam { unsigned int maxLength; unsigned char nIncrease; unsigned char nDecrease; unsigned char nIntialCount; unsigned char policy; }


parseSessParam

original_code:
static int parseSessParam(struct ParseParams *prms, int index, const char *value)
{
 size_t len;
 int tmp;
 const char *ptr;
 void *pptr;
 switch (index) {
 case 0:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 1) || (tmp > 65535)) {
   ;
   return 0;
  }
  prms->param[index].ivalue = tmp;
  return 0;
 case 1:
  {
   return sendTargets(prms, value);
  }
 case 2:
  {
   if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1) || (prms->ap->firstPDU == 0)) {
    ;
    return 0;
   }
   if (prms->param[2].tvalue != ((void *)0)) {
    ;
    return 0;
   }
   if (checkTargetName(prms, value, &ptr, &pptr) == 0) {
    prms->param[2].tvalue = (char*)ptr;
    prms->param[2].pvalue = pptr;
    return 0;
   }
   return -1;
  }
 case 5:
 case 3:
  {
   if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1) || (prms->ap->firstPDU == 0)) {
    ;
    return 0;
   }
   if (prms->param[index].tvalue != ((void *)0)) {
    ;
    return 0;
   }
   len = strlen(value);
   prms->param[index].tvalue = (char*)malloc(len + 1);
   strncpy(prms->param[index].tvalue, value, len);
   *(prms->param[index].tvalue + len) = 0;
   return 0;
  }
 case 10:
 case 11:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 512) || (tmp > ((2<<24) - 1))) {
   ;
   return 0;
  }
  if (index == 10) {
   if (tmp > (128*1024)) {
    tmp = (128*1024);
   }
  } else {
   if (tmp > (128*1024)) {
    tmp = (128*1024);
   }
  }
  prms->param[index].ivalue = tmp;
  return 0;
 case 12:
 case 13:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 0) || (tmp > 3600)) {
   ;
   return 0;
  }
  prms->param[index].ivalue = tmp;
  addParam(prms->outBuff, SessParamNames[index], value);
  return 0;
 case 14:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 1) || (tmp > 65535)) {
   ;
   return 0;
  }
  prms->param[index].ivalue = tmp;
  addParam(prms->outBuff, SessParamNames[index], value);
  return 0;
 case 8:
 case 9:
 case 15:
 case 16:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = strcmp(value, "No");
  if (tmp != 0) {
   tmp = strcmp(value, "Yes");
   if (tmp != 0) {
    ;
    return 0;
   }
   tmp = 1;
  }
  prms->param[index].tvalue = (tmp) ? "Yes" : "No";
  prms->param[index].avalue = tmp;
  if ((index == 9) && (tmp == 1)) {
   addParam(prms->outBuff, "ImmediateData", "Yes");
  }
  if ((index == 8) && (tmp == 0)) {
   addParam(prms->outBuff, "InitialR2T", "No");
  }
  return 0;
 case 17:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 0) || (tmp > 2)) {
   ;
   return 0;
  }
  if (tmp > 0) {
   addParamNum(prms->outBuff, "ErrorRecoveryLevel", 0);
  }
  return 0;
 case 18:
  {
   if ((prms->ap == ((void *)0)) || (prms->ap->firstPDU != 1)) {
    ;
    return 0;
   }
   tmp = strcmp("Discovery", value);
   if (tmp != 0) {
    tmp = strcmp("Normal", value);
    if (tmp != 0) {
     ;
    }
    return 0;
   }
   prms->param[18].tvalue = "Discovery";
   prms->param[18].avalue = 1;
   return 0;
  }
 default:
  ;
 }
 return 0;
}

canonical_original_code:
static int parseSessParam(struct ParseParams *prms, int index, char *value)
{
 unsigned long len;
 int tmp;
 char *ptr;
 void *pptr;
 switch (index) {
 case 0:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 1) || (tmp > 65535)) {
   ;
   return 0;
  }
  prms->param[index].ivalue = tmp;
  return 0;
 case 1:
  {
   return sendTargets(prms, value);
  }
 case 2:
  {
   if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1) || (prms->ap->firstPDU == 0)) {
    ;
    return 0;
   }
   if (prms->param[2].tvalue != ((void *)0)) {
    ;
    return 0;
   }
   if (checkTargetName(prms, value, &ptr, &pptr) == 0) {
    prms->param[2].tvalue = (char *)ptr;
    prms->param[2].pvalue = pptr;
    return 0;
   }
   return -1;
  }
 case 5:
 case 3:
  {
   if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1) || (prms->ap->firstPDU == 0)) {
    ;
    return 0;
   }
   if (prms->param[index].tvalue != ((void *)0)) {
    ;
    return 0;
   }
   len = strlen(value);
   prms->param[index].tvalue = (char *)malloc(len + 1);
   strncpy(prms->param[index].tvalue, value, len);
   *(prms->param[index].tvalue + len) = 0;
   return 0;
  }
 case 10:
 case 11:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 512) || (tmp > ((2<<24) - 1))) {
   ;
   return 0;
  }
  if (index == 10) {
   if (tmp > (128*1024)) {
    tmp = (128*1024);
   }
  } else {
   if (tmp > (128*1024)) {
    tmp = (128*1024);
   }
  }
  prms->param[index].ivalue = tmp;
  return 0;
 case 12:
 case 13:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 0) || (tmp > 3600)) {
   ;
   return 0;
  }
  prms->param[index].ivalue = tmp;
  addParam(prms->outBuff, SessParamNames[index], value);
  return 0;
 case 14:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 1) || (tmp > 65535)) {
   ;
   return 0;
  }
  prms->param[index].ivalue = tmp;
  addParam(prms->outBuff, SessParamNames[index], value);
  return 0;
 case 8:
 case 9:
 case 15:
 case 16:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = strcmp(value, "No");
  if (tmp != 0) {
   tmp = strcmp(value, "Yes");
   if (tmp != 0) {
    ;
    return 0;
   }
   tmp = 1;
  }
  prms->param[index].tvalue = (tmp) ? "Yes" : "No";
  prms->param[index].avalue = tmp;
  if ((index == 9) && (tmp == 1)) {
   addParam(prms->outBuff, "ImmediateData", "Yes");
  }
  if ((index == 8) && (tmp == 0)) {
   addParam(prms->outBuff, "InitialR2T", "No");
  }
  return 0;
 case 17:
  if ((prms->ap == ((void *)0)) || (prms->ap->CSG > 1)) {
   ;
   return 0;
  }
  tmp = atoi(value);
  if ((tmp < 0) || (tmp > 2)) {
   ;
   return 0;
  }
  if (tmp > 0) {
   addParamNum(prms->outBuff, "ErrorRecoveryLevel", 0);
  }
  return 0;
 case 18:
  {
   if ((prms->ap == ((void *)0)) || (prms->ap->firstPDU != 1)) {
    ;
    return 0;
   }
   tmp = strcmp("Discovery", value);
   if (tmp != 0) {
    tmp = strcmp("Normal", value);
    if (tmp != 0) {
     ;
    }
    return 0;
   }
   prms->param[18].tvalue = "Discovery";
   prms->param[18].avalue = 1;
   return 0;
  }
 default:
  ;
 }
 return 0;
}

variable_types:
pptr
void *

user_defined_types: struct ParseParams { struct AuthProc *ap; struct InetConnection *ic; struct Param *param; struct Buffer *inBuff; struct Buffer *outBuff; }

user_defined_types: struct ReadWriteOP { int stage; unsigned int expectedLen; unsigned int perfomedLen; unsigned char *buffer; unsigned int dataCRC; }

user_defined_types: struct PDU { struct { struct bhsBase bhs; union { unsigned int headerDigest; struct AHS ahs; }; unsigned int headerDigestWAHS; struct AHS *next; }; unsigned int dataSegmentLength; union { unsigned int *dataDigest; struct Buffer *dataSeg; }; unsigned char *data; }

user_defined_types: struct ISID_TSIH { unsigned int C; unsigned int B; unsigned int TA; unsigned short tsih; unsigned short D; }

user_defined_types: struct Counter { unsigned int count; unsigned int mask; }

user_defined_types: struct configuration { struct confElement *head; struct confElement *free; struct confElement pool[128]; }

user_defined_types: struct Param { union { int ivalue; char *tvalue; }; union { int avalue; void *pvalue; }; }

user_defined_types: struct bhsBase { unsigned char cmd; unsigned char flags; unsigned char res[2]; unsigned char totalAHSLength; struct uint24 dataSegmentLength; unsigned int lun[2]; unsigned int initiatorTaskTag; unsigned int reserved[7]; }

user_defined_types: struct tfCommand { int cmd; int stage; unsigned long lun; unsigned char *cdbBytes; unsigned int cdbLen; unsigned int residualReadCount; unsigned int writeCount; unsigned int readedCount; unsigned int writedCount; struct Buffer *readBuffer; struct Buffer *imWriteBuffer; struct R2T *writeBuffs; unsigned char response; unsigned char status; unsigned char readUnOv; unsigned char writeUnOv; unsigned char extra[256]; unsigned short senseLen; unsigned char sense[64]; struct Session *ses; void *targetHandle; void *classHandle; }

user_defined_types: struct confElemList { struct confElement *next; struct confElement *prev; }

user_defined_types: struct AHS { unsigned char AHSSpecific; unsigned char AHSType; unsigned short AHSLength; unsigned int ahsData[1]; }

user_defined_types: struct R2T { struct DCirList list; unsigned int r2tSN; struct Buffer *wBuffer; }

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

user_defined_types: struct tfManagement { void *handle; void *attachedHandle; int manFunction; struct tfCommand *ref_cmd; unsigned long lun; struct Session *ses; }