• XSS.stack #1 – первый литературный журнал от юзеров форума

Portable compiler?

qGodless

(L2) cache
Пользователь
Регистрация
10.07.2022
Сообщения
385
Реакции
106
I want to create an application that provides rawData to PEloader.cpp before it's compiled. I tried TinyCC, but I believe there might be a more efficient approach. Can you suggest a better alternative?

I also tried reading rawData from a file on disk, but i belive i have to deliver the file with the PEloader

C:
unsigned char rawData[64] = {
    0x68, 0x65, 0x6D, 0x61, 0x73, 0x2D, 0x6D, 0x69, 0x63, 0x72, 0x6F, 0x73,
    0x6F, 0x66, 0x74, 0x2D, 0x63, 0x6F, 0x6D, 0x3A, 0x61, 0x73, 0x6D, 0x2E
};

void Inject()
{
    //Deobfuscate rawData if obfuscated
    void* imageBuffer = rawData();

    IMAGE_NT_HEADERS64* ntHeaders;
    IMAGE_SECTION_HEADER* sectionHeader;
    IMAGE_DOS_HEADER* dosHeader;
    ...
}
 
Clang can run in portable mode, but you will need windows sdk anyway. Anyway, you have a lot of different approaches. File overlay/resources/adding new PE section and so on
I don't fully understand, can you provide more info or articles in or out the forum
 
INCBIN macros is a good option for the thing you are trying to do: https://github.com/graphitemaster/incbin
Second this. Just a directive: .incbin, no CLI tools required. Quite popular in CTFs.
BUT qGodless, if you want to be faithful to your beloved MSVC... inline assembly... sad.
You need GNU-compatible toolchains. For small scale piddly ass stuff, quite practical. That's why it's quite popular with CTFs. weaver
There are the usual hacks like generating static C arrays (using xxd or whatever) if portability is a concern but generating megabytes of code is not beauteous, obviously.
And with INCBIN, the data often ends up in a section determined by the assembler/linker (.rodata or .data).


But the actual bombshell (sort of, if you are down for C23):
C:
#embed "dat.bin" as bin;



This should be the way. Embedding binary data should be a fundamental feature of the language, not delegated to assembler directives or external tools.
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх