Merge pull request #33 from doegox/phil_fix_utf8

Fix Chinese encodings of some files GB18030=> UTF-8
This commit is contained in:
DXL
2023-07-22 14:00:00 +08:00
committed by GitHub
10 changed files with 82 additions and 75 deletions
+21 -21
View File
@@ -196,20 +196,20 @@ __INLINE uint32_t map(uint32_t x, uint32_t in_min, uint32_t in_max, uint32_t out
return (uint32_t)((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min);
}
//电池电压到百分比计算
//电池电压到百分比计算
uint32_t BATVOL2PERCENT(uint16_t VOL)
{
//100% 4.20V 1
//90 % 4.06V 80%-100% 白
//90 % 4.06V 80%-100% 白
//80 % 3.98V 1
//70 % 3.92V 60%-80% 白
//70 % 3.92V 60%-80% 白
//60 % 3.87V 1
//50 % 3.82V 40%-60% 白
//50 % 3.82V 40%-60% 白
//40 % 3.79V 1
//30 % 3.77V 20%-40% 白
//30 % 3.77V 20%-40% 白
//20 % 3.74V 1
//10 % 3.68V 5%-20% 红
//5 % 3.45V 1 关机
//10 % 3.68V 5%-20% 红
//5 % 3.45V 1 关机
//0 % 3.00V
//#define P100VOL 4200
//#define P80VOL 3980
@@ -219,16 +219,16 @@ uint32_t BATVOL2PERCENT(uint16_t VOL)
//#define P5VOL 3450
//100% 4.20V 1
//90 % 4.00V 80%-100% 白
//90 % 4.00V 80%-100% 白
//80 % 3.89V 1
//70 % 3.79V 60%-80% 白
//70 % 3.79V 60%-80% 白
//60 % 3.70V 1
//50 % 3.62V 40%-60% 白
//50 % 3.62V 40%-60% 白
//40 % 3.57V 1
//30 % 3.53V 20%-40% 白
//30 % 3.53V 20%-40% 白
//20 % 3.51V 1
//10 % 3.46V 5%-20% 红
//5 % 3.43V 1 关机
//10 % 3.46V 5%-20% 红
//5 % 3.43V 1 关机
//0 % 3.00V
#define P100VOL 4200
#define P80VOL 3890
@@ -650,12 +650,12 @@ void create_battery_timer(void) {
* @brief Function for init ble slave.
*/
void ble_slave_init(void) {
adc_configure(); // ADC初始化
create_battery_timer(); // 创建电池电量更新定时器
ble_stack_init(); // BLE协议栈初始化
gap_params_init(); // GAP参数初始化
gatt_init(); // GATT协议初始化
services_init(); // 服务特征初始化
advertising_init(); // 广播参数初始化
conn_params_init(); // 连接参数初始化
adc_configure(); // ADC初始化
create_battery_timer(); // 创建电池电量更新定时器
ble_stack_init(); // BLE协议栈初始化
gap_params_init(); // GAP参数初始化
gatt_init(); // GATT协议初始化
services_init(); // 服务特征初始化
advertising_init(); // 广播参数初始化
conn_params_init(); // 连接参数初始化
}
@@ -2,33 +2,33 @@
#define TAG_BASE_TYPE_H
// 场的感应类型
// 场的感应类型
typedef enum {
// 无场感应
// 无场感应
TAG_SENSE_NO,
// 低频125khz场感应
// 低频125khz场感应
TAG_SENSE_LF,
// 高频13.56mhz场感应
// 高频13.56mhz场感应
TAG_SENSE_HF,
} tag_sense_type_t;
/**
*
* 所有支持模拟的标签的类型的定义
* 注意,以下所有定义的标签类型,都是应用层的细化的具体的类型统计
* 不再区分高低频
* 所有支持模拟的标签的类型的定义
* 注意,以下所有定义的标签类型,都是应用层的细化的具体的类型统计
* 不再区分高低频
*/
typedef enum {
// 特定的且必须存在的标志不存在的类型
// 特定的且必须存在的标志不存在的类型
TAG_TYPE_UNKNOWN,
// 125khzID卡)系列
// 125khzID卡)系列
TAG_TYPE_EM410X,
// Mifare系列
// Mifare系列
TAG_TYPE_MIFARE_Mini,
TAG_TYPE_MIFARE_1024,
TAG_TYPE_MIFARE_2048,
TAG_TYPE_MIFARE_4096,
// NTAG系列
// NTAG系列
TAG_TYPE_NTAG_213,
TAG_TYPE_NTAG_215,
TAG_TYPE_NTAG_216,
@@ -28,15 +28,15 @@ void get_fds_map_by_slot_auto_inc_id(uint16_t key, uint16_t id, uint8_t slot, ta
/**
* 根据卡槽和卡槽中指定的场类型获得其在FDS中对应的数据的KEY和ID
* 根据卡槽和卡槽中指定的场类型获得其在FDS中对应的数据的KEY和ID
*/
void get_fds_map_by_slot_sense_type_for_dump(uint8_t slot, tag_sense_type_t sense_type, fds_slot_record_map_t* map) {
// 根据 @see FDS_SLOT_TAG_DUMP_FILE_KEY 的约定,每个slot以其为起点,每个slot都有其单独的key的record,并且每个slot中独特的场类型也有一个数据的id
// 根据 @see FDS_SLOT_TAG_DUMP_FILE_KEY 的约定,每个slot以其为起点,每个slot都有其单独的key的record,并且每个slot中独特的场类型也有一个数据的id
get_fds_map_by_slot_auto_inc_id(FDS_SLOT_TAG_DUMP_FILE_KEY, FDS_SLOT_TAG_DUMP_FILE_ID, slot, sense_type, map);
}
/**
* 根据卡槽和卡槽中指定的场类型获得其在FDS中对应的数据的KEY和ID
* 根据卡槽和卡槽中指定的场类型获得其在FDS中对应的数据的KEY和ID
*/
void get_fds_map_by_slot_sense_type_for_nick(uint8_t slot, tag_sense_type_t sense_type, fds_slot_record_map_t* map) {
get_fds_map_by_slot_auto_inc_id(FDS_SLOT_TAG_NICK_NAME_KEY, FDS_SLOT_TAG_NICK_NAME_ID, slot, sense_type, map);
@@ -6,21 +6,21 @@
/*
* 卡槽配置,只有一份,一致即可
* 卡槽配置,只有一份,一致即可
*/
#define FDS_CONFIG_RECORD_FILE_KEY 0x1066
#define FDS_CONFIG_RECORD_FILE_ID 0x1066
/*
* 每个卡槽有高低频两种数据,其中key是跟卡槽走的,而id+n就等于数据索引,固定某个索引为指定类型即可
* 每个slot的file_key都不一样
* 每个slot有两种类型的卡片,因此有两个数据ID(当前)
* 每个卡槽有高低频两种数据,其中key是跟卡槽走的,而id+n就等于数据索引,固定某个索引为指定类型即可
* 每个slot的file_key都不一样
* 每个slot有两种类型的卡片,因此有两个数据ID(当前)
*/
#define FDS_SLOT_TAG_DUMP_FILE_KEY 0x1067
#define FDS_SLOT_TAG_DUMP_FILE_ID 0x1067
/*
* 每个卡槽有高低频两种数据,因此卡槽的昵称也要有两种,其中key是跟卡槽走的,而id+n就等于数据索引,固定某个索引为指定类型即可
* 每个卡槽有高低频两种数据,因此卡槽的昵称也要有两种,其中key是跟卡槽走的,而id+n就等于数据索引,固定某个索引为指定类型即可
*/
#define FDS_SLOT_TAG_NICK_NAME_KEY 0x1068
#define FDS_SLOT_TAG_NICK_NAME_ID 0x1068
@@ -32,12 +32,12 @@ typedef struct {
} fds_slot_record_map_t;
/**
* 根据指定的卡槽和卡片场类型,获得其对应的卡片数据的FDS信息的映射对象
* 根据指定的卡槽和卡片场类型,获得其对应的卡片数据的FDS信息的映射对象
*/
void get_fds_map_by_slot_sense_type_for_dump(uint8_t slot, tag_sense_type_t sense_type, fds_slot_record_map_t* map);
/**
* 根据指定的卡槽和卡片场类型,获得其对应的卡片数据的昵称的FDS信息的映射对象
* 根据指定的卡槽和卡片场类型,获得其对应的卡片数据的昵称的FDS信息的映射对象
*/
void get_fds_map_by_slot_sense_type_for_nick(uint8_t slot, tag_sense_type_t sense_type, fds_slot_record_map_t* map);
@@ -8,8 +8,8 @@
#include <stdlib.h>
#define SETS_NR 2 // 使用几组随机数探针,至少是2个能确保有两组随机数组合进行交集查询,这个值越大越容易成功
#define DIST_NR 3 // 越多的距离值越能准确判断当前卡片的通信稳定性
#define SETS_NR 2 // 使用几组随机数探针,至少是2个能确保有两组随机数组合进行交集查询,这个值越大越容易成功
#define DIST_NR 3 // 越多的距离值越能准确判断当前卡片的通信稳定性
// mifare authentication
#define CRYPT_NONE 0
@@ -18,16 +18,16 @@
#define AUTH_FIRST 0
#define AUTH_NESTED 2
typedef struct { // 应答 nested 攻击需要的 距离参数
uint8_t uid[4]; // 这个距离数据的所属UID的U32部分
uint8_t distance[4]; // 未经加密的明文随机数
typedef struct { // 应答 nested 攻击需要的 距离参数
uint8_t uid[4]; // 这个距离数据的所属UID的U32部分
uint8_t distance[4]; // 未经加密的明文随机数
} NestedDist;
typedef struct { // 应答 nested 攻击需要的 随机数参数
uint8_t nt1[4]; // 未经加密的明文随机数
uint8_t nt2[4]; // 嵌套验证加密的随机数
uint8_t par; // 嵌套验证加密的通信过程的奇偶校验位,只用到了 '低3位',也就是右3位
typedef struct { // 应答 nested 攻击需要的 随机数参数
uint8_t nt1[4]; // 未经加密的明文随机数
uint8_t nt2[4]; // 嵌套验证加密的随机数
uint8_t par; // 嵌套验证加密的通信过程的奇偶校验位,只用到了 '低3位',也就是右3位
} NestedCore;
typedef struct {
@@ -1,7 +1,7 @@
#include "data_utils.h"
#include <ctype.h>
//向raw写入2bit数据,datab存0bitdataa存1bit
//向raw写入2bit数据,datab存0bitdataa存1bit
void writebit(uint8_t *dataa, uint8_t *datab, uint8_t pos, uint8_t adata)
{
if (adata >= 4)
@@ -16,7 +16,7 @@ void writebit(uint8_t *dataa, uint8_t *datab, uint8_t pos, uint8_t adata)
getbit(adata, 0) ? setbit(datab[aimbyte], aimbit) : clrbit(datab[aimbyte], aimbit);
}
//输出raw的2bit组合数据
//输出raw的2bit组合数据
uint8_t readbit(uint8_t *dataa, uint8_t *datab, uint8_t pos)
{
static uint8_t aimbyte = 0;
@@ -28,7 +28,7 @@ uint8_t readbit(uint8_t *dataa, uint8_t *datab, uint8_t pos)
(getbit(datab[aimbyte], aimbit)));
}
//向raw写入2bit数据(大端方法,每个byte的第8位写数据的第1位)datab存0bitdataa存1bit
//向raw写入2bit数据(大端方法,每个byte的第8位写数据的第1位)datab存0bitdataa存1bit
void writebit_msb(uint8_t *dataa, uint8_t *datab, uint8_t pos, uint8_t adata)
{
if (adata >= 4)
@@ -43,7 +43,7 @@ void writebit_msb(uint8_t *dataa, uint8_t *datab, uint8_t pos, uint8_t adata)
getbit(adata, 0) ? setbit(datab[aimbyte], aimbit) : clrbit(datab[aimbyte], aimbit);
}
//输出raw的2bit组合数据(大端方法,每个byte的第8位读数据的第1位)
//输出raw的2bit组合数据(大端方法,每个byte的第8位读数据的第1位)
uint8_t readbit_msb(uint8_t *dataa, uint8_t *datab, uint8_t pos)
{
static uint8_t aimbyte = 0;
@@ -55,7 +55,7 @@ uint8_t readbit_msb(uint8_t *dataa, uint8_t *datab, uint8_t pos)
(getbit(datab[aimbyte], aimbit)));
}
//高低位翻转
//高低位翻转
uint8_t invert_num(uint8_t num)
{
uint8_t temp = 0, sh = 0xf;
@@ -71,7 +71,7 @@ uint8_t invert_num(uint8_t num)
return num;
}
//原始数据转换为2倍长度的hex字符数组
//原始数据转换为2倍长度的hex字符数组
void ByteToHexStr(uint8_t *source, uint8_t *dest, uint8_t sourceLen)
{
uint8_t i, highByte, lowByte;
@@ -9,7 +9,7 @@
extern "C" {
#endif
typedef void(*RIO_CALLBACK_S)(void); // µ÷Óú¯Êý¸ñʽ
typedef void(*RIO_CALLBACK_S)(void); // 调用函数格式
void register_rio_callback(RIO_CALLBACK_S P);
void blank_function(void);
+12 -12
View File
@@ -44,11 +44,11 @@ static data_frame_tx_t m_frame_tx_buf_info = {
/**
* @brief 数据包创建,将创建之后的数据包放到缓冲区中,等待发送完毕之后设置非busy状态
* @param cmd: 指令应答
* @param status: 应答状态
* @param length: 应答数据长度
* @param data: 应答数据
* @brief 数据包创建,将创建之后的数据包放到缓冲区中,等待发送完毕之后设置非busy状态
* @param cmd: 指令应答
* @param status: 应答状态
* @param length: 应答数据长度
* @param data: 应答数据
*/
data_frame_tx_t* data_frame_make(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
uint8_t lrc_tx = 0x00;
@@ -94,9 +94,9 @@ void data_frame_reset(void) {
}
/**
* @brief 数据包接收,用于接收发送过来的数据包并且进行拼接处理
* @param data: 接收到的字节数组
* @param length: 接收到的字节数组的长度
* @brief 数据包接收,用于接收发送过来的数据包并且进行拼接处理
* @param data: 接收到的字节数组
* @param length: 接收到的字节数组的长度
*/
void data_frame_receive(uint8_t *data, uint16_t length) {
// buffer wait process
@@ -173,9 +173,9 @@ void data_frame_receive(uint8_t *data, uint16_t length) {
}
/**
* @brief 数据包处理,当接收到的数据形成了一个完整的帧之后,
* 将会通过此函数分发处理任务,此函数会回调通知数据处理者
* 如果数据处理是耗时操作,则需要将此函数放在main循环中调用
* @brief 数据包处理,当接收到的数据形成了一个完整的帧之后,
* 将会通过此函数分发处理任务,此函数会回调通知数据处理者
* 如果数据处理是耗时操作,则需要将此函数放在main循环中调用
*/
void data_frame_process(void) {
// check if data frame
@@ -191,7 +191,7 @@ void data_frame_process(void) {
}
/**
* @brief 数据包处理回调注册
* @brief 数据包处理回调注册
*/
void on_data_frame_complete(data_frame_cbk_t callback) {
m_frame_process_cbk = callback;
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
find . \( -not -path "./firmware/nrf52_sdk/*" -and -not -path "./firmware/objects/*" -and -not -path "./software/script/venv/*" -and -not -path "./software/bin/*" -and -not -path "./software/src/tmp/*" \) -and \( -name "*.[ch]" -or -name "*.py" -or -name "Makefile" -or -name "*.txt" -or -name "*.md" -or -name "*.sh" \) -exec sh -c "cat {} |recode utf8.. >/dev/null || echo {}" \;
# Chinese encoding: GB18030 extending EUC-CN
# recode GB18030..UTF-8 file.c
# If it fails it could be due to mix of GB18030 & UTF-8 in the same file, check by hand
+5 -5
View File
@@ -16,12 +16,12 @@ typedef struct {
uint64_t ks_list;
} DarksideParam;
// 转换字符串为U32类型
// 转换字符串为U32类型
uint64_t atoui(const char* str)
{
uint64_t result = 0, i = 0;
char* tmp = NULL;
for (i = 0; isspace(str[i]) && i < strlen(str); i++)//跳过空白符;
for (i = 0; isspace(str[i]) && i < strlen(str); i++)//跳过空白符;
;
tmp = str + i;
while (*tmp)
@@ -41,7 +41,7 @@ void num_to_bytes(uint64_t n, uint32_t len, uint8_t* dest)
}
int main(int argc, char* argv[]) {
// 初始化UID
// 初始化UID
uint32_t uid = (uint32_t)atoui(argv[1]);
uint32_t count = 0, i = 0;
uint32_t keycount = 0;
@@ -68,7 +68,7 @@ int main(int argc, char* argv[]) {
}
for (i = 0; i < count; i++) {
// 初始化NT, NR, AR
// 初始化NT, NR, AR
uint32_t nt = dps[i].nt;
uint32_t nr = dps[i].nr;
uint32_t ar = dps[i].ar;
@@ -85,7 +85,7 @@ int main(int argc, char* argv[]) {
printf("AR = %"PRIu32"\r\n", ar);
*/
// 开始解密
// 开始解密
keycount = nonce2key(uid, nt, nr, ar, par_list, ks_list, &keylist);
if (keycount == 0) {