NO

Author Topic: ChatGPT examples  (Read 8535 times)

Offline Vortex

  • Member
  • *
  • Posts: 843
    • http://www.vortex.masmcode.com
Re: ChatGPT examples
« Reply #15 on: April 23, 2023, 01:11:23 PM »
Question : Create a Windows based hello world example with Pelle's macro assembler Poasm.

ChatGPT's output :

Code: [Select]
; Program to print "Hello, World!" to the console in Windows

format PE console
entry start

section '.data' data readable writeable

message db 'Hello, World!', 0

section '.text' code readable executable

start:
    ; Print the message to the console
    push dword -11
    call [GetStdHandle]
    mov dword [handle], eax
    push dword 0
    push dword message
    push dword 13
    push dword [handle]
    call [WriteConsoleA]

    ; Exit the program
    push dword 0
    call [ExitProcess]

section '.idata' import data readable

library kernel32, 'kernel32.dll',\
        user32, 'user32.dll'

import kernel32,\
       ExitProcess, 'ExitProcess',\
       GetStdHandle, 'GetStdHandle',\
       WriteConsoleA, 'WriteConsoleA'

section '.data' data readable writeable

handle dd ?

Naturally, this is the syntax of the Flat Assembler and not Poasm.
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 841
Re: ChatGPT examples
« Reply #16 on: April 26, 2023, 10:44:57 PM »
Google BARD released a pseudo-coder too now .... "Coders can choose from 20+ different coding languages too...."

https://www.tomsguide.com/news/googles-bard-ai-can-now-write-code-heres-how-to-use-it

John Z


Offline Vortex

  • Member
  • *
  • Posts: 843
    • http://www.vortex.masmcode.com
Re: ChatGPT examples
« Reply #17 on: April 27, 2023, 09:19:34 PM »
Quote
Question : What are differences between the macro engines of Masm and Poasm?

Quote
Masm (Microsoft Macro Assembler) and Poasm (Pelle's Macro Assembler) are both macro assemblers that support the x86 architecture. While they are similar in many respects, there are some differences between their macro engines:

Syntax: Masm and Poasm use slightly different syntax for defining and invoking macros. Masm uses the MACRO and ENDM directives to define a macro and the INVOKE directive to invoke it, while Poasm uses the macro and endm directives to define a macro and the invoke directive to invoke it.

Parameter passing: Masm and Poasm handle parameter passing differently. Masm passes parameters using the stack, while Poasm uses registers.

Macro expansion: Masm and Poasm expand macros differently. Masm expands macros recursively, which can lead to excessive code duplication if macros are not written carefully. Poasm expands macros non-recursively, which can result in more efficient code generation.

Error checking: Masm and Poasm perform error checking differently. Masm checks for errors during the expansion phase, while Poasm checks for errors during the assembly phase.

Overall, both Masm and Poasm are powerful macro assemblers that are widely used in the industry. The choice between the two largely depends on personal preference and specific project requirements.

ChatGPT is serioulsy confused here.
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 841
Re: ChatGPT examples
« Reply #18 on: August 09, 2023, 01:28:28 AM »
More test results
https://www.theregister.com/2023/08/07/chatgpt_stack_overflow_ai/

“ ChatGPT, OpenAI's fabulating chatbot, produces wrong answers to software programming questions more than half the time, according to a study from Purdue University. That said, the bot was convincing enough to fool a third of participants.”


John Z


Offline Vortex

  • Member
  • *
  • Posts: 843
    • http://www.vortex.masmcode.com
Re: ChatGPT examples
« Reply #19 on: August 09, 2023, 03:26:00 PM »
Hi John,

The incorrect results are not unexpected. ChatGPT and similar tools will evolve and we will get no perfect but better results.
Code it... That's all...

Offline KunJohn

  • Member
  • *
  • Posts: 3
Re: ChatGPT examples
« Reply #20 on: September 23, 2023, 02:25:10 PM »
I read somewhere recently that AI already uses probably 9 programming languages..but integrating AI software into an already diverse business environment requires the use of a range of programming tools, such as several languages, frameworks and libraries. These technologies often require extraordinary competence and expertise.

Offline Vortex

  • Member
  • *
  • Posts: 843
    • http://www.vortex.masmcode.com
Re: ChatGPT examples
« Reply #21 on: September 23, 2023, 08:56:37 PM »
Hi KunJohn,

Welcome to Pelles C forum.

I agree with you. The artificial intelligence is powered by big compainies investing a lot of efforts and money. Time will help to improve the quality of the code written by the artificial intelligence.
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 841
Re: ChatGPT examples
« Reply #22 on: November 18, 2023, 11:19:18 AM »
Windows 10 aficionados rejoice.

https://arstechnica.com/gadgets/2023/11/microsoft-is-revisiting-windows-10-by-backporting-the-copilot-ai-assistant/

https://www.theregister.com/2023/11/17/microsoft_to_bring_copilot_to/

CoPilot - MS ChatGPT coming to windows 10.

It just showed up on my Win11 this week.  Runs from a taskbar icon and opens a chat windows.  Says it can program something for me  ;)


John Z 

Offline Vortex

  • Member
  • *
  • Posts: 843
    • http://www.vortex.masmcode.com
Re: ChatGPT examples
« Reply #23 on: November 18, 2023, 06:47:15 PM »
Another funny "assumption" of ChatGPT :

Code: [Select]
    // Enumerate exports
    FARPROC* pFunctions;
    DWORD numberOfFunctions = 0;
    pFunctions = NULL;

    // Get the number of functions in the DLL
    numberOfFunctions = (DWORD)GetProcAddress(hModule, NULL);
    if (numberOfFunctions == 0) {
        fprintf(stderr, "Failed to get the number of functions in the DLL.\n");
        fclose(outputFile);
        FreeLibrary(hModule);
        return;
    }

GetProcAddress(hModule, NULL) does not return the number of functions exported by a DLL.
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 841
Re: ChatGPT examples
« Reply #24 on: November 18, 2023, 11:19:41 PM »
M$S CoPilot:
"write a function in WIN 64 C to return the number of functions exported by a DLL"
Answer:
Code: [Select]
Here is a sample C function that returns the number of functions exported by a DLL in Windows 64-bit:

```c
#include <windows.h>

int get_exported_functions_count(char* dll_path) {
    HMODULE hModule = LoadLibrary(dll_path);
    if (hModule == NULL) {
        return -1;
    }
    int count = 0;
    PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)hModule;
    PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS)((char*)hModule + dosHeader->e_lfanew);
    PIMAGE_EXPORT_DIRECTORY exportDir = (PIMAGE_EXPORT_DIRECTORY)((char*)hModule + ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
    DWORD* functions = (DWORD*)((char*)hModule + exportDir->AddressOfFunctions);
    for (int i = 0; i < exportDir->NumberOfFunctions; i++) {
        if (functions[i] != 0) {
            count++;
        }
    }
    FreeLibrary(hModule);
    return count;
}

here is how it says it works:
Code: [Select]
This function takes the path of the DLL as an argument and returns the number of functions
exported by the DLL. It uses the `LoadLibrary` function to load the DLL into memory, and
then it extracts the export directory from the DLL's PE header. Finally, it counts the number
of non-zero function addresses in the export directory to determine the number of exported functions.

Haven't tried it yet  :)

John Z

Offline Vortex

  • Member
  • *
  • Posts: 843
    • http://www.vortex.masmcode.com
Re: ChatGPT examples
« Reply #25 on: November 19, 2023, 10:58:54 AM »
Hi John,

Thanks, your code works fine :

Code: [Select]
#include <windows.h>
#include <stdio.h>

// Source :
// https://forum.pellesc.de/index.php?topic=10825.msg38689#msg38689

int get_exported_functions_count(char* dll_path) {

    HMODULE hModule = LoadLibrary(dll_path);
    if (hModule == NULL) {
        return -1;
    }

    int count = 0;
    PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)hModule;
    PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS)((char*)hModule + dosHeader->e_lfanew);
    PIMAGE_EXPORT_DIRECTORY exportDir = (PIMAGE_EXPORT_DIRECTORY)((char*)hModule + ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
    DWORD* functions = (DWORD*)((char*)hModule + exportDir->AddressOfFunctions);

    for (unsigned int i = 0; i < exportDir->NumberOfFunctions; i++) {
        if (functions[i] != 0) {
            count++;
        }
    }
    FreeLibrary(hModule);
    return count;
}

int main(void) {
 
char *dll="kernel32.dll";
printf("%s exports %u functions.\n",dll,get_exported_functions_count(dll));

    return 0;
}
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2098
Re: ChatGPT examples
« Reply #26 on: November 19, 2023, 11:08:10 AM »
This avoid some problems.
Code: [Select]
HMODULE hModule = LoadLibraryEx(dll_path, NULL, LOAD_LIBRARY_AS_DATAFILE);
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 843
    • http://www.vortex.masmcode.com
Re: ChatGPT examples
« Reply #27 on: November 19, 2023, 11:26:02 AM »
Hi Timo,

Your suggestion works fine :

Code: [Select]
// HMODULE hModule = LoadLibrary(dll_path);
   HMODULE hModule = LoadLibraryEx(dll_path, NULL, LOAD_LIBRARY_AS_DATAFILE);
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 841
Re: ChatGPT examples
« Reply #28 on: November 19, 2023, 12:35:50 PM »
Hi John,

Thanks, your CoPilot code works fine :
Thanks for testing it Vortex! Amazing to me, very creditable code ....here are what CoPilot reported as references
Code: [Select]
Source: Conversation with Bing, 11/18/2023
(1) Exporting functions from a DLL with dllexport - Stack Overflow. https://stackoverflow.com/questions/538134/exporting-functions-from-a-dll-with-dllexport.
(2) Return function pointer of DLL functions - CodeProject. https://www.codeproject.com/questions/564590/returnplusfunctionpluspointerplusofplusdllplusfunc.
(3) How to call exported function from dll in C/C++? - Stack Overflow. https://stackoverflow.com/questions/10972499/how-to-call-exported-function-from-dll-in-c-c.
(4) How to get Functions exported from a dll file. https://social.msdn.microsoft.com/Forums/en-US/6490b46f-909f-43b0-9cb9-220d0b4812fc/how-to-get-functions-exported-from-a-dll-file?forum=vbinterop.
(5) c++ - x64 DLL export function names - Stack Overflow. https://stackoverflow.com/questions/28062446/x64-dll-export-function-names.
I haven't yet checked if any are an exact match, going to do that today.
Update:  None of the references show to be a direct source to copy code into the answer . . .

This avoid some problems.

Thanks TimoVJL - always good to be better and avoid issues   :)

John Z
« Last Edit: November 19, 2023, 12:51:43 PM by John Z »

Offline Vortex

  • Member
  • *
  • Posts: 843
    • http://www.vortex.masmcode.com
Re: ChatGPT examples
« Reply #29 on: December 01, 2023, 02:16:14 PM »
This time, I received a better answer regarding my simple console application :

Code: [Select]
; hello.asm - Hello, World! example for Poasm (Console Application)

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\kernel32.lib

.data
HelloWorld db 'Hello, World!',0

.code
start:
    ; Get the standard output handle
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov    ebx, eax

    ; Write the "Hello, World!" string to the console
    invoke WriteConsole, ebx, addr HelloWorld, sizeof HelloWorld - 1, 0, 0, 0

    ; Exit the program
    invoke ExitProcess, 0
end start

Code it... That's all...