[Gambas-user] external function freezes

Demosthenes Koptsis demosthenesk at gmail.com
Sat Jun 9 17:45:24 CEST 2018


Well after many tries and search at Google i found that you cannot use 
waitpid more than once.

i had to attach ptrace then call waitpid and the make all read/writes to 
memory and finaly detach ptrace.

i attach a working example for test and try. You have to open and run it 
as root.


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/16e40095/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Memory-working.tar.gz
Type: application/gzip
Size: 13603 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180609/16e40095/attachment-0001.gz>


More information about the User mailing list