Skip to content

Commit

Permalink
anvill: Add StructType support to CreateConstFromMemory (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrogario authored Feb 11, 2021
1 parent c88f20a commit 1ea7b64
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/Lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,32 @@ CreateConstFromMemory(const uint64_t addr, llvm::Type *type,
case llvm::Type::PointerTyID: {
} break;

case llvm::Type::StructTyID: {
// Take apart the structure type, recursing into each element
// so that we can create a constant structure
auto struct_type = llvm::dyn_cast<llvm::StructType>(type);

auto num_elms = struct_type->getNumElements();
auto elm_offset = 0;

std::vector<llvm::Constant *> const_list;

for (std::uint64_t i = 0U; i < num_elms; ++i) {
auto elm_type = struct_type->getElementType(i);
auto elm_size = dl.getTypeSizeInBits(elm_type);

auto const_elm =
CreateConstFromMemory(addr + elm_offset, elm_type, arch,
program, module);

const_list.push_back(const_elm);
elm_offset += elm_size / 8;
}

result = llvm::ConstantStruct::get(struct_type,
llvm::ArrayRef(const_list));
} break;

case llvm::Type::ArrayTyID: {
const auto elm_type = type->getArrayElementType();
const auto elm_size = dl.getTypeSizeInBits(elm_type);
Expand All @@ -570,12 +596,13 @@ CreateConstFromMemory(const uint64_t addr, llvm::Type *type,
} break;

default:
LOG(FATAL) << "Unknown LLVM Type: " << remill::LLVMThingToString(type);
LOG(FATAL) << "Unhandled LLVM Type: " << remill::LLVMThingToString(type);
break;
}

return result;
}

} // namespace

bool LiftCodeIntoModule(const remill::Arch *arch, const Program &program,
Expand Down

0 comments on commit 1ea7b64

Please sign in to comment.