mirror of
https://github.com/gentilkiwi/mimikatz
synced 2024-12-13 17:45:13 +00:00
b008188f9f
[new] mimikatz & mimilib **very** experimental support for ARM64 [better] code for Mifare protocol [better] code for sekurlsa WinDBG plugin (credential keys, still not good enough) [new] mimilib sub authentication package for @vletoux with 'bad password knocking' and magic password [new] mimikatz: unmarshalling usernames when marshalled [fix] mimikatz SR98/RDM/Busylight could previously crash [fix #184] again and again ;) [fix #172] swscanf_s VS ARRAYSIZE macro [fix #127] stdout/stdin/stderr vs modern Visual Studio and Windows XP support (thank you @Crypt0-M3lon) [code] refactor for defined / !defined
121 lines
2.9 KiB
C
121 lines
2.9 KiB
C
/* Benjamin DELPY `gentilkiwi`
|
|
http://blog.gentilkiwi.com
|
|
benjamin@gentilkiwi.com
|
|
Licence : https://creativecommons.org/licenses/by/4.0/
|
|
*/
|
|
#include "kull_m_output.h"
|
|
|
|
FILE * logfile = NULL;
|
|
#if !defined(MIMIKATZ_W2000_SUPPORT)
|
|
wchar_t * outputBuffer = NULL;
|
|
size_t outputBufferElements = 0, outputBufferElementsPosition = 0;
|
|
#endif
|
|
|
|
void kprintf(PCWCHAR format, ...)
|
|
{
|
|
#if !defined(MIMIKATZ_W2000_SUPPORT)
|
|
int varBuf;
|
|
size_t tempSize;
|
|
wchar_t * tmpBuffer;
|
|
#endif
|
|
va_list args;
|
|
va_start(args, format);
|
|
#if !defined(MIMIKATZ_W2000_SUPPORT)
|
|
if(outputBuffer)
|
|
{
|
|
varBuf = _vscwprintf(format, args);
|
|
if(varBuf > 0)
|
|
{
|
|
if((size_t) varBuf > (outputBufferElements - outputBufferElementsPosition - 1)) // NULL character
|
|
{
|
|
tempSize = (outputBufferElements + varBuf + 1) * 2; // * 2, just to be cool
|
|
if(tmpBuffer = (wchar_t *) LocalAlloc(LPTR, tempSize * sizeof(wchar_t)))
|
|
{
|
|
RtlCopyMemory(tmpBuffer, outputBuffer, outputBufferElementsPosition * sizeof(wchar_t));
|
|
LocalFree(outputBuffer);
|
|
outputBuffer = tmpBuffer;
|
|
outputBufferElements = tempSize;
|
|
}
|
|
else wprintf(L"Erreur LocalAlloc: %u\n", GetLastError());
|
|
//if(outputBuffer = (wchar_t *) LocalReAlloc(outputBuffer, tempSize * sizeof(wchar_t), LPTR))
|
|
// outputBufferElements = tempSize;
|
|
//else wprintf(L"Erreur ReAlloc: %u\n", GetLastError());
|
|
}
|
|
varBuf = vswprintf_s(outputBuffer + outputBufferElementsPosition, outputBufferElements - outputBufferElementsPosition, format, args);
|
|
if(varBuf > 0)
|
|
outputBufferElementsPosition += varBuf;
|
|
}
|
|
}
|
|
#endif
|
|
#if !defined(_POWERKATZ)
|
|
#if !defined(MIMIKATZ_W2000_SUPPORT)
|
|
else
|
|
#endif
|
|
{
|
|
vwprintf(format, args);
|
|
fflush(stdout);
|
|
}
|
|
#endif
|
|
if(logfile)
|
|
{
|
|
vfwprintf(logfile, format, args);
|
|
fflush(logfile);
|
|
}
|
|
va_end(args);
|
|
}
|
|
|
|
void kprintf_inputline(PCWCHAR format, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, format);
|
|
if(logfile)
|
|
{
|
|
vfwprintf(logfile, format, args);
|
|
fflush(logfile);
|
|
}
|
|
va_end(args);
|
|
}
|
|
|
|
BOOL kull_m_output_file(PCWCHAR file)
|
|
{
|
|
BOOL status = FALSE;
|
|
FILE * newlog = NULL;
|
|
|
|
if(file)
|
|
#pragma warning(push)
|
|
#pragma warning(disable:4996)
|
|
newlog = _wfopen(file, L"a"); // XP does not like _wfopen_s
|
|
#pragma warning(pop)
|
|
if(newlog || !file)
|
|
{
|
|
if(logfile)
|
|
fclose(logfile);
|
|
logfile = newlog;
|
|
}
|
|
return (!file || (file && logfile));
|
|
}
|
|
|
|
int previousStdOut, previousStdErr;
|
|
UINT previousConsoleOutput;
|
|
void kull_m_output_init()
|
|
{
|
|
#if !defined(_POWERKATZ)
|
|
#if !defined(_WINDLL)
|
|
previousStdOut = _setmode(_fileno(stdout), _O_U8TEXT);
|
|
previousStdErr = _setmode(_fileno(stderr), _O_U8TEXT);
|
|
#endif
|
|
previousConsoleOutput = GetConsoleOutputCP();
|
|
SetConsoleOutputCP(CP_UTF8);
|
|
#endif
|
|
}
|
|
|
|
void kull_m_output_clean()
|
|
{
|
|
#if !defined(_POWERKATZ)
|
|
#if !defined(_WINDLL)
|
|
_setmode(_fileno(stdout), previousStdOut);
|
|
_setmode(_fileno(stderr), previousStdErr);
|
|
#endif
|
|
SetConsoleOutputCP(previousConsoleOutput);
|
|
#endif
|
|
} |