github.com/LagrangeDev/LagrangeGo@v0.0.0-20240512064304-ad4a85e10cb4/client/packets/tlv/common.go (about) 1 package tlv 2 3 import ( 4 "strconv" 5 6 ftea "github.com/fumiama/gofastTEA" 7 8 "github.com/LagrangeDev/LagrangeGo/client/auth" 9 "github.com/LagrangeDev/LagrangeGo/utils" 10 "github.com/LagrangeDev/LagrangeGo/utils/binary" 11 "github.com/LagrangeDev/LagrangeGo/utils/crypto" 12 ) 13 14 // T18 默认参数 pingVersion, unknown = 0, ssoVersion = 5 15 func T18(appID, appClientVersion, uin, pingVersion, ssoVersion, unknown int) []byte { 16 return binary.NewBuilder(nil). 17 WriteU16(uint16(pingVersion)). 18 WriteU32(uint32(ssoVersion)). 19 WriteU32(uint32(appID)). 20 WriteU32(uint32(appClientVersion)). 21 WriteU32(uint32(uin)). 22 WriteU16(uint16(unknown)). 23 WriteU16(0).Pack(0x18) 24 } 25 26 // T100 dbBufVer 默认为 0 27 func T100(ssoVersion, appID, subAppID, appClientVersion, sigmap, dbBufVer int) []byte { 28 return binary.NewBuilder(nil). 29 WriteU16(uint16(dbBufVer)). 30 WriteU32(uint32(ssoVersion)). 31 WriteU32(uint32(appID)). 32 WriteU32(uint32(subAppID)). 33 WriteU32(uint32(appClientVersion)). 34 WriteU32(uint32(sigmap)). 35 Pack(0x100) 36 } 37 38 // T106 抄的时候注意参数顺序 39 func T106(appId, appClientVersion, uin int, guid string, passwordMd5, tgtgtKey, ip []byte, savePassword bool) []byte { 40 // password_md5 + bytes(4) + write_u32(uin).pack() 41 key := crypto.MD5Digest(binary.NewBuilder(nil). 42 WriteBytes(passwordMd5). 43 WriteU32(0). 44 WriteU32(uint32(uin)). 45 ToBytes(), 46 ) 47 48 body := binary.NewBuilder(nil). 49 WriteStruct(uint16(4), // tgtgt version 50 crypto.RandU32(), 51 uint32(0), // sso_version, depreciated 52 uint32(appId), 53 uint32(appClientVersion), 54 uint64(uin)). 55 WriteU32(uint32(utils.TimeStamp())). 56 WriteBytes(ip). 57 WriteBool(savePassword). 58 WriteBytes(passwordMd5). 59 WriteBytes(tgtgtKey). 60 WriteU32(0). 61 WriteBool(true). 62 WriteBytes(utils.MustParseHexStr(guid)). 63 WriteU32(0). 64 WriteU32(1). 65 WritePacketString(strconv.Itoa(uin), "u16", false). 66 ToBytes() 67 68 return binary.NewBuilder(nil). 69 WritePacketBytes(ftea.NewTeaCipher(key).Encrypt(body), "u32", true). 70 Pack(0x106) 71 } 72 73 // T107 默认参数为 1, 0x0d, 0, 1 74 func T107(picType, capType, picSize, retType int) []byte { 75 return binary.NewBuilder(nil). 76 WriteU16(uint16(picType)). 77 WriteU8(uint8(capType)). 78 WriteU16(uint16(picSize)). 79 WriteU8(uint8(retType)). 80 Pack(0x107) 81 } 82 83 func T116(subSigmap int) []byte { 84 return binary.NewBuilder(nil). 85 WriteU8(0). 86 WriteU32(12058620). // unknown? 87 WriteU32(uint32(subSigmap)). 88 WriteU8(0). 89 Pack(0x116) 90 } 91 92 func T124() []byte { 93 return binary.NewBuilder(nil). 94 WriteBytes(make([]byte, 12)). 95 Pack(0x124) 96 } 97 98 func T128(appInfoOS string, deviceGuid []byte) []byte { 99 return binary.NewBuilder(nil). 100 WriteU16(0). 101 WriteU8(0). 102 WriteU8(1). 103 WriteU8(0). 104 WriteU32(0). 105 WritePacketString(appInfoOS, "u16", false). 106 WritePacketBytes(deviceGuid, "u16", false). 107 WritePacketString("", "u16", false). 108 Pack(0x128) 109 } 110 111 // T141 默认参数 apn = []byte{0} 112 func T141(simInfo, apn []byte) []byte { 113 return binary.NewBuilder(nil). 114 WritePacketBytes(simInfo, "u32", false). 115 WritePacketBytes(apn, "u32", false). 116 Pack(0x141) 117 } 118 119 // T142 默认参数 version = 0 注意apkID长度要过32 120 func T142(apkID string, version int) []byte { 121 return binary.NewBuilder(nil). 122 WriteU16(uint16(version)). 123 // WritePacketString(apkID[:32], "u16", false). 124 // apkID长度没有32,不动了 125 WritePacketString(apkID, "u16", false). 126 Pack(0x142) 127 } 128 129 func T144(tgtgtKey []byte, appInfo *auth.AppInfo, device *auth.DeviceInfo) []byte { 130 return binary.NewBuilder(tgtgtKey). 131 WriteTLV( 132 T16e(device.DeviceName), 133 T147(appInfo.AppID, appInfo.PTVersion, appInfo.PackageName), 134 T128(appInfo.OS, utils.MustParseHexStr(device.Guid)), 135 T124(), 136 ).Pack(0x144) 137 } 138 139 func T145(guid []byte) []byte { 140 return binary.NewBuilder(nil). 141 WriteBytes(guid). 142 Pack(0x145) 143 } 144 145 func T147(appId int, ptVersion string, packageName string) []byte { 146 return binary.NewBuilder(nil). 147 WriteU32(uint32(appId)). 148 WritePacketString(ptVersion, "u16", false). 149 WritePacketString(packageName, "u16", false). 150 Pack(0x147) 151 } 152 153 func T166(imageType int) []byte { 154 return binary.NewBuilder(nil). 155 WriteI8(int8(imageType)). 156 Pack(0x166) 157 } 158 159 func T16a(noPicSig []byte) []byte { 160 return binary.NewBuilder(nil). 161 WriteBytes(noPicSig). 162 Pack(0x16a) 163 } 164 165 func T16e(deviceName string) []byte { 166 return binary.NewBuilder(nil). 167 WriteBytes(utils.S2B(deviceName)). 168 Pack(0x16e) 169 } 170 171 // T177 默认参数 buildTime=0 172 func T177(sdkVersion string, buildTime int) []byte { 173 return binary.NewBuilder(nil). 174 WriteStruct(uint8(1), uint32(buildTime)). 175 WritePacketString(sdkVersion, "u16", false). 176 Pack(0x177) 177 } 178 179 // T191 默认参数 canWebVerify=0 180 func T191(canWebVerify int) []byte { 181 return binary.NewBuilder(nil). 182 WriteU8(uint8(canWebVerify)). 183 Pack(0x191) 184 } 185 186 // T318 默认参数 tgtQr = []byte{0} 187 func T318(tgtQr []byte) []byte { 188 return binary.NewBuilder(nil). 189 WriteBytes(tgtQr). 190 Pack(0x318) 191 } 192 193 // T521 默认参数 0x13, "basicim" 194 func T521(productType int, productDesc string) []byte { 195 return binary.NewBuilder(nil). 196 WriteU32(uint32(productType)). 197 WritePacketString(productDesc, "u16", false). 198 Pack(0x521) 199 }