[Gambas-user] external function freezes

Demosthenes Koptsis demosthenesk at gmail.com
Sat Jun 9 08:42:55 CEST 2018


Hello Jussi,

from man 2 waitpid

The  value  of  options  is an OR of zero or more of the following con‐
        stants:

        WNOHANG     return immediately if no child has exited.

i do not exit the target process and waitpid returns to gambas process.

With WNOHANG the gambas project (and also the c project) behaves like 
there is no waitpid.

As a result is to break the target process and the Me.ret value of

Me.ret = ptrace(PTRACE_PEEKDATA, Me.pid, Me.addr, Null)


Me.ret = -1 which means ptrace exit with an error

After that i cannot ptrace any more the target process.

Thanks.

On 06/09/2018 02:10 AM, Jussi Lahtinen wrote:
> I'm not sure you need waitpid call at all, but if it is needed for 
> some side effects, then try to pass it as:
> waitpid(Me.pid, Null, 1) ''IE WNOHANG
>
>
> Jussi
>
> On Sat, Jun 9, 2018 at 1:57 AM, Jussi Lahtinen 
> <jussi.lahtinen at gmail.com <mailto:jussi.lahtinen at gmail.com>> wrote:
>
>     With exec or shell command, but I'm not sure that is what you want
>     to do. I think you want to attach to existing process.
>
>     From the documentation:
>     /"The *waitpid*() system call suspends execution of the calling
>     process until a child specified by pid argument has changed state."/
>
>     So this is what you observe as freezing.
>
>     /"By default, *waitpid*() waits only for terminated children, but
>     this behavior is modifiable via the options argument, as described
>     below."/
>     /
>     /
>     Not sure what this means... maybe they meant to write "... waitpid
>     waits only for termination of the children ...".
>     Are they required to be child processes or do attaching to process
>     count as child process? I don't know. If so, I don't think the
>     options argument can be zero in your case.
>
>
>     Jussi
>
>
>     On Sat, Jun 9, 2018 at 1:22 AM, Demosthenes Koptsis
>     <demosthenesk at gmail.com <mailto:demosthenesk at gmail.com>> wrote:
>
>         On 06/09/2018 12:11 AM, Tobias Boege wrote:
>
>             On Fri, 08 Jun 2018, Demosthenes Koptsis wrote:
>
>                 Hello, i implemented a ptrace and waitpid external
>                 functions in order to
>                 read/write a memory address of a process.
>
>                 i want to make a trainer for a game in gambas and i
>                 created a small program
>                 that reads and writes to a memory process.
>
>                 The problem is that when i try to write to memory it
>                 freezes at waitpid
>                 line.
>
>                 i attach the test program you have to 1) open it as
>                 root 2) run a process
>                 you want to hack and get the pid 3) scan memory with
>                 scanmem and locate an
>                 address you want to write. 4) run my test program and
>                 see it freezes.
>
>                 Any help?
>
>             Does the same code work in a C program? It seems like
>             waitpid() is just what
>             you need to do after PTRACE_ATTACH, but anyway I'd say
>             it's a good idea to
>             develop the low-level bits in C first, so that we're sure
>             it's the translation
>             to Gambas which is faulty, and not the algorithm.
>
>             Three other remarks:
>
>                * I'm certainly not running a random somebody's buggy
>             program as root.
>                  Can't you spawn a child process yourself and then use
>             PTRACE_TRACEME
>                  for debugging purposes? That shouldn't require root
>             privileges.
>
>                * You should also check return values of system calls.
>
>                * THIS MAILING LIST IS DEPRECATED. USE THE NEW ONE:
>             https://lists.gambas-basic.org/listinfo/user
>             <https://lists.gambas-basic.org/listinfo/user>
>
>             Regards,
>             Tobi
>
>         i also test it with c++ with codeblocks and it also freezes at
>         waitpid of WriteMemory function
>
>         how i spawn a child process?
>
>
>         ----[ Gambas mailing-list is hosted by
>         https://www.hostsharing.net ]----
>
>
>
>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180609/4b9f663c/attachment-0001.html>


More information about the User mailing list