• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

all your private base are belong to us (getting around vJass's privacy)

Status
Not open for further replies.
Level 13
Joined
Nov 7, 2014
Messages
571
Using the ExecuteFunc native one can get around vJass's privacy enforcement for calling functions/methods that do not take arguments (this is an ExecuteFunc limitation):

JASS:
library Foo

function call_Bars_functions takes nothing returns nothing
    local string PRIVACY_UNDERSCORES = SubString(SCOPE_PRIVATE, StringLength("Foo"), StringLength(SCOPE_PRIVATE))
    call ExecuteFunc("Bar" + PRIVACY_UNDERSCORES + "private_function")
    call ExecuteFunc("Bar_public_function")
    call ExecuteFunc("global_namespace_function")
endfunction

function call_Bazs_private_methods takes nothing returns nothing
    call ExecuteFunc("s__Baz_onInit")
    call ExecuteFunc("s__Baz_private_method")
endfunction

function call_Quxs_private_methods takes nothing returns nothing
    // because Qux is a private struct, we have to find out the number of underscores jasshelper used for privacy
    // it can be either 2 or 3
    local string PRIVACY_UNDERSCORES = SubString(SCOPE_PRIVATE, StringLength("Foo"), StringLength(SCOPE_PRIVATE))
    call ExecuteFunc("s__Bar" + PRIVACY_UNDERSCORES + "Qux_onInit")
    call ExecuteFunc("s__Bar" + PRIVACY_UNDERSCORES + "Qux_private_method")
endfunction

endlibrary

library Bar requires Foo

private function private_function takes nothing returns nothing
    call BJDebugMsg("private function Bar.private_function called")
endfunction
public function public_function takes nothing returns nothing
    call BJDebugMsg("public function Bar.public_function called")
endfunction
function global_namespace_function takes nothing returns nothing
    call BJDebugMsg("global_namespace_function defined in Bar called")
endfunction

struct Baz extends array
    private static method onInit takes nothing returns nothing
        call BJDebugMsg("private static Baz.onInit called")
    endmethod
    private static method private_method takes nothing returns nothing
        call BJDebugMsg("private static Baz.private_method called")
    endmethod
endstruct

private struct Qux extends array
    private static method onInit takes nothing returns nothing
        call BJDebugMsg("private static Qux.onInit called")
    endmethod
    private static method private_method takes nothing returns nothing
        call BJDebugMsg("private static Qux.private_method called")
    endmethod
endstruct

endlibrary

//! inject main
    call call_Bars_functions()
    call call_Bazs_private_methods()
    call call_Quxs_private_methods()

    call BJDebugMsg(" ")
    call BJDebugMsg("vJass will now call the onInit method of each struct:")
    //! dovjassinit
//! endinject
 
Level 13
Joined
Nov 7, 2014
Messages
571
You can just also save their name by using the .name(), it works for functions and methods.

Sure, if you don't mind the "bonus" stuff that vJass generates as if .evaluate/.execute were getting called.
JASS:
function foo takes nothing returns nothing
    call BJDebugMsg("function")
    call BJDebugMsg("foo")
    call BJDebugMsg("got")
    call BJDebugMsg("called")
endfunction

function bar takes nothing returns nothing
    local string s = foo.name // it seems .name can be a field and a method i.e: .name()
endfunction

JASS:
globals


//JASSHelper struct globals:
trigger array st___prototype1

endglobals

function sc___prototype1_execute takes integer i returns nothing

    call TriggerExecute(st___prototype1[i])
endfunction
function sc___prototype1_evaluate takes integer i returns nothing

    call TriggerEvaluate(st___prototype1[i])

endfunction

function foo takes nothing returns nothing
    call BJDebugMsg("function")
    call BJDebugMsg("foo")
    call BJDebugMsg("got")
    call BJDebugMsg("called")
endfunction

function bar takes nothing returns nothing
    local string s= "foo"
endfunction

function main takes nothing returns nothing

call ExecuteFunc("jasshelper__initstructs828802")

endfunction




//Struct method generated initializers/callers:
function sa___prototype1_foo takes nothing returns boolean

    call BJDebugMsg("function")
    call BJDebugMsg("foo")
    call BJDebugMsg("got")
    call BJDebugMsg("called")
    return true
endfunction

function jasshelper__initstructs828802 takes nothing returns nothing
    set st___prototype1[1]=CreateTrigger()
    call TriggerAddAction(st___prototype1[1],function sa___prototype1_foo)
    call TriggerAddCondition(st___prototype1[1],Condition(function sa___prototype1_foo))

endfunction

Notice that we didn't use function.name in an ExecuteFunc context or anything, we just mentioned it.
Also you can't use .name when the function/method is private from outside the scope of where it's defined.

PS: one doesn't have to hardcode the struct name within the struct body when using ExecuteFunc to call a private static method:

JASS:
struct StructName
    static method foo takes nothing returns nothing
        // these two calls
        call ExecuteFunc("s__StructName_bar")
        call ExecuteFunc("s__StructName_baz") // doesn't matter that it's private

        // are exactly the same as these:
        call ExecuteFunc("s__" + "thistype" + "_bar")
        call ExecuteFunc("s__" + "thistype" + "_baz")

        // but note that thistype won't get expanded with these calls:
        call ExecuteFunc("s__thistype_bar")
        call ExecuteFunc("s__" + "thistype_baz")
        call ExecuteFunc("s__thistype" + "_baz")
    endmethod

    static method bar takes nothing returns nothing
    endmethod
    private static method baz takes nothing returns nothing
    endmethod
endstruct

It seems thistype is like a macro that's automatically expanded everywhere within a struct's body.
 
Status
Not open for further replies.
Top