Skip to content

Commit

Permalink
Cleanup (#385)
Browse files Browse the repository at this point in the history
* cleanup ELF parsing

* minor ARM (embedded) bugfix on infinite-loop detection

* cobra.cluster made usable after py3 upgrade.

converting from str to bytes for network comms, but leaving everything
as str's otherwise.
  • Loading branch information
atlas0fd00m committed Mar 29, 2021
1 parent 2db9244 commit 0fe1433
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
21 changes: 13 additions & 8 deletions cobra/cluster.py
Expand Up @@ -9,14 +9,14 @@
import struct
import socket
import logging
import urllib2
import traceback
import threading
import subprocess
import multiprocessing
import urllib.request as url_req

import cobra
import dcode
from . import dcode

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -316,7 +316,7 @@ def announceWork(self):

else:
buf = "cobra:%s:%s:%d" % (self.name, self.cobraname, self.cobrad.port)
self.sendsock.sendto(buf, (cluster_ip, cluster_port))
self.sendsock.sendto(buf.encode('utf-8'), (cluster_ip, cluster_port))

def runServer(self, firethread=False):

Expand Down Expand Up @@ -355,7 +355,7 @@ def addWork(self, work):

# If this work has no ID, give it one
if work.id is None:
work.id = self.widiter.next()
work.id = next(self.widiter)

self.qcond.acquire()
if self.maxsize is not None:
Expand Down Expand Up @@ -502,7 +502,7 @@ def __init__(self, name, maxwidth=multiprocessing.cpu_count(), docode=False):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind(("",cluster_port))
mreq = struct.pack("4sL", socket.inet_aton(cluster_ip), socket.INADDR_ANY)
mreq = struct.pack(b"4sL", socket.inet_aton(cluster_ip), socket.INADDR_ANY)
self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

def processWork(self):
Expand All @@ -515,6 +515,9 @@ def processWork(self):
if self.width >= self.maxwidth:
continue

# make it a string again..
buf = buf.decode('utf-8')

server, svrport = sockaddr

if not buf.startswith("cobra"):
Expand All @@ -531,6 +534,7 @@ def processWork(self):
continue

if (self.name != name) and (self.name != "*"):
logger.debug("skipping work, not me...(%r != %r)", name, self.name)
continue

port = int(portstr)
Expand Down Expand Up @@ -571,17 +575,17 @@ def proxyAnnounceWork(self, name, cobraname, port):
# Get the host IP from the connection information
host, x = cobra.getCallerInfo()
buf = "cobra:%s:%s:%d:%s" % (name, cobraname, port, host)
self.sendsock.sendto(buf, (cluster_ip, cluster_port))
self.sendsock.sendto(buf.encode('utf-8'), (cluster_ip, cluster_port))

def getHostPortFromUri(uri):
"""
Take the server URI and pull out the
host and port for use in building the
dcode uri.
"""
x = urllib2.Request(uri)
x = url_req.Request(uri)
port = None
hparts = x.get_host().split(":")
hparts = x.host.split(":")
host = hparts[0]
if len(hparts):
port = int(hparts[1])
Expand Down Expand Up @@ -633,6 +637,7 @@ def runAndWaitWork(server, work):
def getAndDoWork(uri, docode=False):

# If we wanna use dcode, set it up
logger.debug("getAndDoWork: uri=", uri)
try:
if docode:
host,port = getHostPortFromUri(uri)
Expand Down
4 changes: 2 additions & 2 deletions vivisect/analysis/arm/emulation.py
Expand Up @@ -111,8 +111,8 @@ def prehook(self, emu, op, starteip):
logger.info("0x%x: +++++++++++++++ infinite loop +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", op.va)
if op.va not in self.infloops:
self.infloops.append(op.va)
if 'InfiniteLoops' not in vw.getVaSetNames():
vw.addVaSet('InfiniteLoops', (('va', vivisect.VASET_ADDRESS, 'function', vivisect.VASET_STRING)))
if 'InfiniteLoops' not in self.vw.getVaSetNames():
self.vw.addVaSet('InfiniteLoops', (('va', vivisect.VASET_ADDRESS, 'function', vivisect.VASET_STRING)))
self.vw.setVaSetRow('InfiniteLoops', (op.va, self.fva))

except Exception as e:
Expand Down
5 changes: 4 additions & 1 deletion vivisect/parsers/elf.py
Expand Up @@ -597,7 +597,7 @@ def applyRelocs(elf, vw, addbase=False, baseaddr=0):
vw.makeImport(rlva, "*", dmglname)
vw.setComment(rlva, name)

elif rtype in (Elf.R_386_32, Elf.R_386_COPY):
elif rtype in (Elf.R_386_32, Elf.R_386_COPY, Elf.R_X86_64_TPOFF64):
pass

else:
Expand Down Expand Up @@ -754,6 +754,9 @@ def applyRelocs(elf, vw, addbase=False, baseaddr=0):
vw.makeName(rlva, dmglname, makeuniq=True)
vw.setComment(rlva, name)

elif rtype == Elf.R_ARM_COPY:
pass

else:
logger.warning('unknown reloc type: %d %s (at %s)', rtype, name, hex(rlva))
logger.info(r.tree())
Expand Down

0 comments on commit 0fe1433

Please sign in to comment.