Skip to content

Commit

Permalink
v0.3.8: rxSink refact to emitter and generator
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin committed Jun 10, 2024
1 parent 3300110 commit b3a87f9
Show file tree
Hide file tree
Showing 24 changed files with 1,854 additions and 825 deletions.
5 changes: 2 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ module.exports = {
},
rules: {
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/non-nullable-type-assertion-style': 'off',
'@typescript-eslint/return-await': 'off',
'@typescript-eslint/strict-boolean-expressions': 'off',
'@typescript-eslint/unbound-method': 'off',
'multiline-ternary': 'off',
'no-extra-boolean-cast': 'off',
'no-return-await': 'off',
Expand All @@ -39,8 +41,5 @@ module.exports = {
tuples: 'always-multiline',
functions: 'only-multiline',
}],
'@typescript-eslint/unbound-method': ['error', {
ignoreStatic: true,
}]
},
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,8 @@ await run(ultraUsb)
- [GitHub RfidResearchGroup/ChameleonUltra](https://github.com/RfidResearchGroup/ChameleonUltra)
- [Chameleon Ultra Guide](https://chameleonultra.com/docs)
- [Chameleon Ultra GUI Documentation](https://docs.chameleonultragui.dev/)

## Dependents (projects / website using chameleon-ultra.js)

- Sil's Website: `https://drosi.nl/cu` (link is broken!)
- [Tech Security Tools's Website](https://chameleon-ultra.com/)
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"module": "./dist/index.mjs",
"name": "chameleon-ultra.js",
"type": "commonjs",
"version": "0.3.7",
"version": "0.3.8",
"bugs": {
"url": "https://github.com/taichunmin/chameleon-ultra.js/issues"
},
Expand All @@ -20,7 +20,7 @@
}
],
"dependencies": {
"@taichunmin/buffer": "^0.13.4",
"@taichunmin/buffer": "^0.13.6",
"debug": "^4.3.4",
"lodash": "^4.17.21",
"serialport": "^12.0.0",
Expand Down Expand Up @@ -67,6 +67,7 @@
"serve-static": "^1.15.0",
"supports-color": "^9.4.0",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"tsup": "^8.0.2",
"tsx": "^4.11.0",
"typedoc": "^0.25.13",
Expand Down Expand Up @@ -159,7 +160,7 @@
"dev:https": "tsx ./https.ts",
"dev:js": "yarn build:js --watch",
"dev:pug": "nodemon --watch pug --ext pug --exec \"yarn build:pug\"",
"dev": "DEBUG_COLORS=1 concurrently --names \"DOC,HTTPS,PUBLIC,PUG,TS\" -c \"bgGray,bgGreen,bgGray,bgBlue,bgYellow\" \"yarn dev:docs\" \"yarn dev:https\" \"yarn dev:public\" \"yarn dev:pug\" \"yarn dev:js\"",
"dev": "DEBUG_COLORS=1 concurrently --names \"DOC,HTTPS,PUG,TS\" -c \"bgGray,bgGreen,bgGray,bgBlue,bgYellow\" \"yarn dev:docs\" \"yarn dev:https\" \"yarn dev:pug\" \"yarn dev:js\"",
"lint:ci": "eslint --ext .mjs,.js,.js,.ts,.pug .",
"lint": "yarn lint:ci --fix",
"mkcert": "mkdir ./mkcert && mkcert -key-file ./mkcert/key.pem -cert-file ./mkcert/cert.pem -ecdsa localhost",
Expand Down
1 change: 1 addition & 0 deletions pug/include/bootstrapV4.pug
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ html(lang="zh-Hant")
//- pn532 require lodash
script(crossorigin="anonymous", src=`${baseurl}index.global.js`)
script(crossorigin="anonymous", src=`${baseurl}Crypto1.global.js`)
script(crossorigin="anonymous", src=`${baseurl}plugin/Debug.global.js`)
script(crossorigin="anonymous", src=`${baseurl}plugin/WebbleAdapter.global.js`)
script(crossorigin="anonymous", src=`${baseurl}plugin/WebserialAdapter.global.js`)
block script
4 changes: 3 additions & 1 deletion pug/src/device-settings.pug
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ block content
block script
script(crossorigin="anonymous", src="https://cdn.jsdelivr.net/npm/joi@17/dist/joi-browser.min.js")
script.
const { AnimationMode, ButtonAction, ButtonType, ChameleonUltra, DeviceMode, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
const { AnimationMode, ButtonAction, ButtonType, ChameleonDebug, ChameleonUltra, DeviceMode, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
const ultraUsb = new ChameleonUltra(true)
ultraUsb.use(new ChameleonDebug())
ultraUsb.use(new WebserialAdapter())
const ultraBle = new ChameleonUltra(true)
ultraBle.use(new ChameleonDebug())
ultraBle.use(new WebbleAdapter())

const { joi: Joi } = window
Expand Down
4 changes: 3 additions & 1 deletion pug/src/mfkey32.pug
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ block content

block script
script.
const { Buffer, ChameleonUltra, DeviceMode, FreqType, Mf1KeyType, TagType, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
const { Buffer, ChameleonDebug, ChameleonUltra, DeviceMode, FreqType, Mf1KeyType, TagType, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
const ultraUsb = new ChameleonUltra(true)
ultraUsb.use(new ChameleonDebug())
ultraUsb.use(new WebserialAdapter())
const ultraBle = new ChameleonUltra(true)
ultraBle.use(new ChameleonDebug())
ultraBle.use(new WebbleAdapter())

window.vm = new Vue({
Expand Down
4 changes: 3 additions & 1 deletion pug/src/mifare-value.pug
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ block content
block script
script(crossorigin="anonymous", src="https://cdn.jsdelivr.net/npm/joi@17/dist/joi-browser.min.js")
script.
const { Buffer, ChameleonUltra, DeviceMode, Mf1KeyType, Mf1VblockOperator, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
const { Buffer, ChameleonDebug, ChameleonUltra, DeviceMode, Mf1KeyType, Mf1VblockOperator, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
const ultraUsb = new ChameleonUltra(true)
ultraUsb.use(new ChameleonDebug())
ultraUsb.use(new WebserialAdapter())
const ultraBle = new ChameleonUltra(true)
ultraBle.use(new ChameleonDebug())
ultraBle.use(new WebbleAdapter())

window.vm = new Vue({
Expand Down
36 changes: 19 additions & 17 deletions pug/src/mifare1k.pug
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ block content
block script
script(crossorigin="anonymous", src="https://cdn.jsdelivr.net/npm/joi@17/dist/joi-browser.min.js")
script.
const { AnimationMode, Buffer, ButtonAction, ChameleonUltra, DeviceMode, FreqType, TagType, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
const { AnimationMode, Buffer, ButtonAction, ChameleonDebug, ChameleonUltra, DeviceMode, FreqType, TagType, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
const ultraUsb = new ChameleonUltra(true)
ultraUsb.use(new ChameleonDebug())
ultraUsb.use(new WebserialAdapter())
const ultraBle = new ChameleonUltra(true)
ultraBle.use(new ChameleonDebug())
ultraBle.use(new WebbleAdapter())

const WELL_KNOWN_KEYS = ['ffffffffffff', 'a0a1a2a3a4a5', 'd3f7d3f7d3f7']
Expand Down Expand Up @@ -275,14 +277,14 @@ block script
await ultra.cmdMf1SetGen2Mode(this.ss.gen2)
await ultra.cmdMf1SetWriteMode(this.ss.write)
await ultra.cmdHf14aSetAntiCollData({
atqa: Buffer.fromHexString(this.ss.atqa).reverse(),
ats: Buffer.fromHexString(this.ss.ats),
sak: Buffer.fromHexString(this.ss.sak),
uid: Buffer.fromHexString(this.ss.uid),
atqa: Buffer.from(this.ss.atqa, 'hex').reverse(),
ats: Buffer.from(this.ss.ats, 'hex'),
sak: Buffer.from(this.ss.sak, 'hex'),
uid: Buffer.from(this.ss.uid, 'hex'),
})
for (let i = 0; i < 16; i++) {
if (!this.ss.toggle[i]) continue
const sectorData = Buffer.fromHexString(this.ss.body[i])
const sectorData = Buffer.from(this.ss.body[i], 'hex')
await ultra.cmdMf1EmuWriteBlock(i << 2, sectorData)
}
await Swal.fire({ icon: 'success', title: 'Emulate success' })
Expand Down Expand Up @@ -339,7 +341,7 @@ block script
const ultra = this.ultra
for (let i = 0; i < 16; i++) {
if (!this.ss.toggle[i]) continue
const sectorData = Buffer.fromHexString(this.ss.body[i])
const sectorData = Buffer.from(this.ss.body[i], 'hex')
await ultra.mf1Gen1aWriteBlocks(i << 2, sectorData)
this.showLoading(genSwalCfg(i + 1))
}
Expand Down Expand Up @@ -399,7 +401,7 @@ block script
for (let i = 0; i < 16; i++) {
try {
if (!this.ss.toggle[i]) continue
const sectorData = Buffer.fromHexString(this.ss.body[i])
const sectorData = Buffer.from(this.ss.body[i], 'hex')
const { success } = await ultra.mf1WriteSectorByKeys(i, keys, sectorData)
for (let j = 0; j < 4; j++) if (!success[j]) failed.push(i * 4 + j)
} catch (err) {
Expand All @@ -424,7 +426,7 @@ block script
let keys = []
for (let i = 0; i < 16; i++) {
if (!this.ss.toggle[i]) continue
const sectorData = Buffer.fromHexString(this.ss.body[i])
const sectorData = Buffer.from(this.ss.body[i], 'hex')
if (sectorData.length !== 64) continue
keys.push(..._.map([48, 58], offset => sectorData.subarray(offset, offset + 6).toString('hex')))
}
Expand Down Expand Up @@ -490,15 +492,15 @@ block script
const json = JSON5.parse(buf.toString('utf8'))
if (json.FileType !== 'mfcard') throw new Error(`Invalid file type: ${json.FileType}`)
if (!_.isNil(json?.Card?.UID)) this.$set(this.ss, 'uid', _.toLower(json.Card.UID))
if (!_.isNil(json?.Card?.ATQA)) this.$set(this.ss, 'atqa', Buffer.fromHexString(json.Card.ATQA).reverse().toString('hex'))
if (!_.isNil(json?.Card?.ATQA)) this.$set(this.ss, 'atqa', Buffer.from(json.Card.ATQA, 'hex').reverse().toString('hex'))
if (!_.isNil(json?.Card?.SAK)) this.$set(this.ss, 'sak', json.Card.SAK)
if (!_.isNil(json?.blocks)) {
for (let i = 0; i < 16; i++) {
const sectorData = new Buffer(64)
for (let j = 0; j < 4; j++) {
const blockhex = json?.blocks?.[i * 4 + j] ?? ''
if (blockhex.length !== 32) continue
const blockbuf = Buffer.fromHexString(blockhex.replaceAll('-', '0'))
const blockbuf = Buffer.from(blockhex.replaceAll('-', '0'), 'hex')
if (blockbuf.length !== 16) continue
blockbuf.copy(sectorData, j * 16)
}
Expand All @@ -507,7 +509,7 @@ block script
}
},
async btnCardImportEml (file, buf) {
buf = Buffer.fromHexString(buf.toString('utf8').replaceAll('-', '0'))
buf = Buffer.from(buf.toString('utf8').replaceAll('-', '0'), 'hex')
if (buf.length !== 1024) throw new Error(`Invalid eml size: ${buf.length} bytes`)
for (let i = 0; i < 16; i++) {
const sectorData = buf.subarray(i * 64, (i + 1) * 64)
Expand All @@ -523,7 +525,7 @@ block script
blockNo = _.parseInt(row.slice(9)) * 4
} else if (/^[0-9a-fA-F-]{32}$/.test(row)) { // hex
if (blockNo >= 64) throw new Error(`Invalid block number: ${blockNo}`)
const blockbuf = Buffer.fromHexString(row.replaceAll('-', '0'))
const blockbuf = Buffer.from(row.replaceAll('-', '0'), 'hex')
if (blockbuf.length !== 16) throw new Error(`Invalid block size: ${blockbuf.length} bytes`)
blockbuf.copy(buf, blockNo * 16)
blockNo++
Expand All @@ -534,13 +536,13 @@ block script
async btnCardExport () {
const card = new Buffer(1024)
for (let i = 0; i < 16; i++) {
const sectorData = Buffer.fromHexString(this.ss.body[i])
const sectorData = Buffer.from(this.ss.body[i], 'hex')
if (sectorData.length !== 64) continue // skip invalid sector
sectorData.copy(card, i * 64)
}
const uid = Buffer.fromHexString(this.ss.uid)
const atqa = Buffer.fromHexString(this.ss.atqa).reverse()
const sak = Buffer.fromHexString(this.ss.sak)
const uid = Buffer.from(this.ss.uid, 'hex')
const atqa = Buffer.from(this.ss.atqa, 'hex').reverse()
const sak = Buffer.from(this.ss.sak, 'hex')

// helper
const toHex = buf => _.toUpper(buf.toString('hex'))
Expand Down
5 changes: 3 additions & 2 deletions pug/src/test.pug
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ block script
script(crossorigin="anonymous", src="https://cdn.jsdelivr.net/npm/vconsole@3/dist/vconsole.min.js")
script.
window.vConsole = new window.VConsole()
const { ChameleonUltra, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
window.Buffer = ChameleonUltraJS.Buffer
const { Buffer, ChameleonDebug, ChameleonUltra, Debug, WebbleAdapter, WebserialAdapter } = ChameleonUltraJS // eslint-disable-line
const ultraUsb = new ChameleonUltra(true)
ultraUsb.use(new ChameleonDebug())
ultraUsb.use(new WebserialAdapter())
const ultraBle = new ChameleonUltra(true)
ultraBle.use(new ChameleonDebug())
ultraBle.use(new WebbleAdapter())

window.vm = new Vue({
Expand Down
Loading

0 comments on commit b3a87f9

Please sign in to comment.