# Is there an API for Apply patched bytes to input file?

**URL:** <https://community.hex-rays.com/t/is-there-an-api-for-apply-patched-bytes-to-input-file/234>\
**Category:** IDA General\
**Created:** [March 12, 2025, 8:36am UTC](https://community.hex-rays.com/t/is-there-an-api-for-apply-patched-bytes-to-input-file/234 "2025-03-12T08:36:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![avics](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/avics/32/47_2.png) [@avics](https://community.hex-rays.com/u/avics)\
**Post date:** [March 12, 2025, 8:36am UTC](https://community.hex-rays.com/t/is-there-an-api-for-apply-patched-bytes-to-input-file/234/1 "2025-03-12T08:36:57Z")

</div>

Hi,

The title says it all. Is there an API call to save the patched bytes into the inputfile.  
There is a menu entry but is the actual call exposed?

Avi.

---

<div class="post-metadata">

**Author:** ![Harding](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/harding/32/37_2.png) [@Harding](https://community.hex-rays.com/u/Harding)\
**Post date:** [April 19, 2025, 10:35am UTC](https://community.hex-rays.com/t/is-there-an-api-for-apply-patched-bytes-to-input-file/234/2 "2025-04-19T10:35:53Z")

</div>

I haven’t found any way to do it directly but you can call [idc.gen\_file()](https://github.com/HexRaysSA/IDAPython/blob/d12e31eae9d678f647013527596a715dd378f989/python/idc.py#L1056) to generate a `DIF` file that is the difference and then use a thirdparty program to actually make the modifications. I have written a replacement for idc.gen\_file on Github: [community\_base.py](https://github.com/Harding-Stardust/community_base/blob/4c497cbe1c04781f9f0a17d0344a1dbd336eaa9c/community_base.py#L5475)

---

<div class="post-metadata">

**Author:** ![Milanek](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@Milanek](https://community.hex-rays.com/u/Milanek)\
**Post date:** [April 19, 2025, 2:04pm UTC](https://community.hex-rays.com/t/is-there-an-api-for-apply-patched-bytes-to-input-file/234/3 "2025-04-19T14:04:30Z")

</div>

Perhaps [patching/plugins/patching/util/ida.py at f7902033f9c2be9ea71017ce9eb13691906cc858 · gaasedelen/patching · GitHub](https://github.com/gaasedelen/patching/blob/f7902033f9c2be9ea71017ce9eb13691906cc858/plugins/patching/util/ida.py#L80) could help you.

---

<div class="post-metadata">

**Author:** ![0xeb](https://avatars.discourse-cdn.com/v4/letter/0/bc79bd/32.png) [@0xeb](https://community.hex-rays.com/u/0xeb)\
**Post date:** [May 7, 2025, 9:36pm UTC](https://community.hex-rays.com/t/is-there-an-api-for-apply-patched-bytes-to-input-file/234/4 "2025-05-07T21:36:12Z")

</div>

Not directly, but you have half the problem solved with this API:

```c++
idaman int ida_export visit_patched_bytes(
        ea_t ea1,
        ea_t ea2,
        int (idaapi *cb)(ea_t ea, qoff64_t fpos, uint64 o, uint64 v, void *ud),
        void *ud = nullptr);

```

All you have to do is just open a file prior to calling this API, then in the callback, patch the values in; ofc, finally close the file.

---

<div class="post-metadata">

**Author:** ![Harding](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/harding/32/37_2.png) [@Harding](https://community.hex-rays.com/u/Harding)\
**Post date:** [May 10, 2025, 11:16pm UTC](https://community.hex-rays.com/t/is-there-an-api-for-apply-patched-bytes-to-input-file/234/5 "2025-05-10T23:16:39Z")

</div>

I sat down and wrote such function.

See `file_write_patches_to_file` at: [community\_base/community\_base.py at 26137c80ddf20449a09ab7246f8c72c98d42d9e3 · Harding-Stardust/community\_base · GitHub](https://github.com/Harding-Stardust/community_base/blob/26137c80ddf20449a09ab7246f8c72c98d42d9e3/community_base.py#L3880)

---

<div class="post-metadata">

**Author:** ![0xeb](https://avatars.discourse-cdn.com/v4/letter/0/bc79bd/32.png) [@0xeb](https://community.hex-rays.com/u/0xeb)\
**Post date:** [May 11, 2025, 4:27am UTC](https://community.hex-rays.com/t/is-there-an-api-for-apply-patched-bytes-to-input-file/234/6 "2025-05-11T04:27:35Z")

</div>

That looks good! thanks for sharing!
