Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(transport): Add binary support #350

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
467 changes: 317 additions & 150 deletions cycletls/index.go

Large diffs are not rendered by default.

30 changes: 8 additions & 22 deletions cycletls/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"compress/gzip"
"compress/zlib"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"strconv"
"strings"
Expand Down Expand Up @@ -39,42 +38,29 @@ func parseUserAgent(userAgent string) UserAgent {
}

// DecompressBody unzips compressed data
func DecompressBody(Body []byte, encoding []string, content []string) (parsedBody string) {
func DecompressBody(Body []byte, encoding []string, content []string) (parsedBody []byte) {
if len(encoding) > 0 {
if encoding[0] == "gzip" {
unz, err := gUnzipData(Body)
if err != nil {
return string(Body)
return Body
}
return string(unz)
return unz
} else if encoding[0] == "deflate" {
unz, err := enflateData(Body)
if err != nil {
return string(Body)
return Body
}
return string(unz)
return unz
} else if encoding[0] == "br" {
unz, err := unBrotliData(Body)
if err != nil {
return string(Body)
return Body
}
return string(unz)
}
} else if len(content) > 0 {
decodingTypes := map[string]bool{
"image/svg+xml": true,
"image/webp": true,
"image/jpeg": true,
"image/png": true,
"image/gif": true,
"image/avif": true,
"application/pdf": true,
}
if decodingTypes[content[0]] {
return base64.StdEncoding.EncodeToString(Body)
return unz
}
}
parsedBody = string(Body)

return parsedBody

}
Expand Down
Empty file modified docs/setup.sh
100644 → 100755
Empty file.
8 changes: 3 additions & 5 deletions examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ const initCycleTLS = require('../dist/index.js');
(async () => {
const cycleTLS = await initCycleTLS();

const response = cycleTLS('https://example.com', {
const response = await cycleTLS('https://example.com', {
body: '',
ja3: '771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0',
userAgent: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0',
proxy: ''
});

response.then((out) => {
response.text().then((out) => {
console.log(out)
})


});
})();

31 changes: 31 additions & 0 deletions examples/stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require("fs");
const initCycleTLS = require('../dist/index.js');
// import initCycleTLS from '../dist/index.js'
// Typescript: import initCycleTLS from 'cycletls';

(async () => {
const cycleTLS = await initCycleTLS();

{
const response = await cycleTLS('https://localhost:8080/music.mp3', {
body: '',
ja3: '771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0',
userAgent: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0',
proxy: ''
});

response.stream.pipe(fs.createWriteStream("output_cancel.mp3"));
response.stream.destroy();
}

{
const response = await cycleTLS('https://localhost:8080/music.mp3', {
body: '',
ja3: '771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0',
userAgent: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0',
proxy: ''
});

response.stream.pipe(fs.createWriteStream("output.mp3"));
}
})();
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ func main() {
if err != nil {
log.Print("Request Failed: " + err.Error())
}
log.Println(response.Status,)
log.Println(response.Status)

}
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cycletls",
"version": "1.0.27",
"version": "1.0.26",
"description": "Spoof TLS/JA3 fingerprint in JS with help from Go",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -38,26 +38,24 @@
"bugs": {
"url": "https://github.com/Danny-Dasilva/CycleTLS/issues"
},
"engines": {
"node": ">=18.0.0"
},
"homepage": "https://github.com/Danny-Dasilva/CycleTLS#readme",
"dependencies": {
"@types/node": "^20.11.5",
"ws": "^7.5.7"
"@types/node": "^20.14.0",
"form-data": "^4.0.0",
"ws": "^8.17.0"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"concurrently": "^7.2.2",
"@types/jest": "^29.5.12",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"eslint": "^8.51.0",
"eslint": "^8.56.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"jest": "^29.7.0",
"jsdom": "^23.2.0",
"ts-jest": "^29.2.0",
"typescript": "^5.5.4"
"jsdom": "^24.1.0",
"ts-jest": "^29.1.4",
"typescript": "^5.4.5"
}
}
Loading