Skip to content

Commit

Permalink
Bugfix - os.path.dirname returned empty string
Browse files Browse the repository at this point in the history
This caused an exception while writing pcaps
Solution: http://stackoverflow.com/questions/7783308/os-path-dirname-file-returns-empty
  • Loading branch information
7h3rAm authored and 7h3rAm committed Nov 4, 2013
1 parent f53347a commit df12617
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pgtlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def add_packet(self, pkt):
self.packets.append(pkt)

def tcp_conn_to_client(self, dport, sport = 0):
"""tcp_conn_to_client returns a TCPConn() object, where TCP streams come from self.server and go to self.client.
"""tcp_conn_to_client returns a TCPConn() object, where TCP streams come from self.server and go to self.client.
This is useful when the server has to connect to the client, like in certain protocols (FTP active mode).
"""
assert(self.closed == False)
Expand Down Expand Up @@ -162,7 +162,7 @@ def to_client(self, data):
self.pcap.add_packet(pkt)

def to_server(self, data):
assert(self.closed == False)
assert(self.closed == False)

for offset in range(0, len(data), 1200):
piece = data[offset:offset+1200]
Expand All @@ -177,11 +177,11 @@ def to_server(self, data):
class FileObj:
def __init__(self, filename):
self.filename = os.path.basename(filename)
self.dirname = os.path.dirname(filename)
self.dirname = os.path.dirname(os.path.abspath(filename))
self.filedata = open(filename, 'rb').read()

def get_raw(self, prefix=""):
return prefix + self.filedata
return prefix + self.filedata

def get_gzip(self, prefix=""):
s = StringIO.StringIO()
Expand All @@ -196,4 +196,3 @@ def get_zlib(self,prefix=""):

def get_deflate(self, prefix=""):
return self.get_zlib(prefix)

0 comments on commit df12617

Please sign in to comment.