//This function doesn't actually use UDP any more, but it keeps things
//simpler if we keep with this format
void UDPClient::SendAccount(char *username, char *password, char *info)
{
    fprintf(stderr,"\nSending username/password.\n");

    //build packet structure.
    unsigned char data[256];
    int index = 0;
    memset (data, 0, 256);
    m_ticket_length = 0;
    m_global_account_rcv = false;
    m_ticket = 0;

	if (EstablishGlobalConnection(m_IPAddr))
	{
		//data is size,username,size,password
		AddDataLS(data, username, index);
		AddDataLS(data, password, index);

		m_ServerTCP->SendResponse(ENB_OPCODE_2000_ACCOUNTDATA, data, index);

		WaitForResponse();
		
		if (m_global_account_rcv) 
		{
			LogMessage("Received account request.\n");
			memcpy(info, m_ticket, m_ticket_length);
			memcpy(m_AccountName, username, strlen(username));
		}
	}
	return;
}
示例#2
0
void alcMMDevApiProbe(enum DevProbe type)
{
    ThreadRequest req = { NULL, 0 };
    HRESULT hr = E_FAIL;

    switch(type)
    {
        case ALL_DEVICE_PROBE:
            req.FinishedEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
            if(req.FinishedEvt == NULL)
                ERR("Failed to create event: %lu\n", GetLastError());
            else if(PostThreadMessage(ThreadID, WM_USER_Enumerate, (WPARAM)&req, type))
                hr = WaitForResponse(&req);
            if(SUCCEEDED(hr))
            {
                ALuint i;
                for(i = 0;i < NumPlaybackDevices;i++)
                {
                    if(PlaybackDeviceList[i].name)
                        AppendAllDevicesList(PlaybackDeviceList[i].name);
                }
            }
            break;

        case CAPTURE_DEVICE_PROBE:
            break;
    }
    if(req.FinishedEvt != NULL)
        CloseHandle(req.FinishedEvt);
    req.FinishedEvt = NULL;
}
示例#3
0
void TcpClient::ExampleRun()
{
	const std::string host = "127.0.0.1";
	int port = 666;

	ConnectToHost(host, port);
	ShowEndpointInfos();
	_isRunning = true;

	while (_isRunning)
	{
		std::string request;
		
		std::cout << "Enter request: ";
		getline(std::cin, request);
		
		if (request == "END")
			_isRunning = false;
		else if (request == "")
			request = "HELLO-HOW-SHOULD-I-WORK";

		SendHttpRequest(host, request);

		WaitForResponse();
		
		ReceiveResponse(true);

		//DisplayResults();
		//_isRunning = false;
	}
	
	CloseConnection();
}
char* UDPClient::DeleteCharacter(long character_slot)
{
    fprintf(stderr,"\nSending Delete character.\n");

    //build packet structure.
    unsigned char data[128];
    int index = 0;
    memset (data, 0, 8);
    m_ticket_length = 0;
    m_global_account_rcv = false;
    m_ticket = 0;

	//data is character slot and account name
    AddData(data, ntohl(character_slot), index);
    AddDataLS(data, m_AccountName, index);

	m_ServerTCP->SendResponse(ENB_OPCODE_200D_DELETE_AVATAR, (unsigned char*)data, index);

	WaitForResponse();

	if (m_global_account_rcv)
    {
        fprintf(stderr,"\nReceived Avatar list.\n");
    }
    else
    {
        fprintf(stderr,"\nGlobal ERROR!!, server appears to be offline\n");
    }

    return m_ticket;
}
示例#5
0
/*----------------------------------------------------------------------
|   PLT_SyncMediaBrowser::BrowseSync
+---------------------------------------------------------------------*/
NPT_Result 
PLT_SyncMediaBrowser::BrowseSync(PLT_BrowseDataReference& browse_data,
                                 PLT_DeviceDataReference& device, 
                                 const char*              object_id, 
                                 NPT_Int32                index, 
                                 NPT_Int32                count,
                                 bool                     browse_metadata,
                                 const char*              filter, 
                                 const char*              sort)
{
    NPT_Result res;

    browse_data->shared_var.SetValue(0);

    // send off the browse packet.  Note that this will
    // not block.  There is a call to WaitForResponse in order
    // to block until the response comes back.
    res = PLT_MediaBrowser::Browse(device,
        (const char*)object_id,
        index,
        count,
        browse_metadata,
        filter,
        sort,
        new PLT_BrowseDataReference(browse_data));		
    NPT_CHECK_SEVERE(res);

    return WaitForResponse(browse_data->shared_var);
}
示例#6
0
int CmdLFSim(const char *Cmd)
{
  int i;
  static int gap;

  sscanf(Cmd, "%i", &gap);

  /* convert to bitstream if necessary */
  ChkBitstream(Cmd);

  PrintAndLog("Sending data, please wait...");
  for (i = 0; i < GraphTraceLen; i += 48) {
    UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}};
    int j;
    for (j = 0; j < 48; j++) {
      c.d.asBytes[j] = GraphBuffer[i+j];
    }
    SendCommand(&c);
    WaitForResponse(CMD_ACK);
  }

  PrintAndLog("Starting simulator...");
  UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}};
  SendCommand(&c);
  return 0;
}
示例#7
0
int CmdLFPCF7931Read(const char *Cmd)
{
  UsbCommand c = {CMD_PCF7931_READ};
  SendCommand(&c);
  UsbCommand resp;
  WaitForResponse(CMD_ACK,&resp);
  return 0;
}
示例#8
0
static void MMDevApiStopPlayback(ALCdevice *device)
{
    MMDevApiData *data = device->ExtraData;
    ThreadRequest req = { data->MsgEvent, 0 };

    if(PostThreadMessage(ThreadID, WM_USER_StopDevice, (WPARAM)&req, (LPARAM)device))
        (void)WaitForResponse(&req);
}
示例#9
0
bool YModem::SendFile(const std::string &path, YModem::SPort &out) {
  if (path.size() == 0 ||
      not out.is_open())
    return false;
  std::fstream firm_str(path.c_str());
  if (not firm_str.is_open())
    return false;
  firm_str.seekg(0, firm_str.end);
  const size_t kFileSize = firm_str.tellg();
  firm_str.seekg(0, firm_str.beg);
  // ожидание запроса
  WaitForResponse(out, Packet::kRequest);
  Packet::Sequence seq(&out);
  // инициализация соединения
  char buf[24];
  snprintf(buf, 24, "%u", (unsigned)kFileSize);
  const std::string kMsgs[] = {path, buf};
  SendInitialPkt(seq, kMsgs, 2);
  if (not IsResponse(out, Packet::kRequest)) {
    firm_str.close();
    return false;
  }
  // передача файла
  Array frame(NewFrame());
  size_t was_send     = 0;
  size_t last_percent = 0;
  do {
    firm_str.sync();
    firm_str.read((char*)frame.get(), kFrameSize);
    const size_t kWasRead = firm_str.gcount();
    if (kWasRead != kFrameSize) {
      memset(frame.get() + kWasRead, 0, kFrameSize - kWasRead);
    }
    seq.Send(Packet(Packet::kSTX, frame.get(), kFrameSize));
    was_send += kWasRead;
    if (not IsResponse(out, Packet::kACK)) {
      std::cout << "\t ! Ошибка передачи данных" << std::endl;
      break;
    }
    const size_t kPercent = was_send * 100 / kFileSize;
    if (kPercent > last_percent) {
      ShowPercentage("\t * Прогресс", kPercent);
      last_percent = kPercent;
    }
  } while (was_send < kFileSize);
  std::cout << std::endl;
  seq.Send(Packet(Packet::kEOT));
  IsResponse(out, Packet::kACK);
  seq.Send(Packet(Packet::kEOT));
  IsResponse(out, Packet::kACK);
  IsResponse(out, Packet::kRequest);
  SendClosingPkt(seq);
  firm_str.close();
  return true;
}
示例#10
0
static ALCboolean MMDevApiStartPlayback(ALCdevice *device)
{
    MMDevApiData *data = device->ExtraData;
    ThreadRequest req = { data->MsgEvent, 0 };
    HRESULT hr = E_FAIL;

    if(PostThreadMessage(ThreadID, WM_USER_StartDevice, (WPARAM)&req, (LPARAM)device))
        hr = WaitForResponse(&req);

    return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE;
}
示例#11
0
int CmdLegicSave(const char *Cmd)
{
  int requested = 1024;
  int offset = 0;
  int delivered = 0;
  char filename[FILE_PATH_SIZE];
  uint8_t got[1024];
  
  sscanf(Cmd, " %s %i %i", filename, &requested, &offset);

  /* If no length given save entire legic read buffer */
  /* round up to nearest 8 bytes so the saved data can be used with legicload */
  if (requested == 0) {
    requested = 1024;
  }
  if (requested % 8 != 0) {
    int remainder = requested % 8;
    requested = requested + 8 - remainder;
  }
  if (offset + requested > sizeof(got)) {
    PrintAndLog("Tried to read past end of buffer, <bytes> + <offset> > 1024");
    return 0;
  }
  
  FILE *f = fopen(filename, "w");
  if(!f) {
    PrintAndLog("couldn't open '%s'", Cmd+1);
    return -1;
  }

  GetFromBigBuf(got,requested,offset);
  WaitForResponse(CMD_ACK,NULL);

  for (int j = 0; j < requested; j += 8) {
    fprintf(f, "%02x %02x %02x %02x %02x %02x %02x %02x\n",
      got[j+0],
      got[j+1],
      got[j+2],
      got[j+3],
      got[j+4],
      got[j+5],
      got[j+6],
      got[j+7]
    );
    delivered += 8;
    if (delivered >= requested)
      break;
  }

  fclose(f);
  PrintAndLog("saved %u samples", delivered);
  return 0;
}
JBoolean
JXUserNotification::AcceptLicense()
{
	assert( itsCurrentDialog == NULL );

	(JXGetApplication())->PrepareForBlockingWindow();

	itsCurrentDialog = new JXAcceptLicenseDialog(JXGetApplication());
	assert( itsCurrentDialog != NULL );
	WaitForResponse();

	return itsWarningResponse;
}
JBoolean
JXUserNotification::AskUserYes
	(
	const JCharacter* message
	)
{
	assert( itsCurrentDialog == NULL );

	(JXGetApplication())->PrepareForBlockingWindow();

	itsCurrentDialog = new JXWarningDialog(JXGetApplication(), message);
	assert( itsCurrentDialog != NULL );
	WaitForResponse();

	return itsWarningResponse;
}
示例#14
0
int CmdLFRead(const char *Cmd)
{
  UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_125K};
  // 'h' means higher-low-frequency, 134 kHz
  if(*Cmd == 'h') {
    c.arg[0] = 1;
  } else if (*Cmd == '\0') {
    c.arg[0] = 0;
  } else {
    PrintAndLog("use 'read' or 'read h'");
    return 0;
  }
  SendCommand(&c);
  WaitForResponse(CMD_ACK);
  return 0;
}
示例#15
0
// Perform (part of) the PACE protocol
int CmdHFEPACollectPACENonces(const char *Cmd)
{
	// requested nonce size
	unsigned int m = 0;
	// requested number of Nonces
	unsigned int n = 0;
	// delay between requests
	unsigned int d = 0;

	sscanf(Cmd, "%u %u %u", &m, &n, &d);

	// values are expected to be > 0
	m = m > 0 ? m : 1;
	n = n > 0 ? n : 1;

	PrintAndLog("Collecting %u %"hhu"-byte nonces", n, m);
	PrintAndLog("Start: %u", time(NULL));
	// repeat n times
	for (unsigned int i = 0; i < n; i++) {
		// execute PACE
		UsbCommand c = {CMD_EPA_PACE_COLLECT_NONCE, {(int)m, 0, 0}};
		SendCommand(&c);
		UsbCommand resp;

		WaitForResponse(CMD_ACK,&resp);

		// check if command failed
		if (resp.arg[0] != 0) {
			PrintAndLog("Error in step %d, Return code: %d",resp.arg[0],(int)resp.arg[1]);
		} else {
			size_t nonce_length = resp.arg[1];
			char *nonce = (char *) malloc(2 * nonce_length + 1);
			for(int j = 0; j < nonce_length; j++) {
				sprintf(nonce + (2 * j), "%02X", resp.d.asBytes[j]);
			}
			// print nonce
			PrintAndLog("Length: %d, Nonce: %s", nonce_length, nonce);
			free(nonce);
		}
		if (i < n - 1) {
			sleep(d);
		}
	}
	PrintAndLog("End: %u", time(NULL));

	return 1;
}
示例#16
0
int CmdLegicLoad(const char *Cmd)
{
	char filename[FILE_PATH_SIZE] = {0x00};
	int len = 0;
	
	if (param_getchar(Cmd, 0) == 'h' || param_getchar(Cmd, 0)== 0x00) {
		PrintAndLog("It loads datasamples from the file `filename`");
		PrintAndLog("Usage:  hf legic load <file name>");
		PrintAndLog(" sample: hf legic load filename");
		return 0;
	}

	len = strlen(Cmd);	
	if (len > FILE_PATH_SIZE) {
		PrintAndLog("Filepath too long (was %s bytes), max allowed is %s ", len, FILE_PATH_SIZE);
		return 0;
	}
	memcpy(filename, Cmd, len);

    FILE *f = fopen(filename, "r");
    if(!f) {
        PrintAndLog("couldn't open '%s'", Cmd);
        return -1;
    }
    char line[80]; int offset = 0; unsigned int data[8];
    while(fgets(line, sizeof(line), f)) {
        int res = sscanf(line, "%x %x %x %x %x %x %x %x", 
            &data[0], &data[1], &data[2], &data[3],
            &data[4], &data[5], &data[6], &data[7]);
        if(res != 8) {
          PrintAndLog("Error: could not read samples");
          fclose(f);
          return -1;
        }
        UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {offset, 0, 0}};
        int j; for(j = 0; j < 8; j++) {
            c.d.asBytes[j] = data[j];
        }
        SendCommand(&c);
        WaitForResponse(CMD_ACK, NULL);
        offset += 8;
    }
    fclose(f);
    PrintAndLog("loaded %u samples", offset);
    return 0;
}
void
JXUserNotification::ReportError
	(
	const JCharacter* message
	)
{
	assert( itsCurrentDialog == NULL );

	if (!IsSilent())
		{
		(JXGetApplication())->PrepareForBlockingWindow();

		itsCurrentDialog = new JXErrorDialog(JXGetApplication(), message);
		assert( itsCurrentDialog != NULL );
		WaitForResponse();
		}
}
JUserNotification::CloseAction
JXUserNotification::OKToClose
	(
	const JCharacter* message
	)
{
	assert( itsCurrentDialog == NULL && itsOKToCloseDialog == NULL );

	(JXGetApplication())->PrepareForBlockingWindow();

	itsOKToCloseDialog = new JXOKToCloseDialog(JXGetApplication(), message);
	assert( itsOKToCloseDialog != NULL );

	itsCurrentDialog = itsOKToCloseDialog;
	WaitForResponse();

	return itsCloseAction;
}
short UDPClient::SendMasterLogin(long avatar_id, long sector_id, long *sector_ipaddr)
{
    m_PlayerID = avatar_id;
    g_ServerMgr->m_UDPClient->SetPlayerID(m_PlayerID);
    g_ServerMgr->m_UDPClient->FixedClientComm();

    //build packet structure.
    unsigned char data[8];
    int index = 0;
    memset (data, 0, 8);
    m_ticket_length = 0;
    m_global_account_rcv = false;
    m_ticket = 0;

    //data is sector_id
    AddData(data, sector_id, index);

	//Leave this as UDP
	//m_ServerTCP->SendResponse(ENB_OPCODE_2008_MASTER_HANDOFF, (unsigned char*)data, index);
	//WaitForResponse();

    WaitForResponse(UDP_MASTER_SERVER_PORT, ENB_OPCODE_2008_MASTER_HANDOFF, data, index);

    m_CurrentPacketNum = 0;

	if (m_global_account_rcv)
	{
		LogMessage("Received Master login confirm, new UDP port is %d Avatar_id = %d\n", *((short*) &m_ticket[4]), m_PlayerID );
        *sector_ipaddr = *((long*) m_ticket);
        //Now we can establish a TCP link to the server
        EstablishTCPConnection(m_IPAddr);

        //start login doublecheck thread here. If we haven't received a start packet within 10 seconds, send another handoff
        return (*((short*) &m_ticket[4]));
    }
    else
    {
        LogMessage("Error, did not receive master handoff ...\n");
        *sector_ipaddr = 0;
        return -1;
    }
}
示例#20
0
static void MMDevApiClosePlayback(ALCdevice *device)
{
    MMDevApiData *data = device->ExtraData;
    ThreadRequest req = { data->MsgEvent, 0 };

    if(PostThreadMessage(ThreadID, WM_USER_CloseDevice, (WPARAM)&req, (LPARAM)device))
        (void)WaitForResponse(&req);

    CloseHandle(data->MsgEvent);
    data->MsgEvent = NULL;

    CloseHandle(data->NotifyEvent);
    data->NotifyEvent = NULL;

    free(data->devid);
    data->devid = NULL;

    free(data);
    device->ExtraData = NULL;
}
示例#21
0
static BOOL MMDevApiLoad(void)
{
    static HRESULT InitResult;
    if(!ThreadHdl)
    {
        ThreadRequest req;
        InitResult = E_FAIL;

        req.FinishedEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
        if(req.FinishedEvt == NULL)
            ERR("Failed to create event: %lu\n", GetLastError());
        else
        {
            ThreadHdl = CreateThread(NULL, 0, MMDevApiMsgProc, &req, 0, &ThreadID);
            if(ThreadHdl != NULL)
                InitResult = WaitForResponse(&req);
            CloseHandle(req.FinishedEvt);
        }
    }
    return SUCCEEDED(InitResult);
}
示例#22
0
int CmdLegicRfFill(const char *Cmd)
{
    UsbCommand cmd ={CMD_WRITER_LEGIC_RF};
    int res = sscanf(Cmd, " 0x%"llx" 0x%"llx" 0x%"llx, &cmd.arg[0], &cmd.arg[1], &cmd.arg[2]);
    if(res != 3) {
        PrintAndLog("Please specify the offset, length and value as two hex strings");
        return -1;
    }

    int i;
    UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {0, 0, 0}};
    for(i = 0; i < 48; i++) {
      c.d.asBytes[i] = cmd.arg[2];
    }
    for(i = 0; i < 22; i++) {
      c.arg[0] = i*48;
      SendCommand(&c);
      WaitForResponse(CMD_ACK,NULL);
    }
    SendCommand(&cmd);
    return 0;
 }
示例#23
0
nsresult
XRemoteClient::DoSendCommand(Window aWindow, const char *aCommand,
                             const char* aDesktopStartupID,
                             char **aResponse, bool *aDestroyed)
{
  *aDestroyed = false;

  PR_LOG(sRemoteLm, PR_LOG_DEBUG,
     ("(writing " MOZILLA_COMMAND_PROP " \"%s\" to 0x%x)\n",
      aCommand, (unsigned int) aWindow));

  // We add the DESKTOP_STARTUP_ID setting as an extra line of
  // the command string. Firefox ignores all lines but the first.
  static char desktopStartupPrefix[] = "\nDESKTOP_STARTUP_ID=";

  PRInt32 len = strlen(aCommand);
  if (aDesktopStartupID) {
    len += sizeof(desktopStartupPrefix) - 1 + strlen(aDesktopStartupID);
  }
  char* buffer = (char*)malloc(len + 1);
  if (!buffer)
    return NS_ERROR_OUT_OF_MEMORY;

  strcpy(buffer, aCommand);
  if (aDesktopStartupID) {
    strcat(buffer, desktopStartupPrefix);
    strcat(buffer, aDesktopStartupID);
  }

  XChangeProperty (mDisplay, aWindow, mMozCommandAtom, XA_STRING, 8,
           PropModeReplace, (unsigned char *)buffer, len);

  free(buffer);

  if (!WaitForResponse(aWindow, aResponse, aDestroyed, mMozCommandAtom))
    return NS_ERROR_FAILURE;
  
  return NS_OK;
}
retcode ControlTerminalExtension::HandleIssueBO(std::vector<std::string>& arArgs)
{
	if(arArgs.size() < 2) return BAD_ARGUMENTS;

	BinaryOutput b; b.mOnTimeMS = 100; b.mOffTimeMS = 100; b.mCount = 1;
	boost::uint32_t index;
	if(!Parsing::Get(arArgs[0], index)) return BAD_ARGUMENTS;

	b.mRawCode = static_cast<boost::uint8_t>(ParseControlCode(arArgs[1]));
	switch(b.mRawCode) {
	case(CC_PULSE):
	case(CC_PULSE_CLOSE):
	case(CC_PULSE_TRIP):
		switch(arArgs.size()) {
		case(5):
			if(!Parsing::Get(arArgs[4], b.mCount)) return BAD_ARGUMENTS;
		case(4):
			if(!Parsing::Get(arArgs[3], b.mOffTimeMS)) return BAD_ARGUMENTS;
		case(3):
			if(!Parsing::Get(arArgs[2], b.mOnTimeMS)) return BAD_ARGUMENTS;
		case(2):
			break;
		default:
			return BAD_ARGUMENTS;
		}
		break;
	case(CC_LATCH_ON):
	case(CC_LATCH_OFF):
		if(arArgs.size() > 2) return BAD_ARGUMENTS;
		break;
	default:
		return BAD_ARGUMENTS;
	}

	mpCmdAcceptor->AcceptCommand(b, index, ++mSequence, &mRspQueue);
	WaitForResponse();
	return SUCCESS;
}
示例#25
0
retcode ControlTerminalExtension::HandleIssueST(std::vector<std::string>& arArgs)
{
	if(arArgs.size() < 2) return BAD_ARGUMENTS;

	Setpoint st;

	int index;

	if(!Parsing::GetPositive(arArgs[0], index)) return BAD_ARGUMENTS;
	if(arArgs[1].find('.') == std::string::npos) {
		int iValue;
		if(!Parsing::Get(arArgs[1], iValue)) return BAD_ARGUMENTS;
		st.SetValue(static_cast<boost::int32_t>(iValue));
	} else {
		double dValue;
		if(!Parsing::Get(arArgs[1], dValue)) return BAD_ARGUMENTS;
		st.SetValue(dValue);
	}

	mpCmdAcceptor->AcceptCommand(st, static_cast<size_t>(index), ++mSequence, &mRspQueue);
	WaitForResponse();
	return SUCCESS;
}
long UDPClient::SendAvatarLogin(long char_slot)
{
    LogMessage("Sending Avatar Login.\n");

    //build packet structure.
    unsigned char data[128];
    int index = 0;
    memset (data, 0, 8);
    m_ticket_length = 0;
    m_global_account_rcv = false;
    m_ticket = 0;

    //data is character slot and account name
    AddData(data, ntohl(char_slot), index);
    AddDataLS(data, m_AccountName, index);

	m_ServerTCP->SendResponse(ENB_OPCODE_2004_AVATARLOGIN, data, index);

	WaitForResponse();

	m_PlayerID = ntohl(*((long*) (m_ticket + 20)));
	g_ServerMgr->m_UDPClient->SetPlayerID(m_PlayerID);
    LogMessage("Fixed port ID set to 0x%08x\n", m_PlayerID);

    //WaitForResponse(UDP_GLOBAL_SERVER_PORT, ENB_OPCODE_2004_AVATARLOGIN, data, index);

	if (m_global_account_rcv && m_PlayerID != 0)
	{
		//LogMessage("Received avatar login confirm.\n");
        return (*((long*) m_ticket));
    }
    else
    {
        return -1;
    }
}
char * UDPClient::CreateCharacter(GlobalCreateCharacter *create)
{
    fprintf(stderr,"\nSending Avatar Create.\n");
    m_global_account_rcv = false;
    m_ticket = 0;

	m_ServerTCP->SendResponse(ENB_OPCODE_200B_CREATE_AVATAR, (unsigned char*)create, sizeof(GlobalCreateCharacter));

	WaitForResponse();

    //re-send until we recieve the avatarlist
    //WaitForResponse(UDP_GLOBAL_SERVER_PORT, ENB_OPCODE_200B_CREATE_AVATAR, (unsigned char*)create, sizeof(GlobalCreateCharacter));

    //was the return valid?
	if (m_global_account_rcv)
	{
		fprintf(stderr,"\nReceived create avatar confirm.\n");
        return (m_ticket);
    }
    else
    {
        return 0;
    }
}
char* UDPClient::SendTicket(char *ticket)
{
    m_global_account_rcv = false;
    int length = strlen(ticket);
    m_ticket = 0;

	m_ServerTCP->SendResponse(ENB_OPCODE_2002_TICKET, (unsigned char*)ticket, length);

	WaitForResponse();

	if (m_global_account_rcv)
    {
        LogMessage("Received Avatar list.\n");
    }
    else
    {
        fprintf(stderr,"\nGlobal ERROR!!, server appears to be offline\n");
    }

	//now switch this connection to a sector login
	//m_ServerTCP->SetToProxyLink();

    return m_ticket;
}
示例#29
0
nsresult
XRemoteClient::DoSendCommandLine(Window aWindow, int32_t argc, char **argv,
                                 const char* aDesktopStartupID,
                                 char **aResponse, bool *aDestroyed)
{
  *aDestroyed = false;

  char cwdbuf[MAX_PATH];
  if (!getcwd(cwdbuf, MAX_PATH))
    return NS_ERROR_UNEXPECTED;

  // the commandline property is constructed as an array of int32_t
  // followed by a series of null-terminated strings:
  //
  // [argc][offsetargv0][offsetargv1...]<workingdir>\0<argv[0]>\0argv[1]...\0
  // (offset is from the beginning of the buffer)

  static char desktopStartupPrefix[] = " DESKTOP_STARTUP_ID=";

  int32_t argvlen = strlen(cwdbuf);
  for (int i = 0; i < argc; ++i) {
    int32_t len = strlen(argv[i]);
    if (i == 0 && aDesktopStartupID) {
      len += sizeof(desktopStartupPrefix) - 1 + strlen(aDesktopStartupID);
    }
    argvlen += len;
  }

  int32_t* buffer = (int32_t*) malloc(argvlen + argc + 1 +
                                      sizeof(int32_t) * (argc + 1));
  if (!buffer)
    return NS_ERROR_OUT_OF_MEMORY;

  buffer[0] = TO_LITTLE_ENDIAN32(argc);

  char *bufend = (char*) (buffer + argc + 1);

  bufend = estrcpy(cwdbuf, bufend);

  for (int i = 0; i < argc; ++i) {
    buffer[i + 1] = TO_LITTLE_ENDIAN32(bufend - ((char*) buffer));
    bufend = estrcpy(argv[i], bufend);
    if (i == 0 && aDesktopStartupID) {
      bufend = estrcpy(desktopStartupPrefix, bufend - 1);
      bufend = estrcpy(aDesktopStartupID, bufend - 1);
    }
  }

#ifdef DEBUG_bsmedberg
  int32_t   debug_argc   = TO_LITTLE_ENDIAN32(*buffer);
  char *debug_workingdir = (char*) (buffer + argc + 1);

  printf("Sending command line:\n"
         "  working dir: %s\n"
         "  argc:\t%i",
         debug_workingdir,
         debug_argc);

  int32_t  *debug_offset = buffer + 1;
  for (int debug_i = 0; debug_i < debug_argc; ++debug_i)
    printf("  argv[%i]:\t%s\n", debug_i,
           ((char*) buffer) + TO_LITTLE_ENDIAN32(debug_offset[debug_i]));
#endif

  XChangeProperty (mDisplay, aWindow, mMozCommandLineAtom, XA_STRING, 8,
                   PropModeReplace, (unsigned char *) buffer,
                   bufend - ((char*) buffer));
  free(buffer);

  if (!WaitForResponse(aWindow, aResponse, aDestroyed, mMozCommandLineAtom))
    return NS_ERROR_FAILURE;
  
  return NS_OK;
}
示例#30
0
/*
 *  Output BigBuf and deobfuscate LEGIC RF tag data.
 *   This is based on information given in the talk held
 *  by Henryk Ploetz and Karsten Nohl at 26c3
 */
int CmdLegicDecode(const char *Cmd)
{
  int i, j, k, n;
  int segment_len = 0;
  int segment_flag = 0;
  int stamp_len = 0;
  int crc = 0;
  int wrp = 0;
  int wrc = 0;
  uint8_t data_buf[1052]; // receiver buffer
  char out_string[3076]; // just use big buffer - bad practice
  char token_type[4];
  
  // copy data from proxmark into buffer
   GetFromBigBuf(data_buf,sizeof(data_buf),0);
   WaitForResponse(CMD_ACK,NULL);
    
  // Output CDF System area (9 bytes) plus remaining header area (12 bytes)
  
  PrintAndLog("\nCDF: System Area");
  
  PrintAndLog("MCD: %02x, MSN: %02x %02x %02x, MCC: %02x",
    data_buf[0],
    data_buf[1],
    data_buf[2],
    data_buf[3],
    data_buf[4]
  );
  
  crc = data_buf[4];
 
  switch (data_buf[5]&0x7f) {
    case 0x00 ... 0x2f:
      strncpy(token_type, "IAM",sizeof(token_type));
      break;
    case 0x30 ... 0x6f:
      strcpy(token_type, "SAM");
      break;
    case 0x70 ... 0x7f:
      strcpy(token_type, "GAM");
      break;
    default:
      strcpy(token_type, "???");
      break;
  }
  
  stamp_len = 0xfc - data_buf[6];
  
  PrintAndLog("DCF: %02x %02x, Token_Type=%s (OLE=%01u), Stamp_len=%02u",
    data_buf[5],
    data_buf[6],
    token_type,
    (data_buf[5]&0x80)>>7,
    stamp_len
  );
  
  PrintAndLog("WRP=%02u, WRC=%01u, RD=%01u, raw=%02x, SSC=%02x",
    data_buf[7]&0x0f,
    (data_buf[7]&0x70)>>4,
    (data_buf[7]&0x80)>>7,
    data_buf[7],
    data_buf[8]
  );
  
  PrintAndLog("Remaining Header Area");
  
  PrintAndLog("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
      data_buf[9],
    data_buf[10],
    data_buf[11],
    data_buf[12],
    data_buf[13],
    data_buf[14],
    data_buf[15],
    data_buf[16],
    data_buf[17],
    data_buf[18],
    data_buf[19],
    data_buf[20],
    data_buf[21]
  );
  
  PrintAndLog("\nADF: User Area");
  
  i = 22;  
  for (n=0; n<64; n++) {
    segment_len = ((data_buf[i+1]^crc)&0x0f) * 256 + (data_buf[i]^crc);
    segment_flag = ((data_buf[i+1]^crc)&0xf0)>>4;
    
    wrp = (data_buf[i+2]^crc);
    wrc = ((data_buf[i+3]^crc)&0x70)>>4;
    
     PrintAndLog("Segment %02u: raw header=%02x %02x %02x %02x, flag=%01x (valid=%01u, last=%01u), len=%04u, WRP=%02u, WRC=%02u, RD=%01u, CRC=%02x",
      n,
      data_buf[i]^crc,
      data_buf[i+1]^crc,
      data_buf[i+2]^crc,
      data_buf[i+3]^crc,
      segment_flag,
      (segment_flag&0x4)>>2,
      (segment_flag&0x8)>>3,
      segment_len,
      wrp,
      wrc,
      ((data_buf[i+3]^crc)&0x80)>>7,
      (data_buf[i+4]^crc)
    );
    
    i+=5;
    
    if (wrc>0) {
      PrintAndLog("WRC protected area:");
      for (k=0, j=0; k < wrc && j<(sizeof(out_string)-3); k++, i++, j += 3) {
        sprintf(&out_string[j], "%02x", (data_buf[i]^crc));
        out_string[j+2] = ' ';
      };
        
      out_string[j] = '\0';
    
      PrintAndLog("%s", out_string);
    }
    
    if (wrp>wrc) {
      PrintAndLog("Remaining write protected area:");
      
      for (k=0, j=0; k < (wrp-wrc) && j<(sizeof(out_string)-3); k++, i++, j += 3) {
        sprintf(&out_string[j], "%02x", (data_buf[i]^crc));
        out_string[j+2] = ' ';
      };
    
      out_string[j] = '\0';
    
      PrintAndLog("%s", out_string);
      if((wrp-wrc) == 8) {
        sprintf(out_string,"Card ID: %2X%02X%02X",data_buf[i-4]^crc,data_buf[i-3]^crc,data_buf[i-2]^crc);
        PrintAndLog("%s", out_string);
      }
    }
    
    PrintAndLog("Remaining segment payload:");
    for (k=0, j=0; k < (segment_len - wrp - 5) && j<(sizeof(out_string)-3); k++, i++, j += 3) {
      sprintf(&out_string[j], "%02x", (data_buf[i]^crc));
      out_string[j+2] = ' ';
    };
    
    out_string[j] = '\0';
    
    PrintAndLog("%s", out_string);
    
    // end with last segment
    if (segment_flag & 0x8)
      return 0;
  };
  return 0;
}