Ejemplo n.º 1
0
 def addFile(self, file, parentDirName=None):
     buffer = jarray.zeros(self._bufsize, 'b')
     inputStream = FileInputStream(file)
     jarEntryName = file.getName()
     if parentDirName:
         jarEntryName = parentDirName + "/" + jarEntryName
     self.getJarOutputStream().putNextEntry(JarEntry(jarEntryName))
     read = inputStream.read(buffer)
     while read <> -1:
         self.getJarOutputStream().write(buffer, 0, read)
         read = inputStream.read(buffer)
     self.getJarOutputStream().closeEntry()
     inputStream.close()
Ejemplo n.º 2
0
 def addFile(self, file, parentDirName=None):
   buffer = jarray.zeros(self._bufsize, 'b')
   inputStream = FileInputStream(file)
   jarEntryName = file.getName()
   if parentDirName:
     jarEntryName = parentDirName + "/" + jarEntryName
   self.getJarOutputStream().putNextEntry(JarEntry(jarEntryName))
   read = inputStream.read(buffer)
   while read <> -1:
       self.getJarOutputStream().write(buffer, 0, read)
       read = inputStream.read(buffer)
   self.getJarOutputStream().closeEntry()
   inputStream.close()
Ejemplo n.º 3
0
def compareFileHashes(dxFileName, amFileName, msgId):
    dxFile = FileInputStream(dxFileName)
    dxMsgContentHash = sha.new(str(dxFile.read()))
    dxFile.close()
    amFile = FileInputStream(amFileName)
    amMsgContentHash = sha.new(str(amFile.read()))
    amFile.close()

    if dxMsgContentHash.digest() == amMsgContentHash.digest():
        #print "message has same hash on AM partition and DX", msgId
        printQueue.append("output message " +  str(msgId) + " is present in DX")
        return True
    else:
        printErrorToRemigrate(msgId, " content hash differ on AM partition and DX. dx hash: " + dxMsgContentHash.hexdigest() + " am hash: " + amMsgContentHash.hexdigest())
        return False
Ejemplo n.º 4
0
def getFileBytes(path):
    baos = ByteArrayOutputStream()
    fis = FileInputStream(File(path))
    bytes = jarray.zeros(1024, 'b')
    while 1 == 1:
        readSize = fis.read(bytes)
        if (readSize == -1):
            break
        baos.write(bytes, 0, readSize)
    return baos.toByteArray()
def add_folder(zos, folder_name, base_folder_name):
    f = File(folder_name)
    if not f.exists():
        return
    if f.isDirectory():
        for f2 in f.listFiles():
            add_folder(zos, f2.absolutePath, base_folder_name)
        return
    entry_name = folder_name[len(base_folder_name) + 1:len(folder_name)]
    ze = ZipEntry(entry_name)
    zos.putNextEntry(ze)
    input_stream = FileInputStream(folder_name)
    buffer = zeros(1024, 'b')
    rlen = input_stream.read(buffer)
    while (rlen > 0):
        zos.write(buffer, 0, rlen)
        rlen = input_stream.read(buffer)
    input_stream.close()
    zos.closeEntry()
Ejemplo n.º 6
0
def add_folder(zos, folder_name, base_folder_name):
    f = File(folder_name)
    if not f.exists():
        return
    if f.isDirectory():
        for f2 in f.listFiles():
            add_folder(zos, f2.absolutePath, base_folder_name)
        return
    entry_name = folder_name[len(base_folder_name) + 1:len(folder_name)]
    ze = ZipEntry(entry_name)
    zos.putNextEntry(ze)
    input_stream = FileInputStream(folder_name)
    buffer = zeros(1024, 'b')
    rlen = input_stream.read(buffer)
    while (rlen > 0):
        zos.write(buffer, 0, rlen)
        rlen = input_stream.read(buffer)
    input_stream.close()
    zos.closeEntry()
Ejemplo n.º 7
0
 def readBinaryFile(cls, rootFile):
     """ generated source for method readBinaryFile """
     in_ = FileInputStream(rootFile)
     out = ByteArrayOutputStream()
     #  Transfer bytes from in to out
     buf = [None]*1024
     while in_.read(buf) > 0:
         out.write(buf)
     in_.close()
     return out.toByteArray()
Ejemplo n.º 8
0
    def test_read_file(self):
        from java.io import FileInputStream
        from java.lang import String

        filename = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                'data/read_file.txt')
        fin = FileInputStream(filename)
        ar = jarray(20, JBYTE_ID)
        count = fin.read(ar)
        s = String(ar, 0, count)
        self.assertEqual(str(s).strip(), 'aewrv3v')
Ejemplo n.º 9
0
    def test_read_file(self):
        from java.io import FileInputStream
        from java.lang import String

        filename = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            'data/read_file.txt')
        fin = FileInputStream(filename)
        ar = jarray(20, JBYTE_ID)
        count = fin.read(ar)
        s = String(ar, 0, count)
        self.assertEqual(str(s).strip(), 'aewrv3v')
Ejemplo n.º 10
0
def getByteArray(fileUrl):
  file = File(fileUrl);
  inputStream = FileInputStream(file)
  length = file.length()
  bytes = jarray.zeros(length, 'b')
  #Read in the bytes
  offset = 0
  numRead = 0
  while offset<length:
      if numRead>= 0:
          print numRead
          numRead=inputStream.read(bytes, offset, length-offset)
          offset = offset + numRead
  return bytes
Ejemplo n.º 11
0
 def write(self, name, file):
     fp = self.getFile(name)
     if isinstance(file, ByteArrayOutputStream):
         file.writeTo(fp)
     else:
         if isinstance(file, type('')):
             file = FileInputStream(file)
         data = jarray.zeros(1024 * 4, 'b')
         #print 'writing', file,
         while 1:
             n = file.read(data)
             #print n,
             if n == -1: break
             fp.write(data, 0, n)
Ejemplo n.º 12
0
	def write(self, name, file):
		fp = self.getFile(name)
		if isinstance(file, ByteArrayOutputStream):
			file.writeTo(fp)
		else:
			if isinstance(file, type('')):
				file = FileInputStream(file)
			data = jarray.zeros(1024*4, 'b')
			#print 'writing', file,
			while 1:
				n = file.read(data)
				#print n,
				if n == -1: break
				fp.write(data, 0, n)
def __readBytes(file):
	# Returns the contents of the file in a byte array.
	inputstream = FileInputStream(file)
    
	# Get the size of the file
	length = file.length()

	# Create the byte array to hold the data
	bytes = jarray.zeros(length, "b")

	# Read in the bytes
	offset = 0
	numRead = 1
        while (offset < length) and (numRead > 0):
		numRead = inputstream.read(bytes, offset, len(bytes) - offset)
		offset += numRead

	# Ensure all the bytes have been read in
	if offset < len(bytes):
		log.warn("Could not read entire contents of '" + file.getName()) 

	# Close the input stream and return bytes
	inputstream.close()
	return bytes
Ejemplo n.º 14
0
def __readBytes(file):
    # Returns the contents of the file in a byte array.
    inputstream = FileInputStream(file)

    # Get the size of the file
    length = file.length()

    # Create the byte array to hold the data
    bytes = jarray.zeros(length, "b")

    # Read in the bytes
    offset = 0
    numRead = 1
    while (offset < length) and (numRead > 0):
        numRead = inputstream.read(bytes, offset, len(bytes) - offset)
        offset += numRead

    # Ensure all the bytes have been read in
    if offset < len(bytes):
        log.warn("Could not read entire contents of '" + file.getName())

    # Close the input stream and return bytes
    inputstream.close()
    return bytes
Ejemplo n.º 15
0
    def __findGeoLocationsInFile(self, file, abstractFile):

        tempBytes = bytearray([0] * 2) # will temporarily hold bytes to be converted into the correct data types

        try:
            inputStream = FileInputStream(file)

            inputStream.read(tempBytes) # version

            tempBytes = bytearray([0] * 2)
            inputStream.read(tempBytes) # number of location entries

            iterations = BigInteger(tempBytes).intValue()

            for i in range(iterations): # loop through every entry
                tempBytes = bytearray([0] * 2)
                inputStream.read(tempBytes)

                tempBytes = bytearray([0])
                inputStream.read(tempBytes)

                while BigInteger(tempBytes).intValue() != 0: # pass through non important values until the start of accuracy(around 7-10 bytes)
                    if 0 > inputStream.read(tempBytes):
                        break # we've passed the end of the file, so stop

                tempBytes = bytearray([0] * 3)
                inputStream.read(tempBytes)
                if BigInteger(tempBytes).intValue() <= 0: # This refers to a location that could not be calculated
                    tempBytes = bytearray([0] * 28) # read rest of the row's bytes
                    inputStream.read(tempBytes)
                    continue
                accuracy = "" + BigInteger(tempBytes).intValue()

                tempBytes = bytearray([0] * 4)
                inputStream.read(tempBytes)
                confidence = "" + BigInteger(tempBytes).intValue()

                tempBytes = bytearray([0] * 8)
                inputStream.read(tempBytes)
                latitude = CacheLocationAnalyzer.toDouble(bytes)

                tempBytes = bytearray([0] * 8)
                inputStream.read(tempBytes)
                longitude = CacheLocationAnalyzer.toDouble(bytes)

                tempBytes = bytearray([0] * 8)
                inputStream.read(tempBytes)
                timestamp = BigInteger(tempBytes).longValue() / 1000

                attributes = ArrayList()
                artifact = abstractFile.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT)
                attributes.add(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE, AndroidAnalyzer.MODULE_NAME, latitude))
                attributes.add(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE, AndroidAnalyzer.MODULE_NAME, longitude))
                attributes.add(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, AndroidModuleFactorymodule.Name, timestamp))
                attributes.add(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, AndroidAnalyzer.MODULE_NAME,
                    file.getName() + "Location History"))

                artifact.addAttributes(attributes)
                #Not storing these for now.
                #    artifact.addAttribute(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE.getTypeID(), AndroidModuleFactorymodule.moduleName, accuracy))
                #    artifact.addAttribute(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT.getTypeID(), AndroidModuleFactorymodule.moduleName, confidence))
                try:
                    # index the artifact for keyword search
                    blackboard = Case.getCurrentCase().getServices().getBlackboard()
                    blackboard.indexArtifact(artifact)
                except Blackboard.BlackboardException as ex:
                    self._logger.log(Level.SEVERE, "Unable to index blackboard artifact " + artifact.getArtifactID(), ex)
                    self._logger.log(Level.SEVERE, traceback.format_exc())
                    MessageNotifyUtil.Notify.error("Failed to index GPS trackpoint artifact for keyword search.", artifact.getDisplayName())

        except Exception as ex:
            self._logger.log(Level.SEVERE, "Error parsing Cached GPS locations to blackboard", ex)
            self._logger.log(Level.SEVERE, traceback.format_exc())
Ejemplo n.º 16
0
    try:
        Integer.byteValue()
    except:
        print 'regression:       no crash yet'
    #raise TypeError, 'test'

    print """
    ##################################################
    # array handling
    ##################################################
    """

    # just for fun
    fin = FileInputStream("configure")
    ar = jarray(20, JBYTE_ID)
    count = fin.read(ar)

    # strip any other lines, just want first
    if (10 in ar):
        count = ar.index(10)
        ar = ar[0:count]
    print 'configure starts ', String(ar, 0, count)
    fin.close()

    # array handling
    ar = testo.getStringArray()
    print 'string[] len:    ', len(ar)
    print '[0], [1], [2]:   ', ar[0], ar[1], ar[2]
    ar[0] = "new"
    ar[1] = None
    print '[0], [1]:        ', ar[0], ar[1]
Ejemplo n.º 17
0
Archivo: test.py Proyecto: Kroisse/jep
    try:
        Integer.byteValue()
    except:
        print 'regression:       no crash yet'
    #raise TypeError, 'test'

    print """
    ##################################################
    # array handling
    ##################################################
    """

    # just for fun
    fin = FileInputStream("configure")
    ar = jarray(20, JBYTE_ID)
    count = fin.read(ar)

    # strip any other lines, just want first
    if(10 in ar):
        count = ar.index(10)
        ar = ar[0:count]
    print 'configure starts ', String(ar, 0, count)
    fin.close()
    
    # array handling
    ar = testo.getStringArray()
    print 'string[] len:    ', len(ar)
    print '[0], [1], [2]:   ', ar[0], ar[1], ar[2]
    ar[0] = "new"
    ar[1] = None
    print '[0], [1]:        ', ar[0], ar[1]
Ejemplo n.º 18
0
from java.io import FileInputStream as FI
from java.io import FileOutputStream as FO

file_read = FI("file1.txt")
file_write = FO("file2.txt")
while True:
    ch = file_read.read()
    if ch != -1:
        file_write.write(chr(ch))
    else:
        break

file_read.close()
file_write.close()