Skip to content

Commit 166a2d8

Browse files
authored
Merge pull request #64 from Vipon/vkonyche/fix/ubuntu_24.04
Vkonyche/fix/ubuntu 24.04
2 parents 7f57594 + ed86742 commit 166a2d8

File tree

17 files changed

+377
-546
lines changed

17 files changed

+377
-546
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ jobs:
136136
cpath: ${HOME}/.local/include:${CPATH}
137137
library_path: ${HOME}/.local/lib:${LIBRARY_PATH}
138138
- run: ./setup.sh
139-
- run: chmod 0744 "${HOME}/.local/bin/ninja"
140139
- name: Configure Debug Ninja
141140
run: ./configure --ninja --output ninja
142141
- name: Ninja Build Test Install
@@ -171,6 +170,38 @@ jobs:
171170
with:
172171
name: viponTools_Ubuntu
173172
path: viponTools.tar.gz
173+
ubuntu-2404-32-gmake-release:
174+
runs-on: ubuntu-24.04
175+
steps:
176+
- name: Checkout
177+
uses: actions/checkout@v6
178+
- name: Set Env Variables
179+
uses: ./.github/actions/set_env_var
180+
with:
181+
shell: bash
182+
path: ${HOME}/.local/bin
183+
cpath: ${HOME}/.local/include:${CPATH}
184+
library_path: ${HOME}/.local/lib:${LIBRARY_PATH}
185+
- run: ./setup.sh
186+
- name: Set up 32-bits build env
187+
run: |
188+
sudo dpkg --add-architecture i386
189+
sudo apt update
190+
sudo apt install build-essential gcc-multilib g++-multilib
191+
- name: Configure Gmake Release
192+
run: ./configure --gmake --release --target-platform=i386-linux-gnu --output i386_release
193+
- name: Gmake Build Test Install
194+
uses: ./.github/actions/gmake_build_test_install
195+
with:
196+
shell: bash
197+
working-directory: i386_release
198+
- name: Make Achive
199+
working-directory: i386_release
200+
run: tar -czvf ../viponTools.tar.gz viponTools
201+
- uses: actions/upload-artifact@v4
202+
with:
203+
name: viponTools_Ubuntu_i386
204+
path: viponTools.tar.gz
174205
windows-ninja-debug-static:
175206
runs-on: windows-2025-vs2026
176207
steps:

cTools/libs/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ add_subdirectory(binParse)
3131
add_subdirectory(binPrinter)
3232
add_subdirectory(binDynMod)
3333
if (NOT APPLE)
34-
add_subdirectory(perfAnalysis)
34+
add_subdirectory(perfAnalysis)
3535
endif (NOT APPLE)
3636
add_subdirectory(test)
37-
add_subdirectory(x86_64)
38-
add_subdirectory(arch)
39-
add_subdirectory(mod)
37+
if (NOT "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386")
38+
# !TODO: Need to solve problem with capstone and keystone 32 bits build
39+
add_subdirectory(x86_64)
40+
add_subdirectory(arch)
41+
add_subdirectory(mod)
42+
endif()
4043

cTools/libs/binDynMod/elfDynMod/elf32DynMod.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***
22
* MIT License
33
*
4-
* Copyright (c) 2023 Konychev Valerii
4+
* Copyright (c) 2023-2026 Konychev Valerii
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -48,13 +48,16 @@ void *elf32Hook(const Elf32File *elf32, const char *func, const void *hand)
4848
* shSize - contains the size, in bytes, of the section.
4949
* relpltAmount- amount of Elf32Rel structures in .rela.ptl section.
5050
*/
51-
Elf32Shdr *relplt = elf32GetSectByName(elf32, RELAPLT);
51+
Elf32Shdr *relplt = elf32GetSectByName(elf32, RELPLT);
5252
if (relplt == NULL) {
53-
LOG_ERROR("Cannot get the section " RELAPLT);
53+
LOG_ERROR("Cannot get the section " RELPLT);
5454
return NULL;
5555
}
5656

5757
uint32_t relpltAmount = relplt->sh_size / sizeof(Elf32Rel);
58+
Elf32Sym *hook_sym = elf32GetSymByName(elf32, "elf32Hook");
59+
uint32_t func_original_addr = elf32GetSSymAddr(hook_sym);
60+
uint32_t func_addr_diff = (uint32_t)(size_t)(void*)&elf32Hook - func_original_addr;
5861

5962
/***
6063
* r_info - This member gives both the symbol table index,
@@ -69,14 +72,16 @@ void *elf32Hook(const Elf32File *elf32, const char *func, const void *hand)
6972
*/
7073
void *relAddr = NULL;
7174
uint32_t i = 0;
72-
for (i = 0; i < relpltAmount; ++i)
73-
if (ELF32_R_SYM(elf32->relaplt[i].r_info) == symbolIndex){
74-
// !TODO: need refactor
75-
relAddr = (void*) (size_t)*(uint32_t*) (size_t)elf32->relaplt[i].r_offset;
76-
*(uint32_t*) (size_t)(elf32->relaplt[i].r_offset) = (uint32_t)(uint64_t) hand;
75+
for (i = 0; i < relpltAmount; ++i) {
76+
if (((uint32_t)ELF32_R_SYM(elf32->relplt[i].r_info)) == symbolIndex) {
77+
uint32_t offset = elf32->relplt[i].r_offset;
78+
uint32_t* addr = (uint32_t*)(size_t)(func_addr_diff + offset);
79+
relAddr = (void*)(size_t) *addr;
80+
*addr = (uint32_t)(size_t) hand;
7781

7882
return relAddr;
7983
}
84+
}
8085

8186
return NULL;
8287
}

cTools/libs/binDynMod/elfDynMod/elf64DynMod.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***
22
* MIT License
33
*
4-
* Copyright (c) 2023 Konychev Valerii
4+
* Copyright (c) 2023-2026 Konychev Valerii
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -55,6 +55,9 @@ void *elf64Hook(const Elf64File *elf64, const char *func, const void *hand)
5555
}
5656

5757
uint64_t relpltAmount = relplt->sh_size / sizeof(Elf64Rel);
58+
Elf64Sym *hook_sym = elf64GetSymByName(elf64, "elf64Hook");
59+
uint64_t func_original_addr = elf64GetSSymAddr(hook_sym);
60+
uint64_t func_addr_diff = (uint64_t)&elf64Hook - func_original_addr;
5861

5962
/***
6063
* r_info - This member gives both the symbol table index,
@@ -71,8 +74,10 @@ void *elf64Hook(const Elf64File *elf64, const char *func, const void *hand)
7174
uint64_t i = 0;
7275
for (i = 0; i < relpltAmount; ++i)
7376
if (ELF64_R_SYM(elf64->relaplt[i].r_info) == symbolIndex){
74-
relAddr = (void*) *(uint64_t*) elf64->relaplt[i].r_offset;
75-
*(uint64_t*) (elf64->relaplt[i].r_offset) = (uint64_t) hand;
77+
uint64_t offset = elf64->relaplt[i].r_offset;
78+
uint64_t* addr = (uint64_t*)(func_addr_diff + offset);
79+
relAddr = (void*) *addr;
80+
*addr = (uint64_t) hand;
7681

7782
return relAddr;
7883
}

0 commit comments

Comments
 (0)