Python Dll Dosyası Oluşturma

Merhabalar python3 kullanıyorum python üzerinden dll dosyası açılabilirmi acaba yalnız fonksiyonları(işe yarar) olmasını istiyorum python üzerinden dll dosyası açma ve düzenleme mümkün mü yardımcı olabilecek olur ise sevinirim

Merhaba,

Aşağıdaki başlıkları bir inceleyin isterseniz.

Çok teşekkürler iyi zaman’lar.

birazcık hort olacak fakat bir şey sormak istiyorum. İnternette araştırdım fakat tam anlayamadım açıklayan birileri olursa çok sevinirim :slight_smile:

1- dll dosyaları anladığım kadarı ile fonksiyon dosyaları ile benzer mantıkta çalışıyor. bizim python’da tanımladığımız fonksiyonlardan farklı bir görevdemi çalışıyor ?

2- python da programladığımız bir programda dll dosyalarına ne zaman ihtiyacımız olur ?

3- .dll dosyalarının dili sadece c c# dilleri midir ?

Bu konuda bilgili olan arkadaşların eklemek istedikleri bilgiler varsa veya bu mesajda düzeltilmesi gereken kısımlar varsa bunları paylaşmaları yararlı olur.

DLL dosyalarında bir takım kodlar veya veri yapıları bulunur.

Mesela aşağıdaki gibi ismi test.c olan bir dosyanız vardır:

int add(int x, int y){
    return x + y;
}

Bu kodları gcc ile aşağıda gösterildiği gibi derleyerek DLL dosyası oluşturursunuz.

gcc -shared -Wl,-soname,adder -o test.dll -fPIC test.c

Daha sonra bu dll dosyasını ctypes modülü ile Python programınıza aktarabilirsiniz.

from ctypes import CDLL

kutuphane = CDLL("./test.dll")
print(kutuphane.add(1, 2))

Python ile programladığınız bir programda başka bir dilde yazılmış bir programı kullanmak istediğinizde DLL dosyalarına ihtiyaç duyarsınız. Genelde C ve C++ dilleriyle yazılan programların kodlarını ve/veya verilerini tutarlar.

DLL’nin Avantajları:

Advantages of DLL

Given below are a few advantages of having DLL files.

Uses fewer resources

DLL files don’t get loaded into the RAM together with the main program; they don’t occupy space unless required. When a DLL file is needed, it is loaded and run. For example, as long as a user of Microsoft Word is editing a document, the printer DLL file is not required in RAM. If the user decides to print the document, then the Word application causes the printer DLL file to be loaded and run.

Promotes modular architecture

A DLL helps promote developing modular programs. It helps you develop large programs that require multiple language versions or a program that requires modular architecture. An example of a modular program is an accounting program having many modules that can be dynamically loaded at run-time.

Aid easy deployment and installation

When a function within a DLL needs an update or a fix, the deployment and installation of the DLL does not require the program to be relinked with the DLL. Additionally, if multiple programs use the same DLL, then all of them get benefited from the update or the fix. This issue may occur more frequently when you use a third-party DLL that is regularly updated or fixed.

Applications and DLLs can link to other DLLs automatically, if the DLL linkage is specified in the IMPORTS section of the module definition file as a part of the compile. Else, you can explicitly load them using the Windows LoadLibrary function.

Kaynak: DLL - Introduction

1 Beğeni

cevabınız için teşekkür ederim. peki bir .dll dosyasının içinde ki fonksiyonların neler olduğunu nasıl anlayabiliriz ? kullanmadan önce içeriğine nasıl göz atıp ona göre kullanmam gerekir ?

Bunu doğrudan ctypes kullanarak yapma şansımız yok sanırım. Ama DLL’nin içeriğine farklı bir yöntemle bakabiliriz. Bu arada aşağıdaki yöntem Windows’ta mingw olduğu sürece geçerlidir.

test.c dosyasını şu şekilde düzenledim:

int func1(int a, int b){
	return a + b;
}

int func2(int a, int b){
	return a - b;
}

test.dll dosyası oluşturulduktan sonra aşağıdaki Python dosyasını çalıştırıyorum:

from subprocess import Popen, PIPE

print(
    Popen(
        args="nm ./test.dll", 
        shell=True, 
        stdout=PIPE
    ).communicate()[0].decode("utf-8")
)

Windows için aldığım çıktı şöyle oldu:

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7900 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7900 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7600 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7000 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec75e0 b .bss

000000006bec7020 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7020 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec75d0 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7020 b .bss

000000006bec75d0 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7030 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec75c0 b .bss

000000006bec78a0 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006bec7040 b .bss

000000006bec7910 b .bss

000000006bec7910 b .bss

000000006beca000 d .CRT$XCA

000000006beca008 d .CRT$XCZ

000000006beca048 d .CRT$XDA

000000006beca050 d .CRT$XDZ

000000006beca010 d .CRT$XIA

000000006beca018 d .CRT$XIAA

000000006beca020 d .CRT$XIZ

000000006beca028 d .CRT$XLA

000000006beca030 d .CRT$XLC

000000006beca038 d .CRT$XLD

000000006beca040 d .CRT$XLZ

000000006bec2a78 t .ctors.65535

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3010 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3020 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3020 d .data

000000006bec3030 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3020 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3000 d .data

000000006bec3030 d .data

000000006bec3020 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3000 d .data

000000006bec3060 d .data

000000006bec3050 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3030 d .data

000000006bec3030 d .data

000000006bec3020 d .data

000000006bec3000 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3030 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3030 d .data

000000006bec3000 d .data

000000006bec3020 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3030 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3030 d .data

000000006bec3060 d .data

000000006bec3020 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3060 d .data

000000006bec3020 d .data

000000006bec3060 d .data

000000006bec3060 d .data$__security_cookie

000000006bec3070 d .data$__security_cookie_complement

000000006bed0000 N .debug_abbrev

000000006bed0014 N .debug_abbrev

000000006becd000 N .debug_aranges

000000006becd030 N .debug_aranges

000000006bed2000 N .debug_frame

000000006bece000 N .debug_info

000000006bece02e N .debug_info

000000006bed1000 N .debug_line

000000006bed107b N .debug_line

000000006bed3000 N .debug_str

000000006bec9014 i .idata$2

000000006bec9000 i .idata$2

000000006bec903c i .idata$4

000000006bec914c i .idata$4

000000006bec9124 i .idata$4

000000006bec9104 i .idata$4

000000006bec90b4 i .idata$4

000000006bec9084 i .idata$4

000000006bec90dc i .idata$4

000000006bec9154 i .idata$4

000000006bec9044 i .idata$4

000000006bec9164 i .idata$4

000000006bec9114 i .idata$4

000000006bec90f4 i .idata$4

000000006bec9144 i .idata$4

000000006bec9074 i .idata$4

000000006bec915c i .idata$4

000000006bec906c i .idata$4

000000006bec9094 i .idata$4

000000006bec909c i .idata$4

000000006bec903c i .idata$4

000000006bec90bc i .idata$4

000000006bec90ac i .idata$4

000000006bec90f4 i .idata$4

000000006bec90cc i .idata$4

000000006bec908c i .idata$4

000000006bec912c i .idata$4

000000006bec913c i .idata$4

000000006bec910c i .idata$4

000000006bec9064 i .idata$4

000000006bec907c i .idata$4

000000006bec90a4 i .idata$4

000000006bec9134 i .idata$4

000000006bec90d4 i .idata$4

000000006bec9054 i .idata$4

000000006bec90e4 i .idata$4

000000006bec90c4 i .idata$4

000000006bec905c i .idata$4

000000006bec90fc i .idata$4

000000006bec904c i .idata$4

000000006bec911c i .idata$4

000000006bec90ec i .idata$4

000000006bec9184 i .idata$5

000000006bec9224 i .idata$5

000000006bec91f4 i .idata$5

000000006bec9194 i .idata$5

000000006bec924c i .idata$5

000000006bec926c i .idata$5

000000006bec91ec i .idata$5

000000006bec917c i .idata$5

000000006bec928c i .idata$5

000000006bec919c i .idata$5

000000006bec91a4 i .idata$5

000000006bec9214 i .idata$5

000000006bec9174 i .idata$5

000000006bec9234 i .idata$5

000000006bec91ac i .idata$5

000000006bec9284 i .idata$5

000000006bec91e4 i .idata$5

000000006bec91b4 i .idata$5

000000006bec9294 i .idata$5

000000006bec9244 i .idata$5

000000006bec916c i .idata$5

000000006bec9254 i .idata$5

000000006bec927c i .idata$5

000000006bec923c i .idata$5

000000006bec920c i .idata$5

000000006bec91dc i .idata$5

000000006bec91bc i .idata$5

000000006bec91c4 i .idata$5

000000006bec9204 i .idata$5

000000006bec9274 i .idata$5

000000006bec91d4 i .idata$5

000000006bec925c i .idata$5

000000006bec91cc i .idata$5

000000006bec916c i .idata$5

000000006bec918c i .idata$5

000000006bec921c i .idata$5

000000006bec9264 i .idata$5

000000006bec922c i .idata$5

000000006bec9224 i .idata$5

000000006bec91fc i .idata$5

000000006bec94c6 i .idata$6

000000006bec929c i .idata$6

000000006bec92b4 i .idata$6

000000006bec94da i .idata$6

000000006bec92cc i .idata$6

000000006bec94be i .idata$6

000000006bec94d0 i .idata$6

000000006bec9426 i .idata$6

000000006bec94e4 i .idata$6

000000006bec92e0 i .idata$6

000000006bec92f6 i .idata$6

000000006bec94ee i .idata$6

000000006bec94b4 i .idata$6

000000006bec930c i .idata$6

000000006bec94f8 i .idata$6

000000006bec931c i .idata$6

000000006bec9472 i .idata$6

000000006bec9462 i .idata$6

000000006bec9412 i .idata$6

000000006bec94ac i .idata$6

000000006bec949a i .idata$6

000000006bec9336 i .idata$6

000000006bec940a i .idata$6

000000006bec9346 i .idata$6

000000006bec9362 i .idata$6

000000006bec93ec i .idata$6

000000006bec948e i .idata$6

000000006bec9434 i .idata$6

000000006bec93d8 i .idata$6

000000006bec9450 i .idata$6

000000006bec937a i .idata$6

000000006bec93be i .idata$6

000000006bec9394 i .idata$6

000000006bec9480 i .idata$6

000000006bec93aa i .idata$6

000000006bec94a2 i .idata$6

000000006bec9550 i .idata$7

000000006bec956c i .idata$7

000000006bec9534 i .idata$7

000000006bec952c i .idata$7

000000006bec9570 i .idata$7

000000006bec9528 i .idata$7

000000006bec9538 i .idata$7

000000006bec9540 i .idata$7

000000006bec9524 i .idata$7

000000006bec9574 i .idata$7

000000006bec9554 i .idata$7

000000006bec9578 i .idata$7

000000006bec9520 i .idata$7

000000006bec9544 i .idata$7

000000006bec9548 i .idata$7

000000006bec951c i .idata$7

000000006bec9580 i .idata$7

000000006bec95a0 i .idata$7

000000006bec9518 i .idata$7

000000006bec959c i .idata$7

000000006bec9514 i .idata$7

000000006bec9598 i .idata$7

000000006bec9510 i .idata$7

000000006bec9590 i .idata$7

000000006bec9584 i .idata$7

000000006bec950c i .idata$7

000000006bec954c i .idata$7

000000006bec9594 i .idata$7

000000006bec9508 i .idata$7

000000006bec9588 i .idata$7

000000006bec957c i .idata$7

000000006bec9504 i .idata$7

000000006bec958c i .idata$7

000000006bec9530 i .idata$7

000000006bec9558 i .idata$7

000000006bec955c i .idata$7

000000006bec953c i .idata$7

000000006bec95a4 i .idata$7

000000006bec51f8 p .pdata

000000006bec51ec p .pdata

000000006bec51e0 p .pdata

000000006bec51d4 p .pdata

000000006bec515c p .pdata

000000006bec512c p .pdata

000000006bec5108 p .pdata

000000006bec50f0 p .pdata

000000006bec50cc p .pdata

000000006bec50a8 p .pdata

000000006bec5090 p .pdata

000000006bec506c p .pdata

000000006bec5054 p .pdata

000000006bec503c p .pdata

000000006bec5000 p .pdata

000000006bec521c p .pdata

000000006bec5228 p .pdata.startup

000000006bec50e4 p .pdata.unlikely

000000006bec4000 r .rdata

000000006bec4020 r .rdata

000000006bec4080 r .rdata

000000006bec4190 r .rdata

000000006bec41b0 r .rdata$.refptr.__CTOR_LIST__

000000006bec41e0 r .rdata$.refptr.__dyn_tls_init_callback

000000006bec41f0 r .rdata$.refptr.__image_base__

000000006bec4200 r .rdata$.refptr.__native_dllmain_reason

000000006bec4210 r .rdata$.refptr.__native_startup_lock

000000006bec4220 r .rdata$.refptr.__native_startup_state

000000006bec41d0 r .rdata$.refptr.__RUNTIME_PSEUDO_RELOC_LIST__

000000006bec41c0 r .rdata$.refptr.__RUNTIME_PSEUDO_RELOC_LIST_END__

000000006bec4230 r .rdata$.refptr.__xc_a

000000006bec4240 r .rdata$.refptr.__xc_z

000000006bec4250 r .rdata$.refptr.__xi_a

000000006bec4260 r .rdata$.refptr.__xi_z

000000006bec41a0 r .rdata$.refptr._CRT_MT

000000006bec4270 r .rdata$.refptr.mingw_app_type

000000006bec4280 r .rdata$zzz

000000006bec41b0 R .refptr.__CTOR_LIST__

000000006bec41e0 R .refptr.__dyn_tls_init_callback

000000006bec41f0 R .refptr.__image_base__

000000006bec4200 R .refptr.__native_dllmain_reason

000000006bec4210 R .refptr.__native_startup_lock

000000006bec4220 R .refptr.__native_startup_state

000000006bec41d0 R .refptr.__RUNTIME_PSEUDO_RELOC_LIST__

000000006bec41c0 R .refptr.__RUNTIME_PSEUDO_RELOC_LIST_END__

000000006bec4230 R .refptr.__xc_a

000000006bec4240 R .refptr.__xc_z

000000006bec4250 R .refptr.__xi_a

000000006bec4260 R .refptr.__xi_z

000000006bec41a0 R .refptr._CRT_MT

000000006bec4270 R .refptr.mingw_app_type

000000006bec2968 t .text

000000006bec2748 t .text

000000006bec2720 t .text

000000006bec2750 t .text

000000006bec2720 t .text

000000006bec26e0 t .text

000000006bec2960 t .text

000000006bec2970 t .text

000000006bec26d0 t .text

000000006bec2758 t .text

000000006bec2730 t .text

000000006bec2760 t .text

000000006bec22f0 t .text

000000006bec2768 t .text

000000006bec2770 t .text

000000006bec2778 t .text

000000006bec29f0 t .text

000000006bec2740 t .text

000000006bec2780 t .text

000000006bec1000 t .text

000000006bec29e8 t .text

000000006bec2980 t .text

000000006bec1390 t .text

000000006bec29f0 t .text

000000006bec13b0 t .text

000000006bec22f0 t .text

000000006bec22f0 t .text

000000006bec29e0 t .text

000000006bec2988 t .text

000000006bec2080 t .text

000000006bec2958 t .text

000000006bec2788 t .text

000000006bec2790 t .text

000000006bec29d8 t .text

000000006bec13e0 t .text

000000006bec2990 t .text

000000006bec14b0 t .text

000000006bec29d0 t .text

000000006bec2950 t .text

000000006bec2900 t .text

000000006bec1c00 t .text

000000006bec14b0 t .text

000000006bec2998 t .text

000000006bec29f0 t .text

000000006bec29c8 t .text

000000006bec2940 t .text

000000006bec2948 t .text

000000006bec29c0 t .text

000000006bec1690 t .text

000000006bec29a0 t .text

000000006bec2920 t .text

000000006bec2920 t .text

000000006bec1750 t .text

000000006bec2928 t .text

000000006bec1770 t .text

000000006bec2930 t .text

000000006bec29a8 t .text

000000006bec2938 t .text

000000006bec2940 t .text

000000006bec29b8 t .text

000000006bec1750 t .text

000000006bec29b0 t .text

000000006bec2978 t .text

000000006bec2a60 t .text.startup

000000006bec29f0 t .text.unlikely

000000006becb000 d .tls

000000006becb008 d .tls$ZZZ

000000006bec6178 r .xdata

000000006bec60f8 r .xdata

000000006bec617c r .xdata

000000006bec6034 r .xdata

000000006bec603c r .xdata

000000006bec609c r .xdata

000000006bec6174 r .xdata

000000006bec60d8 r .xdata

000000006bec6084 r .xdata

000000006bec60b0 r .xdata

000000006bec619c r .xdata

000000006bec6170 r .xdata

000000006bec6064 r .xdata

000000006bec604c r .xdata

000000006bec6000 r .xdata

000000006bec6128 r .xdata

000000006bec61a4 r .xdata.startup

000000006bec60a4 r .xdata.unlikely

000000006bec26e0 T ___chkstk_ms

000000006beca010 D ___crt_xc_end__

000000006beca000 D ___crt_xc_start__

000000006beca028 D ___crt_xi_end__

000000006beca010 D ___crt_xi_start__

000000006beca028 D ___crt_xl_start__

000000006beca048 D ___crt_xp_end__

000000006beca048 D ___crt_xp_start__

000000006beca048 D ___crt_xt_end__

000000006beca048 D ___crt_xt_start__

000000006bec2a70 T ___CTOR_LIST__

000000006bec2a88 T ___DTOR_LIST__

000000006bec42c0 R ___RUNTIME_PSEUDO_RELOC_LIST__

000000006bec42c0 R ___RUNTIME_PSEUDO_RELOC_LIST_END__

000000006becb010 D ___tls_end__

000000006becb000 D ___tls_start__

000000006bec20f0 T ___w64_mingwthr_add_key_dtor

000000006bec2170 T ___w64_mingwthr_remove_key_dtor

000000006bec2900 T __acrt_iob_func

000000006bec7920 B __bss_end__

000000006bec7000 B __bss_start__

000000006bec2a70 T __CTOR_LIST__

000000006bec3080 D __data_end__

000000006bec3000 D __data_start__

0000000000000000 A __dll__

0000000000000000 A __dll_characteristics__

000000006bec1200 t __DllMainCRTStartup

000000006bec1420 T __do_global_ctors

000000006bec13e0 T __do_global_dtors

000000006bec2a88 T __DTOR_LIST__

000000006bec1690 t __dyn_tls_dtor

000000006bec16c0 T __dyn_tls_init

000000006bec4020 R __dyn_tls_init_callback

                 U __end__

0000000000000200 A __file_alignment__

000000006bec13a0 T __gcc_deregister_frame

000000006bec1390 T __gcc_register_frame

000000006bec929c I __IAT_end__

000000006bec916c I __IAT_start__

000000006bec0000 A __image_base__

000000006bec0000 A __ImageBase

000000006bec3050 D __imp___acrt_iob_func

000000006bec9224 I __imp___iob_func

000000006bec922c I __imp__amsg_exit

000000006bec3030 D __imp__execute_onexit_table

000000006bec3040 D __imp__initialize_onexit_table

000000006bec9234 I __imp__initterm

000000006bec923c I __imp__lock

000000006bec3038 D __imp__register_onexit_function

000000006bec9244 I __imp__unlock

000000006bec924c I __imp_abort

000000006bec9254 I __imp_calloc

000000006bec916c I __imp_DeleteCriticalSection

000000006bec9174 I __imp_EnterCriticalSection

000000006bec925c I __imp_free

000000006bec9264 I __imp_fwrite

000000006bec917c I __imp_GetCurrentProcess

000000006bec9184 I __imp_GetCurrentProcessId

000000006bec918c I __imp_GetCurrentThreadId

000000006bec9194 I __imp_GetLastError

000000006bec919c I __imp_GetSystemTimeAsFileTime

000000006bec91a4 I __imp_GetTickCount

000000006bec91ac I __imp_InitializeCriticalSection

000000006bec91b4 I __imp_LeaveCriticalSection

000000006bec91bc I __imp_QueryPerformanceCounter

000000006bec926c I __imp_realloc

000000006bec91c4 I __imp_RtlAddFunctionTable

000000006bec91cc I __imp_RtlCaptureContext

000000006bec91d4 I __imp_RtlLookupFunctionEntry

000000006bec91dc I __imp_RtlVirtualUnwind

000000006bec91e4 I __imp_SetUnhandledExceptionFilter

000000006bec9274 I __imp_signal

000000006bec91ec I __imp_Sleep

000000006bec927c I __imp_strlen

000000006bec9284 I __imp_strncmp

000000006bec91f4 I __imp_TerminateProcess

000000006bec91fc I __imp_TlsGetValue

000000006bec9204 I __imp_UnhandledExceptionFilter

000000006bec928c I __imp_vfprintf

000000006bec920c I __imp_VirtualProtect

000000006bec9214 I __imp_VirtualQuery

000000006bec2938 T __iob_func

000000006bec955c I __lib64_libkernel32_a_iname

000000006bec95a4 I __lib64_libmsvcrt_os_a_iname

0000000000000000 A __loader_flags__

000000006bec1490 T __main

0000000000000000 A __major_image_version__

0000000000000004 A __major_os_version__

0000000000000005 A __major_subsystem_version__

000000006bec2620 T __mingw_enum_import_library_names

000000006bec2490 T __mingw_GetSectionCount

000000006bec2410 T __mingw_GetSectionForAddress

000000006bec1da0 T __mingw_init_ehandler

000000006bec7600 B __mingw_oldexcpt_handler

000000006bec1c00 T __mingw_SEH_error_handler

000000006bec2210 T __mingw_TLScallback

000000006bec78c0 b __mingwthr_cs

000000006bec78a8 b __mingwthr_cs_init

000000006bec2080 t __mingwthr_run_key_dtors.part.0

0000000000000000 A __minor_image_version__

0000000000000000 A __minor_os_version__

0000000000000002 A __minor_subsystem_version__

000000006bec3014 D __native_dllmain_reason

000000006bec7918 B __native_startup_lock

000000006bec7910 B __native_startup_state

000000006bec3010 D __native_vcclrit_reason

000000006bec7018 b __proc_attached

000000006bec29f0 t __report_error

000000006bec1590 T __report_gsfailure

000000006bec42c0 R __rt_psrelocs_end

0000000000000000 A __rt_psrelocs_size

000000006bec42c0 R __rt_psrelocs_start

000000006bec42c0 R __RUNTIME_PSEUDO_RELOC_LIST__

000000006bec42c0 R __RUNTIME_PSEUDO_RELOC_LIST_END__

0000000000001000 A __section_alignment__

000000006bec3060 D __security_cookie

000000006bec3070 D __security_cookie_complement

000000006bec14b0 T __security_init_cookie

0000000000001000 A __size_of_heap_commit__

0000000000100000 A __size_of_heap_reserve__

0000000000001000 A __size_of_stack_commit__

0000000000200000 A __size_of_stack_reserve__

0000000000000003 A __subsystem__

000000006bec1740 T __tlregdtor

000000006bec1770 t __write_memory.part.0

000000006beca000 D __xc_a

000000006beca008 D __xc_z

000000006beca048 d __xd_a

000000006beca050 d __xd_z

000000006beca010 D __xi_a

000000006beca020 D __xi_z

000000006beca028 D __xl_a

000000006beca030 D __xl_c

000000006beca038 D __xl_d

000000006beca040 D __xl_z

000000006bec2788 T _amsg_exit

000000006bec1010 T _CRT_INIT

000000006bec3020 D _CRT_MT

000000006bec1750 T _decode_pointer

000000006bec1760 T _encode_pointer

000000006bec2890 T _execute_onexit_table

000000006bec2330 T _FindPESection

000000006bec2380 T _FindPESectionByName

000000006bec24d0 T _FindPESectionExec

000000006bec26d0 T _fpreset

000000006bec2540 T _GetPEImageBase

000000006bec1e90 T _gnu_exception_handler

000000006bec9000 I _head_lib64_libkernel32_a

000000006bec9014 I _head_lib64_libmsvcrt_os_a

000000006bec2790 T _initialize_onexit_table

000000006bec2780 T _initterm

000000006bec2580 T _IsNonwritableInCurrentImage

000000006bec2930 T _lock

000000006bec1940 T _pei386_runtime_relocator

000000006bec27c0 T _register_onexit_function

000000006becb008 D _tls_end

000000006bec75cc B _tls_index

000000006becb000 D _tls_start

000000006bec4040 R _tls_used

000000006bec2928 T _unlock

000000006bec2310 T _ValidateImageBase

000000006bec22f0 t _ValidateImageBase.part.0

000000006bec2778 T abort

000000006bec1380 T atexit

000000006bec7000 b atexit_table

000000006bec2770 T calloc

000000006bec29e8 T DeleteCriticalSection

000000006bec2720 T DllEntryPoint

000000006bec2730 T DllMain

000000006bec1330 T DllMainCRTStartup

000000006bec7720 b emu_pdata

000000006bec7620 b emu_xdata

000000006bec29e0 T EnterCriticalSection

000000006bec26d0 T fpreset

000000006bec2768 T free

000000006bec9224 i fthunk

000000006bec916c i fthunk

000000006bec13b0 T func1

000000006bec13c4 T func2

000000006bec2760 T fwrite

000000006bec29d8 T GetCurrentProcess

000000006bec29d0 T GetCurrentProcessId

000000006bec29c8 T GetCurrentThreadId

000000006bec29c0 T GetLastError

000000006bec29b8 T GetSystemTimeAsFileTime

000000006bec29b0 T GetTickCount

000000006bec7040 b GS_ContextRecord

000000006bec4000 r GS_ExceptionPointers

000000006bec7520 b GS_ExceptionRecord

000000006bec903c i hname

000000006bec90f4 i hname

000000006bec29a8 T InitializeCriticalSection

000000006bec7020 b initialized

000000006bec78a0 b key_dtor_list

000000006bec29a0 T LeaveCriticalSection

000000006bec75e4 b maxSections

000000006bec75d0 B mingw_app_type

000000006bec75c8 B mingw_initltsdrot_force

000000006bec75c4 B mingw_initltsdyn_force

000000006bec75c0 B mingw_initltssuo_force

000000006bec3000 d p.93846

000000006beca018 D pcinit

000000006bec1000 t pre_c_init

000000006bec2998 T QueryPerformanceCounter

000000006bec2920 T realloc

000000006bec2a60 t register_frame_ctor

000000006bec2990 T RtlAddFunctionTable

000000006bec2988 T RtlCaptureContext

000000006bec2980 T RtlLookupFunctionEntry

000000006bec2978 T RtlVirtualUnwind

000000006bec2970 T SetUnhandledExceptionFilter

000000006bec2758 T signal

000000006bec2968 T Sleep

000000006bec2750 T strlen

000000006bec2748 T strncmp

000000006bec2960 T TerminateProcess

000000006bec75e8 b the_secs

000000006bec2958 T TlsGetValue

000000006bec2950 T UnhandledExceptionFilter

000000006bec2740 T vfprintf

000000006bec2948 T VirtualProtect

000000006bec2940 T VirtualQuery

000000006bec7608 b was_here.95013

000000006bec75e0 b was_init.95174

Yukarıdaki uzun çıktıyı incelerseniz aşağıdaki iki satırın da yer aldığını görürüz.

000000006bec13b0 T func1

000000006bec13c4 T func2

Ubuntu’da aldığım çıktı ise şöyle oldu:

0000000000201020 B __bss_start
0000000000201020 b completed.7697
                 w __cxa_finalize
00000000000004c0 t deregister_tm_clones
0000000000000550 t __do_global_dtors_aux
0000000000200e78 t __do_global_dtors_aux_fini_array_entry
0000000000201018 d __dso_handle
0000000000200e80 d _DYNAMIC
0000000000201020 D _edata
0000000000201028 B _end
00000000000005c0 T _fini
0000000000000590 t frame_dummy
0000000000200e70 t __frame_dummy_init_array_entry
0000000000000690 r __FRAME_END__
000000000000059a T func1
00000000000005ae T func2
0000000000201000 d _GLOBAL_OFFSET_TABLE_
                 w __gmon_start__
00000000000005cc r __GNU_EH_FRAME_HDR
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
0000000000000488 T _init
0000000000000500 t register_tm_clones
0000000000201020 d __TMC_END__

Gördüğünüz gibi Ubuntu’da alınan çıktıda da func1 ve func2'yi görmek mümkün.

1 Beğeni

Bakın mesela aşağıdaki kodlarla, dolaylı bir yoldan da olsa, bir dll dosyasındaki hangi fonksiyonlar Python tarafından kullanılabilir öğrenebilirsiniz.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from ctypes import CDLL
from subprocess import Popen, PIPE

out = Popen(
    args="nm ./test.dll", 
    shell=True, 
    stdout=PIPE
).communicate()[0].decode("utf-8")

attrs = [
    i.split(" ")[-1].replace("\r", "") 
    for i in out.split("\n") if " T " in i
]

functions = [i for i in attrs if hasattr(CDLL("./test.dll"), i)]

print(functions)

Yukarıdaki kodları Ubuntu’da çalıştırdığım zaman şöyle bir çıktı alıyorum. Bu listedekilerin hepsi _FuncPtr sınıfına ait nesneler.

# ['_fini', 'func1', 'func2', '_init']
1 Beğeni

cevabınız için çok teşekkürler. windows’ta minGW kurdum fakat kodları çalıştırdığım zaman “nm” kısmı ile ilgili hata veriyor.

minGW’yi nasıl kurdunuz? İndirdiğiniz minGW klasörü yanılmıyorsam bir rar dosyası içinde olması lazım. Diyelim bu klasörü rardan çıkardınız ve C: dizininin içine attınız. Daha sonra yapmanız gereken minGW’nin bin klasörünü ortam değişkenlerindeki Path'e C:\minGW\bin; şeklinde eklemektir. Bunları yaptınız mı?

Not: Path ortam değişkenine bir programı eklemek için aşağıdaki komutu cmd’ye yazabilirsiniz.

setx PATH %PATH%;C:\minGW\bin;

Ama yukarıdaki yöntem pek önerilen bir yaklaşım değildir. Çünkü Path ortam değişkenine en fazla 1024 karakter yazılabilir. Yani eğer daha önce bilgisayarınıza kurduğunuz programlar Path’e otomatik olarak eklendiyse, Path’e yazılacak karakter sayısı 1024 karakteri geçerse, daha önce Path’e eklenmiş olan yollar kırpılmaya başlanacaktır.

Eğer Path’e manüel olarak ekleme yapmak istiyorsanız, önce ortam değişkenlerini bulmalısınız.
cmd’ye SystemPropertiesAdvanced yazarsanız açılan sayfanın altında ortam değişkenlerini görürsünüz. Daha sonra aşağıda gösterildiği gibi önce Path’e sonra Düzenle seçeneğine tıklayın, minGW’nin bin klasörünü C:\minGW\bin; şeklinde ekleyin.
resim

1 Beğeni

Dediklerinizi aynen yaptım. Path’e de ekledim. dll dosyamı hem bin klasörüne kopyaladım hemde .py ile aynı klasöre kopyaladım. Verdiğiniz kodlarda ki dosya isimlerini değiştirdim.

nm: ./SAP2000v1.dll: no symbols böyle bir hata aldım. SAP2000v1.dll bu benim kullanacağım programın .dll dosyası. Acaba kullandığım .dll dosyasında mı bir sorun var ?

dll dosyanızı bin klasörünün içine kopyalamaya gerek yok. Valla sorun ne şimdilik bilemiyorum, araştıracağım bu konuyu.

Windows için aşağıdaki kodları çalıştırın. Denedim, olumlu sonuç aldım. Diğeri de çalışıyordu ama neden öyle bir sorun verdi anlamadım.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from ctypes import CDLL
from subprocess import Popen, PIPE

out = Popen(
    args="nm ./test.dll", 
    shell=True, 
    stdout=PIPE
).communicate()[0].decode("utf-8")

attrs = [
    i.split(" ")[-1].replace("\r", "") 
    for i in out.split("\n") if " T " in i
]

functions = [i for i in attrs if hasattr(CDLL("./test.dll"), i)]

print(functions)

Aldığım çıktı şu oldu:

['func1', 'func2']
1 Beğeni

kodlarda bir sıkıntı olduğunu düşünmüyorum. Windows kaynaklı bir şey var. Çünkü aynı test.dll dosyasını oluşturdum. Aynı şekilde çalıştırdım pycharm 'de geçerli bir Win32 uygulaması değil diye bir hata çeviriyor.

bin klasörüne .dll dosyasını atmadığım zaman ise dosya bulunamadı diye bir hata çeviriyor. C klasöründe okuma izinlerinde mi sorun oluyor acaba.

Valla sorun neyden kaynaklanıyor bilemiyorum. PyCharm’da da çalıştırdım, aynı çıktıyı aldım. test.py ile test.dll aynı dizindeler ve test.dll'yi minGW’nin bin klasörüne atmadım.
objdump -t ./test.dll ve nm ./test.dll ile de aynı sonuç elde edilebiliyor normalde.

1 Beğeni

Ek bilgi olarak burada durmasında sakınca yoktur diye düşünüyorum. Şu ara üzerinde çalıştığım programı Windows işletim sisteminde deniyorum. Deneme esnasında daha önce ghostscript yüklenmemiş bir bilgisayara ghostscript’i yükledikten sonra ghostscript’in bin ve lib dizinlerini ortam değişkenlerine eklemem gerekti. Ortam değişkenlerine dizin ekleme işlemi için 11 ay önce aşağıdaki kodu paylaşmışım. Ancak bu yönteme alternatif olarak tahmin edebileceğiniz gibi kayıt defterinde değişiklik yaparak da ortam değişkenlerine yeni bir adres eklenebilir.

Alternatif:

import winreg

sub_key = r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
key = winreg.OpenKey(
    winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE),
    sub_key,
    0,
    winreg.KEY_ALL_ACCESS
)
value = winreg.QueryValueEx(key, "Path")
path = "ortam değişkenlerine eklenecek yol"
new_value = value[0] + ";" + path + ";"
winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_value)
1 Beğeni