Author Topic: Help! Questions on opening files withing an Assembly IDE  (Read 670 times)

Mike Anum

  • Regular Member
  • *
  • Posts: 6
Help! Questions on opening files withing an Assembly IDE
« on: May 07, 2017, 04:14:32 AM »
Hi, I have a question, first time in this community BTW. So I want to know how I can execute, load or open a file, or call a file withing a parent process. I'm not sure what terms I'm supposed to use, so please excuse me if I sound confusing. But if anyone can direct me to finding more on how to do something similar to that, I'd appreciate it

Thanks

jj2007

  • Member
  • *****
  • Posts: 7662
  • Assembler is fun ;-)
    • MasmBasic
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #1 on: May 07, 2017, 06:22:23 AM »
Hi Mike,

There are many ways to do that from assembler. What exactly do you need it for?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4887
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #2 on: May 08, 2017, 12:06:00 AM »
Mike, tell us bit more of what you are trying to do, it will give us some idea of how to respond to your question.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Mike Anum

  • Regular Member
  • *
  • Posts: 6
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #3 on: May 08, 2017, 02:37:22 AM »
I'm was trying to figure out how I could execute a program from the cmd line. I learned a little more on how to do that which is to use CREATE PROCESS which requres windows.inc, or masm32rt.inc but I now have linker error from executing it. I think it has to do with with my framework.c file because it executes correctly without it. I looked up the errors 2019 and 2001. It says either my _MainPROC doesn't exist or is duplicated somewhere else. However I my header needs framework.c to create a message box. If you have a work around I'd appreciate it
 see attached files

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4887
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #4 on: May 08, 2017, 04:57:10 AM »
This will build, I annotated what the changes were.

    .686p
    .mmx
    .xmm
    .MODEL FLAT, stdcall
    option casemap:none

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

;;; INCLUDE io.h

.DATA

    PrcName db 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',0
    CmdLine db '/k "echo.&&'
            db 'echo Recover - Recover C:&&'
            db 'echo Wiz [?] - MBRWizard&&'
            db 'echo Exit    - Reboot"',0

        .DATA?

    SUInfo  STARTUPINFO <>
    PrcInfo PROCESS_INFORMATION <>

.CODE

start:              ; <<<<<<<<<< You need a start label

_main   proc

        INVOKE  CreateProcess,ADDR PrcName,ADDR CmdLine,NULL, NULL,NULL,
                NORMAL_PRIORITY_CLASS,NULL,NULL,ADDR SUInfo,ADDR PrcInfo

        INVOKE  ExitProcess,0

_main   endp

        end start   ; <<<<<<<<<< terminate the same label as the start label
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4887
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #5 on: May 08, 2017, 05:11:40 AM »
I have tested it and it runs the version of Google Chrome on my computer. God know what you are trying to do with the command line but you can get it to start a valid URL.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Mike Anum

  • Regular Member
  • *
  • Posts: 6
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #6 on: May 08, 2017, 06:01:06 AM »
Ok, just ran your code, and it didn't help, but it does run. However it only runs without framework.c.
Which is the current problem

So basically, it will run with framework.c if windows.inc isn't included, but then I won't be able to run the cmdline. So if I remove framework.c, it will run but then the user won't be able to input or output strings.

I'm using the cmdline to output images, if executed inconditional statements. I'd figure that it would be the easier option, but taking the easy way out doesn't seem to be working. So maybe, there's a better way to display images without a command prompt... I currently don't know

Please see attachment

jj2007

  • Member
  • *****
  • Posts: 7662
  • Assembler is fun ;-)
    • MasmBasic
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #7 on: May 08, 2017, 08:16:01 AM »
So if I remove framework.c, it will run but then the user won't be able to input or output strings.

You don't need any "framework.c" to input or output strings. There are many alternatives, e.g. crt_printf() and crt_scanf():
Code: [Select]
include \masm32\include\masm32rt.inc

.data?
buffer db 1000 dup(?)

.code
start:
  mov edi, offset buffer
  invoke crt_printf, chr$("Type a string: ")
  invoke crt_scanf, chr$("%s"), edi
  invoke crt_printf, chr$("You typed %s"), edi
  invoke crt__getch
  exit

end start

Btw, the best thing about Visual Crap is that you can disinstall it fairly easily 8)

Mike Anum

  • Regular Member
  • *
  • Posts: 6
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #8 on: May 09, 2017, 12:51:58 AM »
It compiles, but how do you add a message box to it? Help please

jj2007

  • Member
  • *****
  • Posts: 7662
  • Assembler is fun ;-)
    • MasmBasic
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #9 on: May 09, 2017, 01:40:27 AM »
I don't know, maybe MsgBox 0, "Hello World", "I am a title:", MB_OK ? What does the manual say?

Mike Anum

  • Regular Member
  • *
  • Posts: 6
Re: Help! Questions on opening files withing an Assembly IDE
« Reply #10 on: May 09, 2017, 06:59:03 AM »
If found a solution, I just edited my framework.c file to added a function with create process which then ran an exe containing an executable that opens an image from memory. I then edited my io.h headerhe file to executed the c function

Thanks everyone for the help, Cheers  : :biggrin: