Restored from previous forum. Originally posted by PB.
Anyone know if it's possible to call an API command by a variable name?
Like, to change Sleep_(136) to a$="Sleep_" : a$(136) or something similar?
Reason: To hide which APIs commands are being called in the final executable,
because they're plainly visible with any hex editor at the moment...
PB - Registered PureBasic Coder
Calling APIs by variable?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
You can use this, I think:
Remember to enable inline asm to do this. Anyway ,I'm not 100% sure that this will hide the function name totally (even if you use some string encryption).
Well, tell us if it works and we'll know
, bye,
El_Choni
You can use this, I think:
Code: Select all
FunctionName = "MyFunction"
ModuleHandle = LoadLibrary_("DllName.dll")
FunctionPointer = GetProcAddress_(ModuleHandle, FunctionName$)
; here you use the asm 'push' opcode to pass parameters to the function IN REVERSE ORDER
; If the function syntax is MyFunction(a, b, c):
push c
push b
push a
; and the asm opcode 'call' to call the function
call FunctionPointer
Well, tell us if it works and we'll know
El_Choni
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
If you can see the function name ("sleep") in the
HEX-Editor, its the import table for the .EXE
and you cant change that. Its no code, only
a table with the import names.
You can see the import names of every static
linked function. Thats how the static linking
works.
With dynamic linking a DLL to the .EXE (the way
El_Choni showed) you could encrypt the FunctionName$,
but all API functions that PureBasic needs are still
in the import section.
cya,
...Danilo
(registered PureBasic user)
If you can see the function name ("sleep") in the
HEX-Editor, its the import table for the .EXE
and you cant change that. Its no code, only
a table with the import names.
You can see the import names of every static
linked function. Thats how the static linking
works.
With dynamic linking a DLL to the .EXE (the way
El_Choni showed) you could encrypt the FunctionName$,
but all API functions that PureBasic needs are still
in the import section.
cya,
...Danilo
(registered PureBasic user)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
.
Fred - AlphaSND
Why not using the buildin 'Library' library ? No need for asm and it's much easier to use. It's possible to hide the name by ciphering itYou can use this, I think:
Remember to enable inline asm to do this. Anyway ,I'm not 100% sure that this will hide the function name totally (even if you use some string encryption).Code: Select all
FunctionName = "MyFunction" ModuleHandle = LoadLibrary_("DllName.dll") FunctionPointer = GetProcAddress_(ModuleHandle, FunctionName$) ; here you use the asm 'push' opcode to pass parameters to the function IN REVERSE ORDER ; If the function syntax is MyFunction(a, b, c): push c push b push a ; and the asm opcode 'call' to call the function call FunctionPointer
Well, tell us if it works and we'll know, bye,
El_Choni
Fred - AlphaSND
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Rings.
Its a long way to the top if you wanna .....CodeGuru
Code: Select all
fn.s="peeB"
ln.s="23lenrek"
Procedure.s StringReturn(Instring.s)
dummy.s=""
For I= Len(Instring) To 1 Step -1
Dummy=Dummy + Mid(Instring,i,1)
Next
ProcedureReturn dummy
EndProcedure
ln=StringReturn(ln)
fn=StringReturn(fn)
;MessageRequester("Info",ln+Chr(13)+fn,0)
Result = OpenLibrary(1,ln)
If Result
Result = CallFunction(1,fn,1000,1000)
CloseLibrary(1)
Else
MessageRequester("Info","Cannot open Library",0)
EndIf -
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
Sorry for the outdated advice. Bye,
El_Choni
You can't teach new tricks to an old dog. I'm not used to the new commands yet, but I guess it makes sense to use them.Why not using the buildin 'Library' library ? No need for asm and it's much easier to use. It's possible to hide the name by ciphering it.
Sorry for the outdated advice. Bye,
El_Choni
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm