LocalConvertSDToStringSD_Rev1
NTSTATUS __stdcall LocalConvertSDToStringSD_Rev1(
VOID *SecurityDescriptor,
VOID *SecurityInformation,
WCHAR **StringSecurityDescriptor,
VOID *StringSecurityDescriptorLen,
UINT64 StringSecurityDescriptora,
WCHAR **StringSecurityDescriptorLena,
UINT64 *a7){
NTSTATUS StringForSid;
NTSTATUS OwnerSecurityDescriptor;
unsigned int v10;
VOID *v11;
VOID *RootDomainSid;
_ACL *v13;
__int16 v14;
unsigned int v15;
NTSTATUS SaclSecurityDescriptor;
UINT64 v17;
VOID *v18;
unsigned __int16 v19;
char v20;
unsigned __int8 v21;
WCHAR *v22;
__int64 v23;
PVOID v24;
WCHAR *v25;
__int64 v26;
WCHAR *v27;
unsigned __int64 v28;
__int64 v29;
UINT64 v30;
WCHAR *v31;
WCHAR **v32;
__int64 v33;
__int64 v34;
UINT8 v36;
UINT64 v37;
_ACL *v38;
NTSTATUS v39;
NTSTATUS v40;
__int64 v41;
__int64 v42;
__int64 v43;
__int64 v44;
UINT64 v45;
WCHAR *v46;
__int64 v47;
_STRSD_SID_LOOKUP *AclStringSize;
UINT64 Length;
PVOID v50;
PVOID v51;
WCHAR *ControlString;
PVOID P;
PACL Sacl;
WCHAR *String;
PWCHAR Src;
WCHAR *AclString;
PVOID Owner;
VOID *Group;
PACL Dacl;
UINT64 DaclDefaulted;
VOID *SaclPresent;
unsigned __int8 DaclPresent;
unsigned __int16 Control;
SaclPresent = SecurityInformation;
LODWORD(Length) = 0;
StringForSid = 0;
Owner = 0i64;
OwnerSecurityDescriptor = 0;
Group = 0i64;
v10 = 0;
Dacl = 0i64;
v11 = 0i64;
Sacl = 0i64;
RootDomainSid = 0i64;
P = 0i64;
v13 = 0i64;
LOBYTE(SaclPresent) = 0;
DaclPresent = 0;
String = 0i64;
v50 = 0i64;
Src = 0i64;
AclString = 0i64;
Control = 0;
ControlString = 0i64;
v51 = 0i64;
if( !StringSecurityDescriptorLen || !StringSecurityDescriptorLena )
return 87;
v14 = StringSecurityDescriptora;
if( (StringSecurityDescriptora & 1) != 0 )
{
OwnerSecurityDescriptor = RtlGetOwnerSecurityDescriptor(
StringSecurityDescriptorLen,
&Owner,
(UINT8 *)&DaclDefaulted);
if( OwnerSecurityDescriptor < 0 )
goto LABEL_68;
v11 = Owner;
}
if( (v14 & 2) != 0 )
{
OwnerSecurityDescriptor = RtlGetGroupSecurityDescriptor(
StringSecurityDescriptorLen,
&Group,
(UINT8 *)&DaclDefaulted);
RootDomainSid = Group;
}
if( OwnerSecurityDescriptor < 0 )
goto LABEL_68;
if( (v14 & 4) != 0 )
OwnerSecurityDescriptor = RtlGetDaclSecurityDescriptor(
StringSecurityDescriptorLen,
&DaclPresent,
&Dacl,
(UINT8 *)&DaclDefaulted);
if( OwnerSecurityDescriptor < 0 )
goto LABEL_68;
v15 = v14 & 0x1F8;
if( v15 )
{
SaclSecurityDescriptor = RtlGetSaclSecurityDescriptor(
StringSecurityDescriptorLen,
(UINT8 *)&SaclPresent,
&Sacl,
(UINT8 *)&DaclDefaulted);
if( SaclSecurityDescriptor < 0 )
return RtlNtStatusToDosError((unsigned int)SaclSecurityDescriptor);
v13 = Sacl;
if( (_BYTE)SaclPresent )
{
if( Sacl )
{
SddlFilterSacl(Sacl, 0i64, &Length, v15);
v38 = (_ACL *)SddlpAlloc((unsigned int)Length, v36, v37);
P = v38;
if( !v38 )
{
OwnerSecurityDescriptor = -1073741801;
goto LABEL_68;
}
SddlFilterSacl(v13, v38, &Length, v15);
v13 = (_ACL *)P;
}
}
}
OwnerSecurityDescriptor = RtlGetControlSecurityDescriptor(StringSecurityDescriptorLen, &Control, &DaclDefaulted);
if( OwnerSecurityDescriptor < 0 )
{
LABEL_68:
v39 = RtlNtStatusToDosError((unsigned int)OwnerSecurityDescriptor);
if( P )
ExFreePoolWithTag(P, 0);
return v39;
}
if( v11 )
{
StringForSid = LocalGetStringForSid(v11, &String, 0i64, v18, AclStringSize, 1u);
if( StringForSid )
goto LABEL_46;
}
if( RootDomainSid )
{
v40 = LocalGetStringForSid(RootDomainSid, (WCHAR **)&v50, 0i64, v18, AclStringSize, 1u);
RootDomainSid = 0i64;
StringForSid = v40;
if( v40 )
goto LABEL_46;
}
v19 = Control;
if( Control )
{
StringForSid = LocalGetStringForControl(Control, 1ui64, &ControlString);
if( StringForSid )
goto LABEL_46;
StringForSid = LocalGetStringForControl(v19, 2ui64, (WCHAR **)&v51);
if( StringForSid )
goto LABEL_46;
}
v20 = (char)SaclPresent;
if( (_BYTE)SaclPresent )
{
StringForSid = LocalConvertAclToString(
v13,
(UINT8)SaclPresent,
0,
&Src,
&Length,
RootDomainSid,
RootDomainSid,
(UINT8)RootDomainSid);
if( StringForSid )
goto LABEL_46;
v10 = Length;
}
v21 = DaclPresent;
if( DaclPresent )
{
StringForSid = LocalConvertAclToString(
Dacl,
DaclPresent,
1u,
&AclString,
&Length,
RootDomainSid,
RootDomainSid,
(UINT8)RootDomainSid);
if( StringForSid )
goto LABEL_46;
v10 += Length;
v21 = DaclPresent;
}
v22 = String;
v23 = -1i64;
if( String )
{
v41 = -1i64;
do
++v41;
while( String[v41] != (_WORD)RootDomainSid );
v10 += 2 * v41 + 4;
}
v24 = v50;
if( v50 )
{
v42 = -1i64;
do
++v42;
while( *((_WORD *)v50 + v42) != (_WORD)RootDomainSid );
v10 += 2 * v42 + 4;
}
v25 = ControlString;
if( v21 )
{
v10 += 4;
if( ControlString )
{
v26 = -1i64;
do
++v26;
while( ControlString[v26] );
v10 += 2 * v26;
}
}
if( v20 )
{
v10 += 4;
if( v51 )
{
v43 = -1i64;
do
++v43;
while( *((_WORD *)v51 + v43) );
v10 += 2 * v43;
}
}
v27 = (WCHAR *)SddlpAlloc(v10 + 2i64, 0, v17);
*StringSecurityDescriptorLena = v27;
if( !v27 )
{
StringForSid = 8;
goto LABEL_47;
}
v28 = ((unsigned __int64)v10 + 2) >> 1;
LODWORD(v29) = 0;
if( v22 )
{
LODWORD(AclStringSize) = 58;
swprintf_s(v27, v28, (WCHAR *)L"%ws%wc%ws", L"O", AclStringSize, v22);
v29 = -1i64;
v27 = *StringSecurityDescriptorLena;
do
++v29;
while( v27[v29] );
}
if( v50 )
{
LODWORD(AclStringSize) = 58;
swprintf_s(&v27[(unsigned int)v29], v28 - (unsigned int)v29, (WCHAR *)L"%ws%wc%ws", L"G", AclStringSize, v50);
v27 = *StringSecurityDescriptorLena;
v44 = -1i64;
do
++v44;
while( (*StringSecurityDescriptorLena)[(unsigned int)v29 + v44] );
LODWORD(v29) = v44 + v29;
}
if( DaclPresent )
{
v30 = v28 - (unsigned int)v29;
v31 = &v27[(unsigned int)v29];
LODWORD(AclStringSize) = 58;
if( v25 )
swprintf_s(v31, v30, (WCHAR *)L"%ws%wc%ws", L"D", AclStringSize, v25);
else
swprintf_s(v31, v30, (WCHAR *)L"%ws%wc", L"D", AclStringSize);
v32 = StringSecurityDescriptorLena;
v33 = -1i64;
v27 = *StringSecurityDescriptorLena;
do
++v33;
while( (*StringSecurityDescriptorLena)[(unsigned int)v29 + v33] );
v29 = (unsigned int)(v33 + v29);
if( AclString )
{
wcscpy_s(&v27[v29], v28 - (unsigned int)v29, AclString);
v27 = *v32;
v34 = -1i64;
do
++v34;
while( (*v32)[v29 + v34] );
LODWORD(v29) = v34 + v29;
}
}
else
{
v32 = StringSecurityDescriptorLena;
}
if( (_BYTE)SaclPresent )
{
v45 = v28 - (unsigned int)v29;
v46 = &v27[(unsigned int)v29];
LODWORD(AclStringSize) = 58;
if( v51 )
swprintf_s(v46, v45, (WCHAR *)L"%ws%wc%ws", L"S", AclStringSize, v51);
else
swprintf_s(v46, v45, (WCHAR *)L"%ws%wc", L"S", AclStringSize);
do
++v23;
while( (*v32)[(unsigned int)v29 + v23] );
v47 = (unsigned int)(v23 + v29);
if( Src )
wcscpy_s(&(*v32)[v47], v28 - (unsigned int)v47, Src);
}
if( a7 )
*(_DWORD *)a7 = v10 >> 1;
LABEL_46:
v24 = v50;
LABEL_47:
if( String )
ExFreePoolWithTag(String, 0);
if( v24 )
ExFreePoolWithTag(v24, 0);
if( Src )
ExFreePoolWithTag(Src, 0);
if( AclString )
ExFreePoolWithTag(AclString, 0);
if( v51 )
ExFreePoolWithTag(v51, 0);
if( ControlString )
ExFreePoolWithTag(ControlString, 0);
if( P )
ExFreePoolWithTag(P, 0);
return StringForSid;
}Referenced by:
SeConvertSecurityDescriptorToStringSecurityDescriptor