News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Recent posts

#31
The Workshop / Re: COM, create rule in Firewa...
Last post by Fraile - June 14, 2024, 09:11:37 PM
I already created the rule but it doesn't enable it; I think it's because of put_Grouping. According to Microsoft, it is mandatory and must be filled in the following way: '@<dll name>, <resource string identifier>'. Microsoft says that groups help enable and disable multiple rules at once, but I don't understand how to set the put_Grouping property according to the format. Any ideas? Thank you very much.
#32
The Workshop / Re: COM, create rule in Firewa...
Last post by Fraile - June 14, 2024, 07:23:10 PM
Error!!!!  coinvoke pFwPolicy2, INetFwPolicy2, get_Rules, Offset pFwRules

Microsoft get_rules

Thanks!!!!
#33
The Workshop / Re: COM, create rule in Firewa...
Last post by sinsi - June 14, 2024, 07:22:19 PM
You need to give get_Rules a pointer to store the interface you're after. Try
    coinvoke pFwPolicy2, INetFwPolicy2, get_Rules, addr pFwRules
Generally, EAX will have the result of the invoke, not what you are after.
#34
The Workshop / Re: COM, create rule in Firewa...
Last post by Fraile - June 14, 2024, 06:50:42 PM
First of all, thank you all very much, because now I am starting to see things more clearly. The assignment of properties seems to be going well, but in this part of the code     ; Obtener la colección de reglas del firewall
    ;********************************************
    coinvoke pFwPolicy2, INetFwPolicy2, get_Rules
    Mov pFwRules, Eax
    ;********************************************
 the program crashes, it doesn't respond. Can you think of any reason why this might be happening? Thank you very much.


.386
.Model Flat, StdCall
Option CaseMap :None
AsigText Macro Name, Text:VarArg
Local lbl
Jmp lbl
Name DB Text, 0
lbl:
EndM
coinvoke Macro ppv:Req,interface:Req,member:Req,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16

    FOR arg,<p16,p15,p14,p13,p12,p11,p10,p9,p8,p7,p6,p5,p4,p3,p2,p1>

        IFNB <arg>

            Push arg

        ENDIF

    EndM

    Mov     Eax,ppv
    Push    Eax
    Mov     Eax,DWord Ptr [Eax]
    Call    @CatStr(interface,<.>,member)[Eax]

EndM

.Const
    GuiPolicy  TextEqu   <{098325047H, 0C671H, 04174H, {08DH, 081H, 0DEH, 0FCH, 0D3H, 0F0H, 031H, 086H}}>
    IID_FwRule TextEqu   <{0AF230D27H, 0BABAH, 04E42H, {0ACH, 0EDH, 0F5H, 024H, 0F2H, 02CH, 0FCH, 0E2H}}>



    NET_FW_ACTION_BLOCK Equ 0
    NET_FW_RULE_DIR_IN  Equ 1

.Data?

IShellDispatch Struct

    QueryInterface          DD ?
    AddRef                  DD ?
    Release                 DD ?
   
    GetTypeInfoCount        DD ?
    GetTypeInfo             DD ?
    GetIDsOfNames           DD ?
    _Invoke                 DD ?

    get_Name                DD ?
    put_Name                DD ?
get_Description         DD ?
put_Description         DD ?
get_ApplicationName     DD ?
put_ApplicationName     DD ?
get_serviceName         DD ?
put_serviceName         DD ?
get_Protocol            DD ?
put_Protocol            DD ?
get_LocalPorts          DD ?
put_LocalPorts          DD ?
get_RemotePorts         DD ?
put_RemotePorts         DD ?
get_LocalAddresses      DD ?
put_LocalAddresses      DD ?
get_RemoteAddresses     DD ?
put_RemoteAddresses     DD ?
get_IcmpTypesAndCodes   DD ?
put_IcmpTypesAndCodes   DD ?
get_Direction           DD ?
put_Direction           DD ?
get_Interfaces          DD ?
put_Interfaces          DD ?
get_InterfaceTypes      DD ?
put_InterfaceTypes      DD ?
get_Enabled             DD ?
put_Enabled             DD ?
get_Grouping            DD ?
put_Grouping            DD ?
get_Profiles            DD ?
put_Profiles            DD ?
get_EdgeTraversal       DD ?
put_EdgeTraversal       DD ?
get_Action              DD ?
put_Action              DD ?
   
IShellDispatch EndS
INetFwRules Struct
    QueryInterface          DD ?
    AddRef                  DD ?
    Release                 DD ?
    GetTypeInfoCount        DD ?
    GetTypeInfo             DD ?
    GetIDsOfNames           DD ?
    _Invoke                 DD ?
    get_Count               DD ?
    _Add                    DD ?
    Remove                  DD ?
    Item                    DD ?
    get__NewEnum            DD ?
INetFwRules EndS
INetFwPolicy2 Struct
    QueryInterface               DD ?
    AddRef                       DD ?
    Release                      DD ?
    GetTypeInfoCount             DD ?
    GetTypeInfo                  DD ?
    GetIDsOfNames                DD ?
    _invoke                      DD ?

    get_CurrentProfileTypes      DD ?
    get_FirewallEnabled          DD ?
    put_FirewallEnabled          DD ?
    get_ExcludedInterfaces       DD ?
    put_ExcludedInterfaces       DD ?
    get_BlockAllInboundTraffic   DD ?
    put_BlockAllInboundTraffic   DD ?
    get_NotificationsDisabled    DD ?
    put_NotificationsDisabled    DD ?
    get_UnicastRTMDisabled       DD ?
    put_UnicastRTMBDisabled      DD ?
    get_Rules                    DD ?
    get_ServiceRestriction       DD ?
    EnableRuleGroup              DD ?
    IsRuleGroupEnabled           DD ?
    RestoreLocalFirewallDefaults DD ?
    get_DefaultInboundAction DD ?
    put_DefaultInboundAction DD ?
    get_DefaultOutboundAction DD ?
    put_DefaultOutboundAction DD ?
    get_IsRuleGroupCurrentlyEnabled DD ?
    get_LocalPolicyModifyState DD ?
INetFwPolicy2 EndS

    pFwPolicy2              DD ?
    pFwRules DD ?
pFwRule                 DD ?



.Data
    HandleConsola DD 0
    CarroDeRetorno           DB 13 ; Código ASCII para retorno de carro
    NuevaLinea               DB 10 ; Código ASCII para nueva línea

    ProgID_HNetCfg_FwPolicy2 DW 'H', 'N', 'e', 't', 'C', 'f', 'g', '.', 'F', 'w', 'P', 'o', 'l', 'i', 'c', 'y', '2', 0
    ProgID_HNetCfg_Fwrule    DW 'H', 'N', 'e', 't', 'C', 'f', 'g', '.', 'F', 'W', 'R', 'u', 'l', 'e', 0

CLSIDFw                  GUID <>
    IID_INetFwPolicy2        GUID GuiPolicy
    CLSID_NetFwRule          GUID <>
IID_INetFwRule GUID IID_FwRule

    ruleName            DW 'B', 'l', 'o', 'c', 'k', 'S', 'p', 'e', 'c', 'i', 'f', 'i', 'c', 'I', 'P', 0
    ruleDescription     DW 'B', 'l', 'o', 'c', 'k', ' ', 't', 'r', 'a', 'f', 'f', 'i', 'c', ' ', 'f', 'r', 'o', 'm', ' ', 's', 'p', 'e', 'c', 'i', 'f', 'i', 'c', ' ', 'I', 'P', 0
    remoteAddresses     DW '1', '9', '2', '.', '1', '6', '8', '.', '1', '.', '1', 0  ; Cambia esta IP a la que deseas bloquear

;    ruleName            DB "BlockSpecificIP", 0
;    ruleDescription     DB "Block traffic from specific IP", 0
;    remoteAddresses     DB "192.168.1.1", 0  ; Cambia esta IP a la que deseas bloquear


.Code

start:

  Invoke GetStdHandle, STD_OUTPUT_HANDLE
  Mov HandleConsola, Eax

;=====================

AsigText Cabecera0, "----------------------------------"
    Invoke WriteConsoleA, HandleConsola, Addr Cabecera0, 25, 0, 0
    Invoke ImprimirSaltoDeLinea

AsigText Cabecera1, "FraiFRW by Fraile - 2024."
    Invoke WriteConsoleA, HandleConsola, Addr Cabecera1, 25, 0, 0
    Invoke ImprimirSaltoDeLinea

AsigText Cabecera2, "----------------------------------"
    Invoke WriteConsoleA, HandleConsola, Addr Cabecera2, 25, 0, 0
    Invoke ImprimirSaltoDeLinea
    Invoke ImprimirSaltoDeLinea

;=====================

    ; Initialize COM library
    Invoke CoInitialize, NULL
    Cmp Eax, S_OK
Jne ErrorInicializacionCOM

Invoke CLSIDFromProgID, Addr ProgID_HNetCfg_FwPolicy2, Addr CLSIDFw
Cmp Eax, S_OK
Jne ErrorCLIDIdentifi

    Invoke CoCreateInstance, Addr CLSIDFw, NULL, CLSCTX_LOCAL_SERVER, Addr IID_INetFwPolicy2, Addr pFwPolicy2

    ; Check if the instance was created successfully
    Cmp Eax, S_OK
    Jne ErrorCoCrea

Invoke CLSIDFromProgID, Addr ProgID_HNetCfg_Fwrule, Addr CLSID_NetFwRule
Cmp Eax, S_OK
Jne ErrorCLIDIdentifi

    ; Crear una instancia de la interfaz INetFwRule
    Invoke CoCreateInstance, Addr CLSID_NetFwRule, NULL, CLSCTX_INPROC_SERVER, Addr IID_INetFwRule, Addr pFwRule
    Cmp Eax, S_OK
    Jne ErrorCoCreaRule

    ; Obtener la colección de reglas del firewall
    ;********************************************
    coinvoke pFwPolicy2, INetFwPolicy2, get_Rules
    Mov pFwRules, Eax
    ;********************************************



    ; Establecer las propiedades de la regla
    Invoke SysAllocString, Addr ruleName
    Cmp Eax, 0
    Je ErrorSysAlloc
coinvoke pFwRule, IShellDispatch, put_Name, Eax

    Invoke SysAllocString, Addr ruleDescription
    Cmp Eax, 0
    Je ErrorSysAlloc
coinvoke pFwRule, IShellDispatch, put_Description, Eax

    Invoke SysAllocString, Addr remoteAddresses
    Cmp Eax, 0
    Je ErrorSysAlloc
coinvoke pFwRule, IShellDispatch, put_RemoteAddresses, Eax

    ; Establecer la acción de la regla (bloquear)
    Mov Eax, NET_FW_ACTION_BLOCK
    coinvoke pFwRule, IShellDispatch, put_Action, Eax

    ; Habilitar la regla
    Mov Eax, 1 ; TRUE
    coinvoke pFwRule, IShellDispatch, put_Enabled, Eax


    ; Agregar la regla al firewall


    ; Mensaje de éxito
    AsigText ReglaCreada, "Regla Creada!."
    Invoke WriteConsoleA, HandleConsola, Addr ReglaCreada, 14, 0, 0
    Invoke ImprimirSaltoDeLinea


    ; Cerrar la biblioteca COM
    Invoke CoUninitialize
    Invoke ExitProcess, 0


ErrorInicializacionCOM:
AsigText Error0, "Error Ini COM."
    Invoke WriteConsoleA, HandleConsola, Addr Error0, 14, 0, 0
    Invoke ImprimirSaltoDeLinea

    Invoke CoUninitialize
    Invoke ExitProcess, 1

ErrorCLIDIdentifi:
AsigText Error1, "Error Identifi Clid."
    Invoke WriteConsoleA, HandleConsola, Addr Error1, 20, 0, 0
    Invoke ImprimirSaltoDeLinea

    Invoke CoUninitialize
    Invoke ExitProcess, 1

ErrorClsID:
AsigText Error2, "Error Clid."
    Invoke WriteConsoleA, HandleConsola, Addr Error2, 11, 0, 0
    Invoke ImprimirSaltoDeLinea

    Invoke CoUninitialize
    Invoke ExitProcess, 1

ErrorCoCrea:
AsigText Error3, "Error al instanciar Obj."
    Invoke WriteConsoleA, HandleConsola, Addr Error3, 25, 0, 0
    Invoke ImprimirSaltoDeLinea

    Invoke CoUninitialize
    Invoke ExitProcess, 1

ErrorCoCreaRule:
AsigText Error4, "Error al instanciar regla."
    Invoke WriteConsoleA, HandleConsola, Addr Error4, 27, 0, 0
    Invoke ImprimirSaltoDeLinea

    Invoke CoUninitialize
    Invoke ExitProcess, 1

ErrorSysAlloc:
AsigText Error5, "Error SysAlloc."
    Invoke WriteConsoleA, HandleConsola, Addr Error5, 15, 0, 0
    Invoke ImprimirSaltoDeLinea

    Invoke CoUninitialize
    Invoke ExitProcess, 1

ImprimirSaltoDeLinea Proc
    ; Imprime un retorno de carro (CR) y una nueva línea (LF) en la consola
    Invoke WriteConsole, HandleConsola, Addr CarroDeRetorno, 1, 0, 0
    Invoke WriteConsole, HandleConsola, Addr NuevaLinea, 1, 0, 0
    Ret

ImprimirSaltoDeLinea EndP



End start


#35
16 bit DOS Programming / Re: Bouncing Square Clipping
Last post by _japheth - June 14, 2024, 05:39:37 PM
Quote from: tda0626 on June 14, 2024, 05:04:32 AMIs that good for a line draw routine? Never benchmarked it. I am sure it could use a little bit of optimization.

Optimization is usually good, but:

  • 86 ms for 600 loops without vsync synchronization
  • 10,000 ms for 600 loops with vsync synchronization
  • conclusion: your prog spends more than 99% of its time waiting for vsync

So it's perhaps a bit moot here...

#36
16 bit DOS Programming / Re: Bouncing Square Clipping
Last post by NoCforMe - June 14, 2024, 09:46:24 AM
Quote from: tda0626 on June 14, 2024, 05:04:32 AMWhen drawing a filled in rectangle or square, is there a preferred method? The way I draw it now is line by line, top to bottom.
Well, assuming you've drawn a contiguous border, you could use a flood-fill routine, I guess, but that might actually be slower, as well as requiring recursion.

The advantage of using flood-fill is that it will fill any fully-enclosed shape, regular or not.
#37
16 bit DOS Programming / Re: Bouncing Square Clipping
Last post by tda0626 - June 14, 2024, 05:04:32 AM
Quote from: _japheth on June 13, 2024, 08:38:09 PM
Quote from: tda0626 on June 13, 2024, 04:11:48 AMThank you. Is the technique you are describing called double buffering?

No - I guess double buffering is closely related to "page flipping" ( changing the start address of the "visible" video memory ).

QuoteWhen you allocate memory with DOS function AH=48, you specify the number of pages of memory needed as 1000h. Why did you specify that and not 4000 decimal, which is 64k/16?

You're right, 4000 would have been the exact value - 1000h wastes 1536 bytes.

Btw., I made some timing tests: your code, with the vsync wait deactivated, needs 86 ms for 600 loops - so < 150 microsecs for one loop - for my understanding that's far too fast to cause "flickering" troubles. Would be interesting to see what's displayed with a true CRT monitor attached - regrettably I don't have one.


Is that good for a line draw routine? Never benchmarked it. I am sure it could use a little bit of optimization.

When drawing a filled in rectangle or square, is there a preferred method? The way I draw it now is line by line, top to bottom.
#38
16 bit DOS Programming / Re: Bouncing Square Clipping
Last post by _japheth - June 13, 2024, 08:38:09 PM
Quote from: tda0626 on June 13, 2024, 04:11:48 AMThank you. Is the technique you are describing called double buffering?

No - I guess double buffering is closely related to "page flipping" ( changing the start address of the "visible" video memory ).

QuoteWhen you allocate memory with DOS function AH=48, you specify the number of pages of memory needed as 1000h. Why did you specify that and not 4000 decimal, which is 64k/16?

You're right, 4000 would have been the exact value - 1000h wastes 1536 bytes.

Btw., I made some timing tests: your code, with the vsync wait deactivated, needs 86 ms for 600 loops - so < 150 microsecs for one loop - for my understanding that's far too fast to cause "flickering" troubles. Would be interesting to see what's displayed with a true CRT monitor attached - regrettably I don't have one.
#39
Hardware & Software Corner / Re: Languages
Last post by stoo23 - June 13, 2024, 04:39:40 PM
Via a link from the above pages, I stumbled on this:
Zig

Made me instantly think of 'NoCforMe'  :wink2:  :smiley:  as it's Not C and has No Macros !!  :biggrin:  :cool:

The article, suggests;
QuoteZig is an effort to create a general-purpose programming language with program-level memory controls that outperforms C, while offering a more powerful and less error-prone syntax.
The goal is nothing less than supplanting C as the baseline language of the programming ecosystem.
Because C is ubiquitous (i.e., the most common component in systems and devices everywhere), success for Zig could mean widespread improvements in performance and stability.
That's something we should all hope for.
Plus, Zig is a good, old-fashioned grass-roots project with a huge ambition and an open-source ethos.
:smiley: