Skip to content

Commit

Permalink
Do adapter name translation after converting to ASCII. See nmap/nmap#…
Browse files Browse the repository at this point in the history
…1575
  • Loading branch information
bonsaiviking committed Jun 24, 2019
1 parent 719d645 commit c032935
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packetWin7/Dll/Packet32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,7 @@ LPADAPTER PacketOpenAdapter(PCHAR AdapterNameWA)
{
LPADAPTER lpAdapter = NULL;
PCHAR AdapterNameA = NULL;
PCHAR TranslatedAdapterNameWA = NULL;
PCHAR TranslatedAdapterNameA = NULL;
BOOL bFreeAdapterNameA;
#ifndef _WINNT4
PADAPTER_INFO TAdInfo;
Expand All @@ -2657,13 +2657,6 @@ LPADAPTER PacketOpenAdapter(PCHAR AdapterNameWA)

TRACE_PRINT2("Packet DLL version %hs, Driver version %hs", PacketLibraryVersion, PacketDriverVersion);

// Translate the adapter name string's "NPF_{XXX}" to "NPCAP_{XXX}" for compatibility with WinPcap, because some user softwares hard-coded the "NPF_" string
TranslatedAdapterNameWA = NpcapTranslateAdapterName_Npf2Npcap(AdapterNameWA);
if (TranslatedAdapterNameWA)
{
AdapterNameWA = TranslatedAdapterNameWA;
}

//
// Check the presence on some libraries we rely on, and load them if we found them
//
Expand Down Expand Up @@ -2692,15 +2685,24 @@ LPADAPTER PacketOpenAdapter(PCHAR AdapterNameWA)
if (AdapterNameA == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
if (TranslatedAdapterNameWA)
free(TranslatedAdapterNameWA);
return NULL;
}

StringCchPrintfA(AdapterNameA, bufferSize, "%ws", (PWCHAR)AdapterNameWA);
bFreeAdapterNameA = TRUE;
}

// Translate the adapter name string's "NPF_{XXX}" to "NPCAP_{XXX}" for compatibility with WinPcap, because some user softwares hard-coded the "NPF_" string
TranslatedAdapterNameA = NpcapTranslateAdapterName_Npf2Npcap(AdapterNameA);
if (TranslatedAdapterNameA)
{
if (bFreeAdapterNameA) {
GlobalFree(AdapterNameA);
bFreeAdapterNameA = FALSE;
}
AdapterNameA = TranslatedAdapterNameA;
}

#ifndef _WINNT4
WaitForSingleObject(g_AdaptersInfoMutex, INFINITE);
#endif // not WINNT4
Expand Down Expand Up @@ -2909,16 +2911,16 @@ LPADAPTER PacketOpenAdapter(PCHAR AdapterNameWA)
{
TRACE_EXIT();
SetLastError(dwLastError);
if (TranslatedAdapterNameWA)
free(TranslatedAdapterNameWA);
if (TranslatedAdapterNameA)
free(TranslatedAdapterNameA);

return NULL;
}
else
{
TRACE_EXIT();
if (TranslatedAdapterNameWA)
free(TranslatedAdapterNameWA);
if (TranslatedAdapterNameA)
free(TranslatedAdapterNameA);

return lpAdapter;
}
Expand Down

0 comments on commit c032935

Please sign in to comment.