示例#1
0
        /// <summary>
        /// Check this function to see if it is a library function. Return true if
        /// it is, and copy its name to pProc.Name
        /// </summary>
        public bool LibCheck(IServiceProvider services, Procedure proc, Address addr)
        {
            var listener = services.RequireService<DecompilerEventListener>();
            long fileOffset;
            int h;
            // i, j, arg;
            uint Idx;

            if (!program.SegmentMap.TryFindSegment(addr, out ImageSegment segment))
                return false;
            
            fileOffset = addr - segment.MemoryArea.BaseAddress;              /* Offset into the image */
            //if (fileOffset == program.offMain)
            //{
            //    /* Easy - this function is called main! */
            //    pProc.Name = "main";
            //    return false;
            //}

            byte[] pat = new byte[PATLEN];
            if (!segment.MemoryArea.TryReadBytes(fileOffset, PATLEN, pat))
                return false;

            fixWildCards(pat);                                   /* Fix wild cards in the copy */
            h = g_pattern_hasher.hash(pat);                      /* Hash the found proc */
                                                                 /* We always have to compare keys, because the hash function will always return a valid index */
            if (MemoryArea.CompareArrays(ht![h].htPat!, 0, pat, PATLEN))
示例#2
0
        /// <summary>
        /// Check this function to see if it is a library function. Return true if
        /// it is, and copy its name to pProc.Name
        /// </summary>
        public bool LibCheck(IServiceProvider services, Program program, Procedure proc, Address addr)
        {
            var diagSvc = services.RequireService<IDiagnosticsService>();
            long fileOffset;
            int h;
            // i, j, arg;
            uint Idx;

            if (false) //  && program.bSigs == false)
            {
                /* No signatures... can't rely on hash parameters to be initialised
                so always return false */
                return false;
            }

            ImageSegment segment;
            if (!program.SegmentMap.TryFindSegment(addr, out segment))
                return false;
            

            fileOffset = addr - segment.MemoryArea.BaseAddress;              /* Offset into the image */
            //if (fileOffset == program.offMain)
            //{
            //    /* Easy - this function is called main! */
            //    pProc.Name = "main";
            //    return false;
            //}

            byte[] pat = new byte[PATLEN];
            if (!segment.MemoryArea.TryReadBytes(fileOffset, PATLEN, pat))
                return false;

            fixWildCards(pat);                                   /* Fix wild cards in the copy */
            h = g_pattern_hasher.hash(pat);                      /* Hash the found proc */
                                                                 /* We always have to compare keys, because the hash function will always return a valid index */
            if (MemoryArea.CompareArrays(ht[h].htPat, 0, pat, PATLEN))
            {
#if NOT_YET
                /* We have a match. Save the name, if not already set */
                if (string.IsNullOrEmpty(pProc.Name))     /* Don't overwrite existing name */
                {
                    /* Give proc the new name */
                    pProc.Name = ht[h].htSym;
                }
                /* But is it a real library function? */
                i = NIL;
                if ((numFunc == 0) || (i = searchPList(ht[h].htSym)) != NIL)
                {
                    pProc.flg |= PROC_ISLIB;        /* It's a lib function */
                    pProc.callingConv(CConv::C);
                    if (i != NIL)
                    {
                        /* Allocate space for the arg struct, and copy the hlType to
                            the appropriate field */
                        arg = pFunc[i].firstArg;
                        pProc.args.numArgs = pFunc[i].numArg;
                        pProc.args.resize(pFunc[i].numArg);
                        for (j = 0; j < pFunc[i].numArg; j++)
                        {
                            pProc.args[j].type = pArg[arg++];
                        }
                        if (pFunc[i].typ != hlType.TYPE_UNKNOWN)
                        {
                            pProc.retVal.type = pFunc[i].typ;
                            pProc.flg |= PROC_IS_FUNC;
                            switch (pProc.retVal.type)
                            {
                            case hlType.TYPE_LONG_SIGN:
                            case hlType.TYPE_LONG_UNSIGN:
                                pProc.liveOut.setReg(rDX).addReg(rAX);
                                break;
                            case hlType.TYPE_WORD_SIGN:
                            case hlType.TYPE_WORD_UNSIGN:
                                pProc.liveOut.setReg(rAX);
                                break;
                            case hlType.TYPE_BYTE_SIGN:
                            case hlType.TYPE_BYTE_UNSIGN:
                                pProc.liveOut.setReg(rAL);
                                break;
                            case hlType.TYPE_STR:
                            case hlType.TYPE_PTR:
                                fprintf(stderr, "Warning assuming Large memory model\n");
                                pProc.liveOut.setReg(rAX).addReg(rDS);
                                break;
                            default:
                                diagSvc.Warn(string.Format("Unknown retval type {0} for {1} in LibCheck.",
                                           pProc.retVal.type,
                                           pProc.Name);
                                break;
                                /*** other types are not considered yet ***/
                            }
                        }
                        pProc.getFunctionType()->m_vararg = pFunc[i].bVararg;
                    }
                }
                else if (i == NIL)
                {
                    /* Have a symbol for it, but does not appear in a header file.
                        Treat it as if it is not a library function */
                    pProc.flg |= PROC_RUNTIME;      /* => is a runtime routine */
                }
#endif
            }
            if (locatePattern(segment.MemoryArea.Bytes, (uint) fileOffset,
                              (uint) (fileOffset + pattMsChkstk.Length),
                              pattMsChkstk, out Idx))
            {
                /* Found _chkstk */
                //pProc.Name = "chkstk";
                //pProc.flg |= PROC_ISLIB;        /* We'll say its a lib function */
                //pProc.args.numArgs = 0;     /* With no args */
            }

            return true;  // ((pProc.flg & PROC_ISLIB) != 0);
        }