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

Attendance parser v6.60 returning incorrect values [BUG] #50

Open
Ali-Shaikh opened this issue Aug 8, 2018 · 14 comments
Open

Attendance parser v6.60 returning incorrect values [BUG] #50

Ali-Shaikh opened this issue Aug 8, 2018 · 14 comments

Comments

@Ali-Shaikh
Copy link

Device Z40
Firmware 6.60
Protocol TCP

I am getting the attendance data but the data is incorrect. Could you please look into this.
[{"id":25356,"uid":null,"state":105,"timestamp":"2054-12-17T05:04:58.000Z","verificationType":105,"inOutStatus":74}

@mribichich
Copy link
Collaborator

Hi, the only way to do that is with the buffer data to check the parsing.

Insert a console.log(reply.toString('hex')) at the beginning of the handle function, and post the result please

something like this:

const handleOnData = reply => {
     console.log(reply.toString('hex'))

      reply = this.connectionType === ConnectionTypes.UDP ? reply : removeTcpHeader(reply);

@Ali-Shaikh
Copy link
Author

5050827d10000000dc05b56ff08102008c040000f0030000
5050827df8030000dd05570d0000020088040000b8b935800202049487002b007e0f47002c00700f4c003800f70f560060006d0fae0064007c0f62007b00660f9d007b00750fa6008700750f25009400550f8900a3005c0fd700ad009
20fef00b3009e0f5100b9004b0ff300c000900ffe00c100a90fc800c300880f9100c800480fbb00c8006f0ea200db00e90f1800e300420fdb00e500f90f7700e700370f6500ee00c40fe400f300f90fb500f400160e3e00f500390f29
00fe00c20f8b000101b70ff7000f01f60fa6001001ad0f320028012c0e1c002d012e0e47002e01b40f0d0037012c0e770037011e0f24003e01af0e06014401480e46004b01aa0f7b8b83132b07407b470613f7388bc28e837b4608ca7
acbfe610b4e09af03caf83f0e1ff33100e5fb621bb100d6f96e1a4b0e1ff30beb5e1606eafaebf9f6490f0a05151001f56d0e6b8ad3fa5b17f4eba5f48a015c1b750d6e1b6918d1fb26925d62f2ee961205e87a88f2de39a27e7cbed4
6a80520b27fbb1003672fae6b975
728026f2ad8d368ed20f3100b2050be4122cc2685e1eb97a4276dafbad8a6a80f69bde0c72805ef732fd37fdc3b26af8aa9893c5617acd02ad7fbd0581814906598a0d0f3e063d01617e4602eb6cd775336b81815d86a987ef56eb53e
b5399fb66fd8282fe4942d7380000000000000000000000000000000000000000000020420102a5245c0400a10410940801171249c264590500990f066d0c008b1180c0c2ff7b67c204002f1377780b00831c86c362c0c1c08406009f
2003c1fd760600432b7474c007004b2bf7c03bc10600a8290042fe0500832b7dc0c2c0070046306bfe77c10700483a
6d59730e00503afa563dff68561400f14186625276675cc2c0c01400f94e90776259c1c0c167c1640800525e717e800f005a5ef03e43c0feff38c01500ff5e9a896fff72786ec0821b00aa6180c2ffc26b908b78666a96c2090053646
b71c1c07e0900b26406ffff2f300600aa677dc26617009978777e907578c1ff9dc17a14005e7a6d9080c0c17bc269860a00a17a0033fec0330d009a
7e74c0c371c26e830c00607f6777c184741600a2857ac284c296ffc37c75ffc0c2c30700aa8703fffdfe4415010e8aa9936f787078c1c1791600a38b747c96c36cc08bc269780500209557c1c1c00700259853c070c1070087a460887
3040113a43d521900d3aa90c0c2c2c3c4c2c2c1c1c1c0c4c2c2c0c2fec5c1c0c0c1c210
00ebb3974e97c2c0c3c2c28b0e0051be508c7cc084571a00eebf9065c3c1c3c4c4c095ffc4c1c083c1c2c1ffc30a00c4c18cc3c3c6c5c2c2901000b7c580b7c288c3c18b88140100c549f9fcfefbc1c2c8c5c8c0c4c3c2ffc3c17c050
0bfc80cc0c1c30e00f0c783
fffcc1c398c29fc2030005c943c010008fcb4cc388c3c1c15050827da4000000dd05592701000200c1c2c266c1080111d557fbfefffc3b0411170440590800b4e51775962000dfe500c4c2c5c5c0c3926990c2c1c080c266c26fc1040
10fe870c0fd060019e9467bc30e0076ea3ac28380c1c0c182070005f040655c0c0065f2
3783c0c2c0c2c25d0800b9f4168cc27f0600b6f820c38b04
003bf94087090041f93ac2c0fec478031029023dc20310362b29c00310302c2dc104107a3a248903100f3b2d

@mribichich
Copy link
Collaborator

@Ali-Shaikh There seems to be a different type of buffer here. It's not the same as the ones that are in the library, so we need to create a new parser for this one.

Please re do the download, and send me the buffer again, and algo use a ZKAccess software and send me the attendances data so that I can try to match it to the buffer and find a pattern

@TehKittenCat
Copy link

I've a got very similar problem. Sometimes I get buffer index out of range exceptions, sometimes it manages to get data without errors but dates/ids are all messed up. I have a correctly working implementation of this version of attendance parser but it's in PHP and I don't understand it well enough to write it in JS. @mribichich Maybe you want to take a look?

@mribichich
Copy link
Collaborator

Yes please send it. And also if you can try to send me a couple of attendances and the buffer, that way it will help me understand the structure a create a new parser.

Also could you send all the info from the device: Model, Firmware version with date too, etc. because I have two devices with same 6.60 but different dates

@TehKittenCat
Copy link

ZKLibrary.php. If checked correctly it's almost the same as original PHP implementation of ZKLibrary but with changed getAttendance function. I'll send you some example attendances and device info when I get back to work at monday.

@TehKittenCat
Copy link

Ok, I'm not sure whether I'm doing this correctly but it seems our device needs ATTDATA_SIZE (zkattendance.js) of size 64 and datetime to be hex-reversed before decoding. I wrote a custom, working parser as an example:

const timeParser = require('./timestamp_parser');

module.exports.name = 'custom';

const revHex = inp => {
    let o = '';
    for (let i = inp.length; i>=0; i-=2) o += inp.substr(i, 2)
    return o;
}

module.exports.parse = attdata => {
    const raw = attdata.toString('hex').substr(4, 32);
    const uid = parseInt(raw.substr(0, 2), 16);
    const cid = parseInt(raw.substr(16, 2), 16);
    const time = timeParser.decode(parseInt(revHex(raw.substr(8, 8)), 16));
    
    return {uid, cid, time}
}

When it comes to the device model... looks like some Chinese no-name. Version method returns incredibly helpful "9".

@mribichich
Copy link
Collaborator

mribichich commented Aug 22, 2018 via email

@mribichich
Copy link
Collaborator

mribichich commented Aug 23, 2018 via email

@TehKittenCat
Copy link

Firmware version: 6.60 Aug 17 2015
Access control / reports are empty.

Some random buffers:
dd05b4e67b0002000000000015000000ec154f2300000000000000001000000095164f2300000000000000000b000000c1194f2300000000000000000d000000521b4f2300000000000000000d000000521b4f2300000000000000000c0000005c1b4f2300000000000000000c0000005d1b4f2300000000000000001d000000611c4f23000000000000000008000000661c4f23000000000000000009000000051d4f230000000000000000040000007e1e4f230000000000000000040000007f1e4f230000000000000000140000002b1f4f2300000000000000001300000067214f2300000000000000000e0000003c234f23000000000000000020000000be254f2300000000000000000a0000001e294f23000000000000000002000000fb294f230000000000000000170000002f2b4f23000000000000000007000000832d4f2300000000000000001b000000f92d4f2300000000000000001b000000fa2d4f2300000000000000001a00000064394f2300000000000000001a00000066394f23000000000000000006000000064f4f23000000000000000006000000074f4f2300000000000000001600000082824f2300000000000000001600000085824f2301000000000000001600000086824f2301000000000000000b0000007c844f2301000000000000000800000032864f2301000000000000001500000025874f2301000000000000000d0000009e8b4f2301000000000000000d0000009f8b4f2301000000000000000d000000a08b4f2301000000000000000c000000168c4f23010000000000000009000000a08d4f23010000000000000014000000f4914f2301000000000000001e00000049924f2301000000000000000400000062924f2301000000000000000400000063924f2301000000000000001d000000a7924f2301000000000000001d000000a8924f23010000000000000002000000df924f2301000000000000001300000011944f2301000000000000001300000012944f2301000000000000000700000059944f230100000000000000100000006b944f230100000000000000170000006f944f23010000000000000020000000f4954f2301000000000000001b0000000f974f2301000000000000000a000000ec994f2301000000000000001a00000010a74f2301000000000000000e00000025a84f23010000000000000006000000ecd64f23010000000000000016000000856250230000000000000000160000008662502300000000000000001e00000042675023000000000000000015000000446750230000000000000000100000001a69502300000000000000000c000000126a502300000000000000000c000000136a502300000000000000000b000000316b502300000000000000000d000000c96c502300000000

dd057f257c0002000000000014000000406d502300000000000000000a000000816d5023000000000000000009000000176e5023000000000000000004000000117050230000000000000000040000001370502300000000000000001d0000007e70502300000000000000001d0000007f705023000000000000000008000000837050230000000000000000130000002d715023000000000000000020000000e371502300000000000000000e0000009973502300000000000000001b0000007c765023000000000000000017000000527c5023000000000000000007000000bb83502300000000000000001a000000388b50230000000000000000060000008c935023000000000000000002000000c894502300000000000000001a00000005c1502301000000000000001700000009d0502301000000000000000b0000002dd650230100000000000000160000001ad750230100000000000000160000001bd7502301000000000000001500000017d8502301000000000000000c00000092da502301000000000000000d00000031dd502301000000000000000d00000031dd502301000000000000001b000000d5dd502301000000000000000a00000097de50230100000000000000090000009dde5023010000000000000010000000bfde5023010000000000000010000000c0de502301000000000000000e0000004ee2502301000000000000000e0000004fe2502301000000000000002000000098e25023010000000000000004000000e3e25023010000000000000004000000e4e2502301000000000000001300000056e4502301000000000000001e00000067e5502301000000000000001d00000027e750230100000000000000030000005aeb50230000000000000000030000005beb50230000000000000000070000009bec502301000000000000000800000015f0502301000000000000001400000026f4502301000000000000001400000028f4502301000000000000001400000029f45023010000000000000003000000a00d5123010000000000000006000000ea245123010000000000000002000000ec245123010000000000000016000000f7b0512300000000000000001e000000b0b85123000000000000000015000000ceb8512300000000000000001000000021b95123000000000000000009000000dbbc512300000000000000000b00000047bd512300000000000000000b00000048bd512300000000000000000d000000f0be512300000000000000001400000050bf512300000000000000000c0000006fbf512300000000000000000400000056c2512300000000000000001d000000c9c25123000000000000000008000000cec25123000000000000000002000000ebc35123000000000000000020000000eec3512300000000

dd05754d7d0002000000000020000000eec3512300000000000000001b0000006dc8512300000000000000000e00000050ca512300000000000000000e00000051ca5123000000000000000013000000c3cb512300000000000000001700000012cd5123000000000000000007000000e6d1512300000000000000000600000008eb51230000000000000000020000000b0a5223010000000000000016000000ab225223010000000000000016000000ac2252230100000000000000090000004f25522301000000000000001e0000005d275223010000000000000015000000ec2a522301000000000000000e000000ff2e522301000000000000001b0000004e2f522301000000000000000c000000de2f522301000000000000000d000000ec2f52230100000000000000170000004330522301000000000000001700000044305223010000000000000007000000643052230100000000000000070000008030522301000000000000001d000000bd3452230100000000000000140000008e3552230100000000000000140000008f355223010000000000000014000000903552230100000000000000200000009335522301000000000000000b0000006f36522301000000000000000b0000007036522301000000000000001000000092385223010000000000000013000000133b5223010000000000000013000000143b52230100000000000000060000000059522301000000000000000300000009165323000000000000000003000000a7475323010000000000000016000000a5a65523000000000000000016000000a8a6552300000000000000001500000091ac552300000000000000000b00000011b15523000000000000000010000000e2b1552300000000000000002000000054b3552300000000000000000d000000b1b3552300000000000000001d0000002bb455230000000000000000080000002db4552300000000000000001e00000070b45523000000000000000009000000bdb555230000000000000000170000006bb7552300000000000000001a00000021bc552300000000000000001a00000022bc552300000000000000000a00000038c0552300000000000000000a00000039c0552300000000000000000c000000f3c1552300000000000000000e0000006fc2552300000000000000001b00000078c35523000000000000000007000000bec45523000000000000000006000000adda55230000000000000000160000002219562301000000000000001600000022195623010000000000000015000000811e562301000000000000000b0000000020562301000000000000000d000000f42356230100000000000000100000003925562301000000000000001d0000003c2856230100000000000000200000003f28562301000000

@mribichich
Copy link
Collaborator

mribichich commented Aug 23, 2018 via email

@gt4company
Copy link

same issue i need my firmeware is 4.2

@ohmmee
Copy link

ohmmee commented Nov 4, 2018

using ZkAccess soft you could get something like this on the Device tab: [image: image.png] Something like this on the reports tab: [image: image.png] And something like this on the AccessControl tab: [image: image.png] With that info and the buffer from our lib, I can check everything, create tests and add the new parser You could also use the ZkAccess soft to download attendances, and use wireshark to sniff the transaction and export the whole data. You could filter the stream like this: ip.addr == 192.168.2.60 && data.len > 0 and then export it going to: Analyze -> Follow -> TCP Stream show and saved data as: Raw Right-Click on data and Select All and Copy

On Wed, Aug 22, 2018 at 8:00 PM Matias Ribichich @.> wrote: Could you use any of the ZK softwares to download that data? that way is much easier to check the parsing of attendances. both having the buffer and attendances And with the ZK soft you can get the model and firmware, so that we can link them to the new parser On Tue, Aug 21, 2018 at 6:24 AM MikuPL @.> wrote: > Ok, I'm not sure whether I'm doing this correctly but it seems our device > needs ATTDATA_SIZE (zkattendance.js) of size 64 and datetime to be > hex-reversed before decoding. I wrote a custom, working parser as an > example: > > const timeParser = require('./timestamp_parser'); > module.exports.name = 'custom'; > const revHex = inp => { > let o = ''; > for (let i = inp.length; i>=0; i-=2) o += inp.substr(i, 2) > return o; > } > module.exports.parse = attdata => { > const raw = attdata.toString('hex').substr(4, 32); > const uid = parseInt(raw.substr(0, 2), 16); > const cid = parseInt(raw.substr(16, 2), 16); > const time = timeParser.decode(parseInt(revHex(raw.substr(8, 8)), 16)); > > return {uid, cid, time} > } > > When it comes to the device model... looks like some Chinese no-name. > Version method returns incredibly helpful "9". > > — > You are receiving this because you were mentioned. > > > Reply to this email directly, view it on GitHub > <#50 (comment)>, > or mute the thread > https://github.com/notifications/unsubscribe-auth/AFe3SoIZ2SMbdFxvfV4lRs13P_Lq-9pZks5uS9HTgaJpZM4VziZu > . >

RAW TCP Stream:

5050827d08000000e80316fc00000100
5050827d08000000d0078e8ca06b0100
5050827d080000000d005094a06b0200
5050827d10000000dc05158aa06b02007c000000f0030000
5050827d84000000dd059426000002007800000040d835802f330100d5dc0100df230100c9010200cb140100d1260200e50901004b4d0200c3fe0000b173020085f100006d99020047e4000029bf020061d90000a3e5020019d10000c70c030001cc00005f2c0300d802000018000000160000000a0000009a19000001340300
f00200004800000000280300
5050827d08000000e9037390a06b0300
5050827d08000000d007b1f77c000200
5050827d08000000d0078c8ca06b0300

Attendance Data:

  1. user id(or id... if it's same): 3
    verify: 5
    state: 0
    time: 2018/11/04 21:58

  2. user id: 3
    verify: 5
    state: 0
    time: 2018/11/04 14:42

  3. user id: 3
    verify: 5
    state: 0
    time: 2018/11/04 14:42

@caobo171
Copy link

caobo171 commented Nov 8, 2019

Check my repo , I've already fixed many bugs included these bugs :
https://github.com/caobo171/node-zklib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants