@@ -340,12 +340,22 @@ class PowerpcArchitecture: public Architecture
340340
341341 bool FillInstruction (Instruction* instruction, const uint8_t * data, size_t length, uint64_t address)
342342 {
343- uint32_t word32 = *(const uint32_t *) data;
343+ switch (length)
344+ {
345+ case 4 :
346+ {
347+ uint32_t word32 = *(const uint32_t *) data;
344348
345- if (endian == BigEndian)
346- word32 = bswap32 (word32);
349+ if (endian == BigEndian)
350+ word32 = bswap32 (word32);
347351
348- return Decompose (instruction, word32, address, decodeFlags);
352+ return Decompose32 (instruction, word32, address, decodeFlags);
353+ }
354+
355+ default :
356+ MYLOG (" FillInstruction: unrecognized length %d" , length);
357+ return false ;
358+ }
349359 }
350360
351361 /* think "GetInstructionBranchBehavior()"
@@ -361,17 +371,17 @@ class PowerpcArchitecture: public Architecture
361371 virtual bool GetInstructionInfo (const uint8_t * data, uint64_t addr,
362372 size_t maxLen, InstructionInfo& result) override
363373 {
364- Instruction instruction;
365-
366- if (maxLen < 4 )
374+ size_t instructionLength = GetInstructionLength (data, maxLen, decodeFlags);
375+ if (instructionLength == 0 )
367376 {
368- MYLOG (" ERROR: need at least 4 bytes \n " );
377+ MYLOG (" ERROR: not enough bytes for instruction \n " );
369378 return false ;
370379 }
371380
372- result.length = 4 ;
381+ result.length = instructionLength ;
373382
374- if (!FillInstruction (&instruction, data, maxLen, addr))
383+ Instruction instruction;
384+ if (!FillInstruction (&instruction, data, instructionLength, addr))
375385 {
376386 MYLOG (" ERROR: FillInstruction()\n " );
377387 return false ;
@@ -540,15 +550,15 @@ class PowerpcArchitecture: public Architecture
540550 const char * mnemonic = NULL ;
541551
542552 // MYLOG("%s()\n", __func__);
543-
544- if (len < 4 )
553+ size_t instructionLength = GetInstructionLength (data, len, decodeFlags);
554+ if (instructionLength == 0 )
545555 {
546- MYLOG (" ERROR: need at least 4 bytes \n " );
556+ MYLOG (" ERROR: not enough bytes for instruction \n " );
547557 return false ;
548558 }
549559
550- len = 4 ;
551- if (!FillInstruction (&instruction, data, len , addr))
560+ len = instructionLength ;
561+ if (!FillInstruction (&instruction, data, instructionLength , addr))
552562 {
553563 MYLOG (" ERROR: FillInstruction()\n " );
554564 return false ;
@@ -740,27 +750,24 @@ class PowerpcArchitecture: public Architecture
740750
741751 virtual bool GetInstructionLowLevelIL (const uint8_t * data, uint64_t addr, size_t & len, LowLevelILFunction& il) override
742752 {
743- Instruction instruction;
744- bool rc = false ;
745-
746- if (len < 4 )
753+ size_t instructionLength = GetInstructionLength (data, len, decodeFlags);
754+ if (instructionLength == 0 )
747755 {
748- MYLOG (" ERROR: need at least 4 bytes \n " );
749- goto cleanup ;
756+ MYLOG (" ERROR: not enough bytes for instruction \n " );
757+ return false ;
750758 }
751759
752- if (!FillInstruction (&instruction, data, len, addr))
760+ len = instructionLength;
761+
762+ Instruction instruction;
763+ if (!FillInstruction (&instruction, data, instructionLength, addr))
753764 {
754765 MYLOG (" ERROR: FillInstruction()\n " );
755766 il.AddInstruction (il.Undefined ());
756- goto cleanup ;
767+ return false ;
757768 }
758769
759- rc = GetLowLevelILForPPCInstruction (this , il, &instruction, addr);
760- len = 4 ;
761-
762- cleanup:
763- return rc;
770+ return GetLowLevelILForPPCInstruction (this , il, &instruction, addr);
764771 }
765772
766773 virtual size_t GetFlagWriteLowLevelIL (BNLowLevelILOperation op, size_t size, uint32_t flagWriteType,
0 commit comments