예제 #1
0
        /*
        private static string get_template_name(ParsedSymbol sym)
        {
            char *name, *args;

            unsigned num_mark = sym->names.num;
            unsigned start_mark = sym->names.start;
            unsigned stack_mark = sym->stack.num;

            struct array array_pmt;

            sym->names.start = sym->names.num;
            if (!(name = get_literal_string(sym))) {
                sym->names.start = start_mark;
                return false;
            }

            str_array_init(&array_pmt);
            args = get_args(sym, &array_pmt, FALSE, '<', '>');
            if (args != null)
                name = str_printf(sym, "%s%s", name, args);

            sym->names.num = num_mark;
            sym->names.start = start_mark;
            sym->stack.num = stack_mark;

            return name;
        }
        */

        /*
        private static bool get_class(ParsedSymbol sym)
        {
            const char* name = NULL;

            while (sym.currentc != '@')
            {
                switch (sym.currentc)
                {
                    case '\0': 
                        return false;

                    case '0': case '1': case '2': case '3':
                    case '4': case '5': case '6': case '7':
                    case '8': case '9':
                        name = str_array_get_ref(&sym->names, *sym->current++ - '0');
                        break;

                    case '?':
                        switch (*++sym->current)
                        {
                            case '$':
                                sym->current++;
                                if ((name = get_template_name(sym)) &&
                                    !str_array_push(sym, name, -1, &sym->names))
                                    return false;
                                break;
                            case '?':
                                struct array stack = sym->stack;
                                unsigned int start = sym->names.start;
                                unsigned int num = sym->names.num;

                                str_array_init( &sym->stack );
                                if (symbol_demangle(sym)) 
                                    name = $"`{sym->result}'";
                                sym->names.start = start;
                                sym->names.num = num;
                                sym->stack = stack;
                                break;
                            default:
                                if (!(name = get_number(sym))) 
                                    return false;
                                name = str_printf( sym, "`%s'", name );
                                break;
                        }
                        break;
                    default:
                        name = get_literal_string(sym);
                        break;
                }

                if (!name || !str_array_push(sym, name, -1, &sym->stack))
                    return false;
            }

            sym.current++;
            return true;
        }
        */

        /*
        static char* get_class_string(struct parsed_symbol* sym, int start)
        {
            int          i;
            unsigned int len, sz;
            char*        ret;
            struct array *a = &sym->stack;

            for (len = 0, i = start; i < a->num; i++)
            {
                assert(a->elts[i]);
                len += 2 + strlen(a->elts[i]);
            }
            if (!(ret = und_alloc(sym, len - 1))) return NULL;
            for (len = 0, i = a->num - 1; i >= start; i--)
            {
                sz = strlen(a->elts[i]);
                memcpy(ret + len, a->elts[i], sz);
                len += sz;
                if (i > start)
                {
                    ret[len++] = ':';
                    ret[len++] = ':';
                }
            }
            ret[len] = '\0';
            return ret;
        }
        */

        /*
        private static string get_class_name(ParsedSymbol sym)
        {
            unsigned    mark = sym->stack.num;
            char*       s = NULL;

            if (get_class(sym))
                s = get_class_string(sym, mark);

            sym->stack.num = mark;
            return s;
        }        
        */

        private static bool get_calling_convention(char ch, out string call_conv,
            out string exported, DemanglerFlags flags)
        {
            call_conv = exported = null;

            if (!flags.HasFlag(DemanglerFlags.UNDNAME_NO_MS_KEYWORDS | 
                               DemanglerFlags.UNDNAME_NO_ALLOCATION_LANGUAGE))
            {
                // TODO: Collapse!
                if (flags.HasFlag(DemanglerFlags.UNDNAME_NO_LEADING_UNDERSCORES))
                {
                    if ((ch - 'A') % 2 == 1) 
                        exported = "dll_export ";
                    switch (ch)
                    {
                        case 'A': case 'B': 
                            call_conv = "cdecl"; 
                            break;
                        case 'C': case 'D': 
                            call_conv = "pascal"; 
                            break;
                        case 'E': case 'F': 
                            call_conv = "thiscall"; 
                            break;
                        case 'G': case 'H': 
                            call_conv = "stdcall"; 
                            break;
                        case 'I': case 'J': 
                            call_conv = "fastcall"; 
                            break;
                        case 'K': case 'L': 
                            break;
                        case 'M': 
                            call_conv = "clrcall"; 
                            break;
                        default: 
                            //ERR($"Unknown calling convention {ch}"); 
                            return false;
                    }
                }
                else
                {
                    if ((ch - 'A') % 2 == 1) 
                        exported = "__dll_export ";

                    switch (ch)
                    {
                        case 'A': case 'B': 
                            call_conv = "__cdecl"; 
                            break;
                        case 'C': case 'D': 
                            call_conv = "__pascal"; 
                            break;
                        case 'E': case 'F': 
                            call_conv = "__thiscall"; 
                            break;
                        case 'G': case 'H': 
                            call_conv = "__stdcall"; 
                            break;
                        case 'I': case 'J': 
                            call_conv = "__fastcall"; 
                            break;
                        case 'K': case 'L': 
                            break;
                        case 'M': 
                            call_conv = "__clrcall"; 
                            break;
                        default: 
                            //ERR($"Unknown calling convention {ch}"); 
                            return false;
                    }
                }
            }
            return true;
        }
예제 #2
0
 public ParsedSymbol(string mangled, DemanglerFlags demFlags)
 {
     current = new StringPointer(mangled);
     flags = demFlags;
 }