Skip to content

Commit

Permalink
Revert "kptools: add dump iconfig (#140)"
Browse files Browse the repository at this point in the history
This reverts commit 7b0295d.
  • Loading branch information
bmax121 authored Nov 15, 2024
1 parent 7b0295d commit 3c54e6e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 104 deletions.
48 changes: 47 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ jobs:
install: >-
msys/make
msys/gcc
msys/zlib-devel
- name: Copyfile
shell: pwsh
run: |
Expand Down Expand Up @@ -282,6 +281,53 @@ jobs:
allowUpdates: true
replacesArtifacts: true

Build-kptools-windows-llvm:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out
uses: actions/checkout@v3
- name: Install mingw32 cross toolchains
run: |
MINGW_LLVM_URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20231128/llvm-mingw-20231128-msvcrt-ubuntu-20.04-x86_64.tar.xz"
mkdir -p $HOME/mingw-llvm
wget $MINGW_LLVM_URL -O $HOME/mingw-llvm/llvm.tar.xz
cd $HOME/mingw-llvm
tar -xvf llvm.tar.xz --strip-components 1
- name: Generate version
id: parse_version
run: |
MAJOR=$(grep '#define MAJOR' version | awk '{print $3}')
MINOR=$(grep '#define MINOR' version | awk '{print $3}')
PATCH=$(grep '#define PATCH' version | awk '{print $3}')
VERSION="$MAJOR.$MINOR.$PATCH"
echo "Generated Version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Build kptools
run: |
export PATH="$HOME/mingw-llvm/bin:$PATH"
export ANDROID=1
ABIS="x86_64 i686 aarch64 armv7"
for i in $ABIS; do
make -C kernel hdr TARGET_COMPILE=placeholder
echo "- Compiling kptools-$i-win.exe"
make -C tools CC=$i-w64-mingw32-clang
mv tools/kptools.exe kptools-$i-win.exe
make -C tools clean
done
7za a kptools-llvm-win.zip -tZIP *.exe
- name: Release
uses: ncipollo/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.parse_version.outputs.VERSION }}
artifacts: |
kptools-llvm-win.zip
allowUpdates: true
replacesArtifacts: true
omitBodyDuringUpdate: true

Build-kptools-mac:
runs-on: macos-latest
permissions:
Expand Down
8 changes: 1 addition & 7 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ set(SOURCES
add_executable(
kptools
${SOURCES}
)

find_package(ZLIB REQUIRED)

target_link_libraries(kptools PRIVATE ${ZLIB_LIBRARIES})

target_include_directories(kptools PRIVATE ${ZLIB_INCLUDE_DIRS})
)
4 changes: 2 additions & 2 deletions tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

CFLAGS = -std=c11 -Wall -Wextra -Wno-unused -Wno-unused-parameter
LDFLAGS = -lz

ifdef DEBUG
CFLAGS += -DDEBUG -g
endif
Expand All @@ -13,7 +13,7 @@ all: kptools

.PHONY: kptools
kptools: ${objs}
${CC} -o $@ $^ $(LDFLAGS)
${CC} -o $@ $^

%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
Expand Down
72 changes: 0 additions & 72 deletions tools/kallsym.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#include "insn.h"
#include "common.h"

#define IKCFG_ST "IKCFG_ST"
#define IKCFG_ED "IKCFG_ED"
#include "zlib.h"

#ifdef _WIN32
#include <string.h>
static void *memmem(const void *haystack, size_t haystack_len, const void *const needle, const size_t needle_len)
Expand Down Expand Up @@ -965,74 +961,6 @@ int dump_all_symbols(kallsym_t *info, char *img)
}
return 0;
}
int decompress_data(const unsigned char *compressed_data, size_t compressed_size) {
FILE *temp = fopen("temp.gz", "wb");
if (!temp) {
fprintf(stderr, "Failed to create temp file\n");
return -1;
}

fwrite(compressed_data, 1, compressed_size, temp);
fclose(temp);

gzFile gz = gzopen("temp.gz", "rb");
if (!gz) {
fprintf(stderr, "Failed to open temp file for decompression\n");
return -1;
}

char buffer[1024];
int bytes_read;
while ((bytes_read = gzread(gz, buffer, sizeof(buffer))) > 0) {
fwrite(buffer, 1, bytes_read, stdout);
}

gzclose(gz);
return 0;
}

int dump_all_ikconfig(char *img, int32_t imglen)
{

char *pos_start = memmem(img, imglen, IKCFG_ST, strlen(IKCFG_ST));
if (pos_start == NULL) {
fprintf(stderr, "Cannot find kernel config start (IKCFG_ST).\n");
return 1;
}
size_t kcfg_start = pos_start - img + 8;

// 查找 "IKCFG_ED"
char *pos_end = memmem(img, imglen, IKCFG_ED, strlen(IKCFG_ED));
if (pos_end == NULL) {
fprintf(stderr, "Cannot find kernel config end (IKCFG_ED).\n");
return 1;
}
size_t kcfg_end = pos_end - img - 1;
size_t kcfg_bytes = kcfg_end - kcfg_start + 1;

printf("Kernel config start: %zu, end: %zu, bytes: %zu\n", kcfg_start, kcfg_end, kcfg_bytes);


unsigned char *extracted_data = (unsigned char *)malloc(kcfg_bytes);
if (!extracted_data) {
fprintf(stderr, "Memory allocation for extracted data failed.\n");
return 1;
}

memcpy(extracted_data, img + kcfg_start, kcfg_bytes);



int ret = decompress_data(extracted_data, kcfg_bytes);




free(extracted_data);


return 0;
}

int on_each_symbol(kallsym_t *info, char *img, void *userdata,
int32_t (*fn)(int32_t index, char type, const char *symbol, int32_t offset, void *userdata))
Expand Down
1 change: 0 additions & 1 deletion tools/kallsym.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ typedef struct

int analyze_kallsym_info(kallsym_t *info, char *img, int32_t imglen, enum arch_type arch, int32_t is_64);
int dump_all_symbols(kallsym_t *info, char *img);
int dump_all_ikconfig(char *img, int32_t imglen);
int get_symbol_index_offset(kallsym_t *info, char *img, int32_t index);
int get_symbol_offset_and_size(kallsym_t *info, char *img, char *symbol, int32_t *size);
int get_symbol_offset(kallsym_t *info, char *img, char *symbol);
Expand Down
8 changes: 2 additions & 6 deletions tools/kptools.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ void print_usage(char **argv)
" -u, --unpatch Unpatch patched kernel image(-i).\n"
" -r, --reset-skey Reset superkey of patched image(-i).\n"
" -d, --dump Dump kallsyms infomations of kernel image(-i).\n"
" -f, --flag Dump ikconfig infomations of kernel image(-i).\n"
" -l, --list Print all patch informations of kernel image if (-i) specified.\n"
" Print extra item informations if (-M) specified.\n"
" Print KernelPatch image informations if (-k) specified.\n"
Expand Down Expand Up @@ -82,7 +81,7 @@ int main(int argc, char *argv[])
{ "unpatch", no_argument, NULL, 'u' },
{ "resetkey", no_argument, NULL, 'r' },
{ "dump", no_argument, NULL, 'd' },
{ "flag", no_argument, NULL, 'f' },

{ "list", no_argument, NULL, 'l' },

{ "image", required_argument, NULL, 'i' },
Expand All @@ -99,7 +98,7 @@ int main(int argc, char *argv[])
{ "extra-event", required_argument, NULL, 'V' },
{ "extra-args", required_argument, NULL, 'A' },
{ 0, 0, 0, 0 } };
char *optstr = "hvpurdfli:s:S:k:o:a:M:E:T:N:V:A:";
char *optstr = "hvpurdli:s:S:k:o:a:M:E:T:N:V:A:";

char *kimg_path = NULL;
char *kpimg_path = NULL;
Expand Down Expand Up @@ -127,7 +126,6 @@ int main(int argc, char *argv[])
case 'u':
case 'r':
case 'd':
case 'f':
case 'l':
cmd = opt;
break;
Expand Down Expand Up @@ -191,8 +189,6 @@ int main(int argc, char *argv[])
extra_config_num);
} else if (cmd == 'd') {
ret = dump_kallsym(kimg_path);
} else if (cmd == 'f') {
ret = dump_ikconfig(kimg_path);
} else if (cmd == 'u') {
ret = unpatch_img(kimg_path, out_path);
} else if (cmd == 'r') {
Expand Down
14 changes: 0 additions & 14 deletions tools/patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,4 @@ int dump_kallsym(const char *kimg_path)
set_log_enable(false);
free_kernel_file(&kernel_file);
return 0;
}
int dump_ikconfig(const char *kimg_path)
{
if (!kimg_path) tools_loge_exit("empty kernel image\n");
set_log_enable(true);
// read image files
kernel_file_t kernel_file;
read_kernel_file(kimg_path, &kernel_file);


dump_all_ikconfig(kernel_file.kimg,kernel_file.kimg_len);
set_log_enable(false);
free_kernel_file(&kernel_file);
return 0;
}
1 change: 0 additions & 1 deletion tools/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ int patch_update_img(const char *kimg_path, const char *kpimg_path, const char *
int unpatch_img(const char *kimg_path, const char *out_path);
int reset_key(const char *kimg_path, const char *out_path, const char *key);
int dump_kallsym(const char *kimg_path);
int dump_ikconfig(const char *kimg_path);

int print_kp_image_info_path(const char *kpimg_path);
int print_image_patch_info(patched_kimg_t *pimg);
Expand Down

0 comments on commit 3c54e6e

Please sign in to comment.