<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842290</guid>
        <pubDate>Fri, 20 Nov 2020 14:14:50 +0000</pubDate>
        <title>Как включить 2 и больше привилегии сразу?</title>
        <link>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842290</link>
        <description><![CDATA[Qraizer: Не-а. По современному Стандарту к UB ведёт не разыменование nullptr, а использование разыменования. По Стандарту же sizeof обязан отрабатывать на этапе компиляции, поэтому в исполняемом образе будет уже готовый результат sizeof. Из чего следует, что результат разыменования не используется.]]></description>
        <author>Qraizer</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842288</guid>
        <pubDate>Fri, 20 Nov 2020 12:52:47 +0000</pubDate>
        <title>Как включить 2 и больше привилегии сразу?</title>
        <link>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842288</link>
        <description><![CDATA[shm: Вроде обращение к nullptr даже внутри sizeof - это UB. В исходниках линуха это везде и был лютый срач на эту тему.]]></description>
        <author>shm</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842283</guid>
        <pubDate>Fri, 20 Nov 2020 11:47:31 +0000</pubDate>
        <title>Как включить 2 и больше привилегии сразу?</title>
        <link>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842283</link>
        <description><![CDATA[Qraizer: Почему 512?<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">PTOKEN_PRIVILEGES tp = malloc(sizeof(*tp) + sizeof(tp-&#62;Privileges[0]));</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
Вообще, этот т.н. POSIX style структур с переменным размером лично меня напрягает. Но уж так повелось. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2020-11-20T11:55:08+00:00">20.11.20, 11:55</time></span></span><br>
P.S. Можно накидать макрос, чтоб каждый раз портянки не писать. Что-то типа<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#define GET_VARIADIC_ARRAY_SIZE(str, field, num) (sizeof(str)-sizeof(str::field) + sizeof(str::field[0])*(num))</div><div class="code_line">&nbsp;</div><div class="code_line">/* ... */</div><div class="code_line">&nbsp;</div><div class="code_line">PTOKEN_PRIVILEGES tp = malloc(GET_VARIADIC_ARRAY_SIZE(TOKEN_PRIVILEGES, Privileges, 2);</div></ol></div></div></div></div>Не тестировал. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2020-11-20T12:10:16+00:00">20.11.20, 12:10</time></span></span><br>
P.P.S. Если так не зайдёт, возможно, в чистом C плюсовое :: не работает, не помню, то вот так должно:<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#define GET_VARIADIC_ARRAY_SIZE(str, field, num) (sizeof(str) - sizeof(((str*)0)-&#62;field) + sizeof(((str*)0)-&#62;field[0]) * (num))</div></ol></div></div></div></div>Но как-то криво выглядит.]]></description>
        <author>Qraizer</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842276</guid>
        <pubDate>Fri, 20 Nov 2020 09:36:06 +0000</pubDate>
        <title>Как включить 2 и больше привилегии сразу?</title>
        <link>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842276</link>
        <description><![CDATA[zer0cat: Спасибо, все получилось. не знаю, правильно или нет, но короче так<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">PTOKEN_PRIVILEGES tp = malloc(512);</div><div class="code_line">LUID luid0, luid1;</div><div class="code_line">tp-&#62;PrivilegeCount = 2;</div><div class="code_line">tp-&#62;Privileges[0].Attributes = tp-&#62;Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;</div><div class="code_line">tp-&#62;Privileges[0].Luid = luid0;</div><div class="code_line">tp-&#62;Privileges[1].Luid = luid1;</div></ol></div></div></div></div>]]></description>
        <author>zer0cat</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842271</guid>
        <pubDate>Fri, 20 Nov 2020 04:57:11 +0000</pubDate>
        <title>Как включить 2 и больше привилегии сразу?</title>
        <link>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842271</link>
        <description><![CDATA[Qraizer: Естественно. Память под tp.Privileges[1] есть? Или трётся? <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2020-11-20T04:58:30+00:00">20.11.20, 04:58</time></span></span><br>
P.S. Размер можно вообще в 0 поставить, коли далее NULL. Я привёл цитату не для этого.]]></description>
        <author>Qraizer</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842268</guid>
        <pubDate>Thu, 19 Nov 2020 20:36:36 +0000</pubDate>
        <title>Как включить 2 и больше привилегии сразу?</title>
        <link>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842268</link>
        <description><![CDATA[zer0cat: Пишу <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">sizeof(TOKEN_PRIVILEGES) * 2</div></ol></div></div></div></div>или <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">sizeof(TOKEN_PRIVILEGES) * tp.PrivilegeCount</div></ol></div></div></div></div> , все равно вторая привилегия не добавляется  :wall:]]></description>
        <author>zer0cat</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842266</guid>
        <pubDate>Thu, 19 Nov 2020 20:27:28 +0000</pubDate>
        <title>Как включить 2 и больше привилегии сразу?</title>
        <link>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842266</link>
        <description><![CDATA[Qraizer: <a class='tag-url' href='https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-token_privileges' target='_blank'>TOKEN_PRIVILEGES structure (winnt.h)</a> <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2020-11-19T20:28:47+00:00">19.11.20, 20:28</time></span></span><br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '><strong class='tag-b'>Important</strong>  The constant ANYSIZE_ARRAY is defined as 1 in the public header Winnt.h. To create this array with more than one element, you must allocate sufficient memory for the structure to take into account additional elements.</div></div>sizeof(TOKEN_PRIVILEGES) естественно включает лишь первый элемент Privileges[]]]></description>
        <author>Qraizer</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842259</guid>
        <pubDate>Thu, 19 Nov 2020 18:27:49 +0000</pubDate>
        <title>Как включить 2 и больше привилегии сразу?</title>
        <link>https://forum.sources.ru/index.php?showtopic=420833&amp;view=findpost&amp;p=3842259</link>
        <description><![CDATA[zer0cat: Не могу разобраться в простейшем коде. Требуется включить сразу две привилегии, делаю так:<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">void err(char *errM,DWORD errC)</div><div class="code_line">{</div><div class="code_line">printf(&quot;%s %d\n&quot;,errM,errC);</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">BOOL SetPrivileges()</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;HANDLE hToken;</div><div class="code_line">&nbsp;&nbsp; &nbsp;BOOL bRet = FALSE;</div><div class="code_line">&nbsp;&nbsp; &nbsp;do</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &amp;hToken))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;err(&quot;OpenThreadToken: %u\n&quot;, GetLastError());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;TOKEN_PRIVILEGES tp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;LUID luid0, luid1;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (!LookupPrivilegeValueA(NULL, SE_TAKE_OWNERSHIP_NAME, &amp;luid0))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;err(&quot;LookupPrivilegeValue SE_TAKE_OWNERSHIP_NAME error: %u\n&quot;, GetLastError());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (!LookupPrivilegeValueA(NULL, SE_DEBUG_NAME, &amp;luid1))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;err(&quot;LookupPrivilegeValue SE_DEBUG_NAME error: %u\n&quot;, GetLastError());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;tp.PrivilegeCount = 2;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;tp.Privileges[0].Attributes = tp.Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;tp.Privileges[0].Luid = luid0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;tp.Privileges[1].Luid = luid1;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (!AdjustTokenPrivileges(hToken, FALSE, &amp;tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;err(&quot;AdjustTokenPrivileges error: %u\n&quot;, GetLastError());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bRet = TRUE;</div><div class="code_line">&nbsp;&nbsp; &nbsp;} while (0);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;CloseHandle(hToken);</div><div class="code_line">&nbsp;&nbsp; &nbsp;return bRet;</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
Ошибок никаких нет, но Process Haker и подобное ПО показывает, что включается только первая (в списке) привилегия. Если менять местами- аналогично, первая включается, иные игнорятся. Почему так?? Да, если по одной все работает, но хочу тут разобраться.<br>
Запускаю, ясное дело, от админа у которого эти привилегии есть.]]></description>
        <author>zer0cat</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      </channel>
      </rss>
	