Header
|
Leading guard(0xFC)
|
User data(0xEB)
|
Tailing guard(0xFC)
|
空闲内存(0xDD)
|
Before
if (m_hsession) gblHandles->ReleaseUserHandle( m_hsession );
if (m_dberr) delete m_dberr;
After
if (m_hsession) {
_Insight_stack_call(0);
gblHandles->ReleaseUserHandle(m_hsession);
_Insight_after_call();
}
_Insight_ptra_check(1994, (void **) &m_dberr, (void *) m_dberr);
if (m_dberr) {
_Insight_deletea(1994, (void **) &m_dberr, (void *) m_dberr, 0);
delete m_dberr;
}
|
void
*
__bound_ptr_add
(
void
*
p
,
int
offset
)
{
unsigned
long
addr
= (
unsigned
long
)
p
;
BoundEntry
*
e
;
#if
defined(BOUND_DEBUG)
printf
(
"add: 0x%x %d/n"
, (
int
)
p
,
offset
);
#endif
e
=
__bound_t1
[
addr
>> (
BOUND_T2_BITS
+
BOUND_T3_BITS
)];
e
= (
BoundEntry
*)((
char
*)
e
+
((
addr
>> (
BOUND_T3_BITS
-
BOUND_E_BITS
)) &
((
BOUND_T2_SIZE
- 1) <<
BOUND_E_BITS
)));
addr
-=
e
->
start
;
if
(
addr
>
e
->
size
) {
e
=
__bound_find_region
(
e
,
p
);
addr
= (
unsigned
long
)
p
-
e
->
start
;
}
addr
+=
offset
;
if
(
addr
>
e
->
size
)
return
INVALID_POINTER
;
/* return an invalid pointer */
return
p
+
offset
;
}
static
void
__bound_check
(
const
void
*
p
,
size_t
size
)
{
if
(
size
== 0)
return
;
p
=
__bound_ptr_add
((
void
*)
p
,
size
);
if
(
p
==
INVALID_POINTER
)
bound_error
(
"invalid pointer"
);
}
|
void
*
__bound_malloc
(
size_t
size
,
const
void
*
caller
)
{
void
*
ptr
;
/* we allocate one more byte to ensure the regions will be
separated by at least one byte. With the glibc malloc, it may
be in fact not necessary */
ptr
=
libc_malloc
(
size
+ 1);
if
(!
ptr
)
return
NULL
;
__bound_new_region
(
ptr
,
size
);
return
ptr
;
}
void
__bound_free
(
void
*
ptr
,
const
void
*
caller
)
{
if
(
ptr
==
NULL
)
return
;
if
(
__bound_delete_region
(
ptr
) != 0)
bound_error
(
"freeing invalid region"
);
libc_free
(
ptr
);
}
|
void
*
__bound_memcpy
(
void
*
dst
,
const
void
*
src
,
size_t
size
)
{
__bound_check
(
dst
,
size
);
__bound_check
(
src
,
size
);
/* check also region overlap */
if
(
src
>=
dst
&&
src
<
dst
+
size
)
bound_error
(
"overlapping regions in memcpy()"
);
return
memcpy
(
dst
,
src
,
size
);
}
|
void
main
(
void
)
{
CreateProcess
( ...,
DEBUG_ONLY_THIS_PROCESS
,... ) ;
while
( 1 ==
WaitForDebugEvent
( ... ) )
{
if
( EXIT_PROCESS )
{
break
;
}
ContinueDebugEvent
( ... ) ;
}
}
|
#include
#include
#include
#include
#include
etc. */
int
main
(
int
argc
,
char
*
argv
[])
{ pid_t
traced_process
;
struct
user_regs_struct
regs
;
long
ins
;
if
(
argc
!= 2) {
printf
(
"Usage: %s
argv
[0],
argv
[1]);
exit
(1);
}
traced_process
=
atoi
(
argv
[1]);
ptrace(PTRACE_ATTACH,
traced_process
,
NULL
,
NULL
);
wait(
NULL
);
ptrace(PTRACE_GETREGS,
traced_process
,
NULL
, &
regs
);
ins
= ptrace(PTRACE_PEEKTEXT,
traced_process
,
regs
.eip,
NULL
);
printf
(
"EIP: %lx Instruction executed: %lx/n"
,
regs
.eip,
ins
);
ptrace(PTRACE_DETACH,
traced_process
,
NULL
,
NULL
);
return
0;
}
|