Page 1 of 1

Blacklist|Whitelist URL with Windivert

Posted: Tue Mar 12, 2019 8:00 pm
by boyoss
Based on the work of JHPJHP, WinDivert, i'm trying to build an application of Blacklist and Whitelist URL.
I came across this project (https://it.bmc.uu.se/andlov/proj/sec/urlfilter/), and wonder how is it possible to translate it to purebasic.

It's written in c++, and i will be very thankfull if someone can help me, even a bit, to bring it to purebasic.

Thanks

Re: Blacklist|Whitelist URL with Windivert

Posted: Thu Mar 14, 2019 9:29 am
by boyoss
pliz.. :D

Re: Blacklist|Whitelist URL with Windivert

Posted: Thu Mar 14, 2019 12:42 pm
by Christophe_fr
if you can use it....
small utility for blacklisting url
to be compiled in administrator mode

Image

Image

Code: Select all

OpenWindow(0,0,0,600,800,"BlackList", #PB_Window_SystemMenu | #PB_Window_SystemMenu)
ListIconGadget(0,10,10,580,680,"BlackList",700)
StringGadget(1,10,720,400,20,"")
ButtonGadget(2,250,750,100,30,"ADD")

File$ = "C:\Windows\System32\drivers\etc\hosts"
remove$ = "127.0.0.1  "
SendMessage_(GadgetID(0),#WM_SETREDRAW,0,0)
If ReadFile(0, File$, #PB_Ascii)
  While Not Eof(0)
    f$ =  ReadString(0)
    If Left(f$, 1) = "#"
      Continue
    Else
      f$ = Mid(f$,11, Len(f$))
      AddGadgetItem(0, -1, f$)
    EndIf
  Wend
  CloseFile(0)
EndIf
SendMessage_(GadgetID(0),#WM_SETREDRAW,1,0)
nbr = CountGadgetItems(0)
Debug ""+nbr+" Url BlackListed"

Repeat
  e = WaitWindowEvent()
  Select e
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 2
          If GetGadgetText(1)="" : Debug "Erreur url"
          Else
            Debug "Add "+GetGadgetText(1)
            If  SetFileAttributes(File$, #PB_FileSystem_Normal) : Debug "Suppression des droits OK"
              OpenFile(0, File$, #PB_Ascii)
              FileSeek(0, Lof(0))
              If  WriteStringN(0, remove$+GetGadgetText(1))
                CloseFile(0) 
                SetFileAttributes(File$, #PB_FileSystem_ReadOnly)
                Debug GetGadgetText(1)+" Added"
              Else
                Debug "Erreur ecriture"
              EndIf
            Else
              Debug "Erreur suppression des droits"
            EndIf
          EndIf 
      EndSelect
  EndSelect
  
Until e = #PB_Event_CloseWindow
Sorry for my English. I'm French (translated with DeepL)