Skip to content

Commit 9dbfb5c

Browse files
committed
Documentation Added
1 parent a6e71f1 commit 9dbfb5c

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

src/jni/ElfUtils.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,108 @@
44
#include <elf.h>
55
#include <string>
66

7+
/**
8+
* @brief Holds the ELF File Mapping
9+
*/
710
union ElfPack {
11+
/**
12+
* @brief Pointer to ELF Header
13+
*/
814
Elf32_Ehdr* header;
15+
16+
/**
17+
* @brief Pointer to ELF64 Header
18+
*/
919
Elf64_Ehdr* header64;
20+
21+
/**
22+
* @brief ELF File mapping base address
23+
*/
1024
uintptr_t base;
25+
26+
/**
27+
* @brief Pointer to the ELF Mapping
28+
*/
1129
void* baseV;
30+
31+
/**
32+
* @brief Lazy int version of the Mapping Pointer, to easily do checks
33+
*/
1234
int res;
1335
};
1436

37+
/**
38+
* @brief Initializes the ELF Library, Notify Callback, Cleanup, Frees the ELF library
39+
* @returns true if all the operations was sucessfully, false otherwise
40+
*/
1541
bool ElfOpen(const std::string& fullModulePath, std::function<void(ElfPack libMap)> callback);
42+
43+
/**
44+
* @brief Check if ELF file is 64 bits.
45+
* @returns true if ELF File is 64 bits, false otherwise
46+
*/
1647
bool ElfPeekIs64(const std::string& fullModulePath, bool& outResult);
48+
49+
/**
50+
* @brief Get a ELF Section by its given Index.
51+
* @param sectionIdx: the given section index
52+
* @returns a pointer to a section header if valid, nullptr otherwise
53+
*/
1754
Elf32_Shdr* ElfSectionByIndex(ElfPack libMap, unsigned int sectionIdx);
55+
56+
/**
57+
* @brief Traverses all sections within the ELF File
58+
* @param callback: will be reported, all the given sections
59+
*/
1860
void ElfForEachSection(ElfPack libMap, std::function<bool(Elf32_Shdr* pCurrentSection)> callback);
61+
62+
/**
63+
* @brief Lookup an ELF Section by its given type
64+
* @param sectionType: ELF Section Type
65+
* @returns A pointer to the section if it exists; nullptr otherwise.
66+
*/
1967
Elf32_Shdr* ElfLookupSectionByType(ElfPack libMap, uint32_t sectionType);
68+
69+
/**
70+
* @brief Retrieve the ELF Section Headers Name Blob (shstr) Entry.
71+
* @returns A pointer to the char blob entry if exist; nullptr otherwise
72+
*/
2073
const char* ElfGetSectionHeadersStringBlob(ElfPack libMap);
74+
75+
/**
76+
* @brief Retrieve ELF Section name
77+
* @param sectionHdr: Pointer to ELF Section Header
78+
* @returns A Pointer to the section name if exist; nullptr otherwise.
79+
*/
2180
const char* ElfGetSectionName(ElfPack libMap, Elf32_Shdr* sectionHdr);
81+
82+
/**
83+
* @brief Lookup a ELF Header by its name
84+
* @param sectionName: Name of the section (ex: ".rodata", ".text" ...)
85+
* @returns A Pointer to the ELF Section if found; nullptr otherwise.
86+
*/
2287
Elf32_Shdr* ElfLookupSectionByName(ElfPack libMap, const std::string& sectionName);
88+
89+
/**
90+
* @brief Retrieve any available Symbol Table ELF Section.
91+
* @returns A pointer to the Symbol Table ELF Section if exist; nullptr otherwise;
92+
* @note This function first searches for an SHT_SYMTAB type, and if none is found,
93+
* it searches for an SHT_DYNSYM type.
94+
*/
2395
Elf32_Shdr* ElfGetSymbolSection(ElfPack libMap);
96+
97+
/**
98+
* @brief Traverse the symbol table.
99+
* @param callback: A callback, for each symbol found, this callback will be invocated with the actual symbol & its name.
100+
* @returns true if a symbol table to traverse was found, nullptr otherwise.
101+
*/
24102
bool ElfForEachSymbol(ElfPack libMap, std::function<bool(Elf32_Sym* pCurrentSym, const char* pCurrSymName)> callback);
103+
104+
/**
105+
* @brief Lookup a symbol by its name.
106+
* @param symbolName: The Name of the symbol to look for.
107+
* @param outSymbolOff: (optional) A Pointer to variable where resulting relative displacement of the symbol will be saved if found.
108+
* @returns true if the symbol was found, false otherwise.
109+
* @note Symbol lookup may fail for various reasons, such as the absence of a symbol table or the symbol not being present in the symbol table.
110+
*/
25111
bool ElfLookupSymbol(ElfPack libMap, const std::string& symbolName, uint64_t* outSymbolOff = nullptr);

src/jni/LinuxProcess.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ bool LinuxProcess::LoadToMemoryAndHook(uintptr_t targetSrc, void* targetDst, uin
487487
if(!localDstSize)
488488
return false;
489489

490-
DstAddrinTargetMemory = FindCodeCave(localDstSize, EXECUTE_READ);
490+
DstAddrinTargetMemory = FindCodeCave(localDstSize, PROT_READ);
491491
if(!DstAddrinTargetMemory)
492492
return false;
493493

src/jni/LinuxProcess.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include <vector>
66
#include <sys/mman.h>
77

8+
/**
9+
* @brief Describes a memory segment (ex. a row from the proc/self/maps)
10+
*/
811
struct SegmentInfo{
912
/**
1013
* @brief full segment name, if is present
@@ -33,6 +36,9 @@ struct SegmentInfo{
3336
uintptr_t size;
3437
};
3538

39+
/**
40+
* @brief Describes a linux process
41+
*/
3642
class LinuxProcess
3743
{
3844
private:
@@ -72,7 +78,7 @@ class LinuxProcess
7278
static int FindPid(const char* procName);
7379

7480
/**
75-
* @brief read the memory in target address
81+
* @brief read a T item from target address
7682
*
7783
* @tparam T target object type in target memory
7884
* @param addr it the target address
@@ -91,7 +97,7 @@ class LinuxProcess
9197
uintptr_t FindDMAddy(uintptr_t base, std::vector<uintptr_t> offsets);
9298

9399
/**
94-
* @brief write the memory in target address
100+
* @brief write a T item to given addr in target memory
95101
*
96102
* @tparam T target object type to be writed in target process memory
97103
* @param addr target address in process target memory

0 commit comments

Comments
 (0)