def decodeResponse(self, data): decoder = javaobj.JavaObjectUnmarshaller(StringIO.StringIO(data)) int1 = struct.unpack('>I', decoder.readObject())[0] keyArray = decoder.readObject() key = ''.join('{:02x}'.format(x & 0xff) for x in keyArray) count = struct.unpack('>I', decoder.readObject())[0] return (int1, key, count)
def wekaModel(inputFileName, outputFileName, opts=''): modelFile = open(inputFileName, "rb") marshaller = javaobj.JavaObjectUnmarshaller(modelFile) model = marshaller.readObject() opts = processOptions(opts) with open(outputFileName, "w") as output: output.write(recoverWeka(model, opts))
def test_sun_example(self): marshaller = javaobj.JavaObjectUnmarshaller( self.read_file("sunExample.ser", stream=True)) pobj = marshaller.readObject() self.assertEqual(pobj.value, 17) self.assertTrue(pobj.next) pobj = marshaller.readObject() self.assertEqual(pobj.value, 19) self.assertFalse(pobj.next)
def decodeResponse(self, data): decoder = javaobj.JavaObjectUnmarshaller(io.BytesIO(data)) int1 = struct.unpack('>I', decoder.readObject())[0] # If int1 is 16, then we have valid data in the following object. If it's 0, # then no data follows print "INT RESPONSE: {0}".format(int1) if int1 > 0: keyArray = decoder.readObject() key = ''.join('{:02x}'.format(x & 0xff) for x in keyArray) count = struct.unpack('>I', decoder.readObject())[0] print "COUNT: {0}".format(count) else: key = None count = 0 return (int1, key, count)
def read_ec(ec_path): pobj = '' with open(ec_path, mode='rb') as f: marshaller = javaobj.JavaObjectUnmarshaller(f) pobj = marshaller.readObject() return pobj
import javaobj import sys import io if __name__ == "__main__": import logging javaobj._log.setLevel(logging.DEBUG) jobj = file(sys.argv[1]).read()[16 + 5:] print((repr(jobj[:100]))) pobj, index = javaobj.loads(jobj) rest = jobj[index:] import zlib print((repr(rest[:100]))) datastr = zlib.decompress(rest, -15) stream = io.StringIO(datastr) m = javaobj.JavaObjectUnmarshaller(stream) data = m.readObject() while len(data) == 2: print((data[0].classdesc.name)) #datastr = datastr[data[1]:] x = stream.read(3) print(("data left", [hex(ord(k)) for k in x])) stream.seek(-3, 1) #x = stream.read(10) #print "data left", [hex(ord(k)) for k in x] #stream.seek(-10, 1) #data = javaobj.loads(datastr) data = m.readObject() print(data) if data[0] == "END": print("end...")
import javaobj import pickle import logging marshaller = javaobj.JavaObjectUnmarshaller(open('f.out', 'rb')) pobj = marshaller.readObject() def get(): my_objects = [] for i in pobj.get_class().fields_names: my_objects.append(i) for j in my_objects: print("--------------") print(getattr(pobj, j)) if __name__ == '__main__': get()
def decodeResponse(self, data): decoder = javaobj.JavaObjectUnmarshaller(io.BytesIO(data)) hmacArray = decoder.readObject() hmac = ''.join('{:02x}'.format(x & 0xff) for x in reversed(hmacArray)) return hmac
####################################################################################################### # OPENING MODEL FILE try: file = open(sys.argv[2], "w") except: print "Destination file invalid" exit() try: modelFile = open(sys.argv[1]) except: print "Model file invalid" exit() marshaller = javaobj.JavaObjectUnmarshaller(modelFile) obj = marshaller.readObject() ####################################################################################################### # Convert a float point number to its fixed point representation # returns a string that has this representation in hexidecimal. def toFxp(x): if math.isnan(x): return "INF_POS" if totalBits == 32: return "(FixedNum)0x%.8x" % (int(round(x * (1 << fixedBits))) & 0xFFFFFFFF) if totalBits == 16: return "(FixedNum)0x%.4x" % (int(round(x * (1 << fixedBits))) & 0xFFFF)
def extractTextGridFromAnalorFile(self, ifile): SuccessOrNot = False try: marshaller = javaobj.JavaObjectUnmarshaller(ifile) except IOError: ifile.seek(0, 0) return SuccessOrNot while True: # get one object pobj = marshaller.readObject() if pobj == 'FIN' or \ pobj == '' : break if pobj == 'F0': self.xmin, self.xmax = marshaller.readObject() # check if is at the tiers' header if pobj == 'TIRES': # get tier number tier_num = marshaller.readObject() tier_num = struct.unpack('>i', tier_num)[0] while tier_num: # get the metadata of tier tlims = marshaller.readObject() typ = marshaller.readObject() nom = auto_decode(marshaller.readObject()) mots = auto_decode(marshaller.readObject()) bornes = marshaller.readObject() nomGuide = auto_decode(marshaller.readObject()) # translation between 2 type naming # between Analor and Praat version if typ == 'INTERVALLE': tier_type = 'IntervalTier' elif typ == 'POINT': tier_type = 'TextTier' else: raise Exception('Tiertype does not exist.') # form a tier tier = pympi.Praat.Tier(0, 0, name=nom, tier_type=tier_type) self.tiers.append(tier) tier.xmin = tlims[0] tier.xmax = tlims[-1] if tier.tier_type == 'IntervalTier': for x1, x2, text in zip(bornes, bornes[1:], mots): tier.intervals.append((x1, x2, text)) elif tier.tier_type == 'TextTier': for x1, text in zip(bornes, mots): tier.intervals.append((x1, text)) else: raise Exception('Tiertype does not exist.') # uncount the number of tiers remain to process if tier_num > 0: tier_num -= 1 SuccessOrNot = True ifile.seek(0, 0) return SuccessOrNot
#!/usr/bin/env python2 import javaobj m = javaobj.JavaObjectUnmarshaller(open("CompatibleInfo.cfg")) o = m.readObject() print o.annotations[2]
def read_object(infile): marshaller = javaobj.JavaObjectUnmarshaller(open(infile)) pobj = marshaller.readObject() return pobj