Пример #1
0
static uint32_t regm_CheckSection1 (poffHandle_t hPoff, uint32_t dwOffset)
{
  OPTYPE op;

  /* Seek to the beginning of the section. */

  regm_ProgSeek(hPoff, dwOffset);

  /* Read the opcode at that position. */

  (void)insn_GetOpCode(hPoff, &op);

  /* Is it a oJMP instruction? This happens when there are nested
   * functions.  The entry point into the parent function is a jump
   * around the nested functions.
   */

  if (GETOP(&op) == oJMP)
    {
      /* Yes, then the block really begins at the target of the jump */

      return GETARG(&op);
    }
  else
    {
      /* No, then the block really begins right here */

      return dwOffset;
    }
}
Пример #2
0
uint32_t regm_ReadNodePCodes(struct procdata_s *pNode, poffHandle_t hPoff,
                           uint32_t dwStartOffset, uint32_t dwEndOffset,
                           uint8_t cTerminalOpcode)
{
  uint32_t dwOffset = dwStartOffset;
  long nAlloc = INITIAL_PCODE_ALLOC;
  long nPCodes;
  uint8_t bTerminatorFound;

  dbg("Reading Node: %08lx %08lx %02x\n",
      dwStartOffset, dwEndOffset, cTerminalOpcode);

  /* Allocate an inital buffer to hold the instructions */

  pNode->pPCode = (OPTYPE*)
    malloc(INITIAL_PCODE_ALLOC*sizeof(struct procinsn_s*));
  if (!pNode->pPCode)
    {
      fatal(eNOMEMORY);
    }

  /* Seek to the beginning of the data */

  regm_ProgSeek(hPoff, dwStartOffset);

  /* Read all of the instructions in the main program section */

  nPCodes = 0;
  bTerminatorFound = 0;
  do
    {
      /* Make sure that there is space for another pcode */

      if (nPCodes > nAlloc)
        {
          /* If not, then reallocate the array */

          nAlloc += PCODE_RELLALLOC;
          pNode->pPCode = (OPTYPE*)
            realloc(pNode->pPCode, nAlloc*sizeof(OPTYPE));
        }

      /* Ready the pcode ito the array */

      dwOffset += insn_GetOpCode(hPoff, &pNode->pPCode[nPCodes]);

      /* Check for a terminating pcode */

      if ((GETOP(&pNode->pPCode[nPCodes]) == cTerminalOpcode) ||
          (GETOP(&pNode->pPCode[nPCodes]) == oEND))
        {
          bTerminatorFound++;
        }

      /* Increment the count of pcodes read */

      nPCodes++;
    }
  while (!bTerminatorFound && (dwOffset < dwEndOffset));

  dbg("              %08lx %08lx %02x\n",
      dwStartOffset, dwOffset, GETOP(&pNode->pPCode[nPCodes-1]));

  /* Save the number of pcodes that we found */

  pNode->nPCodes = nPCodes;

  /* Check for the correct terminator */

  if (GETOP(&pNode->pPCode[nPCodes-1]) != cTerminalOpcode)
    {
      fatal(ePOFFCONFUSION);
    }

  /* Return any unused space in the allocation */

  pNode->pPCode = (OPTYPE*)
    realloc(pNode->pPCode, nPCodes*sizeof(OPTYPE));

  /* Return the actual end offset */

  return dwOffset;
}