https://github.com/akibhossainomi/tshark-shared-library
Tshark Shared Library From Wireshark Source Code
https://github.com/akibhossainomi/tshark-shared-library
Last synced: 4 months ago
JSON representation
Tshark Shared Library From Wireshark Source Code
- Host: GitHub
- URL: https://github.com/akibhossainomi/tshark-shared-library
- Owner: AkibHossainOmi
- License: gpl-3.0
- Created: 2023-10-06T14:10:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-12T09:25:23.000Z (over 1 year ago)
- Last Synced: 2025-01-07T20:18:20.050Z (5 months ago)
- Language: C
- Size: 516 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Wireshark Build Instruction
* [For Windows](./BUILD.md)
* [For Ubuntu](https://gist.github.com/syneart/2d30c075c140624b1e150c8ea318a978)
# Tshark Shared Library for Windows
* Change the source code of wireshark by following command
```
copy /Y CMakeLists.txt wireshark\CMakeLists.txt
copy /Y tshark.c wireshark\tshark.c
copy /Y tshark.h wireshark\wsutil\tshark.h
copy /Y json_dumper.c wireshark\wsutil\json_dumper.c
copy /Y json_dumper.h wireshark\wsutil\json_dumper.h
```* Clean and Build wireshark solution again
```
msbuild /m /p:Configuration=RelWithDebInfo Wireshark.sln /t:Clean
msbuild /m /p:Configuration=RelWithDebInfo Wireshark.sln
```
# Tshark Shared Library for Ubuntu* Change the source code of wireshark by following command
```
cp -r CMakeLists.txt wireshark/CMakeLists.txt
cp -r tshark.c wireshark/tshark.c
cp -r tshark.h wireshark/wsutil/tshark.h
cp -r json_dumper.c wireshark/wsutil/json_dumper.c
cp -r json_dumper.h wireshark/wsutil/json_dumper.h
```* Build wireshark solution again from Build directory
```
cmake ../
make -j`nproc` && {
echo "\nBuild Success!"
echo "You can find libtshark.so"
echo "at \"`pwd`/run\""
echo "Use the char* Tb_Main(int argc, char *argv[]) function to have the tshark functionalities"
echo "Use void freememory(char* str) function to free the allocated memory"
}
```
# Wireshark: Modifications#### 1. Make changes in `json_dumper.c`
* Declare string, Lens and flag variable.
* Comment the line `fputc(c, dumper->output_file);` in `jd_putc(const json_dumper* dumper, char c)` and add lines to dynamically allocate the string single time and store the characters.
* Comment the line`fputs(s, dumper->output_file);` in `jd_puts(const json_dumper* dumper, const char* s)` and add lines to store the characters.
![]()
* Make a shared function `char* Tb_Return(int f)` to return the string. Here the parameter will be always `1` to return the string.
#### 2. Make changes in `json_dumper.h`
* Define the shared function `char* Tb_Return(int f)` to be called in `tshark.c`
#### 3. Make changes in `tshark.c`
* Rename the function `int main(int argc, char* argv[])` as `char *Tb_Main(int argc, char* argv[])`
* Comment out the line `return exit_status;` in `char *Tb_Main(int argc, char* argv[])`
* In the next line add `return Tb_Return(1);` to return the string.
* Create a main function `int main(int argc, char* argv[])` again and call the `char *Tb_Main(int argc, char* argv[])` inside the main function and don't forget to release the memory.
#### 4. Add a header file called `tshark.h` inside `wsutil` folder
* Declare the `char *Tb_Main(int argc, char* argv[])` function as shared function to be in the shared library.
#### Note: I have added a function as shared function to free the allocated memory too and define it in `tshark.c`
#### 5. Make changes in CMakeLists.txt
* Go to BUILD_tshark section and add the lines to create a shared library of tshark.
![]()