/****************************************************************************** * public メソッド *****************************************************************************/ void PostDataChecker::validate_uitem(apr_pool_t *pool, apr_uint64_t file_size, apr_time_t mtime, const char **file_name, const char **file_mime, const char *file_digest, const char *remove_pass, const char *download_pass, const char **comment, const char *code_pat) { const char *file_ext; validate_file_name(pool, file_name, code_pat); validate_file_mime(pool, *file_mime); validate_comment(pool, comment, code_pat); file_ext = get_file_ext(*file_name); validate_file_ext(file_ext); if (strlen(*file_name) == 0) { THROW(MESSAGE_POST_FILE_NAME_EMPTY); } else if (strlen(*file_name) > (ITM_MAX_FILE_NAME_SIZE-1)) { THROW(MESSAGE_POST_FILE_NAME_TOO_LONG); } if (file_size == 0) { THROW(MESSAGE_POST_FILE_SIZE_ZERO); } if (strlen(*file_mime) == 0) { THROW(MESSAGE_POST_FILE_MIME_EMPTY); } else if (strlen(*file_mime) > (ITM_MAX_FILE_MIME_SIZE-1)) { THROW(MESSAGE_POST_FILE_MIME_TOO_LONG); } if (strlen(file_ext) == 0) { THROW(MESSAGE_POST_FILE_EXT_EMPTY); } else if (strlen(file_ext) > (ITM_MAX_FILE_EXT_SIZE-1)) { THROW(MESSAGE_POST_FILE_EXT_TOO_LONG); } if (strlen(file_digest) == 0) { THROW(MESSAGE_POST_FILE_DIGEST_EMPTY); } else if (strlen(file_digest) > (ITM_MAX_FILE_DIGEST_SIZE-1)) { THROW(MESSAGE_POST_FILE_DIGEST_TOO_LONG); } if (strlen(remove_pass) > (ITM_MAX_REMOVE_PASS_SIZE-1)) { THROW(MESSAGE_POST_REMOVE_PASS_TOO_LONG); } if (strlen(download_pass) > (ITM_MAX_DOWNLOAD_PASS_SIZE-1)) { THROW(MESSAGE_POST_DOWNLOAD_PASS_TOO_LONG); } if (strlen(*comment) == 0) { #ifndef EMPTY_COMMENT THROW(MESSAGE_POST_COMMENT_EMPTY); #endif } else if (strlen(*comment) > (ITM_MAX_COMMENT_SIZE-1)) { THROW(MESSAGE_POST_COMMENT_TOO_LONG); } }
void idaapi run(int arg) { char buf[MAXSTR]; char cmt[MAXSTR]; char *valid_cmt = NULL; char ext[0x20]; FILE *f = NULL; short checkboxes = OPTION_NAMES | OPTION_COMMENTS; sval_t bank = 1; // default bool first = true; bool hasName = false; flags_t flags; ea_t ea = 0x0; if( AskUsingForm_c( madnes_options, &checkboxes, &bank ) != 1 || checkboxes == 0 ) return; // prepare filename for namelist (.nl) file get_input_file_path( buf, sizeof( buf ) ); qsnprintf( ext, sizeof( ext ),".%X.nl",--bank ); qstrncat( buf, ext, sizeof( buf )-strlen( buf ) ); // (always) create file f = qfopen( buf, "w" ); if( f == NULL ) { warning( "%s could not be created!", buf ); return; } msg( "Writing to file %s..", buf ); while( ea <= 0xFFFF ) { hasName = false; // get flags if( isCode( getFlags( ea ) ) ) flags = getFlags( ea ); else flags = getFlags( get_item_head( ea ) ); // if user either chose to export names or anynames if( ( ( checkboxes & OPTION_NAMES ) && has_name( flags ) ) || ( ( checkboxes & OPTION_ANYNAME ) && has_any_name( flags ) ) ) { // if current item is code or if current item is head of item if( isCode( flags ) || ea==get_item_head( ea ) ) { // get name get_name( ea, ea, buf, sizeof( buf ) ); // write to file qfprintf( f, "$%04X#%s#", ea, buf ); } else // if not code or not head of item (must be an array) { // get name of item start get_name( get_item_head( ea ), get_item_head( ea ), buf, sizeof( buf ) ); // calc displacement, write to file (example: "password+$04") qfprintf( f, "$%04X#%s+$%X#", ea, buf, ea-get_item_head( ea ) ); } hasName = true; } // if user chose to export cross references if( checkboxes & OPTION_XREFS ) { xrefblk_t xb; first = true; // cycle through all xrefs except ordinary flow xrefs for ( bool ok=xb.first_to( ea, XREF_FAR/*XREF_ALL*/); ok; ok=xb.next_to() ) { if( first ) // if first xref { if( !hasName ) // if this location hasn't a name yet, add symbol stub { qfprintf( f, "$%04X##", ea ); hasName = true; } qfprintf( f, "XREFS:\n\\"); // append XREFS first = false; } qfprintf( f, " $%04X\n\\", xb.from ); } } // if user chose to export comments if( checkboxes & OPTION_COMMENTS ) { if( has_cmt( flags ) ) // if current item has comment { // get comment // workaround for get_any_indeted_cmt() // -> unresolved external symbol "char * __stdcall get_any_indented_cmt(unsigned long,unsigned char *)" (?get_any_indented_cmt@@YGPADKPAE@Z) if( get_cmt( ea, false, cmt, sizeof( cmt ) ) == -1 ) get_cmt( ea, true, cmt, sizeof( cmt ) ); // validate comment (replace invalid chars, add room for additional chars) valid_cmt = validate_comment( cmt ); if( valid_cmt != NULL ) { if( !hasName ) { qfprintf( f, "$%04X##", ea ); // add symbol stub if no name yet hasName = true; } qfprintf( f, "%s", valid_cmt ); // write comment to file qfree( valid_cmt ); } } } if( hasName) qfprintf( f, "\n" ); ea++; // get name of each byte } qfclose( f ); msg( "done.\n" ); }