mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
make style
This commit is contained in:
parent
0d9223a547
commit
0373696662
483 changed files with 56514 additions and 52451 deletions
|
@ -72,14 +72,14 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
|
|||
offset);
|
||||
if (filesz != memsz) {
|
||||
fprintf(stderr, "Error: PHDR file size does not equal memory size\n"
|
||||
"(DATA+BSS PHDRs do not make sense on ROM platforms!)\n");
|
||||
"(DATA+BSS PHDRs do not make sense on ROM platforms!)\n");
|
||||
return -1;
|
||||
}
|
||||
if (paddr < last_end) {
|
||||
fprintf(stderr, "Error: PHDRs not sorted or overlap\n");
|
||||
return -1;
|
||||
}
|
||||
if (paddr < FLASH_START || (paddr+filesz) > FLASH_END) {
|
||||
if (paddr < FLASH_START || (paddr + filesz) > FLASH_END) {
|
||||
fprintf(stderr, "Error: PHDR is not contained in Flash\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -101,13 +101,13 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
|
|||
return -1;
|
||||
}
|
||||
|
||||
uint32_t block_offset = paddr & (BLOCK_SIZE-1);
|
||||
uint32_t block_offset = paddr & (BLOCK_SIZE - 1);
|
||||
if (block_offset) {
|
||||
if (ctx->num_segs) {
|
||||
flash_seg_t *prev_seg = seg - 1;
|
||||
uint32_t this_end = paddr + filesz;
|
||||
uint32_t this_firstblock = paddr & ~(BLOCK_SIZE-1);
|
||||
uint32_t prev_lastblock = (last_end - 1) & ~(BLOCK_SIZE-1);
|
||||
uint32_t this_firstblock = paddr & ~(BLOCK_SIZE - 1);
|
||||
uint32_t prev_lastblock = (last_end - 1) & ~(BLOCK_SIZE - 1);
|
||||
|
||||
if (this_firstblock == prev_lastblock) {
|
||||
uint32_t new_length = this_end - prev_seg->start;
|
||||
|
@ -155,11 +155,12 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
|
|||
}
|
||||
|
||||
// Sanity check segments and check for bootloader writes
|
||||
static int check_segs(flash_file_t *ctx, int can_write_bl) {
|
||||
static int check_segs(flash_file_t *ctx, int can_write_bl)
|
||||
{
|
||||
for (int i = 0; i < ctx->num_segs; i++) {
|
||||
flash_seg_t *seg = &ctx->segments[i];
|
||||
|
||||
if (seg->start & (BLOCK_SIZE-1)) {
|
||||
if (seg->start & (BLOCK_SIZE - 1)) {
|
||||
fprintf(stderr, "Error: Segment is not aligned\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -202,8 +203,7 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl)
|
|||
goto fail;
|
||||
}
|
||||
if (memcmp(ehdr.e_ident, elf_ident, sizeof(elf_ident))
|
||||
|| le32(ehdr.e_version) != 1)
|
||||
{
|
||||
|| le32(ehdr.e_version) != 1) {
|
||||
fprintf(stderr, "Not an ELF file or wrong ELF type\n");
|
||||
goto fail;
|
||||
}
|
||||
|
@ -307,33 +307,33 @@ static int enter_bootloader(void)
|
|||
}
|
||||
|
||||
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
|
||||
fprintf(stderr,"Entering bootloader...\n");
|
||||
fprintf(stderr, "Entering bootloader...\n");
|
||||
UsbCommand c;
|
||||
memset(&c, 0, sizeof (c));
|
||||
memset(&c, 0, sizeof(c));
|
||||
|
||||
if ((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT)
|
||||
&& (state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT))
|
||||
{
|
||||
&& (state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT)) {
|
||||
// New style handover: Send CMD_START_FLASH, which will reset the board
|
||||
// and enter the bootrom on the next boot.
|
||||
c.cmd = CMD_START_FLASH;
|
||||
SendCommand(&c);
|
||||
fprintf(stderr,"(Press and release the button only to abort)\n");
|
||||
fprintf(stderr, "(Press and release the button only to abort)\n");
|
||||
} else {
|
||||
// Old style handover: Ask the user to press the button, then reset the board
|
||||
c.cmd = CMD_HARDWARE_RESET;
|
||||
SendCommand(&c);
|
||||
fprintf(stderr,"Press and hold down button NOW if your bootloader requires it.\n");
|
||||
fprintf(stderr, "Press and hold down button NOW if your bootloader requires it.\n");
|
||||
}
|
||||
fprintf(stderr,"Waiting for Proxmark to reappear on USB...");
|
||||
fprintf(stderr, "Waiting for Proxmark to reappear on USB...");
|
||||
|
||||
CloseProxmark();
|
||||
msleep(1000);
|
||||
while (!OpenProxmark(0)) {
|
||||
msleep(1000);
|
||||
fprintf(stderr, "."); fflush(stdout);
|
||||
fprintf(stderr, ".");
|
||||
fflush(stdout);
|
||||
}
|
||||
fprintf(stderr," Found.\n");
|
||||
fprintf(stderr, " Found.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length)
|
|||
|
||||
c.cmd = CMD_FINISH_WRITE;
|
||||
c.arg[0] = address;
|
||||
memcpy(c.d.asBytes, block_buf+240, 16);
|
||||
memcpy(c.d.asBytes, block_buf + 240, 16);
|
||||
SendCommand(&c);
|
||||
return wait_for_ack();
|
||||
}
|
||||
|
@ -444,7 +444,8 @@ int flash_write(flash_file_t *ctx)
|
|||
baddr += block_size;
|
||||
length -= block_size;
|
||||
block++;
|
||||
fprintf(stderr, "."); fflush(stdout);
|
||||
fprintf(stderr, ".");
|
||||
fflush(stdout);
|
||||
}
|
||||
fprintf(stderr, " OK\n");
|
||||
}
|
||||
|
@ -466,7 +467,8 @@ void flash_free(flash_file_t *ctx)
|
|||
}
|
||||
|
||||
// just reset the unit
|
||||
int flash_stop_flashing(void) {
|
||||
int flash_stop_flashing(void)
|
||||
{
|
||||
UsbCommand c = {CMD_HARDWARE_RESET};
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
|
|
|
@ -60,7 +60,8 @@ int main(int argc, char **argv)
|
|||
fprintf(stderr, "Waiting for Proxmark to appear on USB...");
|
||||
while (!OpenProxmark(1)) {
|
||||
msleep(1000);
|
||||
fprintf(stderr, "."); fflush(stdout);
|
||||
fprintf(stderr, ".");
|
||||
fflush(stdout);
|
||||
}
|
||||
fprintf(stderr, " Found.\n");
|
||||
|
||||
|
|
|
@ -34,12 +34,12 @@
|
|||
|
||||
static inline uint16_t le16(uint16_t v)
|
||||
{
|
||||
return (v>>8) | (v<<8);
|
||||
return (v >> 8) | (v << 8);
|
||||
}
|
||||
|
||||
static inline uint32_t le32(uint32_t v)
|
||||
{
|
||||
return (le16(v)<<16) | (le16(v>>16));
|
||||
return (le16(v) << 16) | (le16(v >> 16));
|
||||
}
|
||||
#endif // HOST_LITTLE_ENDIAN
|
||||
|
||||
|
|
|
@ -22,80 +22,80 @@ unsigned char error_occured = 0;
|
|||
|
||||
void SendCommand(UsbCommand *c)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
#if 0
|
||||
printf("Sending %d bytes\n", sizeof(UsbCommand));
|
||||
printf("Sending %d bytes\n", sizeof(UsbCommand));
|
||||
#endif
|
||||
|
||||
ret = usb_bulk_write(devh, 0x01, (char*)c, sizeof(UsbCommand), 1000);
|
||||
if (ret<0) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return;
|
||||
ret = usb_bulk_write(devh, 0x01, (char *)c, sizeof(UsbCommand), 1000);
|
||||
if (ret < 0) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "write failed: %s!\nTrying to reopen device...\n",
|
||||
usb_strerror());
|
||||
fprintf(stderr, "write failed: %s!\nTrying to reopen device...\n",
|
||||
usb_strerror());
|
||||
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while (!OpenProxmark(0)) { msleep(1000); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
while(!OpenProxmark(0)) { msleep(1000); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool ReceiveCommandPoll(UsbCommand *c)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
memset(c, 0, sizeof (UsbCommand));
|
||||
ret = usb_bulk_read(devh, 0x82, (char*)c, sizeof(UsbCommand), 500);
|
||||
if (ret<0) {
|
||||
if (ret != -ETIMEDOUT) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return false;
|
||||
memset(c, 0, sizeof(UsbCommand));
|
||||
ret = usb_bulk_read(devh, 0x82, (char *)c, sizeof(UsbCommand), 500);
|
||||
if (ret < 0) {
|
||||
if (ret != -ETIMEDOUT) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return false;
|
||||
|
||||
fprintf(stderr, "read failed: %s(%d)!\nTrying to reopen device...\n",
|
||||
usb_strerror(), ret);
|
||||
fprintf(stderr, "read failed: %s(%d)!\nTrying to reopen device...\n",
|
||||
usb_strerror(), ret);
|
||||
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while(!OpenProxmark(0)) { msleep(1000); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while (!OpenProxmark(0)) { msleep(1000); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (ret && (ret < sizeof(UsbCommand))) {
|
||||
fprintf(stderr, "Read only %d instead of requested %d bytes!\n",
|
||||
ret, (int)sizeof(UsbCommand));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (ret && (ret < sizeof(UsbCommand))) {
|
||||
fprintf(stderr, "Read only %d instead of requested %d bytes!\n",
|
||||
ret, (int)sizeof(UsbCommand));
|
||||
}
|
||||
}
|
||||
|
||||
return ret > 0;
|
||||
return ret > 0;
|
||||
}
|
||||
|
||||
void ReceiveCommand(UsbCommand *c)
|
||||
{
|
||||
// printf("%s()\n", __FUNCTION__);
|
||||
int retval = 0;
|
||||
do {
|
||||
retval = ReceiveCommandPoll(c);
|
||||
if (retval != 1) printf("ReceiveCommandPoll returned %d\n", retval);
|
||||
} while(retval<0);
|
||||
int retval = 0;
|
||||
do {
|
||||
retval = ReceiveCommandPoll(c);
|
||||
if (retval != 1) printf("ReceiveCommandPoll returned %d\n", retval);
|
||||
} while (retval < 0);
|
||||
// printf("recv %x\n", c->cmd);
|
||||
}
|
||||
|
||||
usb_dev_handle* findProxmark(int verbose, unsigned int *iface)
|
||||
usb_dev_handle *findProxmark(int verbose, unsigned int *iface)
|
||||
{
|
||||
struct usb_bus *busses, *bus;
|
||||
usb_dev_handle *handle = NULL;
|
||||
|
@ -138,21 +138,20 @@ usb_dev_handle* findProxmark(int verbose, unsigned int *iface)
|
|||
fprintf(stdout, "\nConnected units:\n");
|
||||
|
||||
for (int i = 0; i < iUnit; i++) {
|
||||
struct usb_device * dev = usb_device(units[i].handle);
|
||||
fprintf(stdout, "\t%d. SN: %s [%s/%s]\n", i+1, units[i].serial_number, dev->bus->dirname, dev->filename);
|
||||
struct usb_device *dev = usb_device(units[i].handle);
|
||||
fprintf(stdout, "\t%d. SN: %s [%s/%s]\n", i + 1, units[i].serial_number, dev->bus->dirname, dev->filename);
|
||||
}
|
||||
if (iUnit > 1) {
|
||||
while (iSelection < 1 || iSelection > iUnit) {
|
||||
fprintf(stdout, "Which unit do you want to connect to? ");
|
||||
int res = fscanf(stdin, "%d", &iSelection);
|
||||
if ( res != 1 ) {
|
||||
if (res != 1) {
|
||||
fprintf(stderr, "Input parse error");
|
||||
fflush(stderr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
iSelection = 1;
|
||||
}
|
||||
|
||||
|
@ -169,46 +168,46 @@ usb_dev_handle* findProxmark(int verbose, unsigned int *iface)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
usb_dev_handle* OpenProxmark(int verbose)
|
||||
usb_dev_handle *OpenProxmark(int verbose)
|
||||
{
|
||||
int ret;
|
||||
usb_dev_handle *handle = NULL;
|
||||
unsigned int iface;
|
||||
int ret;
|
||||
usb_dev_handle *handle = NULL;
|
||||
unsigned int iface;
|
||||
|
||||
handle = findProxmark(verbose, &iface);
|
||||
if (!handle)
|
||||
return NULL;
|
||||
handle = findProxmark(verbose, &iface);
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
#ifdef __linux__
|
||||
/* detach kernel driver first */
|
||||
ret = usb_detach_kernel_driver_np(handle, iface);
|
||||
/* don't complain if no driver attached */
|
||||
if (ret<0 && ret != -61 && verbose)
|
||||
fprintf(stderr, "detach kernel driver failed: (%d) %s!\n", ret, usb_strerror());
|
||||
/* detach kernel driver first */
|
||||
ret = usb_detach_kernel_driver_np(handle, iface);
|
||||
/* don't complain if no driver attached */
|
||||
if (ret < 0 && ret != -61 && verbose)
|
||||
fprintf(stderr, "detach kernel driver failed: (%d) %s!\n", ret, usb_strerror());
|
||||
#endif
|
||||
|
||||
// Needed for Windows. Optional for Mac OS and Linux
|
||||
ret = usb_set_configuration(handle, 1);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "configuration set failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
// Needed for Windows. Optional for Mac OS and Linux
|
||||
ret = usb_set_configuration(handle, 1);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "configuration set failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = usb_claim_interface(handle, iface);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "claim failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
claimed_iface = iface;
|
||||
devh = handle;
|
||||
return handle;
|
||||
ret = usb_claim_interface(handle, iface);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "claim failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
claimed_iface = iface;
|
||||
devh = handle;
|
||||
return handle;
|
||||
}
|
||||
|
||||
void CloseProxmark(void)
|
||||
{
|
||||
usb_release_interface(devh, claimed_iface);
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
usb_release_interface(devh, claimed_iface);
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
|
|
|
@ -30,13 +30,13 @@ extern unsigned char error_occured;
|
|||
void SendCommand(UsbCommand *c);
|
||||
bool ReceiveCommandPoll(UsbCommand *c);
|
||||
void ReceiveCommand(UsbCommand *c);
|
||||
struct usb_dev_handle* FindProxmark(int verbose, unsigned int *iface);
|
||||
struct usb_dev_handle* OpenProxmark(int verbose);
|
||||
struct usb_dev_handle *FindProxmark(int verbose, unsigned int *iface);
|
||||
struct usb_dev_handle *OpenProxmark(int verbose);
|
||||
void CloseProxmark(void);
|
||||
|
||||
struct prox_unit {
|
||||
usb_dev_handle *handle;
|
||||
char serial_number[256];
|
||||
usb_dev_handle *handle;
|
||||
char serial_number[256];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue