[INC] valist.inc Variable arguments function
1 Attachment(s)
Update: 2.0 released. Check changelog below.
How? Dark Magic! Used a few tricks i created functions for variable arguments access. This workable only with non-array variables for now (write if it needed to add arrays/strings support). Instruction: 1) Include valist.inc in plugin with #include directive (You must include it first among all includes for proper work). 2) Call va_start(int param_n) in variable argument function, where param_n number of argument with ..., counting of arguments start with 1. Note for 1st version: It's important call va_start before any variable will declared. Overwise, it'll work not correct. (In 1st version need to call va_start first in function, in 2nd not). 3) For getting next argument use va_arg(). In case if no more arguments to get, it'll throw error. You can use va_args() for getting count of params passed in function and va_more() to check if all arguments getted. 4) When you no more needed to get arguments, you must call va_end(). Overwise, memory leaks. Offtop: Please, if you see any grammar mistakes, notice me about it. I'm not going well in English. Plugin example: PHP Code:
valist.inc code
Attention! 1st version not working in 1.9 since sourcepawn "Disallow negative indices in all array access patterns" (d7743c3) update. Changelog: v2: Changelog v1: First release. // Download latest version below in attachments. Old versions: v1: valist.inc How i did this: (tricks) 1) Unchecked memory access Then you pass array as param, plugin know only address and check index for negative value PHP Code:
Plugin memory сonsists of DAT (globals, statics, consts), heap, stack (order as i wrote). When functions calls: 1) Pass arguments in reverse order 2) Pass num of arguments 3) pass old frame address 4) pass 0 Using sipmle trick i can dump stack PHP Code:
Code:
etc. Also as we see stack reversed in memory. memory: DAT-start ... DAT-end, heap-start ... heap-end, stack-end ... stack-start; 3) pseudo-class based on methodmap + ArrayList 4) Some macros for good looking code |
Re: [INC] valist.inc Variable arguments function
This is awesome! :bacon!::bacon!::crab:
|
Re: [INC] valist.inc Variable arguments function
Yay n1
|
Re: [INC] valist.inc Variable arguments function
Not working in 1.9 since sourcepawn "Disallow negative indices in all array access patterns" (d7743c3) update.
|
Re: [INC] valist.inc Variable arguments function
New version! Now work with 1.9!
v2 changelog: 1) Now working with 1.9: Code with negative indexes changed to trick: include declare global variable in start of DAT -> variable has low address -> get variable address -> use trick 1 with offset with difference between addresses 2) Changed way to get address and number params -> va_start no more needed to be called first in function. 3) All variables and functions marked as stocks for not including then not used. |
All times are GMT -4. The time now is 23:07. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.