Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 642 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Implementing a basic jump table for dynamic command parsing

#1
So, was in a PM with another member who was complaining about having to have a massive command parser with a shitload of if-strncmp's in it. I gave him this C code to solve that problem and be more clean, maybe you guys will like it as well:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

Reply

#2
Quote:(04-19-2018, 04:17 PM)0xAeschylus Wrote:

[To see links please register here]

Great code! Easily editable and works great. But what about if the functions needed arguments based on user input?

There's 2 ways of attacking that:

Option 1 is to pass the c-string of the command to every function called, and then have a va_list on each of the prototypes, allowing each function to read the rest of the arglist (or parse it ahead of time).
Option 2 is to parse out the arglist based on the command inside that if statement and let every function have a different number of args. To do this, simply remove the void from the proto in the struct, and then C won't enforce the argument list checks and you can pass as many or as few as you need.

I'd advise option 2, then add a "group" field to make it easier
Reply

#3
Great code! Easily editable and works great. But what about if the functions needed arguments based on user input?
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through