PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 14, 2022

[FIXED] How does execv does it?

 September 14, 2022     c, exec, windows     No comments   

Issue

Perhaps this is an issue of magic. I'm trying to create a function that has the following signature(or equivalent const char *const *args)

void ExecuteJavaVM(char** args){
 
}

I want to emulate how execv handles an array of parameters, as you may know execv doesn't requires us to put the max number of elements of the array. It just magically counts the number of elements in the array we pass as its second parameter.

This is the execv signature.

intptr_t _execv( 
   const char *cmdname,
   const char *const *argv 
);

Somehow execv manages to "count" the number of elements in the array argv. This is exactly what I'm trying to do.

sizeof is almost useless, since the datatype of the array decays to a simple pointer, so sizeof will most probably always return 4.

Any ideas? Anyone knows where to find the sources of these functions for Windows?


Solution

From the POSIX docs (emphasis mine):

The argument argv is an array of character pointers to null-terminated strings. The application shall ensure that the last member of this array is a null pointer. These strings shall constitute the argument list available to the new process image. The value in argv[0] should point to a filename that is associated with the process being started by one of the exec functions.



Answered By - R. Martinho Fernandes
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing