Example usage for java.math BigInteger add

List of usage examples for java.math BigInteger add

Introduction

In this page you can find the example usage for java.math BigInteger add.

Prototype

BigInteger add(long val) 

Source Link

Document

Package private methods used by BigDecimal code to add a BigInteger with a long.

Usage

From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java

@Override
public BigInteger rePrintChecksInsert(Motransaction motrans, BigInteger startId, BigInteger endId,
        BigInteger chekcNo, Integer yearID, Integer periodID, String username) throws BankingException {
    itsLogger.debug("moTransaction Update");

    Session aSession = null;/*w  ww .  ja  v  a  2s . c  om*/

    /*
     * Description: MoAccountID is Added to check#. 
     * Table:glLinkage
     * Reason: fetching Purpose
     */
    BigInteger startId1 = new BigInteger(motrans.getMoAccountId() + "" + startId);
    BigInteger endId1 = new BigInteger(motrans.getMoAccountId() + "" + endId);

    GlTransaction aGlTransaction = null;
    GlTransaction bGlTransaction = null;
    GlTransaction theGlTransaction = null;
    String updateQuery = null;
    //int newCheckValue = chekcNo.intValue();
    BigInteger referenceValue = chekcNo;
    int k = 0;
    try {
        Coledgersource aColedgersource = new Coledgersource();

        Cofiscalperiod aCofiscalperiod = accountingCyclesService.getCurrentPeriod(periodID);
        Cofiscalyear aCofiscalyear = accountingCyclesService.getCurrentYear(yearID);
        aColedgersource = gltransactionService.getColedgersourceDetail("WC");

        updateQuery = "SELECT distinct(glTransactionId),vebillID FROM glLinkage WHERE STATUS=0 AND coLedgerSourceId = "
                + aColedgersource.getCoLedgerSourceId() + " and vebillID  BETWEEN  " + startId1 + " AND "
                + endId1;
        itsLogger.info("Query : " + updateQuery);

        itsLogger.info("MoAccountID:---->" + motrans.getMoAccountId());

        aSession = itsSessionFactory.openSession();
        Query insQuery = aSession.createSQLQuery(updateQuery);
        Iterator<?> theIterator = insQuery.list().iterator();
        Transaction aSearchInsert = aSession.beginTransaction();
        ArrayList<GlTransaction> glTransactionList = new ArrayList<GlTransaction>();
        while (theIterator.hasNext()) {
            k++;
            aGlTransaction = new GlTransaction();
            theGlTransaction = new GlTransaction();
            Object[] aObj = (Object[]) theIterator.next();
            aGlTransaction = (GlTransaction) aSession.get(GlTransaction.class, ((Integer) aObj[0]));

            bGlTransaction = new GlTransaction();
            bGlTransaction.setBankClosingBalance(aGlTransaction.getBankClosingBalance());
            bGlTransaction.setBankOpeningBalance(aGlTransaction.getBankOpeningBalance());
            bGlTransaction.setCoAccountDesc(aGlTransaction.getCoAccountDesc());
            bGlTransaction.setCoAccountId(aGlTransaction.getCoAccountId());
            bGlTransaction.setCoAccountNumber(aGlTransaction.getCoAccountNumber());

            bGlTransaction.setCoFiscalPeriodId(aCofiscalperiod.getCoFiscalPeriodId());
            bGlTransaction.setpStartDate(aCofiscalperiod.getStartDate());
            bGlTransaction.setpEndDate(aCofiscalperiod.getEndDate());
            bGlTransaction.setPeriod(aCofiscalperiod.getPeriod());

            bGlTransaction.setCoFiscalYearId(aCofiscalyear.getCoFiscalYearId());
            bGlTransaction.setyStartDate(aCofiscalyear.getStartDate());
            bGlTransaction.setyStartDate(aCofiscalyear.getEndDate());
            bGlTransaction.setFyear(aCofiscalyear.getFiscalYear());

            bGlTransaction.setEntrydate(new Date());
            bGlTransaction.setEnteredBy(username);
            bGlTransaction.setTransactionDate(motrans.getTransactionDate());

            bGlTransaction.setHiddenstatus(aGlTransaction.getHiddenstatus());
            bGlTransaction.setJournalDesc(aGlTransaction.getJournalDesc());
            bGlTransaction.setJournalId(aGlTransaction.getJournalId());
            bGlTransaction.setOldcoAccountId(aGlTransaction.getOldcoAccountId());
            bGlTransaction.setOldcoAccountNumber(aGlTransaction.getOldcoAccountNumber());
            bGlTransaction.setStatus(aGlTransaction.getStatus());
            bGlTransaction.setTransactionDesc(aGlTransaction.getTransactionDesc());
            bGlTransaction.setPoNumber(referenceValue + "");
            bGlTransaction.setDebit(aGlTransaction.getDebit());
            bGlTransaction.setCredit(aGlTransaction.getCredit());
            glTransactionList.add(bGlTransaction);

            if (k % 2 == 0) {
                referenceValue = referenceValue.add(BigInteger.ONE);

                GlRollback glRollback = new GlRollback();
                glRollback.setVeBillID((Integer) aObj[1]);
                glRollback.setCoLedgerSourceID(aColedgersource.getCoLedgerSourceId());
                glRollback.setPeriodID(periodID);
                glRollback.setYearID(yearID);
                glRollback.setTransactionDate(motrans.getTransactionDate());

                gltransactionService.rollBackGlTransaction(glRollback);
            }
            itsLogger.info("Reference Val: " + referenceValue);
        }
        for (int a = 0; a < glTransactionList.size(); a++) {
            GlTransaction cGlTransaction = new GlTransaction();
            cGlTransaction = glTransactionList.get(a);
            Integer glID = 0;
            glID = (Integer) aSession.save(cGlTransaction);
            glLinkageInsert(aColedgersource, glID, Integer.parseInt(cGlTransaction.getPoNumber()),
                    motrans.getMoAccountId());

        }

        aSearchInsert.commit();

    } catch (Exception e) {
        itsLogger.error(e.getMessage(), e);
        BankingException aBankingException = new BankingException(e.getMessage(), e);
        throw aBankingException;
    } finally {
        aSession.flush();
        aSession.close();
        updateQuery = null;
    }

    String aCustomerQry = "SELECT * FROM moTransaction WHERE  CAST(reference AS UNSIGNED) BETWEEN " + startId
            + " AND " + endId + " AND moAccountID=" + motrans.getMoAccountId();
    itsLogger.info("Query : " + aCustomerQry);
    Motransaction aMotransaction = null;
    Motransaction aMotransactionUpdate = null;
    MoAccount aMoAccount = null;
    Query theQuery = null;
    BigInteger newCheckValue = chekcNo;
    try {
        aSession = itsSessionFactory.openSession();
        Query aQuery = aSession.createSQLQuery(aCustomerQry);
        Iterator<?> aIterator = aQuery.list().iterator();
        Transaction aSearchInsert = aSession.beginTransaction();
        while (aIterator.hasNext()) {
            aMotransaction = new Motransaction();
            Object[] aObj = (Object[]) aIterator.next();
            aMotransaction.setMoTransactionId((Integer) aObj[0]);
            aMotransactionUpdate = (Motransaction) aSession.get(Motransaction.class,
                    aMotransaction.getMoTransactionId());
            theQuery = aSession.createQuery(
                    "From VeBillPaymentHistory where checkNo='" + aMotransactionUpdate.getReference() + "'");
            List aList = theQuery.list();
            for (int n = 0; n < aList.size(); n++) {
                VeBillPaymentHistory objph = (VeBillPaymentHistory) aList.get(n);
                VeBillPaymentHistory objvbillph = (VeBillPaymentHistory) aSession
                        .get(VeBillPaymentHistory.class, objph.getPaymentHistoryID());
                objvbillph.setCheckNo(newCheckValue + "");
                aSession.save(objvbillph);
            }
            aMotransactionUpdate.setReference(newCheckValue + "");
            aSession.update(aMotransactionUpdate);
            newCheckValue = newCheckValue.add(BigInteger.ONE);
            itsLogger.info("New Check Val: " + newCheckValue);
            aMoAccount = new MoAccount();
            aMoAccount = (MoAccount) aSession.get(MoAccount.class, motrans.getMoAccountId());
            aMoAccount.setNextCheckNumber(newCheckValue.intValue());
            aSession.update(aMotransactionUpdate);

        }
        aSearchInsert.commit();
    } catch (Exception e) {
        itsLogger.error(e.getMessage(), e);
        BankingException aBankingException = new BankingException(e.getMessage(), e);
        throw aBankingException;
    }

    /*Session bSession = null;
    String InsertQry = "INSERT INTO motransaction " +
    "(rxMasterID,rxAddressID,coAccountID,moAccountId,TransactionDate," +
    "moTransactionTypeID,CheckType,reference,Description,void,reconciled," +
    "temprec,printed,amount,directdeposit) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    Motransaction aSearchList = new Motransaction();
    try {
               
       bSession = itsSessionFactory.openSession();
       Transaction aSearchInsert = bSession.beginTransaction();
       Query aQuery = bSession.createSQLQuery(InsertQry);
       for (int i = 0; i < aQueryList.size(); i++) {
    aSearchList = (Motransaction) aQueryList.get(i);
    aQuery.setInteger(1, aSearchList.getRxMasterId());
    aQuery.setInteger(2, aSearchList.getRxAddressId());
    aQuery.setInteger(3, aSearchList.getCoAccountId());
    aQuery.setInteger(4, aSearchList.getMoAccountId());
    aQuery.setDate(5, aSearchList.getTransactionDate());
    aQuery.setInteger(6, aSearchList.getMoTransactionTypeId());
    aQuery.setInteger(7, aSearchList.getCheckType());
    aQuery.setString(8, newCheckValue+"");
    aQuery.setString(9, aSearchList.getDescription());
    aQuery.setInteger(10, aSearchList.getVoid_());
    aQuery.setInteger(11, aSearchList.getReconciled());
    aQuery.setInteger(12, aSearchList.getTempRec());
    aQuery.setInteger(13, aSearchList.getPrinted());
    aQuery.setBigDecimal(14, aSearchList.getAmount());
    aQuery.setInteger(15, aSearchList.getDirectDeposit());
            
    bSession.save(aQuery);
    if (i % 100 == 0) {
       aSession.flush();
       aSession.clear();
       Session aTransdetailSession = itsSessionFactory.openSession();
       Transaction aTransaction;
       try {
          aTransaction = aTransdetailSession.beginTransaction();
          aTransaction.begin();
          aTransdetailSession.delete(aSearchList);
          aTransaction.commit();
       } catch (Exception excep) {
          itsLogger.error(excep.getMessage(), excep);
          BankingException aBankingException = new BankingException(excep.getMessage(), excep);
          throw aBankingException;
       } finally {
          aTransdetailSession.flush();
          aTransdetailSession.close();
       }
    }
            
       }
       aSearchInsert.commit();
    } catch (Exception e) {
       itsLogger.error(e.getMessage(), e);
       BankingException aBankingException = new BankingException(e.getMessage(), e);
       throw aBankingException;
    }*/
    finally {
        aSession.flush();
        aSession.close();
        aCustomerQry = null;
    }
    return newCheckValue;
}

From source file:com.google.bitcoin.core.Wallet.java

/**
 * Calls {@link Wallet#commitTx} if tx is not already in the pending pool
 *
 * @return true if the tx was added to the wallet, or false if it was already in the pending pool
 *///from w  w  w .  j  ava  2 s.com
public boolean maybeCommitTx(Transaction tx) throws VerificationException {
    tx.verify();
    lock.lock();
    try {
        log.info("!!!! commit START!!! " + tx.getHashAsString());
        if (pending.containsKey(tx.getHash()))
            return false;
        log.info("commitTx of {}", tx.getHashAsString());
        BigInteger balance = getBalance();
        tx.setUpdateTime(Utils.now());
        // Mark the outputs we're spending as spent so we won't try and use them in future creations. This will also
        // move any transactions that are now fully spent to the spent map so we can skip them when creating future
        // spends.
        updateForSpends(tx, false);
        // Add to the pending pool. It'll be moved out once we receive this transaction on the best chain.
        // This also registers txConfidenceListener so wallet listeners get informed.
        log.info("->pending: {}", tx.getHashAsString());
        tx.getConfidence().setConfidenceType(ConfidenceType.PENDING);
        confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.TYPE);
        addWalletTransaction(Pool.PENDING, tx);

        /* CSPK-mike START */

        // Looking for assets in pending transaction
        CS.log.info("New tx " + tx.getHash().toString() + " in memory pool");

        log.info("!!!! commit HIT!!! " + tx.getHashAsString());
        CSTransactionAssets txAssets = new CSTransactionAssets(tx);
        txAssets.updateAssetBalances(this, 0, CS.getInputAssetBalances(tx));
        CS.addToRecentSends(tx);

        /* CSPK-mike END */

        try {
            BigInteger valueSentFromMe = tx.getValueSentFromMe(this);
            BigInteger valueSentToMe = tx.getValueSentToMe(this);
            BigInteger newBalance = balance.add(valueSentToMe).subtract(valueSentFromMe);
            if (valueSentToMe.compareTo(BigInteger.ZERO) > 0) {
                checkBalanceFuturesLocked(null);
                queueOnCoinsReceived(tx, balance, newBalance);
            }
            if (valueSentFromMe.compareTo(BigInteger.ZERO) > 0)
                queueOnCoinsSent(tx, balance, newBalance);

            maybeQueueOnWalletChanged();
        } catch (ScriptException e) {
            // Cannot happen as we just created this transaction ourselves.
            throw new RuntimeException(e);
        }

        checkState(isConsistent());
        informConfidenceListenersIfNotReorganizing();
        //saveNow();
    } finally {
        lock.unlock();
    }
    return true;
}

From source file:com.peterbochs.PeterBochsDebugger.java

private void jPageDirectoryTableMouseClicked(MouseEvent evt) {
    if (evt.getClickCount() == 2) {
        jStatusProgressBar.setValue(0);//from   w ww  .j  a v a2 s. co m
        String pageTableAddress = jPageDirectoryTable.getValueAt(jPageDirectoryTable.getSelectedRow(), 1)
                .toString();
        if (!CommonLib.isNumber(pageTableAddress)) {
            return;
        }

        // commandReceiver.setCommandNoOfLine(512);
        sendCommand("xp /4096bx " + pageTableAddress);

        float totalByte2 = 4096 - 1;
        totalByte2 = totalByte2 / 8;
        int totalByte3 = (int) Math.floor(totalByte2);
        String realEndAddressStr;
        String realStartAddressStr;
        String baseAddress = pageTableAddress;
        BigInteger realStartAddress = CommonLib.string2BigInteger(baseAddress);

        realStartAddressStr = String.format("%08x", realStartAddress);
        BigInteger realEndAddress = realStartAddress.add(BigInteger.valueOf(totalByte3 * 8));
        realEndAddressStr = String.format("%08x", realEndAddress);

        String result = commandReceiver.getCommandResult(realStartAddressStr, realEndAddressStr, null);
        String[] lines = result.split("\n");
        PageTableTableModel model = (PageTableTableModel) jPageTableTable.getModel();
        while (model.getRowCount() > 0) {
            model.removeRow(0);
        }
        jStatusProgressBar.setMaximum(lines.length - 1);
        for (int y = 0; y < lines.length; y++) {
            jStatusProgressBar.setValue(y);
            String[] b = lines[y].replaceFirst("^.*:", "").trim().split("\t");

            for (int z = 0; z < 2; z++) {
                try {
                    int bytes[] = new int[4];
                    for (int x = 0; x < 4; x++) {
                        bytes[x] = CommonLib.string2BigInteger(b[x + z * 4].substring(2).trim()).intValue();
                    }
                    long value = CommonLib.getInt(bytes, 0);
                    // "No.", "PT base", "AVL", "G",
                    // "D", "A", "PCD", "PWT",
                    // "U/S", "W/R", "P"

                    String base = "0x" + Long.toHexString(CommonLib.getValue(value, 12, 31) << 12);
                    String avl = String.valueOf((value >> 9) & 3);
                    String g = String.valueOf((value >> 8) & 1);
                    String pat = String.valueOf((value >> 7) & 1);
                    String d = String.valueOf((value >> 6) & 1);
                    String a = String.valueOf((value >> 5) & 1);
                    String pcd = String.valueOf((value >> 4) & 1);
                    String pwt = String.valueOf((value >> 3) & 1);
                    String us = String.valueOf((value >> 2) & 1);
                    String wr = String.valueOf((value >> 1) & 1);
                    String p = String.valueOf((value >> 0) & 1);
                    boolean tempB = model.isShowZeroAddress();
                    model.setShowZeroAddress(true);
                    model.addRow(new String[] { String.valueOf(y * 2 + z), base, avl, g, pat, d, a, pcd, pwt,
                            us, wr, p });
                    model.setShowZeroAddress(tempB);
                } catch (Exception ex) {
                }
            }

            jPageTableTable.setModel(model);
        }
    }
}

From source file:com.peterbochs.PeterBochsDebugger.java

private void jRefreshAddressTranslateButtonActionPerformed(ActionEvent evt) {
    AddressTranslateTableModel model = (AddressTranslateTableModel) this.jAddressTranslateTable2.getModel();

    if (jSearchAddressRadioButton1.isSelected()) {
        if (!this.jAddressTextField.getText().contains(":")
                || this.jAddressTextField.getText().replaceAll("[^:]", "").length() != 1) {
            JOptionPane.showMessageDialog(this,
                    "Error, please input <segment selector>:<offset>\n\ne.g. : 0x10:0x12345678", "Error",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }/*  w  ww  . ja  v  a 2 s  .  co m*/
        BigInteger segSelector = CommonLib.string2BigInteger(this.jAddressTextField.getText().split(":")[0]);
        BigInteger address = CommonLib.string2BigInteger(this.jAddressTextField.getText().split(":")[1]);

        // for (int x = 0; x < model.getRowCount(); x++) {
        // if (model.searchType.get(x).equals(1) &&
        // model.searchSegSelector.get(x).equals(segSelector) &&
        // model.searchAddress.get(x).equals(address)) {
        // return;
        // }
        // }

        model.searchType.add(1);
        model.searchSegSelector.add(segSelector);
        model.searchAddress.add(address);

        model.virtualAddress.add(address);
        BigInteger segNo = segSelector.shiftRight(3);
        model.segNo.add(segNo);

        // read GDT descriptor
        int descriptor[] = PeterBochsCommonLib
                .getMemoryFromBochs(CommonLib.string2BigInteger(this.registerPanel.jGDTRTextField.getText())
                        .add(segNo.multiply(BigInteger.valueOf(8))), 8);
        BigInteger baseAddress = CommonLib.getBigInteger(descriptor[2], descriptor[3], descriptor[4],
                descriptor[7], 0, 0, 0, 0);
        BigInteger linearAddress = baseAddress.add(address);
        model.baseAddress.add(baseAddress);
        model.linearAddress.add(linearAddress);

        BigInteger pdNo = CommonLib.getBigInteger(linearAddress, 31, 22);
        model.pdNo.add(pdNo);
        int pdeBytes[] = PeterBochsCommonLib
                .getMemoryFromBochs(CommonLib.string2BigInteger(this.registerPanel.jCR3TextField.getText())
                        .add(pdNo.multiply(BigInteger.valueOf(4))), 4);
        BigInteger pde = CommonLib.getBigInteger(pdeBytes, 0);
        model.pde.add(pde);

        BigInteger ptNo = CommonLib.getBigInteger(linearAddress, 21, 12);
        model.ptNo.add(ptNo);
        BigInteger pageTableBaseAddress = pde.and(CommonLib.string2BigInteger("0xfffff000"));
        int pteBytes[] = PeterBochsCommonLib
                .getMemoryFromBochs(pageTableBaseAddress.add(ptNo.multiply(BigInteger.valueOf(4))), 4);
        BigInteger pte = CommonLib.getBigInteger(pteBytes, 0);
        BigInteger pagePhysicalAddress = pte.and(CommonLib.string2BigInteger("0xfffff000"));
        model.pte.add(pte);

        BigInteger physicalAddress = pagePhysicalAddress.add(CommonLib.getBigInteger(linearAddress, 11, 0));
        model.physicalAddress.add(physicalAddress);
        int bytesAtPhysicalAddress[] = PeterBochsCommonLib.getMemoryFromBochs(physicalAddress, 8);
        model.bytes.add(PeterBochsCommonLib.convertToString(bytesAtPhysicalAddress));

        model.fireTableDataChanged();
    } else if (jSearchAddressRadioButton2.isSelected()) {
        // for (int x = 0; x < model.getRowCount(); x++) {
        // if (model.searchType.get(x).equals(2) &&
        // model.searchAddress.get(x).equals(CommonLib.string2long(this.jAddressTextField.getText())))
        // {
        // return;
        // }
        // }
        BigInteger address = CommonLib.string2BigInteger(this.jAddressTextField.getText());

        model.searchType.add(2);
        model.searchAddress.add(address);

        BigInteger baseAddress = BigInteger.ZERO;
        BigInteger linearAddress = baseAddress.add(address);
        model.baseAddress.add(baseAddress);
        model.linearAddress.add(linearAddress);

        BigInteger pdNo = CommonLib.getBigInteger(linearAddress, 31, 22);
        model.pdNo.add(pdNo);
        int pdeBytes[] = PeterBochsCommonLib
                .getMemoryFromBochs(CommonLib.string2BigInteger(this.registerPanel.jCR3TextField.getText())
                        .add(pdNo.multiply(BigInteger.valueOf(4))), 4);
        BigInteger pde = CommonLib.getBigInteger(pdeBytes, 0);
        model.pde.add(pde);

        BigInteger ptNo = CommonLib.getBigInteger(linearAddress, 21, 12);
        model.ptNo.add(ptNo);
        BigInteger pageTableBaseAddress = pde.and(CommonLib.string2BigInteger("0xfffff000"));
        int pteBytes[] = PeterBochsCommonLib
                .getMemoryFromBochs(pageTableBaseAddress.add(ptNo.multiply(BigInteger.valueOf(4))), 4);
        BigInteger pte = CommonLib.getBigInteger(pteBytes, 0);
        BigInteger pagePhysicalAddress = pte.and(CommonLib.string2BigInteger("0xfffff000"));
        model.pte.add(pte);

        BigInteger physicalAddress = pagePhysicalAddress.add(CommonLib.getBigInteger(linearAddress, 11, 0));
        model.physicalAddress.add(physicalAddress);
        int bytesAtPhysicalAddress[] = PeterBochsCommonLib.getMemoryFromBochs(physicalAddress, 8);
        model.bytes.add(PeterBochsCommonLib.convertToString(bytesAtPhysicalAddress));

        model.fireTableDataChanged();
    } else if (jSearchAddressRadioButton3.isSelected()) {
        for (int x = 0; x < model.getRowCount(); x++) {
            if (model.searchType.get(x).equals(3) && model.searchAddress.get(x)
                    .equals(CommonLib.string2long(this.jAddressTextField.getText()))) {
                return;
            }
        }
        BigInteger addr = CommonLib.string2BigInteger(this.jAddressTextField.getText());
        model.searchType.add(3);
        model.searchSegSelector.add(BigInteger.ZERO);
        model.searchAddress.add(addr);
        model.virtualAddress.add(BigInteger.ZERO);
        model.segNo.add(BigInteger.ZERO);
        model.linearAddress.add(BigInteger.ZERO);
        model.pdNo.add(BigInteger.ZERO);
        model.ptNo.add(BigInteger.ZERO);
        model.physicalAddress.add(BigInteger.ZERO);
        model.bytes.add("");

        model.fireTableDataChanged();
    }
}

From source file:com.peterbochs.PeterBochsDebugger.java

private void updateInstructionUsingBochs(BigInteger address) {
    try {/*w w  w.  j a  v  a2s. c  om*/
        final int maximumLine = 400;
        String command;
        jStatusLabel.setText("Updating instruction");
        if (address == null) {
            BigInteger cs = CommonLib.string2BigInteger(this.registerPanel.jCSTextField.getText());
            BigInteger eip = CommonLib.string2BigInteger(this.registerPanel.eipTextField.getText());
            eip = eip.and(CommonLib.string2BigInteger("0xffffffffffffffff"));
            command = "disasm cs:0x" + eip.toString(16) + " 0x" + cs.toString(16) + ":0x"
                    + eip.add(BigInteger.valueOf(0x400)).toString(16);
        } else {
            command = "disasm " + address + " " + address.add(BigInteger.valueOf(0x400));
        }
        commandReceiver.clearBuffer();
        commandReceiver.shouldShow = false;
        sendCommand(command);
        commandReceiver.waitUntilHaveLine(30);
        String result = commandReceiver.getCommandResultUntilEnd();
        String lines[] = result.split("\n");
        if (lines.length > 0) {
            InstructionTableModel model = (InstructionTableModel) instructionTable.getModel();
            jStatusProgressBar.setMaximum(lines.length - 1);
            for (int x = 0; x < lines.length && x < maximumLine; x++) {
                jStatusProgressBar.setValue(x);
                try {
                    lines[x] = lines[x].replaceFirst("\\<.*\\>", "");
                    String strs[] = lines[x].split(":");
                    int secondColon = lines[x].indexOf(":", lines[x].indexOf(":") + 1);

                    // load cCode
                    String pcStr = strs[0].trim();
                    BigInteger pc = CommonLib.string2BigInteger("0x" + pcStr);
                    if (pc == null) {
                        continue;
                    }
                    String s[] = getCCode(pc, false);
                    String lineNo[] = getCCode(pc, true);
                    if (s != null && lineNo != null) {
                        for (int index = 0; index < s.length; index++) {
                            model.addRow(new String[] { "",
                                    "cCode : 0x" + pc.toString(16) + " : " + lineNo[index], s[index], "" });
                        }
                    }
                    // end load cCode
                    model.addRow(new String[] { "", "0x" + pc.toString(16),
                            lines[x].substring(secondColon + 1).trim().split(";")[0].trim(),
                            lines[x].split(";")[1] });
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }

            model.removeNonOrderInstruction();
            model.fireTableDataChanged();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.peterbochs.PeterBochsDebugger.java

private void jRefreshAddressTranslateTableButtonActionPerformed(ActionEvent evt) {
    AddressTranslateTableModel model = (AddressTranslateTableModel) this.jAddressTranslateTable2.getModel();
    for (int x = 0; x < model.getRowCount(); x++) {
        if (model.searchType.get(x).equals(1)) {
            model.segNo.set(x, model.searchSegSelector.get(x).shiftRight(3));
            model.virtualAddress.set(x, model.searchAddress.get(x));

            BigInteger gdtBase = PeterBochsCommonLib.getPhysicalAddress(
                    CommonLib.string2BigInteger(this.registerPanel.jCR3TextField.getText()),
                    CommonLib.string2BigInteger(this.registerPanel.jGDTRTextField.getText()));
            commandReceiver.clearBuffer();
            gdtBase = gdtBase.add(model.segNo.get(x).multiply(BigInteger.valueOf(8)));
            sendCommand("xp /8bx " + gdtBase);
            String result = commandReceiver.getCommandResult(String.format("%08x", gdtBase));

            int bytes[] = new int[8];
            String[] b = result.replaceFirst("^.*:", "").split("\t");
            for (int y = 1; y <= 8; y++) {
                bytes[y - 1] = (int) CommonLib.string2long(b[y]);
            }//from  w ww.  j  a  va  2  s  . co  m

            Long gdtDescriptor = CommonLib.getLong(bytes, 0);
            System.out.println(Long.toHexString(gdtDescriptor));
            BigInteger base = CommonLib.getBigInteger(bytes[2], bytes[3], bytes[4], bytes[7], 0, 0, 0, 0);
            System.out.println(base.toString(16));

            model.linearAddress.set(x, base.add(model.searchAddress.get(x)));
        }
    }
    model.fireTableDataChanged();
}

From source file:com.peterbochs.PeterBochsDebugger.java

public void updatePageTable(BigInteger pageDirectoryBaseAddress) {
    Vector<IA32PageDirectory> ia32_pageDirectories = new Vector<IA32PageDirectory>();
    try {// w  w w.j a v a  2  s . c o m
        commandReceiver.clearBuffer();
        commandReceiver.shouldShow = false;
        jStatusLabel.setText("Updating page table");
        // commandReceiver.setCommandNoOfLine(512);
        sendCommand("xp /4096bx " + pageDirectoryBaseAddress);
        float totalByte2 = 4096 - 1;
        totalByte2 = totalByte2 / 8;
        int totalByte3 = (int) Math.floor(totalByte2);
        String realEndAddressStr;
        String realStartAddressStr;
        BigInteger realStartAddress = pageDirectoryBaseAddress;
        realStartAddressStr = realStartAddress.toString(16);
        BigInteger realEndAddress = realStartAddress.add(BigInteger.valueOf(totalByte3 * 8));
        realEndAddressStr = String.format("%08x", realEndAddress);
        String result = commandReceiver.getCommandResult(realStartAddressStr, realEndAddressStr, null);
        if (result != null) {
            String[] lines = result.split("\n");
            DefaultTableModel model = (DefaultTableModel) jPageDirectoryTable.getModel();
            while (model.getRowCount() > 0) {
                model.removeRow(0);
            }
            jStatusProgressBar.setMaximum(lines.length - 1);

            for (int y = 0; y < lines.length; y++) {
                jStatusProgressBar.setValue(y);
                String[] b = lines[y].replaceFirst("^.*:", "").trim().split("\t");

                for (int z = 0; z < 2; z++) {
                    try {
                        int bytes[] = new int[4];
                        for (int x = 0; x < 4; x++) {
                            bytes[x] = CommonLib.string2BigInteger(b[x + z * 4].substring(2).trim()).intValue();
                        }
                        long value = CommonLib.getInt(bytes, 0);
                        // "No.", "PT base", "AVL", "G",
                        // "D", "A", "PCD", "PWT",
                        // "U/S", "W/R", "P"

                        long baseL = value & 0xfffff000;
                        // if (baseL != 0) {
                        String base = "0x" + Long.toHexString(baseL);
                        String avl = String.valueOf((value >> 9) & 3);
                        String g = String.valueOf((value >> 8) & 1);
                        String d = String.valueOf((value >> 6) & 1);
                        String a = String.valueOf((value >> 5) & 1);
                        String pcd = String.valueOf((value >> 4) & 1);
                        String pwt = String.valueOf((value >> 3) & 1);
                        String us = String.valueOf((value >> 2) & 1);
                        String wr = String.valueOf((value >> 1) & 1);
                        String p = String.valueOf((value >> 0) & 1);

                        ia32_pageDirectories
                                .add(new IA32PageDirectory(base, avl, g, d, a, pcd, pwt, us, wr, p));

                        model.addRow(new String[] { String.valueOf(y * 2 + z), base, avl, g, d, a, pcd, pwt, us,
                                wr, p });
                        // }
                    } catch (Exception ex) {
                    }
                }
                jStatusLabel.setText("Updating page table " + (y + 1) + "/" + lines.length);
            }
            jPageDirectoryTable.setModel(model);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    /*
     * if (false && Global.debug &&
     * jAutoRefreshPageTableGraphCheckBox.isSelected()) {
     * System.out.println("aa"); GraphModel model = new DefaultGraphModel();
     * GraphLayoutCache view = new GraphLayoutCache(model, new
     * DefaultCellViewFactory() { public CellView createView(GraphModel
     * model, Object cell) { CellView view = null; if (model.isPort(cell)) {
     * view = new PortView(cell); } else if (model.isEdge(cell)) { view =
     * new EdgeView(cell); } else { if (cell instanceof IA32PageDirectory) {
     * view = new PageDirectoryView(cell); } else if (cell instanceof
     * IA32PageTable) { view = new JButtonView(cell, 1); } else { view = new
     * VertexView(cell); } } return view; } }); JGraph graph = new
     * JGraph(model, view);
     * 
     * // add cells
     * 
     * // DefaultGraphCell[] cells = new //
     * DefaultGraphCell[ia32_pageDirectories.size() + 1];
     * Vector<DefaultGraphCell> cells = new Vector<DefaultGraphCell>();
     * DefaultGraphCell root = new DefaultGraphCell("cr3 " +
     * jRegisterPanel1.jCR3TextField.getText());
     * GraphConstants.setGradientColor(root.getAttributes(), Color.red);
     * GraphConstants.setOpaque(root.getAttributes(), true);
     * GraphConstants.setBounds(root.getAttributes(), new
     * Rectangle2D.Double(0, 0, 140, 20)); root.add(new DefaultPort());
     * cells.add(root);
     * 
     * Vector<IA32PageDirectory> pageDirectoryCells = new
     * Vector<IA32PageDirectory>(); for (int x = 0; x <
     * ia32_pageDirectories.size(); x++) { IA32PageDirectory cell =
     * ia32_pageDirectories.get(x);
     * GraphConstants.setGradientColor(cell.getAttributes(), Color.orange);
     * GraphConstants.setOpaque(cell.getAttributes(), true);
     * GraphConstants.setBounds(cell.getAttributes(), new
     * Rectangle2D.Double(0, x * 20, 140, 20)); cell.add(new DefaultPort());
     * pageDirectoryCells.add(cell);
     * 
     * // page table String pageTableAddress =
     * ia32_pageDirectories.get(x).base; sendCommand("xp /4096bx " +
     * pageTableAddress);
     * 
     * float totalByte2 = 4096 - 1; totalByte2 = totalByte2 / 8; int
     * totalByte3 = (int) Math.floor(totalByte2); String realEndAddressStr;
     * String realStartAddressStr; String baseAddress = pageTableAddress;
     * long realStartAddress = CommonLib.string2BigInteger(baseAddress);
     * 
     * realStartAddressStr = String.format("%08x", realStartAddress); long
     * realEndAddress = realStartAddress + totalByte3 * 8; realEndAddressStr
     * = String.format("%08x", realEndAddress);
     * 
     * String result = commandReceiver.getCommandResult(realStartAddressStr,
     * realEndAddressStr); String[] lines = result.split("\n");
     * 
     * Vector<DefaultGraphCell> pageTables = new Vector<DefaultGraphCell>();
     * for (int y = 1; y < 4; y++) { String[] b =
     * lines[y].replaceFirst("         cell.add(new DefaultPort());^.*:",
     * "").trim().split("\t");
     * 
     * for (int z = 0; z < 2; z++) { try { int bytes[] = new int[4]; for
     * (int x2 = 0; x2 < 4; x2++) { bytes[x2] =
     * CommonLib.string2BigInteger(b[x2 + z *
     * 4].substring(2).trim()).intValue(); } long value =
     * CommonLib.getInt(bytes, 0);
     * 
     * String base = Long.toHexString(value & 0xfffff000); String avl =
     * String.valueOf((value >> 9) & 3); String g = String.valueOf((value >>
     * 8) & 1); String d = String.valueOf((value >> 6) & 1); String a =
     * String.valueOf((value >> 5) & 1); String pcd = String.valueOf((value
     * >> 4) & 1); String pwt = String.valueOf((value >> 3) & 1); String us
     * = String.valueOf((value >> 2) & 1); String wr = String.valueOf((value
     * >> 1) & 1); String p = String.valueOf((value >> 0) & 1);
     * IA32PageTable pageTableCell = new IA32PageTable(base, avl, g, d, a,
     * pcd, pwt, us, wr, p);
     * GraphConstants.setGradientColor(pageTableCell.getAttributes(),
     * Color.orange);
     * GraphConstants.setOpaque(pageTableCell.getAttributes(), true);
     * GraphConstants.setBounds(pageTableCell.getAttributes(), new
     * Rectangle2D.Double(0, (z + y) * 20, 140, 20)); pageTableCell.add(new
     * DefaultPort()); pageTables.add(pageTableCell); } catch (Exception ex)
     * { } } }
     * 
     * // group it and link it DefaultGraphCell pt[] =
     * pageTables.toArray(new DefaultGraphCell[] {}); DefaultGraphCell
     * vertex1 = new DefaultGraphCell(new String("page table" + x), null,
     * pt); vertex1.add(new DefaultPort()); cells.add(vertex1);
     * 
     * DefaultEdge edge = new DefaultEdge();
     * edge.setSource(cell.getChildAt(0));
     * edge.setTarget(vertex1.getLastChild());
     * 
     * GraphConstants.setLineStyle(edge.getAttributes(),
     * GraphConstants.STYLE_ORTHOGONAL);
     * GraphConstants.setRouting(edge.getAttributes(),
     * GraphConstants.ROUTING_DEFAULT); int arrow =
     * GraphConstants.ARROW_CLASSIC;
     * GraphConstants.setLineEnd(edge.getAttributes(), arrow);
     * GraphConstants.setEndFill(edge.getAttributes(), true);
     * 
     * cells.add(edge); }
     * 
     * if (pageDirectoryCells.toArray().length > 0) { IA32PageDirectory pt[]
     * = pageDirectoryCells.toArray(new IA32PageDirectory[] {});
     * DefaultGraphCell vertex1 = new DefaultGraphCell(new
     * String("Vertex1"), null, pt); vertex1.add(new DefaultPort());
     * cells.add(vertex1);
     * 
     * DefaultEdge edge = new DefaultEdge();
     * edge.setSource(root.getChildAt(0));
     * edge.setTarget(vertex1.getLastChild()); int arrow =
     * GraphConstants.ARROW_CLASSIC;
     * GraphConstants.setLineEnd(edge.getAttributes(), arrow);
     * GraphConstants.setEndFill(edge.getAttributes(), true);
     * 
     * // lastObj = cells[index]; cells.add(edge); }
     * 
     * graph.getGraphLayoutCache().insert(cells.toArray());
     * graph.setDisconnectable(false);
     * 
     * JGraphFacade facade = new JGraphFacade(graph); JGraphLayout layout =
     * new JGraphTreeLayout(); ((JGraphTreeLayout)
     * layout).setOrientation(SwingConstants.WEST); //
     * ((JGraphHierarchicalLayout) layout).setNodeDistance(100);
     * layout.run(facade); Map nested = facade.createNestedMap(true, true);
     * graph.getGraphLayoutCache().edit(nested);
     * 
     * // JGraphFacade facade = new JGraphFacade(graph); // JGraphLayout
     * layout = new JGraphFastOrganicLayout(); // layout.run(facade); // Map
     * nested = facade.createNestedMap(true, true); //
     * graph.getGraphLayoutCache().edit(nested);
     * 
     * jPageTableGraphPanel.removeAll(); jPageTableGraphPanel.add(new
     * JScrollPane(graph), BorderLayout.CENTER); }
     */

}