Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
matrix1001 committed Oct 31, 2018
1 parent 1965da3 commit bbdf881
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
75 changes: 46 additions & 29 deletions HeapInspect.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/python2
from proc_util import *
from libc_util import *
from auxiliary import *
import struct
import re
import sys
import os
import argparse

def u64(data):
return struct.unpack('<Q', data.ljust(8, '\0'))[0]
Expand Down Expand Up @@ -290,7 +292,8 @@ def indexed_chunks(self, chunk_dict, typ='', align=0):
return '\n'.join(lines)

def banner(self, banner):
return '='*25 + '{:^30}'.format(banner) + '='*25
w, h = terminal_size()
return '{:=^{width}}'.format(' {} '.format(banner), width=w)

def banner_index(self, banner, index):
return '{:}[{:}]:'.format(banner, index)
Expand Down Expand Up @@ -444,47 +447,61 @@ def all(self):

@property
def basic(self):
return '''libc_version:{}
return '''libc_version:{}
arch:{}
tcache_enable:{}
libc_base:{}
heap_base:{}'''.format(
color.yellow(self.hi.libc_version),
color.yellow(self.hi.arch),
color.yellow(self.hi.tcache_enable),
color.blue(hex(self.hi.libc_base)),
color.blue(hex(self.hi.heap_base)))
color.yellow(self.hi.libc_version),
color.yellow(self.hi.arch),
color.yellow(self.hi.tcache_enable),
color.blue(hex(self.hi.libc_base)),
color.blue(hex(self.hi.heap_base)))


def banner(self, msg, color1='white'):
w, h = terminal_size()
return color.__getattr__(color1)('{:=^{width}}'.format(' {} '.format(msg), width=w))

if __name__ == '__main__':
pid = int(sys.argv[1])
parser = argparse.ArgumentParser(
prog='HeapInspect.py',
description='''Inspect your heap by a given pid.
Author:matrix1001
Github:https://github.com/matrix1001/heapinspect''')
parser.add_argument('--raw', action='store_true', help='show more detailed chunk info')
parser.add_argument('--rela', action='store_true', help='show relative detailed chunk info')
parser.add_argument('pid', type=int, help='pid of the process')
parser.add_argument('-x', nargs='*', help='''ignore: hc(heapchunks) fb(fastbins) sb(smallbins) lb(largebins) ub(unsortedbins)
tc(tcache) !put this argument at last!''')

args = parser.parse_args()

pid = args.pid

hi = HeapInspector(pid)
r = hi.record
#print()

#hs = HeapShower(r)
#print(hs.heap_chunks)
#print(hs.fastbins)
#print(hs.unsortedbins)
#print(hs.smallbins)
#print(hs.largebins)
#print(hs.tcache_chunks)

#print('\nrelative mode\n')
#hs.relative = True
#print(hs.heap_chunks)
#print(hs.fastbins)
#print(hs.unsortedbins)
#print(hs.smallbins)
#print(hs.largebins)
#print(hs.tcache_chunks)

pp = PrettyPrinter(r)
print(pp.all)
ign = args.x or []
if args.rela:
hs = HeapShower(r)
hs.relative = True
if 'hc' not in ign: print(hs.heap_chunks)
if 'fb' not in ign: print(hs.fastbins)
if 'ub' not in ign: print(hs.unsortedbins)
if 'sb' not in ign: print(hs.smallbins)
if 'lb' not in ign: print(hs.largebins)
if 'tc' not in ign: print(hs.tcache_chunks)
elif args.raw:
hs = HeapShower(r)
if 'hc' not in ign: print(hs.heap_chunks)
if 'fb' not in ign: print(hs.fastbins)
if 'ub' not in ign: print(hs.unsortedbins)
if 'sb' not in ign: print(hs.smallbins)
if 'lb' not in ign: print(hs.largebins)
if 'tc' not in ign: print(hs.tcache_chunks)
else:
pp = PrettyPrinter(r)
print(pp.all)



Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ A quick use of this tool.

![pp2](img/pp2.png)

![pp3](img/pp3.png)
![raw1](img/raw1.png)

![rela1](img/rela1.png)


## Basic

Pretty easy to use. I will make it a package in the first release.
Pretty easy to use. I will make it a package later.

```python
from HeapInspect import *
Expand Down Expand Up @@ -112,6 +114,12 @@ Core script of this project. `HeapInspector` parses `heap` and `main_arena`. `He

# Devlog

## 2018/10/31 version 0.1.0

first release

- better cmdline option

## 2018/10/30 version 0.0.8

next version will be a release.
Expand Down
Binary file added img/raw1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/rela1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bbdf881

Please sign in to comment.