2014-04-06 18:31:53 +00:00
|
|
|
/* Benjamin DELPY `gentilkiwi`
|
|
|
|
http://blog.gentilkiwi.com
|
|
|
|
benjamin@gentilkiwi.com
|
2015-08-25 09:19:01 +00:00
|
|
|
Licence : https://creativecommons.org/licenses/by/4.0/
|
2014-04-06 18:31:53 +00:00
|
|
|
*/
|
|
|
|
#include "kull_m_asn1.h"
|
|
|
|
|
2016-07-16 23:46:14 +00:00
|
|
|
void kull_m_asn1_BitStringFromULONG(BerElement * pBer, ULONG data)
|
2014-04-06 18:31:53 +00:00
|
|
|
{
|
2016-07-16 23:46:14 +00:00
|
|
|
BYTE flagBuffer[5] = {0};
|
|
|
|
*(PDWORD) (flagBuffer + 1) = _byteswap_ulong(data);
|
|
|
|
ber_printf(pBer, "X", flagBuffer, sizeof(flagBuffer));
|
2014-04-06 18:31:53 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 23:46:14 +00:00
|
|
|
void kull_m_asn1_GenTime(BerElement * pBer, PFILETIME localtime)
|
2014-04-06 18:31:53 +00:00
|
|
|
{
|
|
|
|
SYSTEMTIME st;
|
|
|
|
char buffer[4 + 2 + 2 + 2 + 2 + 2 + 1 + 1];
|
|
|
|
if(FileTimeToSystemTime(localtime, &st))
|
2016-07-16 23:46:14 +00:00
|
|
|
if(sprintf_s(buffer, sizeof(buffer), "%04hu%02hu%02hu%02hu%02hu%02huZ", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond) > 0)
|
|
|
|
ber_printf(pBer, "to", DIRTY_ASN1_ID_GENERALIZED_TIME, buffer, sizeof(buffer) - 1);
|
2014-04-06 18:31:53 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 23:46:14 +00:00
|
|
|
void kull_m_asn1_GenString(BerElement * pBer, PCUNICODE_STRING String)
|
2014-04-06 18:31:53 +00:00
|
|
|
{
|
|
|
|
ANSI_STRING aString;
|
|
|
|
if(NT_SUCCESS(RtlUnicodeStringToAnsiString(&aString, String, TRUE)))
|
|
|
|
{
|
2016-07-16 23:46:14 +00:00
|
|
|
ber_printf(pBer, "to", DIRTY_ASN1_ID_GENERAL_STRING, aString.Buffer, aString.Length);
|
2014-04-06 18:31:53 +00:00
|
|
|
RtlFreeAnsiString(&aString);
|
|
|
|
}
|
|
|
|
}
|