Skip to content

Commit

Permalink
improve mf1CheckSectorKeys and some fixup (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin authored Jan 17, 2024
2 parents 413f5e2 + b632079 commit d858cd0
Show file tree
Hide file tree
Showing 16 changed files with 1,098 additions and 874 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ module.exports = {
imports: 'always-multiline',
objects: 'always-multiline',
}],
'@typescript-eslint/unbound-method': ['error', {
ignoreStatic: true,
}]
},
}
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
echo 'secrets=${{ toJSON(secrets) }}'
echo 'steps=${{ toJSON(steps) }}'
echo 'vars=${{ toJSON(vars) }}'
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: 'yarn'
- name: install, lint, test, build
run: |
Expand All @@ -51,30 +51,30 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: 'yarn'
- uses: actions/configure-pages@v3
- name: install and build
run: |
set -ex
yarn
yarn test:ci
yarn build
- name: Coveralls
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
with:
path: './dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
- name: 發布至 npm
uses: JS-DevTools/npm-publish@v1
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/npm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ on:
jobs:
test:
runs-on: ubuntu-latest
container: node:18
container: node:20
steps:
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
- name: install and npm test
run: |
set -ex
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ out
/.rollup.cache
/*.ts
/dist/docs
/jest.config.cjs
/pages
/pug
/src/example
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"repository": "[email protected]:taichunmin/chameleon-ultra.js.git",
"type": "module",
"unpkg": "dist/iife/index.min.js",
"version": "0.2.18",
"version": "0.2.19",
"bugs": {
"url": "https://github.com/taichunmin/chameleon-ultra.js/issues"
},
Expand All @@ -32,28 +32,28 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@tsconfig/node-lts": "^20.1.0",
"@rollup/plugin-typescript": "^11.1.6",
"@tsconfig/node-lts": "^20.1.1",
"@types/debug": "^4.1.12",
"@types/finalhandler": "^1.2.3",
"@types/html-minifier": "^4.0.5",
"@types/jest": "^29.5.11",
"@types/livereload": "^0.9.5",
"@types/lodash": "^4.14.202",
"@types/node": "^20.10.5",
"@types/node": "^20.11.4",
"@types/pug": "^2.0.10",
"@types/serve-static": "^1.15.5",
"@types/uglify-js": "^3.17.4",
"@types/web-bluetooth": "^0.0.20",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"chokidar": "^3.5.3",
"concurrently": "^8.2.2",
"dayjs": "^1.11.10",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
"eslint-config-standard-with-typescript": "^43.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.5.0",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-pug": "^1.2.5",
"finalhandler": "^1.2.0",
Expand All @@ -65,7 +65,7 @@
"nodemon": "^3.0.2",
"pug": "^3.0.2",
"rimraf": "^5.0.5",
"rollup": "^4.9.1",
"rollup": "^4.9.5",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-polyfill-node": "^0.13.0",
"rollup-plugin-version-injector": "^1.3.3",
Expand All @@ -74,10 +74,11 @@
"ts-jest": "^29.1.1",
"tslib": "^2.6.2",
"tsx": "^4.7.0",
"typedoc": "^0.25.4",
"typedoc-plugin-mdn-links": "^3.1.8",
"typedoc-plugin-missing-exports": "^2.1.0",
"typedoc": "^0.25.7",
"typedoc-plugin-mdn-links": "^3.1.12",
"typedoc-plugin-missing-exports": "^2.2.0",
"typedoc-plugin-rename-defaults": "^0.7.0",
"typedoc-plugin-zod": "^1.1.2",
"typescript": "^5.3.3",
"uglify-js": "^3.17.4",
"utility-types": "^3.10.0"
Expand Down
8 changes: 4 additions & 4 deletions pug/src/mifare1k.pug
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ block content
.row.mx-n1.mb-2
.col.px-1: button.btn.btn-block.btn-outline-success(@click="btnGen2Read") #[i.fa.fa-fw.fa-upload] Read
.col.px-1: button.btn.btn-block.btn-outline-primary(@click="btnGen2Write") #[i.fa.fa-fw.fa-download] Write
button.btn.btn-sm.btn-block.btn-outline-info.mb-2(@click="btnKeysGrab") #[i.fa.mr-1.fa-key] Grab keys from Mifare Data
button.btn.btn-sm.btn-block.btn-outline-info.mb-2(@click="btnKeysGrab") #[i.fa.mr-1.fa-key] Grab keys from Mifare Dump
button.btn.btn-sm.btn-block.btn-outline-secondary.mb-2(@click="btnKeysReset") #[i.fa.mr-1.fa-fire] Reset to well-known keys
.card-body.px-3.pt-3.pb-2.letter-spacing-n1px.border-top
h6.card-title UID (Chinese Magic Card gen1a)
.row.mx-n1.mb-2
.col.px-1: button.btn.btn-block.btn-outline-success(@click="btnGen1aRead") #[i.fa.fa-fw.fa-upload] Read
.col.px-1: button.btn.btn-block.btn-outline-primary(@click="btnGen1aWrite") #[i.fa.fa-fw.fa-download] Write
.card.shadow-sm.mb-2
h6.card-header.bg-light #[i.fa.fa-id-card.mr-1] Mifare Data
h6.card-header.bg-light #[i.fa.fa-id-card.mr-1] Mifare Dump
.card-body.px-3.pt-3.pb-2.letter-spacing-n1px
input.d-none(type="file", ref="cardImport", @change="cardImport?.cb?.($event.target.files[0])")
.row.mx-n1.mb-2
.col.px-1: button.btn.btn-block.btn-outline-success(@click="btnCardImport") #[i.fa.fa-fw.fa-file-code-o] Import
.col.px-1: button.btn.btn-block.btn-outline-primary(@click="btnCardExport") #[i.fa.fa-fw.fa-floppy-o] Export
button.btn.btn-sm.btn-block.btn-outline-danger.mb-2(@click="btnCardReset") #[i.fa.mr-1.fa-repeat] Reset to empty mifare
button.btn.btn-sm.btn-block.btn-outline-danger.mb-2(@click="btnCardReset") #[i.fa.mr-1.fa-repeat] Reset to empty dump
.card-body.px-3.pt-3.pb-2.letter-spacing-n1px.border-top
h6.card-title Anit Collision
.input-group.input-group-sm.mb-2.was-validated
Expand All @@ -120,7 +120,7 @@ block content
input.form-control(pattern="([\\dA-Fa-f]{2})*", placeholder="Hex format of ATS", v-model="ss.ats")
.input-group-append: button.btn.btn-outline-secondary(type="button", @click="ss.ats = ''") #[i.fa.fa-fw.fa-times]
.card-body.px-3.pt-3.pb-2.letter-spacing-n1px.border-top
h6.card-title Mifare 1k Card Data
h6.card-title Mifare 1k Card Dump
.input-group.input-group-sm.mb-2(v-for="i in _.times(16)")
.input-group-prepend: label.input-group-text.justify-content-center.flex-column(style="width: 2rem", :for="`i-toggle-${i}`")
input.my-2(type="checkbox", v-model="ss.toggle[i]", :id="`i-toggle-${i}`")
Expand Down
33 changes: 23 additions & 10 deletions src/ChameleonUltra.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import _ from 'lodash'
import { Buffer } from './buffer'
import { ChameleonUltra } from './ChameleonUltra'
import BufferMockAdapter from './plugin/BufferMockAdapter'
import {
ChameleonUltra,

// enum
AnimationMode,
ButtonAction,
ButtonType,
Expand All @@ -17,7 +16,7 @@ import {
Mf1VblockOperator,
Slot,
TagType,
} from './ChameleonUltra'
} from './enums'

describe('ChameleonUltra with BufferMockAdapter', () => {
let ultra: ChameleonUltra
Expand Down Expand Up @@ -1134,7 +1133,7 @@ describe('ChameleonUltra with BufferMockAdapter', () => {
test('#mf1CheckSectorKeys()', async () => {
// arrange
adapter.send.push(Buffer.fromHexString('11ef 07d7 0000 0000 22 00'))
adapter.send.push(Buffer.fromHexString('11ef 07d7 0000 0000 22 00'))
adapter.send.push(Buffer.fromHexString('11ef 07d8 0000 0010 11 000000000000ff078069ffffffffffff 17'))

// act
const keys = Buffer.from('FFFFFFFFFFFF\n000000000000\nA0A1A2A3A4A5\nD3F7D3F7D3F7', 'hex').chunk(6)
Expand All @@ -1146,15 +1145,15 @@ describe('ChameleonUltra with BufferMockAdapter', () => {
[Mf1KeyType.KEY_B]: Buffer.fromHexString('FFFFFFFFFFFF'),
})
expect(adapter.recv).toEqual([
Buffer.fromHexString('11ef 07d7 0000 0008 1a 6103ffffffffffff a2'),
Buffer.fromHexString('11ef 07d7 0000 0008 1a 6003ffffffffffff a3'),
Buffer.fromHexString('11ef 07d8 0000 0008 19 6003ffffffffffff a3'),
])
})

test('#mf1ReadSectorByKeys()', async () => {
// arrange
adapter.send.push(Buffer.fromHexString('11ef 07d7 0000 0000 22 00'))
adapter.send.push(Buffer.fromHexString('11ef 07d7 0000 0000 22 00'))
adapter.send.push(Buffer.fromHexString('11ef 07d8 0000 0010 11 000000000000ff078069ffffffffffff 17'))
adapter.send.push(Buffer.fromHexString('11ef 07d8 0000 0010 11 877209e11d0804000392abdef258ec90 10'))
adapter.send.push(Buffer.fromHexString('11ef 07d8 0000 0010 11 00000000000000000000000000000000 00'))
adapter.send.push(Buffer.fromHexString('11ef 07d8 0000 0010 11 00000000000000000000000000000000 00'))
Expand All @@ -1175,8 +1174,8 @@ describe('ChameleonUltra with BufferMockAdapter', () => {
success: [true, true, true, true],
})
expect(adapter.recv).toEqual([
Buffer.fromHexString('11ef 07d7 0000 0008 1a 6103ffffffffffff a2'),
Buffer.fromHexString('11ef 07d7 0000 0008 1a 6003ffffffffffff a3'),
Buffer.fromHexString('11ef 07d8 0000 0008 19 6003ffffffffffff a3'),
Buffer.fromHexString('11ef 07d8 0000 0008 19 6100ffffffffffff a5'),
Buffer.fromHexString('11ef 07d8 0000 0008 19 6101ffffffffffff a4'),
Buffer.fromHexString('11ef 07d8 0000 0008 19 6102ffffffffffff a3'),
Expand All @@ -1187,7 +1186,7 @@ describe('ChameleonUltra with BufferMockAdapter', () => {
test('#mf1WriteSectorByKeys()', async () => {
// arrange
adapter.send.push(Buffer.fromHexString('11ef 07d7 0000 0000 22 00'))
adapter.send.push(Buffer.fromHexString('11ef 07d7 0000 0000 22 00'))
adapter.send.push(Buffer.fromHexString('11ef 07d8 0000 0010 11 000000000000ff078069ffffffffffff 17'))
adapter.send.push(Buffer.fromHexString('11ef 07d9 0000 0000 20 00'))
adapter.send.push(Buffer.fromHexString('11ef 07d9 0000 0000 20 00'))
adapter.send.push(Buffer.fromHexString('11ef 07d9 0000 0000 20 00'))
Expand All @@ -1206,8 +1205,8 @@ describe('ChameleonUltra with BufferMockAdapter', () => {
// assert
expect(actual).toEqual({ success: [true, true, true, true] })
expect(adapter.recv).toEqual([
Buffer.fromHexString('11ef 07d7 0000 0008 1a 6107ffffffffffff 9e'),
Buffer.fromHexString('11ef 07d7 0000 0008 1a 6007ffffffffffff 9f'),
Buffer.fromHexString('11ef 07d8 0000 0008 19 6007ffffffffffff 9f'),
Buffer.fromHexString('11ef 07d9 0000 0018 08 6104ffffffffffff00000000000000000000000000000000 a1'),
Buffer.fromHexString('11ef 07d9 0000 0018 08 6105ffffffffffff00000000000000000000000000000000 a0'),
Buffer.fromHexString('11ef 07d9 0000 0018 08 6106ffffffffffff00000000000000000000000000000000 9f'),
Expand All @@ -1229,3 +1228,17 @@ describe('ChameleonUltra with BufferMockAdapter', () => {
expect(actual).toBe(expected)
})
})

test('.mf1TrailerBlockNoOfSector()', async () => {
const actual = _.times(40, ChameleonUltra.mf1TrailerBlockNoOfSector)
expect(actual).toEqual([
// mifare classic 1k
3, 7, 11, 15, 19, 23, 27, 31,
35, 39, 43, 47, 51, 55, 59, 63,
// mifare classic 2k
67, 71, 75, 79, 83, 87, 91, 95,
99, 103, 107, 111, 115, 119, 123, 127,
// mifare classic 4k
143, 159, 175, 191, 207, 223, 239, 255,
])
})
Loading

0 comments on commit d858cd0

Please sign in to comment.