Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
cmake_minimum_required(VERSION 2.8.4)

if (WIN32 OR APPLE)
message(FATAL_ERROR "Windows or Mac OSX is not supported")
endif (WIN32 OR APPLE)

project(linux_manual_map)

set(SOURCE_FILES main.cpp FileSystem.cpp Handle.cpp Loader.cpp Region.cpp Module.cpp Elf.cpp Elf64.cpp Elf32.cpp)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})

set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)

include_directories("${PROJECT_INCLUDE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}")

set(SOURCE_FILES
${PROJECT_SOURCE_DIR}/src/main.cpp
${PROJECT_SOURCE_DIR}/src/FileSystem.cpp
${PROJECT_SOURCE_DIR}/src/Handle.cpp
${PROJECT_SOURCE_DIR}/src/Loader.cpp
${PROJECT_SOURCE_DIR}/src/Region.cpp
${PROJECT_SOURCE_DIR}/src/Module.cpp
${PROJECT_SOURCE_DIR}/src/Elf.cpp
${PROJECT_SOURCE_DIR}/src/Elf64.cpp
${PROJECT_SOURCE_DIR}/src/Elf32.cpp)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_executable(linux_manual_map ${SOURCE_FILES})
add_executable(linux_manual_map ${SOURCE_FILES})

add_subdirectory(test)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 0 additions & 45 deletions main.cpp

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Handle.cpp → src/Handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ bool remote::WriteProcessMemory(Handle hProcess, void* lpBaseAddress, void* lpBu
*lpNumberOfBytesWritten = (size_t) result;

return (((size_t) result) == nSize);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "main.hpp"

int main(int argc, char **argv) {

if(argc != 2) {
std::cout << "Error: please provide a process id!\n";
return -1;
}

remote::Handle proc = remote::OpenProcess(atoi(argv[1]));

if(!proc.IsRunning()) {
std::cout << "Error: process is not running!\n";
return -1;
}

std::vector<remote::Region> rs = remote::GetRegions(proc.pid);

for(size_t i = 0; i < rs.size(); i++) {
if(!rs[i].filename.empty())
std::cout << "Filename: " << rs[i].filename << std::endl;

if(!rs[i].pathname.empty())
std::cout << "Path: " << rs[i].pathname << std::endl;

std::cout << "Start: " << std::hex << rs[i].start << std::endl;
std::cout << "End: " << std::hex << rs[i].end << std::endl;
std::cout << "Permissions: " << rs[i].read << rs[i].write << rs[i].exec << rs[i].shared << std::endl;
std::cout << "Offset: " << std::hex << rs[i].offset << std::endl;
std::cout << "Device: " << std::dec << rs[i].deviceMajor << ":" << rs[i].deviceMinor << std::endl;
std::cout << "INode: " << std::dec << rs[i].inodeFileNumber << std::endl;
std::cout << "-------------------------------------" << std::endl;
}

return 0;
}
6 changes: 6 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
project(unit_tests)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_executable(dummy dummy.c)
51 changes: 51 additions & 0 deletions test/dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <sys/syscall.h>
#include <sys/types.h>
#if __WORDSIZE == 64
#define LX "%lx"
#define LU "%lu"
#else
#define LX "%x"
#define LU "%u"
#endif

static int counter = 0;
void myfun()
{
printf("%d: I am here in %s on %d\n", counter++,
__func__, __LINE__);
if (counter >= INT32_MAX)
counter = 0;
}

int main()
{
intptr_t here0 = 0;
intptr_t here1 = 0;
const char *str = "Hello World!";
size_t len = strlen(str);
here0 = (intptr_t)syscall(SYS_brk, 0);
here1 = (intptr_t)syscall(SYS_brk, here0 + len + 1);
printf("Starting dummy 0x"LX" 0x"LX"\n", here0, here1);
printf("Dummy pid: %i\n", getpid());
memcpy((void *)here0, str, len + 1);
printf("String: %s\n", (const char *)here0);
syscall(SYS_brk, here0);
while (1) {
struct timeval tv = { 0 };
sleep(2);
gettimeofday(&tv, NULL);
printf("Working "LU"."LU"\n", (size_t)tv.tv_sec, (size_t)tv.tv_usec);
myfun();
}
printf("Stopping dummy\n");
return 0;
}