Здравствуйте. я хочу получить имя пользователя запустившего процесс посредством SecLookupAccountSid. делаю следующее: Код (Text): NTSTATUS Status; ULONG SizeOfUserToken = 0; HANDLE hToken; HANDLE ProcessHandle; OBJECT_ATTRIBUTES ObjectAttributes; CLIENT_ID cid; InitializeObjectAttributes(&ObjectAttributes, (PUNICODE_STRING)NULL, OBJ_CASE_INSENSITIVE + OBJ_KERNEL_HANDLE, NULL, NULL); cid.UniqueProcess = (HANDLE)ProcessId; cid.UniqueThread = (HANDLE)0; Status = ZwOpenProcess(&ProcessHandle,PROCESS_ALL_ACCESS, &ObjectAttributes, &cid); if (!NT_SUCCESS(Status)) { return Status; } Status = ZwOpenProcessToken(ProcessHandle,TOKEN_QUERY,&hToken); if (!NT_SUCCESS(Status)) { return Status; } Status = ZwQueryInformationToken(hToken, TokenUser, NULL, 0, &SizeOfUserToken); if (Status == STATUS_BUFFER_TOO_SMALL) { ULONG NameSize = 0; ULONG DomainNameSize = 0; PTOKEN_USER pTokenUser; SID_NAME_USE NameUse; pTokenUser = (PTOKEN_USER)ExAllocatePool (NonPagedPool,SizeOfUserToken); if (pTokenUser == NULL) { ZwClose(hToken); return STATUS_INSUFFICIENT_RESOURCES; } Status = ZwQueryInformationToken(hToken, TokenUser, pTokenUser, SizeOfUserToken, &SizeOfUserToken); if(!NT_SUCCESS(Status)) { ZwClose(hToken); ExFreePool(pTokenUser); return Status; } ZwClose(hToken); UserName.Buffer = ExAllocatePool (NonPagedPool,128); if (UserName.Buffer == NULL) { ExFreePool(pTokenUser); return STATUS_INSUFFICIENT_RESOURCES; } UserName.MaximumLength = 128; UserName.Length = 0; DomainName.Buffer = ExAllocatePool (NonPagedPool,128); if (DomainName.Buffer == NULL) { ExFreePool(pTokenUser); ExFreePool(UserName.Buffer); return STATUS_INSUFFICIENT_RESOURCES; } DomainName.MaximumLength = 128; DomainName.Length = 0; Status = SecLookupAccountSid(pTokenUser->User.Sid, &NameSize, &UserName, &DomainNameSize, &DomainName, &NameUse); if (Status == STATUS_BUFFER_TOO_SMALL) { ... } ExFreePool(pTokenUser); } В результате или набитые всегда одним и тем же мусором строчки или (что чаще) BSOD. Код (Text): kd> !analyze -v ******************************************************************************* * * * Bugcheck Analysis * * * ******************************************************************************* PAGE_FAULT_IN_NONPAGED_AREA (50) Invalid system memory was referenced. This cannot be protected by try-except, it must be protected by a Probe. Typically the address is just plain bad or it is pointing at freed memory. Arguments: Arg1: f9b142ca, memory referenced. Arg2: 00000000, value 0 = read operation, 1 = write operation. Arg3: 804ecba1, If non-zero, the instruction address which referenced the bad memory address. Arg4: 00000000, (reserved) Debugging Details: ------------------ READ_ADDRESS: f9b142ca FAULTING_IP: nt!RtlCopyUnicodeString+34 804ecba1 f3a5 rep movs dword ptr es:[edi],dword ptr [esi] MM_INTERNAL_CODE: 0 DEFAULT_BUCKET_ID: CODE_CORRUPTION BUGCHECK_STR: 0x50 PROCESS_NAME: System TRAP_FRAME: f9a3da3c -- (.trap 0xfffffffff9a3da3c) ErrCode = 00000000 eax=0000001e ebx=0000001e ecx=00000007 edx=f9a3dc70 esi=f9b142ca edi=80d22588 eip=804ecba1 esp=f9a3dab0 ebp=f9a3dabc iopl=0 nv up ei pl nz na po cy cs=0008 ss=0010 ds=0023 es=0023 fs=0030 gs=0000 efl=00010203 nt!RtlCopyUnicodeString+0x34: 804ecba1 f3a5 rep movs dword ptr es:[edi],dword ptr [esi] Resetting default scope LAST_CONTROL_TRANSFER: from 8053273f to 804e3592 STACK_TEXT: f9a3d58c 8053273f 00000003 f9b142ca 00000000 nt!RtlpBreakWithStatusInstruction f9a3d5d8 80533216 00000003 806ef03c c03e6c50 nt!KiBugCheckDebugBreak+0x19 f9a3d9b8 80533806 00000050 f9b142ca 00000000 nt!KeBugCheck2+0x574 f9a3d9d8 805241a0 00000050 f9b142ca 00000000 nt!KeBugCheckEx+0x1b f9a3da24 804e1718 00000000 f9b142ca 00000000 nt!MmAccessFault+0x6f5 f9a3da24 804ecba1 00000000 f9b142ca 00000000 nt!KiTrap0E+0xcc f9a3dabc fc2a33ed 80d22588 f9a3dbdc 00000000 nt!RtlCopyUnicodeString+0x34 f9a3dbe4 fc29d98f 00000000 f9a3dc44 f9a3dc38 KSecDD!SecpLookupAccountSid+0x187 f9a3dc14 f9099b55 ffa7efe0 f9a3dc38 f9a3dc44 KSecDD!SecLookupAccountSid+0x59 f9a3dc84 f909a299 00000194 f9a3dcec f9a3dcb0 DCPEXAMPLE!GetProcessUserName+0x1a5 [e:\drivers\drivertest\drivertovmmdev\projectfordriver\drivertest\soursfiles\process_info.c @ 479] f9a3dd3c f9099e4e ff9b4000 0000fff3 f9a3dd9c DCPEXAMPLE!ProcessHostCommand+0x399 [e:\drivers\drivertest\drivertovmmdev\projectfordriver\drivertest\soursfiles\zombie.c @ 440] f9a3ddac 8057c9da ffab3970 00000000 00000000 DCPEXAMPLE!RequestHostCommand+0x14e [e:\drivers\drivertest\drivertovmmdev\projectfordriver\drivertest\soursfiles\zombie.c @ 169] f9a3dddc 804f88ea f9099d00 ffab3970 00000000 nt!PspSystemThreadStartup+0x34 00000000 00000000 00000000 00000000 00000000 nt!KiThreadStartup+0x16 STACK_COMMAND: kb CHKIMG_EXTENSION: !chkimg -lo 50 -d !nt 804d8f94-804d8f98 5 bytes - nt!KiXMMIZeroPage+30 [ fa f7 80 0c 02:e9 ef 0a 1e 7b ] 804d93b6-804d93ba 5 bytes - nt!ExAcquireResourceSharedLite+10 (+0x422) [ fa 8b 75 08 33:e9 05 56 1b 7b ] 804da72e-804da732 5 bytes - nt!KiChainedDispatch+28 (+0x1378) [ fa ff 15 08 76:e9 9d 26 1f 7b ] 804db65b-804db65f 5 bytes - nt!ExReleaseResourceLite+b (+0xf2d) [ fa 66 8b 51 0e:e9 00 1f 1b 7b ] 804db880-804db884 5 bytes - nt!KiDispatchInterrupt+c (+0x225) [ fa 3b 00 74 1d:e9 cb 76 1d 7b ] 804db954-804db958 5 bytes - nt!SwapContext+30 (+0xd4) [ fa 89 67 28 8b:e9 df 17 1b 7b ] 804dbb3a-804dbb3b 2 bytes - nt!KiIdleLoop+13 (+0x1e6) [ fa 3b:e9 79 ] 804dbb3d-804dbb3e 2 bytes - nt!KiIdleLoop+16 (+0x03) [ 00 74:1d 7b ] 804dbbdb-804dbbdf 5 bytes - nt!KiRetireDpcList+4d (+0x9e) [ fa 3b 6d 00 75:e9 f8 70 1d 7b ] 804dbc69-804dbc6d 5 bytes - nt!Ki386AdjustEsp0+1e (+0x8e) [ fa 8b 15 40 f0:e9 d2 f9 1a 7b ] 804dbc7d-804dbc81 5 bytes - nt!KiSetDebugActive+6 (+0x14) [ fa 88 48 2c 88:e9 b6 38 1b 7b ] 804de7fd-804de801 5 bytes - nt!KiServiceExit (+0x2b80) [ fa f7 45 70 00:e9 ee ce 1a 7b ] 804de85f - nt!KiServiceExit+62 (+0x62) [ fa:cc ] 804de9a4-804de9a8 5 bytes - nt!KiServiceExit2 (+0x145) [ fa f7 45 70 00:e9 2f 44 1f 7b ] 804de9e4 - nt!KiServiceExit2+40 (+0x40) [ fa:cc ] 804df05c-804df060 5 bytes - nt!KiExceptionExit (+0x678) [ fa f7 45 70 00:e9 87 05 1b 7b ] 804df09c - nt!Kei386EoiHelper+40 (+0x40) [ fa:cc ] 804e0dc3 - nt!VdmFixEspEbp+3 (+0x1d27) [ 0f:cc ] 804e1f22-804e1f26 5 bytes - nt!KiFlushNPXState+4 (+0x115f) [ fa 8b 3d 1c f0:e9 69 d4 1a 7b ] 804e2b6c-804e2b70 5 bytes - nt!KiCallUserMode+54 (+0xc4a) [ fa 8b 0e 89 0c:e9 df 23 1f 7b ] 804e2c5a-804e2c5e 5 bytes - nt!KeSwitchKernelStack+3e (+0xee) [ fa 89 8a 68 01:e9 09 bc 1a 7b ] 804e2cef-804e2cf3 5 bytes - nt!NtCallbackReturn+3b (+0x95) [ fa 8b 35 04 f0:e9 04 24 1f 7b ] 804e2e11-804e2e15 5 bytes - nt!ExfInterlockedAddUlong+1 (+0x122) [ fa 8b 01 01 11:e9 32 da 1e 7b ] 804e2e1d-804e2e21 5 bytes - nt!ExfInterlockedInsertHeadList+1 (+0x0c) [ fa 8b 01 89 02:e9 b6 f8 1c 7b ] 804e2e35-804e2e39 5 bytes - nt!ExfInterlockedInsertTailList+1 (+0x18) [ fa 8b 41 04 89:e9 86 f0 1c 7b ] 804e2e51-804e2e55 5 bytes - nt!ExfInterlockedRemoveHeadList+1 (+0x1c) [ fa 8b 01 3b c1:e9 fa 58 1e 7b ] 804e32a5-804e32a9 5 bytes - nt!KeUpdateSystemTime+e6 (+0x454) [ fa ff 81 70 08:e9 5e 40 1d 7b ] 804e32f6-804e32fa 5 bytes - nt!KeUpdateSystemTime+137 (+0x51) [ fa ff 15 08 76:e9 8d 19 1d 7b ] 804e35e3-804e35e7 5 bytes - nt!ExAcquireResourceExclusiveLite+f (+0x2ed) [ fa 8b 75 08 eb:e9 b8 9c 1a 7b ] 804e8910-804e8914 5 bytes - nt!ExIsResourceAcquiredExclusiveLite+b (+0x532d) [ fa 8b 4d 08 32:e9 7b 9e 1c 7b ] 804e8a15-804e8a19 5 bytes - nt!ExAcquireSharedWaitForExclusive+10 (+0x105) [ fa 8b 75 08 33:e9 66 1a 1d 7b ] 804ed38c-804ed390 5 bytes - nt!CcGetActiveVacb+5 (+0x4977) [ fa 8b 45 08 8b:e9 9f 48 1c 7b ] 804ee3c2-804ee3c6 5 bytes - nt!ExIsResourceAcquiredSharedLite+c (+0x1036) [ fa 8b 4d 08 39:e9 71 41 1c 7b ] 804efade-804efadf 2 bytes - nt!ExReleaseResourceForThreadLite+8 (+0x171c) [ fa 8b:e9 75 ] 804efae1-804efae2 2 bytes - nt!ExReleaseResourceForThreadLite+b (+0x03) [ 08 66:1d 7b ] 804efe58-804efe5c 5 bytes - nt!ExDisableResourceBoostLite+5 (+0x377) [ fa 8b 45 08 80:e9 1b 21 1c 7b ] 804f0288 - nt!ExAcquireSharedStarveExclusive+f (+0x430) [ fa:cc ] 804f0439-804f043d 5 bytes - nt!ExSetResourceOwnerPointer+c (+0x1b1) [ fa 8b 75 08 f6:e9 82 41 1d 7b ] 804f0be0-804f0be4 5 bytes - nt!ExpAllocateExclusiveWaiterEvent+65 (+0x7a7) [ fa 5f 5e 5b c9:e9 d3 ce 19 7b ] 804f0d01-804f0d05 5 bytes - nt!KeRestoreFloatingPointState+79 (+0x121) [ fa f6 03 01 0f:e9 22 3c 1e 7b ] 804f0ddb-804f0ddf 5 bytes - nt!KeSaveFloatingPointState+9f (+0xda) [ fa 0f 20 c0 8b:e9 50 3d 1e 7b ] 804f134c-804f1350 5 bytes - nt!CcSetActiveVacb+7 (+0x571) [ fa 8b 45 08 83:e9 67 34 1d 7b ] 804fae39-804fae3d 5 bytes - nt!ExpFindCurrentThread+10d (+0x9aed) [ fa 8b 75 f8 8b:e9 9a 40 19 7b ] 804faea3 - nt!ExpFindCurrentThread+187 (+0x6a) [ fa:cc ] 804faf07-804faf0b 5 bytes - nt!ExpAllocateSharedWaiterSemaphore+5e (+0x64) [ fa 5f 5e c9 c2:e9 44 43 19 7b ] 804fb5e8-804fb5ec 5 bytes - nt!ExConvertExclusiveToSharedLite+5 (+0x6e1) [ fa 8b 45 08 66:e9 d3 f5 1b 7b ] 805038af-805038b3 5 bytes - nt!KeRemoveQueueDpc+6 (+0x82c7) [ fa 8b 45 08 8b:e9 ec 19 1d 7b ] 805073df-805073e3 5 bytes - nt!IoStartTimer+17 (+0x3b30) [ fa 66 83 78 02:e9 14 7f 1b 7b ] 8050939e-805093a2 5 bytes - nt!Ki386SetupAndExitToV86Code+a3 (+0x1fbf) [ fa 51 8b 73 04:e9 4d ba 1c 7b ] 8050ba6b-8050ba6f 5 bytes - nt!Ki386VdmEnablePentiumExtentions+5 (+0x26cd) [ fa 0f 20 e0 f7:e9 00 6e 1c 7b ] WARNING: !chkimg output was truncated to 50 lines. Invoke !chkimg without '-lo [num_lines]' to view entire output. 236 errors : !nt (804d8f94-80545fee) MODULE_NAME: memory_corruption IMAGE_NAME: memory_corruption FOLLOWUP_NAME: memory_corruption DEBUG_FLR_IMAGE_TIMESTAMP: 0 MEMORY_CORRUPTOR: LARGE FAILURE_BUCKET_ID: MEMORY_CORRUPTION_LARGE BUCKET_ID: MEMORY_CORRUPTION_LARGE Followup: memory_corruption --------- Что здесь не так?
Drinkerq Судя по багчеку вы передали инвалидную ссылку. Может это юникодовская строка, может есчо что. Не вооружённым глазом трудно сказать.
Ставите бряк на RtlCopyUnicodeString, и смотрите что и куда у вас пытается скопироваться. offtop: как же тяжело читать код без венгерской нотации, нифига не понятно где какие переменные))