[Valgrind-users] About wrapper

2018-07-29 Thread shuai xi
Hello developers:
I want to write a tool for valgrind base on memcheck. I use the  '_WRAP_
macros' to wrap malloc in libc, but there show me an error:

valgrind: m_redir.c:638 (vgPlain_redir_notify_new_DebugInfo): Assertion
'is_plausible_guest_addr(sym_avmas.main)' failed.
Segmentation fault (core dumped)

The code i add to 'mc_main.c' is:
long I_WRAP_SONAME_FNNAME_ZU(libcZdsoZd6,malloc) ( long n )
{
   char *  r;
   OrigFn fn;
   VALGRIND_GET_ORIG_FN(fn);
   CALL_FN_W_W(r, fn, n);
   //cloak_malloc_addr = r;
   return r;
}

(I has already disable the malloc replacement by deleting
vgpreload_memcheck-amd64-linux.so.)

Thanks
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


[Valgrind-users] how to change tmp value in dirty call

2018-08-15 Thread shuai xi
Hi@all,

I am trying to develop a valgrind tool base on memcheck.

Now i can get a shadow tmp id in memcheck's dirty call but i don't know how
to change this tmp's value. Can i change or get this tmp's value by this
id? Is there any Valgrind's API can do this?

Thanks
Shuai xi
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


[Valgrind-users] how to change the a register value of guest code in dirty call

2018-08-17 Thread shuai xi
Hello @all,

Follow the memcheck's code, i insert a dirty call in IRSB. Now i want to
get and change a register(like rax) value in this dirty call.

In vex , Register often shows as 't19 = GET:I64(16)'  or 'PUT(16) = t22'.

Can i get the register's real address and change its value by the num 16?

i read the code of vex's translate. I seems that there has no global values
to store this information. Is there some ways to get this value?

Very Thanks!!
Shuai xi
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


[Valgrind-users] About how to get the guest code memory

2018-08-20 Thread shuai xi
Hi@all,

I add some hooks in the vgpreload*.so and get some information from it. The
vgpreload*.so is a dynamically library  loaded in the guest code.

I want to get this information to do some analysis. But i don't know how to
get this information from guest code memory to valgrind memory space.

I attempt to use a global variable to store this information, but valgrind
show me a error that it can not find this global variable's symbol. Because
this global variable is in guest code memory space.

I attempt to write this information in file, because i hook the function
malloc.

Is there some solution like 'share memory' to deal this problem?

Very Thanks
Xi shuai
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


[Valgrind-users] About how to turn off the malloc hook

2018-07-15 Thread shuai xi
 hello developers,
I want to reuse the shadow memory part of  memcheck , but do not want to
use the malloc hook part.
When I set the 'VG_(needs).malloc_replacement = False',the malloc hook
part  seems still to be working.
Which code do I need to modify to make malloc replace invalid?
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


[Valgrind-users] How to invalidate the malloc replacement

2018-07-22 Thread shuai xi
hello developers,
sorry to ask this question again.
When i delete the 'VG_(needs_malloc_replacement) (MC_(malloc).)' ,
valgrind show me the error :'--7969-- VG_USERREQ__CLIENT_CALL1: func=0x0'.
It seems that the replace system is still working,but don't know which
address to call. so, what should i do to  invalidate the malloc replacement
? plz.
cloak
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


[Valgrind-users] About how to hook malloc to do sth and execute the original malloc

2018-07-12 Thread shuai xi
hello developer, i want to write a tool for valgrind to analysis an
program automatically.
I know that 'Memcheck's implementation of malloc has "nothing to do" with
glibc's implementation' after readind some code of valgrind, but i want to
use the glibc's malloc to avoid changing heap layout.
Memcheck sets the VG_(needs_malloc_replacement) to hook malloc and exec
MC_(malloc) instead of real malloc. It's very convenient. So can i get the
address of the original malloc in  MC_(malloc) and exec it?
if not,can i use I_WRAP_SONAME_FNNAME_ZU function to hook malloc in my
valgrind tool's code?
thanks.
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] About how to hook malloc to do sth and execute the original malloc

2018-07-12 Thread shuai xi
 thank you for your answer.
But when i use  _WRAP_ macros like following code, it gives me an error.
*code:*
long I_WRAP_SONAME_FNNAME_ZU(libcZdsoZd6,malloc) ( long n )
{
   char *  r;
   OrigFn fn;
   printf("1\n");
   VALGRIND_GET_ORIG_FN(fn);
   CALL_FN_W_W(r, fn, n);
   //printf("in wrapper1-post: fact(%d) = %x\n", n, r);
   return r;
}

/* --- */

int main ( void )
{
   char * r , *x, *y;
   //printf("computing fact(5)\n");
   //r = fact(5);
   r = malloc(0x20);
   x = malloc(0x20);
   printf("malloc(0x20) = %x \n",r );
   printf("malloc(0x20) = %x \n",x );

   return 0;
}
* error:*
==14498== Stack overflow in thread #1: can't grow stack to 0xfe04d000
==14498==
==14498== Process terminating with default action of signal 11 (SIGSEGV)
==14498==  Access not within mapped region at address 0xFE04DFFC
==14498== Stack overflow in thread #1: can't grow stack to 0xfe04d000
==14498==at 0x40B1183: _IO_doallocbuf (genops.c:394)
==14498==  If you believe this happened as a result of a stack
==14498==  overflow in your program's main thread (unlikely but
==14498==  possible), you can try to increase the size of the
==14498==  main thread stack using the --main-stacksize= flag.
==14498==  The main thread stack size used in this run was 8388608.

But when i comment out the ' printf("1\n"); ', It seems ok.

On Thu, Jul 12, 2018 at 7:24 PM Tom Hughes  wrote:

> On 12/07/18 10:26, shuai xi wrote:
>
> > I know that 'Memcheck's implementation of malloc has "nothing to do"
> > with glibc's implementation' after readind some code of valgrind, but i
> > want to use the glibc's malloc to avoid changing heap layout.
> > Memcheck sets the VG_(needs_malloc_replacement) to hook malloc and exec
> > MC_(malloc) instead of real malloc. It's very convenient. So can i
> > get the address of the original malloc in MC_(malloc) and exec it?
> > if not,can i use I_WRAP_SONAME_FNNAME_ZU function to hook malloc in my
> > valgrind tool's code?
>
> Yes if you want to wrap the function rather than replacing it
> then use the _WRAP_ macros and then your wrapper can get the
> original address and call it.
>
> Tom
>
> --
> Tom Hughes (t...@compton.nu)
> http://compton.nu/
>
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users