Exemplo n.º 1
0
int main()
{
  usb_init();
  SetLogFilename("snooper.log");

  g_return_on_error = 1;

  while(1) {
    while (!OpenProxmark(0)) { sleep(1); }
    while (1) {
      UsbCommand cmdbuf;
      CommandReceived("hf 14a snoop");
      HANDLE_ERROR;
      ReceiveCommand(&cmdbuf);
      HANDLE_ERROR;
      for (int i = 0; i < 5; ++i) {
        ReceiveCommandPoll(&cmdbuf);
      }
      HANDLE_ERROR;
      CommandReceived("hf 14a list");
      HANDLE_ERROR;
    }
  }

  CloseProxmark();
  return 0;
}
Exemplo n.º 2
0
// Get the state of the proxmark, backwards compatible
static int get_proxmark_state(uint32_t *state)
{
	UsbCommand c;
	c.cmd = CMD_DEVICE_INFO;
  SendCommand(&c);
	UsbCommand resp;
	ReceiveCommand(&resp);

	// Three outcomes:
	// 1. The old bootrom code will ignore CMD_DEVICE_INFO, but respond with an ACK
	// 2. The old os code will respond with CMD_DEBUG_PRINT_STRING and "unknown command"
	// 3. The new bootrom and os codes will respond with CMD_DEVICE_INFO and flags

	switch (resp.cmd) {
		case CMD_ACK:
			*state = DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM;
			break;
		case CMD_DEBUG_PRINT_STRING:
			*state = DEVICE_INFO_FLAG_CURRENT_MODE_OS;
			break;
		case CMD_DEVICE_INFO:
			*state = resp.arg[0];
			break;
		default:
			fprintf(stderr, "Error: Couldn't get proxmark state, bad response type: 0x%04" PRIx64 "\n", resp.cmd);
			return -1;
			break;
	}

	return 0;
}
Exemplo n.º 3
0
static int wait_for_ack(void)
{
  UsbCommand ack;
	ReceiveCommand(&ack);
	if (ack.cmd != CMD_ACK) {
		printf("Error: Unexpected reply 0x%04" PRIx64 " (expected ACK)\n", ack.cmd);
		return -1;
	}
	return 0;
}
Exemplo n.º 4
0
bool DeviceProxy::Process()
{
	// 只有处于关闭状态才继续执行
	if (m_connectState != STATE_DEVICE_CLOSED)
		return false;

	int port = ConfigBlock::GetInstance()->GetIntParameter(L"DeviceAddress", L"port", 0);
	CString ip = ConfigBlock::GetInstance()->GetStringParameter(L"DeviceAddress", L"ip", L"");
	//if (!m_connect.Listen(L"192.168.8.131", 1234))
	if (!m_connect.Listen((LPCTSTR)ip, port))
		return false;
								
	m_connectState = STATE_DEVICE_LISTENING;
	PostMessage(AfxGetApp()->GetMainWnd()->GetSafeHwnd(), WM_STATE_CONNECT_CHANGED, 0, 1);

	// 监听请求
	while (m_connecting)
	{
		SOCKET s = m_connect.Accept(18000);
		if (s != INVALID_SOCKET)// 收到连接请求且接收成功
		{
			m_connect.Attach(s);
			m_connectState = STATE_DEVICE_CONNECTED;
			PostMessage(AfxGetApp()->GetMainWnd()->GetSafeHwnd(), WM_STATE_CONNECT_CHANGED, 0, 1);
			break;
		}	
	}

	m_connect.SetTimeout(18000);

	// 已连接
	while (m_connecting)
	{
		ReceiveResult result;
		if (!ReceiveCommand(&result))
		{
			//TRACE("接收指令与回应失败!\n");
		}
		
		//std::this_thread::sleep_for(std::chrono::milliseconds(200));
	}
	return true;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
    if (argc != 3 && argc != 4)
    {
        printf("\n\tusage: cli <command 1> <command 2> [logfile (default cli.log)]\n");
        printf("\n");
        printf("\texample: cli hi14asnoop hi14alist h14a.log\n");
        printf("\n");
        return -1;
    }

    usb_init();
    if (argc == 4)
        SetLogFilename(argv[3]);
    else
        SetLogFilename("cli.log");

    return_on_error = 1;

    while (1) {
        while (!OpenProxmark(0)) {
            sleep(1);
        }
        while (1) {
            UsbCommand cmdbuf;
            CommandReceived(argv[1]);
            HANDLE_ERROR;
            ReceiveCommand(&cmdbuf);
            HANDLE_ERROR;
            for (int i = 0; i < 5; ++i) {
                ReceiveCommandPoll(&cmdbuf);
            }
            HANDLE_ERROR;
            CommandReceived(argv[2]);
            HANDLE_ERROR;
        }
    }

    CloseProxmark();
    return 0;
}
Exemplo n.º 6
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
bool Panel_ProcessingCommandFromPIC(uint16 command)
{
    if (command != 0)
    {
        gBF.panelControlReceive = 1;

        allRecData++;

        PanelButton relButton = ButtonIsRelease(command);
        if (relButton)
        {
            releaseButton = relButton;
        }
        else
        {
            PanelButton prButton = ButtonIsPress(command);
            if (prButton)
            {
                pressButton = prButton;
                pressedButton = prButton;
            }
            else
            {
                Regulator rLeft = RegulatorLeft(command);
                if (rLeft)
                {
                    regLeft = rLeft;
                    numReg++;
                }
                else
                {
                    Regulator rRight = RegulatorRight(command);
                    if (rRight)
                    {
                        regRight = rRight;
                        numReg++;
                    }
                    else
                    {
                        Regulator rPress = RegulatorPress(command);
                        if (rPress)
                        {
                            regPress = rPress;
                        }
                        else
                        {
                            Regulator rRelease = RegulatorRelease(command);
                            if (rRelease)
                            {
                                regRelease = rRelease;
                            }
                            else
                            {
                                PanelCommand com = ReceiveCommand(command);
                                if (com)
                                {
                                    recvCommand = com;
                                }
                                else
                                {
                                    if (Settings_DebugModeEnable())
                                    {
                                        static int errRecData = 0;
                                        errRecData++;
                                        float percent = (float)errRecData / allRecData * 100.0f;
                                        char buffer[100];
                                        buffer[0] = 0;
                                        sprintf(buffer, "%5.3f", percent);
                                        strcat(buffer, "%");
                                        LOG_ERROR("Ошибок SPI - %s %d/%d, command = %d", buffer, errRecData, allRecData, (int)command);
                                    }
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return true;
}