import sys
import json
import requests
from web3 import Web3

# Define your Binance Smart Chain node URL here
BSC_URL = 'https://bsc-dataseed1.binance.org'

# Connect to Binance Smart Chain node
w3 = Web3(Web3.HTTPProvider(BSC_URL))

# Check if connected to Binance Smart Chain node
if not w3.is_connected():
    print("Not connected to the Binance Smart Chain node.")
    sys.exit()


def check_mint_vulnerability(abi):
    for item in abi:
        if item['type'] == 'function' and item['name'] == 'mint':
            if 'internal' not in item['stateMutability']:
                return True
    return False


def check_transfer_fee_vulnerability(abi):
    for item in abi:
        if item['type'] == 'function' and item['name'] == 'transfer':
            for input in item['inputs']:
                if input['name'] == '_fee':
                    fee = int(input['value'])
                    if fee > 10:
                        return True
    return False


def check_ownable_vulnerability(abi):
    for item in abi:
        if item['type'] == 'function' and item['name'] == 'transferOwnership':
            if 'ownable' not in item.get('function_signature', ''):
                return True
    return False


def check_renounce_ownership_vulnerability(abi):
    for item in abi:
        if item['type'] == 'function' and item['name'] == 'transferOwnership':
            if item.get('function_signature', '') == 'renounceOwnership()':
                return True
    return False


def check_unusual_mappings_params(abi):
    unusual_mappings_params = ["lastClaimTimes", "excludedFromDividends", "tokenHoldersMap", "_isExcludedFromMaxWallet", "_isExcludedFromMaxTx",
    "_slipfeDeD", "_mAccount", "_release", "_sellSumETH", "_sellSum", "_buySum", "_marketersAndDevs",
    "balanceOf", "canSale", "_onSaleNum", "_intAddr", "cooldownTimer"]
    for item in abi:
        for unusual in unusual_mappings_params:
            if unusual in item.get("name", ""):
                return True
    return False


def check_suspicious_encodePacked_calls(abi):
    suspicious_calls = ["encodePacked"]
    for item in abi:
        for suspicious in suspicious_calls:
            if suspicious in item.get("function_signature", ""):
                return True
    return False


def check_hidden_address_usage(abi):
    hidden_addresses = ["TrustSwap", "receiveAddress", "deployer", "BSCGas", "Pancakeswap", "HecoGas", "MDEXBSC",
    "EtherGas", "Uniswap", "SnailExclusive", "rewardToken", "VERSOIN", "UniswapV2Router", "_otherAddress",
    "onlyAddress", "deadAddress", "allowedSeller", "dexContract", "pancakeRouterAddress"]
    for item in abi:
        for hidden in hidden_addresses:
            if hidden in item.get("name", ""):
                return True
    return False


def check_onlyOwner_modifier_usage(abi):
    onlyOwner_functions = ["setSwapTokensAtAmount", "setSwapEnabled", "enableTrading", "changeTreasuryWallet", "changeStakingWallet", "changeMarketingWallet",
    "updateFees", "claimStuckTokens", "resetTaxAmount", "updatePoolWallet", "updateCharityWallet", "updateMarketingWallet", "setAutomatedMarketMakerPair",
    "updateSellFees", "updateBuyFees", "updateRescueSwap", "updateSwapEnabled", "airdropToWallets", "enableTrading", "setDeadWallet", "setSwapTokensAtAmount",
    "swapManual", "updateGasForProcessing", "setAutomatedMarketMakerPair", "setMarketingWallet", "setKing", "setAirdropNumbs", "updateUniswapV2Router",
    "processAccount", "setBalance", "updateMinimumTokenBalanceForDividends", "updateClaimWait", "distributeCAKEDividends", "disableSelling", "enableSelling"]

    for item in abi:
        for onlyOwner in onlyOwner_functions:
            if onlyOwner in item.get("name", "") and "onlyOwner" in item.get("modifiers", []):
                return True
    return False

def analyze_contract(contract_address):

    contract_address = Web3.to_checksum_address(contract_address)

    try:

        # Get contract ABI from BCSCAN API
        abi_response = requests.get(f'https://api.bscscan.com/api?module=contract&action=getabi&address={contract_address}&apikey=<TRUFFLEHOG_REDACTED_BSCSCAN>')
        abi = json.loads(abi_response.text)['result']
        abi = json.loads(abi)

        # Create contract instance
        contract = w3.eth.contract(address=contract_address, abi=abi)

        # Analyze mint vulnerability
        if check_mint_vulnerability(abi):
            print("Mint function with potential vulnerability found.")
        else:
            print("Mint vulnerability not found.")

        # Analyze transfer fee vulnerability
        if check_transfer_fee_vulnerability(abi):
            print("High transfer fee vulnerability found.")
        else:
            print("High transfer fee vulnerability not found.")

            # Analyze ownable vulnerability
        if check_ownable_vulnerability(abi):
            print("Ownable vulnerability found.")
        else:
            print("Ownable vulnerability not found.")

         # Analyze renounce ownership vulnerability
        if check_renounce_ownership_vulnerability(abi):
            print("Renounce ownership vulnerability found.")
        else:
            print("Renounce ownership vulnerability not found.")

        # Additional vulnerability checks
        if check_unusual_mappings_params(abi):
            print("Unusual  mappings or params found.")
        else:
            print("Unusual mappings or params not found.")

        if check_suspicious_encodePacked_calls(abi):
            print("Suspicious encodePacked  calls found.")
        else:
            print("Suspicious encodePacked calls not found.")

        if check_hidden_address_usage(abi):
            print("Hidden address usage found.")
        else:
            print("Hidden address usage not found.")

        if check_onlyOwner_modifier_usage(abi):
            print("OnlyOwner modifier usage found.")
        else:
            print("OnlyOwner modifier usage not found.")

    except Exception as e:
        print("Error occurred while analyzing the contract:", e)

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python rugcheck_bsc.py[contract_address]")
        sys.exit()

    contract_address = sys.argv[1]
    analyze_contract(contract_address)

Add the above code so that it, like Rugcheck by Moonarch.app, can detect vulnerabilities in the contract code as a result of which Rugcheck by Moonarch.app displays the following warnings

_checkOwner restricts calls to an address, check it
withdraw might contain a hidden owner check, check it
withdraw restricts calls to an address, check it
Unusual mapping name minter, check usage
Unusual mapping name disabled, check usage
Unusual mapping name isWhiteList, check usage
Check usage of address erc20Token
setStakePool has onlyOwner modifier
batchDisableWallet has onlyOwner modifier
setAddress has onlyOwner modifier
disableWallet has onlyOwner modifier
setFees can probably change the fees
setEnabledSwap has onlyOwner modifier
multiSetWhiteList has onlyOwner modifier
multiSetFeeExempt has onlyOwner modifier
Check usage of address marketingFeeReceiver
Check usage of address dbToken
Check usage of address basePair
Check usage of address baseToken
Has deployed at least 4 other contracts