-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add COM cmd to load MS-DOS COM files
Since COM files don't have a header/magic, has a simple memory map, it's best to have it a separate command.
- Loading branch information
1 parent
1c9ad5a
commit 0ebc22a
Showing
6 changed files
with
65 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
deps/ | ||
|
||
/cgc | ||
/com | ||
/fuzz | ||
/imgtrace | ||
/repl | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"github.com/pkg/errors" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/lunixbochs/usercorn/go" | ||
"github.com/lunixbochs/usercorn/go/cmd" | ||
"github.com/lunixbochs/usercorn/go/loader" | ||
"github.com/lunixbochs/usercorn/go/models" | ||
) | ||
|
||
func main() { | ||
c := cmd.NewUsercornRawCmd() | ||
c.NoArgs = true | ||
|
||
c.MakeUsercorn = func(exe string) (models.Usercorn, error) { | ||
p, err := ioutil.ReadFile(exe) | ||
if err != nil { | ||
return nil, err | ||
} | ||
r := bytes.NewReader(p) | ||
l, err := loader.NewComLoader(r) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to load COM file") | ||
} | ||
u, err := usercorn.NewUsercornRaw(l, c.Config) | ||
|
||
// Map in entire 16 bit address space | ||
err = u.MemMapProt(0, 0x10000, 7) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to map in address space") | ||
} | ||
|
||
// Write in each segment's data | ||
segments, err := l.Segments() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get segments from loader") | ||
} | ||
for _, seg := range segments { | ||
data, err := seg.Data() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to read segment data") | ||
} | ||
|
||
err = u.MemWrite(seg.Addr, data) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to write segment data") | ||
} | ||
} | ||
|
||
return u, nil | ||
} | ||
c.Run(os.Args, os.Environ()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters