Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zip_open_from_source() & zip_source_buffer_create() not defined in libzip_all.c #64

Open
byt3bl33d3r opened this issue Mar 24, 2021 · 0 comments

Comments

@byt3bl33d3r
Copy link

byt3bl33d3r commented Mar 24, 2021

Heya,

I'm trying to get this library working when cross-compiling to Windows using the MingW toolchain, this is the Nim code i'm using:

import zip/zipfiles
import strformat
import os

const
    pyzip = slurp"../rsrc/python-3.9.1-embed-amd64.zip"
    tmpdir: string = getEnv("LOCALAPPDATA") / "Temp"

proc extractPython(): bool =
    var z: ZipArchive
    z.fromBuffer(pyzip)
    z.extractAll(tmpdir)
    return true

proc main(): void =
    echo fmt"[*] tmpdir: {tmpdir}"
    if extractPython():
        echo fmt"[*] Python extracted"

when isMainModule:
    main()

I compiled zlib v1.2.11 and made it available to MingW using the instructions from here & here

I then ran the following command to cross-compile the above Nim code and point the linker and compiler to the zlib directory:

nim c -d=useLibzipSrc -d=debug -d=mingw --embedsrc=on --hints=on --app=console --cpu=amd64 --passL:"-L/home/byt3bl33d3r/Devel/zlib-1.2.11 -lzlib1" --passC:"-I/home/byt3bl33d3r/Devel/zlib-1.2.11" --out=bin/embed_rsrc_bin_64.exe src/embed_rsrc_bin.nim

This gives the following error when compiled:

Hint: used config file '/usr/local/nim/config/nim.cfg' [Conf]
Hint: used config file '/usr/local/nim/config/config.nims' [Conf]
........................CC: libzip_all
CC: ../../../.nimble/pkgs/zip-#head/zip/libzip.nim
CC: ../../../.nimble/pkgs/zip-#head/zip/zipfiles.nim

Hint:  [Link]
/usr/bin/x86_64-w64-mingw32-ld: /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/@m..@s..@[email protected]@spkgs@szip-@hhead@[email protected]:@m..@s..@[email protected]@spkgs@szip-@hhead@[email protected]:(.text+0x680): undefined reference to `zip_source_buffer_create'
/usr/bin/x86_64-w64-mingw32-ld: /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/@m..@s..@[email protected]@spkgs@szip-@hhead@[email protected]:@m..@s..@[email protected]@spkgs@szip-@hhead@[email protected]:(.text+0x77c): undefined reference to `zip_open_from_source'
collect2: error: ld returned 1 exit status
Error: execution of an external program failed: '/usr/bin/x86_64-w64-mingw32-gcc   -o /home/byt3bl33d3r/Devel/OffensiveNim/bin/embed_rsrc_bin_64.exe  /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/libzip_all.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_assertions.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_widestrs.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_io.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_system.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_streams.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_parseutils.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_unicode.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_strutils.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_dynlib.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_winlean.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_times.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/@m..@s..@[email protected]@spkgs@szip-@hhead@[email protected] /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_pathnorm.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_os.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/@m..@s..@[email protected]@spkgs@szip-@hhead@[email protected] /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/stdlib_strformat.nim.c.o /home/byt3bl33d3r/.cache/nim/embed_rsrc_bin_d/@membed_rsrc_bin.nim.c.o   -L/home/byt3bl33d3r/Devel/zlib-1.2.11 -lzlib1  '

After some investigation libzip.nim has those two functions defined however they're not actually in the libzip_all.c file. It seems like those two functions are only available in libzip starting from version >= 1.0 (the current libzip_all.c file seems to be based off of libzip 0.9?).

I'm not sure If i'm doing something wrong here, but I think that's the problem.

Thanks.

@byt3bl33d3r byt3bl33d3r changed the title "zip_open_from_source" & "zip_source_buffer_create" are not defined when cross-compiling to Windows zip_open_from_source() & zip_source_buffer_create not defined in libzip_all.c Mar 24, 2021
@byt3bl33d3r byt3bl33d3r changed the title zip_open_from_source() & zip_source_buffer_create not defined in libzip_all.c zip_open_from_source() & zip_source_buffer_create() not defined in libzip_all.c Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant