mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-20 20:23:57 +00:00
Move samples into subdirectory
This commit is contained in:
12
src/samples/bad-sample/CMakeLists.txt
Normal file
12
src/samples/bad-sample/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
|
||||
*.cpp
|
||||
*.hpp
|
||||
*.rc
|
||||
)
|
||||
|
||||
list(SORT SRC_FILES)
|
||||
|
||||
add_executable(bad-sample ${SRC_FILES})
|
||||
target_link_libraries(bad-sample PRIVATE emulator-common)
|
||||
|
||||
momo_assign_source_group(${SRC_FILES})
|
||||
63
src/samples/bad-sample/bad.cpp
Normal file
63
src/samples/bad-sample/bad.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <platform/compiler.hpp>
|
||||
|
||||
#define THE_SIZE 30
|
||||
|
||||
extern "C" NO_INLINE EXPORT_SYMBOL void vulnerable(const uint8_t* data, const size_t size)
|
||||
{
|
||||
if (size < 10)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (data[9] != 'A')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (data[8] != 'B')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (data[7] != 'C')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (data[2] != 'V')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (data[4] != 'H')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (size < 100)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
*(int*)1 = 1;
|
||||
}
|
||||
|
||||
uint8_t buffer[THE_SIZE] = {};
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
const void* input = buffer;
|
||||
auto size = sizeof(buffer);
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
input = argv[1];
|
||||
size = strlen(argv[1]);
|
||||
}
|
||||
|
||||
vulnerable((uint8_t*)input, size);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user