257 lines
9.7 KiB
C
257 lines
9.7 KiB
C
#include "usbutes.h"
|
|
#include "fjpvutes.h"
|
|
#include "pgmutes.h"
|
|
|
|
|
|
|
|
|
|
|
|
void unmask(typImg * p){
|
|
int i = 0;
|
|
for (i=0; i< p->w; i++){
|
|
*(p->imgc + PICSIZ/4 + i) = ( *(p->imgc + PICSIZ/4 - p->w + i)
|
|
+ *(p->imgc + PICSIZ/4 + p->w + i) ) /2;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int quadrant(typImg * pImg) {
|
|
int i = 0;
|
|
int j = 0;
|
|
int val = 0;
|
|
// q1 q3
|
|
// q2 q4
|
|
int q1 = 0;
|
|
int q2 = 0;
|
|
int q3 = 0;
|
|
int q4 = 0;
|
|
unsigned char * p = pImg->imgc;
|
|
int h = pImg->h;
|
|
int w = pImg->w;
|
|
int div = w*h/4;
|
|
for (i=0; i<h; i++){
|
|
for (j=0; j<w; j++){
|
|
val = p[i*w + j] ;
|
|
if (i<h/2 && j<w/2){
|
|
q1+=val;
|
|
}
|
|
if (i>h/2 && j<w/2){
|
|
q2+=val;
|
|
}
|
|
if (i<h/2 && j>w/2){
|
|
q3+=val;
|
|
}
|
|
if (i>h/2 && j>w/2){
|
|
q4+=val;
|
|
}
|
|
}
|
|
}
|
|
q1 = (int)(q1/(div));
|
|
q2 = (int)(q2/(div));
|
|
q3 = (int)(q3/(div));
|
|
q4 = (int)(q4/(div));
|
|
printf("quadrants: %d %d %d %d \n", q1, q2, q3 ,q4);
|
|
if (q1<TOOFAR && q2<TOOFAR && q3<TOOFAR && q4<TOOFAR){
|
|
printf("too far - move hand nearer\n");
|
|
return 1;
|
|
}
|
|
if (q1>TOONEAR && q2>TOONEAR && q3>TOONEAR && q4>TOONEAR){
|
|
printf("too near - move hand away\n");
|
|
return 2;
|
|
}
|
|
if (q1 > q2 && q3 > q4){
|
|
printf("pitch - make your hand flatter\n");
|
|
return 3;
|
|
}
|
|
if (q1 > q2 && q3 > q4){
|
|
printf("pitch - make your hand flatter\n");
|
|
return 4;
|
|
}
|
|
if (q1 < q3 && q2 < q4){
|
|
printf("roll - make your hand flatter\n");
|
|
return 5;
|
|
}
|
|
if (q1 > q3 && q2 > q4){
|
|
printf("roll - make your hand flatter\n");
|
|
return 6;
|
|
}
|
|
printf("******************* GOOD SCAN *****************\n");
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
// PALMSECURE : make some preparations (security stuff)
|
|
int prep(libusb_device_handle * hdev) {
|
|
int res= 0;
|
|
int i = 0;
|
|
int j = 0;
|
|
unsigned char * p;
|
|
char device_key[18];
|
|
unsigned char mask[PICSIZ];
|
|
memset(&mask,0,sizeof(mask));
|
|
|
|
printf(" preamble with device handle at %p\n", hdev);
|
|
p = ctlxfer(hdev, 0xc0, 0xa0, 0, 0, 3); // returns a0 00 cb <- defo needed
|
|
//p = ctlxfer(hdev, 0xc0, 0x29, 0, 0, 4); // returns 29 00 03 00 (probably means "flag value is 3") seems_redundanct
|
|
//p = ctlxfer(hdev, 0xc0, 0x66, 0, 0, 3); // returns 66 00 00 seems_redundanct
|
|
//p = ctlxfer(hdev, 0xc0, 0xa3, 0, 0, 4); // returns a3 92 cd 01 seems_redundanct
|
|
|
|
printf("I**** PalmSecure: Connected to device\n");
|
|
//p = ctlxfer(hdev, 0xc0, 0x29, 1, 4, 4); // returns 29010400 (probably means "flag value is 4") appears to switch on encryption, so seems redundant
|
|
|
|
// We initialize device's random generator with this method, it seems
|
|
//p = ctlxfer(hdev, 0xc0, 0x35, rand() % 0xffff, rand() % 0xffff, sizeof(device_key)); // returns 3500 + encryption key seems_redundanct
|
|
printf("***SEC KEY*** (different for every device)\n");
|
|
hexdump(p,sizeof(device_key),1);
|
|
memcpy(&device_key, p+2, sizeof(device_key));
|
|
printf("*************\n");
|
|
|
|
// send a blank mask
|
|
//p = ctlxfer(hdev, 0xc0, 0x36, 0, 0, 3); seems_redundanct
|
|
//res = bulkSend(hdev, 0x01, mask, sizeof(mask)); seems_redundanct
|
|
|
|
//ctlxfer(hdev, 0xc0, 0x29, 1, 0, 4); // returns 29010400 (probably means something)
|
|
//ctlxfer(hdev, 0xc0, 0xf6, 9, 0, 168); // returns a400000002000000d0051000b7071000d7a3703d0ad7fd3fd7a3703d0ad7a
|
|
//33f6666666666565e401c041000f80410003108ac1c5a640040367689eaad81ad3f713d0ad7a3605540e80210004b031000f0a7c64b378901404faf946588
|
|
//63b53f52b81e85eb314e400e0210003e021000fed478e9263102406002b7eee6a9be3fae47e17a144e4540740110008c011000cff753e3a59b024024624a2
|
|
//4d1cbc43f0ad7a3703d0a3e40
|
|
//ctlxfer(hdev, 0xc0, 0xf6, 8, 0, 152); // returns 9400000001000000000000000000004000000000000032400000000000008
|
|
//4400000000000007e40fa7e6abc7493783f0038b1e02533833fccc5bd1f468d54bf00001ae91ded883f00ac11642c67ed3f4ba5ca32f867b0bfc42951a36f
|
|
//36793f34fe9ffa4662f43fe3d40ddaa64bd53f9b186be9afb2d9bf693754c7b3e55240aee258d2929a67bf504164df91a63dbf953ead43900be9bf seems_redundanct
|
|
|
|
//ctlxfer(hdev, 0xc0, 0xf6, 7, 0, 302); // returns 3401000001000000040000000000000061e849533fe226c0190e2d82fc282
|
|
//7c00000000000000000094155c358418b3f60805047ad44513fd6fd521d45ffef3f7eb6d422de042740cdccd212dc4a27c00000000000000000433ed92b61
|
|
//9f7b3f0f25c8d5ce9661bf3816387acbffef3f29a96ce37edc26c072cc748eef102740000000000000000082f2c7d86e53933f9a4c9416e67b8a3f77fc491
|
|
//6dbfdef3fac1796de70ed2640e428b29c3ce02640000000000000000033f14bd221639f3ffd970612085827bf5f59a39326fcef3f020004004201f0004201
|
|
//ef004301f5004801f20000000000d2a12dffc12342400901b700f800a6007b01b6008c01a5000a012e01fa003e0180012a0191013b01bff27cd4352453402
|
|
//901d7001d01cb005b01d6006701ca002a010e011f01 seems_redundanct
|
|
|
|
lights_off(hdev);
|
|
printf("PalmSecure: preparations done");
|
|
|
|
return 0;
|
|
}
|
|
|
|
// PALMSECURE : get an image
|
|
unsigned char * capture_on(libusb_device_handle * pdev) {
|
|
|
|
printf("Capture!");
|
|
//ctlxfer(pdev, 0xc0, 0x4e, 0, 0, 3); // returns 4e0100 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x4e, 1, 0, 3); // returns 4e0100 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x4e, 2, 0, 3); // returns 4e0100 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x4e, 3, 0, 3); // returns 4e0100 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x46, 0x5d0, 0, 3); // returns 460100 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x47, 0x10, 0, 3); // returns 470100 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x49, 0x100, 0, 3); // returns 490100 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x4a, 0x78, 1, 5); // returns 4a01005802 - height of encrypted region > 0 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x46, 0xc8, 3, 3); // returns 460100 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x47, 0x10, 3, 3); // returns 470100 seems_redundanct
|
|
//ctlxfer(pdev, 0xc0, 0x49, 0x100, 3, 3); // returns 490100 seems_redundanct
|
|
ctlxfer(pdev, 0xc0, 0x42, 0x100, 2, 3); // returns 420100 seems_needed
|
|
ctlxfer(pdev, 0xc0, 0x43, 0, 0, 3); // returns 430100 < defo needed
|
|
ctlxfer(pdev, 0xc0, 0x4a, 0, 480, 5); // returns 4a0100b004 - image height? < defo needed
|
|
|
|
}
|
|
|
|
//
|
|
int lights_on(libusb_device_handle * hdev) {
|
|
// switch on lights?
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x07, 1, 8); // returns 2707000000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x08, 1, 8); // returns 2708000000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x00, 1, 6); // returns 270000280000 seems_redundanct
|
|
}
|
|
|
|
int lights_off(libusb_device_handle * hdev) {
|
|
// switch off all lights?
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0, 0, 6); // returns 270000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x05, 0, 8); // returns 2705000000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x06, 0, 8); // returns 2706000000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x07, 0, 8); // returns 2707000000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x08, 0, 8); // returns 2708000000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x09, 0, 8); // returns 2709000000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x0a, 0, 8); // returns 270a000000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x0b, 0, 8); // returns 270b000000000000 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x27, 0x0c, 0, 8); // returns 270c000000000000 seems_redundanct
|
|
|
|
}
|
|
|
|
int fuzz(libusb_device_handle * hdev, typPics * pPics){
|
|
int i = 0;
|
|
unsigned char * p;
|
|
for (i=0; i< 255; i++){
|
|
printf("%d %x %d %d\n", 0xc0, 0x44, i, 0);
|
|
ctlxfer(hdev, 0xc0, 0x27, 0, i, 6); // returns 440100b00400
|
|
p = bulkReceive(hdev, 2, PICSIZ); // normal picture
|
|
memcpy(pPics->pvisible->imgc,p,PICSIZ);
|
|
pgmascii(pPics->pvisible, 16);
|
|
sleep(1);
|
|
}
|
|
}
|
|
|
|
int detect(libusb_device_handle * hdev, typPics * pPics) {
|
|
|
|
//ctlxfer(hdev, 0xc0, 0x4d, 0x78, 240, 5); // resize returns 4d01005802 seems_redundanct
|
|
//ctlxfer(hdev, 0xc0, 0x58, 0, 0xf0f, 56);
|
|
// returns 5801000000000808080808090809090808080809080908090808090807080808080808080808080909080908080908080808080808080800
|
|
|
|
unsigned char * p;
|
|
unsigned char * q;
|
|
unsigned char * r;
|
|
int i = 0;
|
|
|
|
capture_on(hdev);
|
|
//lights_on(hdev);
|
|
|
|
printf("\n==== Visible Spectrum capture\n");
|
|
ctlxfer(hdev, 0xc0, 0x44, 0, 1, 6); // returns 440100b00400
|
|
p = bulkReceive(hdev, 2, PICSIZ); // normal picture
|
|
memcpy(pPics->pvisible->imgc,p,PICSIZ);
|
|
|
|
printf("\n==== Regular IR capture\n");
|
|
ctlxfer(hdev, 0xc0, 0x44, 0, 0, 6); // returns 440100b00400
|
|
p = bulkReceive(hdev, 2, PICSIZ); // IR picture
|
|
|
|
ctlxfer(hdev, 0xc0, 0x44, 0, 0, 6); // returns 440100b00400
|
|
q = bulkReceive(hdev, 2, PICSIZ); // IR picture
|
|
|
|
ctlxfer(hdev, 0xc0, 0x44, 0, 0, 6); // returns 440100b00400
|
|
r = bulkReceive(hdev, 2, PICSIZ); // IR picture
|
|
|
|
for (i=0; i<PICSIZ; i++){
|
|
*(pPics->pir->imgc + i) = (unsigned char)((*(p+i) + *(q+i) + *(r+i)) / 3);
|
|
}
|
|
pgmascii(pPics->pir,16);
|
|
|
|
printf("\n==== Dots\n");
|
|
ctlxfer(hdev, 0xc0, 0x4d, 0x78, 240, 5); // returns 4d01005802
|
|
ctlxfer(hdev, 0xc0, 0x44, 3, 2, 6); // returns 440100580200
|
|
p = bulkReceive(hdev, 2, PICSIZ/2); // "4 dots"
|
|
memcpy(pPics->pdots->imgc,p,PICSIZ/2);
|
|
|
|
// lights_off(hdev);
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
Copyright (c) Atlantean Technical Solutions Limited (ATSL) 2022
|
|
|
|
This software has been produced by ATSL and is the copyright of ATSL. The
|
|
use of source code for the software is strictly governed by the terms and
|
|
conditions of the source code licence. Any unauthorised use of the source
|
|
source code for the software in any manner shall invalidate the licence,
|
|
any existing warranty and software support agreements by ATSL.
|
|
|
|
@proj usbutes
|
|
@subsys CCL
|
|
@file ccl.c
|
|
@brief <B> *** Useful general purpose common C functions *** </B>
|
|
@author GoodwinC
|
|
@date 2022-10-27
|
|
@spec N.A
|
|
|
|
*/
|