-
Notifications
You must be signed in to change notification settings - Fork 367
TRY Add new EMV scan and attack features for ChameleonUltra #329
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
Open
realdaveblanch
wants to merge
1
commit into
RfidResearchGroup:main
Choose a base branch
from
realdaveblanch:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Compila el firmware de ChameleonUltra (Application) y genera el paquete DFU. | ||
|
|
||
| .DESCRIPTION | ||
| Este script configura el entorno (PATH) para usar el compilador ARM descargado localmente | ||
| y las utilidades de Git, compila el código fuente en firmware/application usando 'make', | ||
| y finalmente empaqueta el resultado en un archivo .zip usando 'nrfutil'. | ||
|
|
||
| .NOTES | ||
| Requisitos: | ||
| - Carpeta 'tools' con 'arm-toolchain' y 'nrfutil.exe' en la raíz del repo. | ||
| - Git instalado (para utilidades Unix como mkdir, rm). | ||
| - 'make' instalado (vía Scoop o Choco). | ||
| #> | ||
|
|
||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| # --- Configuración de Rutas --- | ||
| $ScriptDir = $PSScriptRoot | ||
| $ToolsDir = Join-Path $ScriptDir "tools" | ||
| $FirmwareDir = Join-Path $ScriptDir "firmware" | ||
| $AppDir = Join-Path $FirmwareDir "application" | ||
| $ObjDir = Join-Path $FirmwareDir "objects" | ||
|
|
||
| # Rutas específicas de herramientas | ||
| # Ajusta la versión del toolchain si cambia la carpeta descomprimida | ||
| $ArmBin = Join-Path $ToolsDir "arm-toolchain\arm-gnu-toolchain-12.2.rel1-mingw-w64-i686-arm-none-eabi\bin" | ||
| $NrfUtil = Join-Path $ToolsDir "nrfutil.exe" | ||
| $GitBin = "C:\Program Files\Git\usr\bin" # Necesario para comandos unix dentro del Makefile | ||
| $DfuKey = Join-Path $ScriptDir "resource\dfu_key\chameleon.pem" | ||
|
|
||
| # --- Verificaciones --- | ||
| Write-Host "Verificando herramientas..." -ForegroundColor Cyan | ||
|
|
||
| if (-not (Test-Path "$ArmBin\arm-none-eabi-gcc.exe")) { | ||
| Write-Error "No se encontró el compilador ARM en: $ArmBin" | ||
| exit 1 | ||
| } | ||
|
|
||
| if (-not (Test-Path $NrfUtil)) { | ||
| Write-Error "No se encontró nrfutil en: $NrfUtil" | ||
| exit 1 | ||
| } | ||
|
|
||
| # --- Configurar Entorno --- | ||
| Write-Host "Configurando entorno de compilación..." | ||
| # Añadimos ARM y Git/usr/bin al inicio del PATH | ||
| $env:PATH = "$ArmBin;$GitBin;$env:PATH" | ||
|
|
||
| # --- Compilar Aplicación --- | ||
| Write-Host "Compilando Aplicación (Make)..." -ForegroundColor Cyan | ||
| Push-Location $AppDir | ||
|
|
||
| try { | ||
| # Ejecutamos make. '-j' usa todos los núcleos para ir rápido. | ||
| make -j | ||
| if ($LASTEXITCODE -ne 0) { throw "Error en la compilación." } | ||
| } | ||
| finally { | ||
| Pop-Location | ||
| } | ||
|
|
||
| # --- Generar Paquete DFU --- | ||
| Write-Host "Generando paquete DFU (ZIP)..." -ForegroundColor Cyan | ||
|
|
||
| # Asegurar que existe directorio objects | ||
| if (-not (Test-Path $ObjDir)) { New-Item -ItemType Directory -Path $ObjDir | Out-Null } | ||
|
|
||
| $AppHex = Join-Path $ObjDir "application.hex" | ||
| $OutputZip = Join-Path $ObjDir "ultra-dfu-app.zip" | ||
|
|
||
| if (-not (Test-Path $AppHex)) { | ||
| Write-Error "No se encontró el archivo compilado: $AppHex" | ||
| exit 1 | ||
| } | ||
|
|
||
| # Comando nrfutil para generar el paquete de actualización | ||
| & $NrfUtil pkg generate --hw-version 0 ` | ||
| --key-file $DfuKey ` | ||
| --application $AppHex ` | ||
| --application-version 1 ` | ||
| --sd-req 0x0100 ` | ||
| $OutputZip | ||
|
|
||
| if ($LASTEXITCODE -eq 0) { | ||
| Write-Host "`n---------------------------------------------------" -ForegroundColor Green | ||
| Write-Host "¡ÉXITO! Firmware compilado y empaquetado." -ForegroundColor Green | ||
| Write-Host "Archivo listo para flashear: $OutputZip" -ForegroundColor Yellow | ||
| Write-Host "---------------------------------------------------" | ||
| } else { | ||
| Write-Error "Falló la generación del paquete DFU." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #include "desfire.h" | ||
| #include "rc522.h" | ||
| #include "iso14443_4_transceiver.h" | ||
| #include "rfid_main.h" | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| bool desfire_scan(char *out_buffer, uint16_t max_len) { | ||
| picc_14a_tag_t tag; | ||
| uint8_t status; | ||
| uint8_t tx_buf[64]; | ||
| uint8_t rx_buf[256]; | ||
| uint16_t rx_len; | ||
|
|
||
| out_buffer[0] = '\0'; | ||
|
|
||
| // Increase timeout | ||
| pcd_14a_reader_timeout_set(500); | ||
|
|
||
| // 1. Scan for card | ||
| status = pcd_14a_reader_scan_auto(&tag); | ||
| if (status != STATUS_HF_TAG_OK) { | ||
| snprintf(out_buffer, max_len, "No Card"); | ||
| return false; | ||
| } | ||
|
|
||
| if (tag.ats_len == 0) { | ||
| snprintf(out_buffer, max_len, "Not DESFire (No ATS)"); | ||
| return false; | ||
| } | ||
|
|
||
| iso14443_4_reset_block_num(); | ||
|
|
||
| // 2. Get Version (0x60) | ||
| tx_buf[0] = 0x60; | ||
|
|
||
| if (iso14443_4_transceive(tx_buf, 1, rx_buf, &rx_len, sizeof(rx_buf))) { | ||
| // DESFire returns version in 3 frames usually (AF -> AF -> 00) | ||
| // Frame 1: HW Vendor, Type, Subtype, Version, Storage | ||
| if (rx_len > 0) { | ||
| uint8_t vendor = rx_buf[0]; | ||
| uint8_t type = rx_buf[1]; | ||
| uint8_t storage = rx_buf[5]; // 16=2k, 18=4k, 1A=8k usually (approx) | ||
|
|
||
| char type_str[20] = "Unknown"; | ||
| if (type == 0x81) strcpy(type_str, "DESFire EV1"); | ||
| else if (type == 0x82) strcpy(type_str, "DESFire EV2"); | ||
| else if (type == 0x83) strcpy(type_str, "DESFire EV3"); | ||
| else if (type == 0x88) strcpy(type_str, "DESFire Light"); | ||
|
|
||
| snprintf(out_buffer, max_len, "%s (0x%02X), V:0x%02X, S:0x%02X", type_str, type, vendor, storage); | ||
|
|
||
| // Get more frames if status is 0xAF (More Data) | ||
| // We can stop here for basic info | ||
| } | ||
| } else { | ||
| snprintf(out_buffer, max_len, "GetVersion Failed"); | ||
| return false; | ||
| } | ||
|
|
||
| // 3. Get Application IDs (0x6A) | ||
| tx_buf[0] = 0x6A; | ||
| if (iso14443_4_transceive(tx_buf, 1, rx_buf, &rx_len, sizeof(rx_buf))) { | ||
| if (rx_len > 0 && rx_buf[rx_len-1] == 0x00) { // Success | ||
| int apps = (rx_len - 1) / 3; | ||
| char temp[32]; | ||
| snprintf(temp, sizeof(temp), ", Apps: %d", apps); | ||
| strncat(out_buffer, temp, max_len - strlen(out_buffer) - 1); | ||
|
|
||
| if (apps > 0) { | ||
| strncat(out_buffer, " [", max_len - strlen(out_buffer) - 1); | ||
| for (int i=0; i<apps && i<3; i++) { // Show first 3 | ||
| uint32_t aid = (rx_buf[i*3] << 16) | (rx_buf[i*3+1] << 8) | rx_buf[i*3+2]; | ||
| snprintf(temp, sizeof(temp), "%06lX ", (unsigned long)aid); | ||
| strncat(out_buffer, temp, max_len - strlen(out_buffer) - 1); | ||
| } | ||
| strncat(out_buffer, "]", max_len - strlen(out_buffer) - 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #ifndef DESFIRE_H | ||
| #define DESFIRE_H | ||
|
|
||
| #include <stdint.h> | ||
| #include <stdbool.h> | ||
|
|
||
| bool desfire_scan(char *buffer, uint16_t max_len); | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This includes the .c files but misses the header files, could be fixed by including the directory or the files one by one, would fix compilation issues