Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.cpp
- extern "C" {
- __declspec(dllimport) int __stdcall WriteConsoleW(void* hConsoleOutput, const void *lpBuffer, unsigned int nNumberOfCharsToWrite, unsigned int* lpNumberOfCharsWritten, void* lpReserved);
- }
- int main() {
- WriteConsoleW(nullptr, nullptr, 0, nullptr);
- }
- //API.cpp
- clang::CompilerInstance ci;
- clang::FileSystemOptions fso;
- clang::FileManager fm(fso);
- std::string errors;
- llvm::raw_string_ostream error_stream(errors);
- clang::DiagnosticOptions diagopts;
- clang::TextDiagnosticPrinter printer(error_stream, &diagopts);
- llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagids(new clang::DiagnosticIDs);
- clang::DiagnosticsEngine engine(diagids, &diagopts, &printer, false);
- clang::SourceManager sm(engine, fm);
- clang::LangOptions langopts;
- langopts.CPlusPlus = true;
- langopts.CPlusPlus0x = true;
- clang::TargetOptions target;
- target.Triple = llvm::sys::getDefaultTargetTriple();
- auto targetinfo = clang::TargetInfo::CreateTargetInfo(engine, &target);
- auto headeropts = llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions>(new clang::HeaderSearchOptions());
- clang::HeaderSearch hs(headeropts, fm, engine, langopts, targetinfo);
- auto x = llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions>(new clang::PreprocessorOptions());
- clang::Preprocessor p(x, engine, langopts, targetinfo, sm, hs, ci);
- clang::ASTContext astcon(langopts, sm, targetinfo, p.getIdentifierTable(), p.getSelectorTable(), p.getBuiltinInfo(), 1000);
- clang::ASTConsumer semacons;
- semacons.Initialize(astcon);
- clang::Sema sema(p, astcon, semacons, clang::TranslationUnitKind::TU_Complete);
- sm.createMainFileID(fm.getFile("main.cpp"));
- engine.getClient()->BeginSourceFile(langopts, &p);
- clang::ParseAST(sema);
- engine.getClient()->EndSourceFile();
- auto identinfo = p.getIdentifierInfo("WriteConsoleW");
- auto fileentry = fm.getFile("main.cpp");
- auto fileid = sm.translateFile(fileentry);
- auto sloc = sm.getLocForEndOfFile(fileid);
- clang::LookupResult lr(sema, clang::DeclarationNameInfo(identinfo, sloc), clang::Sema::LookupNameKind::LookupOrdinaryName);
- auto result = sema.LookupName(lr, sema.TUScope);
- if (!result) __debugbreak(); // Fail
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement