Skip to content

Commit

Permalink
presentation of language and project related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pruzko committed Jan 31, 2019
1 parent 8dea938 commit a749f11
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 111 deletions.
150 changes: 62 additions & 88 deletions src/fileformat/file_format/pe/pe_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,6 @@ void PeFormat::loadVisualBasicHeader()

// TODO check VB header magic

std::cout << "[KUBO] VB header size:" << std::to_string(vbh.headerSize()) << "\n";
vbh.dump(std::cout);

if (vbh.projExeNameOffset != 0)
{
projExeName = retdec::utils::readNullTerminatedAscii(allBytes.data(), allBytes.size(),
Expand All @@ -730,9 +727,6 @@ void PeFormat::loadVisualBasicHeader()
visualBasicInfo.setProjectName(projName);
}

std::cout << "KUBO KING: " << projExeName << " | " << projDesc << " | " << helpFile << " | "
<< projName << "\n\n";

for (size_t i = 0; i < sizeof(vbh.languageDLL) && vbh.languageDLL[i]; i++)
{
projLanguageDLL.push_back(vbh.languageDLL[i]);
Expand All @@ -745,8 +739,6 @@ void PeFormat::loadVisualBasicHeader()
visualBasicInfo.setBackupLanguageDLL(projBackupLanguageDLL);
visualBasicInfo.setLanguageDLLPrimaryLCID(vbh.LCID1);
visualBasicInfo.setLanguageDLLSecondaryLCID(vbh.LCID2);
std::cout << "KUBO KING: " << projLanguageDLL << " | " << projBackupLanguageDLL << "\n\n";


if (vbh.projectInfoAddr >= baseAddress)
{
Expand All @@ -769,65 +761,67 @@ void PeFormat::loadVisualBasicHeader()
*/
bool PeFormat::parseVisualBasicComRegistrationData(std::size_t structureOffset, std::size_t baseAddress)
{
auto allBytes = getBytes();
std::vector<std::uint8_t> bytes;
std::size_t offset = 0;
struct VBCOMRData vbcrd;
std::string projName;
std::string helpFile;
std::string projDesc;

if (!getBytes(bytes, structureOffset, vbcrd.structureSize()) || bytes.size() != vbcrd.structureSize())
{
return false;
}

vbcrd.regInfoOffset = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.regInfoOffset);
vbcrd.projNameOffset = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.projNameOffset);
vbcrd.helpFileOffset = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.helpFileOffset);
vbcrd.projDescOffset = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.projDescOffset);
std::memcpy(&vbcrd.projCLSID, reinterpret_cast<void *>(&bytes.data()[offset]), sizeof(vbcrd.projCLSID)); offset += sizeof(vbcrd.projCLSID);
vbcrd.projTlbLCID = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.projTlbLCID);
vbcrd.unknown = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.unknown);
vbcrd.tlbVerMajor = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.tlbVerMajor);
vbcrd.tlbVerMinor = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.tlbVerMinor);

if (!isLittleEndian())
{
vbcrd.regInfoOffset = byteSwap32(vbcrd.regInfoOffset);
vbcrd.projNameOffset = byteSwap32(vbcrd.projNameOffset);
vbcrd.helpFileOffset = byteSwap32(vbcrd.helpFileOffset);
vbcrd.projDescOffset = byteSwap32(vbcrd.projDescOffset);
vbcrd.projTlbLCID = byteSwap32(vbcrd.projTlbLCID);
vbcrd.unknown = byteSwap32(vbcrd.unknown);
vbcrd.tlbVerMajor = byteSwap32(vbcrd.tlbVerMajor);
vbcrd.tlbVerMinor = byteSwap32(vbcrd.tlbVerMinor);
}
// visualBasicInfo.setTypeLibCLSID(vbcrd.projCLSID); TODO
visualBasicInfo.setTypeLibLCID(vbcrd.projDescOffset);
if (!visualBasicInfo.hasProjectName())
{
projName = retdec::utils::readNullTerminatedAscii(allBytes.data(), allBytes.size(),
structureOffset + vbcrd.projNameOffset);
}
if (!visualBasicInfo.hasProjectHelpFile())
{
helpFile = retdec::utils::readNullTerminatedAscii(allBytes.data(), allBytes.size(),
structureOffset + vbcrd.helpFileOffset);
}
if (!visualBasicInfo.hasProjectDescription())
{
projDesc = retdec::utils::readNullTerminatedAscii(allBytes.data(), allBytes.size(),
structureOffset + vbcrd.projDescOffset);
}

std::cout << "[KUBO] VB COM register data size: " << std::to_string(vbcrd.structureSize()) << "\n";
std::cout << "projName: " << projName << "\n";
std::cout << "helpFile: " << helpFile << "\n";
std::cout << "projDesc: " << projDesc << "\n";

vbcrd.dump(std::cout);

// auto allBytes = getBytes();
// std::vector<std::uint8_t> bytes;
// std::size_t offset = 0;
// struct VBCOMRData vbcrd;
// std::string projName;
// std::string helpFile;
// std::string projDesc;

// if (!getBytes(bytes, structureOffset, vbcrd.structureSize()) || bytes.size() != vbcrd.structureSize())
// {
// return false;
// }

// vbcrd.regInfoOffset = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.regInfoOffset);
// vbcrd.projNameOffset = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.projNameOffset);
// vbcrd.helpFileOffset = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.helpFileOffset);
// vbcrd.projDescOffset = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.projDescOffset);
// std::memcpy(&vbcrd.projCLSID, reinterpret_cast<void *>(&bytes.data()[offset]), sizeof(vbcrd.projCLSID)); offset += sizeof(vbcrd.projCLSID);
// vbcrd.projTlbLCID = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.projTlbLCID);
// vbcrd.unknown = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.unknown);
// vbcrd.tlbVerMajor = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.tlbVerMajor);
// vbcrd.tlbVerMinor = *reinterpret_cast<std::uint32_t *>(&bytes.data()[offset]); offset += sizeof(vbcrd.tlbVerMinor);

// if (!isLittleEndian())
// {
// vbcrd.regInfoOffset = byteSwap32(vbcrd.regInfoOffset);
// vbcrd.projNameOffset = byteSwap32(vbcrd.projNameOffset);
// vbcrd.helpFileOffset = byteSwap32(vbcrd.helpFileOffset);
// vbcrd.projDescOffset = byteSwap32(vbcrd.projDescOffset);
// vbcrd.projTlbLCID = byteSwap32(vbcrd.projTlbLCID);
// vbcrd.unknown = byteSwap32(vbcrd.unknown);
// vbcrd.tlbVerMajor = byteSwap32(vbcrd.tlbVerMajor);
// vbcrd.tlbVerMinor = byteSwap32(vbcrd.tlbVerMinor);
// }
// // visualBasicInfo.setTypeLibCLSID(vbcrd.projCLSID); TODO
// visualBasicInfo.setTypeLibLCID(vbcrd.projDescOffset);
// if (!visualBasicInfo.hasProjectName())
// {
// projName = retdec::utils::readNullTerminatedAscii(allBytes.data(), allBytes.size(),
// structureOffset + vbcrd.projNameOffset);
// }
// if (!visualBasicInfo.hasProjectHelpFile())
// {
// helpFile = retdec::utils::readNullTerminatedAscii(allBytes.data(), allBytes.size(),
// structureOffset + vbcrd.helpFileOffset);
// }
// if (!visualBasicInfo.hasProjectDescription())
// {
// projDesc = retdec::utils::readNullTerminatedAscii(allBytes.data(), allBytes.size(),
// structureOffset + vbcrd.projDescOffset);
// }

// std::cout << "[KUBO] VB COM register data size: " << std::to_string(vbcrd.structureSize()) << "\n";
// std::cout << "projName: " << projName << "\n";
// std::cout << "helpFile: " << helpFile << "\n";
// std::cout << "projDesc: " << projDesc << "\n";

// vbcrd.dump(std::cout);

// return true;
(void)structureOffset; (void)baseAddress;
return true;
}

Expand Down Expand Up @@ -883,10 +877,6 @@ bool PeFormat::parseVisualBasicProjectInfo(std::size_t structureOffset, std::siz
visualBasicInfo.setProjectPath(projPath);
visualBasicInfo.setPcode(vbpi.nativeCodeAddr == 0);

std::cout << "[KUBO] VB project info size: " << std::to_string(vbpi.headerSize()) << "\n";
std::cout << "[KUBO] path: " << retdec::utils::unicodeToAscii(vbpi.pathInformation, sizeof(vbpi.pathInformation)) << "\n";
vbpi.dump(std::cout);

if (vbpi.externalTableAddr >= baseAddress)
{
vbExternTableOffset = vbpi.externalTableAddr - baseAddress;
Expand Down Expand Up @@ -940,8 +930,6 @@ bool PeFormat::parseVisualBasicExternTable(std::size_t structureOffset, std::siz
entry.importDataAddr = byteSwap32(entry.importDataAddr);
}

// std::cerr << "Entry type: " << entry.type << "\n";

if (entry.type != static_cast<std::uint32_t>(VBExternTableEntryType::external)
|| entry.importDataAddr < baseAddress)
{
Expand Down Expand Up @@ -981,12 +969,7 @@ bool PeFormat::parseVisualBasicExternTable(std::size_t structureOffset, std::siz
auto ext = std::make_unique<VisualBasicExtern>();
ext->setModuleName(moduleName);
ext->setApiName(apiName);
// std::cerr << "[<3] " << ext->getModuleName() << "\n";
// std::cerr << "[<3] " << ext->getApiName() << "\n";
visualBasicInfo.addExtern(std::move(ext));
// std::cerr << "[<3] " << visualBasicInfo.getNumberOfExterns() << "\n";
// std::cout << "[KUBO] moduleName: " << moduleName << "\n";
// std::cout << "[KUBO] apiName: " << apiName << "\n";
}

return true;
Expand Down Expand Up @@ -1059,18 +1042,14 @@ bool PeFormat::parseVisualBasicObjectTable(std::size_t structureOffset, std::siz

visualBasicInfo.setProjectPrimaryLCID(vbot.LCID1);
visualBasicInfo.setProjectSecondaryLCID(vbot.LCID2);
// TODO KUBO GUID

std::cout << "[KUBO] VB object table size: " << std::to_string(vbot.structureSize()) << "\n";
// TODO GUID

if (!visualBasicInfo.hasProjectName() && vbot.projectNameAddr >= baseAddress)
{
projectNameOffset = vbot.projectNameAddr - baseAddress;
projName = retdec::utils::readNullTerminatedAscii(allBytes.data(), allBytes.size(), projectNameOffset);
visualBasicInfo.setProjectName(projName);
std::cout << "[KUBO] Project name: " << projName << "\n";
}
vbot.dump(std::cout);

if (vbot.objectDescriptorsAddr >= baseAddress)
{
Expand Down Expand Up @@ -1145,7 +1124,6 @@ bool PeFormat::parseVisualBasicObjects(std::size_t structureOffset, std::size_t
std::string objectName = readNullTerminatedAscii(allBytes.data(), allBytes.size(), objectNameOffset);
object = std::make_unique<VisualBasicObject>();
object->setName(objectName);
std::cout << "[KUBO] objectName: " << objectName << "\n";

if (vbpod.methodNamesAddr >= baseAddress)
{
Expand Down Expand Up @@ -1173,14 +1151,10 @@ bool PeFormat::parseVisualBasicObjects(std::size_t structureOffset, std::size_t
std::size_t methodNameOffset = methodNameAddr - baseAddress;
std::string methodName = readNullTerminatedAscii(allBytes.data(), allBytes.size(), methodNameOffset);
object->addMethod(methodName);

std::cout << "[KUBO] method" << mIdx << ": " << methodName << "\n";
}
}

visualBasicInfo.addObject(std::move(object));
std::cout << "\n[KUBO] object" << i << "\n";
vbpod.dump(std::cout);
}

return true;
Expand Down
9 changes: 9 additions & 0 deletions src/fileinfo/file_information/file_information.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,15 @@ bool FileInformation::isVisualBasicUsed() const
return visualBasicInfo.isUsed();
}

/**
* Check whether visual basic uses P-Code.
* @return @c true if it does, otherwise @c false/
*/
bool FileInformation::getVisualBasicIsPcode() const
{
return visualBasicInfo.isPcode();
}

/**
* Get visual basic language DLL
* @return Visual basic language DLL
Expand Down
1 change: 1 addition & 0 deletions src/fileinfo/file_information/file_information.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class FileInformation
/// @name Getters of @a visualBasicInfo
/// @{
bool isVisualBasicUsed() const;
bool getVisualBasicIsPcode() const;
std::string getVisualBasicLanguageDLL() const;
std::string getVisualBasicBackupLanguageDLL() const;
std::string getVisualBasicProjectExeName() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "retdec/fileformat/utils/conversions.h"
#include "fileinfo/file_presentation/getters/simple_getter/visual_basic_plain_getter.h"

using namespace retdec::utils;
using namespace retdec::fileformat;

namespace fileinfo {
Expand Down Expand Up @@ -38,31 +39,35 @@ std::size_t VisualBasicPlainGetter::loadInformation(std::vector<std::string> &de
return 0;
}

desc.push_back("Super Cool Info : ");
desc.push_back("More Super Cool Info : ");
info.push_back("TODO");
info.push_back("TODO");
desc.push_back("Project name : ");
desc.push_back("Project exe name : ");
desc.push_back("Project path : ");
desc.push_back("Project description : ");
desc.push_back("Project help file : ");
desc.push_back("Language DLL : ");
desc.push_back("Backup Language DLL : ");
desc.push_back("Language DLL primary LCID : ");
desc.push_back("Language DLL secondary LCID : ");
desc.push_back("Project primary LCID : ");
desc.push_back("Project secondary LCID : ");
desc.push_back("TypeLibLCID : ");
desc.push_back("Is P-Code : ");

info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicProjectName()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicProjectExeName()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicProjectPath()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicProjectDescription()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicProjectHelpFile()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicLanguageDLL()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicBackupLanguageDLL()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicLanguageDLLPrimaryLCIDStr()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicLanguageDLLSecondaryLCIDStr()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicProjectPrimaryLCIDStr()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicProjectSecondaryLCIDStr()));
info.push_back(replaceNonprintableChars(fileinfo.getVisualBasicTypeLibLCIDStr()));
info.push_back((fileinfo.getVisualBasicIsPcode()) ? "Yes" : "No");

// isPcode
// getLanguageDLL
// getBackupLanguageDLL
// getProjectExeName
// getProjectDescription
// getProjectHelpFile
// getProjectName
// getLanguageDLLPrimaryLCID
// getLanguageDLLSecondaryLCID
// getProjectPath
// getProjectPrimaryLCID
// getProjectSecondaryLCID
// getObjects
// getExterns
// getObject
// getExtern
// getNumberOfObjects
// getNumberOfExterns
// getTypeLibCLSID
// getTypeLibLCID

return info.size();
}
Expand Down

0 comments on commit a749f11

Please sign in to comment.