SaneWinMain( argc, argv ) { FILE *input; if( argc > 2 ) { input = sack_fopen( 0, argv[2], WIDE("rb+") ); if( input ) { if( StrCaseCmpEx( argv[1], WIDE( "u" ), 1 ) == 0 ) { read_ascii( input ); ascii_to_unicode(); write_unicode( input ); } else { read_unicode( input ); unicode_to_ascii(); write_ascii( input ); } fclose( input ); } else printf( WIDE( "Failed to open %s" ), argv[2] ); } else { printf( WIDE("Usage: %s [u/a] [filename]\n"), argv[0] ); printf( WIDE(" u or a is unicode or ascii mode; unicode translates from ascii to unicode\n") ); printf( WIDE(" ascii translates from unicode to ascii\n") ); printf( WIDE(" file will be written back in-place\n") ); } return 0; }
//------------------------------------------------------------------------------------------------------------------- char* bytebuffer::readUSTRINGtoASCII() { unsigned int size = readINT(); wchar_t* tempArray = new wchar_t[size]; readDATA((char*)tempArray,size * 2); char* ret = createArray(size + 1); unicode_to_ascii(ret,tempArray,size); delete [] tempArray; ret[size] = 0; return ret; }
//------------------------------------------------------------------------------------------------------------------- void bytebuffer::writeASTRING(const wchar_t* string) { unsigned int size; for(size = 0;string[size] != 0;size++) ; char* new_string = new char[size]; unicode_to_ascii(new_string,string,size); writeSHORT(size); writeDATA(new_string,size); delete [] new_string; }
static std::string codepage_issue_fixToOEM(const std::wstring& sVal) { #if defined(_WIN32) || defined (_WIN64) const wchar_t* buffer = sVal.c_str(); int nBufferSize = WideCharToMultiByte( CP_OEMCP, 0, buffer, -1, NULL, 0, NULL, NULL ); char* pBuffer = new char[nBufferSize]; WideCharToMultiByte( CP_OEMCP, 0, buffer, -1, pBuffer, nBufferSize, NULL, NULL ); std::string sRes(pBuffer, nBufferSize); RELEASEARRAYOBJECTS(pBuffer); return sRes; #else return unicode_to_ascii(sVal.c_str()); #endif }
int parse_mms(const char *data, const unsigned int datalen, u_int32_t *mms_ip, u_int16_t *mms_proto, u_int16_t *mms_port, char **mms_string_b, char **mms_string_e, char **mms_padding_e) { int unicode_size, i; char tempstring[28]; /* "\\255.255.255.255\UDP\65535" */ char getlengthstring[28]; for(unicode_size=0; (char) *(data+(MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2)) != (char)0; unicode_size++) if ((unicode_size == 28) || (MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2 >= datalen)) return -1; /* out of bounds - incomplete packet */ unicode_to_ascii(tempstring, (short *)(data+MMS_SRV_UNICODE_STRING_OFFSET), unicode_size); DEBUGP("ip_conntrack_mms: offset 60: %s\n", (const char *)(tempstring)); /* IP address ? */ *mms_ip = asciiiptoi(tempstring+2); i=sprintf(getlengthstring, "%u.%u.%u.%u", HIPQUAD(*mms_ip)); /* protocol ? */ if(strncmp(tempstring+3+i, "TCP", 3)==0) *mms_proto = IPPROTO_TCP; else if(strncmp(tempstring+3+i, "UDP", 3)==0) *mms_proto = IPPROTO_UDP; /* port ? */ *mms_port = atoi(tempstring+7+i); /* we store a pointer to the beginning of the "\\a.b.c.d\proto\port" unicode string, one to the end of the string, and one to the end of the packet, since we must keep track of the number of bytes between end of the unicode string and the end of packet (padding) */ *mms_string_b = (char *)(data + MMS_SRV_UNICODE_STRING_OFFSET); *mms_string_e = (char *)(data + MMS_SRV_UNICODE_STRING_OFFSET + unicode_size * 2); *mms_padding_e = (char *)(data + datalen); /* looks funny, doesn't it */ return 0; }
int parse_gpt_entry(gpt_entry_t *gpt_entry, partition_entry_t *entry) { int result; assert((gpt_entry != 0) && (entry != 0)); if ((gpt_entry->first_lba == 0) && (gpt_entry->last_lba == 0)) { return -EINVAL; } memset(entry, 0, sizeof(partition_entry_t)); result = unicode_to_ascii(gpt_entry->name, (uint8_t *)entry->name); if (result != 0) { return result; } entry->start = (uint64_t)gpt_entry->first_lba * PARTITION_BLOCK_SIZE; entry->length = (uint64_t)(gpt_entry->last_lba - gpt_entry->first_lba + 1) * PARTITION_BLOCK_SIZE; return 0; }
static int file_list_handle_key(struct key_event * k) { int new_file = current_file; new_file = CLAMP(new_file, 0, flist.num_files - 1); if (k->mouse != MOUSE_NONE) { if (k->x >= 6 && k->x <= 67 && k->y >= 13 && k->y <= 47) { slash_search_mode = -1; if (k->mouse == MOUSE_SCROLL_UP) { new_file -= MOUSE_SCROLL_LINES; } else if (k->mouse == MOUSE_SCROLL_DOWN) { new_file += MOUSE_SCROLL_LINES; } else { new_file = top_file + (k->y - 13); } } } else if (slash_search_mode > -1) { int c = unicode_to_ascii(k->unicode); if (k->sym == SDLK_RETURN || k->sym == SDLK_ESCAPE) { if (k->state == KEY_PRESS) return 1; slash_search_mode = -1; status.flags |= NEED_UPDATE; return 1; } else if (k->sym == SDLK_BACKSPACE) { if (k->state == KEY_RELEASE) return 1; slash_search_mode--; status.flags |= NEED_UPDATE; reposition_at_slash_search(); return 1; } else if (c >= 32) { if (k->state == KEY_RELEASE) return 1; if (slash_search_mode < PATH_MAX) { slash_search_str[ slash_search_mode ] = c; slash_search_mode++; reposition_at_slash_search(); status.flags |= NEED_UPDATE; } return 1; } } switch (k->sym) { case SDLK_UP: new_file--; slash_search_mode = -1; break; case SDLK_DOWN: new_file++; slash_search_mode = -1; break; case SDLK_PAGEUP: new_file -= 35; slash_search_mode = -1; break; case SDLK_PAGEDOWN: new_file += 35; slash_search_mode = -1; break; case SDLK_HOME: new_file = 0; slash_search_mode = -1; break; case SDLK_END: new_file = flist.num_files - 1; slash_search_mode = -1; break; case SDLK_RETURN: if (k->state == KEY_PRESS) return 0; handle_enter_key(); slash_search_mode = -1; return 1; case SDLK_DELETE: if (k->state == KEY_RELEASE) return 1; slash_search_mode = -1; if (flist.num_files > 0) dialog_create(DIALOG_OK_CANCEL, "Delete file?", do_delete_file, NULL, 1, NULL); return 1; case SDLK_ESCAPE: slash_search_mode = -1; if (k->state == KEY_RELEASE && NO_MODIFIER(k->mod)) set_page(PAGE_INSTRUMENT_LIST); return 1; case SDLK_SLASH: if (k->orig_sym == SDLK_SLASH) { if (status.flags & CLASSIC_MODE) return 0; if (k->state == KEY_RELEASE) return 0; slash_search_mode = 0; status.flags |= NEED_UPDATE; return 1; } default: if (k->mouse == MOUSE_NONE) return 0; } if (k->mouse == MOUSE_CLICK) { if (k->state == KEY_RELEASE) return 0; } else if (k->mouse == MOUSE_DBLCLICK) { handle_enter_key(); return 1; } else { if (k->state == KEY_PRESS) return 0; } new_file = CLAMP(new_file, 0, flist.num_files - 1); if (new_file < 0) new_file = 0; if (new_file != current_file) { current_file = new_file; file_list_reposition(); status.flags |= NEED_UPDATE; } return 1; }
/* If containernumber == NULL, list the containers. * If containernumber is a string containing the number of the container, * fill in the provider name, container name and keyspec. */ long listMyCerts(const char *containerNumber, char *providerName, char *containerName, DWORD *pKeySpec) { HCERTSTORE hCertStore; PCCERT_CONTEXT pCertContext = NULL; int i = 1; int iContainerNr; if (containerNumber != NULL) { iContainerNr = atoi(containerNumber); providerName[0] = '\0'; containerName[0] = '\0'; *pKeySpec = -1; } if (hCertStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, L"MY")) { if (containerNumber == NULL) printf("Listing certs in MY cert store:\n"); } else { int err = GetLastError(); printf("CertOpenStore: %s (0x%0x)\n", e2str(err), err); return err; } // Retrieve each of the certificates in the store. while(pCertContext= CertEnumCertificatesInStore(hCertStore, pCertContext)) { char buf[400], provName[200], contName[200]; DWORD size = sizeof(buf); CRYPT_KEY_PROV_INFO *prov_info; if (CertGetCertificateContextProperty(pCertContext, CERT_KEY_PROV_INFO_PROP_ID, buf, &size)) { prov_info = (CRYPT_KEY_PROV_INFO *) buf; unicode_to_ascii(prov_info->pwszProvName, provName, sizeof(provName)); unicode_to_ascii(prov_info->pwszContainerName, contName, sizeof(contName)); if (containerNumber == NULL) { printf("%d. %S: \t%S (%s)\n", i, prov_info->pwszProvName, prov_info->pwszContainerName, prov_info->dwKeySpec == AT_KEYEXCHANGE ? "AT_KEYEXCHANGE" : "AT_SIGNATURE"); } else if (i == iContainerNr) { strcpy_s(providerName,PROVIDER_BUFFER_SIZE, provName); strcpy_s(containerName,CONTAINER_BUFFER_SIZE, contName); *pKeySpec = prov_info->dwKeySpec; break; } i++; } else { int err = GetLastError(); printf("- Error doing CertEnumCertificatesInStore: %s (0x%0x)\n", e2str(err), err); } } CertCloseStore(hCertStore, CERT_CLOSE_STORE_CHECK_FLAG); if (containerNumber == NULL) printf(" done\n"); return 0; }