public Capstone(int arch, int mode) { cs = (CS)Native.loadLibrary("capstone", CS.class); int version = cs.cs_version(null, null); if (version != (CS_API_MAJOR << 8) + CS_API_MINOR) { throw new RuntimeException("Different API version between core & binding (CS_ERR_VERSION)"); } this.arch = arch; this.mode = mode; ns = new NativeStruct(); ns.handleRef = new NativeLongByReference(); if (cs.cs_open(arch, mode, ns.handleRef) != CS_ERR_OK) { throw new RuntimeException("ERROR: Wrong arch or mode"); } ns.csh = ns.handleRef.getValue(); this.detail = CS_OPT_OFF; this.diet = cs.cs_support(CS_SUPPORT_DIET); }
public NativeLong getPrivateKeyHandle(RtPkcs11 pkcs11, NativeLong session) throws Pkcs11CallerException { CK_ATTRIBUTE[] template = (CK_ATTRIBUTE[]) (new CK_ATTRIBUTE()).toArray(2); final NativeLongByReference keyClass = new NativeLongByReference(Pkcs11Constants.CKO_PRIVATE_KEY); template[0].type = Pkcs11Constants.CKA_CLASS; template[0].pValue = keyClass.getPointer(); template[0].ulValueLen = new NativeLong(NativeLong.SIZE); ByteBuffer idBuffer = ByteBuffer.allocateDirect(mKeyPairId.length); idBuffer.put(mKeyPairId); template[1].type = Pkcs11Constants.CKA_ID; template[1].pValue = Native.getDirectBufferPointer(idBuffer); template[1].ulValueLen = new NativeLong(mKeyPairId.length); return findObject(pkcs11, session, template); }
private NativeLong findObject(RtPkcs11 pkcs11, NativeLong session, CK_ATTRIBUTE[] template) throws Pkcs11CallerException { NativeLong rv = pkcs11.C_FindObjectsInit(session, template, new NativeLong(template.length)); if (!rv.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv); NativeLong objects[] = new NativeLong[1]; NativeLongByReference count = new NativeLongByReference(new NativeLong(objects.length)); rv = pkcs11.C_FindObjects(session, objects, new NativeLong(objects.length), count); NativeLong rv2 = pkcs11.C_FindObjectsFinal(session); if (!rv.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv); else if (!rv2.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv2); else if (count.getValue().intValue() <= 0) return null; return objects[0]; }
Token(NativeLong slotId) throws Pkcs11CallerException { RtPkcs11 pkcs11 = RtPkcs11Library.getInstance(); synchronized (pkcs11) { mId = slotId; initTokenInfo(); NativeLongByReference session = new NativeLongByReference(); NativeLong rv = RtPkcs11Library.getInstance().C_OpenSession(mId, Pkcs11Constants.CKF_SERIAL_SESSION, null, null, session); if (!rv.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv); mSession = session.getValue(); try { initCertificatesList(pkcs11); } catch (Pkcs11CallerException exception) { try { close(); } catch (Pkcs11CallerException exception2) { } throw exception; } } }
@Override public AudioFormat readHeader() throws IOException { NativeLongByReference sr = new NativeLongByReference(); IntByReference ch = new IntByReference(), en = new IntByReference(); throwOnError(mpg123_getformat(h, sr, ch, en)); safeBuffer = mpg123_safe_buffer(); format.setBitDepth(AudioFormat.bitDepthFromNumber(mpg123_samplesize(en.getValue()) * 8)); format.setChannels(ch.getValue()); format.setSampleRate(sr.getValue().intValue()); long ret2 = mpg123_length(h).longValue(); if(ret2 != MPG123_ERR) format.setSamples(ret2); tmpBuff = MemoryUtils.createByteBuffer(safeBuffer); return format; }
@Before public void setUp() throws Exception { // Create client ID clientName = Foundation.cfString("Client"); MIDINotifyProc notifyProc = new CoreMidiLibrary.MIDINotifyProc() { @Override public void apply(MIDINotification message, Pointer refCon) { } }; NativeLongByReference nativeLongByReference = new NativeLongByReference(); LOGGER.info(nativeLongByReference.getValue().longValue()); int midiClientCreate = CoreMidiLibrary.INSTANCE.MIDIClientCreate(clientName, notifyProc, null, nativeLongByReference); LOGGER.info(nativeLongByReference.getValue().longValue()); LOGGER.info(midiClientCreate); }
/** * readProcessMemory to memory. */ long readProcessMemory(Pointer baseAddress, Memory goal) { NativeLong sizeAvalaible = new NativeLong(goal.size()); NativeLongByReference bytesReadRefernce = new NativeLongByReference(); boolean ret = MyKernel32.INSTANCE.ReadProcessMemory( _processInformation.hProcess.getPointer(), baseAddress, goal, sizeAvalaible, bytesReadRefernce); if (!ret) log("pid " + _pid + " ReadProcessMemory returns " + ret); long bytesRead = bytesReadRefernce.getValue().longValue(); return bytesRead; }
private Map<NativeLong, Certificate> getCertificatesWithCategory(RtPkcs11 pkcs11, CertificateCategory category) throws Pkcs11CallerException { CK_ATTRIBUTE[] template = (CK_ATTRIBUTE[]) (new CK_ATTRIBUTE()).toArray(2); NativeLongByReference certClass = new NativeLongByReference(Pkcs11Constants.CKO_CERTIFICATE); template[0].type = Pkcs11Constants.CKA_CLASS; template[0].pValue = certClass.getPointer(); template[0].ulValueLen = new NativeLong(NativeLong.SIZE); NativeLongByReference certCategory = new NativeLongByReference(new NativeLong(category.getValue())); template[1].type = Pkcs11Constants.CKA_CERTIFICATE_CATEGORY; template[1].pValue = certCategory.getPointer(); template[1].ulValueLen = new NativeLong(NativeLong.SIZE); NativeLong rv = pkcs11.C_FindObjectsInit(mSession, template, new NativeLong(template.length)); if (!rv.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv); NativeLong[] objects = new NativeLong[30]; NativeLongByReference count = new NativeLongByReference(new NativeLong(objects.length)); ArrayList<NativeLong> certs = new ArrayList<NativeLong>(); do { rv = pkcs11.C_FindObjects(mSession, objects, new NativeLong(objects.length), count); if (!rv.equals(Pkcs11Constants.CKR_OK)) break; certs.addAll(Arrays.asList(objects).subList(0, count.getValue().intValue())); } while (count.getValue().intValue() == objects.length); NativeLong rv2 = pkcs11.C_FindObjectsFinal(mSession); if (!rv.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv); else if (!rv2.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv2); HashMap<NativeLong, Certificate> certificateMap = new HashMap<NativeLong, Certificate>(); for (NativeLong c : certs) { certificateMap.put(c, new Certificate(pkcs11, mSession, c)); } return certificateMap; }
public void sign(final NativeLong certificate, final byte[] data, Pkcs11Callback callback) { new Pkcs11AsyncTask(callback) { @Override protected Pkcs11Result doWork() throws Pkcs11CallerException { Certificate cert = mCertificateMap.get(certificate); if (cert == null) throw new CertNotFoundException(); NativeLong keyHandle = cert.getPrivateKeyHandle(mPkcs11, mSession); if (keyHandle == null) throw new KeyNotFoundException(); NativeLongByReference count = new NativeLongByReference(new NativeLong()); final byte[] oid = { 0x06, 0x07, 0x2a, (byte) 0x85, 0x03, 0x02, 0x02, 0x1e, 0x01 }; ByteBuffer oidBuffer = ByteBuffer.allocateDirect(oid.length); oidBuffer.put(oid); CK_MECHANISM mechanism = new CK_MECHANISM(RtPkcs11Constants.CKM_GOSTR3410_WITH_GOSTR3411, Native.getDirectBufferPointer(oidBuffer), new NativeLong(oid.length)); NativeLong rv = mPkcs11.C_SignInit(mSession, mechanism, keyHandle); if (!rv.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv); rv = mPkcs11.C_Sign(mSession, data, new NativeLong(data.length), null, count); if (!rv.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv); byte signature[] = new byte[count.getValue().intValue()]; rv = mPkcs11.C_Sign(mSession, data, new NativeLong(data.length), signature, count); if (!rv.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv); return new Pkcs11Result(signature); } }.execute(); }
NativeLong C_OpenSession ( NativeLong slotID, /* the slot's ID */ NativeLong flags, /* from CK_SESSION_INFO */ Pointer pApplication, /* passed to callback */ Callback Notify, /* callback function */ NativeLongByReference phSession /* gets session handle */ );
NativeLong C_CreateObject ( NativeLong hSession, /* the session's handle */ CK_ATTRIBUTE[] pTemplate, /* the object's template */ NativeLong ulCount, /* attributes in template */ NativeLongByReference phObject /* gets new object's handle. */ );
NativeLong C_CopyObject ( NativeLong hSession, /* the session's handle */ NativeLong hObject, /* the object's handle */ CK_ATTRIBUTE[] pTemplate, /* template for new object */ NativeLong ulCount, /* attributes in template */ NativeLongByReference phNewObject /* receives handle of copy */ );
NativeLong C_FindObjects ( NativeLong hSession, /* session's handle */ NativeLong[] phObject, /* gets obj. handles */ NativeLong ulMaxObjectCount, /* max handles to get */ NativeLongByReference pulObjectCount /* actual # returned */ );
NativeLong C_Encrypt ( NativeLong hSession, /* session's handle */ byte[] pData, /* the plaintext data */ NativeLong ulDataLen, /* bytes of plaintext */ byte[] pEncryptedData, /* gets ciphertext */ NativeLongByReference pulEncryptedDataLen /* gets c-text size */ );
NativeLong C_EncryptUpdate ( NativeLong hSession, /* session's handle */ byte[] pPart, /* the plaintext data */ NativeLong ulPartLen, /* plaintext data len */ byte[] pEncryptedPart, /* gets ciphertext */ NativeLongByReference pulEncryptedPartLen /* gets c-text size */ );
NativeLong C_Decrypt ( NativeLong hSession, /* session's handle */ byte[] pEncryptedData, /* ciphertext */ NativeLong ulEncryptedDataLen, /* ciphertext length */ byte[] pData, /* gets plaintext */ NativeLongByReference pulDataLen /* gets p-text size */ );
NativeLong C_DecryptUpdate ( NativeLong hSession, /* session's handle */ byte[] pEncryptedPart, /* encrypted data */ NativeLong ulEncryptedPartLen, /* input length */ byte[] pPart, /* gets plaintext */ NativeLongByReference pulPartLen /* p-text size */ );
NativeLong C_Digest ( NativeLong hSession, /* the session's handle */ byte[] pData, /* data to be digested */ NativeLong ulDataLen, /* bytes of data to digest */ byte[] pDigest, /* gets the message digest */ NativeLongByReference pulDigestLen /* gets digest length */ );
NativeLong C_Sign ( NativeLong hSession, /* the session's handle */ byte[] pData, /* the data to sign */ NativeLong ulDataLen, /* count of bytes to sign */ byte[] pSignature, /* gets the signature */ NativeLongByReference pulSignatureLen /* gets signature length */ );
NativeLong C_SignRecover ( NativeLong hSession, /* the session's handle */ byte[] pData, /* the data to sign */ NativeLong ulDataLen, /* count of bytes to sign */ byte[] pSignature, /* gets the signature */ NativeLongByReference pulSignatureLen /* gets signature length */ );
NativeLong C_VerifyRecover ( NativeLong hSession, /* the session's handle */ byte[] pSignature, /* signature to verify */ NativeLong ulSignatureLen, /* signature length */ byte[] pData, /* gets signed data */ NativeLongByReference pulDataLen /* gets signed data len */ );
NativeLong C_DigestEncryptUpdate ( NativeLong hSession, /* session's handle */ byte[] pPart, /* the plaintext data */ NativeLong ulPartLen, /* plaintext length */ byte[] pEncryptedPart, /* gets ciphertext */ NativeLongByReference pulEncryptedPartLen /* gets c-text length */ );
NativeLong C_DecryptDigestUpdate ( NativeLong hSession, /* session's handle */ byte[] pEncryptedPart, /* ciphertext */ NativeLong ulEncryptedPartLen, /* ciphertext length */ byte[] pPart, /* gets plaintext */ NativeLongByReference pulPartLen /* gets plaintext len */ );
NativeLong C_SignEncryptUpdate ( NativeLong hSession, /* session's handle */ byte[] pPart, /* the plaintext data */ NativeLong ulPartLen, /* plaintext length */ byte[] pEncryptedPart, /* gets ciphertext */ NativeLongByReference pulEncryptedPartLen /* gets c-text length */ );
NativeLong C_DecryptVerifyUpdate ( NativeLong hSession, /* session's handle */ byte[] pEncryptedPart, /* ciphertext */ NativeLong ulEncryptedPartLen, /* ciphertext length */ byte[] pPart, /* gets plaintext */ NativeLongByReference pulPartLen /* gets p-text length */ );
NativeLong C_GenerateKey ( NativeLong hSession, /* the session's handle */ CK_MECHANISM pMechanism, /* key generation mech. */ CK_ATTRIBUTE[] pTemplate, /* template for new key */ NativeLong ulCount, /* # of attrs in template */ NativeLongByReference phKey /* gets handle of new key */ );
NativeLong C_GenerateKeyPair ( NativeLong hSession, /* session handle */ CK_MECHANISM pMechanism, /* key-gen mech. */ CK_ATTRIBUTE[] pPublicKeyTemplate, /* template for pub. key */ NativeLong ulPublicKeyAttributeCount, /* # pub. attrs. */ CK_ATTRIBUTE[] pPrivateKeyTemplate, /* template for priv. key */ NativeLong ulPrivateKeyAttributeCount, /* # priv. attrs. */ NativeLongByReference phPublicKey, /* gets pub. key handle */ NativeLongByReference phPrivateKey /* gets priv. key handle */ );
NativeLong C_WrapKey ( NativeLong hSession, /* the session's handle */ CK_MECHANISM pMechanism, /* the wrapping mechanism */ NativeLong hWrappingKey, /* wrapping key */ NativeLong hKey, /* key to be wrapped */ byte[] pWrappedKey, /* gets wrapped key */ NativeLongByReference pulWrappedKeyLen /* gets wrapped key size */ );
NativeLong C_UnwrapKey ( NativeLong hSession, /* session's handle */ CK_MECHANISM pMechanism, /* unwrapping mech. */ NativeLong hUnwrappingKey, /* unwrapping key */ byte[] pWrappedKey, /* the wrapped key */ NativeLong ulWrappedKeyLen, /* wrapped key len */ CK_ATTRIBUTE[] pTemplate, /* new key template */ NativeLong ulAttributeCount, /* template length */ NativeLongByReference phKey /* gets new handle */ );
NativeLong C_DeriveKey ( NativeLong hSession, /* session's handle */ CK_MECHANISM pMechanism, /* key deriv. mech. */ NativeLong hBaseKey, /* base key */ CK_ATTRIBUTE[] pTemplate, /* new key template */ NativeLong ulAttributeCount, /* template length */ NativeLongByReference phKey /* gets new handle */ );
NativeLong C_EX_GetLicense ( NativeLong hSession, /* the session's handle */ NativeLong ulLicenseNum, /* the number of the license, can only be 1 or 2 */ byte[] pLicense, /* receives the license */ NativeLongByReference pulLicenseLen /* length of the license */ );
NativeLong C_EX_GetCertificateInfoText ( NativeLong hSession, /* the session's handle */ NativeLong hCert, /* the object's handle */ Pointer pInfo, /* returns address of allocated buffer with text information */ NativeLongByReference pulInfoLen /* length of the allocated buffer */ );
NativeLong C_EX_PKCS7Sign ( NativeLong hSession, byte[] pData, NativeLong ulDataLen, NativeLong hCert, Pointer ppEnvelope, NativeLongByReference pEnvelopeLen, NativeLong hPrivKey, NativeLong[] phCertificates, NativeLong ulCertificatesLen, NativeLong flags );
NativeLong C_EX_CreateCSR ( NativeLong hSession, NativeLong hPublicKey, String[] dn, NativeLong dnLength, Pointer pCsr, NativeLongByReference pulCsrLength, NativeLong hPrivKey, NativeLong[] pAttributes, NativeLong ulAttributesLength, String[] pExtensions, NativeLong ulExtensionsLength );
@Override public AudioPCM decodeAll() throws IOException { NativeLongByReference decodedBytes = new NativeLongByReference(); ByteBuffer pcm = null; if(format.getNumberOfSamples() != 0) pcm = MemoryUtils.createByteBuffer((int) format.getNumberOfSamples() * format.getChannels() * format.getBitDepth().bitDepth / 8); int ret = MPG123_OK; int bytesRead = 0; while(ret != MPG123_DONE) { ret = mpg123_read(h, tmpBuff, new NativeLong(tmpBuff.capacity()), decodedBytes); if(ret == MPG123_OK || ret == MPG123_NEW_FORMAT) { bytesRead += decodedBytes.getValue().intValue(); if(ret == MPG123_NEW_FORMAT) { readHeader(); if(pcm != null) { pcm = MemoryUtils.realloc(pcm, (int) format.getNumberOfSamples() * format.getChannels() * format.getBitDepth().bitDepth / 8); } } if(format.getNumberOfSamples() != 0) { pcm.position(bytesRead); MemoryUtils.copy(tmpBuff, pcm, decodedBytes.getValue().intValue()); } else { pcm = MemoryUtils.realloc(pcm, (pcm != null ? pcm.capacity() : 0) + decodedBytes.getValue().intValue()); pcm.position(bytesRead); MemoryUtils.copy(tmpBuff, pcm, decodedBytes.getValue().intValue()); } } else if(ret != MPG123_DONE) { MemoryUtils.free(pcm); delete(); throw new AudioDecoderException(mpg123_plain_strerror(ret)); } } delete(); return new AudioPCM(format, pcm); }
public MidiClient(final String string, final MIDINotifyProc notifyProc) throws CoreMidiException { final ID name = Foundation.cfString(string); final NativeLongByReference temp = new NativeLongByReference(); final int midiClientCreate = CoreMidiLibrary.INSTANCE.MIDIClientCreate(name, notifyProc, null, temp); if (midiClientCreate != 0) { throw new CoreMidiException(midiClientCreate); } LOGGER.info("MidiClientRef: " + temp.getValue().longValue()); midiClientRef = temp.getValue(); }
public MidiOutputPort outputPortCreate(final String string) throws CoreMidiException { final NativeLongByReference temp = new NativeLongByReference(); final ID name = Foundation.cfString(string); final int midiOutputPortCreate = CoreMidiLibrary.INSTANCE.MIDIOutputPortCreate(midiClientRef, name, temp); if (midiOutputPortCreate != 0) { throw new CoreMidiException(midiOutputPortCreate); } return new MidiOutputPort(temp.getValue()); }
public MidiInputPort inputPortCreate(final String name, final MIDIReadProc readProc) throws CoreMidiException { final NativeLongByReference temp = new NativeLongByReference(); final int midiInputPortCreate = CoreMidiLibrary.INSTANCE.MIDIInputPortCreate(midiClientRef, Foundation.cfString(name), readProc, null, temp); if (midiInputPortCreate != 0) { throw new CoreMidiException(midiInputPortCreate); } return new MidiInputPort(temp.getValue()); }
boolean ReadProcessMemory(Pointer hProcess, Pointer lpBaseAddress, Pointer lpBuffer, NativeLong nSize, NativeLongByReference lpNumberOfBytesRead);