def check_control_bits(packet, counter):
     amount = 0
     temp_counter = Bits(int=counter, length=4)
     pos = temp_counter.find('0b1')
     pos_int = pos[0]
     for i in range(1, 8):
         temp_pos = Bits(int=i, length=4)
         res = BitArray(temp_pos ^ temp_counter)
         if res._readbin(1, pos_int) == '0' and packet._readbin(
                 1, i - 1) == '1':
             amount += 1
     return amount
    def TH260_GetFeatures(self, device: int = 0):
        """
        Use the predefined bit feature values in th260defin.h (FEATURE_xxx) to extract individual bits through a bitwise AND.
        Typically this is only for information, or to check if your board has a specific (optional) capability.
        #define FEATURE_DLL       0x0001  // DLL License available
        #define FEATURE_TTTR      0x0002  // TTTR mode available
        #define FEATURE_MARKERS   0x0004  // Markers available
        #define FEATURE_LOWRES    0x0008  // Long range mode available
        #define FEATURE_TRIGOUT   0x0010  // Trigger output available
        #define FEATURE_PROG_TD   0x0020  // Programmable deadtime available
        Parameters
        ----------
        device: (int) device index if multiple devices 0..3 (default 0)

        Returns
        -------
        list of str listing the hardware features
        """
        feature = c_int()
        res = self._TH260_GetFeatures(device, byref(feature))
        ret=[]

        if res == 0:
            feature = Bits(int=feature.value, length=32)
            if len(feature.find('0x0001')) != 0:
                ret.append("FEATURE_DLL")
            if len(feature.find('0x0002')) != 0:
                ret.append("FEATURE_TTTR")
            if len(feature.find('0x0004')) != 0:
                ret.append("FEATURE_MARKERS")
            if len(feature.find('0x0008')) != 0:
                ret.append("FEATURE_LOWRES")
            if len(feature.find('0x0010')) != 0:
                ret.append("FEATURE_TRIGOUT")
            if len(feature.find('0x0020')) != 0:
                ret.append("FEATURE_PROG_TD")

            return ret
        else:
            raise IOError(ErrorCodes(res).name)
 def testFind(self):
     a = Bits('0xabcd')
     r = a.find('0xbc')
     self.assertEqual(r[0], 4)
     r = a.find('0x23462346246', bytealigned=True)
     self.assertFalse(r)
Exemple #4
0
#!/usr/bin/env python3

from PIL import Image
from bitstring import Bits
import requests

# Download target image
targetUrl = 'https://jupiter.challenges.picoctf.org/static/011955b303f293d60c8116e6a4c5c84f/buildings.png'
targetFilename = 'buildings.png'
with open(targetFilename, 'xb') as f:
    r = requests.get(targetUrl)
    f.write(r.content)

# Extract lsb bits
with Image.open(targetFilename, 'r') as img:
    imgData = img.getdata()
rgbBytes = [byte for pixel in imgData for byte in pixel[:3]]
lsbBits = [byte & 1 for byte in rgbBytes]

# Decode message from bits, also remove null bytes for aesthetics
message = Bits(lsbBits)
nullPos = message.find('0b00000000', bytealigned=True)[0]
decodedMessage = message[:nullPos].tobytes().decode()
print(f"Flag: {decodedMessage}")
Exemple #5
0
 def testFind(self):
     a = Bits('0xabcd')
     r = a.find('0xbc')
     self.assertEqual(r[0], 4)
     r = a.find('0x23462346246', bytealigned=True)
     self.assertFalse(r)