SQLGetStmtAttr

decompiled_code:
__int64 __fastcall SQLGetStmtAttr(__int64 a1, __int64 a2, _QWORD *a3, __int64 a4, const void *a5)
{
__int64 v10; // rax
int v11; // edx
_QWORD *v12; // rcx
bool v13; // si
bool v14; // dl
const char *v16; // rax
__int64 v17; // rcx
__int16 v18; // bp
bool v19; // cl
bool v20; // di
_QWORD *v21; // rcx
__int64 (__fastcall *v22)(_QWORD, __int64, _QWORD *, __int64, const void *); // r9
__int64 v23; // r10
__int64 (__fastcall *v24)(_QWORD, __int64, _QWORD *, __int64, const void *); // r9
__int64 (__fastcall *v25)(_QWORD, __int64, _QWORD *); // rcx
const char *v26; // rax
_BYTE v27[296]; // [rsp+0h] [rbp-128h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLGetStmtAttr.c", 198LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
v16 = (const char *)_stmt_attr_as_string(v27, a2);
sprintf(
(char *)(a1 + 16),
"\n"
"\t\tEntry:\n"
"\t\t\tStatement = %p\n"
"\t\t\tAttribute = %s\n"
"\t\t\tValue = %p\n"
"\t\t\tBuffer Length = %d\n"
"\t\t\tStrLen = %p",
(const void *)a1,
v16,
a3,
(unsigned int)a4,
a5);
dm_log_write("SQLGetStmtAttr.c", 223LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( a2 == 14 && (unsigned int)(*(_DWORD *)(a1 + 1040) - 1) <= 3 )
{
dm_log_write("SQLGetStmtAttr.c", 243LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 8) <= 4 )
{
dm_log_write("SQLGetStmtAttr.c", 263LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v10 = *(_QWORD *)(a1 + 1048);
v11 = *(_DWORD *)(v10 + 1456);
if ( v11 )
{
v12 = *(_QWORD **)(v10 + 1320);
if ( !v12[373] && !v12[381] && !v12[372] && !v12[380] )
{
dm_log_write("SQLGetStmtAttr.c", 287LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
}
else
{
v17 = *(_QWORD *)(v10 + 1320);
if ( !*(_QWORD *)(v17 + 2976) && !*(_QWORD *)(v17 + 3040) )
{
dm_log_write("SQLGetStmtAttr.c", 305LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
}
switch ( a2 )
{
case 10010LL:
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1544);
goto LABEL_30;
case 10011LL:
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1528);
goto LABEL_30;
case 10012LL:
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1536);
goto LABEL_30;
case 10013LL:
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1520);
goto LABEL_30;
case 16LL:
if ( *(_DWORD *)(v10 + 1484) == 2 && *(_QWORD *)(*(_QWORD *)(v10 + 1320) + 1824LL) )
{
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1584);
goto LABEL_30;
}
LABEL_40:
v19 = a2 == 27;
v13 = v11 != 0;
goto LABEL_41;
case 25LL:
if ( *(_DWORD *)(v10 + 1484) == 2 && *(_QWORD *)(*(_QWORD *)(v10 + 1320) + 1824LL) )
{
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1600);
goto LABEL_30;
}
goto LABEL_40;
}
if ( a2 != 26 )
{
v19 = a2 == 27;
v13 = v11 != 0 && a2 == 27;
if ( v11 != 0 && a2 == 27 )
{
v20 = 0;
if ( *(_DWORD *)(v10 + 1484) != 2 )
{
LABEL_58:
v14 = v20;
goto LABEL_43;
}
v23 = *(_QWORD *)(v10 + 1320);
v24 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *, __int64, const void *))(v23 + 2984);
if ( !v24 )
{
v18 = (*(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *, __int64, const void *))(v23 + 2976))(
*(_QWORD *)(a1 + 1056),
9LL,
a3,
a4,
a5);
goto LABEL_30;
}
LABEL_60:
v18 = v24(*(_QWORD *)(a1 + 1056), 9LL, a3, a4, a5);
goto LABEL_30;
}
v13 = v11 != 0;
LABEL_41:
v14 = v11 == 0;
v20 = v19 && v14;
if ( v19 && v14 )
{
if ( *(_DWORD *)(v10 + 1484) != 2 )
goto LABEL_58;
v24 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *, __int64, const void *))(*(_QWORD *)(v10 + 1320) + 2976LL);
if ( v24 )
goto LABEL_60;
}
else if ( !v19 || *(_DWORD *)(v10 + 1484) != 2 )
{
goto LABEL_43;
}
v18 = (*(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *))(*(_QWORD *)(v10 + 1320) + 3040LL))(
*(_QWORD *)(a1 + 1056),
9LL,
a3);
goto LABEL_30;
}
if ( *(_DWORD *)(v10 + 1484) == 2 && *(_QWORD *)(*(_QWORD *)(v10 + 1320) + 1824LL) )
{
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1592);
goto LABEL_30;
}
v13 = v11 != 0;
v14 = v11 == 0;
LABEL_43:
if ( v13 )
{
v21 = *(_QWORD **)(v10 + 1320);
v22 = (__int64 (__fastcall *)(_QWORD, __int64, _QWORD *, __int64, const void *))v21[373];
if ( !v22 )
{
v22 = (__int64 (__fastcall *)(_QWORD, __int64, _QWORD *, __int64, const void *))v21[372];
if ( !v22 )
{
if ( !v14 )
{
v25 = (__int64 (__fastcall *)(_QWORD, __int64, _QWORD *))v21[381];
if ( v25 )
{
if ( a2 <= 19999 && (unsigned __int64)a2 > 0xE )
{
dm_log_write("SQLGetStmtAttr.c", 480LL, 0LL, 0LL, "Error: HY092");
_post_internal_error(
a1 + 1088,
30LL,
0LL,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v18 = v25(*(_QWORD *)(a1 + 1056), a2, a3);
goto LABEL_30;
}
}
goto LABEL_75;
}
}
LABEL_73:
v18 = v22(*(_QWORD *)(a1 + 1056), a2, a3, a4, a5);
goto LABEL_30;
}
v22 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *, __int64, const void *))(*(_QWORD *)(v10 + 1320) + 2976LL);
if ( v22 )
goto LABEL_73;
LABEL_75:
if ( a2 <= 19999 && (unsigned __int64)a2 > 0xE )
{
dm_log_write("SQLGetStmtAttr.c", 507LL, 0LL, 0LL, "Error: HY092");
_post_internal_error(a1 + 1088, 30LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v18 = (*(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *))(*(_QWORD *)(v10 + 1320) + 3040LL))(
*(_QWORD *)(a1 + 1056),
a2,
a3);
LABEL_30:
if ( log_info[4] )
{
v26 = (const char *)_get_return_status((unsigned int)v18, v27);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v26);
dm_log_write("SQLGetStmtAttr.c", 532LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v18, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _QWORD *a3, __int64 a4, const void *a5)
{
__int64 v10; // rax
int v11; // edx
_QWORD *v12; // rcx
bool v13; // si
bool v14; // dl
const char *v16; // rax
__int64 v17; // rcx
__int16 v18; // bp
bool v19; // cl
bool v20; // di
_QWORD *v21; // rcx
__int64 (__fastcall *v22)(_QWORD, __int64, _QWORD *, __int64, const void *); // r9
__int64 v23; // r10
__int64 (__fastcall *v24)(_QWORD, __int64, _QWORD *, __int64, const void *); // r9
__int64 (__fastcall *v25)(_QWORD, __int64, _QWORD *); // rcx
const char *v26; // rax
_BYTE v27[296]; // [rsp+0h] [rbp-128h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLGetStmtAttr.c", 198LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
v16 = (const char *)_stmt_attr_as_string(v27, a2);
sprintf(
(char *)(a1 + 16),
"\n"
"\t\tEntry:\n"
"\t\t\tStatement = %p\n"
"\t\t\tAttribute = %s\n"
"\t\t\tValue = %p\n"
"\t\t\tBuffer Length = %d\n"
"\t\t\tStrLen = %p",
(const void *)a1,
v16,
a3,
(unsigned int)a4,
a5);
dm_log_write("SQLGetStmtAttr.c", 223LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( a2 == 14 && (unsigned int)(*(_DWORD *)(a1 + 1040) - 1) <= 3 )
{
dm_log_write("SQLGetStmtAttr.c", 243LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 8) <= 4 )
{
dm_log_write("SQLGetStmtAttr.c", 263LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v10 = *(_QWORD *)(a1 + 1048);
v11 = *(_DWORD *)(v10 + 1456);
if ( v11 )
{
v12 = *(_QWORD **)(v10 + 1320);
if ( !v12[373] && !v12[381] && !v12[372] && !v12[380] )
{
dm_log_write("SQLGetStmtAttr.c", 287LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
}
else
{
v17 = *(_QWORD *)(v10 + 1320);
if ( !*(_QWORD *)(v17 + 2976) && !*(_QWORD *)(v17 + 3040) )
{
dm_log_write("SQLGetStmtAttr.c", 305LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
}
switch ( a2 )
{
case 10010LL:
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1544);
goto LABEL_30;
case 10011LL:
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1528);
goto LABEL_30;
case 10012LL:
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1536);
goto LABEL_30;
case 10013LL:
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1520);
goto LABEL_30;
case 16LL:
if ( *(_DWORD *)(v10 + 1484) == 2 && *(_QWORD *)(*(_QWORD *)(v10 + 1320) + 1824LL) )
{
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1584);
goto LABEL_30;
}
LABEL_40:
v19 = a2 == 27;
v13 = v11 != 0;
goto LABEL_41;
case 25LL:
if ( *(_DWORD *)(v10 + 1484) == 2 && *(_QWORD *)(*(_QWORD *)(v10 + 1320) + 1824LL) )
{
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1600);
goto LABEL_30;
}
goto LABEL_40;
}
if ( a2 != 26 )
{
v19 = a2 == 27;
v13 = v11 != 0 && a2 == 27;
if ( v11 != 0 && a2 == 27 )
{
v20 = 0;
if ( *(_DWORD *)(v10 + 1484) != 2 )
{
LABEL_58:
v14 = v20;
goto LABEL_43;
}
v23 = *(_QWORD *)(v10 + 1320);
v24 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *, __int64, const void *))(v23 + 2984);
if ( !v24 )
{
v18 = (*(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *, __int64, const void *))(v23 + 2976))(
*(_QWORD *)(a1 + 1056),
9LL,
a3,
a4,
a5);
goto LABEL_30;
}
LABEL_60:
v18 = v24(*(_QWORD *)(a1 + 1056), 9LL, a3, a4, a5);
goto LABEL_30;
}
v13 = v11 != 0;
LABEL_41:
v14 = v11 == 0;
v20 = v19 && v14;
if ( v19 && v14 )
{
if ( *(_DWORD *)(v10 + 1484) != 2 )
goto LABEL_58;
v24 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *, __int64, const void *))(*(_QWORD *)(v10 + 1320) + 2976LL);
if ( v24 )
goto LABEL_60;
}
else if ( !v19 || *(_DWORD *)(v10 + 1484) != 2 )
{
goto LABEL_43;
}
v18 = (*(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *))(*(_QWORD *)(v10 + 1320) + 3040LL))(
*(_QWORD *)(a1 + 1056),
9LL,
a3);
goto LABEL_30;
}
if ( *(_DWORD *)(v10 + 1484) == 2 && *(_QWORD *)(*(_QWORD *)(v10 + 1320) + 1824LL) )
{
v18 = 0;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 1592);
goto LABEL_30;
}
v13 = v11 != 0;
v14 = v11 == 0;
LABEL_43:
if ( v13 )
{
v21 = *(_QWORD **)(v10 + 1320);
v22 = (__int64 (__fastcall *)(_QWORD, __int64, _QWORD *, __int64, const void *))v21[373];
if ( !v22 )
{
v22 = (__int64 (__fastcall *)(_QWORD, __int64, _QWORD *, __int64, const void *))v21[372];
if ( !v22 )
{
if ( !v14 )
{
v25 = (__int64 (__fastcall *)(_QWORD, __int64, _QWORD *))v21[381];
if ( v25 )
{
if ( a2 <= 19999 && (unsigned __int64)a2 > 0xE )
{
dm_log_write("SQLGetStmtAttr.c", 480LL, 0LL, 0LL, "Error: HY092");
_post_internal_error(
a1 + 1088,
30LL,
0LL,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v18 = v25(*(_QWORD *)(a1 + 1056), a2, a3);
goto LABEL_30;
}
}
goto LABEL_75;
}
}
LABEL_73:
v18 = v22(*(_QWORD *)(a1 + 1056), a2, a3, a4, a5);
goto LABEL_30;
}
v22 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *, __int64, const void *))(*(_QWORD *)(v10 + 1320) + 2976LL);
if ( v22 )
goto LABEL_73;
LABEL_75:
if ( a2 <= 19999 && (unsigned __int64)a2 > 0xE )
{
dm_log_write("SQLGetStmtAttr.c", 507LL, 0LL, 0LL, "Error: HY092");
_post_internal_error(a1 + 1088, 30LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v18 = (*(__int64 (__fastcall **)(_QWORD, __int64, _QWORD *))(*(_QWORD *)(v10 + 1320) + 3040LL))(
*(_QWORD *)(a1 + 1056),
a2,
a3);
LABEL_30:
if ( log_info[4] )
{
v26 = (const char *)_get_return_status((unsigned int)v18, v27);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v26);
dm_log_write("SQLGetStmtAttr.c", 532LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v18, 0LL);
}

original_code:
SQLRETURN SQLGetStmtAttr( SQLHSTMT statement_handle,
           SQLINTEGER attribute,
           SQLPOINTER value,
           SQLINTEGER buffer_length,
           SQLINTEGER *string_length )
{
    DMHSTMT statement = (DMHSTMT) statement_handle;
    SQLRETURN ret;
    SQLCHAR s1[ 100 + 128 ];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLGetStmtAttr.c",
                    198,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tAttribute = %s\n\t\t\tValue = %p\n\t\t\tBuffer Length = %d\n\t\t\tStrLen = %p",
                statement,
                __stmt_attr_as_string( s1, attribute ),
                value,
                (int)buffer_length,
                (void*)string_length );
        dm_log_write( "SQLGetStmtAttr.c",
                223,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( attribute == 14 )
    {
        if ( statement -> state == 1 ||
                statement -> state == 2 ||
                statement -> state == 3 ||
                statement -> state == 4 )
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    243,
                    0,
                    0,
                    "Error: 24000" );
            __post_internal_error( &statement -> error,
                    ERROR_24000, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 ||
            statement -> state == 11 ||
            statement -> state == 12 )
    {
        dm_log_write( "SQLGetStmtAttr.c",
                263,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> connection -> unicode_driver )
    {
        if ( !(statement -> connection->functions[46].funcW!=((void *)0)) &&
            !(statement -> connection->functions[47].funcW!=((void *)0)) &&
            !(statement -> connection->functions[46].func!=((void *)0)) &&
            !(statement -> connection->functions[47].func!=((void *)0)))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    287,
                    0,
                    0,
                    "Error: IM001" );
            __post_internal_error( &statement -> error,
                    ERROR_IM001, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    else
    {
        if ( !(statement -> connection->functions[46].func!=((void *)0)) &&
            !(statement -> connection->functions[47].func!=((void *)0)))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    305,
                    0,
                    0,
                    "Error: IM001" );
            __post_internal_error( &statement -> error,
                    ERROR_IM001, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( attribute == 10010 )
    {
        if ( value )
            memcpy( value, &statement -> ard, sizeof( statement -> ard ));
        ret = 0;
    }
    else if ( attribute == 10011 )
    {
        if ( value )
            memcpy( value, &statement -> apd, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 10012 )
    {
        if ( value )
            memcpy( value, &statement -> ird, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 10013 )
    {
        if ( value )
            memcpy( value, &statement -> ipd, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 16 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> fetch_bm_ptr, sizeof( SQLUINTEGER * ));
        ret = 0;
    }
    else if ( attribute == 25 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> row_st_arr, sizeof( SQLUINTEGER * ));
        ret = 0;
    }
    else if ( attribute == 26 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> row_ct_ptr, sizeof( SQLUINTEGER * ));
        ret = 0;
    }
    else if ( statement -> connection -> unicode_driver &&
            attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        if ( (statement -> connection->functions[46].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[46].funcW) (statement -> driver_stmt,9,value,buffer_length,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,9,value,buffer_length,string_length);
        }
    }
    else if ( !statement -> connection -> unicode_driver &&
            attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[46].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,9,value,buffer_length,string_length);
    }
    else if ( attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        if ( statement -> connection -> unicode_driver &&
                (statement -> connection->functions[47].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[47].funcW) (statement -> driver_stmt,9,value);
        }
        else
        {
            ret = (statement -> connection->functions[47].func) (statement -> driver_stmt,9,value);
        }
    }
    else if ( statement -> connection -> unicode_driver &&
            ( (statement -> connection->functions[46].funcW!=((void *)0)) ||
            (statement -> connection->functions[46].func!=((void *)0))))
    {
        if ( (statement -> connection->functions[46].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[46].funcW) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
        }
    }
    else if ( !statement -> connection -> unicode_driver &&
            (statement -> connection->functions[46].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
    }
    else if ( statement -> connection -> unicode_driver &&
            (statement -> connection->functions[47].funcW!=((void *)0)))
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    480,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[47].funcW) (statement -> driver_stmt,attribute,value);
    }
    else
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    507,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[47].func) (statement -> driver_stmt,attribute,value);
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLGetStmtAttr.c",
                532,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

canonical_original_code:
short SQLGetStmtAttr(void *statement_handle, long attribute, void *value, long buffer_length, long *string_length)
{
    struct statement *statement = (DMHSTMT) statement_handle;
    short ret;
    unsigned char s1[-1];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLGetStmtAttr.c",
                    198,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tAttribute = %s\n\t\t\tValue = %p\n\t\t\tBuffer Length = %d\n\t\t\tStrLen = %p",
                statement,
                __stmt_attr_as_string( s1, attribute ),
                value,
                (int)buffer_length,
                (void *)string_length );
        dm_log_write( "SQLGetStmtAttr.c",
                223,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( attribute == 14 )
    {
        if ( statement -> state == 1 ||
                statement -> state == 2 ||
                statement -> state == 3 ||
                statement -> state == 4 )
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    243,
                    0,
                    0,
                    "Error: 24000" );
            __post_internal_error( &statement -> error,
                    ERROR_24000, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 ||
            statement -> state == 11 ||
            statement -> state == 12 )
    {
        dm_log_write( "SQLGetStmtAttr.c",
                263,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> connection -> unicode_driver )
    {
        if ( !(statement -> connection->functions[46].funcW!=((void *)0)) &&
            !(statement -> connection->functions[47].funcW!=((void *)0)) &&
            !(statement -> connection->functions[46].func!=((void *)0)) &&
            !(statement -> connection->functions[47].func!=((void *)0)))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    287,
                    0,
                    0,
                    "Error: IM001" );
            __post_internal_error( &statement -> error,
                    ERROR_IM001, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    else
    {
        if ( !(statement -> connection->functions[46].func!=((void *)0)) &&
            !(statement -> connection->functions[47].func!=((void *)0)))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    305,
                    0,
                    0,
                    "Error: IM001" );
            __post_internal_error( &statement -> error,
                    ERROR_IM001, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( attribute == 10010 )
    {
        if ( value )
            memcpy( value, &statement -> ard, sizeof( statement -> ard ));
        ret = 0;
    }
    else if ( attribute == 10011 )
    {
        if ( value )
            memcpy( value, &statement -> apd, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 10012 )
    {
        if ( value )
            memcpy( value, &statement -> ird, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 10013 )
    {
        if ( value )
            memcpy( value, &statement -> ipd, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 16 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> fetch_bm_ptr, sizeof( unsigned long * ));
        ret = 0;
    }
    else if ( attribute == 25 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> row_st_arr, sizeof( unsigned long * ));
        ret = 0;
    }
    else if ( attribute == 26 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> row_ct_ptr, sizeof( unsigned long * ));
        ret = 0;
    }
    else if ( statement -> connection -> unicode_driver &&
            attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        if ( (statement -> connection->functions[46].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[46].funcW) (statement -> driver_stmt,9,value,buffer_length,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,9,value,buffer_length,string_length);
        }
    }
    else if ( !statement -> connection -> unicode_driver &&
            attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[46].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,9,value,buffer_length,string_length);
    }
    else if ( attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        if ( statement -> connection -> unicode_driver &&
                (statement -> connection->functions[47].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[47].funcW) (statement -> driver_stmt,9,value);
        }
        else
        {
            ret = (statement -> connection->functions[47].func) (statement -> driver_stmt,9,value);
        }
    }
    else if ( statement -> connection -> unicode_driver &&
            ( (statement -> connection->functions[46].funcW!=((void *)0)) ||
            (statement -> connection->functions[46].func!=((void *)0))))
    {
        if ( (statement -> connection->functions[46].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[46].funcW) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
        }
    }
    else if ( !statement -> connection -> unicode_driver &&
            (statement -> connection->functions[46].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
    }
    else if ( statement -> connection -> unicode_driver &&
            (statement -> connection->functions[47].funcW!=((void *)0)))
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    480,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[47].funcW) (statement -> driver_stmt,attribute,value);
    }
    else
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    507,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[47].func) (statement -> driver_stmt,attribute,value);
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLGetStmtAttr.c",
                532,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

variable_types: attribute long

variable_types:
value
void *

variable_types: struct statement { int type; struct statement *next_class_list; char msg[1024]; int state; struct connection { int type; struct connection *next_class_list; char msg[1024]; int state; struct environment { int type; struct environment *next_class_list; char msg[1024]; int state; long requested_version; int connection_count; int sql_driver_count; struct error_head { struct error_header { int error_count; struct error { unsigned short sqlstate[6]; unsigned short *msg; long native_error; int return_val; short diag_column_number_ret; short diag_row_number_ret; short diag_class_origin_ret; short diag_subclass_origin_ret; short diag_connection_name_ret; short diag_server_name_ret; long diag_column_number; long diag_row_number; unsigned short diag_class_origin[128]; unsigned short diag_subclass_origin[128]; unsigned short diag_connection_name[128]; unsigned short diag_server_name[128]; struct error *next; struct error *prev; } *error_list_head; struct error *error_list_tail; int internal_count; struct error *internal_list_head; struct error *internal_list_tail; } sql_error_head; struct error_header sql_diag_head; void *owning_handle; int handle_type; short return_code; long header_set; short diag_cursor_row_count_ret; short diag_dynamic_function_ret; short diag_dynamic_function_code_ret; short diag_number_ret; short diag_row_count_ret; long diag_cursor_row_count; unsigned short diag_dynamic_function[128]; long diag_dynamic_function_code; long diag_number; long diag_row_count; } error; long connection_pooling; long cp_match; int fetch_mode; int entry; void *sh; struct env_lib_struct { char *lib_name; void *env_handle; int count; struct env_lib_struct *next; } *env_lib_list; } *environment; void *dl_handle; char dl_name[256]; struct driver_func { int ordinal; char *name; void *dm_func; void *dm_funcW; short (*func)(); short (*funcW)(); short (*funcA)(); int can_supply; } *functions; struct driver_func ini_func; struct driver_func fini_func; int unicode_driver; void *driver_env; void *driver_dbc; int driver_version; int driver_act_ver; int statement_count; struct error_head error; char dsn[-1]; int access_mode; int access_mode_set; int login_timeout; int login_timeout_set; int auto_commit; int auto_commit_set; int async_enable; int async_enable_set; int auto_ipd; int auto_ipd_set; int connection_timeout; int connection_timeout_set; int metadata_id; int metadata_id_set; int packet_size; int packet_size_set; long quite_mode; int quite_mode_set; int txn_isolation; int txn_isolation_set; long cursors; void *cl_handle; int trace; char tracefile[-1]; 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; int protection_level; int ex_fetch_mapping; int disable_gf; int dont_dlclose; int bookmarks_on; void *pooled_connection; int pooling_timeout; int ttl; char driver_connect_string[1024]; int dsn_length; char server[128]; int server_length; char user[128]; int user_length; char password[128]; int password_length; char cli_year[5]; struct attr_struct { int count; struct attr_set { char *keyword; char *value; int override; int attribute; int is_int_type; int int_value; struct attr_set *next; } *list; } env_attribute; struct attr_struct dbc_attribute; struct attr_struct stmt_attribute; struct save_attr { int attr_type; char *str_attr; int str_len; int int_attr; struct save_attr *next; } *save_attr; void *iconv_cd_uc_to_ascii; void *iconv_cd_ascii_to_uc; char unicode_string[64]; struct env_lib_struct *env_list_ent; char probe_sql[512]; int threading_level; int cbs_found; short ccb_value; short crb_value; } *connection; void *driver_stmt; short hascols; int prepared; int interupted_func; int interupted_state; int bookmarks_on; struct error_head error; long metadata_id; struct descriptor { int type; struct descriptor *next_class_list; char msg[1024]; int state; struct error_head error; void *driver_desc; struct connection *connection; int implicit; void *associated_with; union pthread_mutex_t mutex; } *ipd; struct descriptor *apd; struct descriptor *ird; struct descriptor *ard; struct descriptor *implicit_ipd; struct descriptor *implicit_apd; struct descriptor *implicit_ird; struct descriptor *implicit_ard; unsigned long *fetch_bm_ptr; unsigned long *row_ct_ptr; unsigned short *row_st_arr; unsigned long row_array_size; void *valueptr; union pthread_mutex_t mutex; int eod; } *

variable_types: ret short


SQLProcedures

repo: xiaotmiaomiao/unixODBC-SPEC

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

result = 4294967294LL;
if ( a1 )
{
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLProcedures.c", "SQLProcedures.c", 32LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLProcedures.c",
"SQLProcedures.c",
37LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = 4294967294LL;
if ( a1 )
{
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLProcedures.c", "SQLProcedures.c", 32LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLProcedures.c",
"SQLProcedures.c",
37LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
RETCODE SQLProcedures(
                              HSTMT hstmt,
                              UCHAR * szProcQualifier,
                              SWORD cbProcQualifier,
                              UCHAR * szProcOwner,
                              SWORD cbProcOwner,
                              UCHAR * szProcName,
                              SWORD cbProcName)
{
static char* const func="SQLProcedures";
 mylog("%s: entering...\n", func);
 SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
    return (-1);
}

canonical_original_code:
short SQLProcedures(void *hstmt, unsigned char *szProcQualifier, short cbProcQualifier, unsigned char *szProcOwner, short cbProcOwner, unsigned char *szProcName, short cbProcName)
{
static char *func = "SQLProcedures";
 mylog("%s: entering...\n", func);
 SC_log_error(func, "Function not implemented", (struct StatementClass_ *) hstmt);
    return (-1);
}

variable_types:
hstmt
void *

variable_types:
szProcQualifier
unsigned char *

variable_types: cbProcQualifier short

variable_types:
szProcOwner
unsigned char *

variable_types: cbProcOwner short

variable_types:
szProcName
unsigned char *

variable_types: cbProcName short

variable_types:
func
char *

return_type: short

user_defined_types: struct StatementClass_ { struct ConnectionClass_ *hdbc; struct QResultClass_ *result; void **phstmt; struct StatementOptions_ options; enum STMT_Status status; char *__error_message; int __error_number; struct BindInfoClass_ *bindings; struct BindInfoClass_ bookmark; int bindings_allocated; int parameters_allocated; struct ParameterInfoClass_ *parameters; int currTuple; int save_rowset_size; int rowset_start; int bind_row; int last_fetch_count; int current_col; int lobj_fd; char *statement; struct TABLE_INFO **ti; struct FIELD_INFO **fi; int nfld; int ntab; int parse_status; int statement_type; int data_at_exec; int current_exec_param; char put_data; char errormsg_created; char manual_result; char prepare; char internal; char cursor_name[-1]; char stmt_with_params[65536]; int reexecute; }

user_defined_types: enum STMT_Status { STMT_ALLOCATED=0, STMT_READY=1, STMT_PREMATURE=2, STMT_FINISHED=3, STMT_EXECUTING=4 }

user_defined_types: struct ConnectionClass_ { void *henv; struct StatementOptions_ stmtOptions; char *__error_message; int __error_number; enum CONN_Status status; struct ConnInfo connInfo; struct StatementClass_ **stmts; int num_stmts; struct SocketClass_ *sock; int lobj_type; int ntables; struct col_info **col_info; long translation_option; void *translation_handle; int (*DataSourceToDriver)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); int (*DriverToDataSource)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); short driver_version; char transact_status; char errormsg_created; char pg_version[128]; float pg_version_number; short pg_version_major; short pg_version_minor; char ms_jet; char unicode; char result_uncommitted; char schema_support; char *client_encoding; char *server_encoding; int ccsc; int be_pid; int be_key; unsigned int isolation; char *current_schema; int num_discardp; char **discardp; }

user_defined_types: struct BindInfoClass_ { int buflen; int data_left; char *buffer; long *used; short returntype; }

user_defined_types: struct ParameterInfoClass_ { int buflen; char *buffer; long *used; short paramType; short CType; short SQLType; unsigned int precision; short scale; unsigned int lobj_oid; int *EXEC_used; char *EXEC_buffer; char data_at_exec; }

user_defined_types: struct StatementOptions_ { int maxRows; int maxLength; int rowset_size; int keyset_size; int cursor_type; int scroll_concurrency; int retrieve_data; int bind_size; int use_bookmarks; }

user_defined_types: enum CONN_Status { CONN_NOT_CONNECTED=0, CONN_CONNECTED=1, CONN_DOWN=2, CONN_EXECUTING=3 }

user_defined_types: struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; }

user_defined_types: struct TABLE_INFO { struct col_info *col_info; char name[-1]; char alias[-1]; }

user_defined_types: struct FIELD_INFO { struct TABLE_INFO *ti; int precision; int display_size; int length; int type; char nullable; char func; char expr; char quote; char dquote; char numeric; char dot[-1]; char name[-1]; char alias[-1]; }

user_defined_types: struct SocketClass_ { int buffer_filled_in; int buffer_filled_out; int buffer_read_in; unsigned char *buffer_in; unsigned char *buffer_out; int socket; char *errormsg; int errornumber; char reverse; }

user_defined_types: struct col_info { struct QResultClass_ *result; char name[-1]; }

user_defined_types: struct QResultClass_ { struct ColumnInfoClass_ *fields; struct TupleListClass_ *manual_tuples; struct ConnectionClass_ *conn; int fetch_count; int fcount; int currTuple; int base; int num_fields; int cache_size; int rowset_size; enum QueryResultCode_ status; char *message; char *cursor; char *command; char *notice; struct TupleField_ *backend_tuples; struct TupleField_ *tupleField; char inTuples; char aborted; }

user_defined_types: enum QueryResultCode_ { PGRES_EMPTY_QUERY=0, PGRES_COMMAND_OK=1, PGRES_TUPLES_OK=2, PGRES_COPY_OUT=3, PGRES_COPY_IN=4, PGRES_BAD_RESPONSE=5, PGRES_NONFATAL_ERROR=6, PGRES_FATAL_ERROR=7, PGRES_FIELDS_OK=8, PGRES_END_TUPLES=9, PGRES_INTERNAL_ERROR=10 }

user_defined_types: struct ColumnInfoClass_ { short num_fields; char **name; unsigned int *adtid; short *adtsize; short *display_size; int *atttypmod; }

user_defined_types: struct TupleListClass_ { int num_fields; int num_tuples; struct TupleNode_ *list_start; int last_indexed; }

user_defined_types: struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ tuple[1]; }

user_defined_types: struct TupleField_ { int len; void *value; }


SQLColumns

decompiled_code:
__int64 __fastcall SQLColumns(__int64 a1, __int64 a2, __int16 a3, __int64 a4, __int16 a5, __int64 a6, __int16 a7, __int64 a8, __int16 a9)
{
const char *v12; // rax
int v13; // eax
int v14; // edx
__int64 v15; // rdx
void *v16; // r15
__int16 v17; // bp
__int64 (__fastcall *v18)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD); // r10
const char *v19; // rax
void *v20; // [rsp+0h] [rbp-428h]
void *v22; // [rsp+8h] [rbp-420h]
const char *ptra; // [rsp+18h] [rbp-410h]
void *ptr; // [rsp+18h] [rbp-410h]
const char *v26; // [rsp+20h] [rbp-408h]
const char *v27; // [rsp+28h] [rbp-400h]
char v28[240]; // [rsp+30h] [rbp-3F8h] BYREF
char v29[240]; // [rsp+120h] [rbp-308h] BYREF
char v30[240]; // [rsp+210h] [rbp-218h] BYREF
char v31[296]; // [rsp+300h] [rbp-128h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLColumns.c", 190LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
ptra = (const char *)_string_with_length(v28, a8, a9);
v26 = (const char *)_string_with_length(v29, a6, a7);
v27 = (const char *)_string_with_length(v30, a4, a5);
v12 = (const char *)_string_with_length(v31, a2, a3);
sprintf(
(char *)(a1 + 16),
"\n"
"\t\tEntry:\n"
"\t\t\tStatement = %p\n"
"\t\t\tCatalog Name = %s\n"
"\t\t\tSchema Name = %s\n"
"\t\t\tTable Name = %s\n"
"\t\t\tColumn Name = %s",
(const void *)a1,
v12,
v27,
v26,
ptra);
dm_log_write("SQLColumns.c", 215LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( a3 < 0 && a3 != -3 || a5 < 0 && a5 != -3 || a7 < 0 && a7 != -3 || a9 < 0 && a9 != -3 )
{
_post_internal_error(a1 + 1088, 29LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v13 = *(_DWORD *)(a1 + 1040);
if ( v13 == 6 )
{
v14 = 6;
if ( *(_DWORD *)(a1 + 1664) )
goto LABEL_17;
LABEL_29:
dm_log_write("SQLColumns.c", 249LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v13 == 7 )
goto LABEL_29;
v14 = *(_DWORD *)(a1 + 1040);
if ( (unsigned int)(v13 - 8) <= 2 )
{
dm_log_write("SQLColumns.c", 265LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
LABEL_17:
if ( (unsigned int)(v14 - 11) <= 1 && *(_DWORD *)(a1 + 1072) != 40 )
{
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v15 = *(_QWORD *)(a1 + 1048);
if ( *(_DWORD *)(v15 + 1456) )
{
if ( !*(_QWORD *)(*(_QWORD *)(v15 + 1320) + 1000LL) )
{
dm_log_write("SQLColumns.c", 301LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
ptr = (void *)ansi_to_unicode_alloc(a2, a3);
v20 = (void *)ansi_to_unicode_alloc(a4, a5);
v22 = (void *)ansi_to_unicode_alloc(a6, a7);
v16 = (void *)ansi_to_unicode_alloc(a8, a9);
v17 = (*(__int64 (__fastcall **)(_QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD))(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1320LL) + 1000LL))(
*(_QWORD *)(a1 + 1056),
ptr,
(unsigned int)a3,
v20,
(unsigned int)a5,
v22,
(unsigned int)a7,
v16,
(unsigned int)a9);
if ( ptr )
free(ptr);
if ( v20 )
free(v20);
if ( v22 )
free(v22);
if ( v16 )
free(v16);
}
else
{
v18 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD))(*(_QWORD *)(v15 + 1320) + 992LL);
if ( !v18 )
{
dm_log_write("SQLColumns.c", 343LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v17 = v18(
*(_QWORD *)(a1 + 1056),
a2,
(unsigned int)a3,
a4,
(unsigned int)a5,
a6,
(unsigned int)a7,
a8,
(unsigned int)a9);
}
if ( (v17 & 0xFFFE) != 0 )
{
if ( v17 == 2 )
{
*(_DWORD *)(a1 + 1072) = 40;
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 11) > 1 )
*(_DWORD *)(a1 + 1040) = 11;
}
else
{
*(_DWORD *)(a1 + 1040) = 1;
}
}
else
{
*(_DWORD *)(a1 + 1040) = 5;
*(_WORD *)(a1 + 1064) = 1;
*(_DWORD *)(a1 + 1068) = 0;
}
if ( log_info[4] )
{
v19 = (const char *)_get_return_status((unsigned int)v17, v31);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v19);
dm_log_write("SQLColumns.c", 412LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v17, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int16 a3, __int64 a4, __int16 a5, __int64 a6, __int16 a7, __int64 a8, __int16 a9)
{
const char *v12; // rax
int v13; // eax
int v14; // edx
__int64 v15; // rdx
void *v16; // r15
__int16 v17; // bp
__int64 (__fastcall *v18)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD); // r10
const char *v19; // rax
void *v20; // [rsp+0h] [rbp-428h]
void *v22; // [rsp+8h] [rbp-420h]
const char *ptra; // [rsp+18h] [rbp-410h]
void *ptr; // [rsp+18h] [rbp-410h]
const char *v26; // [rsp+20h] [rbp-408h]
const char *v27; // [rsp+28h] [rbp-400h]
char v28[240]; // [rsp+30h] [rbp-3F8h] BYREF
char v29[240]; // [rsp+120h] [rbp-308h] BYREF
char v30[240]; // [rsp+210h] [rbp-218h] BYREF
char v31[296]; // [rsp+300h] [rbp-128h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLColumns.c", 190LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
ptra = (const char *)_string_with_length(v28, a8, a9);
v26 = (const char *)_string_with_length(v29, a6, a7);
v27 = (const char *)_string_with_length(v30, a4, a5);
v12 = (const char *)_string_with_length(v31, a2, a3);
sprintf(
(char *)(a1 + 16),
"\n"
"\t\tEntry:\n"
"\t\t\tStatement = %p\n"
"\t\t\tCatalog Name = %s\n"
"\t\t\tSchema Name = %s\n"
"\t\t\tTable Name = %s\n"
"\t\t\tColumn Name = %s",
(const void *)a1,
v12,
v27,
v26,
ptra);
dm_log_write("SQLColumns.c", 215LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( a3 < 0 && a3 != -3 || a5 < 0 && a5 != -3 || a7 < 0 && a7 != -3 || a9 < 0 && a9 != -3 )
{
_post_internal_error(a1 + 1088, 29LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v13 = *(_DWORD *)(a1 + 1040);
if ( v13 == 6 )
{
v14 = 6;
if ( *(_DWORD *)(a1 + 1664) )
goto LABEL_17;
LABEL_29:
dm_log_write("SQLColumns.c", 249LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v13 == 7 )
goto LABEL_29;
v14 = *(_DWORD *)(a1 + 1040);
if ( (unsigned int)(v13 - 8) <= 2 )
{
dm_log_write("SQLColumns.c", 265LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
LABEL_17:
if ( (unsigned int)(v14 - 11) <= 1 && *(_DWORD *)(a1 + 1072) != 40 )
{
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v15 = *(_QWORD *)(a1 + 1048);
if ( *(_DWORD *)(v15 + 1456) )
{
if ( !*(_QWORD *)(*(_QWORD *)(v15 + 1320) + 1000LL) )
{
dm_log_write("SQLColumns.c", 301LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
ptr = (void *)ansi_to_unicode_alloc(a2, a3);
v20 = (void *)ansi_to_unicode_alloc(a4, a5);
v22 = (void *)ansi_to_unicode_alloc(a6, a7);
v16 = (void *)ansi_to_unicode_alloc(a8, a9);
v17 = (*(__int64 (__fastcall **)(_QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD))(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1320LL) + 1000LL))(
*(_QWORD *)(a1 + 1056),
ptr,
(unsigned int)a3,
v20,
(unsigned int)a5,
v22,
(unsigned int)a7,
v16,
(unsigned int)a9);
if ( ptr )
free(ptr);
if ( v20 )
free(v20);
if ( v22 )
free(v22);
if ( v16 )
free(v16);
}
else
{
v18 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD))(*(_QWORD *)(v15 + 1320) + 992LL);
if ( !v18 )
{
dm_log_write("SQLColumns.c", 343LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v17 = v18(
*(_QWORD *)(a1 + 1056),
a2,
(unsigned int)a3,
a4,
(unsigned int)a5,
a6,
(unsigned int)a7,
a8,
(unsigned int)a9);
}
if ( (v17 & 0xFFFE) != 0 )
{
if ( v17 == 2 )
{
*(_DWORD *)(a1 + 1072) = 40;
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 11) > 1 )
*(_DWORD *)(a1 + 1040) = 11;
}
else
{
*(_DWORD *)(a1 + 1040) = 1;
}
}
else
{
*(_DWORD *)(a1 + 1040) = 5;
*(_WORD *)(a1 + 1064) = 1;
*(_DWORD *)(a1 + 1068) = 0;
}
if ( log_info[4] )
{
v19 = (const char *)_get_return_status((unsigned int)v17, v31);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v19);
dm_log_write("SQLColumns.c", 412LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v17, 0LL);
}

original_code:
RETCODE SQLColumns(
                           HSTMT hstmt,
                           UCHAR * szTableQualifier,
                           SWORD cbTableQualifier,
                           UCHAR * szTableOwner,
                           SWORD cbTableOwner,
                           UCHAR * szTableName,
                           SWORD cbTableName,
                           UCHAR * szColumnName,
                           SWORD cbColumnName)
{
    return PG_SQLColumns( hstmt,
                        szTableQualifier,
                        cbTableQualifier,
                        szTableOwner,
                        cbTableOwner,
                        szTableName,
                        cbTableName,
                        szColumnName,
                        cbColumnName );
}

canonical_original_code:
short SQLColumns(void *hstmt, unsigned char *szTableQualifier, short cbTableQualifier, unsigned char *szTableOwner, short cbTableOwner, unsigned char *szTableName, short cbTableName, unsigned char *szColumnName, short cbColumnName)
{
    return PG_SQLColumns( hstmt,
                        szTableQualifier,
                        cbTableQualifier,
                        szTableOwner,
                        cbTableOwner,
                        szTableName,
                        cbTableName,
                        szColumnName,
                        cbColumnName );
}

variable_types:
szTableQualifier
unsigned char *

variable_types: cbTableQualifier short

variable_types:
szTableOwner
unsigned char *

variable_types: cbTableOwner short

variable_types:
szTableName
unsigned char *

variable_types: cbTableName short

variable_types:
szColumnName
unsigned char *

variable_types: cbColumnName short


SQLWriteFileDSNW

decompiled_code:
__int64 __fastcall SQLWriteFileDSNW(char *src, void *ptr, void *a3, void *a4)
{
char *v4; // r13
void *v5; // r12
unsigned int v8; // er14

v4 = src;
v5 = ptr;
if ( src )
v4 = (char *)((__int64 (*)(void))single_string_alloc_and_copy)();
if ( ptr )
v5 = (void *)single_string_alloc_and_copy(ptr);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a4 )
a4 = (void *)single_string_alloc_and_copy(a4);
v8 = SQLWriteFileDSN(v4, (__int64)v5, (__int64)a3, (__int64)a4);
if ( v4 )
free(v4);
if ( v5 )
free(v5);
if ( a3 )
free(a3);
if ( a4 )
free(a4);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, void *ptr, void *a3, void *a4)
{
char *v4; // r13
void *v5; // r12
unsigned int v8; // er14

v4 = src;
v5 = ptr;
if ( src )
v4 = (char *)((__int64 (*)(void))single_string_alloc_and_copy)();
if ( ptr )
v5 = (void *)single_string_alloc_and_copy(ptr);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a4 )
a4 = (void *)single_string_alloc_and_copy(a4);
v8 = func0(v4, (__int64)v5, (__int64)a3, (__int64)a4);
if ( v4 )
free(v4);
if ( v5 )
free(v5);
if ( a3 )
free(a3);
if ( a4 )
free(a4);
return v8;
}

original_code:
int SQLWriteFileDSNW(LPCWSTR lpszFileName,
                              LPCWSTR lpszAppName,
                              LPCWSTR lpszKeyName,
                              LPCWSTR lpszString)
{
 int ret;
 char *file;
 char *app;
 char *key;
 char *str;
 file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char*)((void *)0);
 app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char*)((void *)0);
 key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char*)((void *)0);
 str = lpszString ? _single_string_alloc_and_copy( lpszString ) : (char*)((void *)0);
 ret = SQLWriteFileDSN( file, app, key, str );
 if ( file )
  free( file );
 if ( app )
  free( app );
 if ( key )
  free( key );
 if ( str )
  free( str );
 return ret;
}

canonical_original_code:
int SQLWriteFileDSNW(unsigned short *lpszFileName, unsigned short *lpszAppName, unsigned short *lpszKeyName, unsigned short *lpszString)
{
 int ret;
 char *file;
 char *app;
 char *key;
 char *str;
 file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char *)((void *)0);
 app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char *)((void *)0);
 key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char *)((void *)0);
 str = lpszString ? _single_string_alloc_and_copy( lpszString ) : (char *)((void *)0);
 ret = SQLWriteFileDSN( file, app, key, str );
 if ( file )
  free( file );
 if ( app )
  free( app );
 if ( key )
  free( key );
 if ( str )
  free( str );
 return ret;
}

variable_types:
lpszFileName
unsigned short *

variable_types:
lpszAppName
unsigned short *

variable_types:
lpszKeyName
unsigned short *

variable_types:
lpszString
unsigned short *

variable_types: ret int

variable_types:
file
char *

variable_types:
app
char *

variable_types:
key
char *

variable_types:
str
char *

return_type: int


variable_types: n int

variable_types: i int


decompiled_code:
__int64 nnodbc_conndialog()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0xFFFFFFFFLL;
}

original_code:
int nnodbc_conndialog()
{
 return -1;
}

canonical_original_code:
int nnodbc_conndialog()
{
 return -1;
}


SQLSetDescField

decompiled_code:
__int64 SQLSetDescField()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0xFFFFFFFFLL;
}

original_code:
SQLRETURN SQLSetDescField( SQLHDESC DescriptorHandle,
                             SQLSMALLINT RecordNumber,
                             SQLSMALLINT FieldIdentifier,
                             SQLPOINTER Value,
                             SQLINTEGER BufferLength
                          )
{
    return (-1);
}

canonical_original_code:
short SQLSetDescField(void *DescriptorHandle, short RecordNumber, short FieldIdentifier, void *Value, long BufferLength)
{
    return (-1);
}

variable_types:
DescriptorHandle
void *

variable_types: RecordNumber short

variable_types: FieldIdentifier short

variable_types:
Value
void *

variable_types: BufferLength long


SQLFetchScroll

decompiled_code:
__int64 __fastcall SQLFetchScroll(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rax
int v5; // eax
__int64 v6; // rax
__int64 v7; // rdx
__int64 (__fastcall *v8)(_QWORD, _QWORD, __int64); // rcx
__int16 v9; // bp
__int64 (__fastcall *v11)(_QWORD, __int64, __int64, _QWORD, _QWORD); // r9
__int64 *v12; // rax
__int64 v13; // rdx
const char *v14; // rax
__int64 v15; // [rsp+0h] [rbp-118h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLFetchScroll.c", 138LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
sprintf(
(char *)(a1 + 16),
"\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tFetch Orentation = %d\n\t\t\tFetch Offset = %d",
(const void *)a1,
(unsigned int)(__int16)a2,
(unsigned int)a3);
dm_log_write("SQLFetchScroll.c", 159LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( (_WORD)a2 != 1 && (_WORD)a2 != 4 )
{
if ( (unsigned __int16)a2 > 8u || (v4 = 364LL, !_bittest64(&v4, a2)) )
{
dm_log_write("SQLFetchScroll.c", 176LL, 0LL, 0LL, "Error: HY106");
_post_internal_error(a1 + 1088, 38LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
}
v5 = *(_DWORD *)(a1 + 1040);
if ( (unsigned int)(v5 - 1) <= 2 )
{
dm_log_write("SQLFetchScroll.c", 197LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v5 == 4 )
{
dm_log_write("SQLFetchScroll.c", 212LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v5 == 7 )
{
dm_log_write("SQLFetchScroll.c", 227LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( (unsigned int)(v5 - 8) <= 2 )
{
dm_log_write("SQLFetchScroll.c", 244LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( (unsigned int)(v5 - 11) <= 1 && *(_DWORD *)(a1 + 1072) != 1021 )
{
dm_log_write("SQLFetchScroll.c", 262LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v6 = *(_QWORD *)(a1 + 1048);
v7 = *(_QWORD *)(v6 + 1320);
v8 = *(__int64 (__fastcall **)(_QWORD, _QWORD, __int64))(v7 + 1952);
if ( v8 )
{
v9 = v8(*(_QWORD *)(a1 + 1056), (unsigned int)(__int16)a2, a3);
}
else
{
if ( *(_DWORD *)(v6 + 1484) != 2
|| (v11 = *(__int64 (__fastcall **)(_QWORD, __int64, __int64, _QWORD, _QWORD))(v7 + 1824)) == 0LL )
{
dm_log_write("SQLFetchScroll.c", 315LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( (_WORD)a2 == 8 )
{
v12 = *(__int64 **)(a1 + 1584);
v13 = 0LL;
if ( v12 )
v13 = *v12;
v9 = v11(*(_QWORD *)(a1 + 1056), 8LL, v13, *(_QWORD *)(a1 + 1592), *(_QWORD *)(a1 + 1600));
}
else
{
v9 = v11(*(_QWORD *)(a1 + 1056), (unsigned int)(__int16)a2, a3, *(_QWORD *)(a1 + 1592), *(_QWORD *)(a1 + 1600));
}
}
if ( v9 == 2 )
{
*(_DWORD *)(a1 + 1072) = 1021;
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 11) > 1 )
*(_DWORD *)(a1 + 1040) = 11;
}
else if ( (v9 & 0xFFFE) != 0 )
{
if ( v9 == 100 )
*(_DWORD *)(a1 + 1664) = 1;
}
else
{
*(_DWORD *)(a1 + 1040) = 6;
}
if ( log_info[4] )
{
v14 = (const char *)_get_return_status((unsigned int)v9, &v15);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v14);
dm_log_write("SQLFetchScroll.c", 349LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v9, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rax
int v5; // eax
__int64 v6; // rax
__int64 v7; // rdx
__int64 (__fastcall *v8)(_QWORD, _QWORD, __int64); // rcx
__int16 v9; // bp
__int64 (__fastcall *v11)(_QWORD, __int64, __int64, _QWORD, _QWORD); // r9
__int64 *v12; // rax
__int64 v13; // rdx
const char *v14; // rax
__int64 v15; // [rsp+0h] [rbp-118h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLFetchScroll.c", 138LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
sprintf(
(char *)(a1 + 16),
"\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tFetch Orentation = %d\n\t\t\tFetch Offset = %d",
(const void *)a1,
(unsigned int)(__int16)a2,
(unsigned int)a3);
dm_log_write("SQLFetchScroll.c", 159LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( (_WORD)a2 != 1 && (_WORD)a2 != 4 )
{
if ( (unsigned __int16)a2 > 8u || (v4 = 364LL, !_bittest64(&v4, a2)) )
{
dm_log_write("SQLFetchScroll.c", 176LL, 0LL, 0LL, "Error: HY106");
_post_internal_error(a1 + 1088, 38LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
}
v5 = *(_DWORD *)(a1 + 1040);
if ( (unsigned int)(v5 - 1) <= 2 )
{
dm_log_write("SQLFetchScroll.c", 197LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v5 == 4 )
{
dm_log_write("SQLFetchScroll.c", 212LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v5 == 7 )
{
dm_log_write("SQLFetchScroll.c", 227LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( (unsigned int)(v5 - 8) <= 2 )
{
dm_log_write("SQLFetchScroll.c", 244LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( (unsigned int)(v5 - 11) <= 1 && *(_DWORD *)(a1 + 1072) != 1021 )
{
dm_log_write("SQLFetchScroll.c", 262LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v6 = *(_QWORD *)(a1 + 1048);
v7 = *(_QWORD *)(v6 + 1320);
v8 = *(__int64 (__fastcall **)(_QWORD, _QWORD, __int64))(v7 + 1952);
if ( v8 )
{
v9 = v8(*(_QWORD *)(a1 + 1056), (unsigned int)(__int16)a2, a3);
}
else
{
if ( *(_DWORD *)(v6 + 1484) != 2
|| (v11 = *(__int64 (__fastcall **)(_QWORD, __int64, __int64, _QWORD, _QWORD))(v7 + 1824)) == 0LL )
{
dm_log_write("SQLFetchScroll.c", 315LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( (_WORD)a2 == 8 )
{
v12 = *(__int64 **)(a1 + 1584);
v13 = 0LL;
if ( v12 )
v13 = *v12;
v9 = v11(*(_QWORD *)(a1 + 1056), 8LL, v13, *(_QWORD *)(a1 + 1592), *(_QWORD *)(a1 + 1600));
}
else
{
v9 = v11(*(_QWORD *)(a1 + 1056), (unsigned int)(__int16)a2, a3, *(_QWORD *)(a1 + 1592), *(_QWORD *)(a1 + 1600));
}
}
if ( v9 == 2 )
{
*(_DWORD *)(a1 + 1072) = 1021;
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 11) > 1 )
*(_DWORD *)(a1 + 1040) = 11;
}
else if ( (v9 & 0xFFFE) != 0 )
{
if ( v9 == 100 )
*(_DWORD *)(a1 + 1664) = 1;
}
else
{
*(_DWORD *)(a1 + 1040) = 6;
}
if ( log_info[4] )
{
v14 = (const char *)_get_return_status((unsigned int)v9, &v15);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v14);
dm_log_write("SQLFetchScroll.c", 349LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v9, 0LL);
}

original_code:
SQLRETURN SQLFetchScroll( SQLHSTMT statement_handle,
           SQLSMALLINT fetch_orientation,
           SQLINTEGER fetch_offset )
{
    DMHSTMT statement = (DMHSTMT) statement_handle;
    SQLRETURN ret;
    SQLCHAR s1[ 100 + 128 ];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLFetchScroll.c",
                    138,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tFetch Orentation = %d\n\t\t\tFetch Offset = %d",
                statement,
                fetch_orientation,
                (int)fetch_offset );
        dm_log_write( "SQLFetchScroll.c",
                159,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( fetch_orientation != 1 &&
            fetch_orientation != 4 &&
            fetch_orientation != 2 &&
            fetch_orientation != 3 &&
            fetch_orientation != 5 &&
            fetch_orientation != 6 &&
            fetch_orientation != 8 )
    {
        dm_log_write( "SQLFetchScroll.c",
                176,
                0,
                0,
                "Error: HY106" );
        __post_internal_error( &statement -> error,
                ERROR_HY106, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 1 ||
            statement -> state == 2 ||
            statement -> state == 3 )
    {
        dm_log_write( "SQLFetchScroll.c",
                197,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 4 )
    {
        dm_log_write( "SQLFetchScroll.c",
                212,
                0,
                0,
                "Error: 24000" );
        __post_internal_error( &statement -> error,
                ERROR_24000, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 7 )
    {
        dm_log_write( "SQLFetchScroll.c",
                227,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 )
    {
        dm_log_write( "SQLFetchScroll.c",
                244,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 11 ||
            statement -> state == 12 )
    {
        if ( statement -> interupted_func != 1021 )
        {
            dm_log_write( "SQLFetchScroll.c",
                    262,
                    0,
                    0,
                    "Error: HY010" );
            __post_internal_error( &statement -> error,
                    ERROR_HY010, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( (statement -> connection->functions[30].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[30].func) (statement -> driver_stmt,fetch_orientation,fetch_offset);
    }
    else if ( statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        SQLINTEGER bm_ptr = 0;
        if ( fetch_orientation == 8 )
        {
            if ( statement -> fetch_bm_ptr )
                bm_ptr = *statement -> fetch_bm_ptr;
            ret = (statement -> connection->functions[28].func) (statement -> driver_stmt,fetch_orientation,bm_ptr,statement -> row_ct_ptr,statement -> row_st_arr);
        }
        else
        {
            ret = (statement -> connection->functions[28].func) (statement -> driver_stmt,fetch_orientation,fetch_offset,statement -> row_ct_ptr,statement -> row_st_arr);
        }
    }
    else
    {
        dm_log_write( "SQLFetchScroll.c",
                315,
                0,
                0,
                "Error: IM001" );
        __post_internal_error( &statement -> error,
                ERROR_IM001, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( ret == 2 )
    {
        statement -> interupted_func = 1021;
        if ( statement -> state != 11 &&
                statement -> state != 12 )
            statement -> state = 11;
    }
    else if ( (((ret)&(~1))==0))
    {
        statement -> state = 6;
    }
    else if ( ret == 100 ) {
        statement -> eod = 1;
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLFetchScroll.c",
                349,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

canonical_original_code:
short SQLFetchScroll(void *statement_handle, short fetch_orientation, long fetch_offset)
{
    struct statement *statement = (DMHSTMT) statement_handle;
    short ret;
    unsigned char s1[-1];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLFetchScroll.c",
                    138,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tFetch Orentation = %d\n\t\t\tFetch Offset = %d",
                statement,
                fetch_orientation,
                (int)fetch_offset );
        dm_log_write( "SQLFetchScroll.c",
                159,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( fetch_orientation != 1 &&
            fetch_orientation != 4 &&
            fetch_orientation != 2 &&
            fetch_orientation != 3 &&
            fetch_orientation != 5 &&
            fetch_orientation != 6 &&
            fetch_orientation != 8 )
    {
        dm_log_write( "SQLFetchScroll.c",
                176,
                0,
                0,
                "Error: HY106" );
        __post_internal_error( &statement -> error,
                ERROR_HY106, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 1 ||
            statement -> state == 2 ||
            statement -> state == 3 )
    {
        dm_log_write( "SQLFetchScroll.c",
                197,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 4 )
    {
        dm_log_write( "SQLFetchScroll.c",
                212,
                0,
                0,
                "Error: 24000" );
        __post_internal_error( &statement -> error,
                ERROR_24000, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 7 )
    {
        dm_log_write( "SQLFetchScroll.c",
                227,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 )
    {
        dm_log_write( "SQLFetchScroll.c",
                244,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 11 ||
            statement -> state == 12 )
    {
        if ( statement -> interupted_func != 1021 )
        {
            dm_log_write( "SQLFetchScroll.c",
                    262,
                    0,
                    0,
                    "Error: HY010" );
            __post_internal_error( &statement -> error,
                    ERROR_HY010, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( (statement -> connection->functions[30].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[30].func) (statement -> driver_stmt,fetch_orientation,fetch_offset);
    }
    else if ( statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        long bm_ptr = 0;
        if ( fetch_orientation == 8 )
        {
            if ( statement -> fetch_bm_ptr )
                bm_ptr = *statement -> fetch_bm_ptr;
            ret = (statement -> connection->functions[28].func) (statement -> driver_stmt,fetch_orientation,bm_ptr,statement -> row_ct_ptr,statement -> row_st_arr);
        }
        else
        {
            ret = (statement -> connection->functions[28].func) (statement -> driver_stmt,fetch_orientation,fetch_offset,statement -> row_ct_ptr,statement -> row_st_arr);
        }
    }
    else
    {
        dm_log_write( "SQLFetchScroll.c",
                315,
                0,
                0,
                "Error: IM001" );
        __post_internal_error( &statement -> error,
                ERROR_IM001, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( ret == 2 )
    {
        statement -> interupted_func = 1021;
        if ( statement -> state != 11 &&
                statement -> state != 12 )
            statement -> state = 11;
    }
    else if ( (((ret)&(~1))==0))
    {
        statement -> state = 6;
    }
    else if ( ret == 100 ) {
        statement -> eod = 1;
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLFetchScroll.c",
                349,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

variable_types: struct statement { int type; struct statement *next_class_list; char msg[1024]; int state; struct connection { int type; struct connection *next_class_list; char msg[1024]; int state; struct environment { int type; struct environment *next_class_list; char msg[1024]; int state; long requested_version; int connection_count; int sql_driver_count; struct error_head { struct error_header { int error_count; struct error { unsigned short sqlstate[6]; unsigned short *msg; long native_error; int return_val; short diag_column_number_ret; short diag_row_number_ret; short diag_class_origin_ret; short diag_subclass_origin_ret; short diag_connection_name_ret; short diag_server_name_ret; long diag_column_number; long diag_row_number; unsigned short diag_class_origin[128]; unsigned short diag_subclass_origin[128]; unsigned short diag_connection_name[128]; unsigned short diag_server_name[128]; struct error *next; struct error *prev; } *error_list_head; struct error *error_list_tail; int internal_count; struct error *internal_list_head; struct error *internal_list_tail; } sql_error_head; struct error_header sql_diag_head; void *owning_handle; int handle_type; short return_code; long header_set; short diag_cursor_row_count_ret; short diag_dynamic_function_ret; short diag_dynamic_function_code_ret; short diag_number_ret; short diag_row_count_ret; long diag_cursor_row_count; unsigned short diag_dynamic_function[128]; long diag_dynamic_function_code; long diag_number; long diag_row_count; } error; long connection_pooling; long cp_match; int fetch_mode; int entry; void *sh; struct env_lib_struct { char *lib_name; void *env_handle; int count; struct env_lib_struct *next; } *env_lib_list; } *environment; void *dl_handle; char dl_name[256]; struct driver_func { int ordinal; char *name; void *dm_func; void *dm_funcW; short (*func)(); short (*funcW)(); short (*funcA)(); int can_supply; } *functions; struct driver_func ini_func; struct driver_func fini_func; int unicode_driver; void *driver_env; void *driver_dbc; int driver_version; int driver_act_ver; int statement_count; struct error_head error; char dsn[-1]; int access_mode; int access_mode_set; int login_timeout; int login_timeout_set; int auto_commit; int auto_commit_set; int async_enable; int async_enable_set; int auto_ipd; int auto_ipd_set; int connection_timeout; int connection_timeout_set; int metadata_id; int metadata_id_set; int packet_size; int packet_size_set; long quite_mode; int quite_mode_set; int txn_isolation; int txn_isolation_set; long cursors; void *cl_handle; int trace; char tracefile[-1]; 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; int protection_level; int ex_fetch_mapping; int disable_gf; int dont_dlclose; int bookmarks_on; void *pooled_connection; int pooling_timeout; int ttl; char driver_connect_string[1024]; int dsn_length; char server[128]; int server_length; char user[128]; int user_length; char password[128]; int password_length; char cli_year[5]; struct attr_struct { int count; struct attr_set { char *keyword; char *value; int override; int attribute; int is_int_type; int int_value; struct attr_set *next; } *list; } env_attribute; struct attr_struct dbc_attribute; struct attr_struct stmt_attribute; struct save_attr { int attr_type; char *str_attr; int str_len; int int_attr; struct save_attr *next; } *save_attr; void *iconv_cd_uc_to_ascii; void *iconv_cd_ascii_to_uc; char unicode_string[64]; struct env_lib_struct *env_list_ent; char probe_sql[512]; int threading_level; int cbs_found; short ccb_value; short crb_value; } *connection; void *driver_stmt; short hascols; int prepared; int interupted_func; int interupted_state; int bookmarks_on; struct error_head error; long metadata_id; struct descriptor { int type; struct descriptor *next_class_list; char msg[1024]; int state; struct error_head error; void *driver_desc; struct connection *connection; int implicit; void *associated_with; union pthread_mutex_t mutex; } *ipd; struct descriptor *apd; struct descriptor *ird; struct descriptor *ard; struct descriptor *implicit_ipd; struct descriptor *implicit_apd; struct descriptor *implicit_ird; struct descriptor *implicit_ard; unsigned long *fetch_bm_ptr; unsigned long *row_ct_ptr; unsigned short *row_st_arr; unsigned long row_array_size; void *valueptr; union pthread_mutex_t mutex; int eod; } *

variable_types: ret short

user_defined_types: struct statement { int type; struct statement *next_class_list; char msg[1024]; int state; struct connection *connection; void *driver_stmt; short hascols; int prepared; int interupted_func; int interupted_state; int bookmarks_on; struct error_head error; long metadata_id; struct descriptor *ipd; struct descriptor *apd; struct descriptor *ird; struct descriptor *ard; struct descriptor *implicit_ipd; struct descriptor *implicit_apd; struct descriptor *implicit_ird; struct descriptor *implicit_ard; unsigned long *fetch_bm_ptr; unsigned long *row_ct_ptr; unsigned short *row_st_arr; unsigned long row_array_size; void *valueptr; union pthread_mutex_t mutex; int eod; }

user_defined_types: struct connection { int type; struct connection *next_class_list; char msg[1024]; int state; struct environment *environment; void *dl_handle; char dl_name[256]; struct driver_func *functions; struct driver_func ini_func; struct driver_func fini_func; int unicode_driver; void *driver_env; void *driver_dbc; int driver_version; int driver_act_ver; int statement_count; struct error_head error; char dsn[-1]; int access_mode; int access_mode_set; int login_timeout; int login_timeout_set; int auto_commit; int auto_commit_set; int async_enable; int async_enable_set; int auto_ipd; int auto_ipd_set; int connection_timeout; int connection_timeout_set; int metadata_id; int metadata_id_set; int packet_size; int packet_size_set; long quite_mode; int quite_mode_set; int txn_isolation; int txn_isolation_set; long cursors; void *cl_handle; int trace; char tracefile[-1]; union pthread_mutex_t mutex; int protection_level; int ex_fetch_mapping; int disable_gf; int dont_dlclose; int bookmarks_on; void *pooled_connection; int pooling_timeout; int ttl; char driver_connect_string[1024]; int dsn_length; char server[128]; int server_length; char user[128]; int user_length; char password[128]; int password_length; char cli_year[5]; struct attr_struct env_attribute; struct attr_struct dbc_attribute; struct attr_struct stmt_attribute; struct save_attr *save_attr; void *iconv_cd_uc_to_ascii; void *iconv_cd_ascii_to_uc; char unicode_string[64]; struct env_lib_struct *env_list_ent; char probe_sql[512]; int threading_level; int cbs_found; short ccb_value; short crb_value; }

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

user_defined_types: struct attr_struct { int count; struct attr_set *list; }

user_defined_types: struct environment { int type; struct environment *next_class_list; char msg[1024]; int state; long requested_version; int connection_count; int sql_driver_count; struct error_head error; long connection_pooling; long cp_match; int fetch_mode; int entry; void *sh; struct env_lib_struct *env_lib_list; }

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 error_head { struct error_header sql_error_head; struct error_header sql_diag_head; void *owning_handle; int handle_type; short return_code; long header_set; short diag_cursor_row_count_ret; short diag_dynamic_function_ret; short diag_dynamic_function_code_ret; short diag_number_ret; short diag_row_count_ret; long diag_cursor_row_count; unsigned short diag_dynamic_function[128]; long diag_dynamic_function_code; long diag_number; long diag_row_count; }

user_defined_types: struct error_header { int error_count; struct error *error_list_head; struct error *error_list_tail; int internal_count; struct error *internal_list_head; struct error *internal_list_tail; }


SQLReadFileDSNW

decompiled_code:
__int64 __fastcall SQLReadFileDSNW(char *src, void *ptr, void *a3, __int64 a4, unsigned __int16 a5, _WORD *a6)
{
char *v6; // rbx
void *v7; // rbp
unsigned int v11; // er14
char *v12; // r15
__int16 v15[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v6 = src;
v7 = ptr;
inst_logClear();
if ( src )
v6 = (char *)single_string_alloc_and_copy(src);
if ( ptr )
v7 = (void *)single_string_alloc_and_copy(ptr);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a5 && a4 )
{
v12 = (char *)calloc(a5 + 1, 1uLL);
v11 = SQLReadFileDSN(v6, (__int64)v7, (__int64)a3, v12, a5, v15);
if ( v11 && v12 )
single_copy_to_wide(a4, v12, (unsigned int)(unsigned __int16)v15[0] + 1);
}
else
{
v11 = SQLReadFileDSN(v6, (__int64)v7, (__int64)a3, 0LL, a5, v15);
v12 = 0LL;
}
if ( v6 )
free(v6);
if ( v7 )
free(v7);
if ( a3 )
free(a3);
if ( v12 )
free(v12);
if ( a6 )
*a6 = v15[0];
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, void *ptr, void *a3, __int64 a4, unsigned __int16 a5, _WORD *a6)
{
char *v6; // rbx
void *v7; // rbp
unsigned int v11; // er14
char *v12; // r15
__int16 v15[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v6 = src;
v7 = ptr;
inst_logClear();
if ( src )
v6 = (char *)single_string_alloc_and_copy(src);
if ( ptr )
v7 = (void *)single_string_alloc_and_copy(ptr);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a5 && a4 )
{
v12 = (char *)calloc(a5 + 1, 1uLL);
v11 = func2(v6, (__int64)v7, (__int64)a3, v12, a5, v15);
if ( v11 && v12 )
single_copy_to_wide(a4, v12, (unsigned int)(unsigned __int16)v15[0] + 1);
}
else
{
v11 = func2(v6, (__int64)v7, (__int64)a3, 0LL, a5, v15);
v12 = 0LL;
}
if ( v6 )
free(v6);
if ( v7 )
free(v7);
if ( a3 )
free(a3);
if ( v12 )
free(v12);
if ( a6 )
*a6 = v15[0];
return v11;
}

original_code:
int SQLReadFileDSNW(LPCWSTR lpszFileName,
                              LPCWSTR lpszAppName,
                              LPCWSTR lpszKeyName,
                              LPWSTR lpszString,
                              WORD cbString,
                              WORD *pcbString)
{
    char *file;
    char *app;
    char *key;
    char *str;
    WORD len;
    int ret;
    inst_logClear();
    file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char*)((void *)0);
    app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char*)((void *)0);
    key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char*)((void *)0);
    if ( lpszString )
    {
        if ( cbString > 0 )
        {
            str = calloc( cbString + 1, 1 );
        }
        else
        {
            str = ((void *)0);
        }
    }
    else
    {
        str = ((void *)0);
    }
    ret = SQLReadFileDSN( file, app, key, str, cbString, &len );
    if ( ret )
    {
        if ( str && lpszString )
        {
            _single_copy_to_wide( lpszString, str, len + 1 );
        }
    }
    if ( file )
        free( file );
    if ( app )
        free( app );
    if ( key )
        free( key );
    if ( str )
        free( str );
    if ( pcbString )
        *pcbString = len;
    return ret;
}

canonical_original_code:
int SQLReadFileDSNW(unsigned short *lpszFileName, unsigned short *lpszAppName, unsigned short *lpszKeyName, unsigned short *lpszString, unsigned short cbString, unsigned short *pcbString)
{
    char *file;
    char *app;
    char *key;
    char *str;
    unsigned short len;
    int ret;
    inst_logClear();
    file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char *)((void *)0);
    app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char *)((void *)0);
    key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char *)((void *)0);
    if ( lpszString )
    {
        if ( cbString > 0 )
        {
            str = calloc( cbString + 1, 1 );
        }
        else
        {
            str = ((void *)0);
        }
    }
    else
    {
        str = ((void *)0);
    }
    ret = SQLReadFileDSN( file, app, key, str, cbString, &len );
    if ( ret )
    {
        if ( str && lpszString )
        {
            _single_copy_to_wide( lpszString, str, len + 1 );
        }
    }
    if ( file )
        free( file );
    if ( app )
        free( app );
    if ( key )
        free( key );
    if ( str )
        free( str );
    if ( pcbString )
        *pcbString = len;
    return ret;
}

variable_types:
lpszFileName
unsigned short *

variable_types:
lpszAppName
unsigned short *

variable_types:
cbString
unsigned short

variable_types:
pcbString
unsigned short *

variable_types:
len
unsigned short


SQLSetCursorName

decompiled_code:
__int64 __fastcall SQLSetCursorName(__int64 a1, const char *a2, __int16 a3)
{
__int64 result; // rax

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSetCursorName.c", "SQLSetCursorName.c", 27LL, 1LL, 1LL, a1 + 136);
if ( a2 && ((*_ctype_b_loc())[*(unsigned __int8 *)a2] & 0x400) != 0 )
{
if ( a3 == -3 )
strncpy((char *)(a1 + 24), a2, 0x64uLL);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSetCursorName.c", "SQLSetCursorName.c", 48LL, 0LL, 0LL, "SQL_SUCCESS");
result = 0LL;
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLSetCursorName.c",
"SQLSetCursorName.c",
31LL,
1LL,
1LL,
"SQL_ERROR Invalid cursor name");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, __int16 a3)
{
__int64 result; // rax

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSetCursorName.c", "SQLSetCursorName.c", 27LL, 1LL, 1LL, a1 + 136);
if ( a2 && ((*_ctype_b_loc())[*(unsigned __int8 *)a2] & 0x400) != 0 )
{
if ( a3 == -3 )
strncpy((char *)(a1 + 24), a2, 0x64uLL);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSetCursorName.c", "SQLSetCursorName.c", 48LL, 0LL, 0LL, "SQL_SUCCESS");
result = 0LL;
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLSetCursorName.c",
"SQLSetCursorName.c",
31LL,
1LL,
1LL,
"SQL_ERROR Invalid cursor name");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
RETCODE SQLSetCursorName(
        HSTMT hstmt,
        UCHAR *szCursor,
        SWORD cbCursor)
{
static char* const func="SQLSetCursorName";
StatementClass *stmt = (StatementClass *) hstmt;
int len;
mylog("SQLSetCursorName: hstmt=%u, szCursor=%u, cbCursorMax=%d\n", hstmt, szCursor, cbCursor);
 if ( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 len = (cbCursor == (-3)) ? strlen((char*)szCursor) : cbCursor;
 if (len <= 0 || len > sizeof(stmt->cursor_name) - 1) {
  SC_set_error(stmt, 19, "Invalid Cursor Name");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 strncpy_null((char*)stmt->cursor_name, (char*)szCursor, len+1);
 return 0;
}

canonical_original_code:
short SQLSetCursorName(void *hstmt, unsigned char *szCursor, short cbCursor)
{
static char *func = "SQLSetCursorName";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
int len;
mylog("SQLSetCursorName: hstmt=%u, szCursor=%u, cbCursorMax=%d\n", hstmt, szCursor, cbCursor);
 if ( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 len = (cbCursor == (-3)) ? strlen((char *)szCursor) : cbCursor;
 if (len <= 0 || len > sizeof(stmt->cursor_name) - 1) {
  SC_set_error(stmt, 19, "Invalid Cursor Name");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 strncpy_null((char *)stmt->cursor_name, (char *)szCursor, len+1);
 return 0;
}

variable_types:
hstmt
void *

variable_types:
szCursor
unsigned char *

variable_types: cbCursor short

variable_types:
func
char *

variable_types: struct StatementClass_ { struct ConnectionClass_ { void *henv; struct StatementOptions_ { int maxRows; int maxLength; int rowset_size; int keyset_size; int cursor_type; int scroll_concurrency; int retrieve_data; int bind_size; int use_bookmarks; } stmtOptions; char *__error_message; int __error_number; enum CONN_Status { CONN_NOT_CONNECTED=0, CONN_CONNECTED=1, CONN_DOWN=2, CONN_EXECUTING=3 } status; struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; } connInfo; struct StatementClass_ **stmts; int num_stmts; struct SocketClass_ { int buffer_filled_in; int buffer_filled_out; int buffer_read_in; unsigned char *buffer_in; unsigned char *buffer_out; int socket; char *errormsg; int errornumber; char reverse; } *sock; int lobj_type; int ntables; struct col_info { struct QResultClass_ { struct ColumnInfoClass_ { short num_fields; char **name; unsigned int *adtid; short *adtsize; short *display_size; int *atttypmod; } *fields; struct TupleListClass_ { int num_fields; int num_tuples; struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ { int len; void *value; } tuple[1]; } *list_start; int last_indexed; } *manual_tuples; struct ConnectionClass_ *conn; int fetch_count; int fcount; int currTuple; int base; int num_fields; int cache_size; int rowset_size; enum QueryResultCode_ { PGRES_EMPTY_QUERY=0, PGRES_COMMAND_OK=1, PGRES_TUPLES_OK=2, PGRES_COPY_OUT=3, PGRES_COPY_IN=4, PGRES_BAD_RESPONSE=5, PGRES_NONFATAL_ERROR=6, PGRES_FATAL_ERROR=7, PGRES_FIELDS_OK=8, PGRES_END_TUPLES=9, PGRES_INTERNAL_ERROR=10 } status; char *message; char *cursor; char *command; char *notice; struct TupleField_ *backend_tuples; struct TupleField_ *tupleField; char inTuples; char aborted; } *result; char name[-1]; } **col_info; long translation_option; void *translation_handle; int (*DataSourceToDriver)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); int (*DriverToDataSource)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); short driver_version; char transact_status; char errormsg_created; char pg_version[128]; float pg_version_number; short pg_version_major; short pg_version_minor; char ms_jet; char unicode; char result_uncommitted; char schema_support; char *client_encoding; char *server_encoding; int ccsc; int be_pid; int be_key; unsigned int isolation; char *current_schema; int num_discardp; char **discardp; } *hdbc; struct QResultClass_ *result; void **phstmt; struct StatementOptions_ options; enum STMT_Status { STMT_ALLOCATED=0, STMT_READY=1, STMT_PREMATURE=2, STMT_FINISHED=3, STMT_EXECUTING=4 } status; char *__error_message; int __error_number; struct BindInfoClass_ { int buflen; int data_left; char *buffer; long *used; short returntype; } *bindings; struct BindInfoClass_ bookmark; int bindings_allocated; int parameters_allocated; struct ParameterInfoClass_ { int buflen; char *buffer; long *used; short paramType; short CType; short SQLType; unsigned int precision; short scale; unsigned int lobj_oid; int *EXEC_used; char *EXEC_buffer; char data_at_exec; } *parameters; int currTuple; int save_rowset_size; int rowset_start; int bind_row; int last_fetch_count; int current_col; int lobj_fd; char *statement; struct TABLE_INFO { struct col_info *col_info; char name[-1]; char alias[-1]; } **ti; struct FIELD_INFO { struct TABLE_INFO *ti; int precision; int display_size; int length; int type; char nullable; char func; char expr; char quote; char dquote; char numeric; char dot[-1]; char name[-1]; char alias[-1]; } **fi; int nfld; int ntab; int parse_status; int statement_type; int data_at_exec; int current_exec_param; char put_data; char errormsg_created; char manual_result; char prepare; char internal; char cursor_name[-1]; char stmt_with_params[65536]; int reexecute; } *

variable_types: len int

user_defined_types: struct StatementClass_ { struct ConnectionClass_ *hdbc; struct QResultClass_ *result; void **phstmt; struct StatementOptions_ options; enum STMT_Status status; char *__error_message; int __error_number; struct BindInfoClass_ *bindings; struct BindInfoClass_ bookmark; int bindings_allocated; int parameters_allocated; struct ParameterInfoClass_ *parameters; int currTuple; int save_rowset_size; int rowset_start; int bind_row; int last_fetch_count; int current_col; int lobj_fd; char *statement; struct TABLE_INFO **ti; struct FIELD_INFO **fi; int nfld; int ntab; int parse_status; int statement_type; int data_at_exec; int current_exec_param; char put_data; char errormsg_created; char manual_result; char prepare; char internal; char cursor_name[-1]; char stmt_with_params[65536]; int reexecute; }

user_defined_types: struct ConnectionClass_ { void *henv; struct StatementOptions_ stmtOptions; char *__error_message; int __error_number; enum CONN_Status status; struct ConnInfo connInfo; struct StatementClass_ **stmts; int num_stmts; struct SocketClass_ *sock; int lobj_type; int ntables; struct col_info **col_info; long translation_option; void *translation_handle; int (*DataSourceToDriver)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); int (*DriverToDataSource)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); short driver_version; char transact_status; char errormsg_created; char pg_version[128]; float pg_version_number; short pg_version_major; short pg_version_minor; char ms_jet; char unicode; char result_uncommitted; char schema_support; char *client_encoding; char *server_encoding; int ccsc; int be_pid; int be_key; unsigned int isolation; char *current_schema; int num_discardp; char **discardp; }