| 37 | |
| 38 | |
| 39 | std::vector<DisassemblyTextLine> CodeDataRenderer::GetLinesForData(BinaryView* data, uint64_t addr, Type* type, |
| 40 | const std::vector<InstructionTextToken>& prefix, size_t width, std::vector<std::pair<Type*, size_t>>& context) |
| 41 | { |
| 42 | size_t instCount = 50; |
| 43 | auto arch = data->GetDefaultArchitecture(); |
| 44 | size_t readLength = arch->GetMaxInstructionLength() * instCount; |
| 45 | |
| 46 | std::vector<DisassemblyTextLine> result; |
| 47 | DisassemblyTextLine contents; |
| 48 | |
| 49 | auto buffer = data->ReadBuffer(addr, readLength); |
| 50 | if (buffer.GetLength() == 0) |
| 51 | return result; |
| 52 | |
| 53 | size_t totalRead = 0; |
| 54 | for (size_t i = 0; i < instCount; i++) |
| 55 | { |
| 56 | uint64_t lineAddr = addr + totalRead; |
| 57 | size_t length = readLength - totalRead; |
| 58 | std::vector<InstructionTextToken> insnTokens; |
| 59 | auto ok = arch->GetInstructionText((uint8_t*)buffer.GetDataAt(totalRead), lineAddr, length, insnTokens); |
| 60 | if ((!ok) || (insnTokens.size() == 0)) |
| 61 | { |
| 62 | insnTokens = {InstructionTextToken(TextToken, "??")}; |
| 63 | length = arch->GetInstructionAlignment(); |
| 64 | if (length == 0) |
| 65 | length = 1; |
| 66 | } |
| 67 | |
| 68 | contents.addr = lineAddr; |
| 69 | contents.tokens = insnTokens; |
| 70 | |
| 71 | result.push_back(contents); |
| 72 | totalRead += length; |
| 73 | } |
| 74 | |
| 75 | return result; |
| 76 | } |